[pure-lang-svn] SF.net SVN: pure-lang: [79] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-13 18:41:46
|
Revision: 79 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=79&view=rev Author: agraef Date: 2008-05-13 11:41:46 -0700 (Tue, 13 May 2008) Log Message: ----------- 64 bit: bigint fixes. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-05-13 07:07:01 UTC (rev 78) +++ pure/trunk/interpreter.cc 2008-05-13 18:41:46 UTC (rev 79) @@ -191,7 +191,8 @@ declare_extern((void*)pure_int, "pure_int", "expr*", 1, "int"); declare_extern((void*)pure_bigint, - "pure_bigint", "expr*", 2, "int", "int*"); + "pure_bigint", "expr*", 2, "int", + sizeof(mp_limb_t)==8?"long*":"int*"); declare_extern((void*)pure_double, "pure_double", "expr*", 1, "double"); declare_extern((void*)pure_string_dup, @@ -203,7 +204,7 @@ declare_extern((void*)pure_apply, "pure_apply", "expr*", 2, "expr*", "expr*"); declare_extern((void*)pure_cmp_bigint, - "pure_cmp_bigint", "int", 3, "expr*", "int", "int*"); + "pure_cmp_bigint", "int", 3, "expr*", "int", "long*"); declare_extern((void*)pure_cmp_string, "pure_cmp_string", "int", 2, "expr*", "char*"); @@ -2066,12 +2067,16 @@ return Type::Int8Ty; else if (name == "int") return Type::Int32Ty; + else if (name == "long") + return Type::Int64Ty; else if (name == "double") return Type::DoubleTy; else if (name == "char*") return PointerType::get(Type::Int8Ty, 0); else if (name == "int*") return PointerType::get(Type::Int32Ty, 0); + else if (name == "long*") + return PointerType::get(Type::Int64Ty, 0); else if (name == "double*") return PointerType::get(Type::DoubleTy, 0); else if (name == "expr*") @@ -2097,12 +2102,16 @@ return "char"; else if (type == Type::Int32Ty) return "int"; + else if (type == Type::Int64Ty) + return "long"; else if (type == Type::DoubleTy) return "double"; else if (type == PointerType::get(Type::Int8Ty, 0)) return "char*"; else if (type == PointerType::get(Type::Int32Ty, 0)) return "int*"; + else if (type == PointerType::get(Type::Int64Ty, 0)) + return "long*"; else if (type == PointerType::get(Type::DoubleTy, 0)) return "double*"; else if (type == ExprPtrTy) @@ -3698,31 +3707,30 @@ /* We're a bit lazy in that we only support 32 and 64 bit limbs here, but that should probably work on most if not all systems where GMP is available. */ -#ifdef _LONG_LONG_LIMB - // assume 64 bit limbs - assert(sizeof(mp_limb_t) == 8); - // second arg: array of unsigned long ints (least significant limb first) - size_t n = (size_t)(z->_mp_size>=0 ? z->_mp_size : -z->_mp_size); - vector<Constant*> u(n); - for (size_t i = 0; i < n; i++) u[i] = UInt64(z->_mp_d[i]); - Constant *limbs = ConstantArray::get(ArrayType::get(Type::Int64Ty, n), u); Env& e = act_env(); - GlobalVariable *v = new GlobalVariable - (ArrayType::get(Type::Int64Ty, n), true, - GlobalVariable::InternalLinkage, limbs, "", module); -#else - // assume 32 bit limbs - assert(sizeof(mp_limb_t) == 4); - // second arg: array of unsigned ints (least significant limb first) - size_t n = (size_t)(z->_mp_size>=0 ? z->_mp_size : -z->_mp_size); - vector<Constant*> u(n); - for (size_t i = 0; i < n; i++) u[i] = UInt(z->_mp_d[i]); - Constant *limbs = ConstantArray::get(ArrayType::get(Type::Int32Ty, n), u); - Env& e = act_env(); - GlobalVariable *v = new GlobalVariable - (ArrayType::get(Type::Int32Ty, n), true, - GlobalVariable::InternalLinkage, limbs, "", module); -#endif + GlobalVariable *v; + if (sizeof(mp_limb_t) == 8) { + // 64 bit limbs + // second arg: array of unsigned long ints (least significant limb first) + size_t n = (size_t)(z->_mp_size>=0 ? z->_mp_size : -z->_mp_size); + vector<Constant*> u(n); + for (size_t i = 0; i < n; i++) u[i] = UInt64(z->_mp_d[i]); + Constant *limbs = ConstantArray::get(ArrayType::get(Type::Int64Ty, n), u); + v = new GlobalVariable + (ArrayType::get(Type::Int64Ty, n), true, + GlobalVariable::InternalLinkage, limbs, "", module); + } else { + // assume 32 bit limbs + assert(sizeof(mp_limb_t) == 4); + // second arg: array of unsigned ints (least significant limb first) + size_t n = (size_t)(z->_mp_size>=0 ? z->_mp_size : -z->_mp_size); + vector<Constant*> u(n); + for (size_t i = 0; i < n; i++) u[i] = UInt(z->_mp_d[i]); + Constant *limbs = ConstantArray::get(ArrayType::get(Type::Int32Ty, n), u); + v = new GlobalVariable + (ArrayType::get(Type::Int32Ty, n), true, + GlobalVariable::InternalLinkage, limbs, "", module); + } // "cast" the int array to a int* ptr = e.CreateGEP(v, Zero, Zero); } Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-05-13 07:07:01 UTC (rev 78) +++ pure/trunk/runtime.cc 2008-05-13 18:41:46 UTC (rev 79) @@ -714,27 +714,25 @@ case EXPR::STR: return pure_pointer(x->data.s); case EXPR::INT: return pure_pointer((void*)x->data.i); case EXPR::BIGINT: -#ifdef _LONG_LONG_LIMB - return pure_pointer((void*)x->data.z->_mp_d[0]); -#else - if (sizeof(void*) == 4) + if (sizeof(mp_limb_t) == 8) + return pure_pointer((void*)x->data.z->_mp_d[0]); + else if (sizeof(void*) == 4) return pure_pointer((void*)mpz_get_ui(x->data.z)); else { uint64_t u = x->data.z->_mp_d[0]+(((uint64_t)x->data.z->_mp_d[1])<<32); return pure_pointer((void*)u); } -#endif default: return 0; } } static pure_expr *pointer_to_bigint(void *p) { -#ifdef _LONG_LONG_LIMB - // In this case the pointer value ought to fit into a single limb. - limb_t u[1] = { (uint64_t)p }; - return pure_bigint(1, u); -#else + if (sizeof(mp_limb_t) == 8) { + // In this case the pointer value ought to fit into a single limb. + limb_t u[1] = { (uint64_t)p }; + return pure_bigint(1, u); + } // 4 byte limbs. if (sizeof(void*) == 4) { // 4 byte pointers. Note that we still cast to 64 bit first, since @@ -747,7 +745,6 @@ limb_t u[2] = { (uint32_t)(uint64_t)p, (uint32_t)(((uint64_t)p)>>32) }; return pure_bigint(2, u); } -#endif } extern "C" Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-05-13 07:07:01 UTC (rev 78) +++ pure/trunk/runtime.h 2008-05-13 18:41:46 UTC (rev 79) @@ -12,11 +12,7 @@ #endif /* Our "limb" type. Used to pass bigint constants to the runtime. */ -#ifdef _LONG_LONG_LIMB // try to match what GMP uses -typedef uint64_t limb_t; -#else -typedef uint32_t limb_t; -#endif +typedef mp_limb_t limb_t; /* Closure data. This is a bit on the heavy side, so expressions which need it (i.e., functions) refer to this extra data via an allocated pointer. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |