mpn_zero_p

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Wed Jun 24 09:41:11 UTC 2015


Ciao,

Il Mer, 24 Giugno 2015 9:56 am, Torbjörn Granlund ha scritto:
> bodrato at mail.dm.unipi.it writes:

>   As the manual says about low-level functions: "No size argument may be
> zero".
>
> That certainly isn't true in general, at least not for the entire set of
> mpn functions.  I think it might be a mistake to make functions which
> naturally and usefully support zero sizes require non-zero sizes.

In general, when supporting zero sizes is an O(1) cost compared to an O(n)
or bigger cost of the function, I may agree.
On average mpn_zero_p will return after the first branch (on random data,
the first limb we check is non-zero). Supporting zero sizes here means
doubling the branches on average...

In the whole library, only two calls to mpn_zero_p required support for
zero size: https://gmplib.org/repo/gmp/rev/cb5da779cc81 . The other will
benefit of the reduced branching.

Sometimes we have oddities in the library.
E.g. mpn_sqrtrem requires that "The most significant limb of {sp, n} must
be non-zero.", but supports n=0 (not tested by our test-suite, look at
https://gmplib.org/devel/lcov/shell/var/tmp/lcov/gmp/mpn/sqrtrem.c.gcov.html
).
mpn_rootrem does not, it begins with ASSERT (un > 0 && up[un - 1] != 0).

mpn/x86_64/fastsse/com.asm does support zero size with an initial
        test    n, n
        jz      L(don)
while neither the generic C function for the library ( mpn/generic/com.c ),
nor the inlined version in gmp-impl.h does.


Best regards,
m

-- 
http://bodrato.it/



More information about the gmp-devel mailing list