* bignum.c (bary_mul): Use simple multiplication if yl is small.
(rb_cstr_to_inum): Invoke bigsq instead of bigmul0. (bigsq): Re-implemented. (bigmul0): Invoke bigsq if two arguments are identical. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a2116ef2cd
commit
5cf931d65e
@ -1,3 +1,10 @@
|
|||||||
|
Sun Jul 21 21:08:59 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (bary_mul): Use simple multiplication if yl is small.
|
||||||
|
(rb_cstr_to_inum): Invoke bigsq instead of bigmul0.
|
||||||
|
(bigsq): Re-implemented.
|
||||||
|
(bigmul0): Invoke bigsq if two arguments are identical.
|
||||||
|
|
||||||
Sun Jul 21 09:58:19 2013 Tanaka Akira <akr@fsij.org>
|
Sun Jul 21 09:58:19 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (bary_mul_toom3): New function based on bigmul1_toom3.
|
* bignum.c (bary_mul_toom3): New function based on bigmul1_toom3.
|
||||||
|
37
bignum.c
37
bignum.c
@ -2496,7 +2496,7 @@ bary_mul_toom3_start(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds
|
|||||||
static void
|
static void
|
||||||
bary_mul(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl)
|
bary_mul(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl)
|
||||||
{
|
{
|
||||||
if (xl < KARATSUBA_MUL_DIGITS) {
|
if (xl < KARATSUBA_MUL_DIGITS || yl < KARATSUBA_MUL_DIGITS) {
|
||||||
if (xds == yds && xl == yl)
|
if (xds == yds && xl == yl)
|
||||||
bary_sq_fast(zds, zl, xds, xl);
|
bary_sq_fast(zds, zl, xds, xl);
|
||||||
else
|
else
|
||||||
@ -3586,7 +3586,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
|
|||||||
MEMCPY(vds+i, uds+i, BDIGIT, num_bdigits-i);
|
MEMCPY(vds+i, uds+i, BDIGIT, num_bdigits-i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
powerv = bigtrunc(bigmul0(powerv, powerv));
|
powerv = bigtrunc(bigsq(powerv));
|
||||||
tds = vds;
|
tds = vds;
|
||||||
vds = uds;
|
vds = uds;
|
||||||
uds = tds;
|
uds = tds;
|
||||||
@ -5012,6 +5012,30 @@ rb_big_minus(VALUE x, VALUE y)
|
|||||||
|
|
||||||
static VALUE bigdivrem(VALUE, VALUE, volatile VALUE*, volatile VALUE*);
|
static VALUE bigdivrem(VALUE, VALUE, volatile VALUE*, volatile VALUE*);
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
bigsq(VALUE x)
|
||||||
|
{
|
||||||
|
long xn, zn;
|
||||||
|
VALUE z;
|
||||||
|
BDIGIT *xds, *zds;
|
||||||
|
|
||||||
|
xn = RBIGNUM_LEN(x);
|
||||||
|
zn = 2 * xn;
|
||||||
|
|
||||||
|
z = bignew(zn, 1);
|
||||||
|
|
||||||
|
xds = BDIGITS(x);
|
||||||
|
zds = BDIGITS(z);
|
||||||
|
|
||||||
|
if (xn < KARATSUBA_MUL_DIGITS)
|
||||||
|
bary_sq_fast(zds, zn, xds, xn);
|
||||||
|
else
|
||||||
|
bary_mul(zds, zn, xds, xn, xds, xn);
|
||||||
|
|
||||||
|
RB_GC_GUARD(x);
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
bigmul0(VALUE x, VALUE y)
|
bigmul0(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
@ -5019,6 +5043,9 @@ bigmul0(VALUE x, VALUE y)
|
|||||||
VALUE z;
|
VALUE z;
|
||||||
BDIGIT *xds, *yds, *zds;
|
BDIGIT *xds, *yds, *zds;
|
||||||
|
|
||||||
|
if (x == y)
|
||||||
|
return bigsq(x);
|
||||||
|
|
||||||
xn = RBIGNUM_LEN(x);
|
xn = RBIGNUM_LEN(x);
|
||||||
yn = RBIGNUM_LEN(y);
|
yn = RBIGNUM_LEN(y);
|
||||||
zn = xn + yn;
|
zn = xn + yn;
|
||||||
@ -5590,12 +5617,6 @@ rb_big_fdiv(VALUE x, VALUE y)
|
|||||||
return DBL2NUM(dx / dy);
|
return DBL2NUM(dx / dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
bigsq(VALUE x)
|
|
||||||
{
|
|
||||||
return bigtrunc(bigmul0(x, x));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* big ** exponent -> numeric
|
* big ** exponent -> numeric
|
||||||
|
Loading…
x
Reference in New Issue
Block a user