diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-11-22 16:53:15 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-11-22 16:53:15 -0800 |
commit | 8d208245fc1666076e2e7ef0a4682194b899de0f (patch) | |
tree | f03076db5f44355e91784a5cc6b39938c6cb5cd1 | |
parent | ffb185cc61e0c218ac9d5a1c7b74b00b1b657f34 (diff) | |
download | txr-8d208245fc1666076e2e7ef0a4682194b899de0f.tar.gz txr-8d208245fc1666076e2e7ef0a4682194b899de0f.tar.bz2 txr-8d208245fc1666076e2e7ef0a4682194b899de0f.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.
-rw-r--r-- | mpi/mpi.c | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -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) |