summaryrefslogtreecommitdiffstats
path: root/mpi
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-11-22 16:53:15 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-11-22 16:53:15 -0800
commitce92f87e3c3ddfb8d564d2b881145a17b74d6b57 (patch)
treef03076db5f44355e91784a5cc6b39938c6cb5cd1 /mpi
parenta9b23a145709f2f8fac65964f363da3829ee6745 (diff)
downloadtxr-ce92f87e3c3ddfb8d564d2b881145a17b74d6b57.tar.gz
txr-ce92f87e3c3ddfb8d564d2b881145a17b74d6b57.tar.bz2
txr-ce92f87e3c3ddfb8d564d2b881145a17b74d6b57.zip
mpi: small rearrangement in is-power-of-two function.
* mpi.c (s_mp_ispow2): Delay call to s_highest_bit until that value is actually needed. Perhaps the compiler does the code motion, but let's write the code that way.
Diffstat (limited to 'mpi')
-rw-r--r--mpi/mpi.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 355a8d1f..0d5e0beb 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -4037,7 +4037,7 @@ mp_size s_mp_ispow2(mp_int *v)
{
mp_digit d, *dp;
mp_size uv = USED(v);
- mp_size extra = 0, ix;
+ mp_size ix;
d = DIGIT(v, uv - 1); /* most significant digit of v */
@@ -4045,8 +4045,6 @@ mp_size s_mp_ispow2(mp_int *v)
if ((d & (d - 1)) != 0)
return MP_SIZE_MAX; /* not a power of two */
- extra = s_highest_bit(d) - 1;
-
if (uv >= 2) {
ix = uv - 2;
dp = DIGITS(v) + ix;
@@ -4059,7 +4057,7 @@ mp_size s_mp_ispow2(mp_int *v)
}
}
- return ((uv - 1) * DIGIT_BIT) + extra;
+ return ((uv - 1) * DIGIT_BIT) + s_highest_bit(d) - 1;
}
int s_mp_ispow2d(mp_digit d)