summaryrefslogtreecommitdiff
path: root/gmp-impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'gmp-impl.h')
-rw-r--r--gmp-impl.h72
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. */