diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2023-07-24 23:16:27 +0100 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2023-07-26 00:09:49 +0100 |
| commit | 3dbee5bc71cf2412707fbc00009e44ef3e32af63 (patch) | |
| tree | a8247f520048a1895dadcb588948a4fef18e1420 /compiler/rustc_codegen_gcc/example/std_example.rs | |
| parent | 8ca44ef9caa4049d584fbbce218c219cdca33a2f (diff) | |
| download | rust-3dbee5bc71cf2412707fbc00009e44ef3e32af63.tar.gz rust-3dbee5bc71cf2412707fbc00009e44ef3e32af63.zip | |
Optimize `AtomicBool` for target that don't support byte-sized atomics
`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.
Diffstat (limited to 'compiler/rustc_codegen_gcc/example/std_example.rs')
0 files changed, 0 insertions, 0 deletions
