问题描述
我试图为此清理 GCC 手册页,但仍然不明白,真的.
I tried to scrub the GCC man page for this, but still don't get it, really.
-march
和 -mtune
有什么区别?
什么时候只使用-march
,而不是同时使用?是否有可能只 -mtune
?
When does one use just -march
, vs. both? Is it ever possible to just -mtune
?
推荐答案
如果你使用 -march
那么 GCC 将可以自由生成在指定 CPU 上工作的指令,但(通常)不在架构系列中较早的 CPU.
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.
如果您只使用 -mtune
,那么编译器将生成适用于其中任何一个的代码,但会偏向在您指定的特定 CPU 上运行速度最快的指令序列.例如为该 CPU 适当地设置循环展开启发式.
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
暗示 -mtune=foo
,除非您还指定了不同的 -mtune
.这就是为什么使用 -march
比只启用像 -mavx
这样的选项而不做任何调整更好的原因之一.
-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.
警告:在 GCC 未明确识别的 CPU 上的 -march=native
仍会启用 GCC 可以检测到的新指令集,但会保留 -mtune=generic
.如果您希望它编写好的代码,请使用了解您的 CPU 的足够新的 GCC.
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.
这篇关于GCC:march 与 mtune 有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!