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?
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.)