summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 23:15:30 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 23:15:30 +0000
commit14ec81b0a26458e0099472cbb0e768b0411016cb (patch)
tree23118c4cc5f30788f8f136fe8cfc6d417f1af20f /bignum.c
parent4eabe8193a801fca0a6456b465217baae472ee7a (diff)
* bignum.c (rb_big_pow): Don't need to multiply SIZEOF_BDIGITS.
Use nlz instead of bitlength_bdigit. (bitlength_bdigit): Removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c22
1 files changed, 2 insertions, 20 deletions
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)) {