bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

x86-64: gas could do a better job on movq imm32, r64


From: David Wragg
Subject: x86-64: gas could do a better job on movq imm32, r64
Date: Mon, 27 Aug 2007 05:12:29 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.1 (gnu/linux)

Hi,

These two instructions are equivalent:

movq $0x12345678, %rax
movl $0x12345678, %eax

But gas (2.17.50.0.12 on Fedora 7) chooses a longer encoding for the
former:

  22:   48 c7 c0 78 56 34 12    mov    $0x12345678,%rax
  29:   b8 78 56 34 12          mov    $0x12345678,%eax

In fact, for any non-negative immediate constant that fits in 32 bits,
it's better to use the "mov imm32, r32" instruction (0xb8), rather
than "mov imm32, r64" (REX 0xc7).  Negative constants need the
sign-extending effect of REX 0xc7.

gcc-generated assembly doesn't seem to run into this, but hand-coded
assembly often does (see for example the x86-64 Linux kernel).


David Wragg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]