summaryrefslogtreecommitdiff
path: root/sub1.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-11-07 10:08:57 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-11-07 10:08:57 +0000
commit73e6d7bd621b015bfb8d64b5be5fa80f52e6ae0a (patch)
treed0cc39f0951ec9cd728f9698681e5a88c9d348ab /sub1.c
parentd406c7c3f07cacb170533149e9319c334062792b (diff)
downloadmpfr-73e6d7bd621b015bfb8d64b5be5fa80f52e6ae0a.tar.gz
Some minor optimizations.
Optimization of mul.c / sub1.c. Some clean up in the header files. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2537 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'sub1.c')
-rw-r--r--sub1.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/sub1.c b/sub1.c
index 078e33eae..fedd0bde1 100644
--- a/sub1.c
+++ b/sub1.c
@@ -87,13 +87,17 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* reserve a space to store b aligned with the result, i.e. shifted by
(-cancel) % BITS_PER_MP_LIMB to the right */
bn = MPFR_LIMB_SIZE(b);
- /* shift_b = cancel % BITS_PER_MP_LIMB;
- if (shift_b)
- shift_b = BITS_PER_MP_LIMB - shift_b;
- I think (-cancel)%BITS_PER_MP_LIMB is ok. I add an assert anyway */
- shift_b = (-cancel) % BITS_PER_MP_LIMB;
- cancel1 = (cancel + shift_b) / BITS_PER_MP_LIMB;
+ if ((UINT_MAX % BITS_PER_MP_LIMB) == (BITS_PER_MP_LIMB-1))
+ shift_b = (-cancel) % BITS_PER_MP_LIMB;
+ else
+ {
+ shift_b = cancel % BITS_PER_MP_LIMB;
+ if (shift_b)
+ shift_b = BITS_PER_MP_LIMB - shift_b;
+ }
MPFR_ASSERTD( shift_b >= 0 && shift_b < BITS_PER_MP_LIMB);
+
+ cancel1 = (cancel + shift_b) / BITS_PER_MP_LIMB;
/* the high cancel1 limbs from b should not be taken into account */
if (MPFR_UNLIKELY(shift_b == 0))
@@ -115,9 +119,13 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* reserve a space to store c aligned with the result, i.e. shifted by
(diff_exp-cancel) % BITS_PER_MP_LIMB to the right */
cn = MPFR_LIMB_SIZE(c);
- /* shift_c = diff_exp - (cancel % BITS_PER_MP_LIMB);
- shift_c = (shift_c + BITS_PER_MP_LIMB) % BITS_PER_MP_LIMB;*/
- shift_c = (diff_exp - cancel) % BITS_PER_MP_LIMB;
+ if ((UINT_MAX % BITS_PER_MP_LIMB) == (BITS_PER_MP_LIMB-1))
+ shift_c = (diff_exp - cancel) % BITS_PER_MP_LIMB;
+ else
+ {
+ shift_c = diff_exp - (cancel % BITS_PER_MP_LIMB);
+ shift_c = (shift_c + BITS_PER_MP_LIMB) % BITS_PER_MP_LIMB;
+ }
MPFR_ASSERTD( shift_c >= 0 && shift_c < BITS_PER_MP_LIMB);
if (MPFR_UNLIKELY(shift_c == 0))
@@ -191,7 +199,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
#endif
/* subtract high(c) */
- if (an + cancel2 > 0) /* otherwise c does not overlap with a */
+ if (MPFR_LIKELY(an + cancel2 > 0)) /* otherwise c does not overlap with a */
{
mp_limb_t *ap2;
@@ -238,7 +246,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
carry = ap[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE);
ap[0] -= carry;
- if (rnd_mode == GMP_RNDN)
+ if (MPFR_LIKELY(rnd_mode == GMP_RNDN))
{
if (MPFR_LIKELY(sh))
{