传递包含 SSE/AVX 值的类型
假设我有以下内容
struct A
{
__m256 a;
}
struct B
{
__m256 a;
float b;
}
在硬核循环中,以下哪一项通常更好(如果有的话,为什么)?
void f0(A a) { ... }
void f1(A& a) { ... } //and the pointer variation
void f2(B b) { ...}
void f3(B& b) { ... } //and the pointer variation
Let's say I have the following
struct A
{
__m256 a;
}
struct B
{
__m256 a;
float b;
}
Which of the following's generally better (if any and why) in a hard core loop?
void f0(A a) { ... }
void f1(A& a) { ... } //and the pointer variation
void f2(B b) { ...}
void f3(B& b) { ... } //and the pointer variation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是没关系。
根据此:
http://msdn.microsoft.com/en-us/library /ms235286.aspx
调用约定规定 16 字节(也可能是 32 字节)操作数始终通过引用传递。因此,即使您按值传递,编译器也会在下面按引用传递它。
换句话说,XMM 和 YMM 寄存器在 Windows 中永远不会按值传递。但 XMM0-4 的下半部分仍可用于按值传递 64 位参数。
编辑:
在使用
float
值的第二个示例中,存在细微差别,因为它仍然会影响b
是通过引用还是通过值传递。The answer is that it doesn't matter.
According to this:
http://msdn.microsoft.com/en-us/library/ms235286.aspx
The calling convention states that 16-byte (and probably 32-byte) operands are always passed by reference. So even if you to pass by value, the compiler will pass it by reference underneath.
In other words, XMM and YMM registers are never passed by value in Windows. But the lower halves of XMM0-4 can still be used to pass 64-bit parameters by value.
EDIT:
In your second example with the
float
value, there is a slight difference since it will still affect whether or notb
is passed by reference or by value.