mpn_perfpow: do we need a special GCD for mp_bitcnt_t?

Niels Möller nisse at lysator.liu.se
Mon Sep 1 20:59:15 UTC 2014


bodrato at mail.dm.unipi.it writes:

>> I am not aware of any configurations where mp_limb_t is the smaller of
>> the two.  But I feel bothered by type mixing such as this.
>
> Mixing types is not good for abstraction, i.e. portability and
> maintainability.

A compromise might be to add something like

  #if MP_BITCNT_T_MAX < MP_LIMB_T_MAX
  #error mp_limb_t too small !?
  #endif

close to the code which assigns an mp_bitcnt_t to an mp_limb_t. At
least, this documents the assumption made. (Except that I don't think
MP_BITCNT_T_MAX exists, and the common way of writing it as
~(mp_bitcnt_t) 0 won't work in a preprocessor conditional).

Another alternative might be to define a gcd_11 function taking
uintmax_t arguments. However, I don't really trust uintmax_t; it's
specified in essentially the same way as "unsigned long long" was
originally specified, but long is often not the largest type in current
C compilers.

I dislike the idea of having several gcd_11 functions differing only in
argument type, all of which are equal or smaller than the natural word
size.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list