-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Simplify AtomicBool::fetch_nand #40563
Conversation
This should also be faster
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (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. Due to 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 the contribution instructions for more information. |
Looks like tests are failing? |
I think you can simply |
@nagis That is true. However, a swap implies a write all the time instead while a compare and swap does not which can be faster sometimes. In any case the bug was in the |
The lack of a |
@alexcrichton That's deliberate. !(x && false) = true. If x is true and not false then no write needs to happen which is good for the cache. |
// !(false && true) == true | ||
|
||
// !(x && true) == !x | ||
// !(x && false) == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use &
instead of &&
in these, seems clearer.
// !(x && true) == !x | ||
// !(x && false) == true | ||
if val { | ||
return self.fetch_xor(true, order); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit return
isn't needed.
This is odd https://travis-ci.org/rust-lang/rust/jobs/213176849 I can't view what happened here. |
To me this all seems correct. I still think atomoc_swap would be better in
a sense that it's easier to see it's obviously correct unlike he CAS but
either way seems correct to me.
…On Mar 21, 2017 05:54, "Steven Stewart-Gallus" ***@***.***> wrote:
This is odd https://travis-ci.org/rust-lang/rust/jobs/213176849 I can't
view what happened here.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#40563 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AApc0lTDx9MPxut9YjQeAv9u25dJL9L3ks5rn0n2gaJpZM4Metst>
.
|
@sstewartgallus Only one configuration is supposed to run on a PR, but the only way to do that in travis is to finish immediately for non-PR configurations. But macOS ones sometimes even fail at that. |
Do you have benchmarks for this as well to justify this change? |
@alexcrichton Fair enough. However, as this is in libcore I can't easily use std::threads for benchmarking purposes can I? |
@sstewartgallus You can write your own standalone benchmark. |
Benchmark: source
Pretty good imprevements! :) Let's just get rid of that unnecessary |
Let's close this stale PR, as we've pushed the changes forward through a newer PR. |
…r=nagisa Optimize AtomicBool::fetch_nand This is an attempt to push the PR rust-lang#40563 to completion. Benchmark: [source](https://gist.github.com/stjepang/023f5025623f5474184f9f4dfd6379ae) Improvement: ``` name old_ ns/iter new_ce_ ns/iter diff ns/iter diff % 1t 146,440 89,904 -56,536 -38.61% 2t 561,456 316,835 -244,621 -43.57% 4t 2,822,821 1,005,424 -1,817,397 -64.38% ``` r? @eddyb cc @alexcrichton @nagisa
…r=nagisa Optimize AtomicBool::fetch_nand This is an attempt to push the PR rust-lang#40563 to completion. Benchmark: [source](https://gist.github.com/stjepang/023f5025623f5474184f9f4dfd6379ae) Improvement: ``` name old_ ns/iter new_ce_ ns/iter diff ns/iter diff % 1t 146,440 89,904 -56,536 -38.61% 2t 561,456 316,835 -244,621 -43.57% 4t 2,822,821 1,005,424 -1,817,397 -64.38% ``` r? @eddyb cc @alexcrichton @nagisa
This should also be faster.
This code avoids storing in cases where there would not be a change.