Is mov %esi, %esi a no-op or not on x86-64?

后端 未结 2 709
花落未央
花落未央 2020-12-17 22:05

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

<...> the following

相关标签:
2条回答
  • 2020-12-17 22:20
    mov %esi, %esi
    

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

    See Why do x86-64 instructions on 32-bit registers zero the upper part of the full 64-bit register?

    0 讨论(0)
  • 2020-12-17 22:28
    #include <stdio.h>
    
    int main(int argc, char * argv[])
    {
        void * reg_rsi = 0;
    
        asm (
            "movq $0x1234567812345678, %%rsi;\n"
            "movl %%esi, %%esi;\n"
            "movq %%rsi, %0;\n"
            : "=r" (reg_rsi)
            : /* no inputs */
            : /* no clobbered */
        );
    
        printf("reg_rsi = %p\n", reg_rsi);
    
        return 0;
    }
    

    This gives "reg_rsi = 0x12345678" for my x86_64 machine.

    0 讨论(0)
提交回复
热议问题