Skip to content

Commit e8f7afe

Browse files
Rollup merge of rust-lang#128149 - RalfJung:nontemporal_store, r=jieyouxu,Amanieu,Jubilee
nontemporal_store: make sure that the intrinsic is truly just a hint The `!nontemporal` flag for stores in LLVM *sounds* like it is just a hint, but actually, it is not -- at least on x86, non-temporal stores need very special treatment by the programmer or else the Rust memory model breaks down. LLVM still treats these stores as-if they were normal stores for optimizations, which is [highly dubious](llvm/llvm-project#64521). Let's avoid all that dubiousness by making our own non-temporal stores be truly just a hint, which is possible on some targets (e.g. ARM). On all other targets, non-temporal stores become regular stores. ~~Blocked on rust-lang/stdarch#1541 propagating to the rustc repo, to make sure the `_mm_stream` intrinsics are unaffected by this change.~~ Fixes rust-lang#114582 Cc `@Amanieu` `@workingjubilee`
2 parents 9147777 + e6aede2 commit e8f7afe

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: core/src/intrinsics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2675,12 +2675,12 @@ extern "rust-intrinsic" {
26752675
#[rustc_nounwind]
26762676
pub fn catch_unwind(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
26772677

2678-
/// Emits a `!nontemporal` store according to LLVM (see their docs).
2679-
/// Probably will never become stable.
2678+
/// Emits a `nontemporal` store, which gives a hint to the CPU that the data should not be held
2679+
/// in cache. Except for performance, this is fully equivalent to `ptr.write(val)`.
26802680
///
2681-
/// Do NOT use this intrinsic; "nontemporal" operations do not exist in our memory model!
2682-
/// It exists to support current stdarch, but the plan is to change stdarch and remove this intrinsic.
2683-
/// See <https://github.com/rust-lang/rust/issues/114582> for some more discussion.
2681+
/// Not all architectures provide such an operation. For instance, x86 does not: while `MOVNT`
2682+
/// exists, that operation is *not* equivalent to `ptr.write(val)` (`MOVNT` writes can be reordered
2683+
/// in ways that are not allowed for regular writes).
26842684
#[rustc_nounwind]
26852685
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
26862686

0 commit comments

Comments
 (0)