1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2013-08-15 16:47:08 +00:00
parent 49e8387bae
commit 6df786c79f
2 changed files with 22 additions and 9 deletions

View file

@ -1,3 +1,7 @@
Fri Aug 16 01:37:43 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigdivrem_single): Use shift when y is a power of two.
Fri Aug 16 01:09:33 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigdivrem_restoring): Use bigdivrem_single if non-topmost

View file

@ -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