I tried to scrub the GCC man page for this, but still don't get it, really.
What's the difference between -march
and -mtune
?
When does one use just -march
, vs. both? Is it ever possible to just -mtune
?
If you use -march
then GCC will be free to generate instructions that work on the specified CPU, but (typically) not on earlier CPUs in the architecture family.
If you just use -mtune
, then the compiler will generate code that works on any of them, but will favour instruction sequences that run fastest on the specific CPU you indicated. e.g. setting loop-unrolling heuristics appropriately for that CPU.
-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.
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
. Use a new enough GCC that knows about your CPU if you want it to make good code.