-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Optimize AtomicBool
for target that don't support byte-sized atomics
#114034
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
This looks fine to me, you can r=me when you're happy with the set of platforms. |
758686d
to
6b9998e
Compare
6b9998e
to
9e5077d
Compare
As far as I can tell LoongArch and RISC-V are the main ones that people care about. There might be other but I will leave those to follow-up PRs. @bors r=thomcc |
📌 Commit 9e5077dce91db0f4761aba04567b42fa6884f789 has been approved by It is now in the queue for this repository. |
⌛ Testing commit 9e5077dce91db0f4761aba04567b42fa6884f789 with merge 8bd1c3eef862bd2ecdc2774529142004de3febf5... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
9e5077d
to
3282132
Compare
@bors r=thomcc |
📌 Commit 3282132c7c428b01821d3d7454c5e015deb7a860 has been approved by It is now in the queue for this repository. |
`AtomicBool` is defined to have the same layout as `bool`, which means that we guarantee that it has a size of 1 byte. However on certain architectures such as RISC-V, LLVM will emulate byte atomics using a masked CAS loop on an aligned word. We can take advantage of the fact that `bool` only ever has a value of 0 or 1 to replace `swap` operations with `and`/`or` operations that LLVM can lower to word-sized atomic `and`/`or` operations. This takes advantage of the fact that the incoming value to a `swap` or `compare_exchange` for `AtomicBool` is often a compile-time constant.
3282132
to
3dbee5b
Compare
@bors r=thomcc |
☀️ Test successful - checks-actions |
Finished benchmarking commit (e7d6ce3): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 652.686s -> 656.285s (0.55%) |
Similar to D156801 for RISCV. Link: rust-lang/rust#114034 Link: #64090 Reviewed By: SixWeining, xen0n Differential Revision: https://reviews.llvm.org/D159252
AtomicBool
is defined to have the same layout asbool
, which means that we guarantee that it has a size of 1 byte. However on certain architectures such as RISC-V, LLVM will emulate byte atomics using a masked CAS loop on an aligned word.We can take advantage of the fact that
bool
only ever has a value of 0 or 1 to replaceswap
operations withand
/or
operations that LLVM can lower to word-sized atomicand
/or
operations. This takes advantage of the fact that the incoming value to aswap
orcompare_exchange
forAtomicBool
is often a compile-time constant.Example
Old
New