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

Niels Möller nisse at lysator.liu.se
Sun Mar 11 08:32:28 UTC 2018


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

> ... if the compiler inlines the static gmp_tests_dbl_mant_bits function,
> and optimizes away the local variable n, directly updating c in the loop,
> then it can be a problem... suggestions?
> We can declare c as int and n as unsigned. But I fear this is not a real 
> obstacle for an optimizer.

Might help to declare c and/or n as volatile.

>> If we could use float.h constants, we wouldn't need to worry.
>
> In GMP we can #if HAVE_FLOAT_H ... but in mini-gmp?

I think float.h is standard C (not sure which version, though).
Configure check needed only for obscure systems. If it really is still needed
for gmp, maybe we can have GMP define it, and let mini-gmp.c do something
like

#ifndef GMP_DOUBLE_MANTISA_DIGITS
# include <float.h>
# if FLT_RADIX == 2
#  define GMP_DOUBLE_MANTISA_DIGITS DBL_MANT_DIG
# endif
#endif

And later fall back to something generic and less precise if
GMP_DOUBLE_MANTISA_DIGITS is not defined.

I hope we don't need it though, since (i) it's a bit ugly, and (ii) gmp
needs mini-gmp for the build system, not the host system, and I don't
think we have any configure checks for float.h using CC_FOR_BUILD.

I hope we can do the simple thing and include float.h unconditionally.

Hmm, according to the ChangeLog, the configure test was added by Kevin Ryde in
2002, because the SunOS C compiler (the one bundled with the
system if you didn't buy the SunPRO compiler separately, I guess) didn't
provide it. Maybe it's time to delete that?

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