mini-gmp mpz_{get,set}_d not fully compatible with GMP

Niels Möller nisse at lysator.liu.se
Sat May 26 08:20:59 UTC 2018


"Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:

> Il Dom, 20 Maggio 2018 9:57 pm, Niels Möller ha scritto:

>> You could consider making this into small step towards modularizing
>> mini-gmp. Something like
>
>> #ifndef MINI_GMP_FLOAT_SUPPORT
>
>> ...
>
> The idea is interesting. How should we modularize? Should we split mini-
> in many files (each #include-ing the ones it depends on) or should we have
> a single file with selector like the one you propose? The only module we
> have, currently is mini-mpq, as a file apart.

I think it should stay as one file. Not sure if it's worth the effort,
but I was thinking of trying to divide mini-gmp into modules including
things like

* Add and sub.

* Bitwise logic functions

* Mul

* Div

* Base conversion for power-of-2 bases

* Base conversion for non-power-of-2 bases, in particular, 10

* Float conversion

* Import/export

* Various higher level functions, roots, gcd, primality testing, ...

We'd need to sort out dependencies between the modules and likely
maintain that graph manually.

By default, compiling mini-gmp would include everything, but if the user
does something like

#define MINI_GMP_ENABLE_BASE_CONVERSION_POWER_OF_TWO 1
#define MINI_GMP_ENABLE_MUL 1
#include "mini.gmp.c"

only those routines and their dependencies would be included. We'd need a
pretty large block of #ifs at the top to implement the dependencies. So
the drawback is the complexity of the needed #ifdeffery, and the testing
thereof.

Uncler to me how far it's worth going in dividing code into smaller
modules. To have one or (even two, in the case of get_str) module per
function will not be easy to maintain.

Alternative might be to recommend applications that care about binary
size to compile mini-gmp.c with -ffunction-sections and let the linker
sort it out, or rely on link-time-optimization eliminating unused code.
But I doubt that LTO will detect, e.g., that mpz_get_str is only ever
called with power-of-two arguments, and eliminate the unused
mpn_get_str_other together with the division code it depends on.

> I'm already tempted to join at least mini-gmp.h and mini-mpq.h

Makes sense to me. Could consider renaming mini-gmp.c to mini-mpz.c, but
doesn't matter so much.

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