diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-09-20 09:21:54 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-09-20 09:21:54 (GMT) |
commit | a3c9570c9f3b6544c471985ca89b8712daafa603 (patch) | |
tree | b9cbb08ca3ac72de4a6292147b199b36beb9f4a1 /libtommath/bn_mp_div_d.c | |
parent | 88b282766104841d47f9878536605bc08ae4c599 (diff) | |
download | tcl-a3c9570c9f3b6544c471985ca89b8712daafa603.zip tcl-a3c9570c9f3b6544c471985ca89b8712daafa603.tar.gz tcl-a3c9570c9f3b6544c471985ca89b8712daafa603.tar.bz2 |
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.
Diffstat (limited to 'libtommath/bn_mp_div_d.c')
-rw-r--r-- | libtommath/bn_mp_div_d.c | 11 |
1 files 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)<<x)) { *p = x; @@ -60,7 +55,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) } /* power of two ? */ - if (s_is_power_of_two(b, &ix) == 1) { + if (((b & (b-1)) == 0) && s_is_power_of_two(b, &ix)) { if (d != NULL) { *d = a->dp[0] & ((((mp_digit)1)<<ix) - 1); } |