From owner-freebsd-bugs Sat Aug 10 13:50:16 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2B50437B406 for ; Sat, 10 Aug 2002 13:50:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 84A9A43E72 for ; Sat, 10 Aug 2002 13:50:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7AKo2JU013656 for ; Sat, 10 Aug 2002 13:50:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7AKo2Kj013655; Sat, 10 Aug 2002 13:50:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1422937B400 for ; Sat, 10 Aug 2002 13:41:00 -0700 (PDT) Received: from berkeley.sa2c.net (berkeley.sa2c.net [61.194.193.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7C3BA43E3B for ; Sat, 10 Aug 2002 13:40:59 -0700 (PDT) (envelope-from sa2c@sa2c.net) Received: by berkeley.sa2c.net (Postfix, from userid 3104) id 33B9231D; Sun, 11 Aug 2002 05:40:58 +0900 (JST) Message-Id: <20020810204058.33B9231D@berkeley.sa2c.net> Date: Sun, 11 Aug 2002 05:40:58 +0900 (JST) From: NIIMI Satoshi Reply-To: NIIMI Satoshi To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: i386/41528: better stack alignment patch for lib/csu/i386-elf/ Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 41528 >Category: i386 >Synopsis: better stack alignment patch for lib/csu/i386-elf/ >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Aug 10 13:50:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: NIIMI Satoshi >Release: FreeBSD 4.6.1-RELEASE-p10 i386 >Organization: >Environment: System: FreeBSD berkeley.sa2c.net 4.6.1-RELEASE-p10 FreeBSD 4.6.1-RELEASE-p10 #5: Fri Aug 9 16:33:26 JST 2002 sa2c@berkeley.sa2c.net:/usr/obj/usr/src/sys/SA2C_NET i386 >Description: Although system C compiler, GCC, maintains stack pointer to keep aligned to 2**preferred-stack-boundary byte, C startup routine does not care about this. This causes a big performance penalty for floating point operations with variables in stack frame because IA32 CPUs are optimized to operate with aligned data. >How-To-Repeat: With code: foo.c #include main() { double x; printf("%p\n", &x); } % cc foo.c % ./a.out 0xbfbff730 <- aligned to 8-byte boundary. % ./a.out a 0xbfbff72c <- not aligned if command line arguments are passed. >Fix: (gcc 3.1 masks %esp by himself, so this patch might not be required for -current.) --- diff begins here --- Index: stable/lib/csu/i386-elf/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.4.2.1 diff -u -r1.4.2.1 crt1.c --- stable/lib/csu/i386-elf/crt1.c 30 Oct 2000 20:32:24 -0000 1.4.2.1 +++ stable/lib/csu/i386-elf/crt1.c 10 Aug 2002 19:40:54 -0000 @@ -93,7 +93,33 @@ monstartup(&eprol, &etext); #endif _init(); +#if 0 exit( main(argc, argv, env) ); +#else + /* + * GCC expects stack frame to be aligned like following figure. + * + * +--------------+ + * |%ebp (if any) | + * +--------------+ + * |return address| + * +--------------+ --- aligned by PREFERRED_STACK_BOUNDARY + * | arguments | + * | : | + * | : | + */ + __asm__ (" + subl $12, %%esp # create stack frame for arguments + andl $~0xf, %%esp # align stack to 16-byte boundary + movl %0, 0(%%esp) + movl %1, 4(%%esp) + movl %2, 8(%%esp) + call main + movl %%eax, 0(%%esp) + call exit + hlt # do not return + " : : "r"(argc), "r"(argv), "r"(env)); +#endif } #ifdef GCRT Index: current/lib/csu/i386-elf/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.9 diff -u -r1.9 crt1.c --- current/lib/csu/i386-elf/crt1.c 16 Jul 2002 12:28:49 -0000 1.9 +++ current/lib/csu/i386-elf/crt1.c 10 Aug 2002 19:46:42 -0000 @@ -100,7 +100,33 @@ monstartup(&eprol, &etext); #endif _init(); +#if 0 exit( main(argc, argv, env) ); +#else + /* + * GCC expects stack frame to be aligned like following figure. + * + * +--------------+ + * |%ebp (if any) | + * +--------------+ + * |return address| + * +--------------+ --- aligned by PREFERRED_STACK_BOUNDARY + * | arguments | + * | : | + * | : | + */ + __asm__ (" + subl $12, %%esp # create stack frame for arguments + andl $~0xf, %%esp # align stack to 16-byte boundary + movl %0, 0(%%esp) + movl %1, 4(%%esp) + movl %2, 8(%%esp) + call main + movl %%eax, 0(%%esp) + call exit + hlt # do not return + " : : "r"(argc), "r"(argv), "r"(env)); +#endif } #ifdef GCRT --- diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message