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

bodrato at bodrato at
Sun Feb 10 20:22:38 CET 2013


I played with gmpxx.h for a while, because Torbjorn said something about
possible functions for comparison with shortcuts to detect specific
conditions (>, =, or <)...

After some tests with C++ I moved my experiments to plain C.

The current status of the experiments is shown by the attached patch. The
proposal is: let's introduce new macros like mpz_lt_ui_p, with default
definition like the following:
#define mpz_lt_ui_p(Z,UI) (_mpz_cmp_ui (Z,UI) < 0)
but possibly handling special cases with faster code...

Do you think it can make sense?

The attached patch is able to sensibly speed-up the execution of the
simple C++ loop I'm testing:

#include "gmpxx.h"

#define BIGN 123456789
#define BIGS 987654321

int main (void)
  mpz_class z(BIGN);
  unsigned r = 0;

  for (z*=BIGS; z>r; z-=BIGS)

  printf ("%u",r);

If you like the idea, then please read carefully the lt_si and gt_si
variants, I'm not sure I'm handling correctly the negative constants.

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmp.diff
Type: text/x-patch
Size: 5265 bytes
Desc: not available
URL: <>

More information about the gmp-devel mailing list