diff --git a/ChangeLog b/ChangeLog index 5c1ea23f8b..29262bfd3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jun 5 08:13:37 2013 Tanaka Akira + + * bignum.c (rb_big_pow): Don't need to multiply SIZEOF_BDIGITS. + Use nlz instead of bitlength_bdigit. + (bitlength_bdigit): Removed. + Wed Jun 5 07:14:18 2013 Tadayoshi Funaba * ext/date/date_core.c (d_lite_cmp, d_lite_equal): simplified. diff --git a/bignum.c b/bignum.c index c197ccaca9..5c7fc1ea8d 100644 --- a/bignum.c +++ b/bignum.c @@ -3178,24 +3178,6 @@ bigsqr(VALUE x) return bigtrunc(bigmul0(x, x)); } -static int -bitlength_bdigit(BDIGIT v) -{ - if (v == 0) - return 0; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; -#if 2 < SIZEOF_BDIGITS - v |= v >> 16; -#endif - v++; - if (v == 0) - return SIZEOF_BDIGITS*CHAR_BIT; - return ffs(v)-1; /* assumption: sizeof(BDIGIT) <= sizeof(int) */ -} - /* * call-seq: * big ** exponent -> numeric @@ -3236,8 +3218,8 @@ rb_big_pow(VALUE x, VALUE y) else { VALUE z = 0; SIGNED_VALUE mask; - const long xlen = RBIGNUM_LEN(x) - 1; - const long xbits = bitlength_bdigit(RBIGNUM_DIGITS(x)[xlen]) + SIZEOF_BDIGITS*BITSPERDIG*xlen; + const long xlen = RBIGNUM_LEN(x); + const long xbits = BITSPERDIG*xlen - nlz(RBIGNUM_DIGITS(x)[xlen-1]); const long BIGLEN_LIMIT = BITSPERDIG*1024*1024; if ((xbits > BIGLEN_LIMIT) || (xbits * yy > BIGLEN_LIMIT)) {