c++visual-c++compiler-options

Make MSVC optimize for a specific microarch


With GCC/Clang/ICC/etc I can use

How do I do these with MSVC?


Solution

  • Microsoft's compiler splits this into two separate areas. One is generating code specific to a particular instruction set, which won't work on a CPU that doesn't support that instruction set. This falls under its -arch: flag. The x64 compiler only supports two variants here: AVX and AVX2 (or no flag, which supports up to SSE2). The x86 version of the compiler adds a couple more flags for older instruction set extensions (e.g., SSE), but I doubt you care about that any more.

    The other category is generating code that will work on any of a number of architectures, but favors one over another. This is supported by the -favor switch, which supports targets of ATOM, AMD64, INTEL64, and "blend" (which basically means to try not to favor one at the expense of others).

    It doesn't have any (documented) flags for something like favoring Skylake vs. (say) Haswell or Broadwell though.