diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2018-07-19 08:18:34 +0200 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2018-07-19 08:18:34 +0200 |
commit | 27c51dedcf374affcfdbea03228b00a955aada5b (patch) | |
tree | 68e7fcb1d39e90f0060b09f856b643b4a1c78a14 /mpz/powm_ui.c | |
parent | 02be51d31564a0dc07f6723be66fb5e69f68efa4 (diff) | |
download | gmp-27c51dedcf374affcfdbea03228b00a955aada5b.tar.gz |
mpz/powm_ui.c: Avoid a branch in the flow, handling el==1 early.
Diffstat (limited to 'mpz/powm_ui.c')
-rw-r--r-- | mpz/powm_ui.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/mpz/powm_ui.c b/mpz/powm_ui.c index cfab66da8..23d3ed8b1 100644 --- a/mpz/powm_ui.c +++ b/mpz/powm_ui.c @@ -136,8 +136,13 @@ mpz_powm_ui (mpz_ptr r, mpz_srcptr b, unsigned long int el, mpz_srcptr m) if (UNLIKELY (mn == 0)) DIVIDE_BY_ZERO; - if (el == 0) + if (el <= 1) { + if (el == 1) + { + mpz_mod (r, b, m); + return; + } /* Exponent is zero, result is 1 mod M, i.e., 1 or 0 depending on if M equals 1. */ SIZ(r) = mn != 1 || mp[0] != 1; @@ -193,16 +198,7 @@ mpz_powm_ui (mpz_ptr r, mpz_srcptr b, unsigned long int el, mpz_srcptr m) e = (e << c) << 1; /* shift the exp bits to the left, lose msb */ c = GMP_LIMB_BITS - 1 - c; - if (c == 0) - { - /* If m is already normalized (high bit of high limb set), and b is - the same size, but a bigger value, and e==1, then there's no - modular reductions done and we can end up with a result out of - range at the end. */ - if (xn == mn && mpn_cmp (xp, mp, mn) >= 0) - mpn_sub_n (xp, xp, mp, mn); - } - else + ASSERT (c != 0); /* el > 1 */ { /* Main loop. */ do |