3 ms·
https://godbolt.org/z/szMvnTT63 https://godbolt.org/z/szMvnTT63 Looking at the naive code from Analysis 1 and comparing GCC 4.1.2 to GCC 13.2 there's a huge di
by mastax 3y ago
https://godbolt.org/z/szMvnTT63 https://godbolt.org/z/szMvnTT63
Looking at the naive code from Analysis 1 and comparing GCC 4.1.2 to GCC 13.2 there's a huge difference. Even when forcing both to generate code for the same old architecture (k8) so its more fair.
GCC 4.1 generates code which is a pretty direct translation of the source: branchy, operates on bytes.
GCC 13.2 does a ton of optimization. There's only a single jump/loop. It uses prefetch. It uses SSE instructions to operate on 128-bits at a time. It looks like all the instructions are duplicated as well to operate on a pair of registers, too. I'm not exactly sure.
- ack_complete 3y agoGCC is just vectorizing the code literally. It's doing multiple bytes in each loop iteration, but the vectorized code is still bit-testing the index to conditionally XOR into each accumulator. This is still much less efficient than taking advantage of the regular patterns as in the latter parts of the article. It also runs with a lot less lanes than it could, because it uses 32-bit lanes instead of 8-bit for some reason.