udiv_qrnnd_preinv and udiv_rnnd_preinv macros

Niels Möller nisse at lysator.liu.se
Mon Feb 28 15:28:16 CET 2011


Torbjorn Granlund <tg at gmplib.org> writes:

> I have relied on compilers supressing the q adustment, by means of dead
> code elimination.

Even if compilers manage to do that well (I don't know), I think there
are estetic reasons to have a separate udiv_rnnd_preinv:

1. It makes the code using it prettier if it doesn't need to have a
   dummy quotient variable.

2. The interface is sightly more liberal: We get the correct remainder
   also for nh == d. While in this case, the correct quotient is too big
   to be returned as a single limb. Documenting this is clearer with a
   separate function.

I've now checked in optimized udiv_qrnnd_preinv and udiv_rnnd_preinv
(masking tricks, and better handling of the special case nl = constant
0). Checked with ./configure --disable-assembly && make && make check.

> I think it is easy enough to pass a 0 there.

Do you want me to convert uses of udiv_rnd_preinv (r, nh, d, di) to

  udiv_rnnd_preinv (r, nh, CNST_LIMB(0), d, di)

and delete udiv_rnd_preinv? And would it work without the somewhat ugly
CNST_LIMB?

With a compiler supporting __builtin_constant_p, it ought to generate
the same code, but without __builtin_constant_p, using udiv_rnnd_preinv
with nl == 0 is going to be slightly less efficient.

Regards,
/nisse

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list