ADD 1 真的比 INC 快吗?x86 [英] Is ADD 1 really faster than INC ? x86

查看:29
本文介绍了ADD 1 真的比 INC 快吗?x86的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了各种优化指南,声称 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆