Date: 2 Dec 1999 09:40:37 -0000 From: Ville-Pertti Keinonen <will@iki.fi> To: current@freebsd.org Cc: marcel@scc.nl, dillon@apollo.backplane.com, bde@zeta.org.au Subject: Re: kernel: -mpreferred-stack-boundary=2 ?? Message-ID: <19991202094037.4079.qmail@ns.demophon.com>
next in thread | raw e-mail | index | archive | help
Ok, I've checked, and in -current, userland stack boundary alignment is useless because the stack pointer is initially only aligned on a word-boundary. I've also verified that the correct alignment is indeed expected to apply to frame pointers, i.e. stored frame pointers are at aligned stack slots and the current frame pointer points to an aligned address. Alignment can be verified by doing something like this: struct { int a[4]; } x __attribute__((aligned(16))); printf("offset: %u\n", (unsigned int)&x & 15); You have to run the program using different arguments and argument lengths to ensure that what you get isn't coincidental. When things are working properly, the above should always print 0. Note that double-alignment vs. word-alignment can really have >30% performance impact, at least on an Athlon and one meaningless floating point microbenchmark (operations on small, fixed-sized matrices...maybe it isn't even *that* meaningless). Here's a patch against -current that fixes this problem (note that this doesn't maintain alignment for constructors, and it isn't very pretty because it has to be done all in asm...): Index: crt1.c =================================================================== RCS file: /m/cvs/freebsd/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.4 diff -u -r1.4 crt1.c --- crt1.c 1999/08/27 23:57:57 1.4 +++ crt1.c 1999/12/02 09:02:05 @@ -92,7 +92,17 @@ monstartup(&eprol, &etext); #endif _init(); - exit( main(argc, argv, env) ); + asm volatile("andl $~15,%%esp;" + "addl $4,%%esp;" + "pushl %2;" + "pushl %1;" + "pushl %0;" + "call main;" + "movl %%eax,(%%esp);" + "call exit" + : : "rm" (argc), "rm" (argv), "rm" (env)); + for (;;) + ; } #ifdef GCRT To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991202094037.4079.qmail>