support larger int types

Marc Glisse marc.glisse at inria.fr
Wed Oct 12 22:24:20 UTC 2016


On Thu, 6 Oct 2016, Ulrich Drepper wrote:

> I have a question about an issue which might on affect me or it might
> not.  In future I'm sure more people will stumble across this.
>
> gcc and other compilers now support for many targets types larger than
> long.  This has long been as issue for long long on 32-bit platforms
> but now there is __int128.  In arithmetic-heavy code I use it as an
> intermediate type before switching to mpz etc and therefore it would
> be nice to be able to convert such numbers.  I.e., variants of
> mpz_set_si are needed.
>
> I wrote those for my code.  The question is: would these be of
> interest for upstream?  I'm perfectly happy to send my code along.

Hello,

sorry for the slow reply, it looks like the others are even more busy than 
I am... I would love to have setters from all missing types (long long, 
__int128, long double, maybe even __float128), I could have used them 
years ago. I don't remember exactly the reasons that have blocked the 
previous attempts, let me try to list some from memory:

- there were plans to completely decouple the limb size from the size of 
long (the argument of mpz_*_si), so the same code could be used for 
different sizes (and so we could play with arbitrary limb sizes).

- the ABI should be relatively stable, the list of functions provided by 
libgmp should not be too random depending on the exact compiler and 
options used to build it.

- some argue we should provide a setter from intmax_t and that will cover 
all integer types (except that this excludes __int128).

- I believe GMP still doesn't require a C99 compiler.

(at some point, I was tempted to add long long support in the C++ wrapper, 
where it is easier because overloading and inlining avoid most ABI 
complications)

What does your interface look like? 2 new functions mpz_set_si128 and 
mpz_set_ui128? Or did you also add fits_* and get_* functions? Or even the 
mixed operations like mpz_add_si128?

I assume an autoconf test would determine if the functions are compiled. 
In gmp.h, would we test the macro __SIZEOF_INT128__, or would we hard-code 
the result from autoconf?

-- 
Marc Glisse


More information about the gmp-discuss mailing list