问题描述
假设我有以下
: struct A
{
__m256 a;
}
struct B
{
__m256 a;
float b;
}
在硬核中下列哪一个通常更好(如果有的话,为什么)
void f0(A a){...}
void f1(A& a){。 ..} //和指针变量
void f2(B b){...}
void f3(B& b){...} //和指针变量
p>
解决方案答案是无关紧要。
根据此:
通话约定规定16字节(可能是32字节)操作数总是通过引用传递。因此,即使你传递的值,编译器将通过引用在下面传递它。
换句话说,XMM和YMM寄存器从来没有在Windows中传递的值。但是XMM0-4的下半部分仍然可以用于按值传递64位参数。
编辑:
在第二个使用 float
值的示例中,有一点小小的差别,因为它仍然会影响 b
通过引用或值传递。
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
解决方案 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 not b
is passed by reference or by value.
这篇关于传递包含SSE / AVX值的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!