Attempting to optimize a multiply

Richard Cavell richardcavell at mail.com
Thu Feb 17 14:39:33 CET 2005


I have a calculation which goes like this:

mpz_t a;   This is initialised to some number
mpz_t b;   This is initialised to some number
mpz_t c, d;

mpz_mul (c, a, b);
mpz_setbit(a, 25);    // I know categorically that bit 25 is clear before this line.
mpz_mul (d, a b);

I tried to optimize it like this:

mpz_t a;   This is initialised to some number
mpz_t b;   This is initialised to some number
mpz_t c, d;

mpz_mul (c, a, b);
mpz_mul_2exp (b, b, 25);
mpz_add (d, c, b);

In theory, this should work.  It should eliminate a multiply and instead convert it to a left shift and add.  But it grows my execution time considerably (on a G4 using GCC, 32-bit size operands).

1.  Is this what you would expect?
2.  For operands in the region of 10 to the power 100, what would you expect?


-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm



More information about the gmp-discuss mailing list