mini-gmp

Vincent Lefevre vincent at vinc17.net
Thu Dec 20 13:56:52 UTC 2018


On 2018-12-16 02:22:27 +0100, Vincent Lefevre wrote:
> On 2018-12-15 20:18:44 +0100, Niels Möller wrote:
> > Vincent Lefevre <vincent at vinc17.net> writes:
> > 
> > > Yes, this is expected by MPFR. But since mini-gmp.c includes
> > > mini-gmp.h, this prevents one from redefining GMP_LIMB_BITS
> > > in mini-gmp.h, except by exactly the same content, which is
> > > not interesting.
> > 
> > I'm afraid I'm missing simthing. Why would you redefine it in
> > mini-gmp.h? Since it's now *not* in mini-gmp.h, you can define
> > GMP_LIMB_BITS elsewhere in mpfr, without colliding.
> 
> This was a suggestion by Paul:
> 
> ------------------------------------------------------------------
> How to use mini-gmp with reduced limb size
> ==========================================
> 
> Following the idea of Micro-GMP [1], the GMP developers have adapted mini-gmp
> so that it can be used with a reduced limb size.
> 
> For that, you have to take a GMP snapshot from December 09, 2018, or later
> (see https://gmplib.org/download/snapshot/).
> 
> Then edit the first line of mini-gmp.h to have for example:
> 
>   #include <stdint.h>
>   typedef uint8_t mp_limb_t;
>   #define GMP_LIMB_BITS 8
>   #define __GMP_SHORT_LIMB
> 
> Then you can configure MPFR with that version of mini-gmp, as indicated above.
> ------------------------------------------------------------------

Actually I've found that GMP_LIMB_BITS is not used by mini-gmp.h,
so that the

#define GMP_LIMB_BITS 8

is useless, i.e.

#include <stdint.h>
typedef uint8_t mp_limb_t;
#define __GMP_SHORT_LIMB

is sufficient for MPFR.

However, this is not supported by mini-gmp.c, which still expects
an unsigned long:

mini-gmp.c: In function 'mpz_ui_pow_ui':
mini-gmp.c:3135:42: error: passing argument 2 of 'mpz_roinit_normal_n' from incompatible pointer type [-Werror=incompatible-pointer-types]
 3135 |   mpz_pow_ui (r, mpz_roinit_normal_n (b, &blimb, blimb != 0), e);
      |                                          ^~~~~~
      |                                          |
      |                                          long unsigned int *
mini-gmp.c:1625:41: note: expected 'mp_srcptr' {aka 'const unsigned char *'} but argument is of type 'long unsigned int *'
 1625 | mpz_roinit_normal_n (mpz_t x, mp_srcptr xp, mp_size_t xs)
      |                               ~~~~~~~~~~^~
mini-gmp.c: In function 'mpz_powm_ui':
mini-gmp.c:3247:43: error: passing argument 2 of 'mpz_roinit_normal_n' from incompatible pointer type [-Werror=incompatible-pointer-types]
 3247 |   mpz_powm (r, b, mpz_roinit_normal_n (e, &elimb, elimb != 0), m);
      |                                           ^~~~~~
      |                                           |
      |                                           long unsigned int *
mini-gmp.c:1625:41: note: expected 'mp_srcptr' {aka 'const unsigned char *'} but argument is of type 'long unsigned int *'
 1625 | mpz_roinit_normal_n (mpz_t x, mp_srcptr xp, mp_size_t xs)
      |                               ~~~~~~~~~~^~

For instance:

void
mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e)
{
  mpz_t b;
  mpz_pow_ui (r, mpz_roinit_normal_n (b, &blimb, blimb != 0), e);
}

needs to be adapted.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-devel mailing list