Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling AVX2 program on Mavericks

Tags:

c++

c

gcc

avx

avx2

I try to compile a dummy AVX2 program on my Mac OS 10.9 with gcc version 4.9.0 20131201

//dummy program
#include <immintrin.h> // AVX2
#include <stdio.h>
int main(int argc, char* argv[]) {
   __m256i reg =  _mm256_set1_epi8(1);
   __m256i result = _mm256_max_epu8(reg,reg);
   printf("%d",((int *)&result)[0]);
}

I used this command to compile

gcc -mavx -O0 test.C

and I get this error

In function 'int main(int, char**)':
avx2intrin.h:373:1: 
error: inlining failed in call to always_inline 
'__m256i _mm256_max_epu8(__m256i, __m256i)': target specific option mismatch
 _mm256_max_epu8 (__m256i __A, __m256i __B)

The _mm256_max_epu8 uses an always_inline attribute. Is this the problem?

I also get the problem if I compile with O3.

What am I doing wrong?

like image 221
martin s Avatar asked Apr 23 '26 06:04

martin s


1 Answers

To compile for a target with AVX2, use -mavx2.

like image 190
Eric Postpischil Avatar answered Apr 24 '26 19:04

Eric Postpischil



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!