4 ms·
If I'm understanding the linked bug report right, this is just plain unpleasant. So, running SSE code mixed with AVX code has a penalty unless you zero out the
by makomk 6y ago
If I'm understanding the linked bug report right, this is just plain unpleasant. So, running SSE code mixed with AVX code has a penalty unless you zero out the upper parts of the registers in a special way when switching from AVX to SSE. This seems annoying but no big deal - just save the registers your function needs to preserve using AVX instructions, zero them out, do your SSE computations, and restore them before returning. Not so fast! If the calling code was legacy SSE rather than AVX, this will mark the upper halves of the registers as dirty and incur a performance penalty after the function returns, even though the offending registers have the same contents at the architectural level as they did before the call and the only AVX code is the code intended to clear out and restore the upper halves of the registers in order to prevent exactly this. Apparently, the fix is to test if the upper halves of the registers are zero and use different code paths to save and restore them depending on whether they are. What a mess.
- Const-me 6y agoAll SSE instructions can be encoded into VEX and won’t trigger the issue. It’s just an unfortunate combination of compiler and linker settings, where compiler used legacy encoding despite AVX was enabled somewhere else. Modern compilers are aware, e.g. check out gcc 10: https://godbolt.org/z/39v98r https://godbolt.org/z/39v98r I asked it to compile for Sandy Bridge and the compiler has encoded all vector instruction in VEX, you can tell by opcodes starting with v, e.g. vmovmskpd instead of just movmskpd: https://www.felixcloutier.com/x86/movmskpd https://www.felixcloutier.com/x86/movmskpd
- makomk 6y agoThat's not much help when the function being called is in a shared system library like ld.so or libc that needs to support being used both by older binaries that use SSE and newer ones that use AVX, which I think is the case here. People aren't just going to recompile every single program on the planet and break backwards compatibility with older systems in the process, so on some level I think there's no alternative but to work around this. (Also, remember that SSE is used for even non-vectorized floating point in modern software, and that a lot of the vectorized stuff is likely to be hand-optimized assembler.)
- gnufx 6y agoGNU libc, at least, has versions of a variety of functions for different SIMD variants with runtime dispatch. You can provide that with GCC attributes, or explicitly with the cpuid-like mechanisms typically used in linear algebra libraries, for instance.
- jdsully 6y agoThe upper parts of the registers are volatile per the ABI. So the caller was never able to assume they were untouched vzeroupper or not.