开发者

GCC hotpatching?

开发者 https://www.devze.com 2023-01-24 03:11 出处:网络
When I compile this piece of code unsigned char A[] = {1, 2, 3, 4}; unsigned int f (unsigned int x) { return A[x];

When I compile this piece of code

unsigned char A[] = {1, 2, 3, 4};

unsigned int
f (unsigned int x)
{
  return A[x];
}

gcc outputs

mov edi, edi
movzx  eax, BYTE PTR A[rdi]
ret

on a x86_64 machine开发者_如何学JAVA.

The question is: why is a nop instruction (mov edi, edi) there for?

Im am using gcc-4.4.4.


In 64-bit mode, mov edi, edi is not a no-op. What it does is set the top 32 bits of rdi to 0.

This is a special case of the general fact that all 32-bit operations clear the top 32 bits of the destination register in 64-bit mode. (This allows a more efficient CPU than leaving them unchanged and is perhaps more useful as well.)

0

精彩评论

暂无评论...
验证码 换一张
取 消