summaryrefslogtreecommitdiff
path: root/mpn
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2020-02-02 16:05:45 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2020-02-02 16:05:45 +0100
commit0e300e7843e1633eaa3aebd3e5577fdb8fa3cee4 (patch)
tree82edb78366821c025b48dd0d205825be51ae14c2 /mpn
parentee06fcde206905dda7ac5657c504676cc656fa17 (diff)
downloadgmp-0e300e7843e1633eaa3aebd3e5577fdb8fa3cee4.tar.gz
mpn/generic/powm.c: Better handling of current window-size.
Diffstat (limited to 'mpn')
-rw-r--r--mpn/generic/powm.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/mpn/generic/powm.c b/mpn/generic/powm.c
index 1a3e83d7d..201f17d2b 100644
--- a/mpn/generic/powm.c
+++ b/mpn/generic/powm.c
@@ -6,7 +6,7 @@
SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
-Copyright 2007-2012, 2019 Free Software Foundation, Inc.
+Copyright 2007-2012, 2019, 2020 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -142,7 +142,7 @@ getbits (const mp_limb_t *p, mp_bitcnt_t bi, int nbits)
mp_limb_t r;
mp_size_t i;
- if (bi < nbits)
+ if (bi <= nbits)
{
return p[0] & (((mp_limb_t) 1 << bi) - 1);
}
@@ -682,11 +682,9 @@ mpn_powm (mp_ptr rp, mp_srcptr bp, mp_size_t bn,
}
expbits = getbits (ep, ebi, windowsize);
- if (ebi < windowsize)
- ebi = 0;
- else
- ebi -= windowsize;
+ ebi -= windowsize;
+ /* THINK: Should we initialise the case expbits % 4 == 0 with a mul? */
count_trailing_zeros (cnt, expbits);
ebi += cnt;
expbits >>= cnt;
@@ -709,18 +707,11 @@ mpn_powm (mp_ptr rp, mp_srcptr bp, mp_size_t bn,
significant bit is 1. */ \
\
expbits = getbits (ep, ebi, windowsize); \
- this_windowsize = windowsize; \
- if (ebi < windowsize) \
- { \
- this_windowsize -= windowsize - ebi; \
- ebi = 0; \
- } \
- else \
- ebi -= windowsize; \
+ this_windowsize = MIN (ebi, windowsize); \
\
count_trailing_zeros (cnt, expbits); \
this_windowsize -= cnt; \
- ebi += cnt; \
+ ebi -= this_windowsize; \
expbits >>= cnt; \
\
do \