diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-15 16:47:08 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-15 16:47:08 +0000 |
commit | 6df786c79fda2b174785f983ec976b158534c669 (patch) | |
tree | 2a8c38018bcc31e7e74c47466235baea667f3e24 /bignum.c | |
parent | 49e8387baef9e0d750853ccc3534e5077ea26a1a (diff) | |
download | ruby-6df786c79fda2b174785f983ec976b158534c669.tar.gz |
* bignum.c (bigdivrem_single): Use shift when y is a power of two.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -2683,16 +2683,25 @@ bigdivrem_num_extra_words(size_t xn, size_t yn) static BDIGIT bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y) { - size_t i; - BDIGIT_DBL t2; - t2 = 0; - i = xn; - while (i--) { - t2 = BIGUP(t2) + xds[i]; - qds[i] = (BDIGIT)(t2 / y); - t2 %= y; + assert(0 < xn); + if (POW2_P(y)) { + BDIGIT r; + r = xds[0] & (y-1); + bary_small_rshift(qds, xds, xn, bitsize(y)-1, 0); + return r; + } + else { + size_t i; + BDIGIT_DBL t2; + t2 = 0; + i = xn; + while (i--) { + t2 = BIGUP(t2) + xds[i]; + qds[i] = (BDIGIT)(t2 / y); + t2 %= y; + } + return (BDIGIT)t2; } - return (BDIGIT)t2; } static void |