问题描述
要了解为什么推土机不如我,我一直在看Agner Fog出色的微体系结构书,在第178页的推土机下有此段落.
To get an understanding on why Bulldozer was subpar I've been looking at Agner Fog's excellent microarchitecture book, in it on page 178 under bulldozer it has this paragraph.
当我搜索前缀时,我遇到了非常技术性的定义,这远远超出了我的能力范围.或者,建议每条指令将其限制为4个,这与上述摘录有冲突.
When I searched for prefixes I was hit with very technical definitions far and away beyond my abilities. Or, suggested that they were limited to 4 per instruction which conflicts with the above extract.
因此,简单地说,有人可以解释他们是什么/做什么,以及为什么您可能希望将最多14个以上的内容添加到一条指令上而不是将其分解?
So in simple terms, can someone explain what they are/do and why you might want to tack on up to 14+ onto an instruction instead of breaking it up?
推荐答案
通常,您会根据需要使用尽可能多的内容,并使用预期的指令和操作数来确定.汇编器会自动发出某些前缀,而其他一些则可以手动使用.
Normally you use as many as needed, with the intended instruction and operands determining that. The assembler issues some of the prefixes automatically, while others you get to use manually.
他们提到的情况是针对多字节NOP
,该字节传统上用于对齐填充,其思想是使用一条但适当长的指令来节省资源.显然,事实证明,使用更多前缀只是为了保持一条指令可能比使用两条前缀更少的指令要差.
The case they mention is for multi-byte NOP
which is traditionally used for alignment padding where the idea is to use a single but appropriately long instruction to conserve resources. Apparently it turns out that using more prefixes just to keep it a single instruction may be worse performer than using two instructions with less prefixes.
示例:
- 操作数大小:可以在32位和16位寄存器之间切换,例如
- 地址大小:可以在32/16或64/32位地址大小之间切换,例如
mov [eax], foo
的编码与mov [rax], foo
相同,但前缀为67h
(在64位模式下) - 细分:可以覆盖所使用的细分,例如
mov [fs:eax], foo
的编码与mov [eax], foo
相同,但前缀为64h
. - repeat:与字符串指令一起重复使用,例如
rep cmpsb
的编码与cmpsb
相同,但前缀为f3h
- lock:与某些指令结合使用以使其原子化,例如
lock add [foo], 1
的编码与add [foo], 1
相同,但前缀为f0h
- REX.W:用于切换到64位操作数大小,例如
add rax, 1
的编码与add eax, 1
相同,但前缀为48h
- REX.R,B,X:用作modr/m字节的扩展名以访问额外的寄存器,例如
add r8d, 1
与add eax, 1
相同,但前缀为41h
- XOP,VEX:与向量指令子集一起使用
mov ax, [foo]
的编码与mov eax, [foo]
相同,但前缀为 - operand size: can switch between 32 and 16 bit registers, e.g.
mov ax, [foo]
is encoded the same asmov eax, [foo]
but with the prefix66h
- address size: can switch between 32/16 or 64/32 bit address sizes, e.g.
mov [eax], foo
is encoded the same asmov [rax], foo
but with the prefix67h
(in 64 bit mode) - segment: can override the segment used, e.g.
mov [fs:eax], foo
is encoded the same asmov [eax], foo
but with the prefix64h
. - repeat: used with string instructions for repeating, e.g.
rep cmpsb
is the encoded the same ascmpsb
but with the prefixf3h
- lock: used with certain instructions to make them atomic, e.g.
lock add [foo], 1
is encoded the same asadd [foo], 1
but with the prefixf0h
- REX.W: used to switch to 64 bit operand size, e.g.
add rax, 1
is encoded the same asadd eax, 1
but with the prefix48h
- REX.R,B,X: used as extensions of the modr/m byte to access extra registers, e.g.
add r8d, 1
is the same asadd eax, 1
but with the prefix41h
- XOP, VEX: used with vector instruction subsets
这篇关于“指令前缀"在现代x86中是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!