From: John Marino Date: Sat, 12 May 2012 07:22:30 +0000 (+0200) Subject: Upgrade GMP from 5.0.2 to 5.0.5 on the vendor branch X-Git-Tag: v3.2.0~957^2 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/d2d4b6594b5a0b8d5bb8af2281dc28c69247e98b Upgrade GMP from 5.0.2 to 5.0.5 on the vendor branch --- diff --git a/contrib/gmp/gmp-impl.h b/contrib/gmp/gmp-impl.h index d6336569c2..b424f9dd0a 100644 --- a/contrib/gmp/gmp-impl.h +++ b/contrib/gmp/gmp-impl.h @@ -4,7 +4,8 @@ BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES. Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, -2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, +Inc. This file is part of the GNU MP Library. @@ -64,7 +65,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #define DECL_copyi(name) \ DECL_copyd (name) #define DECL_divexact_1(name) \ - __GMP_DECLSPEC mp_limb_t name __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) + __GMP_DECLSPEC void name __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) #define DECL_divexact_by3c(name) \ __GMP_DECLSPEC mp_limb_t name __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) #define DECL_divrem_1(name) \ @@ -478,6 +479,7 @@ __GMP_DECLSPEC void __gmp_tmp_debug_free __GMP_PROTO ((const char *, int, int, #define UNLIKELY(cond) __GMP_UNLIKELY(cond) #define ABS(x) ((x) >= 0 ? (x) : -(x)) +#define ABS_CAST(T,x) ((x) >= 0 ? (T)(x) : -((T)((x) + 1) - 1)) #undef MIN #define MIN(l,o) ((l) < (o) ? (l) : (o)) #undef MAX @@ -4519,12 +4521,17 @@ extern struct fft_table_nk mpn_fft_table3[2][FFT_TABLE3_SIZE]; #define mpn_toom2_sqr_itch(an) \ (2 * ((an) + GMP_NUMB_BITS)) -/* Can probably be trimmed to 2 an + O(log an). */ +/* toom33/toom3: Scratch need is 5an/2 + 10k, k is the recursion depth. + We use 3an + C, so that we can use a smaller constant. + */ #define mpn_toom33_mul_itch(an, bn) \ - ((5 * (an) >> 1) + GMP_NUMB_BITS) + (3 * (an) + GMP_NUMB_BITS) #define mpn_toom3_sqr_itch(an) \ - ((5 * (an) >> 1) + GMP_NUMB_BITS) + (3 * (an) + GMP_NUMB_BITS) +/* toom33/toom3: Scratch need is 8an/3 + 13k, k is the recursion depth. + We use 3an + C, so that we can use a smaller constant. + */ #define mpn_toom44_mul_itch(an, bn) \ (3 * (an) + GMP_NUMB_BITS) #define mpn_toom4_sqr_itch(an) \ diff --git a/contrib/gmp/longlong.h b/contrib/gmp/longlong.h index 130dc85129..8cac79da9c 100644 --- a/contrib/gmp/longlong.h +++ b/contrib/gmp/longlong.h @@ -1,7 +1,7 @@ /* longlong.h -- definitions for mixed size 32/64 bit arithmetic. Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2002, 2003, -2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. +2004, 2005, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. This file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -654,27 +654,172 @@ extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype)); #endif /* hppa */ #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32 -#define smul_ppmm(xh, xl, m0, m1) \ +#if defined (__zarch__) || defined (HAVE_HOST_CPU_s390_zarch) +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ + do { \ +/* if (__builtin_constant_p (bl)) \ + __asm__ ("alfi\t%1,%o5\n\talcr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" (ah), "r" (bh), "%1" (al), "n" (bl) __CLOBBER_CC);\ + else \ +*/ __asm__ ("alr\t%1,%5\n\talcr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" (ah), "r" (bh), "%1" (al), "r" (bl)__CLOBBER_CC); \ + } while (0) +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ + do { \ +/* if (__builtin_constant_p (bl)) \ + __asm__ ("slfi\t%1,%o5\n\tslbr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" (ah), "r" (bh), "1" (al), "n" (bl) __CLOBBER_CC); \ + else \ +*/ __asm__ ("slr\t%1,%5\n\tslbr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" (ah), "r" (bh), "1" (al), "r" (bl) __CLOBBER_CC); \ + } while (0) +#if __GMP_GNUC_PREREQ (4,5) +#define umul_ppmm(xh, xl, m0, m1) \ + do { \ + union {UDItype __ll; \ + struct {USItype __h, __l;} __i; \ + } __x; \ + __x.__ll = (UDItype) (m0) * (UDItype) (m1); \ + (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ + } while (0) +#else +#if 0 +/* FIXME: this fails if gcc knows about the 64-bit registers. Use only + with a new enough processor pretending we have 32-bit registers. */ +#define umul_ppmm(xh, xl, m0, m1) \ + do { \ + union {UDItype __ll; \ + struct {USItype __h, __l;} __i; \ + } __x; \ + __asm__ ("mlr\t%0,%2" \ + : "=r" (__x.__ll) \ + : "%0" (m0), "r" (m1)); \ + (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ + } while (0) +#else +#define umul_ppmm(xh, xl, m0, m1) \ + do { \ + /* When we have 64-bit regs and gcc is aware of that, we cannot simply use + DImode for the product, since that would be allocated to a single 64-bit + register, whereas mlr uses the low 32-bits of an even-odd register pair. + */ \ + register USItype __r0 __asm__ ("0"); \ + register USItype __r1 __asm__ ("1") = (m0); \ + __asm__ ("mlr\t%0,%3" \ + : "=r" (__r0), "=r" (__r1) \ + : "r" (__r1), "r" (m1)); \ + (xh) = __r0; (xl) = __r1; \ + } while (0) +#endif /* if 0 */ +#endif +#if 0 +/* FIXME: this fails if gcc knows about the 64-bit registers. Use only + with a new enough processor pretending we have 32-bit registers. */ +#define udiv_qrnnd(q, r, n1, n0, d) \ + do { \ + union {UDItype __ll; \ + struct {USItype __h, __l;} __i; \ + } __x; \ + __x.__i.__h = n1; __x.__i.__l = n0; \ + __asm__ ("dlr\t%0,%2" \ + : "=r" (__x.__ll) \ + : "0" (__x.__ll), "r" (d)); \ + (q) = __x.__i.__l; (r) = __x.__i.__h; \ + } while (0) +#else +#define udiv_qrnnd(q, r, n1, n0, d) \ + do { \ + register USItype __r0 __asm__ ("0") = (n1); \ + register USItype __r1 __asm__ ("1") = (n0); \ + __asm__ ("dlr\t%0,%4" \ + : "=r" (__r0), "=r" (__r1) \ + : "r" (__r0), "r" (__r1), "r" (d)); \ + (q) = __r1; (r) = __r0; \ + } while (0) +#endif /* if 0 */ +#else /* if __zarch__ */ +/* FIXME: this fails if gcc knows about the 64-bit registers. */ +#define smul_ppmm(xh, xl, m0, m1) \ do { \ union {DItype __ll; \ struct {USItype __h, __l;} __i; \ } __x; \ - __asm__ ("lr %N0,%1\n\tmr %0,%2" \ - : "=&r" (__x.__ll) \ - : "r" (m0), "r" (m1)); \ + __asm__ ("mr\t%0,%2" \ + : "=r" (__x.__ll) \ + : "%0" (m0), "r" (m1)); \ (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ } while (0) -#define sdiv_qrnnd(q, r, n1, n0, d) \ +/* FIXME: this fails if gcc knows about the 64-bit registers. */ +#define sdiv_qrnnd(q, r, n1, n0, d) \ do { \ union {DItype __ll; \ struct {USItype __h, __l;} __i; \ } __x; \ __x.__i.__h = n1; __x.__i.__l = n0; \ - __asm__ ("dr %0,%2" \ + __asm__ ("dr\t%0,%2" \ : "=r" (__x.__ll) \ : "0" (__x.__ll), "r" (d)); \ (q) = __x.__i.__l; (r) = __x.__i.__h; \ } while (0) +#endif /* if __zarch__ */ +#endif + +#if defined (__s390x__) && W_TYPE_SIZE == 64 +/* We need to cast operands with register constraints, otherwise their types + will be assumed to be SImode by gcc. For these machines, such operations + will insert a value into the low 32 bits, and leave the high 32 bits with + garbage. */ +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ + do { \ + __asm__ ("algr\t%1,%5\n\talcgr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)), \ + "%1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC); \ + } while (0) +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ + do { \ + __asm__ ("slgr\t%1,%5\n\tslbgr\t%0,%3" \ + : "=r" (sh), "=&r" (sl) \ + : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)), \ + "1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC); \ + } while (0) +#define umul_ppmm(xh, xl, m0, m1) \ + do { \ + union {unsigned int __attribute__ ((mode(TI))) __ll; \ + struct {UDItype __h, __l;} __i; \ + } __x; \ + __asm__ ("mlgr\t%0,%2" \ + : "=r" (__x.__ll) \ + : "%0" ((UDItype)(m0)), "r" ((UDItype)(m1))); \ + (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ + } while (0) +#define udiv_qrnnd(q, r, n1, n0, d) \ + do { \ + union {unsigned int __attribute__ ((mode(TI))) __ll; \ + struct {UDItype __h, __l;} __i; \ + } __x; \ + __x.__i.__h = n1; __x.__i.__l = n0; \ + __asm__ ("dlgr\t%0,%2" \ + : "=r" (__x.__ll) \ + : "0" (__x.__ll), "r" ((UDItype)(d))); \ + (q) = __x.__i.__l; (r) = __x.__i.__h; \ + } while (0) +#if 0 /* FIXME: Enable for z10 (?) */ +#define count_leading_zeros(cnt, x) \ + do { \ + union {unsigned int __attribute__ ((mode(TI))) __ll; \ + struct {UDItype __h, __l;} __i; \ + } __clr_cnt; \ + __asm__ ("flogr\t%0,%1" \ + : "=r" (__clr_cnt.__ll) \ + : "r" (x) __CLOBBER_CC); \ + (cnt) = __clr_cnt.__i.__h; \ + } while (0) +#endif #endif #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32 @@ -1271,7 +1416,7 @@ extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype)); #define count_leading_zeros(count, x) \ __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x)) #define COUNT_LEADING_ZEROS_0 64 -#if __GMP_GNUC_PREREQ (4,4) +#if 0 && __GMP_GNUC_PREREQ (4,4) /* Disable, this results in libcalls! */ #define umul_ppmm(w1, w0, u, v) \ do { \ typedef unsigned int __ll_UTItype __attribute__((mode(TI))); \ @@ -1869,6 +2014,7 @@ extern UWtype mpn_udiv_qrnnd_r _PROTO ((UWtype, UWtype, UWtype, UWtype *)); (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \ (r) = __r; \ } while (0) +__GMP_DECLSPEC UWtype __MPN(udiv_w_sdiv) (UWtype *, UWtype, UWtype, UWtype); #endif /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */ diff --git a/contrib/gmp/mp_get_fns.c b/contrib/gmp/mp_get_fns.c index c8c9f9997c..8d7c69f4f6 100644 --- a/contrib/gmp/mp_get_fns.c +++ b/contrib/gmp/mp_get_fns.c @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ void mp_get_memory_functions (void *(**alloc_func) (size_t), void *(**realloc_func) (void *, size_t, size_t), - void (**free_func) (void *, size_t)) + void (**free_func) (void *, size_t)) __GMP_NOTHROW { if (alloc_func != NULL) *alloc_func = __gmp_allocate_func; diff --git a/contrib/gmp/mp_set_fns.c b/contrib/gmp/mp_set_fns.c index f5402c6fd4..3d2aaf3eca 100644 --- a/contrib/gmp/mp_set_fns.c +++ b/contrib/gmp/mp_set_fns.c @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ void mp_set_memory_functions (void *(*alloc_func) (size_t), void *(*realloc_func) (void *, size_t, size_t), - void (*free_func) (void *, size_t)) + void (*free_func) (void *, size_t)) __GMP_NOTHROW { if (alloc_func == 0) alloc_func = __gmp_default_allocate; diff --git a/contrib/gmp/mpf/cmp.c b/contrib/gmp/mpf/cmp.c index fc29309bcd..9a3c7ae74c 100644 --- a/contrib/gmp/mpf/cmp.c +++ b/contrib/gmp/mpf/cmp.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -mpf_cmp (mpf_srcptr u, mpf_srcptr v) +mpf_cmp (mpf_srcptr u, mpf_srcptr v) __GMP_NOTHROW { mp_srcptr up, vp; mp_size_t usize, vsize; diff --git a/contrib/gmp/mpf/cmp_si.c b/contrib/gmp/mpf/cmp_si.c index 541ac36e31..9b364a3873 100644 --- a/contrib/gmp/mpf/cmp_si.c +++ b/contrib/gmp/mpf/cmp_si.c @@ -22,13 +22,14 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -mpf_cmp_si (mpf_srcptr u, long int vval) +mpf_cmp_si (mpf_srcptr u, long int vval) __GMP_NOTHROW { mp_srcptr up; mp_size_t usize; mp_exp_t uexp; mp_limb_t ulimb; int usign; + unsigned long abs_vval; uexp = u->_mp_exp; usize = u->_mp_size; @@ -55,13 +56,13 @@ mpf_cmp_si (mpf_srcptr u, long int vval) usign = usize >= 0 ? 1 : -1; usize = ABS (usize); - vval = ABS (vval); + abs_vval = ABS_CAST (unsigned long, vval); /* 2. Are the exponents different (V's exponent == 1)? */ #if GMP_NAIL_BITS != 0 - if (uexp > 1 + ((unsigned long) vval > GMP_NUMB_MAX)) + if (uexp > 1 + (abs_vval > GMP_NUMB_MAX)) return usign; - if (uexp < 1 + ((unsigned long) vval > GMP_NUMB_MAX)) + if (uexp < 1 + (abs_vval > GMP_NUMB_MAX)) return -usign; #else if (uexp > 1) @@ -85,9 +86,9 @@ mpf_cmp_si (mpf_srcptr u, long int vval) usize--; /* 3. Compare the most significant mantissa limb with V. */ - if (ulimb > (unsigned long) vval) + if (ulimb > abs_vval) return usign; - else if (ulimb < (unsigned long) vval) + else if (ulimb < abs_vval) return -usign; /* Ignore zeroes at the low end of U. */ diff --git a/contrib/gmp/mpf/cmp_ui.c b/contrib/gmp/mpf/cmp_ui.c index 33f418c731..5e5ed00eff 100644 --- a/contrib/gmp/mpf/cmp_ui.c +++ b/contrib/gmp/mpf/cmp_ui.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -mpf_cmp_ui (mpf_srcptr u, unsigned long int vval) +mpf_cmp_ui (mpf_srcptr u, unsigned long int vval) __GMP_NOTHROW { mp_srcptr up; mp_size_t usize; diff --git a/contrib/gmp/mpf/fits_s.h b/contrib/gmp/mpf/fits_s.h index 6306930a0c..f10f2c7418 100644 --- a/contrib/gmp/mpf/fits_s.h +++ b/contrib/gmp/mpf/fits_s.h @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* Notice this is equivalent to mpz_set_f + mpz_fits_s*_p. */ int -FUNCTION (mpf_srcptr f) +FUNCTION (mpf_srcptr f) __GMP_NOTHROW { mp_size_t fs, fn; mp_srcptr fp; diff --git a/contrib/gmp/mpf/fits_u.h b/contrib/gmp/mpf/fits_u.h index 724f06c352..4503f037f6 100644 --- a/contrib/gmp/mpf/fits_u.h +++ b/contrib/gmp/mpf/fits_u.h @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* Notice this is equivalent to mpz_set_f + mpz_fits_u*_p. */ int -FUNCTION (mpf_srcptr f) +FUNCTION (mpf_srcptr f) __GMP_NOTHROW { mp_size_t fn; mp_srcptr fp; diff --git a/contrib/gmp/mpf/get_dfl_prec.c b/contrib/gmp/mpf/get_dfl_prec.c index e48a3a1f40..14606f0379 100644 --- a/contrib/gmp/mpf/get_dfl_prec.c +++ b/contrib/gmp/mpf/get_dfl_prec.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ mp_bitcnt_t -mpf_get_default_prec (void) +mpf_get_default_prec (void) __GMP_NOTHROW { return __GMPF_PREC_TO_BITS (__gmp_default_fp_limb_precision); } diff --git a/contrib/gmp/mpf/get_prc.c b/contrib/gmp/mpf/get_prc.c index c413582b91..ca7a056291 100644 --- a/contrib/gmp/mpf/get_prc.c +++ b/contrib/gmp/mpf/get_prc.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" mp_bitcnt_t -mpf_get_prec (mpf_srcptr x) +mpf_get_prec (mpf_srcptr x) __GMP_NOTHROW { return __GMPF_PREC_TO_BITS (x->_mp_prec); } diff --git a/contrib/gmp/mpf/get_si.c b/contrib/gmp/mpf/get_si.c index a0beb2c037..e3d18e89fa 100644 --- a/contrib/gmp/mpf/get_si.c +++ b/contrib/gmp/mpf/get_si.c @@ -40,7 +40,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ -0x80000000 instead of the desired 0. */ long -mpf_get_si (mpf_srcptr f) +mpf_get_si (mpf_srcptr f) __GMP_NOTHROW { mp_exp_t exp; mp_size_t size, abs_size; @@ -72,5 +72,5 @@ mpf_get_si (mpf_srcptr f) return fl & LONG_MAX; else /* this form necessary to correctly handle -0x80..00 */ - return ~ ((fl - 1) & LONG_MAX); + return -1 - (long) ((fl - 1) & LONG_MAX); } diff --git a/contrib/gmp/mpf/get_ui.c b/contrib/gmp/mpf/get_ui.c index 0acaf94a87..0d909d4ab8 100644 --- a/contrib/gmp/mpf/get_ui.c +++ b/contrib/gmp/mpf/get_ui.c @@ -61,7 +61,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ tested first we ensure MP_EXP_T_MIN doesn't reach exp>1. */ unsigned long -mpf_get_ui (mpf_srcptr f) +mpf_get_ui (mpf_srcptr f) __GMP_NOTHROW { mp_size_t size; mp_exp_t exp; diff --git a/contrib/gmp/mpf/int_p.c b/contrib/gmp/mpf/int_p.c index d43dcf8136..3168314665 100644 --- a/contrib/gmp/mpf/int_p.c +++ b/contrib/gmp/mpf/int_p.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int -mpf_integer_p (mpf_srcptr f) +mpf_integer_p (mpf_srcptr f) __GMP_NOTHROW { mp_srcptr ptr; mp_exp_t exp; diff --git a/contrib/gmp/mpf/iset_si.c b/contrib/gmp/mpf/iset_si.c index be5490807d..a689d0d05a 100644 --- a/contrib/gmp/mpf/iset_si.c +++ b/contrib/gmp/mpf/iset_si.c @@ -31,7 +31,7 @@ mpf_init_set_si (mpf_ptr r, long int val) r->_mp_prec = prec; r->_mp_d = (mp_ptr) (*__gmp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val); + vl = (mp_limb_t) ABS_CAST (unsigned long int, val); r->_mp_d[0] = vl & GMP_NUMB_MASK; size = vl != 0; diff --git a/contrib/gmp/mpf/set_dfl_prec.c b/contrib/gmp/mpf/set_dfl_prec.c index df52488609..c209dd9976 100644 --- a/contrib/gmp/mpf/set_dfl_prec.c +++ b/contrib/gmp/mpf/set_dfl_prec.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ mp_size_t __gmp_default_fp_limb_precision = __GMPF_BITS_TO_PREC (53); void -mpf_set_default_prec (mp_bitcnt_t prec_in_bits) +mpf_set_default_prec (mp_bitcnt_t prec_in_bits) __GMP_NOTHROW { __gmp_default_fp_limb_precision = __GMPF_BITS_TO_PREC (prec_in_bits); } diff --git a/contrib/gmp/mpf/set_prc_raw.c b/contrib/gmp/mpf/set_prc_raw.c index c42e7a0dc2..0473b5d137 100644 --- a/contrib/gmp/mpf/set_prc_raw.c +++ b/contrib/gmp/mpf/set_prc_raw.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" void -mpf_set_prec_raw (mpf_ptr x, mp_bitcnt_t prec_in_bits) +mpf_set_prec_raw (mpf_ptr x, mp_bitcnt_t prec_in_bits) __GMP_NOTHROW { x->_mp_prec = __GMPF_BITS_TO_PREC (prec_in_bits); } diff --git a/contrib/gmp/mpf/set_si.c b/contrib/gmp/mpf/set_si.c index 9c5605b5e2..aa7b4ee84a 100644 --- a/contrib/gmp/mpf/set_si.c +++ b/contrib/gmp/mpf/set_si.c @@ -27,7 +27,7 @@ mpf_set_si (mpf_ptr dest, long val) mp_size_t size; mp_limb_t vl; - vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val); + vl = (mp_limb_t) ABS_CAST (unsigned long int, val); dest->_mp_d[0] = vl & GMP_NUMB_MASK; size = vl != 0; diff --git a/contrib/gmp/mpf/size.c b/contrib/gmp/mpf/size.c index 514873e9b4..34dfa5f759 100644 --- a/contrib/gmp/mpf/size.c +++ b/contrib/gmp/mpf/size.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" size_t -mpf_size (mpf_srcptr f) +mpf_size (mpf_srcptr f) __GMP_NOTHROW { return __GMP_ABS (f->_mp_size); } diff --git a/contrib/gmp/mpf/sub.c b/contrib/gmp/mpf/sub.c index 845bdbc255..575b412960 100644 --- a/contrib/gmp/mpf/sub.c +++ b/contrib/gmp/mpf/sub.c @@ -1,6 +1,6 @@ /* mpf_sub -- Subtract two floats. -Copyright 1993, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free +Copyright 1993, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2011 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -273,19 +273,19 @@ general_case: vsize = prec - ediff; } - /* Allocate temp space for the result. Allocate - just vsize + ediff later??? */ - tp = TMP_ALLOC_LIMBS (prec); - if (ediff >= prec) { /* V completely cancelled. */ - if (tp != up) + if (rp != up) MPN_COPY (rp, up, usize); rsize = usize; } else { + /* Allocate temp space for the result. Allocate + just vsize + ediff later??? */ + tp = TMP_ALLOC_LIMBS (prec); + /* Locate the least significant non-zero limb in (the needed parts of) U and V, to simplify the code below. */ for (;;) diff --git a/contrib/gmp/mpf/swap.c b/contrib/gmp/mpf/swap.c index 61c99f5cf1..26934f641f 100644 --- a/contrib/gmp/mpf/swap.c +++ b/contrib/gmp/mpf/swap.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" void -mpf_swap (mpf_ptr u, mpf_ptr v) +mpf_swap (mpf_ptr u, mpf_ptr v) __GMP_NOTHROW { mp_ptr up, vp; mp_size_t usize, vsize; diff --git a/contrib/gmp/mpn/generic/dcpi1_bdiv_q.c b/contrib/gmp/mpn/generic/dcpi1_bdiv_q.c index 8c4a22a3ef..2bc85efc4e 100644 --- a/contrib/gmp/mpn/generic/dcpi1_bdiv_q.c +++ b/contrib/gmp/mpn/generic/dcpi1_bdiv_q.c @@ -7,7 +7,7 @@ SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE. -Copyright 2006, 2007, 2009, 2010 Free Software Foundation, Inc. +Copyright 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -28,7 +28,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" - mp_size_t mpn_dcpi1_bdiv_q_n_itch (mp_size_t n) { @@ -130,7 +129,7 @@ mpn_dcpi1_bdiv_q (mp_ptr qp, qn = nn - qn; while (qn > dn) { - mpn_sub_1 (np + dn, np + dn, qn, cy); + mpn_sub_1 (np + dn, np + dn, qn - dn, cy); cy = mpn_dcpi1_bdiv_qr_n (qp, np, dp, dn, dinv, tp); qp += dn; np += dn; diff --git a/contrib/gmp/mpn/generic/gcdext.c b/contrib/gmp/mpn/generic/gcdext.c index d7078b3928..06e6c138a7 100644 --- a/contrib/gmp/mpn/generic/gcdext.c +++ b/contrib/gmp/mpn/generic/gcdext.c @@ -386,7 +386,10 @@ mpn_gcdext (mp_ptr gp, mp_ptr up, mp_size_t *usizep, MPN_COPY (gp, ap, n); MPN_CMP (c, u0, u1, un); - ASSERT (c != 0); + /* c == 0 can happen only when A = (2k+1) G, B = 2 G. And in + this case we choose the cofactor + 1, corresponding to G = A + - k B, rather than -1, corresponding to G = - A + (k+1) B. */ + ASSERT (c != 0 || (un == 1 && u0[0] == 1 && u1[0] == 1)); if (c < 0) { MPN_NORMALIZE (u0, un); diff --git a/contrib/gmp/mpn/generic/gcdext_subdiv_step.c b/contrib/gmp/mpn/generic/gcdext_subdiv_step.c index d54b3bdee1..21a3a3b22e 100644 --- a/contrib/gmp/mpn/generic/gcdext_subdiv_step.c +++ b/contrib/gmp/mpn/generic/gcdext_subdiv_step.c @@ -181,15 +181,17 @@ mpn_gcdext_subdiv_step (mp_ptr gp, mp_size_t *gn, mp_ptr up, mp_size_t *usizep, if (qn + u0n > un) { - ASSERT_NOCARRY (mpn_add (u1, tp, qn + u0n, u1, un)); + mp_size_t u1n = un; un = qn + u0n; - un -= (u1[un-1] == 0); + un -= (tp[un-1] == 0); + u1[un] = mpn_add (u1, tp, un, u1, u1n); } else { u1[un] = mpn_add (u1, u1, un, tp, qn + u0n); - un += (u1[un] > 0); } + + un += (u1[un] > 0); } *unp = un; diff --git a/contrib/gmp/mpn/generic/hgcd.c b/contrib/gmp/mpn/generic/hgcd.c index d25fdaa0ca..709f880eb2 100644 --- a/contrib/gmp/mpn/generic/hgcd.c +++ b/contrib/gmp/mpn/generic/hgcd.c @@ -115,8 +115,8 @@ hgcd_matrix_update_q (struct hgcd_matrix *M, mp_srcptr qp, mp_size_t qn, if (c[0] | c[1]) { M->n = n + qn + 1; - M->p[0][col][n-1] = c[0]; - M->p[1][col][n-1] = c[1]; + M->p[0][col][M->n - 1] = c[0]; + M->p[1][col][M->n - 1] = c[1]; } else { diff --git a/contrib/gmp/mpn/generic/popham.c b/contrib/gmp/mpn/generic/popham.c index b9d0bf3356..d81ad9dd98 100644 --- a/contrib/gmp/mpn/generic/popham.c +++ b/contrib/gmp/mpn/generic/popham.c @@ -1,6 +1,6 @@ /* mpn_popcount, mpn_hamdist -- mpn bit population count/hamming distance. -Copyright 1994, 1996, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. +Copyright 1994, 1996, 2000, 2001, 2002, 2005, 2011 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -35,7 +35,7 @@ FNAME (mp_srcptr up, #if OPERATION_hamdist mp_srcptr vp, #endif - mp_size_t n) + mp_size_t n) __GMP_NOTHROW { mp_bitcnt_t result = 0; mp_limb_t p0, p1, p2, p3, x, p01, p23; diff --git a/contrib/gmp/mpn/generic/powm_sec.c b/contrib/gmp/mpn/generic/powm_sec.c index 315ae6e5e0..196030866b 100644 --- a/contrib/gmp/mpn/generic/powm_sec.c +++ b/contrib/gmp/mpn/generic/powm_sec.c @@ -7,7 +7,7 @@ SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. -Copyright 2007, 2008, 2009 Free Software Foundation, Inc. +Copyright 2007, 2008, 2009, 2011, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -82,7 +82,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #if ! HAVE_NATIVE_mpn_sqr_basecase /* The limit of the generic code is SQR_TOOM2_THRESHOLD. */ -#define SQR_BASECASE_MAX SQR_TOOM2_THRESHOLD +#define SQR_BASECASE_LIM SQR_TOOM2_THRESHOLD #endif #if HAVE_NATIVE_mpn_sqr_basecase @@ -91,12 +91,19 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ mpn_sqr_basecase, it comes from SQR_TOOM2_THRESHOLD_MAX in the assembly file. An assembly mpn_sqr_basecase that does not define it, should allow any size. */ -#define SQR_BASECASE_MAX SQR_TOOM2_THRESHOLD +#define SQR_BASECASE_LIM SQR_TOOM2_THRESHOLD #endif #endif -#ifndef SQR_BASECASE_MAX -/* If SQR_BASECASE_MAX is now not defined, use mpn_sqr_basecase for any operand +#ifdef WANT_FAT_BINARY +/* For fat builds, we use SQR_TOOM2_THRESHOLD which will expand to a read from + __gmpn_cpuvec. Perhaps any possible sqr_basecase.asm allow any size, and we + limit the use unnecessarily. We cannot tell, so play it safe. FIXME. */ +#define SQR_BASECASE_LIM SQR_TOOM2_THRESHOLD +#endif + +#ifndef SQR_BASECASE_LIM +/* If SQR_BASECASE_LIM is now not defined, use mpn_sqr_basecase for any operand size. */ #define mpn_local_sqr(rp,up,n,tp) mpn_sqr_basecase(rp,up,n) #else @@ -110,7 +117,7 @@ mpn_local_sqr (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_ptr tp) ASSERT (n >= 1); ASSERT (! MPN_OVERLAP_P (rp, 2*n, up, n)); - if (n < SQR_BASECASE_MAX) + if (BELOW_THRESHOLD (n, SQR_BASECASE_LIM)) { mpn_sqr_basecase (rp, up, n); return; @@ -125,8 +132,6 @@ mpn_local_sqr (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_ptr tp) if (n > 1) { mp_limb_t cy; - TMP_DECL; - TMP_MARK; cy = mpn_mul_1 (tp, up + 1, n - 1, up[0]); tp[n - 1] = cy; @@ -148,8 +153,6 @@ mpn_local_sqr (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_ptr tp) #endif rp[2 * n - 1] += cy; } - - TMP_FREE; } } #endif @@ -196,15 +199,12 @@ static void redcify (mp_ptr rp, mp_srcptr up, mp_size_t un, mp_srcptr mp, mp_size_t n, mp_ptr tp) { mp_ptr qp; - TMP_DECL; - TMP_MARK; qp = tp + un + n; MPN_ZERO (tp, n); MPN_COPY (tp + n, up, un); mpn_tdiv_qr (qp, rp, 0L, tp, un + n, mp, n); - TMP_FREE; } /* rp[n-1..0] = bp[bn-1..0] ^ ep[en-1..0] mod mp[n-1..0] @@ -224,13 +224,10 @@ mpn_powm_sec (mp_ptr rp, mp_srcptr bp, mp_size_t bn, mp_ptr pp, this_pp; long i; int cnd; - TMP_DECL; ASSERT (en > 1 || (en == 1 && ep[0] > 0)); ASSERT (n >= 1 && ((mp[0] & 1) != 0)); - TMP_MARK; - count_leading_zeros (cnt, ep[en - 1]); ebi = (mp_bitcnt_t) en * GMP_LIMB_BITS - cnt; @@ -261,7 +258,11 @@ mpn_powm_sec (mp_ptr rp, mp_srcptr bp, mp_size_t bn, else ebi -= windowsize; +#if WANT_CACHE_SECURITY + mpn_tabselect (rp, pp, n, 1 << windowsize, expbits); +#else MPN_COPY (rp, pp + n * expbits, n); +#endif while (ebi != 0) { @@ -297,7 +298,6 @@ mpn_powm_sec (mp_ptr rp, mp_srcptr bp, mp_size_t bn, mpn_redc_1_sec (rp, tp, mp, n, minv); cnd = mpn_sub_n (tp, rp, mp, n); /* we need just retval */ mpn_subcnd_n (rp, rp, mp, n, !cnd); - TMP_FREE; } #if ! HAVE_NATIVE_mpn_tabselect diff --git a/contrib/gmp/mpn/generic/toom63_mul.c b/contrib/gmp/mpn/generic/toom63_mul.c index f4bb3deeac..9c21457e9b 100644 --- a/contrib/gmp/mpn/generic/toom63_mul.c +++ b/contrib/gmp/mpn/generic/toom63_mul.c @@ -6,7 +6,7 @@ SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. -Copyright 2009 Free Software Foundation, Inc. +Copyright 2009, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -105,8 +105,8 @@ mpn_toom63_mul (mp_ptr pp, ASSERT (0 < s && s <= n); ASSERT (0 < t && t <= n); - /* WARNING! it assumes s+t>n */ - ASSERT ( s + t > n ); + /* WARNING! it assumes s+t>=n */ + ASSERT ( s + t >= n ); ASSERT ( s + t > 4); /* WARNING! it assumes n>1 */ ASSERT ( n > 2); diff --git a/contrib/gmp/mpn/generic/toom_interpolate_16pts.c b/contrib/gmp/mpn/generic/toom_interpolate_16pts.c index 3b26bc165d..36ed15dab7 100644 --- a/contrib/gmp/mpn/generic/toom_interpolate_16pts.c +++ b/contrib/gmp/mpn/generic/toom_interpolate_16pts.c @@ -6,7 +6,7 @@ SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. -Copyright 2009, 2010 Free Software Foundation, Inc. +Copyright 2009, 2010, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -299,11 +299,15 @@ mpn_toom_interpolate_16pts (mp_ptr pp, mp_ptr r1, mp_ptr r3, mp_ptr r5, mp_ptr r DO_mpn_subrsh(r5, n3p1, r0, spt, 4, wsi); cy = DO_mpn_sublsh_n (r1 + BIT_CORRECTION, r0, spt, 42 - CORRECTION_BITS, wsi); - MPN_DECR_U (r1 + spt + BIT_CORRECTION, n3p1 - spt - BIT_CORRECTION, cy); #if BIT_CORRECTION + cy = mpn_sub_1 (r1 + spt + BIT_CORRECTION, r1 + spt + BIT_CORRECTION, + n3p1 - spt - BIT_CORRECTION, cy); + ASSERT (BIT_CORRECTION > 0 || cy == 0); /* FIXME: assumes r7[n3p1] is writable (it is if r5 follows). */ cy = r7[n3p1]; r7[n3p1] = 0x80; +#else + MPN_DECR_U (r1 + spt + BIT_CORRECTION, n3p1 - spt - BIT_CORRECTION, cy); #endif DO_mpn_subrsh(r7, n3p1 + BIT_CORRECTION, r0, spt, 6, wsi); #if BIT_CORRECTION diff --git a/contrib/gmp/mpn/generic/toom_interpolate_8pts.c b/contrib/gmp/mpn/generic/toom_interpolate_8pts.c index 9667f51037..b11af25c2b 100644 --- a/contrib/gmp/mpn/generic/toom_interpolate_8pts.c +++ b/contrib/gmp/mpn/generic/toom_interpolate_8pts.c @@ -188,5 +188,8 @@ mpn_toom_interpolate_8pts (mp_ptr pp, mp_size_t n, cy = mpn_add_1 (pp + 6*n, r3 + n, n, pp[6*n]); MPN_INCR_U (r3 + 2*n, n + 1, cy); cy = r3[3*n] + mpn_add_n (pp + 7*n, pp + 7*n, r3 + 2*n, n); - MPN_INCR_U (pp + 8*n, spt - n, cy); + if (LIKELY(spt != n)) + MPN_INCR_U (pp + 8*n, spt - n, cy); + else + ASSERT (cy == 0); } diff --git a/contrib/gmp/mpn/generic/udiv_w_sdiv.c b/contrib/gmp/mpn/generic/udiv_w_sdiv.c index c01f958474..f1353c6bdd 100644 --- a/contrib/gmp/mpn/generic/udiv_w_sdiv.c +++ b/contrib/gmp/mpn/generic/udiv_w_sdiv.c @@ -9,7 +9,7 @@ GNU MP RELEASE. -Copyright 1992, 1994, 1996, 2000 Free Software Foundation, Inc. +Copyright 1992, 1994, 1996, 2000, 2011, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -31,8 +31,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "longlong.h" mp_limb_t -mpn_udiv_w_sdiv (rp, a1, a0, d) - mp_limb_t *rp, a1, a0, d; +mpn_udiv_w_sdiv (mp_limb_t *rp, mp_limb_t a1, mp_limb_t a0, mp_limb_t d) { mp_limb_t q, r; mp_limb_t c0, c1, b1; @@ -116,12 +115,12 @@ mpn_udiv_w_sdiv (rp, a1, a0, d) { /* Hence a1 = d - 1 = 2*b1 - 1 */ if (a0 >= -d) { - q = -1; + q = -CNST_LIMB(1); r = a0 + d; } else { - q = -2; + q = -CNST_LIMB(2); r = a0 + 2*d; } } diff --git a/contrib/gmp/mpq/equal.c b/contrib/gmp/mpq/equal.c index e5c5f8e5e8..36f7d372d9 100644 --- a/contrib/gmp/mpq/equal.c +++ b/contrib/gmp/mpq/equal.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -mpq_equal (mpq_srcptr op1, mpq_srcptr op2) +mpq_equal (mpq_srcptr op1, mpq_srcptr op2) __GMP_NOTHROW { mp_size_t num1_size, num2_size, den1_size, den2_size, i; mp_srcptr num1_ptr, num2_ptr, den1_ptr, den2_ptr; diff --git a/contrib/gmp/mpq/set_si.c b/contrib/gmp/mpq/set_si.c index 8fe5540a29..2d2bd4aa04 100644 --- a/contrib/gmp/mpq/set_si.c +++ b/contrib/gmp/mpq/set_si.c @@ -35,7 +35,7 @@ mpq_set_si (MP_RAT *dest, signed long int num, unsigned long int den) return; } - abs_num = ABS (num); + abs_num = ABS_CAST (unsigned long, num); if (num == 0) { diff --git a/contrib/gmp/mpq/swap.c b/contrib/gmp/mpq/swap.c index 507e7d51d2..e1d96cc47f 100644 --- a/contrib/gmp/mpq/swap.c +++ b/contrib/gmp/mpq/swap.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" void -mpq_swap (mpq_ptr u, mpq_ptr v) +mpq_swap (mpq_ptr u, mpq_ptr v) __GMP_NOTHROW { mp_ptr up, vp; mp_size_t usize, vsize; diff --git a/contrib/gmp/mpz/cmp.c b/contrib/gmp/mpz/cmp.c index 20056c682a..a6d9d38893 100644 --- a/contrib/gmp/mpz/cmp.c +++ b/contrib/gmp/mpz/cmp.c @@ -28,7 +28,7 @@ int #ifdef BERKELEY_MP mcmp (mpz_srcptr u, mpz_srcptr v) #else -mpz_cmp (mpz_srcptr u, mpz_srcptr v) +mpz_cmp (mpz_srcptr u, mpz_srcptr v) __GMP_NOTHROW #endif { mp_size_t usize, vsize, dsize, asize; diff --git a/contrib/gmp/mpz/cmp_si.c b/contrib/gmp/mpz/cmp_si.c index f53932e139..1919bd33ed 100644 --- a/contrib/gmp/mpz/cmp_si.c +++ b/contrib/gmp/mpz/cmp_si.c @@ -23,11 +23,12 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -_mpz_cmp_si (mpz_srcptr u, signed long int v_digit) +_mpz_cmp_si (mpz_srcptr u, signed long int v_digit) __GMP_NOTHROW { mp_size_t usize = u->_mp_size; mp_size_t vsize; mp_limb_t u_digit; + unsigned long int absv_digit = (unsigned long int) v_digit; #if GMP_NAIL_BITS != 0 /* FIXME. This isn't very pretty. */ @@ -45,7 +46,7 @@ _mpz_cmp_si (mpz_srcptr u, signed long int v_digit) else if (v_digit < 0) { vsize = -1; - v_digit = -v_digit; + absv_digit = -absv_digit; } if (usize != vsize) @@ -56,10 +57,10 @@ _mpz_cmp_si (mpz_srcptr u, signed long int v_digit) u_digit = u->_mp_d[0]; - if (u_digit == (mp_limb_t) (unsigned long) v_digit) + if (u_digit == (mp_limb_t) absv_digit) return 0; - if (u_digit > (mp_limb_t) (unsigned long) v_digit) + if (u_digit > (mp_limb_t) absv_digit) return usize; else return -usize; diff --git a/contrib/gmp/mpz/cmp_ui.c b/contrib/gmp/mpz/cmp_ui.c index e5702c159c..f9f27ba494 100644 --- a/contrib/gmp/mpz/cmp_ui.c +++ b/contrib/gmp/mpz/cmp_ui.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -_mpz_cmp_ui (mpz_srcptr u, unsigned long int v_digit) +_mpz_cmp_ui (mpz_srcptr u, unsigned long int v_digit) __GMP_NOTHROW { mp_ptr up; mp_size_t un; diff --git a/contrib/gmp/mpz/cmpabs.c b/contrib/gmp/mpz/cmpabs.c index ec3e98e5b3..f7bbcd7c77 100644 --- a/contrib/gmp/mpz/cmpabs.c +++ b/contrib/gmp/mpz/cmpabs.c @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int -mpz_cmpabs (mpz_srcptr u, mpz_srcptr v) +mpz_cmpabs (mpz_srcptr u, mpz_srcptr v) __GMP_NOTHROW { mp_size_t usize, vsize, dsize; mp_srcptr up, vp; diff --git a/contrib/gmp/mpz/cmpabs_ui.c b/contrib/gmp/mpz/cmpabs_ui.c index 881692de62..f8df4b8c42 100644 --- a/contrib/gmp/mpz/cmpabs_ui.c +++ b/contrib/gmp/mpz/cmpabs_ui.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" int -mpz_cmpabs_ui (mpz_srcptr u, unsigned long int v_digit) +mpz_cmpabs_ui (mpz_srcptr u, unsigned long int v_digit) __GMP_NOTHROW { mp_ptr up; mp_size_t un; diff --git a/contrib/gmp/mpz/cong_2exp.c b/contrib/gmp/mpz/cong_2exp.c index f9a7f153ee..bf3ae54cc0 100644 --- a/contrib/gmp/mpz/cong_2exp.c +++ b/contrib/gmp/mpz/cong_2exp.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int -mpz_congruent_2exp_p (mpz_srcptr a, mpz_srcptr c, mp_bitcnt_t d) +mpz_congruent_2exp_p (mpz_srcptr a, mpz_srcptr c, mp_bitcnt_t d) __GMP_NOTHROW { mp_size_t i, dlimbs; unsigned dbits; diff --git a/contrib/gmp/mpz/divis_2exp.c b/contrib/gmp/mpz/divis_2exp.c index f01aafeee1..814037fdf2 100644 --- a/contrib/gmp/mpz/divis_2exp.c +++ b/contrib/gmp/mpz/divis_2exp.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int -mpz_divisible_2exp_p (mpz_srcptr a, mp_bitcnt_t d) +mpz_divisible_2exp_p (mpz_srcptr a, mp_bitcnt_t d) __GMP_NOTHROW { mp_size_t i, dlimbs; unsigned dbits; diff --git a/contrib/gmp/mpz/fits_s.h b/contrib/gmp/mpz/fits_s.h index a91e82189f..d690c08df1 100644 --- a/contrib/gmp/mpz/fits_s.h +++ b/contrib/gmp/mpz/fits_s.h @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int -FUNCTION (mpz_srcptr z) +FUNCTION (mpz_srcptr z) __GMP_NOTHROW { mp_size_t n = SIZ(z); mp_ptr p = PTR(z); diff --git a/contrib/gmp/mpz/get_si.c b/contrib/gmp/mpz/get_si.c index 1308308fed..2f8a4738cd 100644 --- a/contrib/gmp/mpz/get_si.c +++ b/contrib/gmp/mpz/get_si.c @@ -22,7 +22,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" signed long int -mpz_get_si (mpz_srcptr z) +mpz_get_si (mpz_srcptr z) __GMP_NOTHROW { mp_ptr zp = z->_mp_d; mp_size_t size = z->_mp_size; @@ -34,10 +34,10 @@ mpz_get_si (mpz_srcptr z) #endif if (size > 0) - return (long) zl & LONG_MAX; + return zl & LONG_MAX; else if (size < 0) /* This expression is necessary to properly handle 0x80000000 */ - return ~(((long) zl - 1L) & LONG_MAX); + return -1 - (long) ((zl - 1) & LONG_MAX); else return 0; } diff --git a/contrib/gmp/mpz/hamdist.c b/contrib/gmp/mpz/hamdist.c index bd4dcd707c..5c62e0b40a 100644 --- a/contrib/gmp/mpz/hamdist.c +++ b/contrib/gmp/mpz/hamdist.c @@ -1,6 +1,7 @@ /* mpz_hamdist -- calculate hamming distance. -Copyright 1994, 1996, 2001, 2002 Free Software Foundation, Inc. +Copyright 1994, 1996, 2001, 2002, 2009, 2010, 2011 Free Software Foundation, +Inc. This file is part of the GNU MP Library. @@ -22,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ mp_bitcnt_t -mpz_hamdist (mpz_srcptr u, mpz_srcptr v) +mpz_hamdist (mpz_srcptr u, mpz_srcptr v) __GMP_NOTHROW { mp_srcptr up, vp; mp_size_t usize, vsize; @@ -37,20 +38,20 @@ mpz_hamdist (mpz_srcptr u, mpz_srcptr v) if (usize >= 0) { if (vsize < 0) - return ~ (mp_bitcnt_t) 0; + return ~ (mp_bitcnt_t) 0; /* positive/positive */ if (usize < vsize) - MPN_SRCPTR_SWAP (up,usize, vp,vsize); + MPN_SRCPTR_SWAP (up,usize, vp,vsize); count = 0; if (vsize != 0) - count = mpn_hamdist (up, vp, vsize); + count = mpn_hamdist (up, vp, vsize); usize -= vsize; if (usize != 0) - count += mpn_popcount (up + vsize, usize); + count += mpn_popcount (up + vsize, usize); return count; } @@ -60,7 +61,7 @@ mpz_hamdist (mpz_srcptr u, mpz_srcptr v) mp_size_t old_vsize, step; if (vsize >= 0) - return ~ (mp_limb_t) 0; + return ~ (mp_bitcnt_t) 0; /* negative/negative */ @@ -69,96 +70,96 @@ mpz_hamdist (mpz_srcptr u, mpz_srcptr v) /* skip common low zeros */ for (;;) - { - ASSERT (usize > 0); - ASSERT (vsize > 0); + { + ASSERT (usize > 0); + ASSERT (vsize > 0); - usize--; - vsize--; + usize--; + vsize--; - ulimb = *up++; - vlimb = *vp++; + ulimb = *up++; + vlimb = *vp++; - if (ulimb != 0) - break; + if (ulimb != 0) + break; - if (vlimb != 0) - { - MPN_SRCPTR_SWAP (up,usize, vp,vsize); - ulimb = vlimb; - vlimb = 0; - break; - } - } + if (vlimb != 0) + { + MPN_SRCPTR_SWAP (up,usize, vp,vsize); + ulimb = vlimb; + vlimb = 0; + break; + } + } /* twos complement first non-zero limbs (ulimb is non-zero, but vlimb - might be zero) */ + might be zero) */ ulimb = -ulimb; vlimb = -vlimb; popc_limb (count, (ulimb ^ vlimb) & GMP_NUMB_MASK); if (vlimb == 0) - { - mp_bitcnt_t twoscount; - - /* first non-zero of v */ - old_vsize = vsize; - do - { - ASSERT (vsize > 0); - vsize--; - vlimb = *vp++; - } - while (vlimb == 0); - - /* part of u corresponding to skipped v zeros */ - step = old_vsize - vsize - 1; - count += step * GMP_NUMB_BITS; - step = MIN (step, usize); - if (step != 0) - { - count -= mpn_popcount (up, step); - usize -= step; - up += step; - } - - /* First non-zero vlimb as twos complement, xor with ones - complement ulimb. Note -v^(~0^u) == (v-1)^u. */ - vlimb--; - if (usize != 0) - { - usize--; - vlimb ^= *up++; - } - popc_limb (twoscount, vlimb); - count += twoscount; - } + { + mp_bitcnt_t twoscount; + + /* first non-zero of v */ + old_vsize = vsize; + do + { + ASSERT (vsize > 0); + vsize--; + vlimb = *vp++; + } + while (vlimb == 0); + + /* part of u corresponding to skipped v zeros */ + step = old_vsize - vsize - 1; + count += step * GMP_NUMB_BITS; + step = MIN (step, usize); + if (step != 0) + { + count -= mpn_popcount (up, step); + usize -= step; + up += step; + } + + /* First non-zero vlimb as twos complement, xor with ones + complement ulimb. Note -v^(~0^u) == (v-1)^u. */ + vlimb--; + if (usize != 0) + { + usize--; + vlimb ^= *up++; + } + popc_limb (twoscount, vlimb); + count += twoscount; + } /* Overlapping part of u and v, if any. Ones complement both, so just - plain hamdist. */ + plain hamdist. */ step = MIN (usize, vsize); if (step != 0) - { - count += mpn_hamdist (up, vp, step); - usize -= step; - vsize -= step; - up += step; - vp += step; - } + { + count += mpn_hamdist (up, vp, step); + usize -= step; + vsize -= step; + up += step; + vp += step; + } /* Remaining high part of u or v, if any, ones complement but xor - against all ones in the other, so plain popcount. */ + against all ones in the other, so plain popcount. */ if (usize != 0) - { - remaining: - count += mpn_popcount (up, usize); - } + { + remaining: + count += mpn_popcount (up, usize); + } else if (vsize != 0) - { - up = vp; - usize = vsize; - goto remaining; - } + { + up = vp; + usize = vsize; + goto remaining; + } return count; } } diff --git a/contrib/gmp/mpz/iset_si.c b/contrib/gmp/mpz/iset_si.c index 0eb3881f45..64e51b386c 100644 --- a/contrib/gmp/mpz/iset_si.c +++ b/contrib/gmp/mpz/iset_si.c @@ -31,7 +31,7 @@ mpz_init_set_si (mpz_ptr dest, signed long int val) dest->_mp_alloc = 1; dest->_mp_d = (mp_ptr) (*__gmp_allocate_func) (BYTES_PER_MP_LIMB); - vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val); + vl = (mp_limb_t) ABS_CAST (unsigned long int, val); dest->_mp_d[0] = vl & GMP_NUMB_MASK; size = vl != 0; diff --git a/contrib/gmp/mpz/mul_i.h b/contrib/gmp/mpz/mul_i.h index d86196049b..2de3fe0b5e 100644 --- a/contrib/gmp/mpz/mul_i.h +++ b/contrib/gmp/mpz/mul_i.h @@ -26,7 +26,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #ifdef OPERATION_mul_si #define FUNCTION mpz_mul_si #define MULTIPLICAND_UNSIGNED -#define MULTIPLICAND_ABS(x) ((unsigned long) ABS(x)) +#define MULTIPLICAND_ABS(x) ABS_CAST(unsigned long, (x)) #endif #ifdef OPERATION_mul_ui diff --git a/contrib/gmp/mpz/nextprime.c b/contrib/gmp/mpz/nextprime.c index 6ba2515682..9e68ea8a66 100644 --- a/contrib/gmp/mpz/nextprime.c +++ b/contrib/gmp/mpz/nextprime.c @@ -107,7 +107,7 @@ mpz_nextprime (mpz_ptr p, mpz_srcptr n) difference = 0; /* Miller-Rabin test */ - if (mpz_millerrabin (p, 10)) + if (mpz_millerrabin (p, 25)) goto done; next:; incr += 2; diff --git a/contrib/gmp/mpz/scan0.c b/contrib/gmp/mpz/scan0.c index 9cb05337da..ac081a6a20 100644 --- a/contrib/gmp/mpz/scan0.c +++ b/contrib/gmp/mpz/scan0.c @@ -1,6 +1,6 @@ /* mpz_scan0 -- search for a 0 bit. -Copyright 2000, 2001, 2002, 2004 Free Software Foundation, Inc. +Copyright 2000, 2001, 2002, 2004, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -28,7 +28,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ reasonable to inline that code. */ mp_bitcnt_t -mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) +mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) __GMP_NOTHROW { mp_srcptr u_ptr = PTR(u); mp_size_t size = SIZ(u); @@ -42,7 +42,7 @@ mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) /* When past end, there's an immediate 0 bit for u>=0, or no 0 bits for u<0. Notice this test picks up all cases of u==0 too. */ if (starting_limb >= abs_size) - return (size >= 0 ? starting_bit : ULONG_MAX); + return (size >= 0 ? starting_bit : ~(mp_bitcnt_t) 0); limb = *p; @@ -52,14 +52,14 @@ mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) limb |= (CNST_LIMB(1) << (starting_bit % GMP_NUMB_BITS)) - 1; /* Search for a limb which isn't all ones. If the end is reached then - the zero bit immediately past the end is returned. */ + the zero bit immediately past the end is returned. */ while (limb == GMP_NUMB_MAX) - { - p++; - if (p == u_end) - return (mp_bitcnt_t) abs_size * GMP_NUMB_BITS; - limb = *p; - } + { + p++; + if (p == u_end) + return (mp_bitcnt_t) abs_size * GMP_NUMB_BITS; + limb = *p; + } /* Now seek low 1 bit. */ limb = ~limb; @@ -69,21 +69,21 @@ mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) mp_srcptr q; /* If there's a non-zero limb before ours then we're in the ones - complement region. Search from *(p-1) downwards since that might - give better cache locality, and since a non-zero in the middle of a - number is perhaps a touch more likely than at the end. */ + complement region. Search from *(p-1) downwards since that might + give better cache locality, and since a non-zero in the middle of a + number is perhaps a touch more likely than at the end. */ q = p; while (q != u_ptr) - { - q--; - if (*q != 0) - goto inverted; - } + { + q--; + if (*q != 0) + goto inverted; + } /* Adjust so ~limb implied by searching for 1 bit below becomes -limb. - If limb==0 here then this isn't the beginning of twos complement - inversion, but that doesn't matter because limb==0 is a zero bit - immediately (-1 is all ones for below). */ + If limb==0 here then this isn't the beginning of twos complement + inversion, but that doesn't matter because limb==0 is a zero bit + immediately (-1 is all ones for below). */ limb--; inverted: @@ -93,24 +93,24 @@ mpz_scan0 (mpz_srcptr u, mp_bitcnt_t starting_bit) limb &= (MP_LIMB_T_MAX << (starting_bit % GMP_NUMB_BITS)); if (limb == 0) - { - /* If the high limb is zero after masking, then no 1 bits past - starting_bit. */ - p++; - if (p == u_end) - return ULONG_MAX; - - /* Search further for a non-zero limb. The high limb is non-zero, - if nothing else. */ - for (;;) - { - limb = *p; - if (limb != 0) - break; - p++; - ASSERT (p < u_end); - } - } + { + /* If the high limb is zero after masking, then no 1 bits past + starting_bit. */ + p++; + if (p == u_end) + return ~(mp_bitcnt_t) 0; + + /* Search further for a non-zero limb. The high limb is non-zero, + if nothing else. */ + for (;;) + { + limb = *p; + if (limb != 0) + break; + p++; + ASSERT (p < u_end); + } + } } ASSERT (limb != 0); diff --git a/contrib/gmp/mpz/scan1.c b/contrib/gmp/mpz/scan1.c index dcf77986fb..e7e3c7f816 100644 --- a/contrib/gmp/mpz/scan1.c +++ b/contrib/gmp/mpz/scan1.c @@ -1,6 +1,6 @@ /* mpz_scan1 -- search for a 1 bit. -Copyright 2000, 2001, 2002, 2004 Free Software Foundation, Inc. +Copyright 2000, 2001, 2002, 2004, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -28,7 +28,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ so it seems reasonable to inline that code. */ mp_bitcnt_t -mpz_scan1 (mpz_srcptr u, mp_bitcnt_t starting_bit) +mpz_scan1 (mpz_srcptr u, mp_bitcnt_t starting_bit) __GMP_NOTHROW { mp_srcptr u_ptr = PTR(u); mp_size_t size = SIZ(u); @@ -42,7 +42,7 @@ mpz_scan1 (mpz_srcptr u, mp_bitcnt_t starting_bit) /* Past the end there's no 1 bits for u>=0, or an immediate 1 bit for u<0. Notice this test picks up any u==0 too. */ if (starting_limb >= abs_size) - return (size >= 0 ? ULONG_MAX : starting_bit); + return (size >= 0 ? ~(mp_bitcnt_t) 0 : starting_bit); limb = *p; @@ -52,60 +52,60 @@ mpz_scan1 (mpz_srcptr u, mp_bitcnt_t starting_bit) limb &= (MP_LIMB_T_MAX << (starting_bit % GMP_NUMB_BITS)); if (limb == 0) - { - /* If it's the high limb which is zero after masking, then there's - no 1 bits after starting_bit. */ - p++; - if (p == u_end) - return ULONG_MAX; - - /* Otherwise search further for a non-zero limb. The high limb is - non-zero, if nothing else. */ - for (;;) - { - limb = *p; - if (limb != 0) - break; - p++; - ASSERT (p < u_end); - } - } + { + /* If it's the high limb which is zero after masking, then there's + no 1 bits after starting_bit. */ + p++; + if (p == u_end) + return ~(mp_bitcnt_t) 0; + + /* Otherwise search further for a non-zero limb. The high limb is + non-zero, if nothing else. */ + for (;;) + { + limb = *p; + if (limb != 0) + break; + p++; + ASSERT (p < u_end); + } + } } else { mp_srcptr q; /* If there's a non-zero limb before ours then we're in the ones - complement region. Search from *(p-1) downwards since that might - give better cache locality, and since a non-zero in the middle of a - number is perhaps a touch more likely than at the end. */ + complement region. Search from *(p-1) downwards since that might + give better cache locality, and since a non-zero in the middle of a + number is perhaps a touch more likely than at the end. */ q = p; while (q != u_ptr) - { - q--; - if (*q != 0) - goto inverted; - } + { + q--; + if (*q != 0) + goto inverted; + } if (limb == 0) - { - /* Skip zero limbs, to find the start of twos complement. The - high limb is non-zero, if nothing else. This search is - necessary so the -limb is applied at the right spot. */ - do - { - p++; - ASSERT (p < u_end); - limb = *p; - } - while (limb == 0); - - /* Apply twos complement, and look for a 1 bit in that. Since - limb!=0 here, also have (-limb)!=0 so there's certainly a 1 - bit. */ - limb = -limb; - goto got_limb; - } + { + /* Skip zero limbs, to find the start of twos complement. The + high limb is non-zero, if nothing else. This search is + necessary so the -limb is applied at the right spot. */ + do + { + p++; + ASSERT (p < u_end); + limb = *p; + } + while (limb == 0); + + /* Apply twos complement, and look for a 1 bit in that. Since + limb!=0 here, also have (-limb)!=0 so there's certainly a 1 + bit. */ + limb = -limb; + goto got_limb; + } /* Adjust so ~limb implied by searching for 0 bit becomes -limb. */ limb--; @@ -117,14 +117,14 @@ mpz_scan1 (mpz_srcptr u, mp_bitcnt_t starting_bit) limb |= (CNST_LIMB(1) << (starting_bit % GMP_NUMB_BITS)) - 1; /* Search for a limb which is not all ones. If the end is reached - then the zero immediately past the end is the result. */ + then the zero immediately past the end is the result. */ while (limb == GMP_NUMB_MAX) - { - p++; - if (p == u_end) - return (mp_bitcnt_t) abs_size * GMP_NUMB_BITS; - limb = *p; - } + { + p++; + if (p == u_end) + return (mp_bitcnt_t) abs_size * GMP_NUMB_BITS; + limb = *p; + } /* Now seeking low 1 bit. */ limb = ~limb; diff --git a/contrib/gmp/mpz/set_si.c b/contrib/gmp/mpz/set_si.c index 7c73047e30..bffb2ee333 100644 --- a/contrib/gmp/mpz/set_si.c +++ b/contrib/gmp/mpz/set_si.c @@ -27,7 +27,7 @@ mpz_set_si (mpz_ptr dest, signed long int val) mp_size_t size; mp_limb_t vl; - vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val); + vl = (mp_limb_t) ABS_CAST (unsigned long int, val); dest->_mp_d[0] = vl & GMP_NUMB_MASK; size = vl != 0; diff --git a/contrib/gmp/mpz/sizeinbase.c b/contrib/gmp/mpz/sizeinbase.c index 1b2f5b1b42..d70e87832c 100644 --- a/contrib/gmp/mpz/sizeinbase.c +++ b/contrib/gmp/mpz/sizeinbase.c @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "longlong.h" size_t -mpz_sizeinbase (mpz_srcptr x, int base) +mpz_sizeinbase (mpz_srcptr x, int base) __GMP_NOTHROW { size_t result; MPN_SIZEINBASE (result, PTR(x), ABSIZ(x), base); diff --git a/contrib/gmp/mpz/swap.c b/contrib/gmp/mpz/swap.c index 1fdfcc1100..de8195a7d8 100644 --- a/contrib/gmp/mpz/swap.c +++ b/contrib/gmp/mpz/swap.c @@ -21,7 +21,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" void -mpz_swap (mpz_ptr u, mpz_ptr v) +mpz_swap (mpz_ptr u, mpz_ptr v) __GMP_NOTHROW { mp_ptr up, vp; mp_size_t usize, vsize; diff --git a/contrib/gmp/mpz/tstbit.c b/contrib/gmp/mpz/tstbit.c index 02133cc004..c3006c813b 100644 --- a/contrib/gmp/mpz/tstbit.c +++ b/contrib/gmp/mpz/tstbit.c @@ -38,7 +38,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ the limb_index >= abs_size test covers u=0 too. */ int -mpz_tstbit (mpz_srcptr u, mp_bitcnt_t bit_index) +mpz_tstbit (mpz_srcptr u, mp_bitcnt_t bit_index) __GMP_NOTHROW { mp_srcptr u_ptr = PTR(u); mp_size_t size = SIZ(u); diff --git a/contrib/gmp/printf/doprntf.c b/contrib/gmp/printf/doprntf.c index 537dce5b63..0a1928b26e 100644 --- a/contrib/gmp/printf/doprntf.c +++ b/contrib/gmp/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. @@ -89,8 +89,10 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, overestimate the integer part, and add prec. If f<1 then underestimate the zeros between the radix point and the first digit and subtract that from prec. In either case add 2 so the - round to nearest can be applied accurately. */ - ndigits = prec + 2 + round to nearest can be applied accurately. Finally, we add 1 to + handle the case of 1-eps where EXP(f) = 0 but mpf_get_str returns + exp as 1. */ + ndigits = prec + 2 + 1 + EXP(f) * (mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0)); ndigits = MAX (ndigits, 1); break;