The right test is on __AVX__
, it works just as well with clang as with gcc. It even works with Visual Studio...
Clang, detecting -mavx compiler argument on the source code side
سؤال
When I use GCC and set the command line argument -mavx, then the compiler will automagically define __AVX__
in the source code.
This way I can detect if the project is built with AVX instructions and if not fall back to another code path.
Is there a way to do the same thing with Clang?
Thanks, Christophe
المحلول
نصائح أخرى
The source in llvm/tools/lib/Basic/Targets.cpp:
switch (SSELevel) {
....
case AVX:
Builder.defineMacro("__AVX__");
...
With Visual C++ the define is _AVX_
not __AVX__
.
I was actually checking __AVX__
but I wasn't successful with it. It's possible that I am running into an issue with my project generator (CMake) to properly set the flags to use AVX.
EDIT: Correction it's two underscores, not one, my mistake!
So yes __AVX__
is working for VC, GCC and Clang. \o/
Thanks! Christophe