The modern toolchains support a wide range of CPU architecture tuning and instruction set targets through -march and -mtune options. These options control code generation optimizations, instruction selection, and CPU-specific scheduling behavior. Rather than relying on external documentation, the compiler itself can be queried to reveal all supported values for the current build. This tutorial explains how to get all available -march and -mtune values for gcc or g++ compiler.
The following commands list all available architecture targets recognized by the compiler:
gcc --help=target | awk '/-march= option/{getline; for(i=1;i<=NF;i++) print $i}'
g++ --help=target | awk '/-march= option/{getline; for(i=1;i<=NF;i++) print $i}'
Output may include entries such as:
x86-64
x86-64-v2
x86-64-v3
x86-64-v4
...
Command explanation:
--help=target- displays target-specific configuration details including architecture and tuning options supported by the compiler build.awk '/-march= option/{getline; ... }'- searches for the-mtune= optionsection and prints the next line where available values are listed.for(i=1;i<=NF;i++) print $i- splits the line into individual tokens and prints each supported value separately.
To display CPU tuning presets used for instruction scheduling and performance optimization:
gcc --help=target | awk '/-mtune= option/{getline; for(i=1;i<=NF;i++) print $i}'
g++ --help=target | awk '/-mtune= option/{getline; for(i=1;i<=NF;i++) print $i}'
Common tuning presets include CPU families and microarchitectures such as:
core2
nehalem
sandybridge
haswell
...
Leave a Comment
Cancel reply