Skip to content

Commit 6777baa

Browse files
committed
add macro MP_IS_2EXPT
1 parent 2e88b57 commit 6777baa

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

mp_div_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
3434
}
3535
return (c == NULL) ? MP_OKAY : mp_div_2(a, c);
3636
}
37-
if (MP_HAS(MP_DIV_2D) && (b != 0u) && ((b & (b - 1u)) == 0u)) {
37+
if (MP_HAS(MP_DIV_2D) && MP_IS_2EXPT(b)) {
3838
ix = 1;
3939
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
4040
ix++;

mp_log_u32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
1717
return MP_VAL;
1818
}
1919

20-
if (MP_HAS(S_MP_LOG_POW2) && ((base & (base - 1u)) == 0u)) {
20+
if (MP_HAS(S_MP_LOG_POW2) && MP_IS_2EXPT(base)) {
2121
*c = s_mp_log_pow2(a, base);
2222
return MP_OKAY;
2323
}

mp_mul_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
1818
if (MP_HAS(MP_MUL_2) && (b == 2u)) {
1919
return mp_mul_2(a, c);
2020
}
21-
if (MP_HAS(MP_MUL_2D) && (b != 0u) && ((b & (b - 1u)) == 0u)) {
21+
if (MP_HAS(MP_MUL_2D) && MP_IS_2EXPT(b)) {
2222
ix = 1;
2323
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
2424
ix++;

tommath_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ extern void MP_FREE(void *mem, size_t size);
120120

121121
#define MP_EXCH(t, a, b) do { t _c = a; a = b; b = _c; } while (0)
122122

123+
#define MP_IS_2EXPT(x) (((x) != 0u) && (((x) & ((x) - 1u)) == 0u))
124+
123125
/* Static assertion */
124126
#define MP_STATIC_ASSERT(msg, cond) typedef char mp_static_assert_##msg[(cond) ? 1 : -1];
125127

0 commit comments

Comments
 (0)