mpz_{eq,lt,gt}_{ui,si}_p macros?

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Sun Feb 10 21:51:27 CET 2013


Ciao,

Il Dom, 10 Febbraio 2013 9:08 pm, Torbjorn Granlund ha scritto:
>   > Example: __builtin_constant_p ((UI) > 0 && (UI) <= GMP_NUMB_MAX)
>
> Perhaps that will then work as intended, but I would still suggest that
> it is a typo in this case.  At least the argument in that code sometimes
> is just the constants, sometimes also range conditions involving the
> constant.

I believe they are correct. They do not simply involve constants...

Let's take the gt_ui macro:
#define mpz_gt_ui_p(Z,UI)                                               \
  (__builtin_constant_p (UI) && (UI) == 0 ? (Z)->_mp_size > 0           \
   : __builtin_constant_p ((UI) >= 0 && (UI) <= GMP_NUMB_MAX)           \
   && ((UI) >= 0 && (UI) <= GMP_NUMB_MAX)                               \
   ? (Z)->_mp_size > ((Z)->_mp_d[0] <= __GMP_CAST (mp_limb_t, UI))      \
   : _mpz_cmp_ui (Z,UI) > 0)

__builtin_constant_p (UI) is true iif UI is a constant, if it is, the
macro checks (compile-time) if it's zero...
__builtin_constant_p ((UI) >= 0 && (UI) <= GMP_NUMB_MAX) can be true for a
constant, but also for a variable! E.g. mpz_gt_ui_p (z, (unsigned) r) will
be optimised by this line, because the compiler knows that whatever the
value of r is, UI is not a constant, but the condition is constantly true.

I do not know if current gcc can optimise a loop like:
for (int i = 3; (i < 1 << 30) && mpz_gt_ui_p (z, i); i <<= 1) ;
but we give it the chance to.

Regards,
m

-- 
http://bodrato.it/software/strassen.html



More information about the gmp-devel mailing list