[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK1hOcO+Z+1z7AMvTjH9efATMRaMN-pSvP4kdEJYXPPfLU_-oA@mail.gmail.com>
Date: Thu, 26 Mar 2015 11:07:42 +0100
From: Denys Vlasenko <vda.linux@...glemail.com>
To: Ingo Molnar <mingo@...nel.org>
Cc: Borislav Petkov <bp@...en8.de>,
Linus Torvalds <torvalds@...ux-foundation.org>,
"H. Peter Anvin" <hpa@...or.com>,
Denys Vlasenko <dvlasenk@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Andy Lutomirski <luto@...capital.net>,
Oleg Nesterov <oleg@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Alexei Starovoitov <ast@...mgrid.com>,
Will Drewry <wad@...omium.org>,
Kees Cook <keescook@...omium.org>,
"the arch/x86 maintainers" <x86@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 3/4] x86/asm/entry/64: use smaller insns
On Thu, Mar 26, 2015 at 10:37 AM, Ingo Molnar <mingo@...nel.org> 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.
In my experiment, GAS uses 10-byte insn only for constants which
won't work with 7-byte encoding; or if I explicitly ask for "movabs":
_start: .globl _start
mov $0x12345678,%edi # 5 bytes
mov $0x12345678,%rdi # 7 bytes
movq $0x12345678,%rdi # 7 bytes
mov $0x80000000,%rdi # 10 bytes
mov $0x123456789,%rdi # 10 bytes
movabs $0x12345678,%rdi # 10 bytes
$ gcc -nostartfiles -nostdlib -c z.S && objdump -dr z.o
z.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_start>:
0: bf 78 56 34 12 mov $0x12345678,%edi
5: 48 c7 c7 78 56 34 12 mov $0x12345678,%rdi
c: 48 c7 c7 78 56 34 12 mov $0x12345678,%rdi
13: 48 bf 00 00 00 80 00 movabs $0x80000000,%rdi
1a: 00 00 00
1d: 48 bf 89 67 45 23 01 movabs $0x123456789,%rdi
24: 00 00 00
27: 48 bf 78 56 34 12 00 movabs $0x12345678,%rdi
2e: 00 00 00
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists