diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2020-02-09 11:57:53 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2020-02-09 11:57:53 +0100 |
commit | 818b08d7d17e6f89ef0ab12345025a35fbe9134d (patch) | |
tree | df4f943bb959051ba7656d81522bc3114a5ec78e /mpn | |
parent | 95f8771ec55091433a81bcb8f6a4e4c2e9158ecb (diff) | |
download | gmp-818b08d7d17e6f89ef0ab12345025a35fbe9134d.tar.gz |
mpn/generic/sqrmod_bnm1.c (mpn_bc_sqrmod_bnp1): Shorter mpn_sqr.
Diffstat (limited to 'mpn')
-rw-r--r-- | mpn/generic/sqrmod_bnm1.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/mpn/generic/sqrmod_bnm1.c b/mpn/generic/sqrmod_bnm1.c index 0a27d7b14..3f832e1e8 100644 --- a/mpn/generic/sqrmod_bnm1.c +++ b/mpn/generic/sqrmod_bnm1.c @@ -59,8 +59,8 @@ mpn_bc_sqrmod_bnm1 (mp_ptr rp, mp_srcptr ap, mp_size_t rn, mp_ptr tp) /* Input is {ap,rn+1}; output is {rp,rn+1}, in - semi-normalised representation, computation is mod B^rn + 1. Needs - a scratch area of 2rn + 2 limbs at tp; tp == rp is allowed. + normalised representation, computation is mod B^rn + 1. Needs + a scratch area of 2rn limbs at tp; tp == rp is allowed. Output is normalised. */ static void mpn_bc_sqrmod_bnp1 (mp_ptr rp, mp_srcptr ap, mp_size_t rn, mp_ptr tp) @@ -69,12 +69,16 @@ mpn_bc_sqrmod_bnp1 (mp_ptr rp, mp_srcptr ap, mp_size_t rn, mp_ptr tp) ASSERT (0 < rn); - mpn_sqr (tp, ap, rn + 1); - ASSERT (tp[2*rn+1] == 0); - ASSERT (tp[2*rn] < GMP_NUMB_MAX); - cy = tp[2*rn] + mpn_sub_n (rp, tp, tp+rn, rn); + if (UNLIKELY (ap[rn])) + { + *rp = 1; + MPN_FILL (rp + 1, rn, 0); + return; + } + mpn_sqr (tp, ap, rn); + cy = mpn_sub_n (rp, tp, tp + rn, rn); rp[rn] = 0; - MPN_INCR_U (rp, rn+1, cy); + MPN_INCR_U (rp, rn + 1, cy); } |