summaryrefslogtreecommitdiff
path: root/Build/source/libs/mpfr/mpfr-src/src/set_uj.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/mpfr/mpfr-src/src/set_uj.c')
-rw-r--r--Build/source/libs/mpfr/mpfr-src/src/set_uj.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/Build/source/libs/mpfr/mpfr-src/src/set_uj.c b/Build/source/libs/mpfr/mpfr-src/src/set_uj.c
index 6049e638741..fafc101c281 100644
--- a/Build/source/libs/mpfr/mpfr-src/src/set_uj.c
+++ b/Build/source/libs/mpfr/mpfr-src/src/set_uj.c
@@ -21,7 +21,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
-# include "config.h" /* for a build within gmp */
+# include "config.h"
#endif
#define MPFR_NEED_LONGLONG_H
@@ -30,6 +30,8 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#ifdef _MPFR_H_HAVE_INTMAX_T
+#define uintmaxpml (sizeof(uintmax_t) / sizeof(mp_limb_t))
+
int
mpfr_set_uj (mpfr_t x, uintmax_t j, mpfr_rnd_t rnd)
{
@@ -39,10 +41,10 @@ mpfr_set_uj (mpfr_t x, uintmax_t j, mpfr_rnd_t rnd)
int
mpfr_set_uj_2exp (mpfr_t x, uintmax_t j, intmax_t e, mpfr_rnd_t rnd)
{
- unsigned int cnt, i;
- mp_size_t k, len;
+ int cnt;
+ mp_size_t i, k;
mp_limb_t limb;
- mp_limb_t yp[sizeof(uintmax_t) / sizeof(mp_limb_t)];
+ mp_limb_t yp[uintmaxpml];
mpfr_t y;
unsigned long uintmax_bit_size = sizeof(uintmax_t) * CHAR_BIT;
unsigned long bpml = GMP_NUMB_BITS % uintmax_bit_size;
@@ -57,13 +59,20 @@ mpfr_set_uj_2exp (mpfr_t x, uintmax_t j, intmax_t e, mpfr_rnd_t rnd)
MPFR_ASSERTN (sizeof(uintmax_t) % sizeof(mp_limb_t) == 0);
- /* Create an auxillary var */
+ /* Create an auxiliary var */
MPFR_TMP_INIT1 (yp, y, uintmax_bit_size);
- k = numberof (yp);
- if (k == 1)
- limb = yp[0] = j;
+ /* The compiler will optimize the code by removing the useless branch. */
+ k = uintmaxpml;
+ if (uintmaxpml == 1)
+ {
+ limb = j;
+ count_leading_zeros(cnt, limb);
+ /* Normalize the most significant limb */
+ yp[0] = limb << cnt;
+ }
else
{
+ mp_size_t len;
/* Note: either GMP_NUMB_BITS = uintmax_bit_size, then k = 1 the
shift j >>= bpml is never done, or GMP_NUMB_BITS < uintmax_bit_size
and bpml = GMP_NUMB_BITS. */
@@ -78,23 +87,22 @@ mpfr_set_uj_2exp (mpfr_t x, uintmax_t j, intmax_t e, mpfr_rnd_t rnd)
}
while (limb == 0);
k++;
- }
- count_leading_zeros(cnt, limb);
- len = numberof (yp) - k;
-
- /* Normalize it: len = number of last 0 limb, k number of non-zero limbs */
- if (MPFR_LIKELY(cnt))
- mpn_lshift (yp+len, yp, k, cnt); /* Normalize the High Limb*/
- else if (len != 0)
- MPN_COPY_DECR (yp+len, yp, k); /* Must use DECR */
- if (len != 0)
- /* Note: when numberof(yp)==1, len is constant and null, so the compiler
- can optimize out this code. */
- {
- if (len == 1)
- yp[0] = (mp_limb_t) 0;
- else
- MPN_ZERO (yp, len); /* Zeroing the last limbs */
+ len = numberof (yp) - k;
+ count_leading_zeros(cnt, limb);
+
+ /* Normalize it: len = number of last zero limbs,
+ k = number of previous limbs */
+ if (MPFR_LIKELY (cnt != 0))
+ mpn_lshift (yp+len, yp, k, cnt); /* Normalize the high limb */
+ else if (len != 0)
+ mpn_copyd (yp+len, yp, k); /* Must use copyd */
+ if (len != 0)
+ {
+ if (len == 1)
+ yp[0] = MPFR_LIMB_ZERO;
+ else
+ MPN_ZERO (yp, len); /* Zero the last limbs */
+ }
}
e += k * GMP_NUMB_BITS - cnt; /* Update Expo */
MPFR_ASSERTD (MPFR_LIMB_MSB(yp[numberof (yp) - 1]) != 0);