summaryrefslogtreecommitdiff
path: root/mpz/bin_uiui.c
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2012-05-09 16:18:18 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2012-05-09 16:18:18 +0200
commit9c038331cce3d160408be46523983450a9d671b4 (patch)
tree5ec7e74f2afd0304ca93c9d5d84fc9cf97ca2cbd /mpz/bin_uiui.c
parentfa75a7ab2b4fb10fab255628db419e907da38a7c (diff)
downloadgmp-9c038331cce3d160408be46523983450a9d671b4.tar.gz
mpz/bin_uiui.c: reinserted one of the shifts.
Diffstat (limited to 'mpz/bin_uiui.c')
-rw-r--r--mpz/bin_uiui.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/mpz/bin_uiui.c b/mpz/bin_uiui.c
index be465df67..12a1a0345 100644
--- a/mpz/bin_uiui.c
+++ b/mpz/bin_uiui.c
@@ -83,10 +83,8 @@ mul1 (mp_limb_t m)
static mp_limb_t
mul2 (mp_limb_t m)
{
- /* THINK: (m + 0) * (m + 1) >> 1 does overflow if (m + 0) * (m + 1)
- does. The shift does not give any advantage. We should shift
- _before_ multiplying: (m | 1) * ((m + 1) >> 1) ... */
- mp_limb_t m01 = (m + 0) * (m + 1);
+ /* We need to shift before multiplying, to avoid an overflow. */
+ mp_limb_t m01 = (m | 1) * ((m + 1) >> 1);
return m01;
}
@@ -152,7 +150,7 @@ static const mulfunc_t mulfunc[] = {0,mul1,mul2,mul3,mul4,mul5,mul6,mul7,mul8};
#define M (numberof(mulfunc)-1)
/* Number of factors-of-2 removed by the corresponding mulN functon. */
-static const unsigned char tcnttab[] = {0,0,0,1,2,2,4,4,6};
+static const unsigned char tcnttab[] = {0,0,1,1,2,2,4,4,6};
#if 1
/* This variant is inaccurate but share the code with other functions. */