When debugging some code using AVX, I was getting results which made no sense. I reduced my program to the following:
#include <iostream>
#include <immintrin.h>
int main()
{
while (1)
{
static float v[] = {1, 2, 3, 4, 5, 6, 7, 8};
__m256 v8 = _mm256_load_ps(v);
std::cout << v8.m256_f32[2] << v8.m256_f32[5];
}
}
When I run this program, it prints 36
endlessly, which is correct (it prints 3
, and then 6
). If I set a breakpoint in a debugger inside the loop, and do single-step, it prints 30
. If I remove the breakpoint and continue the program, it starts printing 36
again. I see the same behavior in Release/Debug, Win32/x86 (4 combinations).
To be able to use AVX, I set "Enable Enhanced Instruction Set" to "Advanced Vector Extensions (/arch:AVX)" in Configuration Properties - C/C++ - Code Generation. Did I forget to set some other configuration?
As a result of this behavior, I cannot use the debugger to debug my real program (not included here). This is annoying.
Did I do anything wrong? Can I fix this behavior?
My Visual Studio is: MS Visual Studio Professional 2017, version 15.9.3.
Visual studio 2017 15.9.7 fixes a bug which corrupts AVX/MPX/AVX512 registers while Debugging, you should update to the latest version, 15.9.3 is nearly 3 years old.