开发者

Aligning stack variables in D

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜