Compare up to x bits
richardcavell at mail.com
Sun Feb 20 13:35:24 CET 2005
I want to do the following as fast as possible:
mpz_t a, b, d;
mpz_tdiv_r_2exp (a, b, c);
if (mpz_cmp(a, d)!=0) return false;
This has the effect of the following:
Chop off the last c bits of b and store it in a.
Compare that finding with a known value.
Now, I'm profiling my code and I'm losing a lot of bus cycles to the mpz_tdiv_r_2exp function. I wonder if it's possible to combine the two, like this:
look at the rightmost limb of the numbers and return unequal if they're unequal, otherwise
look at the next limb of the numbers and return unequal if they're unequal, otherwise
for the limb that contains the c-th bit, create a bit template, and compare the leftmost limbs through the bit template.
This will allow the function to return much sooner in almost all cases by aborting after the very first comparison.
As a sidenote, is anyone else excited about the Playstation 3/Cell? And am I the only person who would like to port gmp to it and use it as a general purpose computing device?
Sign-up for Ads Free at Mail.com
More information about the gmp-discuss