mini-gmp
Niels Möller
nisse at lysator.liu.se
Wed Dec 6 18:53:04 UTC 2017
paul zimmermann <Paul.Zimmermann at inria.fr> writes:
> However, we are still missing a proper (documented) way to distinguish
> mini-gmp from plain gmp. We could use the __MINI_GMP_H__ macro but it is not
> documented.
We could add some documented macro for this purpse, but I'm not sure I
understand why you need it. In nettle, I do things like this:
In configure.ac:
AC_ARG_ENABLE(mini-gmp,
AC_HELP_STRING([--enable-mini-gmp], [Enable mini-gmp, used instead of
libgmp.]),,
[enable_mini_gmp=no])
if test "x$enable_mini_gmp" = xyes ; then
NETTLE_USE_MINI_GMP=1
else
NETTLE_USE_MINI_GMP=0
fi
AC_SUBST([NETTLE_USE_MINI_GMP])
Then in version.h.in (which is subject to configure substitutions, and
unlike config.h, nettle/version.h is a public header file):
#define NETTLE_USE_MINI_GMP @NETTLE_USE_MINI_GMP@
Finally, in bignum.h,
#include "version.h"
#if NETTLE_USE_MINI_GMP
# include "mini-gmp.h"
/* Any other min--gmp-specific hacks */
#else
# include <gmp.h>
#endif
And then I have a couple of #if NETTLE_USE_MINI_GMP spread out in the
rest of the code.
> And I notice that very few of the division functions from mini-gmp correspond
> to those of the GMP documentation. Thus to compile MPFR with mini-gmp we had
> to re-implement mpn_divrem_1, mpn_divrem and mpn_tdiv_qr. We can contribute
> them to mini-gmp if you want.
mini-gmp.h doesn't declare any mpn_*div functions. The mpn division
interface in GMP needs some work, and the code in mini-gmp is closer in
spirit to the new division functions we worked on (must be a decade
ago!), which still haven't made it to the public GMP api.
For compatibility, it would make some sense to add more of the public
mpn division functions to mini-gmp, if they can be done as reasonably
simple wrappers around the existing functions.
> The other functions we had to re-implement are some random functions
> (using srand48/lrand48, thus generating different random sequences, but
> for MPFR this is fine),
Right, I think sophisticated random numbers is out-of-scope for
mini-gmp.
> and finally mpz_dump.
Hmm. It seems this function is declared in gmp.h, but not mentioned in
the manual, and with a discouraging comment at the top of mpz/dump.c.
Any reason you can't switch to always use mpz_out_str instead?
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
More information about the gmp-devel
mailing list