assembly - 'instruction prefixes' 在现代 x86 中意味着什么

标签 assembly x86 prefix

为了理解为什么 Bulldozer 表现不佳,我一直在看 Agner Fog 的优秀微架构书,在第 178 页的 bulldozer 下有这一段。

Instructions with up to three prefixes can be decoded in one clock cycle. There is a very large penalty for instructions with more than three prefixes. Instructions with 4-7 prefixes take 14-15 clock cycles extra to decode. Instructions with 8-11 prefixes take 20-22 clock cycles extra, and instructions with 12-14 prefixes take 27 - 28 clock cycles extra. It is therefore not recommended to make NOP instructions longer with more than three prefixes. The prefix count for this rule includes operand size, address size, segment, repeat, lock, REX and XOP prefixes. A three-bytes VEX prefix counts as one, while a two-bytes VEX prefix does not count. Escape codes (0F, 0F38, 0F3A) do not count.

当我搜索前缀时,我遇到了远远超出我能力的技术性定义。或者,建议将它们限制为每条指令 4 个,这与上面的摘录相冲突。

简单来说,有人可以解释一下它们是什么/做什么以及为什么你可能想在指令上添加最多 14+ 而不是将其分解?

最佳答案

通常,您可以根据需要使用尽可能多的数量,由预期的指令和操作数决定。汇编器会自动发出一些前缀,而其他前缀则需要手动使用。

他们提到的情况是多字节 NOP传统上用于对齐填充,其想法是使用单个但适当长的指令来节省资源。显然,事实证明,使用更多的前缀只是为了保持单个指令的性能可能比使用带有较少前缀的两条指令的性能更差。

The prefix count for this rule includes operand size, address size, segment, repeat, lock, REX and XOP prefixes. A three-bytes VEX prefix counts as one, while a two-bytes VEX prefix does not count.

示例:

  • 操作数大小:可以在32位和16位寄存器之间切换,例如mov ax, [foo]编码与 mov eax, [foo] 相同但带有前缀66h
  • 地址大小:可以在 32/16 或 64/32 位地址大小之间切换,例如mov [eax], foo编码与 mov [rax], foo 相同但带有前缀67h (64位模式)
  • segment:可以覆盖所使用的段,例如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, 1add eax, 1 相同但带有前缀41h
  • XOP、VEX:与向量指令子集一起使用

关于assembly - 'instruction prefixes' 在现代 x86 中意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35379820/

相关文章:

c++ - 跨平台 SIMD 调用可能只用一个可执行文件吗?

jquery-ui - jqueryui 自动完成 : lists entries with search terms in middle

assembly - Ada 和组装

linux - 是否可以在 Linux x86 GAS 程序集中创建没有系统调用的线程?

c - 为什么 number++ 使用 EAX 而 number-- 使用 ECX?

assembly - 为何完成旅行?

assembly - 16位及更高版本的x86汇编乘法和除法指令操作数

assembly - 只有一个操作数的 SHR

bash,emacs 绑定(bind)的数字前缀?

url - Http.sys URL 前缀注册如何转换为 IIS 绑定(bind)配置?