summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-09 04:16:27 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-09 04:16:27 +0000
commit995e42817c01111bc3dfeb092d3ed7e080edd8c2 (patch)
tree414972ec9c922d0bbb1bd4a9d813de7941a9ff17 /bignum.c
parent122b6dbcb7c7c5e3c02277d75b5f38bc6d5c3103 (diff)
merge revision(s) 37567: [Backport #7315]
* bignum.c (bigmul0): enable big_mul_toom3. [ruby-core:48552] [Bug #7242] * bignum.c (bigmul1_toom3): fix incorrect calculation. the patch is made by Heesob Park. [ruby-core:48552] [Bug #7242] * bignum.c (bigmul0): disable big_mul_toom3 temporalily. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index ffc1105ccc..04df7ba4ea 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2419,7 +2419,7 @@ bigmul1_toom3(VALUE x, VALUE y)
z2 = bigtrunc(bigadd(u2, u0, 0));
/* z3 <- (z2 - z3) / 2 + 2 * z(inf) == (z2 - z3) / 2 + 2 * u4 */
- z3 = bigadd(z2, z3, 0);
+ z3 = bigtrunc(bigadd(z2, z3, 0));
bigrsh_bang(BDIGITS(z3), RBIGNUM_LEN(z3), 1);
t = big_lshift(u4, 1); /* TODO: combining with next addition */
z3 = bigtrunc(bigadd(z3, t, 1));
@@ -2535,8 +2535,13 @@ bigmul0(VALUE x, VALUE y)
/* balance multiplication by slicing y when x is much smaller than y */
if (2 * xn <= yn) return bigmul1_balance(x, y);
- /* multiplication by karatsuba method */
- return bigmul1_karatsuba(x, y);
+ if (xn < TOOM3_MUL_DIGITS) {
+ /* multiplication by karatsuba method */
+ return bigmul1_karatsuba(x, y);
+ }
+ else if (3*xn <= 2*(yn + 2))
+ return bigmul1_balance(x, y);
+ return bigmul1_toom3(x, y);
}
/*