GCC hotpatching?

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

by machine x86_64.

The question is: why does the nop instruction (mov edi, edi) exist for?

I am using gcc-4.4.4.

+5
source share
1 answer

In 64-bit mode is mov edi, edinot a no-op. It sets the top 32 bits rdito 0.

This is a special case of the general fact that all 32-bit operations clear the upper 32 bits of the target register in 64-bit mode. (This allows you to use a more efficient processor than leaving them unchanged and possibly more useful.)

+3
source

All Articles