I am having a really weird bug with Intel Intrinsics on an AVX2 function, which I would want to share here. Either it is me doing something wrong (I cannot really see what at this point), or a bug in the library.
I have this simple code inside my main.c:
__int64 test = 0xFFFF'FFFF'FFFF'FFFF;
__m256i ymm = _mm256_set_epi64x(0x0000'0000'0000'0000,
0x0000'0000'0000'0000,
0x0000'0000'0000'0000,
test);
The value that gets assigned to variable ymm is for some strange reason:
ymm.m256i_i64[0] = 0xffff'ffff'ffff'ffff
ymm.m256i_i64[1] = 0x0000'0000'0000'0000
ymm.m256i_i64[2] = 0x0000'ffff'0000'0000
ymm.m256i_i64[3] = 0x0000'0000'0000'0000
I have been debugging for hours at this point, but cannot see why ymm.m256i_i64[2]
gets this rogue value. Please help!
Fun/weird fact: If I write this C-code:
__m256i ymm = _mm256_set_epi64x(0x0000'0000'0000'0000,
0x0000'0000'0000'0000,
0x0000'0000'0000'0000,
0xFFFF'FFFF'FFFF'FFFF);
Then the values get correctly set to:
ymm.m256i_i64[0] = 0xffff'ffff'ffff'ffff
ymm.m256i_i64[1] = 0x0000'0000'0000'0000
ymm.m256i_i64[2] = 0x0000'0000'0000'0000
ymm.m256i_i64[3] = 0x0000'0000'0000'0000
Note: I am using Visual Studio; both their compiler and their debugging tools, as below example picture shows:
The printf following the code printed: ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 ff ff ff 00 ff ff 00 00 ff 00 00 00 ff 00 00 00
.
It seems that the rogue changes in the other variables in the struct can change, since they are not the same after I added the loop, as they were before... (I don't know if the loop specifically made the change).
Edit: I am no hawk to assembly.... Not at all. I added the generated assembly-code though in the picture below, in case that can help anyone to help me understand what's going on, and if it is a bug not caused by me: