summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-11-05 12:11:47 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-11-05 12:11:47 +0000
commit3e4ced245d9e603cfc806e64ab56b9b2b7223287 (patch)
tree07d2403dc7906d32a852d032df4b348aed7616b5
parentc1ff1a575e238532d7329dd5ebb15f5f48581868 (diff)
downloadmpfr-3e4ced245d9e603cfc806e64ab56b9b2b7223287.tar.gz
Optimize mpfr_prec_round.
Optimize mpfr_set (Case of both src & dest have the same precision). Start optimizing mpfr_sub1. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2535 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--cmp2.c3
-rw-r--r--mpfr-impl.h5
-rw-r--r--round_prec.c10
-rw-r--r--set.c10
-rw-r--r--sub1.c5
5 files changed, 22 insertions, 11 deletions
diff --git a/cmp2.c b/cmp2.c
index a64cd35ed..4b260feff 100644
--- a/cmp2.c
+++ b/cmp2.c
@@ -47,9 +47,10 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
MPFR_ASSERTD(MPFR_IS_FP(c));
/* Optimized case x - x */
- if (b == c)
+ if (MPFR_UNLIKELY(b == c))
return 0;
+ /*FIXME: Useless for sub1 ? */
if (MPFR_IS_ZERO(b))
{
if (MPFR_IS_ZERO(c))
diff --git a/mpfr-impl.h b/mpfr-impl.h
index 7fca300ea..8165e6aa1 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -292,6 +292,8 @@ long double __gmpfr_longdouble_volatile _MPFR_PROTO ((long double)) ATTRIBUTE_CO
#define MPFR_ARE_SINGULAR(x,y) \
(MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)) || MPFR_UNLIKELY(MPFR_IS_SINGULAR(y)))
+/* TODO: Redo all the macros dealing with the signs */
+
/* Without zeros */
#define MPFR_ISNONNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) > 0)
#define MPFR_ISNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) < 0)
@@ -312,8 +314,7 @@ long double __gmpfr_longdouble_volatile _MPFR_PROTO ((long double)) ATTRIBUTE_CO
(MPFR_CHECK_SIGN(s), MPFR_SIGN(x) = s)
#define MPFR_IS_POS_SIGN(s1) (s1 > 0)
#define MPFR_IS_NEG_SIGN(s1) (s1 < 0)
-#define MPFR_MULT_SIGN(s1, s2) \
- ((s1) * (s2))
+#define MPFR_MULT_SIGN(s1, s2) ((s1) * (s2))
#define MPFR_SET_MULT_SIGN(x, s) \
(MPFR_CHECK_SIGN(s), MPFR_SIGN(x) *= s)
/* Transform a sign to 1 or -1 */
diff --git a/round_prec.c b/round_prec.c
index 42376ac26..d938ffb84 100644
--- a/round_prec.c
+++ b/round_prec.c
@@ -72,12 +72,12 @@ mpfr_round_raw_generic(mp_limb_t *yp, mp_limb_t *xp, mp_prec_t xprec,
lomask = -1;
himask = -1;
}
- MPFR_ASSERTN(nw >= 1);
+ MPFR_ASSERTD(nw >= 1);
if (xprec <= yprec)
{ /* No rounding is necessary. */
/* if yp=xp, maybe an overlap: MPN_COPY_DECR is ok when src <= dst */
- MPFR_ASSERTN(nw >= xsize);
+ MPFR_ASSERTD(nw >= xsize);
if (inexp)
*inexp = 0;
if (flag)
@@ -100,7 +100,7 @@ mpfr_round_raw_generic(mp_limb_t *yp, mp_limb_t *xp, mp_prec_t xprec,
k = xsize - nw;
if (!rw)
k--;
- MPFR_ASSERTN(k >= 0);
+ MPFR_ASSERTD(k >= 0);
sb = xp[k] & lomask; /* First non-significant bits */
if (rnd_mode == GMP_RNDN)
{
@@ -172,7 +172,7 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode)
MPFR_SET_ALLOC_SIZE(x, nw); /* new number of allocated limbs */
}
- if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
+ if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) ))
{
if (MPFR_IS_NAN(x))
MPFR_RET_NAN;
@@ -185,7 +185,7 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode)
TMP_MARK(marker);
tmp = TMP_ALLOC (nw * BYTES_PER_MP_LIMB);
xp = MPFR_MANT(x);
- carry = mpfr_round_raw (tmp, xp, MPFR_PREC(x), MPFR_SIGN(x) < 0,
+ carry = mpfr_round_raw (tmp, xp, MPFR_PREC(x), MPFR_IS_NEG(x),
prec, rnd_mode, &inexact);
MPFR_PREC(x) = prec;
diff --git a/set.c b/set.c
index 83075e227..732235bbf 100644
--- a/set.c
+++ b/set.c
@@ -52,6 +52,16 @@ mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb)
/* Should never reach this code */
MPFR_ASSERTN(1);
}
+ else if (MPFR_LIKELY(MPFR_PREC(b) == MPFR_PREC(a)))
+ {
+ /* Same precision and b is not special:
+ * just copy the mantissa, and set the exponent and the sign */
+ MPFR_CLEAR_FLAGS(a);
+ MPN_COPY(MPFR_MANT(a), MPFR_MANT(b), MPFR_LIMB_SIZE(b));
+ MPFR_SET_SIGN(a, signb);
+ MPFR_SET_EXP(a, MPFR_GET_EXP(b));
+ MPFR_RET(0);
+ }
else
{
mp_limb_t *ap;
diff --git a/sub1.c b/sub1.c
index 6f4f900a4..d9814d4a1 100644
--- a/sub1.c
+++ b/sub1.c
@@ -49,11 +49,10 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
an = 1 + (MPFR_PREC(a) - 1) / BITS_PER_MP_LIMB;
sign = mpfr_cmp2 (b, c, &cancel);
- if (sign == 0)
+ if (MPFR_UNLIKELY(sign == 0))
{
if (rnd_mode == GMP_RNDD)
MPFR_SET_NEG(a);
-
else
MPFR_SET_POS(a);
MPFR_SET_ZERO(a);
@@ -80,7 +79,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
{
mpfr_srcptr t;
MPFR_CHANGE_SIGN(a);
- t = b; b = c; c = t;
+ t = b; b = c; c = t;
}
diff_exp = (mp_exp_unsigned_t) MPFR_GET_EXP (b) - MPFR_GET_EXP (c);