Merge pull request #303 from libtom/refactor_mp_div_d Eliminate unneeded static function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/bn_mp_div_d.c b/bn_mp_div_d.c
index 780aab6..569f594 100644
--- a/bn_mp_div_d.c
+++ b/bn_mp_div_d.c
@@ -3,24 +3,6 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
-static int s_is_power_of_two(mp_digit b, int *p)
-{
- int x;
-
- /* fast return if no power of two */
- if ((b == 0u) || ((b & (b-1u)) != 0u)) {
- return 0;
- }
-
- for (x = 0; x < MP_DIGIT_BIT; x++) {
- if (b == ((mp_digit)1<<(mp_digit)x)) {
- *p = x;
- return 1;
- }
- }
- return 0;
-}
-
/* single digit division (based on routine from MPI) */
mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
{
@@ -47,7 +29,11 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}
/* power of two ? */
- if (s_is_power_of_two(b, &ix) == 1) {
+ if ((b & (b-1)) == 0u) {
+ ix = 1;
+ while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
+ ix++;
+ }
if (d != NULL) {
*d = a->dp[0] & (((mp_digit)1<<(mp_digit)ix) - 1uL);
}