Dynamic stack alignment for i386

Jan Hubicka jh@suse.cz
Wed May 29 05:02:00 GMT 2002


> This patch adds the ability to align the stack dynamically at run time.
> Credit for most of this work goes to Catherine Moore; I hope I managed
> to get all the relevant pieces out of Red Hat's tree.  Bootstrapped and
> regression tested on i686-linux.
> 
> The stack pointer is and-ed with an appropriate mask at function entry;
> to be able to access the arguments, we use %esi as argument pointer.
> There are two entry points, one which does the forced alignment, and
> another which assumes the stack was aligned on entry.  If we detect a
> call to another function that was defined in the same source file, we
> call the aligned entrypoint.  All of this is essentially what is
> recommended in Intel's documentation.
> 
> I haven't checked this in yet; I want to get a bit of feedback first.
> When do we want to enable this code?  Whenever -mmmx/-msse/-msse2 is
> enabled?  Do we want to reduce PREFERRED_STACK_ALIGNMENT to 64 again for
> normal compilations (I'd personally prefer 32, but...)?

Ideally the code should not have effect until the stack alignment is
really needed, that can be checked by keeping track of what is allocated
on the stack... preffered_stack_alignment gives us the information
partially (it will say that it should be 8 for doubles and 16 for long
doubles, so perhaps we can add required_stack_alignment...

Last time I seen the code, it blown away one register independently on
whether the alignment is needed or not, I will check after the finals to
see how it works now.

Honza



More information about the Gcc-patches mailing list