2 ms·
> xor512d does it 16 bytes at a time and xor512a does it 1 byte at a time. Not it doesn't. The compiler chooses how many bytes to do at a time. And in fact it
by tom_mellior 7y ago
> xor512d does it 16 bytes at a time and xor512a does it 1 byte at a time.
Not it doesn't. The compiler chooses how many bytes to do at a time. And in fact it defers that choice to run time. For reference, here are both functions compiled with GCC and Clang at -O3: https://godbolt.org/z/WmduxJ https://godbolt.org/z/WmduxJ
For xor512a both compilers insert an aliasing check and fall back to a scalar loop if the input arrays overlap. But for the case where they do not overlap, both compilers produce vector code that is essentially equivalent to xor512d.
If we expect aliasing to be rare, the two functions will usually both execute essentially the same vector code, with the performance difference only being the slight cost of the aliasing check. This holds for both GCC and Clang.