Skip to content

Commit 7c2211c

Browse files
authored
Merge pull request #303 from libtom/refactor_mp_div_d
Eliminate unneeded static function
2 parents 34f2ddb + f2d6f52 commit 7c2211c

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

bn_mp_div_d.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,6 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6-
static int s_is_power_of_two(mp_digit b, int *p)
7-
{
8-
int x;
9-
10-
/* fast return if no power of two */
11-
if ((b == 0u) || ((b & (b-1u)) != 0u)) {
12-
return 0;
13-
}
14-
15-
for (x = 0; x < MP_DIGIT_BIT; x++) {
16-
if (b == ((mp_digit)1<<(mp_digit)x)) {
17-
*p = x;
18-
return 1;
19-
}
20-
}
21-
return 0;
22-
}
23-
246
/* single digit division (based on routine from MPI) */
257
mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
268
{
@@ -47,7 +29,11 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
4729
}
4830

4931
/* power of two ? */
50-
if (s_is_power_of_two(b, &ix) == 1) {
32+
if ((b & (b-1)) == 0u) {
33+
ix = 1;
34+
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
35+
ix++;
36+
}
5137
if (d != NULL) {
5238
*d = a->dp[0] & (((mp_digit)1<<(mp_digit)ix) - 1uL);
5339
}

0 commit comments

Comments
 (0)