问题描述
我阅读了各种优化指南,声称 ADD 1 比在 x86 中使用 INC 更快.这是真的吗?
I have read various optimization guides that claim ADD 1 is faster than using INC in x86. Is this really true?
推荐答案
在一些微架构上,对于一些指令流,INC
会导致部分标志更新停顿"(因为它更新了一些的标志,同时保留其他标志).ADD
设置所有标志的值,因此不会冒这种停顿的风险.
On some micro-architectures, with some instruction streams, INC
will incur a "partial flags update stall" (because it updates some of the flags while preserving the others). ADD
sets the value of all of the flags, and so does not risk such a stall.
ADD
并不总是比 INC
快,但它几乎总是至少一样快(在某些较旧的微架构上有一些极端情况,但它们非常罕见),有时速度明显更快.
ADD
is not always faster than INC
, but it is almost always at least as fast (there are a few corner cases on certain older micro-architectures, but they are exceedingly rare), and sometimes significantly faster.
更多详情,请参阅Intel 的优化参考手册 或 Agner Fog 的微架构笔记.
For more details, consult Intel's Optimization Reference Manual or Agner Fog's micro-architecture notes.
这篇关于ADD 1 真的比 INC 快吗?x86的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!