或"eax,eax"之间的区别在于:和“测试eax,eax"; [英] Difference between "or eax,eax" and "test eax,eax"

查看:101
本文介绍了或"eax,eax"之间的区别在于:和“测试eax,eax";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

or eax,eaxtest eax,eax有什么区别?我已经看到不同的编译器会产生相同的比较结果,而且就文档而言,它们做的事情完全相同,所以我想知道为什么它们都不全部使用test eax,eax.考虑它and eax,eax会以相同的方式设置标志,但是我在freepascal,delphi或msVC ++中都没有看到它.

What's the difference between or eax,eax and test eax,eax? I've seen different compilers produce both for the same comparison and as far as documentation goes they do exactly the same thing, so I'm wondering why they don't all use test eax,eax. Thinking about it and eax,eax would set the flags in an identical fashion as either but I haven't seen it in either freepascal, delp or msVC++.

我确实在delphi中编译了一些asm块,并检查了汇编源,所有3种形式的操作码长度都完全相同,并且还检查了Intel性能PDF,并指出它们具有相同的延迟和吞吐量.

I did compile some asm blocks in delphi and checked out the assembler source and all 3 forms are the exact same length in opcodes and also checked the intel performance PDF and it says they have the same latency and throughput.


问题特别是关于特定情况test eax,eaxor eax,eaxand eax,eax之间的区别.对于寄存器,标志,操作码长度,等待时间,吞吐量,这3个都给出完全相同的结果.但是为了测试是否为0,是否为零或是否为有符号,某些编译器将使用test eax,eax,而另一些则使用or eax,eax,我想知道为什么它们不都使用test eax,eax,因为这会使代码非常轻微更清晰.


The question is specifically about the difference between the specific cases test eax,eax, or eax,eax and and eax,eax. All 3 give completely identical results for registers, flags, opcode length, latency, throughput. And yet for testing if 0, if not zero, or if signed, some compilers will use test eax,eax while some use or eax,eax, and I was wondering why they aren't all using test eax,eax since it makes the code very slightly clearer.

Edit2:
作为参考,我在家,这里只有较旧的msvc ++和Delphi,但是如果测试变量是否为零,则msvc ++会执行test eax,eax,而Delphi会执行or eax,eax.


For reference I'm at home and only have and older msvc++ and Delphi here, but testing a variable if zero, msvc++ does test eax,eax, while Delphi does or eax,eax.

推荐答案

通常,testand之间的唯一区别是test <reg>, <reg>不会修改其操作数.本质上,test应用and操作,丢弃结果的非标记部分.如果操作数相同,则结果将相同(or).

In general, the only difference between test and and is that test <reg>, <reg> doesn't modify its operands. Essentially test applies an and operation, discarding the non-flags part of the result. If the operands are identical, the results will be the same (as will or).

test可能是更好的指令选择.因此,除非必须重复计算,否则通常首选test. cmp/sub也是如此.

test can be a superior instruction choice because of things like micro-op fusion. As a result, test is usually preferred unless the computation would have to be repeated. The same thing goes for cmp/sub.

在Intel的文档中搜索融合",您应该找到详细信息.

Search Intel's doc for "fusion" and you should find the details.

这篇关于或"eax,eax"之间的区别在于:和“测试eax,eax";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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