struct alignments
    dominik 
    asd at asd.com
       
    Sun Apr 13 15:42:21 PDT 2008
    
    
  
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 
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 {
  union {
   struct { float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f; };
   struct { float r, g, b, a; };
   struct { float cell[4]; };
   Repeat!(float, 4) tuple;
  };
...
}
also somewhere down the road in the code I'd like equivalent of declspec 
align too, for example something like
Vector4d opAdd( ref Vector4d v ) {
version(NORMAL) {
    return Vector4d( x + v.x, y + v.y, z + v.z, w + v.w );
}
else version(SIMD) {
    __declspec(align(16)) Vector4d v4_ret;
    asm {
        mov esi, this
        mov edi, v
        movaps xmm0, [esi]
        addps xmm0, [edi]
        movaps v4_ret, xmm0
    }
    return v4_ret;
}
}
or something like that, its illustrative only :) 
    
    
More information about the Digitalmars-d-learn
mailing list