mpn_divexact_1 comments

Niels Möller nisse at lysator.liu.se
Wed Oct 16 14:22:46 CEST 2013


Mark Sofroniou <marks at wolfram.com> writes:

> If the quotient will be one word shorter than the dividend then set
> the top word to zero:
>
>   if ((divisor & 1) == 0)
>     {
>       if ((dst != src) && (src[size - 1] < divisor)) dst[size - 1] = 0;
> ...

I don't understand. Doesn't the current loop always write all quotient
limbs, including dst[size-1]? And why the condition (dst != src) ???

> If the divisor is a power of two then skip the division code and
> just shift or copy:

Low-level gmp functions, like this one, usually don't do that type of
optimizations. The caller can do that check, if powers of two are likely
enough that it matters. And I magine constant d is an important usecase.

Furthermore, this function is implemented in assembly on several
platforms, and adding a power-of-two check and a call to mpn_rshift to
all implementations of mpn_divexact_1 would get a bit messy.

Regards,
/Niels

-- 
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