本文介绍了"rep;" 是什么意思?不;"在 x86 汇编中是什么意思?和“暂停"一样吗?操作说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 什么是rep;nop 是什么意思?
  • pause指令一样吗?
  • 它是否与 rep nop 相同(没有分号)?
  • 与简单的 nop 指令有何不同?
  • 它在 AMD 和 Intel 处理器上的表现是否不同?
  • (额外奖励)这些说明的官方文档在哪里?

这个问题的动机

的评论中进行了一些讨论后另一个问题,我意识到我不知道什么rep;nop; 表示在 x86(或 x86-64)程序集中.而且我在网上也找不到很好的解释.

我知道 rep 是一个前缀,意思是 重复下一条指令 cx 次"(或者至少是,在旧的16 位 x86 程序集).根据这个维基百科摘要表,似乎rep 只能与 movsstoscmpslodsscas 一起使用(但也许这个限制在较新的处理器上被删除了).因此,我认为 rep nop(不带分号)会重复 nop 操作 cx 次.

然而,经过进一步的搜索,我更加困惑了.似乎 rep;noppause 映射到完全相同的操作码,并且 pausenop 的行为略有不同.一些 2005 年的旧邮件 说了不同的话:>

  • 尽量不要消耗太多电量"
  • 它等价于 'nop' 只是使用 2 字节编码."
  • 这对英特尔来说很神奇.就像'nop 但让另一个 HT 兄弟运行'"
  • 英特尔暂停,Athlon 快速填充"

由于这些不同的意见,我无法理解正确的含义.

它正在 Linux 内核中使用(在 i386x86_64),连同此注释:/* REP NOP (PAUSE) 是插入的好东西进入忙等待循环.*/它也在在BeRTOS中使用,与评论.

解决方案

rep;nop 确实与pause 指令相同(操作码F390).它可能用于尚不支持 pause 指令的汇编程序.在以前的处理器上,这只是什么都不做,就像 nop 一样,只是两个字节.在支持超线程的新处理器上,它用作向处理器提示您正在执行自旋循环以提高性能.来自 Intel 的指令参考:

提高自旋等待循环的性能.在执行自旋等待循环"时,奔腾 4 或英特尔至强处理器在退出循环时会遭受严重的性能损失,因为它检测到可能的内存顺序违规.PAUSE 指令向处理器提示代码序列是一个自旋等待循环.处理器使用这个提示来避免大多数情况下的内存顺序违规,从而大大提高了处理器性能.为此,建议在所有自旋等待循环中放置一条 PAUSE 指令.

  • What does rep; nop mean?
  • Is it the same as pause instruction?
  • Is it the same as rep nop (without the semi-colon)?
  • What's the difference to the simple nop instruction?
  • Does it behave differently on AMD and Intel processors?
  • (bonus) Where is the official documentation for these instructions?

Motivation for this question

After some discussion in the comments of another question, I realized that I don't know what rep; nop; means in x86 (or x86-64) assembly. And also I couldn't find a good explanation on the web.

I know that rep is a prefix that means "repeat the next instruction cx times" (or at least it was, in old 16-bit x86 assembly). According to this summary table at Wikipedia, it seems rep can only be used with movs, stos, cmps, lods, scas (but maybe this limitation was removed on newer processors). Thus, I would think rep nop (without semi-colon) would repeat a nop operation cx times.

However, after further searching, I got even more confused. It seems that rep; nop and pause map to the exactly same opcode, and pause has a bit different behavior than just nop. Some old mail from 2005 said different things:

  • "try not to burn too much power"
  • "it is equivalent to 'nop' just with 2 byte encoding."
  • "it is magic on intel. Its like 'nop but let the other HT sibling run'"
  • "it is pause on intel and fast padding on Athlon"

With these different opinions, I couldn't understand the correct meaning.

It's being used in Linux kernel (on both i386 and x86_64), together with this comment: /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ It is also being used in BeRTOS, with the same comment.

解决方案

rep; nop is indeed the same as the pause instruction (opcode F390). It might be used for assemblers which don't support the pause instruction yet. On previous processors, this simply did nothing, just like nop but in two bytes. On new processors which support hyperthreading, it is used as a hint to the processor that you are executing a spinloop to increase performance. From Intel's instruction reference:

这篇关于"rep;" 是什么意思?不;"在 x86 汇编中是什么意思?和“暂停"一样吗?操作说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:42