Skip to content

Commit a6b1097

Browse files
committed
auto merge of #19835 : pythonesque/rust/add-unordered-intrinsic, r=thestinger
This corresponds to the JMM memory model's non-volatile reads and writes to shared variables. It provides fairly weak guarantees, but prevents UB (specifically, you will never see a value that was not written _at some point_ to the provided location). It is not part of the C++ memory model and is only legal to provide to LLVM for loads and stores (not fences, atomicrmw, etc.). Valid uses of this ordering are things like racy counters where you don't care about the operation actually being atomic, just want to avoid UB. It cannot be used for synchronization without additional memory barriers since unordered loads and stores may be reordered freely by the optimizer (this is the main way it differs from relaxed). Because it is new to Rust and it provides so few guarantees, for now only the intrinsic is provided--this patch doesn't add it to any of the higher-level atomic wrappers.
2 parents c894171 + ccd88c5 commit a6b1097

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/libcore/intrinsics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ extern "rust-intrinsic" {
7474
pub fn atomic_load<T>(src: *const T) -> T;
7575
pub fn atomic_load_acq<T>(src: *const T) -> T;
7676
pub fn atomic_load_relaxed<T>(src: *const T) -> T;
77+
pub fn atomic_load_unordered<T>(src: *const T) -> T;
7778

7879
pub fn atomic_store<T>(dst: *mut T, val: T);
7980
pub fn atomic_store_rel<T>(dst: *mut T, val: T);
8081
pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
82+
pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
8183

8284
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
8385
pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;

src/librustc_trans/trans/intrinsic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
525525
llvm::SequentiallyConsistent
526526
} else {
527527
match split[2] {
528+
"unordered" => llvm::Unordered,
528529
"relaxed" => llvm::Monotonic,
529530
"acq" => llvm::Acquire,
530531
"rel" => llvm::Release,

0 commit comments

Comments
 (0)