diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-25 12:02:19 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-25 12:02:19 +0000 |
commit | 4fc658f4c030cdf8550bcf1a308df660ce617aae (patch) | |
tree | c125157a0790fc3733507da60ef550c31c861076 /src | |
parent | 6c399d91a25032e34a4609422757c83d7e7fcf07 (diff) | |
download | mpfr-4fc658f4c030cdf8550bcf1a308df660ce617aae.tar.gz |
Code clean-up:
* Simplified the definition of simple mp_limb_t constants: it is
better to avoid GMP internals when there is a standard way.
* Replaced the use of MP_LIMB_T_MAX by the new macro MPFR_LIMB_MAX.
* So, removed the now useless MP_LIMB_T_MAX and GMP_LIMB_HIGHBIT
definitions from "mpfr-gmp.h".
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9090 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src')
-rw-r--r-- | src/add1.c | 8 | ||||
-rw-r--r-- | src/get_f.c | 2 | ||||
-rw-r--r-- | src/mpfr-gmp.h | 4 | ||||
-rw-r--r-- | src/mpfr-impl.h | 26 | ||||
-rw-r--r-- | src/next.c | 4 | ||||
-rw-r--r-- | src/rint.c | 2 | ||||
-rw-r--r-- | src/round_p.c | 6 | ||||
-rw-r--r-- | src/setmax.c | 4 |
8 files changed, 20 insertions, 36 deletions
diff --git a/src/add1.c b/src/add1.c index f5b3b5154..6e7f21402 100644 --- a/src/add1.c +++ b/src/add1.c @@ -234,7 +234,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) MPFR_ASSERTD(fb != 0); if (fb > 0) { - if (bb != MP_LIMB_T_MAX) + if (bb != MPFR_LIMB_MAX) { fb = 1; /* c hasn't been taken into account ==> sticky bit != 0 */ @@ -249,7 +249,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) bb |= MPFR_LIMB_HIGHBIT; } fb = 1; - if (bb != MP_LIMB_T_MAX) + if (bb != MPFR_LIMB_MAX) goto rounding; } @@ -318,7 +318,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) } fb = bb != 0; - if (fb && bb != MP_LIMB_T_MAX) + if (fb && bb != MPFR_LIMB_MAX) goto rounding; } /* fb < 0 */ @@ -368,7 +368,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) fb = 1; goto rounding; } - if (fb && bb != MP_LIMB_T_MAX) + if (fb && bb != MPFR_LIMB_MAX) goto rounding; } /* while */ diff --git a/src/get_f.c b/src/get_f.c index 794d94d55..d5565d3ab 100644 --- a/src/get_f.c +++ b/src/get_f.c @@ -64,7 +64,7 @@ mpfr_get_f (mpf_ptr x, mpfr_srcptr y, mpfr_rnd_t rnd_mode) SIZ (x) = sx; xp = PTR (x); for (i = 0; i < sx; i++) - xp[i] = MP_LIMB_T_MAX; + xp[i] = MPFR_LIMB_MAX; if (MPFR_IS_POS (y)) return -1; diff --git a/src/mpfr-gmp.h b/src/mpfr-gmp.h index 9f26d2888..90cad1ecf 100644 --- a/src/mpfr-gmp.h +++ b/src/mpfr-gmp.h @@ -111,14 +111,10 @@ void *alloca (size_t); /* Define some macros */ -#define MP_LIMB_T_MAX (~(mp_limb_t)0) - #define ULONG_HIGHBIT (ULONG_MAX ^ ((unsigned long) ULONG_MAX >> 1)) #define UINT_HIGHBIT (UINT_MAX ^ ((unsigned) UINT_MAX >> 1)) #define USHRT_HIGHBIT ((unsigned short) (USHRT_MAX ^ ((unsigned short) USHRT_MAX >> 1))) -#define GMP_LIMB_HIGHBIT (MP_LIMB_T_MAX ^ (MP_LIMB_T_MAX >> 1)) - #if __GMP_MP_SIZE_T_INT #define MP_SIZE_T_MAX INT_MAX diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index 10005b175..1db245499 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -948,29 +948,17 @@ typedef intmax_t mpfr_eexp_t; ******************* Limb Macros ********************** ******************************************************/ - /* Definition of MPFR_LIMB_HIGHBIT */ -#if defined(GMP_LIMB_HIGHBIT) -# define MPFR_LIMB_HIGHBIT GMP_LIMB_HIGHBIT -#elif defined(MP_LIMB_T_HIGHBIT) -# define MPFR_LIMB_HIGHBIT MP_LIMB_T_HIGHBIT -#else -# error "Neither GMP_LIMB_HIGHBIT nor MP_LIMB_T_HIGHBIT defined in GMP" -#endif +/* Definition of simple mp_limb_t constants */ +#define MPFR_LIMB_ZERO ((mp_limb_t) 0) +#define MPFR_LIMB_ONE ((mp_limb_t) 1) +#define MPFR_LIMB_HIGHBIT (MPFR_LIMB_ONE << (GMP_NUMB_BITS - 1)) +#define MPFR_LIMB_MAX ((mp_limb_t) -1) /* Mask to get the Most Significant Bit of a limb */ -#define MPFR_LIMB_MSB(l) ((l)&MPFR_LIMB_HIGHBIT) - -/* Definition of MPFR_LIMB_ONE & MPFR_LIMB_ZERO */ -#ifdef CNST_LIMB -# define MPFR_LIMB_ONE CNST_LIMB(1) -# define MPFR_LIMB_ZERO CNST_LIMB(0) -#else -# define MPFR_LIMB_ONE ((mp_limb_t) 1L) -# define MPFR_LIMB_ZERO ((mp_limb_t) 0L) -#endif +#define MPFR_LIMB_MSB(l) ((l) & MPFR_LIMB_HIGHBIT) /* Mask for the low 's' bits of a limb */ -#define MPFR_LIMB_MASK(s) ((MPFR_LIMB_ONE<<(s))-MPFR_LIMB_ONE) +#define MPFR_LIMB_MASK(s) ((MPFR_LIMB_ONE << (s)) - MPFR_LIMB_ONE) diff --git a/src/next.c b/src/next.c index dbf86dc28..2806beccb 100644 --- a/src/next.c +++ b/src/next.c @@ -59,9 +59,9 @@ mpfr_nexttozero (mpfr_ptr x) { mp_size_t i; MPFR_SET_EXP (x, exp - 1); - xp[0] = MP_LIMB_T_MAX << sh; + xp[0] = MPFR_LIMB_MAX << sh; for (i = 1; i < xn; i++) - xp[i] = MP_LIMB_T_MAX; + xp[i] = MPFR_LIMB_MAX; } } } diff --git a/src/rint.c b/src/rint.c index cb87179b3..56eee0363 100644 --- a/src/rint.c +++ b/src/rint.c @@ -278,7 +278,7 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mpfr_rnd_t rnd_mode) } if (sh != 0) - rp[0] &= MP_LIMB_T_MAX << sh; + rp[0] &= MPFR_LIMB_MAX << sh; /* If u is a representable integer, there is no rounding. */ if (uflags == 0) diff --git a/src/round_p.c b/src/round_p.c index 5570ce0ad..00899caa0 100644 --- a/src/round_p.c +++ b/src/round_p.c @@ -77,7 +77,7 @@ mpfr_round_p (mp_limb_t *bp, mp_size_t bn, mpfr_exp_t err0, mpfr_prec_t prec) /* Check first limb */ bp += bn-1-k; tmp = *bp--; - mask = s == GMP_NUMB_BITS ? MP_LIMB_T_MAX : MPFR_LIMB_MASK (s); + mask = s == GMP_NUMB_BITS ? MPFR_LIMB_MAX : MPFR_LIMB_MASK (s); tmp &= mask; if (MPFR_LIKELY (n == 0)) @@ -106,14 +106,14 @@ mpfr_round_p (mp_limb_t *bp, mp_size_t bn, mpfr_exp_t err0, mpfr_prec_t prec) { /* Check if all (n-1) limbs are 11111111111111111 */ while (--n) - if (*bp-- != MP_LIMB_T_MAX) + if (*bp-- != MPFR_LIMB_MAX) return 1; /* Check if final error limb is 0 */ s = GMP_NUMB_BITS - err % GMP_NUMB_BITS; if (s == GMP_NUMB_BITS) return 0; tmp = *bp >> s; - return tmp != (MP_LIMB_T_MAX >> s); + return tmp != (MPFR_LIMB_MAX >> s); } else { diff --git a/src/setmax.c b/src/setmax.c index 5e3d1ed37..c2bd7856c 100644 --- a/src/setmax.c +++ b/src/setmax.c @@ -35,7 +35,7 @@ mpfr_setmax (mpfr_ptr x, mpfr_exp_t e) xn = MPFR_LIMB_SIZE (x); sh = (mpfr_prec_t) xn * GMP_NUMB_BITS - MPFR_PREC(x); xp = MPFR_MANT(x); - xp[0] = MP_LIMB_T_MAX << sh; + xp[0] = MPFR_LIMB_MAX << sh; for (i = 1; i < xn; i++) - xp[i] = MP_LIMB_T_MAX; + xp[i] = MPFR_LIMB_MAX; } |