I have a strange behaviour when trying to cast a vector __m256i to an int array. There is no warning and this is really alarming. It happens with gcc 9/10 and with optimization higher than 1 (see below).
int main(int argc, char** argv)
{
int array[8] = {10, 20, 30, 40, 50, 60, 70, 80};
__m256i values = _mm256_loadu_si256((__m256i*) array);
int* ptr = (int*) &values; // this cast seems to be problematic
printf("WRONG:\n");
for (int i = 0; i < 8; i++)
printf("%d ", ptr[i]);
printf("\n");
int ptr1[8];
_mm256_storeu_si256 ( (__m256i*)ptr1, values);
printf("GOOD:\n");
for (int i = 0; i < 8; i++)
printf("%d ", ptr1[i]);
printf("\n");
}
Try to compile with this:
gcc -g -O3 -march=broadwell main.c -o main