Optimizing Modulus

Kevin Ryde user42 at zip.com.au
Wed Oct 29 07:14:40 CET 2003

David McKen <cic_3_b at yahoo.com> writes:
> From what I understand function pointers are faster than having an
> if..then..else statement that would be evaluated every time an
> iteration occours.

Actually, some chips don't branch predict an indirect call, so you
might find the conditional a few cycles faster, if the condition is
non-random and hence amenable to branch prediction.  Probaby too small
to measure the difference though. :)

> My question is looking at the results of the profiler can anyone
> suggest anything that might further speed up my program.

You can call mpn_modexact_1_odd instead of reaching mpn_mod_1, if you
don't mind getting into some undocumented/unsupported/etc internals.

	remainder = __gmpn_modexact_1c_odd (up_counter->_mp_d,
                                            (mp_size_t) up_counter->_mp_size,
                                            (mp_limb_t) prime_product_3_29,
                                            (mp_limb_t) 0);

More information about the gmp-discuss mailing list