Is there a way to get gcc to output the available -march=arch options? I'm getting build errors (tried -march=x86_64
) and I don't know what my options are.
The compiler I'm using is a proprietary wrapper around gcc that doesn't seem to like -march=skylake
. The flags should be the same so I assume whatever options I'd send to gcc to dump architectures would be the same for this wrapper.
I managed to cause gcc to error with a bogus parameter and it dumped a list, but I'm not seeing that now that I'm going through a wrapper.
How can I get gcc to tell me what it supports?
In contrast to -mtune= cpu-type , which merely tunes the generated code for the specified cpu-type , -march= cpu-type allows GCC to generate code that may not run at all on processors other than the one indicated. Specifying -march= cpu-type implies -mtune= cpu-type , except where noted otherwise.
The first and most important option is -march . This tells the compiler what code it should produce for the system's processor architecture (or arch); it tells GCC that it should produce code for a certain kind of CPU.
Bookmark this question. Show activity on this post. With most C/C++ compilers, there's a flag passable to the compiler, -march=native , which tells the compiler to tune generated code for the micro-architecture and ISA extensions of the host CPU.
If gcc -v shows GCC was configured with a --with-arch option (or --with-arch-32 and/or --with-arch-64 ) then that's what will be the default. Without a --with-arch option (and if there isn't a custom specs file in use) then the arch used will be the default for the target.
-march=foo implies -mtune=foo unless you also specify a different -mtune. This is one reason why using -march is better than just enabling options like -mavx without doing anything about tuning.
There's also -mtune=generic. generic makes GCC produce code that runs best on current CPUs (meaning of generic changes from one version of GCC to another). There are rumors on Gentoo forums that -march=X -mtune=generic produces code that runs faster on X than code produced by -march=X -mtune=X does (or just -march=X, as -mtune=X is implied).
This is one reason why using -march is better than just enabling options like -mavx without doing anything about tuning. Caveat: -march=native on a CPU that GCC doesn't specifically recognize will still enable new instruction sets that GCC can detect, but will leave -mtune=generic.
While the baseline version of -marchis -march=x86-64, the baseline / default tune option is -mtune=generic. That aims to not be terrible anywhere, avoiding performance pitfalls even at the cost of extra instructions or code size.
Use gcc --target-help
-march=CPU[,+EXTENSION...]
generate code for CPU and EXTENSION, CPU is one of:
generic32, generic64, i386, i486, i586, i686,
pentium, pentiumpro, pentiumii, pentiumiii, pentium4,
prescott, nocona, core, core2, corei7, l1om, k1om,
iamcu, k6, k6_2, athlon, opteron, k8, amdfam10,
bdver1, bdver2, bdver3, bdver4, znver1, znver2,
btver1, btver2
...
It's often not the general architecture like x86
or x86-64
but the specific microarchitectures. But there's x86-64
(not x86_64
) for a generic x86 CPU with 64-bit extensions. The full list for each architecture can be found on GCC's -march
manual. For x86:
-march=cpu-type
Generate instructions for the machine type cpu-type. In contrast to
-mtune=cpu-type
, which merely tunes the generated code for the specifiedcpu-type
,-march=cpu-type
allows GCC to generate code that may not run at all on processors other than the one indicated. Specifying-march=cpu-type
implies-mtune=cpu-type
....
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-march-13
While the baseline version of -march
is -march=x86-64
, the baseline / default tune option is -mtune=generic
. That aims to not be terrible anywhere, avoiding performance pitfalls even at the cost of extra instructions or code size.
-march=native
will pick the right arch and tune settings for the machine the compiler is running on, or tune=generic
if the compiler doesn't recognize the specific model of CPU it's running on.
(e.g. old gcc on a Skylake, will still enable -mavx2 -mpopcnt -mbmi2
and so on, but will set -mtune=generic
instead of something closer to appropriate.)
Using gcc --target-help
seems like it might be the right idea, but gives an incomplete list.
One workaround on modern gcc versions is just to pass a bogus value to -march
:
$ gcc --target-help -march=foo
cc1: error: bad value (‘foo’) for ‘-march=’ switch
cc1: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client icelake-server bonnell atom silvermont slm knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 btver1 btver2 native
...
Note how there are many more options compared to the output from --target-help
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With