-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[r+] Return passed value from black_box #20463
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
I'm trying to do perlin2(&seed, black_box(&[0.0f32, 0.0])) to prevent the compiler from optimizing away perlin2 by knowing what its inputs are. There is currently no way to do this. |
It can be done now, via let data = [0.0f32, 0.0];
black_box(&mut data); // doesn't mutate, but LLVM doesn't know
perlin2(&seed, &data); |
That said, that trick is somewhat annoying; I have certainly thought about making the same change as performed here to be able fluently opaquify values. |
I was actually surprised that LLVM doesn't have a 0-cost intrinsic for this, since tricks like this do have the potential to slow down benchmarks (memcpy/memset(0)). |
Inline assembly seems like it would work, as long as it's passed the right stuff. |
I guess I have no strong objection. Seems nice to be able to use it fluently. |
By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away.
Is there something more needed for this? If I'm reading github correctly it doesn't need a rebase still. |
The automated tests failed and will need to be fixed before another r+ (can be reproduced with |
Weird, those didn't fail locally, guess the already existing failure on OS X hid them from me. The build log said it was killed so I thought maybe it just didn't get a chance to run the tests. |
By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away.
I think I've got the test failures sorted out, things pass locally now at least. |
Return passed value from black_box Reviewed-by: alexcrichton
[r+] Return passed value from black_box Reviewed-by: alexcrichton
[r+] Return passed value from black_box Reviewed-by: alexcrichton
[r+] Return passed value from black_box Reviewed-by: alexcrichton
By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away.
By returning the passed value black_box can be used on data being
passed to a function being benchmarked. This ensures the compiler
does not optimize the function for the input which could result in
the entire function being optimized away.