Preventing GCC from automatically using AVX and FMA instructions when compiled with -mavx and -mfma

前端 未结 2 741
星月不相逢
星月不相逢 2020-12-03 06:01

How can I disable auto-vectorization with AVX and FMA instructions? I would still prefer the compiler to employ SSE and SSE2 automatically, but not FMA and AVX.

My c

相关标签:
2条回答
  • 2020-12-03 06:55

    What you want to do is compile different object files for each instruction set you are targeting. Then create a cpu dispatcher which asks CPUID for the available instruction set and then jumps to the appropriate version of the function.

    I already described this in several different questions and answers

    • disable-avx2-functions-on-non-haswell-processors

    • do-i-need-to-make-multiple-executables-for-targetting-different-instruction-set

    • how-to-check-with-intel-intrinsics-if-avx-extensions-is-supported-by-the-cpu

    • cpu-dispatcher-for-visual-studio-for-avx-and-sse

    • create-separate-object-files-from-the-same-source-code-and-link-to-an-executable

    0 讨论(0)
  • 2020-12-03 06:59

    You will need to separate the code that uses AVX into a separate compile unit (in other words, a separate .cpp file), and compile only that with -mfma or whatever options you want. Normally, gcc will use -march=native, so it will compile for "your processor", and if you want generic code, you will need to use -march=x86_64 or -march=core2, or something like that.

    0 讨论(0)
提交回复
热议问题