mpn_divexact_1 comments
Mark Sofroniou
marks at wolfram.com
Wed Oct 16 13:46:52 CEST 2013
I noticed a couple of minor issues in mpn_divexact_1 (dive1.c) that are
not in my own implementation, so I thought I'd pass them on.
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;
...
This simplifies setting the length of the result in a caller function.
If the divisor is a power of two then skip the division code and
just shift or copy:
...
/* divisor = 1, 2, 4, ... */
if (divisor == 1)
{
if (shift)
{
mp_limb_t shifted_out;
shifted_out = mpn_rshift (dst, src, size, shift);
ASSERT (shifted_out == 0);
}
else
{
if (dst != src) mpn_copyi(dst, src, size);
}
return ;
}
binvert_limb (inverse, divisor);
...
Regards, Mark
More information about the gmp-devel
mailing list