From a3c9570c9f3b6544c471985ca89b8712daafa603 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 20 Sep 2017 09:21:54 +0000 Subject: Move fast return from s_is_power_of_two() to mp_div_d(). This saves a function call in the common case where b is not a power of 2. --- libtommath/bn_mp_div_d.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c index 0e9dc95..d0131c3 100644 --- a/libtommath/bn_mp_div_d.c +++ b/libtommath/bn_mp_div_d.c @@ -19,13 +19,8 @@ static int s_is_power_of_two(mp_digit b, int *p) { int x; - /* fast return if no power of two */ - if ((b & (b-1)) != 0) { - return 0; - } - - /* This loops gives the wrong result for b==1, - * but this function is never called for those values. */ + /* Gives the wrong result for b==1, but this function + * is never called for this value anyway. */ for (x = 1; x < DIGIT_BIT; x++) { if (b == (((mp_digit)1)<dp[0] & ((((mp_digit)1)<