比零比任何其他数字快吗?

编程入门 行业动态 更新时间:2024-10-09 01:22:19
本文介绍了比零比任何其他数字快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

if(!test)

快于

if(test==-1)

我可以生产装配,但生产的装配太多,我不能找到我之后的细节。我希望有人只知道答案。我猜想他们是一样的,除非大多数CPU架构有某种比较零的捷径。

I can produce assembly but there is too much assembly produced and I can never locate the particulars I'm after. I was hoping someone just knows the answer. I would guess they are the same unless most CPU architectures have some sort of "compare to zero" short cut.

感谢任何帮助。

推荐答案

通常情况下,是的。在典型的处理器测试零,或测试符号(负/正)是简单的条件代码检查。这意味着可以重新排序指令以省略测试指令。在伪汇编中,考虑这样:

Typically, yes. In typical processors testing against zero, or testing sign (negative/positive) are simple condition code checks. This means that instructions can be re-ordered to omit a test instruction. In pseudo assembly, consider this:

Loop: LOADCC r1, test // load test into register 1, and set condition codes BCZS Loop // If zero was set, go to Loop

测试1:

Loop: LOAD r1, test // load test into register 1 SUBT r1, 1 // Subtract Test instruction, with destination suppressed BCNE Loop // If not equal to 1, go to Loop

现在对于通常的优化前免责声明:您的程序太慢了?不进行优化,对其进行配置。

Now for the usual pre-optimization disclaimer: Is your program too slow? Don't optimize, profile it.

更多推荐

比零比任何其他数字快吗?

本文发布于:2023-11-27 18:05:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639040.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!