add macro MP_IS_2EXPT
This commit is contained in:
parent
2e88b571c1
commit
6777baaf97
@ -34,7 +34,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
}
|
||||
return (c == NULL) ? MP_OKAY : mp_div_2(a, c);
|
||||
}
|
||||
if (MP_HAS(MP_DIV_2D) && (b != 0u) && ((b & (b - 1u)) == 0u)) {
|
||||
if (MP_HAS(MP_DIV_2D) && MP_IS_2EXPT(b)) {
|
||||
ix = 1;
|
||||
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
|
||||
ix++;
|
||||
|
@ -17,7 +17,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
|
||||
return MP_VAL;
|
||||
}
|
||||
|
||||
if (MP_HAS(S_MP_LOG_POW2) && ((base & (base - 1u)) == 0u)) {
|
||||
if (MP_HAS(S_MP_LOG_POW2) && MP_IS_2EXPT(base)) {
|
||||
*c = s_mp_log_pow2(a, base);
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
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)) {
|
||||
if (MP_HAS(MP_MUL_2D) && MP_IS_2EXPT(b)) {
|
||||
ix = 1;
|
||||
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
|
||||
ix++;
|
||||
|
@ -120,6 +120,8 @@ extern void MP_FREE(void *mem, size_t size);
|
||||
|
||||
#define MP_EXCH(t, a, b) do { t _c = a; a = b; b = _c; } while (0)
|
||||
|
||||
#define MP_IS_2EXPT(x) (((x) != 0u) && (((x) & ((x) - 1u)) == 0u))
|
||||
|
||||
/* Static assertion */
|
||||
#define MP_STATIC_ASSERT(msg, cond) typedef char mp_static_assert_##msg[(cond) ? 1 : -1];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user