3 ms·
As one of the comments in the article points out, there's an issue of mismatched compiler optimization flags for the different examples shown. The first was com
by Narishma 7y ago
As one of the comments in the article points out, there's an issue of mismatched compiler optimization flags for the different examples shown. The first was compiled with -Os, the last with -O3, and it's not mentioned for the ones in between. Using the same flags for both will produce the same code, so it doesn't seem like restrict helps much in this case.
- lilyball 7y agoWhen 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.