aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/bignum.c b/bignum.c
index 856ad99eb1..a20f8369fd 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;
}