for the flags:
-march
flag specifies the target architecture version, i.e. a set of ISA extensions. -march
tells the compiler that it is allowed to generate special instructions to use the specific hardware features of a given architecture. (On x86, it also implies -mtune=
the same thing)
-mtune
flag specifies the target microarchitecture (specific CPU) to tune for, in terms of choices like loop unrolling thresholds or instruction choices that don't affect compatibility. -mtune
without any -march
tells the compiler to generate a binary with a bare-minimum, generic instruction set but also tune the resulting binary code for the specified target. The -mtune
flag does not enable the compiler to use the special hardware features of the target, but can be used with it.
It can be used with -march
to set a baseline CPU feature level, but also to tune for a specific CPU, which is hopefully representative of the CPUs you care most about actually running on. Even if that's newer than the oldest CPUs that match the -march
setting, i.e. which could run the binary.
-mcpu
flag on ARM specifies the target processor to tune for, and to use any extension it supports. GCC uses this name to derive the name of the target ARM architecture (as if specified by -march
), such as -mcpu=cortex-a53
implying -march=
and -mtune=
settings.
GCC and LLVM agree on the meanings of these flags, e.g. both treating -mcpu
as a synonym for -mtune
on x86-64, but being different on ARM.
example:
-mcpu=cortex-a8
will perform specific optimisations for the Cortex-A8 such as instruction scheduling and will produce better performing code on that core, as well as using instructions it supports but older CPUs don't.
-march=armv7-a
just selects the ARMv7-a architecture which tells the compiler
that it can use the instructions in ARMv7-a, but it will leave the performance tuning / instruction scheduling heuristics at their default values, aimed at running well across a range of CPUs of the overall architecture. (e.g. ARM in general, not restricted to ones new enough to support the selected -march
, unfortunately).
‑mtune=thunderx2t99
, the compiler will generate a binary that is optimized for the ThunderX2 microarchitecture. This binary will not take full advantage of all the ThunderX2’s hardware features; But the binary may be somewhat optimized for the ThunderX2 and it will be more portable than a binary compiled with ‑march=armv8.1‑a
for instance.
The x86 convention is to let -march
imply -mtune
as stated here in the docs
Links:
For further reference maybe these arm docs help
Deprecation of -mcpu as synonym of -mtune
Docs for x86 options