Aligned types and passing arguments by value

吃可爱长大的小学妹 提交于 2019-12-02 20:57:17

I think the only safe way to do this in general is to pass by reference. Some platforms (e.g. Xbox 360) support passing vector arguments in registers, but I don't think this is possible on x86.

For the std::vector case, you'll need to make sure that the memory allocated is aligned to 16 bytes; otherwise you'll get crashes when you try to perform most operations on unaligned vectors.

If you're supporting multiple platforms, a safe plan is to use a typedef e.g.

typedef const MyVector& MyVectorParameter;

You can then change the typedef on platforms that support vector pass-by-value.

the oftenly used resize() function is causing all the alignment and perhaps you can try to specialise vector template for __m128 ?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!