What does “rep; nop;” mean in x86 assembly? Is it the same as the “pause” instruction?

后端 未结 2 1638
一生所求
一生所求 2020-11-28 03:25
  • What does rep; nop mean?
  • Is it the same as pause instruction?
  • Is it the same as rep nop (without the semi-colo
2条回答
  •  天涯浪人
    2020-11-28 04:01

    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:

    Improves the performance of spin-wait loops. When executing a “spin-wait loop,” a Pentium 4 or Intel Xeon processor suffers a severe performance penalty when exiting the loop because it detects a possible memory order violation. The PAUSE instruction provides a hint to the processor that the code sequence is a spin-wait loop. The processor uses this hint to avoid the memory order violation in most situations, which greatly improves processor performance. For this reason, it is recommended that a PAUSE instruction be placed in all spin-wait loops.

提交回复
热议问题