remove extra division in mpq/aors.c

Marc Glisse marc.glisse at inria.fr
Sun Feb 20 23:07:50 CET 2011


On Sun, 20 Feb 2011, Torbjorn Granlund wrote:

> I have attached a patch to modernise a related function.  Does it look
> correct to you?

It looks correct (I was confused by the interface of the bdiv_dbm1 
function but it makes sense).

If the gcd is 7, it looks like it lets tdiv copy the number into the 
result and then performs the division by 7 in place. Is that wanted? I 
guess I would have replaced:
       mpz_tdiv_q_2exp (q, a, twos);
with:
       if(twos>0){
         mpz_tdiv_q_2exp (q, a, twos);
         a=q;
       }
and kept using 'a' afterwards.

And then it might be possible to move the power-of-2 thing before the test 
for 1 and write the tests for 1-3-5 only once (note that mpq (the main 
consumer?) already tests for 1 so this test doesn't need to be too early).

If the gcd is 14, is it better to divide by 2 before calling the generic 
division function with 7? It looks like the other functions also proceed 
in 2 steps, although it seems possible to do both at once.

Would it make sense to replace the tests for 3 and 5 by a single test that 
GMP_NUMB_MASK%d==0?

Wow, I have started ranting... sorry for that.

-- 
Marc Glisse


More information about the gmp-discuss mailing list