问题描述
《英特尔软件开发手册》关于neg
指令的内容是这样的:
The Intel Software Development Manual says this about the neg
instruction:
我认为将AF和CF设置为好像由neg %eax
替换为
I thought that AF and CF would be set as if neg %eax
were replaced by,
not %eax # bitwise negation
add $1, %eax
但是事实并非如此,在实际CPU上取反0x6ffffef5会设置AF和CF.
But that's not the case, negating 0x6ffffef5 on a real CPU sets AF and CF.
推荐答案
neg
将所有标志设置为与sub
从0开始获得的标志相同.
neg
sets all flags identically to what you'd get with a sub
from 0.
此指令序列将所有标志(包括AF和CF)设置为与neg %eax
相同:
This sequence of instructions sets all flags (including AF and CF) identically to neg %eax
:
xor %ecx, %ecx
sub %eax, %ecx # ecx = 0 - eax
英特尔文档确实确实指定了此内容,但没有在neg
本身的指令集参考(第2卷)条目的伪代码操作"部分或受标志影响的部分中指定.
Intel's documentation does actually specify this, but not in the pseudo-code Operation section or in the flags-affected section of the instruction-set reference (Volume 2) entry for neg
itself.
neg
的描述"部分的文本包括此块:
The text of the Description section for neg
includes this nugget:
并且在第1卷:
[有关CMP的段落]
[a paragraph about CMP]
NEG(取反)指令从零中减去有符号整数操作数.
,其措辞不那么直接.
The existence of this documentation was pointed out by a comment on an earlier duplicate of this question which isn't as directly worded.
我不知道第1卷的整个章节都对说明进行了说明.事实证明,第2卷insn集合参考中并没有提到Intel关于单个指令的所有内容.
I didn't know that vol.1 had a whole section explaining the instructions. It turns out that not everything Intel has to say about individual instructions is in the Volume 2 insn set reference.
有证据表明,neg
在内部解码为与Intel CPU上的sub
指令相同的uop. (例如,neg [mem]
可以与ALU op微融合负载,以及微融合存储地址和存储数据uops.inc [mem]
只能微融合存储,因此总共有3个融合域哦.
There's some evidence that neg
decodes internally to the same uop as a sub
instruction on Intel CPUs. (e.g. neg [mem]
can micro-fuse the load with the ALU op, as well as micro-fusing the store-address and store-data uops. inc [mem]
can only micro-fuse the store, so it's 3 total fused-domain uops).
这篇关于NEG指令如何影响x86上的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!