GCC:march 和 mtune 有什么不同? [英] GCC: how is march different from mtune?
问题描述
我试图为此擦洗 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.
警告:-march=native
在 GCC 未明确识别的 CPU 上仍将启用 GCC 可以检测的新指令集,但会保留 -mtune=generic
.如果你想让它编写好的代码,请使用一个足够新的 GCC,它了解你的 CPU.
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 有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!