summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-15 16:47:08 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-15 16:47:08 +0000
commit6df786c79fda2b174785f983ec976b158534c669 (patch)
tree2a8c38018bcc31e7e74c47466235baea667f3e24 /bignum.c
parent49e8387baef9e0d750853ccc3534e5077ea26a1a (diff)
* 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.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/bignum.c b/bignum.c
index fecd0b1953..969dde9e66 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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