visual-studiox86-64intelcompiler-optimization

Compiling with instruction set extensions


From my understanding, when I compile in Visual Studio for x64, it is using some baseline version of the x86-64 ISA.

Newer instruction sets from Intel have been supersets of old ones, so if I want to compile for my own processor, I should be able to use tons of new instructions that are not being included by default when I compile (since by default it only uses the x64 baseline). After scouring the internet for a while, I found this page: https://en.wikipedia.org/wiki/X86-64. It has a list of "microarchitecture levels", v1-v4, where each level consists of a set of instruction set extensions, which in turn consist of a set of instructions.

My own processor is new and should support v4, so I'm trying to find a way to compile using all of the available instructions. From what I could tell, MSVC does not support most of these extensions, although I did find in project properties, under C/C++, code generation, there is an option for "enable enhanced instruction set". It looks like I can enable SSE or SSE2 through it, but certainly not the comprehensive list on the wiki page. So I went and installed the Intel C++ compiler, but I can't find a way to make that compiler use the advanced options either.

So my question is: how can I tell the compiler to use the full set of instructions of my processor (v4)?


Solution

  • For MSVC, the compiler’s /arch switch only supports AVX, AVX2 or AVX512, so it isn’t possible to obtain a binary which is specifically tuned for your CPU.

    For other compilers, including Intel, GCC, and Clang, use the -march=native flag to unlock the use of any instructions supported by your CPU.