Compilers: all of the three clang11 / gcc10 / msvc (vs2019).
What I want to write
my_math_func(raw_pointers_to_data)
{
if (CpuSupportsAvx512()) {
/* processing data via __m512 and _mm512_intrinsics */
} else if(CpuSupportsAvx2()) {
/* processing data via AVX2-specific */
} else {
/* processing data via SSE4 */
}
}
The problem is that GCC (and AFAIK clang) refuse to compile when I set the -msse4.2
.
If I set -mavx512f
then the compiler can generate avx512 specific instructions anywhere in the binary, which is unacceptable for me.
The question is, is there a way to tell the compiler "please, let me use AVX+ intrinsics where I want, but don't generate avx+ instructions anywhere else" without using raw assembly or moving code to a separate dynamic library?
I'm ready to take responsibility (and future ERROR: Illegal Instruction
) for checking that my avx512 blocks won't run on an incompatible CPU.