[Issue 2278] Guarantee alignment of stack-allocated variables on x86

Don nospam at nospam.com.au
Tue Aug 12 08:11:14 PDT 2008


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=2278
> 
> 
> 
> 
> 
> ------- Comment #1 from andrei at metalanguage.com  2008-08-11 10:29 -------
> This looks like a broad change for a particular case. The particular case is
> short numeric arrays of constant size (because those get stack-allocated). So
> why not have the compiler align only those at 8-byte boundaries and leave
> everything else alone?

Yes, it would be possible to align only those functions which use 
arrays, or large structures. But, note that
(a) it's relevant for _any_ usage of SSE instructions, not just array 
operations.  Many C++ compilers are using SSE in place of 
general-purpose registers.
(b) It also makes a big difference to the speed of memcpy/memmove, even 
when no vector instructions are used. In some cases, it also speeds up 
floating point operations on 'real' operands; and
(c) as Walter notes, the procedure for aligning a stack frame is quite 
clumsy.
(d) if you want pass-by-value for constant-size arrays, you need to 
align them, too, and that is only possible by doing this kind of padding 
of the stack

> Copy semantics for constant-size arrays will certainly help too.

Yes.

======
A quote from Agner Fog's assembly programming manual:
---
All 64-bit operating systems, and some 32-bit operating systems (Mac OS 
and later
versions of Linux) keep the stack aligned by 16 at all CALL 
instructions. This eliminates the
need for the AND instruction and the frame pointer. It is necessary to 
propagate this
alignment from one CALL instruction to the next by proper adjustment of 
the stack pointer in
each function.
---

It's really a much nicer solution than multiple frame pointers.


More information about the Digitalmars-d-bugs mailing list