struct alignments

Don nospam at nospam.com
Wed Apr 16 00:03:22 PDT 2008


dominik wrote:
> I'm working on my vector and matrix math library, and now I'm prototyping my 
> SIMD optimizations, obviously I would like data alignment.. fact is I have 

Good news!

> no clue how to do it ( I vaguely remember align directive)

> 
> for example something like (mixed C++ and D! :) ), what would I need for 
> pragma pack equivalent in D then for a struct?
> 
> #pragma pack(16)
> struct Vector4d {



align(16) struct Vector4d {


> also somewhere down the road in the code I'd like equivalent of declspec 
> align too, for example something like
> 
>     __declspec(align(16)) Vector4d v4_ret;
>     asm {
>         mov esi, this
>         mov edi, v

asm {
    align 16;
    mov esi, this;
    mov edi, v;
}


Bad news!

One problem is that the stack (and hence all local variables) are only 
aligned to 32 bytes. This means you can only use SSE aligned loads 
(movaps, movapd) on static and heap variables. (This is something that D 
really should fix while it has the chance).


More information about the Digitalmars-d-learn mailing list