4 ms·
When testing on clang, the first and last examples produce radically different code even when both using -Os or -O3. The choice of flag does affect the code emi
by lilyball 7y ago
When testing on clang, the first and last examples produce radically different code even when both using -Os or -O3. The choice of flag does affect the code emitted, but it doesn't change the article's point as xor512d does it 16 bytes at a time and xor512a does it 1 byte at a time.
- 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.