Compare up to x bits

Richard Cavell richardcavell at mail.com
Sun Feb 20 13:35:24 CET 2005


Hi,

I want to do the following as fast as possible:

mpz_t a, b, d;
int c;

	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
http://promo.mail.com/adsfreejump.htm



More information about the gmp-discuss mailing list