From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbbCZJhk (ORCPT ); Thu, 26 Mar 2015 05:37:40 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:35179 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751227AbbCZJhh (ORCPT ); Thu, 26 Mar 2015 05:37:37 -0400 Date: Thu, 26 Mar 2015 10:37:32 +0100 From: Ingo Molnar To: Borislav Petkov Cc: Linus Torvalds , "H. Peter Anvin" , Denys Vlasenko , Steven Rostedt , Andy Lutomirski , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , the arch/x86 maintainers , Linux Kernel Mailing List Subject: Re: [PATCH 3/4] x86/asm/entry/64: use smaller insns Message-ID: <20150326093732.GC14706@gmail.com> References: <1427303896-24023-1-git-send-email-dvlasenk@redhat.com> <1427303896-24023-3-git-send-email-dvlasenk@redhat.com> <20150326092712.GA27751@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150326092712.GA27751@pd.tnic> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Borislav Petkov 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