Port-i386 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fix GCC's preferred stack alignment to match psABI



On Tue, Sep 11, 2012 at 09:49:19PM +0100, David Laight wrote:
> On Tue, Sep 11, 2012 at 10:22:48PM +0200, Joerg Sonnenberger wrote:
> > Hi all,
> > the attached patch consists of two parts. The first part ensures that
> > GCC honours the SYSV ABI on i386 as used by NetBSD. The second part
> > adjusts the alignment of stack variables, so that double and complex
> > double as well as long long are not aligned to 64bit by default, if the
> > stack alignment is smaller. This avoids triggering unnecessary stack
> > reliagnments.
> 
> For those of us who don't have an innate knowledge of gcc config stuff
> explain the exact effect of these proposed changes.
> Including what some of the variables/constants actually contain.
> I can also see 5 changes, not 2.

There are two changes, the two header files which redefine the default
preferred stack alignment to what the ABI mandates and the changes in
i386.c to implement the rest.

> I presume/hope that they have no effect on 64bit compilations.
> This isn't 100% obvious.

MIN_STACK_BOUNDARY uses TARGET_64BIT.

> I suspect that one effects of the current code it to align the locals
> on their natural boundary with respect to the stack pointer
> (ie align large items at > 4byte boundaries).

The problem is that the stack pointer generally is not aligned
correctly, so this code doesn't really work at expected.

> 16 byte alignment is needed for the 128bit media instructions (I think
> later AMD cpus have instructions for unaligned accesses, but the intel
> ones don't).

Correct, both SSE and MMX want to have 128bit alignment for some
instructions, AVX wants 256bit alignment in other cases.

> This means that it would be nice to maintain the current stack layout
> except that we force realignment if any locals require 16 byte alignemnt
> (rather than the current 32).
> 
> I think your changes remove the code that tries to keep 64bit
> items aligned.

The change to i386.c ensures that double and long double do not force
the stack alignment to 64bit, if the default alignment is smaller. In
other words, if a function uses them and nothing forces 64bit alignment
or larger AND the user hasn't requested it either, no stack realignment
happens. If another stack variable requires 64bit alignment, natural
alignment is used for double and long long as well.

Joerg


Home | Main Index | Thread Index | Old Index