optimize mp_mul_d
This commit is contained in:
parent
6ec36e0b9b
commit
2e88b571c1
16
mp_mul_d.c
16
mp_mul_d.c
@ -10,6 +10,22 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
mp_err err;
|
||||
int ix, oldused;
|
||||
|
||||
if (b == 1u) {
|
||||
return mp_copy(a, c);
|
||||
}
|
||||
|
||||
/* power of two ? */
|
||||
if (MP_HAS(MP_MUL_2) && (b == 2u)) {
|
||||
return mp_mul_2(a, c);
|
||||
}
|
||||
if (MP_HAS(MP_MUL_2D) && (b != 0u) && ((b & (b - 1u)) == 0u)) {
|
||||
ix = 1;
|
||||
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
|
||||
ix++;
|
||||
}
|
||||
return mp_mul_2d(a, ix, c);
|
||||
}
|
||||
|
||||
/* make sure c is big enough to hold a*b */
|
||||
if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
|
||||
return err;
|
||||
|
Loading…
Reference in New Issue
Block a user