Re: [PATCH 3/4] x86/asm/entry/64: use smaller insns

From: Ingo Molnar
Date: Thu Mar 26 2015 - 05:37:43 EST



* Borislav Petkov <bp@xxxxxxxxx> wrote:

> On Wed, Mar 25, 2015 at 05:05:50PM -0700, Linus Torvalds wrote:
> > so 'as' is clearly just stupid. It already takes the size of the
> > constant into account and generates different instructions. Why not
> > for the common 32-bit case too?
>
> I think the destination register mandates which insn to use:
>
> mov $0x12345678, %rdi
> mov $0x12345678, %edi
>
> ...
>
> 15: 48 c7 c7 78 56 34 12 mov $0x12345678,%rdi
> 1c: bf 78 56 34 12 mov $0x12345678,%edi
>
> and 'as' is perhaps not insolent enough to go and change it when
> seeing the 32-bit constant.

Well, GAS generally has the freedom to use more optimal opcodes, as
long as behavior on the CPU matches what the specified opcode does.

Saying that 'movq $0x1, %rdi' should map to the longer variant is
defensible: there should probably always be a way to specify a very
specific opcode even if it's not optimal - say I want to fill in an
alignment space and don't want to use an extra NOP.

But here GAS generates the 10-byte opcode even if 'mov $0x12345678,
%rdi' is used, which is an unforced error.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/