Why set zero in zero.c rather than use xor_n

Vincent Lefevre vincent at vinc17.net
Mon Feb 5 15:38:17 UTC 2018

On 2018-02-05 09:41:24 +0000, Win C wrote:
> Hi! There are a lot of reports that using xor is faster than setting
> a variable to zero. Therefore, I did a little test with the
> following code:

Your test is wrong because after one iteration, the data will be
in the cache. I mean that the first call may be much slower than
the subsequent calls. And in practice, mpn_zero will be just
called once on a given object. So only the first call matters.
Moreover "rp[i] = 0;" does not need to read data, which is better
for the cache. Testing on real applications would give more
meaningful results.

Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-devel mailing list