In D, you can align struct/class members by using the align
keyword, e.g.:
struct Vec4 { align(16) float[4] elems; }
However, it appears that you can't do the same on the stack:
void foo()
{
align(16) float[4] vec; // error: found 'align' instead of statement
}
Is there a way to align data on the stack? In particular, I want to create an 16-byte aligned array of floats to load into XMM registers using movaps
, which is significantly faster than movups
.
e.g.
void foo()
{
float[4] v = [1.0f, 2.0f, 3.0f, 4.0f];
asm
{
movaps XMM0, v; // v must be 16-byte aligned for this to work.
...
}
}
If you are willing to burn an extra 16 bytes you can do the alignment your self at run time. Aside from that, I wouldn't know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With