From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3692 invoked by alias); 19 Dec 2007 02:07:32 -0000 Received: (qmail 3510 invoked by uid 22791); 19 Dec 2007 02:07:31 -0000 X-Spam-Check-By: sourceware.org Received: from qmta03.emeryville.ca.mail.comcast.net (HELO QMTA03.emeryville.ca.mail.comcast.net) (76.96.30.32) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 19 Dec 2007 02:07:24 +0000 Received: from OMTA09.emeryville.ca.mail.comcast.net ([76.96.30.20]) by QMTA03.emeryville.ca.mail.comcast.net with comcast id SR6s1Y0070S2fkC0A06n00; Wed, 19 Dec 2007 02:07:29 +0000 Received: from lucon.org ([24.6.230.138]) by OMTA09.emeryville.ca.mail.comcast.net with comcast id SS7U1Y0072zoa488V00000; Wed, 19 Dec 2007 02:07:28 +0000 X-Authority-Analysis: v=1.0 c=1 a=bb96pJ7XoGF7rpomGO8A:9 a=dkpRMpEUQV6G5Zb3gmLlxYPfHwAA:4 a=LY0hPdMaydYA:10 Received: by lucon.org (Postfix, from userid 500) id 33C23F8251; Tue, 18 Dec 2007 18:07:22 -0800 (PST) Date: Wed, 19 Dec 2007 02:18:00 -0000 From: "H.J. Lu" To: Ross Ridge Cc: gcc@gcc.gnu.org Subject: Re: A proposal to align GCC stack Message-ID: <20071219020722.GB15046@lucon.org> References: <20071218233125.5586173D25@caffeine.csclub.uwaterloo.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071218233125.5586173D25@caffeine.csclub.uwaterloo.ca> User-Agent: Mutt/1.5.17 (2007-11-01) X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg00553.txt.bz2 On Tue, Dec 18, 2007 at 06:31:25PM -0500, Ross Ridge wrote: > Ye, Joey writes: > >i. STACK_BOUNDARY in bits, which is enforced by hardware, 32 for i386 > >and 64 for x86_64. It is the minimum stack boundary. It is fixed. > > Ross Ridge wrote: > >Strictly speaking by the above definition it would be 8 for i386. > >The hardware doesn't force the stack to be 32-bit aligned, it just > >performs poorly if it isn't. > > Robert Dewar writes: > >First, although for some types, the accesses may work, the optimizer > >is allowed to assume that data is properly aligned, and could possibly > >generate incorrect code ... > > That's not enforced by hardware. > > >Second, I am pretty sure there are SSE types that require > >alignment at the hardware levell, even on the i386 > > This isn't a restriction on stack aligment. It's a restriction on what > kinds of machine types can be accessed on the stack. > > As I mentioned later in my message STACK_BOUNDARY shouldn't be defined in > terms of hardware, but in terms of the ABI. While the i386 allows the > stack pointer to bet set to any value, by convention the stack pointer > is always kept 4-byte aligned at all times. GCC should never generate > code that that would violate this requirement, even in leaf-functions > or transitorily during the prologue/epilogue. >From gcc internal manual: -- Macro: STACK_BOUNDARY Define this macro to the minimum alignment enforced by hardware for the stack pointer on this machine. The definition is a C expression for the desired alignment (measured in bits). This value is used as a default if `PREFERRED_STACK_BOUNDARY' is not defined. On most machines, this should be the same as `PARM_BOUNDARY'. Since x86 always push/pop stack by decrementing/incrementing address size, it makes senses to define STACK_BOUNDARY as address size. It has nothing to do with application binary interface (ABI). > > This is different than the proposed ABI_STACK_BOUNDARY macro which defines The proposed ABI_STACK_BOUNDARY defines the value specified by the various psABIs which gcc conforms. > the possibily stricter aligment the ABI requires at function entry. Since > most i386 ABIs don't require a stricter alignment, that has ment that > SSE types couldn't be located on the stack. Currently you can get around > this problem by changing the ABI using -fperferred-stack-boundary or by No, gcc works around by setting ix86_preferred_stack_boundary = 128; by default. > forcing an SSE compatible alignment using -mstackrealign or __attribute__ > ((force_align_arg_pointer)). Joey Ye's proposal is another solution > to this problem where GCC would automatically force an SSE compatible > aligment when SSE types are used on the stack. > Our proposal isn't just "another" solution. It is a solution for generic stack alignment problems. H.J.