mov %esi, %esi 在 x86-64 上是否为空操作? [英] Is mov %esi, %esi a no-op or not on x86-64?

查看:18
本文介绍了mov %esi, %esi 在 x86-64 上是否为空操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Linux 内核头文件之一中的注释感到有些困惑,arch/x86/include/asm/nops.h.它指出

I am a bit confused by the comment in one of the header files for the Linux kernel, arch/x86/include/asm/nops.h. It states that

<...> 以下指令不是 64 位模式下的 nops,对于 64 位模式,请改用 K8 或 P6 nops
movl %esi,%esi
leal 0x00(%esi),%esi
<...>

<...> the following instructions are NOT nops in 64-bit mode, for 64-bit mode use K8 or P6 nops instead
movl %esi,%esi
leal 0x00(%esi),%esi
<...>

我猜作者在那里暗示了机器指令(分别是89 F6"和8D 76 00")而不是汇编指令.根据 Intel Software Developer's Manual Vol 2A 中 LEA 的描述,后一条指令 (lea 0x00(%rsi), %esi) 与前一条指令的作用相同, mov %esi,%esi.

I guess the author implied the machine instructions ('89 F6' and '8D 76 00', respectively) there rather than assembly instructions. It follows from the description of LEA in Intel Software Developer's Manual Vol 2A that the latter instruction (lea 0x00(%rsi), %esi) does the same as the the former, mov %esi,%esi.

所以这归结为一个问题,mov %esi,%esi 是否实际上是 x86-64 上的无操作.

So this reduces to the question, whether mov %esi,%esi is actually a no-op on x86-64.

mov 不会改变标志.这种 mov 也不会改变内存.看起来,如果它改变了 %rip 之外的东西,那应该是通用寄存器.但我不知道它是如何改变 %rsi 或其他内容的.如果你操作通用寄存器的下半部分,上半部分应该不会改变,对吗?

mov does not change flags. This kind of mov does not change memory either. It seems, if it changes something besides %rip, that should be general purpose registers. But I have no clue how it can change the contents of %rsi or whatever. If you manipulate the lower half of a general purpose register, the upper half should not change, right?

推荐答案

mov %esi, %esi

将 %rsi 的高 32 位清零,因此在 x86_64 上不是空操作.

zeros out the high 32 bits of %rsi, and is therefore not a no-op on x86_64.

为什么 32 位寄存器上的 x86-64 指令将完整 64 位寄存器的上半部分归零?

这篇关于mov %esi, %esi 在 x86-64 上是否为空操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆