mpz_mod inside loop

Paul Underwood paulunderwood at
Thu May 16 21:47:46 UTC 2019

I have noticed some efficiency when doing repeated mpz_mod (r, r, n) by replacing it with with mpz_mod (r, r, align) where align is n shifted left to the 64 bit boundary of the most significant quadword with the following (possibly incorrect) precomputed function:

mpz_mul_2exp (align, n, 64 - ( ( mpz_sizeinbase ( n, 2 ) + 2 ) % 64 ));

Is this correct expression for alignment of n?


More information about the gmp-discuss mailing list