3

I'd like to know if there are other compilers than gcc and clang that provide something like an -march=native option, and if so, what that option is. I already understand from another question (Automatically building for best available platform in visual c++ (equivalent to gcc's -march=native)) that Microsoft's compilers do not have that option (unless it's implied in the option that activates the SSE2 instruction set, up to and excluding AVX and higher at least).

The use case is simple: provide a cmake set-up and thus the user with an option to activate and build with support for all the "intrinsics" his or her CPU supports. We currently have detection logic for the actual intrinsics we target (e.g. SSE4.2 and/or PCLMUL on x86) but that logic will probably get very complex when more platforms and compilers have to be taken into consideration. Simplifying them could lead to situations where the compiler starts to use unsupported instruction sets outside of the intended places protected by runtime checks.

Community
  • 1
  • 1
RJVB
  • 698
  • 8
  • 18
  • Make a [cpu dispatcher](https://stackoverflow.com/questions/18868235/preventing-gcc-from-automatically-using-avx-and-fma-instructions-when-compiled-w/25911959#25911959). – Z boson Jun 12 '15 at 14:01
  • That's not exactly what I'm looking for. There are already already runtime checks. The problem that can arise when you build with a compiler that requires activation of the intrinsics functions (say, -msse4) is that it will be able to use that instruction set throughout the compilation unit, including in expressions where you don't expect it. I ran into this with code built with SSE4.2 enabled and executed on a CPU without SSE4.2: it crashed on an expression of the form `a = b + c` because the compiler had identified that it could do that better with SSE4.2 . – RJVB Jun 12 '15 at 16:01
  • The advantage of `-march=native` is that it will expand to the appropriate list of `-mfoo` and `-mno-bar` options that are appropriate for the current CPU. It is kind of double purpose with the cpu dispatcher approach, but it provides the advantage that you can build the full project with a single flag, and benefit from optimisations everywhere they can be made. – RJVB Jun 12 '15 at 16:05

1 Answers1

6

Currently, the Microsoft Visual C++ compiler doesn't provide equivalent flags to march=native. You'll have to figure out the appropriate flags manually or using a script before building the code.

Regarding the Intel C++ compiler, the xHost and QxHost flags have basically the same purpose.

Hadi Brais
  • 22,259
  • 3
  • 54
  • 95