Skip to content

Commit 2e88b57

Browse files
committed
optimize mp_mul_d
1 parent 6ec36e0 commit 2e88b57

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mp_mul_d.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
1010
mp_err err;
1111
int ix, oldused;
1212

13+
if (b == 1u) {
14+
return mp_copy(a, c);
15+
}
16+
17+
/* power of two ? */
18+
if (MP_HAS(MP_MUL_2) && (b == 2u)) {
19+
return mp_mul_2(a, c);
20+
}
21+
if (MP_HAS(MP_MUL_2D) && (b != 0u) && ((b & (b - 1u)) == 0u)) {
22+
ix = 1;
23+
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
24+
ix++;
25+
}
26+
return mp_mul_2d(a, ix, c);
27+
}
28+
1329
/* make sure c is big enough to hold a*b */
1430
if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
1531
return err;

0 commit comments

Comments
 (0)