Stack Alignment for Numerics

dsimcha dsimcha at yahoo.com
Wed Mar 3 13:05:06 PST 2010


== Quote from Don (nospam at nospam.com)'s article
> dsimcha wrote:
> > Does the freezing of the D2 language spec and the publication of TDPL preclude
> > fixing low level ABI issues like stack alignment?  I have some numerics code
> > that is taking a massive performance hit because the stack keeps ending up
> > aligned such that none of my doubles are aligned on 8-byte boundaries,
> > resulting in something like a 2x performance hit.
> >
> > If not, this is a pretty serious performance problem.  Is there a "standard"
> > solution to the stack alignment problem that will allow consistently good
> > performance on numerics code that uses double-precision floats?
> I agree. See bugzilla 2278. Something that's changed since this issue
> was last raised, is that the DMD backend now has 8-byte stack alignment
> for the Mac compiler. So the hard work has already been done. All that
> would be required to support it on Windows and Linux as well, is to
> enable it, and to align the stack to 8 bytes around every extern(C) call.
> As a workaround, I've been doing things like:
> // Align the stack to a multiple of 64 bytes
> void main()
> {
>      asm {
>          naked;
>          mov EBP, ESP;
>          and ESP, 0xFFFF_FFC0;
>          call alignedmain;
>          mov ESP, EBP;
>          ret;
>      }
> }

Possibly stupid question:  Would aligning each stack frame on 8-byte boundaries be
enough to ensure that each individual stack-allocated double is aligned on 8-byte
boundaries?



More information about the Digitalmars-d mailing list