From owner-freebsd-hackers Mon Feb 4 21:59:30 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 6B2E737B41D for ; Mon, 4 Feb 2002 21:59:25 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id QAA09574; Tue, 5 Feb 2002 16:59:03 +1100 Date: Tue, 5 Feb 2002 17:01:29 +1100 (EST) From: Bruce Evans X-X-Sender: To: Mike Silbersack Cc: Michal Mertl , , Subject: Re: stack alignment issues In-Reply-To: <20020204120547.B2144-100000@patrocles.silby.com> Message-ID: <20020205163210.G25358-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 4 Feb 2002, Mike Silbersack wrote: > On Tue, 5 Feb 2002, Bruce Evans wrote: > > I haven't done anything to clean up the patch. I hope the problem > > will go away in future versions of gcc (align the stack at runtime in > > the few routines that actually need it). > > Well, if Linux aligns the initial stack, the chance that gcc will have > auto-alignment added sounds to be about zero. You might as well go ahead > with your patch when you get a chance. There is a nonzero probability that the pessimization of aligning in almost every routine will be fixed someday. Actually, the pessimization is worse -- the alignment is done before every call. Example: %%% foo.c: foo() { f1(1); f2(2); f3(3.0); } %%% gcc -O -S [-mpreferred-stack boundary] currently generates the following code for this: %%% .file "z.c" .version "01.01" gcc2_compiled.: .section .rodata .p2align 3 .LC0: .long 0x0,0x40080000 .text .p2align 2,0x90 .globl foo .type foo,@function foo: pushl %ebp movl %esp,%ebp subl $8,%esp # <- extra instruction for alignment (for foo) addl $-12,%esp # <- extra instruction for alignment (for f1) pushl $1 call f1 addl $-12,%esp # <- extra instruction for alignment (for f2) pushl $2 call f2 addl $32,%esp # <- extra instruction for alignment (for f3) addl $-8,%esp # <- extra instruction for alignment (another) pushl .LC0+4 pushl .LC0 call f3 leave ret .Lfe1: .size foo,.Lfe1-foo .ident "GCC: (c) 2.95.3 20010315 (release)" %%% It should generate something like: .file "z.c" .version "01.01" gcc2_compiled.: .section .rodata .p2align 3 .LC0: .long 0x0,0x40080000 .text .p2align 2,0x90 .globl foo .type foo,@function foo: pushl %ebp movl %esp,%ebp andl $~0x7,%esp # <- extra instruction for alignment (for foo) # Only needed since foo() uses FPU. # 8-byte alignment enough for doubles? # Adjust in prologue so that there are # hopefully no alloca()-like issues, except # we need a frame pointer to restore %esp. pushl $1 call f1 pushl $2 call f2 pushl .LC0+4 pushl .LC0 call f3 leave ret .Lfe1: .size foo,.Lfe1-foo .ident "GCC: (c) 2.95.3 20010315 (release)" %%% My patch is not suitable for committing verbatim. It has 2 or 3 XXX's. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message