I am running a C code with SIMD instructions to test my environment. I am running this in Codeblocks and Windows 10
#include <immintrin.h>
#include <stdio.h>
#define ARRAY_LENGTH 8
int main(int argc, char* argv[]) {
__m256i first = _mm256_set_epi32(10, 20, 30, 40, 50, 60, 70, 80);
__m256i second = _mm256_set_epi32(5, 5, 5, 5, 5, 5, 5, 5);
__m256i result = _mm256_add_epi32(first, second);
int* values = (int*) &result;
for (
unsigned short i = 0;
i < ARRAY_LENGTH;
i += 1
) {
printf("%d ", values[i]);
}
return 0;
}
This code is throwing an error and I am not able to fix it.
error: inlining failed in call to always_inline '_mm256_add_epi32': target specific option mismatch
Is it something caused due to Codeblocks environment?
You have to enable the corresponding instruction set natively by adding the correct option to the gcc command line, -mavx2 in this case, i.e.:
gcc -O2 -mavx2 prog.c -o prog
Of course, you have to make sure that the CPU you run the program on indeed supports this instruction set extension, otherwise you will run into a segmentation fault or illegal instruction exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With