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

* bignum.c (bigmul1_single): new function specialized respect to

multiply two single digit bignums.
  (bigmul0): use bigmul1_single.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-08-30 00:46:32 +00:00
parent 8b32a1de29
commit fc6be8cdeb
2 changed files with 25 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Sun Aug 30 09:45:11 2009 Tanaka Akira <akr@fsij.org>
* bignum.c (bigmul1_single): new function specialized respect to
multiply two single digit bignums.
(bigmul0): use bigmul1_single.
Sun Aug 30 03:59:43 2009 Tanaka Akira <akr@fsij.org>
* timev.h (TIME_SCALE): defined as 1000000000.

View file

@ -1745,6 +1745,24 @@ big_real_len(VALUE x)
return i + 1;
}
static VALUE
bigmul1_single(VALUE x, VALUE y)
{
BDIGIT_DBL n;
VALUE z = bignew(2, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
BDIGIT *xds, *yds, *zds;
xds = BDIGITS(x);
yds = BDIGITS(y);
zds = BDIGITS(z);
n = (BDIGIT_DBL)xds[0] * yds[0];
zds[0] = BIGLO(n);
zds[1] = BIGDN(n);
return z;
}
static VALUE
bigmul1_normal(VALUE x, VALUE y)
{
@ -2022,6 +2040,7 @@ bigmul0(VALUE x, VALUE y)
if (xn < KARATSUBA_MUL_DIGITS) {
normal:
if (x == y) return bigsqr_fast(x);
if (xn == 1 && yn == 1) return bigmul1_single(x, y);
return bigmul1_normal(x, y);
}