diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-04 23:15:30 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-04 23:15:30 +0000 |
commit | 14ec81b0a26458e0099472cbb0e768b0411016cb (patch) | |
tree | 23118c4cc5f30788f8f136fe8cfc6d417f1af20f | |
parent | 4eabe8193a801fca0a6456b465217baae472ee7a (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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | bignum.c | 22 |
2 files changed, 8 insertions, 20 deletions
@@ -1,3 +1,9 @@ +Wed Jun 5 08:13:37 2013 Tanaka Akira <akr@fsij.org> + + * 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 <tadf@dotrb.org> * ext/date/date_core.c (d_lite_cmp, d_lite_equal): simplified. @@ -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)) { |