public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Craig Burley <burley@gnu.org>
To: law@cygnus.com
Cc: d.love@dl.ac.uk, egcs@cygnus.com
Subject: ix86 `double' alignment (was Re: egcs-1.1 release schedule)
Date: Mon, 22 Jun 1998 12:04:00 -0000	[thread overview]
Message-ID: <199806221811.OAA07410@melange.gnu.org> (raw)
In-Reply-To: <4986.898489891@hurl.cygnus.com>

>  In message < rzqaf79nru7.fsf@djlvig.dl.ac.uk >you write:
>  > _Please_ include some means of allowing Fortran (at least) to get
>  > stack-allocated doubles double-aligned on x86 (modulo libc).  (I hope
>  > I haven't missed this going in at some stage!)  The one-line patch for
>  > STACK_BOUNDARY used by g77 0.5.22 is good enough.
>I'm still waiting on some kind of solution that doesn't totally break
>the ABI.

I'm willing to do some serious work to make this happen for 1.1,
which assumes it can be done in the next couple of weeks, right?

>To do this "right" you have to:
>
>	* Make sure gcc always allocates stack in multiples of 8 bytes,
>	  adding dummy outgoing args as necessary to keep the stack
>	  properly aligned at call points.
>
>	  You can't do this with STACK_BOUNDARY since that says we
>	  will 100% always have a properly aligned stack, which can
>	  never be true since we might be linking in code from
>	  another compiler which didn't keep the stack suitably
>	  aligned.

For Fortran code, we can usually hand-wave that; this case would
only come up when the call tree has an *embedded* procedure
that doesn't maintain proper alignment, and since the big
computational problem with g77 performance is in code compiled
by g77, and such code is rarely called by C code, I don't think
this would represent a huge deficiency.

>	  If the stack gets mis-aligned relative to STACK_BOUNDARY
>	  combine could end up removing a seemingly useless
>	  stack operation/address calculation.

I don't understand this, but presumably I need to look into it
further.

>	  The idea is to make sure the stack is 8 byte aligned in the
>	  common cases, but not absolutely rely on it for correct code
>	  generation.

Absolutely.

>	* Second, assuming that gcc always keeps the pointer aligned
>	  for itself, then arrange for doubles to end up 8 byte
>	  aligned relative to the stack pointer.
>
>	  If the stack gets mis-aligned due to an old module, then
>	  our doubles won't be aligned correctly, but the vast majority
>	  of the time they will be suitably aligned.
>
>	  I don't think there's any mechanism to do this when the
>	  desired alignment is less than STACK_BOUNDARY.  I fact
>	  I know that to be the case since I worked on a similar
>	  problem recently.

Okay, that makes sense to me.  We want to hit a majority of cases
anyway.  We don't care (for now) about cases where users are
combining multiple languages in weird ways, for example.

>	* The ABI is still going to mandate that some doubles in
>	  argument lists are going to be mis-aligned.  We'd have
>	  to arrange to copy them from the arglist into a suitable
>	  stack slot.  This may be more trouble than its worth.

I'm not sure how this can ever happen in the x86 architecture?

Well, I mean, not when passing argument by reference, which is
generally how g77 works anyway.

>Note that some non-ABI breaking changes to align doubles and other
>values have gone into the x86 compiler.  In particular we should be
>properly aligning all data in the static store.

Right.  The Next Big Thing is to, by default, 64-bit-align any
stack-based VAR_DECLs.  Just doing that would be Great.

What I'd like to see, and think wouldn't be too hard, is a change
that'd leave TYPE_ALIGN for doubles at 32, so g77 would still
be able to produce COMMON and EQUIVALENCE blocks ("aggregates")
containing doubles without breaking the ABI or rejecting
standard-conforming code.  (Never mind that g77 already does this
for systems like SPARC; SPARC users expect that, apparently,
while x86 users don't, mostly.)

But this change would set DECL_ALIGN for stack-based VAR_DECLs
to 64, and implement that, presumably by assuring that the
stack frame is itself 64-bit aligned.

What I don't know (having not looked into it in any detail) is
how best to ensure the stack frame is 64-bit aligned.  Presumably
%sp will always be 32-bit aligned upon entry to any procedure
(according to the ABI; perhaps the hardware?).  Is it reasonable
to just subtract an extra 8 bytes when creating the frame
pointer upon procedure entry and then NAND it with 7 to align
it?  Or would that make for problems with debugger, profiling,
and/or exception support, or is there no quick way to NAND the
frame pointer on the x86?

It seems like everyone else thinks the right way to do this is
to try to always assure %sp is 64-bit aligned across calls by
modifying all the code that is in the procedure-call chain.
That probably means an extra dummy push before odd-number-of-args
calls, etc., right?

The reason I'd generally prefer the former approach to the latter
is that either one is likely to cost some performance, but the
latter *always* costs performance since the caller doesn't know
whether the callee uses doubles, whereas the former costs only
when the procedure doing the extra dance actually uses doubles.
(Whether we can teach gcc to not do the NAND(%fp,7) if there
are no doubles on the stack is another issue.)

        tq vm, (burley)

  parent reply	other threads:[~1998-06-22 12:04 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-18  1:32 egcs-1.1 release schedule Jeffrey A Law
1998-06-19  9:02 ` Gerald Pfeifer
1998-06-19 23:47   ` Jeffrey A Law
1998-06-19 11:57 ` Dave Love
1998-06-21 21:43   ` Craig Burley
1998-06-21 23:07   ` Jeffrey A Law
1998-06-22  5:19     ` David S. Miller
1998-06-22 12:04       ` Dave Love
1998-06-22 13:45       ` Toon Moene
1998-06-22 22:29         ` Jeffrey A Law
1998-06-22 18:20       ` ix86 double alignment (was Re: egcs-1.1 release schedule) Craig Burley
1998-06-23  3:32         ` Jeffrey A Law
1998-06-23  5:13           ` Craig Burley
1998-06-23  3:32         ` David S. Miller
1998-06-23  6:30           ` Craig Burley
1998-06-22 12:04     ` Craig Burley [this message]
1998-06-23  3:32       ` ix86 `double' " Jeffrey A Law
1998-06-23  5:13         ` Craig Burley
1998-06-24  2:28           ` Jeffrey A Law
1998-06-24 14:50             ` Craig Burley
1998-06-25  0:25               ` Jeffrey A Law
1998-06-25  9:59                 ` Tim Hollebeek
1998-06-28 18:01                 ` Marc Lehmann
1998-06-22 12:04     ` egcs-1.1 release schedule Dave Love
1998-06-23  3:32       ` Craig Burley
1998-06-23  3:32       ` Jeffrey A Law
1998-06-23  9:29         ` H.J. Lu
1998-06-24 17:12           ` x86 double alignment (was egcs-1.1 release schedule) Marc Lehmann
1998-06-25  0:25             ` Jeffrey A Law
1998-06-28 18:02               ` Marc Lehmann
1998-06-25 12:33             ` PÃ¥l-Kristian Engstad
1998-06-28 18:02               ` Marc Lehmann
1998-06-25 21:48             ` Craig Burley
1998-06-25 18:53               ` Jeffrey A Law
1998-06-28 22:41               ` Marc Lehmann
1998-06-29  5:20                 ` Martin Kahlert
1998-06-29 11:08                   ` Jeffrey A Law
1998-06-29 19:43                   ` Craig Burley
1998-06-29 20:41                 ` Craig Burley
1998-06-30  0:42                   ` Jeffrey A Law
1998-06-30  8:19                     ` gcc2 merge H.J. Lu
1998-06-30 19:49                       ` Jeffrey A Law
1998-06-30  4:50                 ` x86 double alignment (was egcs-1.1 release schedule) Jeffrey A Law
1998-06-20  6:41 ` egcs-1.1 release schedule Gabriel Dos Reis
1998-06-20  9:22   ` Joe Buck
1998-06-20 15:36     ` Mark Mitchell
1998-06-21  0:07   ` Jeffrey A Law
1998-06-23  3:32 ix86 double alignment (was Re: egcs-1.1 release schedule) John Wehle
1998-06-23 15:06 ` Craig Burley
1998-06-23 22:55   ` Jeffrey A Law
1998-06-24 10:08   ` Dave Love
1998-06-24 21:23     ` Jeffrey A Law
1998-06-23 10:23 ix86 `double' " John Wehle
1998-06-23 14:56 ` Craig Burley
1998-06-23 22:55 ` Jeffrey A Law
1998-06-24 17:12 ix86 double " John Wehle
1998-06-24 21:23 ` Jeffrey A Law

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=199806221811.OAA07410@melange.gnu.org \
    --to=burley@gnu.org \
    --cc=d.love@dl.ac.uk \
    --cc=egcs@cygnus.com \
    --cc=law@cygnus.com \
    /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).