I have code written that uses embedded AVXs when they are available in the current CPU. In GCC and Clang, unlike Visual C ++, in order to use the built-in functions, you must enable them on the command line.
The problem with GCC and Clang is that when you enable these options, you give the compiler free use of these instructions throughout your source file. This is very bad when you have header files that contain built-in functions or template functions, because the compiler will generate these functions using AVX instructions.
When linked, duplicate functions will be discarded. However, since some source files were compiled with -mavx and some were not, the various compilations of the inline / template functions will be different. If you are not lucky, the linker will randomly select the version with instructions for AVX, which will lead to a program crash when launched on a system without AVX.
GCC solves this with #pragma GCC target . You can disable special instructions for header files, and the generated code will not use AVX:
#pragma GCC push_options #pragma GCC target("no-avx") #include "MyHeader.h" #pragma GCC pop_options
Does the Clan have something like this? It appears that these options are ignored and generate AVX code.
avx intrinsics clang pragma
Myria
source share