public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tim Prince <tprince@computer.org>
To: "Dave Korn" <dk@artimi.com>,<cygwin@cygwin.com>
Cc: <gcc@gcc.gnu.org>
Subject: RE: g++ 3.4.0 cygwin, codegen SSE & alignement issues
Date: Wed, 28 Apr 2004 17:04:00 -0000	[thread overview]
Message-ID: <6.0.1.1.0.20040428085945.01f20a90@imap.myrealbox.com> (raw)
In-Reply-To: <NUTMEGeBa1kg3AmsfGd00000090@NUTMEG.CAM.ARTIMI.COM>

At 08:51 AM 4/28/2004, Dave Korn wrote:

> > -----Original Message-----
> > From: cygwin-owner On Behalf Of tbp
> > Sent: 28 April 2004 16:16
>
>[  Now x-posted to gcc list, since it's seemingly a gcc issue rather than a
>cygwin environment issue.  You might also care to refer to the current
>discussion on the gcc-patches mailing list under the thread
>
>"Re: [Bug target/15106] Vector varargs failure for AltiVec on ppc32 linux"
>
>which is discussing the same problem arising on ppc targets.  ]
>
>
> > > It's an ABI incompatiblity issue, GCC expects a 16-byte
> > aligned stack,
> > > but the Windows ABI, to the extent one actually exists, only assumes
> > > a 4-byte aligned stack (and even that's not a strict requirement).
> > Is there an official or semi official way to fix it or do i have to
> > insert something like "mov esp, eax; and 0x15, eax; sub eax,
> > esp" where
> > it helps?
>
>   I'd recommend doing that in the startup code in gcc's crt0.s myself.  The
>real question is, is the compiler generating code that guarantees the stack
>stays aligned, so you can do that just once at startup?  It certainly ought
>to.
>
> > I understand -mfpmath=sse is flagged as experimental. What i
> > don't get
> > is why the compiler emits totally bogus code when using default
> > switches: -O3 -march=k8 -> boom. -O3 -march=pentium4 -> boom.
>
>   The division of responsibility between OS, CRT/startup and compiler leaves
>it unclear as to who is supposed to ensure the alignment of the stack.  IMO,
>it's a compiler's problem to see to it that if the stack starts off aligned
>it remains that way, by always generating stack frames that are a multiple
>of the alignment requirement, and it's the CRT/startup code that is
>responsible for mediating between what the compiled code requires and what
>the underlying OS/arch provides for stack pointer alignment at startup.  Of
>course, that's IMO, and my opinion is hardly definitive.
>

As Dave said, this is more of a gcc than a cygwin issue, provided that 
cygwin doesn't defeat one of the functions of binutils or gcc (as it did in 
the past).  gcc made a decision, which is different from commercial 
compilers, that stack alignment requires each function to be compiled with 
-mpreferred-stack-alignment=4, so that it passes an aligned stack to the 
callee.  binutils has to be built with maximum alignment set to at least 4 
(as cygwin has done for some months now).

stack-alignment=4 is a default for gcc, except when -Os is specified.  If 
you use -Os, and any called function uses SSE, you must over-ride the stack 
alignment set by -Os.  gcc did this because the stack alignment caused some 
applications (which don't use SSE) to fail with stack overflow.  I suspect 
this could happen in cygwin.

Because of the different division of responsibilities, if a function built 
by gcc is called by a function built by a commercial compiler (or by gcc 
-Os), the stack has a 75% probability of being mis-aligned.  It may be 
possible to overcome this by having a wrapper function between, which is 
built by gcc with alignment specified, but does not use SSE.

Presumably, there is a performance advantage to gcc of assuming that the 
caller passes an aligned stack, but not enough to persuade commercial 
compilers to adopt a compatible scheme.


Tim Prince 

  reply	other threads:[~2004-04-28 16:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <408FCABF.2050702@ompf.org>
2004-04-28 16:56 ` Dave Korn
2004-04-28 17:04   ` Tim Prince [this message]
2004-04-28 19:17     ` Dave Korn
2004-04-28 20:42     ` Brian Ford
2004-04-29  4:49 Ross Ridge
2004-04-29  6:12 ` DJ Delorie
2004-04-29  6:46 Ross Ridge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6.0.1.1.0.20040428085945.01f20a90@imap.myrealbox.com \
    --to=tprince@computer.org \
    --cc=cygwin@cygwin.com \
    --cc=dk@artimi.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).