Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine what architectures gcc supports?

GCC supports a -march switch that allows you to specify the architecture you are targeting - allowing it to tune instruction sequences for that platform as well as using instructions that might be available on the platform which aren't available on the "default" or base version of the architecture.

For example, -march=skylake will tell the compiler to target Skylake CPUs, including using instruction sets available on Skylake such as AVX2.

How can I tell what values for -march the local version of gcc supports? Newer versions helpfully list the valid arguments when an invalid argument is passed, but older versions do not.

like image 785
BeeOnRope Avatar asked Nov 15 '17 04:11

BeeOnRope


3 Answers

With gcc7 and later, gcc will print the values it supports as part of the error message.

$ gcc -E -march=help -xc /dev/null
# 1 "/dev/null"
cc1: error: bad value (‘help’) 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 bonnell atom silvermont slm knl 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

I checked on Godbolt, and x86 gcc6.x and earlier just say error: bad value (invalid) for -march= switch even with -v.

It also doesn't work with clang5.0 or ICC18.


This is target-specific: ARM gcc6.3 does produce a list of supported -march values, or -mcpu=.

like image 65
Peter Cordes Avatar answered Nov 03 '22 02:11

Peter Cordes


For gcc-7.2.0, it's here: https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Options.html#x86-Options

You could go to gcc online documentation. Then, find the manual for the version you are interested. Following that, go to machine dependent options section. If you are looking into x86, jump to the "x86 options" section. Now, search "-march."

I haven't checked the old gcc versions. Another way you could try is to check out the source code, and open the source code that keeps the literal strings for the supported arch.

svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc_trunk
cd gcc_trunk

Then, maybe, you could try like this:

find . -type f | egrep "*\.(c|cc|cpp|h|hpp)$" | xargs egrep '"skylake-avx'

As of today, the literal strings are kept in ./gcc/config/i386/i386.c in case of x86 architectures.

%P.S.

As Peter mentioned, it seems machine-specific. I suspect that there isn't a standard/desired behavior that lists available march values. For example, if gcc has been just ported to a brand-new instruction set architecture, LEG--as opposed to ARM--, it does not necessarily have a command-line option to list all supported march values.

Fortunately, it seems like some newer gcc versions provide a way to do so. If you do need such an option for old gccs, writing a gcc plugin, which might work from gcc 4.5 or so, could be taken into consideration:

gcc plugin

simple gcc plugin how to

Gcc plugins are plugged-in to an existing gcc by adding some command-line options. Gcc has APIs for plugins. All you need would be to write a code that checks the information such as gcc version, the arch that runs gcc, etc, and that prints out the list of the supported march.

like image 26
Stephen Avatar answered Nov 03 '22 02:11

Stephen


Use the detailed help page:

gcc -v --help

Look for the option -march=CPU, for example in gcc v4.8.4

  -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,
                           k6, k6_2, athlon, opteron, k8, amdfam10, bdver1,
                           bdver2, bdver3, btver1, btver2
                          EXTENSION is combination of:
                           8087, 287, 387, no87, mmx, nommx, sse, sse2, sse3,
                           ssse3, sse4.1, sse4.2, sse4, nosse, avx, avx2,
                           avx512f, avx512cd, avx512er, avx512pf, noavx, vmx,
                           vmfunc, smx, xsave, xsaveopt, aes, pclmul, fsgsbase,
                           rdrnd, f16c, bmi2, fma, fma4, xop, lwp, movbe, cx16,
                           ept, lzcnt, hle, rtm, invpcid, clflush, nop, syscall,
                           rdtscp, 3dnow, 3dnowa, padlock, svme, sse4a, abm,
                           bmi, tbm, adx, rdseed, prfchw, smap, mpx, sha,
                           clflushopt, xsavec, xsaves, prefetchwt1
like image 22
BitByteDog Avatar answered Nov 03 '22 01:11

BitByteDog