对齐 D 中的堆栈变量
在 D 中,您可以使用 align
关键字来对齐结构/类成员,例如:
struct Vec4 { align(16) float[4] elems; }
但是,似乎您不能在堆栈上执行相同的操作:
void foo()
{
align(16) float[4] vec; // error: found 'align' instead of statement
}
是否有一种方法可以在堆栈上对齐数据堆?特别是,我想创建一个 16 字节对齐的浮点数数组,以使用 movaps
,比 movups
。
例如
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.
...
}
}
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.
...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您愿意额外刻录 16 个字节,您可以在运行时自行进行对齐。除此之外,我就不知道了。
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.