是不是比<=更快?我在读一本书,作者说if( a < 901 )比if( a <= 900 ).不完全像这个简单的例子,但是循环复杂的代码有轻微的性能变化。我认为这必须对生成的机器代码做一些操作,以防它是真的。
3 回答
汪汪一只猫
TA贡献1898条经验 获得超8个赞
Comparison Subtraction---------- -----------A < B --> A - B < 0A = B --> A - B = 0A > B --> A - B > 0
A < B
Comparison Subtraction Carry Bit Zero Bit---------- ----------- --------- --------A < B --> A - B < 0 0 0A = B --> A - B = 0 1 1A > B --> A - B > 0 1 0
A < B
;; Implementation of "if (A < B) goto address;"cmp A, B ;; compare A to B bcz address ;; Branch if Carry is Zero to the new address
;; Implementation of "if (A <= B) goto address;"cmp A, B ;; compare A to B bcz address ;; branch if A < B bzs address ;; also, Branch if the Zero bit is Set
Helenr
TA贡献1780条经验 获得超4个赞
<
<=
<=
<
- 3 回答
- 0 关注
- 295 浏览
添加回答
举报
0/150
提交
取消