hash of mpz_t and mpq_t

Marco Bodrato bodrato at mail.dm.unipi.it
Thu Jun 17 19:36:01 UTC 2021


Ciao,

Il 2021-06-17 18:05 Hans Åberg ha scritto:
>> On 17 Jun 2021, at 17:21, Marco Bodrato <bodrato at mail.dm.unipi.it> 
>> wrote:

>> You are right, one should use mpz_sgn(X) < 0 ? -mpz_size(X) : 
>> mpz_size(X) , instead.
>> 
>> It might seem too complex, …
> 
> Conditions can be expensive on piped CPUs.

If for a given target a branch is expensive, then the compiler can use a 
conditional operation, or a mask, or... any other reasonable solution 
for that specific target.
This is exactly the work I expect from an optimising compiler.

>> but a modern gcc is able to understand what we mean and compile the 
>> right thing.

> Even though modern compilers are pretty aggressive in optimizations,
> it would be better to having rely on that.

May I suggest that relying on good compilers can be more "future-proof" 
than relying on undocumented internals :-)

Ĝis,
m


More information about the gmp-discuss mailing list