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

后端 未结 2 715
花落未央
花落未央 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:28

    #include 
    
    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.

提交回复
热议问题