问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/7852783/passing-types-containing-sse-avx-values