bodrato at bodrato at
Wed Jun 24 09:41:11 UTC 2015


Il Mer, 24 Giugno 2015 9:56 am, Torbjörn Granlund ha scritto:
> bodrato at 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: . 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
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,


More information about the gmp-devel mailing list