summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-13 15:16:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-13 15:16:23 +0000
commitf9029004eeb1deedb91c4133df2e99ed73414830 (patch)
tree88cd1772687e92cbfc84c725702ba9f24964cdf6
parentde79b66f4689ad0b7f845a24092189a418f13ce4 (diff)
* 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--ChangeLog5
-rw-r--r--bignum.c25
2 files changed, 22 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f92cb39fd22..4c555d39aae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/bignum.c b/bignum.c
index 856ad99eb1a..a20f8369fde 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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;
}