diff options
author | Kevin Ryde <user42@zip.com.au> | 2002-01-30 00:51:54 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2002-01-30 00:51:54 +0100 |
commit | 5af21e78d7553b8b4ea45657a4fc46ba8b0af75e (patch) | |
tree | 391e0489c83725231042b6124a03e703f51638ac /gmp-impl.h | |
parent | 550425af039e79ef13c905cca85717c344c0d76e (diff) | |
download | gmp-5af21e78d7553b8b4ea45657a4fc46ba8b0af75e.tar.gz |
* gmp-impl.h (GMP_NUMB_MASK, GMP_NAIL_MASK, GMP_NUMB_HIGHBIT,
ASSERT_MPN, ASSERT_MP_LIMB_T): New macros.
* mpn/generic/fib2_ui.c: Use GMP_NUMB_BITS, simplify the data
generator program, share __gmp_fib_table initializers between bit
sizes, cope with bit sizes other than those specifically setup.
* gmp-impl.h (FIB_TABLE_LIMIT, FIB_TABLE_LUCNUM_LIMIT): Corresponding
rearrangement of conditionals.
Diffstat (limited to 'gmp-impl.h')
-rw-r--r-- | gmp-impl.h | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/gmp-impl.h b/gmp-impl.h index 98cb34695..8afb2c6d0 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -395,6 +395,11 @@ void __gmp_tmp_debug_free _PROTO ((const char *, int, int, #define SHRT_HIGHBIT SHRT_MIN +#define GMP_NUMB_MASK (MP_LIMB_T_MAX >> GMP_NAIL_BITS) +#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) +#define GMP_NUMB_HIGHBIT (CNST_LIMB(1) << (GMP_NUMB_BITS-1)) + + /* Swap macros. */ #define MP_LIMB_T_SWAP(x, y) \ @@ -1017,33 +1022,33 @@ void mpn_copyd _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); This data generated by code at the end of mpn/generic/fib2_ui.c. */ +extern const mp_limb_t __gmp_fib_table[]; #define FIB_TABLE(n) (__gmp_fib_table[(n)+1]) -#if BITS_PER_MP_LIMB == 4 -extern const mp_limb_t __gmp_fib_table[]; -#define FIB_TABLE_LIMIT 7 -#define FIB_TABLE_LUCNUM_LIMIT 5 -#endif -#if BITS_PER_MP_LIMB == 8 -extern const mp_limb_t __gmp_fib_table[]; -#define FIB_TABLE_LIMIT 13 -#define FIB_TABLE_LUCNUM_LIMIT 11 -#endif -#if BITS_PER_MP_LIMB == 16 -extern const mp_limb_t __gmp_fib_table[]; -#define FIB_TABLE_LIMIT 24 -#define FIB_TABLE_LUCNUM_LIMIT 23 -#endif -#if BITS_PER_MP_LIMB == 32 -extern const mp_limb_t __gmp_fib_table[]; -#define FIB_TABLE_LIMIT 47 -#define FIB_TABLE_LUCNUM_LIMIT 46 -#endif -#if BITS_PER_MP_LIMB == 64 -extern const mp_limb_t __gmp_fib_table[]; +#if GMP_NUMB_BITS >= 64 #define FIB_TABLE_LIMIT 93 #define FIB_TABLE_LUCNUM_LIMIT 92 -#endif +#else +#if GMP_NUMB_BITS >= 32 +#define FIB_TABLE_LIMIT 47 +#define FIB_TABLE_LUCNUM_LIMIT 46 +#else +#if GMP_NUMB_BITS >= 16 +#define FIB_TABLE_LIMIT 24 +#define FIB_TABLE_LUCNUM_LIMIT 23 +#else +#if GMP_NUMB_BITS >= 8 +#define FIB_TABLE_LIMIT 13 +#define FIB_TABLE_LUCNUM_LIMIT 11 +#else +#if GMP_NUMB_BITS >= 4 +#define FIB_TABLE_LIMIT 7 +#define FIB_TABLE_LUCNUM_LIMIT 5 +#endif /* 4 */ +#endif /* 8 */ +#endif /* 16 */ +#endif /* 32 */ +#endif /* 64 */ /* For a threshold between algorithms A and B, size>=thresh is where B @@ -1284,6 +1289,27 @@ void __gmp_assert_fail _PROTO ((const char *filename, int linenum, #define ASSERT_MPQ_CANONICAL(q) do {} while (0) #endif +/* Check that the nail parts are zero. */ +#if WANT_ASSERT +#define ASSERT_MP_LIMB_T(limb) \ + do { \ + mp_limb_t __nail = (limb) & GMP_NAIL_MASK; \ + ASSERT (__nail == 0); \ + } while (0) +#define ASSERT_MPN(ptr, size) \ + do { \ + if (GMP_NAIL_BITS != 0) \ + { \ + mp_size_t __i; \ + for (__i = 0; __i < (size); __i++) \ + ASSERT_MP_LIMB_T ((ptr)[__i]); \ + } \ + } while (0) +#else +#define ASSERT_MP_LIMB_T(limb) do {} while (0) +#define ASSERT_MPN(ptr, size) do {} while (0) +#endif + /* Assert that an mpn region {ptr,size} is zero, or non-zero. size==0 is allowed, and in that case {ptr,size} considered to be zero. */ |