From ce92f87e3c3ddfb8d564d2b881145a17b74d6b57 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 22 Nov 2020 16:53:15 -0800 Subject: 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. --- mpi/mpi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mpi/mpi.c') 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) -- cgit v1.2.3