summaryrefslogtreecommitdiff
path: root/mini-gmp
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2020-10-18 07:35:43 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2020-10-18 07:35:43 +0200
commitb8d780cef37d7f5d396029f1e380bfab3ab69489 (patch)
tree62b3980217d3de24323e0cd949333d4027e4dde8 /mini-gmp
parenta3257b2eb299c4b806b6d42a92b0d8c5e52367f0 (diff)
downloadgmp-b8d780cef37d7f5d396029f1e380bfab3ab69489.tar.gz
mini-gmp/mini-gmp.c (mpn_set_str_bits): Reduce bramches and writes.
Diffstat (limited to 'mini-gmp')
-rw-r--r--mini-gmp/mini-gmp.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/mini-gmp/mini-gmp.c b/mini-gmp/mini-gmp.c
index ab092adce..a78264533 100644
--- a/mini-gmp/mini-gmp.c
+++ b/mini-gmp/mini-gmp.c
@@ -1331,29 +1331,26 @@ mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn,
unsigned bits)
{
mp_size_t rn;
- size_t j;
+ mp_limb_t limb;
unsigned shift;
- for (j = sn, rn = 0, shift = 0; j-- > 0; )
+ for (limb = 0, rn = 0, shift = 0; sn-- > 0; )
{
- if (shift == 0)
- {
- rp[rn++] = sp[j];
- shift += bits;
- }
- else
+ limb |= (mp_limb_t) sp[sn] << shift;
+ shift += bits;
+ if (shift >= GMP_LIMB_BITS)
{
- rp[rn-1] |= (mp_limb_t) sp[j] << shift;
- shift += bits;
- if (shift >= GMP_LIMB_BITS)
- {
- shift -= GMP_LIMB_BITS;
- if (shift > 0)
- rp[rn++] = (mp_limb_t) sp[j] >> (bits - shift);
- }
+ shift -= GMP_LIMB_BITS;
+ rp[rn++] = limb;
+ /* Next line is correct also if shift == 0,
+ bits == 8, and mp_limb_t == unsigned char. */
+ limb = (unsigned int) sp[sn] >> (bits - shift);
}
}
- rn = mpn_normalized_size (rp, rn);
+ if (limb != 0)
+ rp[rn++] = limb;
+ else
+ rn = mpn_normalized_size (rp, rn);
return rn;
}