diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-13 15:16:23 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-13 15:16:23 +0000 |
commit | f9029004eeb1deedb91c4133df2e99ed73414830 (patch) | |
tree | 88cd1772687e92cbfc84c725702ba9f24964cdf6 | |
parent | de79b66f4689ad0b7f845a24092189a418f13ce4 (diff) | |
download | ruby-f9029004eeb1deedb91c4133df2e99ed73414830.tar.gz |
* bignum.c (bary_mul_precheck): Use bary_small_lshift or
bary_mul_normal if xl is 1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 25 |
2 files changed, 22 insertions, 8 deletions
@@ -1,3 +1,8 @@ +Sun Jul 14 00:14:15 2013 Tanaka Akira <akr@fsij.org> + + * bignum.c (bary_mul_precheck): Use bary_small_lshift or + bary_mul_normal if xl is 1. + Sat Jul 13 22:58:16 2013 Tanaka Akira <akr@fsij.org> * bignum.c (big_shift3): New function. @@ -1903,14 +1903,23 @@ bary_mul_precheck(BDIGIT **zdsp, size_t *zlp, BDIGIT **xdsp, size_t *xlp, BDIGIT return 1; } - if (xl == 1 && xds[0] == 1) { - MEMCPY(zds, yds, BDIGIT, yl); - MEMZERO(zds + yl, BDIGIT, zl - yl); - return 1; - } - if (yl == 1 && yds[0] == 1) { - MEMCPY(zds, xds, BDIGIT, xl); - MEMZERO(zds + xl, BDIGIT, zl - xl); + if (xl == 1) { + if (xds[0] == 1) { + MEMCPY(zds, yds, BDIGIT, yl); + MEMZERO(zds+yl, BDIGIT, zl-yl); + return 1; + } + if (POW2_P(xds[0])) { + zds[yl] = bary_small_lshift(zds, yds, yl, bitsize(xds[0])-1); + MEMZERO(zds+yl+1, BDIGIT, zl-yl-1); + return 1; + } + if (yl == 1 && yds[0] == 1) { + zds[0] = xds[0]; + MEMZERO(zds+1, BDIGIT, zl-1); + return 1; + } + bary_mul_normal(zds, zl, xds, xl, yds, yl); return 1; } |