test if an unsigned long fits in a limb.

Marc Glisse marc.glisse at inria.fr
Wed Mar 7 09:46:12 CET 2012


On Wed, 7 Mar 2012, Niels Möller wrote:

> Marc Glisse <marc.glisse at inria.fr> writes:
>
>> Imagine that mpz_set_si takes as argument a long long on win64. I can
>> still pass it a long with no problem. Imagine that mpz_get_si outputs
>> a long long. I can still store it safely in a long, because I first
>> called mpz_fits_slong_p to check that it would fit. It doesn't look
>> like I have lost anything.
>
> I see. That could work, even if I'm still not convinced it's a good idea
> to have the type used depend on the GMP configuration. If the intention
> is to get an integer of size matching a the native word size, no matter
> which C type that may be, I think using mp_limb_t and mp_limb_signed_t
> (but without nail bits) should be goood enough.

Possibly. I repeated some arguments, but I don't know the answer either.

> Functions using long long would provide additional functionality on
> platforms where long long is larger than mp_limb_t (presumably because
> long long is larger than the native word size). But I think those should
> be additional functions, since they will give a larger overhead if you
> really just want a long (which fits in a native word on sane platforms).
>
> We can add an awful lot of functions here, so I imagine we need to think
> a bit on which function really are needed. If I understand you
> correctly, the most urgent problem is to be able to convert between
> mpz_t and native (64-bit) integers on W64. Is there any other supported
> platform that has chosen an ABI where "Long" is smaller than the native
> word size?

I would assume that this mostly corresponds to the 'longlong' 
configurations, which according to configure.in include quite a few 64bit 
platforms that provide a 32bit ABI.

-- 
Marc Glisse


More information about the gmp-devel mailing list