Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang generates errors when I try to use AVX features

Tags:

c++

c

clang

I'm on Windows 10, with Clang version 5 (recently installed). When I compile the following

#define __AVX__
#define __AVX2__
#include <immintrin.h>

int main(void) {
    __m256i a, b, result;
    result = _mm256_add_epi64(a, b);
    return 0;
}

I get the following error:

 error: always_inline function '_mm256_add_epi64' requires target 
 feature 'avx2', but would be inlined into function 'main' that is 
 compiled without support for 'avx2'
    result = _mm256_add_epi64(a, b);
             ^

MSVC compiles it just fine. What compiler option do I need to use in order to get Clang to compile this? Or is there something else going on?

like image 679
brothir Avatar asked Dec 05 '25 07:12

brothir


1 Answers

If you are native compiling (host and target being the same machine so, not cross-compilation), then consider passing -march=native to clang

See also the user manual of the Clang compiler.

Notice that the Clang compiler is open source. You are allowed to download its source code and improve it.

like image 149
Basile Starynkevitch Avatar answered Dec 07 '25 21:12

Basile Starynkevitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!