diff --git a/src/bignum.c b/src/bignum.c index eb198a7f33a71f98ff2c4b8a37ebefeb855b08f3..215b12517b68d0e403e4724d195c7343f654b4bc 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: bignum.c,v 1.35 2003/03/25 19:07:48 mast Exp $ +|| $Id: bignum.c,v 1.36 2003/03/28 15:53:12 mast Exp $ */ #include "global.h" @@ -123,93 +123,18 @@ PMOD_EXPORT void convert_svalue_to_bignum(struct svalue *s) } #ifdef INT64 - -PMOD_EXPORT void push_int64(INT64 i) +static void bootstrap_push_int64 (INT64 i) { if(i == DO_NOT_WARN((INT_TYPE)i)) { push_int(DO_NOT_WARN((INT_TYPE)i)); } else - { - unsigned int neg = 0; - if( i < 0 ) - { - i = -i; - neg = 1; - } - -#if PIKE_BYTEORDER == 1234 - { - char digits[8]; - char *ledigits = (char *)&i; - digits[7] = ledigits[ 0 ]; digits[6] = ledigits[ 1 ]; - digits[5] = ledigits[ 2 ]; digits[4] = ledigits[ 3 ]; - digits[3] = ledigits[ 4 ]; digits[2] = ledigits[ 5 ]; - digits[1] = ledigits[ 6 ]; digits[0] = ledigits[ 7 ]; - push_string( make_shared_binary_string( digits, 8 ) ); - } -#else - push_string( make_shared_binary_string( (char *)&i, 8 ) ); -#endif - push_int( 256 ); - apply_svalue(&auto_bignum_program, 2); - - - if(neg) { - apply_low(sp[-1].u.object,FIND_LFUN(sp[-1].u.object->prog,LFUN_SUBTRACT),0); - stack_pop_n_elems_keep_top(1); - } - } + Pike_error ("Failed to convert large integer (Gmp.bignum not loaded).\n"); } -/* This routines can be optimized quite drastically. */ -#define BIGNUM_INT64_MASK 0xffffff -#define BIGNUM_INT64_SHIFT 24 -PMOD_EXPORT int int64_from_bignum(INT64 *i, struct object *bignum) -{ - int neg, pos, rshfun, andfun; - - *i = 0; - - push_int(0); - apply_low(bignum, FIND_LFUN(bignum->prog, LFUN_LT), 1); - if(sp[-1].type != T_INT) - Pike_error("Result from Gmp.bignum->`< not an integer.\n"); - neg = (--sp)->u.integer; - - if(neg) { - apply_low(bignum, FIND_LFUN(bignum->prog, LFUN_SUBTRACT), 0); - dmalloc_touch_svalue(sp-1); - } - else - ref_push_object(bignum); - - rshfun = FIND_LFUN(bignum->prog, LFUN_RSH); - andfun = FIND_LFUN(bignum->prog, LFUN_AND); - - for(pos = 0; sp[-1].type != T_INT; ) - { - push_int(BIGNUM_INT64_MASK); - apply_low(sp[-2].u.object, andfun, 1); - if(sp[-1].type != T_INT) - Pike_error("Result from Gmp.bignum->`& not an integer.\n"); - *i |= (INT64)(--sp)->u.integer << (INT64)pos; - pos += BIGNUM_INT64_SHIFT; - - push_int(BIGNUM_INT64_SHIFT); - apply_low(sp[-2].u.object, rshfun, 1); - stack_pop_n_elems_keep_top(1); - dmalloc_touch_svalue(sp-1); - } - - *i |= (INT64)(--sp)->u.integer << (INT64)pos; - - if(neg) - *i = -*i; - - return 1; /* We may someday return 0 if the conversion fails. */ -} -#endif /* INT64 */ +PMOD_EXPORT void (*push_int64) (INT64) = bootstrap_push_int64; +PMOD_EXPORT int (*int64_from_bignum) (INT64 *, struct object *) = NULL; +#endif #endif /* AUTO_BIGNUM */ diff --git a/src/bignum.h b/src/bignum.h index 2d62460ef5d8811338f94ebfcee2f00d50a12130..e442e31c07893ceb7a54f548b155e0637906f303 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: bignum.h,v 1.19 2003/02/26 17:22:24 mast Exp $ +|| $Id: bignum.h,v 1.20 2003/03/28 15:53:12 mast Exp $ */ #include "global.h" @@ -58,8 +58,8 @@ struct pike_string *string_from_bignum(struct object *o, int base); void convert_svalue_to_bignum(struct svalue *s); #ifdef INT64 -void push_int64(INT64 i); -int int64_from_bignum(INT64 *i, struct object *bignum); +PMOD_EXPORT void (*push_int64)(INT64 i); +PMOD_EXPORT int (*int64_from_bignum) (INT64 *i, struct object *bignum); #else #define push_int64(i) push_int((INT_TYPE)i) #define int64_from_bignum(I,BIGNUM) 0