문제

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 right test is on __AVX__, it works just as well with clang as with gcc. It even works with Visual Studio...

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top