From ce590af8525020d476d4a3c000ddcfb975f8de78 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Fri, 27 Feb 2015 10:16:42 +0000 Subject: [src/sub1sp.c] Avoid an unnecessary mpn_lshift after an mpn_sub_1 when the initial value was a power of two. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9328 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/sub1sp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/sub1sp.c') diff --git a/src/sub1sp.c b/src/sub1sp.c index 5e4703b9b..d8f6e7513 100644 --- a/src/sub1sp.c +++ b/src/sub1sp.c @@ -694,7 +694,9 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) { /* ap was a power of 2, and we lose a bit */ /* Now it is 0111111111111111111[00000 */ - mpn_lshift(ap, ap, n, 1); + /* The following 2 lines are equivalent to: mpn_lshift(ap, ap, n, 1); */ + ap[0] <<= 1; + ap[n-1] |= MPFR_LIMB_HIGHBIT; bx--; /* And the lost bit x depends on Cp+1, and Cp */ /* Compute Cp+1 if it isn't already compute (ie d==1) */ @@ -742,10 +744,10 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) if (MPFR_UNLIKELY(ap[n-1] == MPFR_LIMB_HIGHBIT)) { mp_size_t k = n-1; - do { + do k--; - } while (k>=0 && ap[k]==0); - if (MPFR_UNLIKELY(k<0)) + while (k >= 0 && ap[k] == 0); + if (MPFR_UNLIKELY (k < 0)) { /* It is a power of 2! */ /* Compute Cp+1 if it isn't already compute (ie d==1) */ @@ -763,11 +765,10 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) { DEBUG( printf("(Truncate) Do sub\n") ); mpn_sub_1 (ap, ap, n, MPFR_LIMB_ONE << sh); - mpn_lshift(ap, ap, n, 1); - ap[0] |= MPFR_LIMB_ONE<