diff options
Diffstat (limited to 'Build/source/libs/gmp/gmp-src/gen-bases.c')
-rw-r--r-- | Build/source/libs/gmp/gmp-src/gen-bases.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/Build/source/libs/gmp/gmp-src/gen-bases.c b/Build/source/libs/gmp/gmp-src/gen-bases.c index 4d4b0db8ace..5f5e7ed3a97 100644 --- a/Build/source/libs/gmp/gmp-src/gen-bases.c +++ b/Build/source/libs/gmp/gmp-src/gen-bases.c @@ -1,7 +1,7 @@ /* Generate mp_bases data. -Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012 Free Software -Foundation, Inc. +Copyright 1991, 1993, 1994, 1996, 2000, 2002, 2004, 2011, 2012, +2015-2018 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -33,9 +33,11 @@ see https://www.gnu.org/licenses/. */ int chars_per_limb; +int big_base_ctz; mpz_t big_base; int normalization_steps; mpz_t big_base_inverted; +mpz_t big_base_binverted; mpz_t t; @@ -51,19 +53,27 @@ ulog2 (unsigned int x) } void +binvert (int numb_bits) +{ + mpz_t bbo; + + mpz_init_set (bbo, big_base); + big_base_ctz = mpz_make_odd (bbo); + mpz_invert_2exp (big_base_binverted, bbo, numb_bits); +} + +void generate (int limb_bits, int nail_bits, int base) { int numb_bits = limb_bits - nail_bits; mpz_set_ui (t, 1L); mpz_mul_2exp (t, t, numb_bits); - mpz_set_ui (big_base, 1L); + mpz_set_ui (big_base, (long) base); chars_per_limb = 0; - for (;;) + while (mpz_cmp (big_base, t) <= 0) { mpz_mul_ui (big_base, big_base, (long) base); - if (mpz_cmp (big_base, t) > 0) - break; chars_per_limb++; } @@ -74,9 +84,9 @@ generate (int limb_bits, int nail_bits, int base) mpz_set_ui (t, 1L); mpz_mul_2exp (t, t, 2*limb_bits - normalization_steps); mpz_tdiv_q (big_base_inverted, t, big_base); - mpz_set_ui (t, 1L); - mpz_mul_2exp (t, t, limb_bits); - mpz_sub (big_base_inverted, big_base_inverted, t); + mpz_clrbit (big_base_inverted, limb_bits); + + binvert (numb_bits); } void @@ -94,12 +104,16 @@ header (int limb_bits, int nail_bits) printf ("\n"); printf ("/* mp_bases[10] data, as literal values */\n"); printf ("#define MP_BASES_CHARS_PER_LIMB_10 %d\n", chars_per_limb); + printf ("#define MP_BASES_BIG_BASE_CTZ_10 %d\n", big_base_ctz); printf ("#define MP_BASES_BIG_BASE_10 CNST_LIMB(0x"); mpz_out_str (stdout, 16, big_base); printf (")\n"); printf ("#define MP_BASES_BIG_BASE_INVERTED_10 CNST_LIMB(0x"); mpz_out_str (stdout, 16, big_base_inverted); printf (")\n"); + printf ("#define MP_BASES_BIG_BASE_BINVERTED_10 CNST_LIMB(0x"); + mpz_out_str (stdout, 16, big_base_binverted); + printf (")\n"); printf ("#define MP_BASES_NORMALIZATION_STEPS_10 %d\n", normalization_steps); } @@ -113,13 +127,13 @@ 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 (t); + mpz_setbit (t, prec + EXTRA); mpz_init (t2); - mpz_init_set_ui (two, 2); - mpz_mul_2exp (two, two, prec+EXTRA); + mpz_init (two); + mpz_setbit (two, prec + EXTRA + 1); mpz_set_ui (r, 0); @@ -137,7 +151,7 @@ mp_2logb (mpz_t r, int bi, int prec) 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_swap (t, t2); /* new value acceptable */ } } @@ -161,7 +175,6 @@ table (int limb_bits, int nail_bits) printf ("/* This file generated by gen-bases.c - DO NOT EDIT. */\n"); printf ("\n"); - printf ("#include \"gmp.h\"\n"); printf ("#include \"gmp-impl.h\"\n"); printf ("\n"); printf ("#if GMP_NUMB_BITS != %d\n", numb_bits); @@ -217,6 +230,7 @@ main (int argc, char **argv) mpz_init (big_base); mpz_init (big_base_inverted); + mpz_init (big_base_binverted); mpz_init (t); if (argc != 4) |