Thread overview
[Issue 2278] Guarantee alignment of stack-allocated variables on x86
Feb 19, 2014
Temtaime
Mar 10, 2014
MCD
Mar 18, 2014
Denis Shelomovskij
February 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2278


Temtaime <temtaime@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |regression


--- Comment #12 from Temtaime <temtaime@gmail.com> 2014-02-19 06:06:01 PST ---
BUMP.

align(16) struct A { ubyte t; }

void main() {
    A a;
    writeln(cast(size_t)&a % 16);
}

Prints 4 right now.
When it will be fixed?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 10, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2278


MCD <s_lange@ira.uni-karlsruhe.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |s_lange@ira.uni-karlsruhe.d
                   |                            |e


--- Comment #13 from MCD <s_lange@ira.uni-karlsruhe.de> 2014-03-10 07:33:21 PDT ---
The problem about alignment of the stack for (128 bit) SSE is, that it even
needs to be aligned to 16 byte (or double quadrouble word) boundary for fast
access (via aligned moves), 8 byte (or quadword) won't be enough(yes, there are
unaligned SSE move instructions, but...). And that's only for basic 128 bit
SSE, AVX may take 256 bit or even 512 bit alignment, at least when you need to
use fast aligned move instructions.

Hopefully, no (pure) 32 bit x86 CPU has 256 or 512 bit AVX registers. However, it's possible to use the upper parts of 256 or 512 bit AVX registers in 32 bit Windows on a 64 bit CPU in 32 bit compatibility mode, but I'm not sure whether older versions of Windows do recognize and correctly save/restore them on context switch, which is essential for using them safely (someone needs to check this out).

so here you have it. 32-bit Windows requires 16 byte alignment for SSE. 64-bit Windows already has 16 byte alignment, but may require even more if AVX registers are used.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 18, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2278


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg@gmail.com
           Severity|regression                  |enhancement


--- Comment #14 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2014-03-18 18:00:56 MSK ---
This isn't a regression. It was just a luck build in Comment 10.

As a [partial] workaround one can use an autoaligned buffer e.g. this one: http://denis-sh.bitbucket.org/unstandard/unstd.memory.misc.html

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------