-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning multiple arguments via struct #495
Comments
Would it be useful to benchmark something like this before making any changes? |
I agree that this needs to be benchmarked first, before we merge it. I expect that the implementation will be complex enough that editing the generated code by hand may still be worth it. That said, if someone wants to try implementing the full thing straight away then I won't stop them. |
I did some tests for the N=2 case on some artificial microbenchmarks, with three variants
size_t s = 0;
for (size_t i = 0; i < N; i++) {
Ret ret = foo(x)
s += ret.a;
s += ret.b;
bar();
s += ret.a;
s += ret.b;
}
size_t s = 0;
size_t a, b;
for (size_t i = 0; i < N; i++) {
foo(x, &a, &b)
s += a;
s += b;
bar();
s += a;
s += b;
}
size_t s = 0;
size_t a,b;
for (size_t i = 0; i < N; i++) {
{
size_t c, d;
foo(x, &c, &d);
a = c; b = d;
}
s += a;
s += b;
bar();
s += a;
s += b;
} In this extremely artificial microbenchmark, option 1 and 3 took about 6% less time than option 2. This is an extreme example, and the body of the foo and bar functions is extremely simple (it just returns the argument it receives). I would expect that the performance improvement would be less if the body of foo and bar were larger. Based on this, the performance angle doesn't seem very impressive for N = 2. However, we may want to consider at least returning to a temporary variable, to avoid taking the address of a x1 variable. I still haven't tested what happens with N >= 3. |
I wonder if it would be faster to return multiple arguments via struct, instead of by passing one pointer for each argument.
Possible advantages:
x1
variables, that may stop it from being stored in a register.Possible disadvantages:
The text was updated successfully, but these errors were encountered: