summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--gen-bases.c98
-rw-r--r--gmp-impl.h47
-rw-r--r--mpf/get_str.c11
-rw-r--r--mpf/out_str.c3
-rw-r--r--mpf/set_str.c9
-rw-r--r--mpn/generic/get_str.c7
-rw-r--r--mpn/generic/sizeinbase.c8
-rw-r--r--mpq/get_str.c10
-rw-r--r--mpz/inp_str.c8
-rw-r--r--mpz/out_str.c8
-rw-r--r--mpz/set_str.c8
-rw-r--r--printf/doprntf.c3
-rw-r--r--tune/speed.h7
-rw-r--r--tune/tuneup.c3
15 files changed, 182 insertions, 62 deletions
diff --git a/ChangeLog b/ChangeLog
index 7203df287..fc088f03e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-08-07 Torbjorn Granlund <tege@gmplib.org>
+
+ * gmp-impl.h (struct bases): Add log2b and logb2 field, remove
+ chars_per_limb_exactly field.
+ (DIGITS_IN_BASE_FROM_BITS): New.
+ (DIGITS_IN_BASE_PER_LIMB): New.
+ (LIMBS_PER_DIGIT_IN_BASE): New.
+ * gen-bases.c: Generate log2b and logb2 fields; do not generate
+ chars_per_limb_exactly field.
+ * mpf/get_str.c mpf/out_str.c mpf/set_str.c mpn/generic/get_str.c
+ mpn/generic/sizeinbase.c mpq/get_str.c mpz/inp_str.c mpz/out_str.c
+ mpz/set_str.c printf/doprntf.c tune/speed.h tune/tuneup.c:
+ Use new macros.
+
2011-08-03 Torbjorn Granlund <tege@gmplib.org>
* dumbmp.c (mpz_tdiv_qr): Correctly handle dividend value being equal
diff --git a/gen-bases.c b/gen-bases.c
index 31895e8b2..a467c19eb 100644
--- a/gen-bases.c
+++ b/gen-bases.c
@@ -1,7 +1,7 @@
/* Generate mp_bases data.
-Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004 Free Software Foundation,
-Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011 Free Software
+Foundation, Inc.
This file is part of the GNU MP Library.
@@ -24,7 +24,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
int chars_per_limb;
-double chars_per_bit_exactly;
mpz_t big_base;
int normalization_steps;
mpz_t big_base_inverted;
@@ -59,8 +58,6 @@ generate (int limb_bits, int nail_bits, int base)
chars_per_limb++;
}
- chars_per_bit_exactly = 0.69314718055994530942 / log ((double) base);
-
mpz_ui_pow_ui (big_base, (long) base, (long) chars_per_limb);
normalization_steps = limb_bits - mpz_sizeinbase (big_base, 2);
@@ -97,11 +94,61 @@ header (int limb_bits, int nail_bits)
printf ("#define MP_BASES_NORMALIZATION_STEPS_10 %d\n", normalization_steps);
}
+
+#define EXTRA 16
+
+/* Compute log(2)/log(b) as a fixnum. */
+void
+mp_2logb (mpz_t r, int bi, int prec)
+{
+ mpz_t t, t2, two, b;
+ int i;
+
+ mpz_init_set_ui (t, 1);
+ mpz_mul_2exp (t, t, prec+EXTRA);
+
+ mpz_init (t2);
+
+ mpz_init_set_ui (two, 2);
+ mpz_mul_2exp (two, two, prec+EXTRA);
+
+ mpz_set_ui (r, 0);
+
+ mpz_init_set_ui (b, bi);
+ mpz_mul_2exp (b, b, prec+EXTRA);
+
+ for (i = prec-1; i >= 0; i--)
+ {
+ mpz_mul_2exp (b, b, prec+EXTRA);
+ mpz_sqrt (b, b);
+
+ mpz_mul (t2, t, b);
+ mpz_tdiv_q_2exp (t2, t2, prec+EXTRA);
+
+ if (mpz_cmp (t2, two) < 0) /* not too large? */
+ {
+ mpz_setbit (r, i); /* set next less significant bit */
+ mpz_set (t, t2); /* new value acceptable */
+ }
+ }
+
+ mpz_clear (t);
+ mpz_clear (t2);
+ mpz_clear (two);
+ mpz_clear (b);
+}
+
void
table (int limb_bits, int nail_bits)
{
int numb_bits = limb_bits - nail_bits;
int base;
+ mpz_t r, t, logb2, log2b;
+
+ mpz_init (r);
+ mpz_init (t);
+ mpz_init (logb2);
+ mpz_init (log2b);
printf ("/* This file generated by gen-bases.c - DO NOT EDIT. */\n");
printf ("\n");
@@ -113,30 +160,45 @@ table (int limb_bits, int nail_bits)
printf ("#endif\n");
printf ("\n");
puts ("const struct bases mp_bases[257] =\n{");
- puts (" /* 0 */ { 0, 0.0, 0 },");
- puts (" /* 1 */ { 0, 1e37, 0 },");
+ puts (" /* 0 */ { 0, 0.0, 0, 0, 0, 0 },");
+ puts (" /* 1 */ { 0, 1e37, 0, 0, 0, 0 },");
for (base = 2; base <= 256; base++)
{
generate (limb_bits, nail_bits, base);
+ mp_2logb (r, base, limb_bits + 8);
+ mpz_tdiv_q_2exp (logb2, r, 8);
+ mpz_set_ui (t, 1);
+ mpz_mul_2exp (t, t, 2*limb_bits + 5);
+ mpz_sub_ui (t, t, 1);
+ mpz_add_ui (r, r, 1);
+ mpz_tdiv_q (log2b, t, r);
printf (" /* %3u */ { ", base);
if (POW2_P (base))
{
- printf ("%u, %.16f, 0x%x },\n",
- chars_per_limb, chars_per_bit_exactly, ulog2 (base) - 1);
- }
- else
- {
- printf ("%u, %.16f, CNST_LIMB(0x",
- chars_per_limb, chars_per_bit_exactly);
- mpz_out_str (stdout, 16, big_base);
- printf ("), CNST_LIMB(0x");
- mpz_out_str (stdout, 16, big_base_inverted);
- printf (") },\n");
+ mpz_set_ui (big_base, ulog2 (base) - 1);
+ mpz_set_ui (big_base_inverted, 0);
}
+
+ printf ("%u,", chars_per_limb);
+ printf (" CNST_LIMB(0x");
+ mpz_out_str (stdout, 16, logb2);
+ printf ("), CNST_LIMB(0x");
+ mpz_out_str (stdout, 16, log2b);
+ printf ("), CNST_LIMB(0x");
+ mpz_out_str (stdout, 16, big_base);
+ printf ("), CNST_LIMB(0x");
+ mpz_out_str (stdout, 16, big_base_inverted);
+ printf (") },\n");
}
puts ("};");
+
+ mpz_clear (r);
+ mpz_clear (t);
+ mpz_clear (logb2);
+ mpz_clear (log2b);
+
}
int
diff --git a/gmp-impl.h b/gmp-impl.h
index 035820e18..ab03ad83b 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -2594,7 +2594,10 @@ struct bases
int chars_per_limb;
/* log(2)/log(conversion_base) */
- double chars_per_bit_exactly;
+ mp_limb_t logb2;
+
+ /* log(conversion_base)/log(2) */
+ mp_limb_t log2b;
/* base**chars_per_limb, i.e. the biggest number that fits a word, built by
factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base),
@@ -2611,6 +2614,20 @@ struct bases
__GMP_DECLSPEC extern const struct bases mp_bases[257];
+/* Compute the number of digits in base for nbits bits, making sure the result
+ is never too small. The +1 in umul_ppmm makes the rounded-down log value to
+ be a rounded-up value. This make the full ph,,dummy product be rounded up,
+ but we chop the low half, meaning that we round down, but just once. The
+ return value is then incremented, to make sure it is never too small.
+ Caveat: The table value for base 2 will be all-bit-set, so things will break
+ in that case. Consider alternatives that allow all bases. */
+#define DIGITS_IN_BASE_FROM_BITS(res, nbits, b) \
+ do { \
+ mp_limb_t ph, dummy; \
+ umul_ppmm (ph, dummy, mp_bases[b].logb2 + 1, nbits); \
+ res = ph + 1; \
+ } while (0)
+
/* For power of 2 bases this is exact. For other bases the result is either
exact or one too big.
@@ -2644,8 +2661,9 @@ __GMP_DECLSPEC extern const struct bases mp_bases[257];
(result) = (__totbits + __lb_base - 1) / __lb_base; \
} \
else \
- (result) = (size_t) \
- (__totbits * mp_bases[base].chars_per_bit_exactly) + 1; \
+ { \
+ DIGITS_IN_BASE_FROM_BITS (result, __totbits, base); \
+ } \
} \
} while (0)
@@ -4031,6 +4049,24 @@ __GMP_DECLSPEC void mpn_set_str_compute_powtab __GMP_PROTO ((powers_t *, mp
__GMP_DECLSPEC extern mp_size_t __gmp_default_fp_limb_precision;
+/* Compute the number of base-b digits corresponding to nlimbs limbs, rounding
+ down. */
+#define DIGITS_IN_BASE_PER_LIMB(res, nlimbs, b) \
+ do { \
+ mp_limb_t ph, dummy; \
+ umul_ppmm (ph, dummy, mp_bases[b].logb2, GMP_NUMB_BITS * (nlimbs)); \
+ res = ph; \
+ } while (0)
+
+/* Compute the number of limbs corresponding to ndigits base-b digits, rounding
+ up. */
+#define LIMBS_PER_DIGIT_IN_BASE(res, ndigits, b) \
+ do { \
+ mp_limb_t ph, dummy; \
+ umul_ppmm (ph, dummy, mp_bases[base].log2b, ndigits); \
+ res = 8 * ph / GMP_NUMB_BITS + 2; \
+ } while (0)
+
/* Set n to the number of significant digits an mpf of the given _mp_prec
field, in the given base. This is a rounded up value, designed to ensure
@@ -4046,9 +4082,10 @@ __GMP_DECLSPEC extern mp_size_t __gmp_default_fp_limb_precision;
#define MPF_SIGNIFICANT_DIGITS(n, base, prec) \
do { \
+ size_t rawn; \
ASSERT (base >= 2 && base < numberof (mp_bases)); \
- (n) = 2 + (size_t) ((((size_t) (prec) - 1) * GMP_NUMB_BITS) \
- * mp_bases[(base)].chars_per_bit_exactly); \
+ DIGITS_IN_BASE_PER_LIMB (rawn, (prec) - 1, base); \
+ n = rawn + 2; \
} while (0)
diff --git a/mpf/get_str.c b/mpf/get_str.c
index cdadbacc3..d0cba5936 100644
--- a/mpf/get_str.c
+++ b/mpf/get_str.c
@@ -4,8 +4,8 @@
example, the number 3.1416 would be returned as "31416" in DIGIT_PTR and
1 in EXP.
-Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005, 2006 Free
-Software Foundation, Inc.
+Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005, 2006, 2011
+Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -178,8 +178,7 @@ mpf_get_str (char *dbuf, mp_exp_t *exp, int base, size_t n_digits, mpf_srcptr u)
conversion.) */
tstr = (unsigned char *) TMP_ALLOC (n_digits + 2 * GMP_LIMB_BITS + 3);
- n_limbs_needed = 2 + (mp_size_t)
- (n_digits / (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly));
+ LIMBS_PER_DIGIT_IN_BASE (n_limbs_needed, n_digits, base);
if (ue <= n_limbs_needed)
{
@@ -188,7 +187,7 @@ mpf_get_str (char *dbuf, mp_exp_t *exp, int base, size_t n_digits, mpf_srcptr u)
unsigned long e;
n_more_limbs_needed = n_limbs_needed - ue;
- e = (unsigned long) n_more_limbs_needed * (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly);
+ DIGITS_IN_BASE_PER_LIMB (e, n_more_limbs_needed, base);
if (un > n_limbs_needed)
{
@@ -225,7 +224,7 @@ mpf_get_str (char *dbuf, mp_exp_t *exp, int base, size_t n_digits, mpf_srcptr u)
mp_ptr dummyp, xp;
n_less_limbs_needed = ue - n_limbs_needed;
- e = (unsigned long) n_less_limbs_needed * (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly);
+ DIGITS_IN_BASE_PER_LIMB (e, n_less_limbs_needed, base);
if (un > n_limbs_needed)
{
diff --git a/mpf/out_str.c b/mpf/out_str.c
index afccdbb03..3e34a5341 100644
--- a/mpf/out_str.c
+++ b/mpf/out_str.c
@@ -2,7 +2,7 @@
the float OP to STREAM in base BASE. Return the number of characters
written, or 0 if an error occurred.
-Copyright 1996, 1997, 2001, 2002, 2005 Free Software Foundation, Inc.
+Copyright 1996, 1997, 2001, 2002, 2005, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -36,6 +36,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
size_t
diff --git a/mpf/set_str.c b/mpf/set_str.c
index 214ecceb2..644b201d8 100644
--- a/mpf/set_str.c
+++ b/mpf/set_str.c
@@ -3,7 +3,7 @@
of STRING is used to figure out the base.
Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005, 2007,
-2008 Free Software Foundation, Inc.
+2008, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -47,6 +47,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp-impl.h"
#include "longlong.h"
+
#define digit_value_tab __gmp_digit_value_tab
/* Compute base^exp and return the most significant prec limbs in rp[].
@@ -243,14 +244,12 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
/* This breaks things like 0.000...0001. To safely ignore superfluous
digits, we need to skip over leading zeros. */
/* Just consider the relevant leading digits of the mantissa. */
- n_chars_needed = 2 + (size_t)
- (((size_t) prec * GMP_NUMB_BITS) * mp_bases[base].chars_per_bit_exactly);
+ LIMBS_PER_DIGIT_IN_BASE (n_chars_needed, prec, base);
if (str_size > n_chars_needed)
str_size = n_chars_needed;
#endif
- ma = 2 + (mp_size_t)
- (str_size / (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly));
+ LIMBS_PER_DIGIT_IN_BASE (ma, str_size, base);
mp = TMP_ALLOC_LIMBS (ma);
mn = mpn_set_str (mp, (unsigned char *) begs, str_size, base);
diff --git a/mpn/generic/get_str.c b/mpn/generic/get_str.c
index ac4fb52a9..61273d1ad 100644
--- a/mpn/generic/get_str.c
+++ b/mpn/generic/get_str.c
@@ -8,7 +8,7 @@
GNU MP RELEASE.
Copyright 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, 2004, 2006, 2007,
-2008 Free Software Foundation, Inc.
+2008, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -439,9 +439,12 @@ mpn_get_str (unsigned char *str, int base, mp_ptr up, mp_size_t un)
mp_size_t n_pows, xn, pn, exptab[GMP_LIMB_BITS], bexp;
mp_limb_t cy;
mp_size_t shift;
+ size_t ndig;
+
+ DIGITS_IN_BASE_PER_LIMB (ndig, un, base);
+ xn = 1 + ndig / mp_bases[base].chars_per_limb; /* FIXME: scalar integer division */
n_pows = 0;
- xn = 1 + un*(mp_bases[base].chars_per_bit_exactly*GMP_NUMB_BITS)/mp_bases[base].chars_per_limb;
for (pn = xn; pn != 1; pn = (pn + 1) >> 1)
{
exptab[n_pows] = pn;
diff --git a/mpn/generic/sizeinbase.c b/mpn/generic/sizeinbase.c
index 303359a5c..4f8f80f56 100644
--- a/mpn/generic/sizeinbase.c
+++ b/mpn/generic/sizeinbase.c
@@ -4,7 +4,7 @@
CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
FUTURE GNU MP RELEASES.
-Copyright 1991, 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1995, 2001, 2002, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -54,5 +54,9 @@ mpn_sizeinbase (mp_srcptr xp, mp_size_t xsize, int base)
return (totbits + lb_base - 1) / lb_base;
}
else
- return (size_t) (totbits * mp_bases[base].chars_per_bit_exactly) + 1;
+ {
+ size_t ndigits;
+ DIGITS_IN_BASE_FROM_BITS (ndigits, totbits, base);
+ return ndigits;
+ }
}
diff --git a/mpq/get_str.c b/mpq/get_str.c
index 074c48c9f..d85914f94 100644
--- a/mpq/get_str.c
+++ b/mpq/get_str.c
@@ -1,6 +1,6 @@
/* mpq_get_str -- mpq to string conversion.
-Copyright 2001, 2002, 2006 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2006, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -21,6 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <string.h>
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
char *
mpq_get_str (char *str, int base, mpq_srcptr q)
@@ -36,10 +37,9 @@ mpq_get_str (char *str, int base, mpq_srcptr q)
/* This is an overestimate since we don't bother checking how much of
the high limbs of num and den are used. +2 for rounding up the
chars per bit of num and den. +3 for sign, slash and '\0'. */
- str_alloc = ((size_t) ((ABS (q->_mp_num._mp_size) + q->_mp_den._mp_size)
- * GMP_LIMB_BITS
- * mp_bases[ABS(base)].chars_per_bit_exactly))
- + 5;
+ DIGITS_IN_BASE_PER_LIMB (str_alloc, ABS (q->_mp_num._mp_size) + q->_mp_den._mp_size, ABS(base));
+ str_alloc += 6;
+
str = (char *) (*__gmp_allocate_func) (str_alloc);
}
diff --git a/mpz/inp_str.c b/mpz/inp_str.c
index b0ebb971f..a933eac55 100644
--- a/mpz/inp_str.c
+++ b/mpz/inp_str.c
@@ -5,8 +5,8 @@
REST ARE INTERNALS AND ARE ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE
CHANGES OR DISAPPEAR COMPLETELY IN FUTURE GNU MP RELEASES.
-Copyright 1991, 1993, 1994, 1996, 1998, 2000, 2001, 2002, 2003 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1998, 2000, 2001, 2002, 2003, 2011 Free
+Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -27,6 +27,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <ctype.h>
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
#define digit_value_tab __gmp_digit_value_tab
@@ -150,8 +151,7 @@ mpz_inp_str_nowhite (mpz_ptr x, FILE *stream, int base, int c, size_t nread)
}
else
{
- xsize = 2 + (mp_size_t)
- (str_size / (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly));
+ LIMBS_PER_DIGIT_IN_BASE (xsize, str_size, base);
MPZ_REALLOC (x, xsize);
/* Convert the byte array in base BASE to our bignum format. */
diff --git a/mpz/out_str.c b/mpz/out_str.c
index a3b1b6615..fbb30d191 100644
--- a/mpz/out_str.c
+++ b/mpz/out_str.c
@@ -1,7 +1,8 @@
/* mpz_out_str(stream, base, integer) -- Output to STREAM the multi prec.
integer INTEGER in base BASE.
-Copyright 1991, 1993, 1994, 1996, 2001, 2005 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 2001, 2005, 2011 Free Software Foundation,
+Inc.
This file is part of the GNU MP Library.
@@ -21,6 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
size_t
mpz_out_str (FILE *stream, int base, mpz_srcptr x)
@@ -75,8 +77,8 @@ mpz_out_str (FILE *stream, int base, mpz_srcptr x)
}
TMP_MARK;
- str_size = ((size_t) (x_size * GMP_LIMB_BITS
- * mp_bases[base].chars_per_bit_exactly)) + 3;
+
+ DIGITS_IN_BASE_PER_LIMB (str_size, x_size, base);
str = (unsigned char *) TMP_ALLOC (str_size);
/* Move the number to convert into temporary space, since mpn_get_str
diff --git a/mpz/set_str.c b/mpz/set_str.c
index cdea7a248..51f3ce4d6 100644
--- a/mpz/set_str.c
+++ b/mpz/set_str.c
@@ -4,8 +4,8 @@
the base in the C standard way, i.e. 0xhh...h means base 16,
0oo...o means base 8, otherwise assume base 10.
-Copyright 1991, 1993, 1994, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005
-Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005,
+2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -26,6 +26,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <ctype.h>
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
#define digit_value_tab __gmp_digit_value_tab
@@ -121,8 +122,7 @@ mpz_set_str (mpz_ptr x, const char *str, int base)
str_size = s - begs;
- xsize = 2 + (mp_size_t)
- (str_size / (GMP_NUMB_BITS * mp_bases[base].chars_per_bit_exactly));
+ LIMBS_PER_DIGIT_IN_BASE (xsize, str_size, base);
MPZ_REALLOC (x, xsize);
/* Convert the byte array in base BASE to our bignum format. */
diff --git a/printf/doprntf.c b/printf/doprntf.c
index 537dce5b6..6ddb58590 100644
--- a/printf/doprntf.c
+++ b/printf/doprntf.c
@@ -4,7 +4,7 @@
CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
FUTURE GNU MP RELEASES.
-Copyright 2001, 2002 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2011 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -36,6 +36,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
/* change this to "#define TRACE(x) x" for diagnostics */
diff --git a/tune/speed.h b/tune/speed.h
index 1ed35266a..48a420668 100644
--- a/tune/speed.h
+++ b/tune/speed.h
@@ -1,7 +1,7 @@
/* Header for speed and threshold things.
-Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2008, 2009, 2010 Free
-Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2008, 2009, 2010, 2011
+Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -2974,8 +2974,7 @@ int speed_routine_count_zeros_setup
for (i = 0; i < s->size; i++) \
xp[i] = s->xp[i] % base; \
\
- wn = ((mp_size_t) (s->size / mp_bases[base].chars_per_bit_exactly)) \
- / GMP_LIMB_BITS + 2; \
+ LIMBS_PER_DIGIT_IN_BASE (wn, s->size, base); \
SPEED_TMP_ALLOC_LIMBS (wp, wn, s->align_wp); \
\
/* use this during development to check wn is big enough */ \
diff --git a/tune/tuneup.c b/tune/tuneup.c
index 8a82e06b5..88ee2158b 100644
--- a/tune/tuneup.c
+++ b/tune/tuneup.c
@@ -2344,8 +2344,7 @@ speed_mpn_pre_set_str (struct speed_params *s)
for (i = 0; i < s->size; i++)
str[i] = s->xp[i] % base;
- wn = ((mp_size_t) (s->size / mp_bases[base].chars_per_bit_exactly))
- / GMP_LIMB_BITS + 2;
+ LIMBS_PER_DIGIT_IN_BASE (wn, s->size, base);
SPEED_TMP_ALLOC_LIMBS (wp, wn, s->align_wp);
/* use this during development to check wn is big enough */