intrinsics - Does Clang have something like #pragma GCC target? -
i have code written uses avx intrinsics when available on current cpu. in gcc , clang, unlike visual c++, in order use intrinsics, must enable them on command line.
the problem gcc , clang when enable these options, you're giving compiler free reign use instructions everywhere in source file. bad when have header files containing inline functions or template functions, because compiler generate these functions avx instructions.
when linking, duplicate functions discarded. however, because source files compiled -mavx
, not, various compilations of inline/template functions different. if you're unlucky, linker randomly choose version has avx instructions, causing program crash when run on system without avx.
gcc solves #pragma gcc target
. can turn off special instructions header files, , code generated not use avx:
#pragma gcc push_options #pragma gcc target("no-avx") #include "myheader.h" #pragma gcc pop_options
does clang have this? seems ignore these options , generates avx code anyway.
you should using static inline
instead of inline
, version of function compiled -mavx
used callers translation unit.
the linker still merge actual duplicates, instead of picking 1 non-inline definition name.
this has advantage compiler doesn't waste time emitting stand-alone definition functions decides inline every caller in translation unit.
the gcc/clang way makes sense if you're used , design code it. , note msvc need avx enabled if you're compiling functions use avx. otherwise mix vex , non-vex encodings, leading big penalties, instead of using vex encoding 128-bit _mm_add_ps
in horizontal add @ end of _mm256_add_ps
loop.
so have same problem msvc, compiling _mm_whatever
make avx-only machine code.
Comments
Post a Comment