Reputation: 519
In Visual Studio 2013, there is a flag located in the project Configuration Properties > C/C++ > Code Generation
page called Enable Enhanced Instruction Set
. It can be set to SSE
, SSE2
, AVX
, AVX2
or IA32
.
IA32
is specified as making "No Enhanced Instructions".
If I compile and run a project that uses AVX
instructions, while having the flag set as IA32
, it still works. Running the program also works fine.
What does the compiler do on this scenario ? Does it keep AVX
instructions as they are because they are "hardcoded" and not compiler-generated instructions ? Or does the compiler replace these AVX
SIMD instructions with SISD instructions ?
Upvotes: 1
Views: 1810
Reputation: 9678
It's worth considering that the old x87 FPU ops aren't valid within an x64 binary, so if you have 64bit output enabled, setting IA-32 will be ignored, and SSE2 will be used as the default. If you happen to use AVX2 intrinsics within an app compiled for AVX (or prior instruction set), the AVX2 instructions will still be emitted within the binary, which will cause an app to hard crash on a CPU that doesn't support AVX2. See for example this:
Even though we are asking for x87, f() gets compiled using SSE2 (hence movss v.s. fld), and g() gets compiled using AVX2 instructions (e.g. vmovss).
So in effect, Visual Studio allows you to insert AVX2 instrinsics into an SSE binary, but you will have to do your own cpuid checks to make sure the CPU supports those features before running that code.
Upvotes: 2