diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-10-29 08:31:48 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-10-29 08:31:48 +0000 |
commit | 055f887fb71ed9d3d7a4877c461918a7c8e55cc8 (patch) | |
tree | 6294f3be786cad6be2c403e68e23001725122ebd | |
parent | 1ed2b6314fec9b90854669a4ff52e5fdfdb7694c (diff) | |
download | mpfr-055f887fb71ed9d3d7a4877c461918a7c8e55cc8.tar.gz |
adapt for mini-gmp (from GMP 6.1.0-rc1)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9703 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | doc/mini-gmp | 45 | ||||
-rw-r--r-- | src/free_cache.c | 4 | ||||
-rw-r--r-- | src/mpfr-impl.h | 5 | ||||
-rw-r--r-- | src/mpfr-mini-gmp.c | 47 | ||||
-rw-r--r-- | src/mpfr-mini-gmp.h | 35 | ||||
-rw-r--r-- | src/urandomb.c | 6 |
6 files changed, 67 insertions, 75 deletions
diff --git a/doc/mini-gmp b/doc/mini-gmp index 1a98996d9..14c1bc00a 100644 --- a/doc/mini-gmp +++ b/doc/mini-gmp @@ -1,13 +1,12 @@ How to compile GNU MPFR with mini-gmp ===================================== -(this was tested with MPFR 3.1.2 and GMP 5.1.3 on x86_64 GNU/Linux machine) -(also with MPFR svn 9700 and GMP 6.1.0-rc1: some GMP functions are missing) +(this was tested with MPFR svn 9703 and GMP 6.1.0-rc1 on x86_64 GNU/Linux) -1) extract the GMP tarball in say /tmp/gmp-5.1.3 - go into /tmp/gmp-5.1.3/mini-gmp - add the following line in mini-gmp.c (say at line 43): - char gmp_version[] = "5.1.3"; +1) extract the GMP tarball in say /tmp/gmp-6.1.0-rc1 + go into /tmp/gmp-6.1.0-rc1/mini-gmp + add the following line in mini-gmp.c (say at line 53): + char gmp_version[] = "6.1.0"; gcc -O2 -g -fPIC -c mini-gmp.c ar r libgmp.a mini-gmp.o @@ -17,30 +16,24 @@ How to compile GNU MPFR with mini-gmp mv libgmp.a /tmp/lib cp mini-gmp.h /tmp/include/gmp.h -3) do the following changes in /tmp/include/gmp.h: - -$ diff gmp.h.orig gmp.h -29a30,35 -> #define __GNU_MP_VERSION 5 -> #define __GNU_MP_VERSION_MINOR 1 -> #define __GNU_MP_VERSION_PATCHLEVEL 3 -> -> extern char gmp_version[]; -> -34a41,46 -> #endif -> -> /* random generation functions */ -> #ifndef gmp_randstate_t -> typedef long int __gmp_randstate_struct; -> typedef __gmp_randstate_struct gmp_randstate_t[1]; - -You also need to define GMP_NUMB_BITS and GMP_NAIL_BITS, for example: +3) add the following in /tmp/include/gmp.h: + +#define __GNU_MP_VERSION 6 +#define __GNU_MP_VERSION_MINOR 1 +#define __GNU_MP_VERSION_PATCHLEVEL 0 #define GMP_NUMB_BITS 64 #define GMP_NAIL_BITS 0 -4) extract the MPFR tarball in say /tmp/mpfr-3.1.2 +extern char gmp_version[]; + +/* random generation functions */ +#ifndef gmp_randstate_t +typedef long int __gmp_randstate_struct; +typedef __gmp_randstate_struct gmp_randstate_t[1]; +#endif + +4) extract the MPFR tarball in say /tmp/mpfr ./configure --with-gmp=/tmp --enable-mini-gmp Note: to use this version of the MPFR library, you need to define diff --git a/src/free_cache.c b/src/free_cache.c index 8c46058fb..1ed0e0675 100644 --- a/src/free_cache.c +++ b/src/free_cache.c @@ -24,11 +24,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., /* Default value for the cache of mpz_t */ #ifndef MPFR_MY_MPZ_INIT -# ifndef MPFR_USE_MINI_GMP # define MPFR_MY_MPZ_INIT 32 -# else -# define MPFR_MY_MPZ_INIT 0 -# endif #endif /* If the number of value to cache is not zero */ diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index 4dda07ac7..7963d2f6d 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -2101,6 +2101,11 @@ __MPFR_DECLSPEC void mpfr_mpz_clear _MPFR_PROTO((mpz_ptr)); ************** Internal mpz caching ***************** ******************************************************/ +/* don't use mpz caching with mini-gmp */ +#ifdef MPFR_USE_MINI_GMP +#define MPFR_MY_MPZ_INIT 0 +#endif + /* Cache for mpz_t */ #if !defined(MPFR_MY_MPZ_INIT) || MPFR_MY_MPZ_INIT != 0 # undef mpz_init diff --git a/src/mpfr-mini-gmp.c b/src/mpfr-mini-gmp.c index 17756cf1f..57e8614ba 100644 --- a/src/mpfr-mini-gmp.c +++ b/src/mpfr-mini-gmp.c @@ -51,39 +51,26 @@ gmp_randclear (gmp_randstate_t state) } #endif -#ifdef WANT_gmp_default_alloc -void * -gmp_default_alloc (size_t s) -{ - return malloc (s); -} -#endif - -#ifdef WANT_gmp_default_realloc -void * -gmp_default_realloc (void *x, size_t olds, size_t s) +#ifdef WANT_mpn_neg +mp_limb_t +mpn_neg (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n) { - return realloc (x, s); -} -#endif + mp_size_t i; -#ifdef WANT_gmp_default_free -void -gmp_default_free (void *x, size_t s) -{ - free (x); + for (i = 0; i < n; i++) + rp[i] = ~sp[i]; + return mpn_add_1 (rp, rp, n, (mp_limb_t) 1); } #endif -#ifdef WANT_mpn_neg +#ifdef WANT_mpn_com mp_limb_t -mpn_neg (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n) +mpn_com (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n) { mp_size_t i; for (i = 0; i < n; i++) rp[i] = ~sp[i]; - return mpn_add_1 (rp, rp, n, (mp_limb_t) 1); } #endif @@ -156,6 +143,22 @@ mpz_urandomb (mpz_t rop, gmp_randstate_t state, mp_bitcnt_t nbits) } #endif +#ifdef WANT_gmp_urandomm_ui +unsigned long +gmp_urandomm_ui (gmp_randstate_t state, unsigned long n) +{ + return random_limb () % n; +} +#endif + +#ifdef WANT_gmp_urandomb_ui +unsigned long +gmp_urandomb_ui (gmp_randstate_t state, unsigned long n) +{ + return random_limb () % (1UL << n); +} +#endif + #ifdef WANT_mpn_divrem mp_limb_t mpn_divrem (mp_limb_t *qp, mp_size_t qn, mp_limb_t *np, diff --git a/src/mpfr-mini-gmp.h b/src/mpfr-mini-gmp.h index 4072135b8..388039b7a 100644 --- a/src/mpfr-mini-gmp.h +++ b/src/mpfr-mini-gmp.h @@ -52,21 +52,6 @@ void gmp_randseed_ui (gmp_randstate_t, unsigned long int); void gmp_randclear (gmp_randstate_t); #endif -#ifndef gmp_default_alloc -#define WANT_gmp_default_alloc -void *gmp_default_alloc (size_t); -#endif - -#ifndef gmp_default_realloc -#define WANT_gmp_default_realloc -void *gmp_default_realloc (void *, size_t, size_t); -#endif - -#ifndef gmp_default_free -#define WANT_gmp_default_free -void gmp_default_free (void *, size_t); -#endif - #ifndef mpn_scan1 #define WANT_mpn_scan1 mp_bitcnt_t mpn_scan1 (const mp_limb_t *, mp_bitcnt_t); @@ -77,6 +62,11 @@ mp_bitcnt_t mpn_scan1 (const mp_limb_t *, mp_bitcnt_t); mp_limb_t mpn_neg (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n); #endif +#ifndef mpn_com +#define WANT_mpn_com +mp_limb_t mpn_com (mp_limb_t *rp, const mp_limb_t *sp, mp_size_t n); +#endif + #ifndef mpz_perfect_square_p #define WANT_mpz_perfect_square_p int mpz_perfect_square_p (const mpz_t); @@ -93,11 +83,6 @@ mp_limb_t mpn_divrem_1 (mp_limb_t*, mp_size_t, mp_limb_t*, mp_size_t, mp_limb_t); #endif -#ifndef mpz_realloc2 -#define WANT_mpz_realloc2 -void mpz_realloc2 (mpz_t, mp_bitcnt_t); -#endif - #ifndef mpz_urandomb #define WANT_mpz_urandomb void mpz_urandomb (mpz_t, gmp_randstate_t, mp_bitcnt_t); @@ -113,6 +98,16 @@ void mpn_zero (mp_limb_t *, mp_size_t); mp_bitcnt_t mpn_popcount (const mp_limb_t *, mp_size_t); #endif +#ifndef gmp_urandomm_ui +#define WANT_gmp_urandomm_ui +unsigned long gmp_urandomm_ui (gmp_randstate_t state, unsigned long n); +#endif + +#ifndef gmp_urandomb_ui +#define WANT_gmp_urandomb_ui +unsigned long gmp_urandomb_ui (gmp_randstate_t state, unsigned long n); +#endif + #ifndef mpn_divrem #define WANT_mpn_divrem mp_limb_t mpn_divrem (mp_limb_t *, mp_size_t, mp_limb_t *, diff --git a/src/urandomb.c b/src/urandomb.c index 16b7fbba6..48403c9bd 100644 --- a/src/urandomb.c +++ b/src/urandomb.c @@ -36,16 +36,16 @@ mpfr_rand_raw (mpfr_limb_ptr mp, gmp_randstate_t rstate, mpz_t z; MPFR_ASSERTN (nbits >= 1); - /* To be sure to avoid the potential allocation of mpz_urandomb */ - ALLOC(z) = SIZ(z) = MPFR_PREC2LIMBS (nbits); - PTR(z) = mp; #if __MPFR_GMP(5,0,0) /* Check for integer overflow (unless mp_bitcnt_t is signed, but according to the GMP manual, this shouldn't happen). Note: mp_bitcnt_t has been introduced in GMP 5.0.0. */ MPFR_ASSERTN ((mp_bitcnt_t) -1 < 0 || nbits <= (mp_bitcnt_t) -1); #endif + mpz_init (z); mpz_urandomb (z, rstate, nbits); + MPN_COPY(mp, PTR(z), MPFR_PREC2LIMBS (nbits)); + mpz_clear (z); } int |