Skip to content

Commit 40dd1fd

Browse files
sayantnmadhav-madhusoodanan
authored andcommitted
Make _mm_prefetch safe
1 parent 9b15f2c commit 40dd1fd

File tree

1 file changed

+6
-2
lines changed
  • crates/core_arch/src/x86

1 file changed

+6
-2
lines changed

crates/core_arch/src/x86/sse.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,8 @@ pub const _MM_HINT_ET1: i32 = 6;
18871887
/// * Prefetching may also fail if there are not enough memory-subsystem
18881888
/// resources (e.g., request buffers).
18891889
///
1890+
/// Note: this intrinsic is safe to use even though it takes a raw pointer argument. In general, this
1891+
/// cannot change the behavior of the program, including not trapping on invalid pointers.
18901892
///
18911893
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_prefetch)
18921894
#[inline]
@@ -1897,11 +1899,13 @@ pub const _MM_HINT_ET1: i32 = 6;
18971899
#[cfg_attr(test, assert_instr(prefetchnta, STRATEGY = _MM_HINT_NTA))]
18981900
#[rustc_legacy_const_generics(1)]
18991901
#[stable(feature = "simd_x86", since = "1.27.0")]
1900-
pub unsafe fn _mm_prefetch<const STRATEGY: i32>(p: *const i8) {
1902+
pub fn _mm_prefetch<const STRATEGY: i32>(p: *const i8) {
19011903
static_assert_uimm_bits!(STRATEGY, 3);
19021904
// We use the `llvm.prefetch` intrinsic with `cache type` = 1 (data cache).
19031905
// `locality` and `rw` are based on our `STRATEGY`.
1904-
prefetch(p, (STRATEGY >> 2) & 1, STRATEGY & 3, 1);
1906+
unsafe {
1907+
prefetch(p, (STRATEGY >> 2) & 1, STRATEGY & 3, 1);
1908+
}
19051909
}
19061910

19071911
/// Returns vector of type __m128 with indeterminate elements.with indetermination elements.

0 commit comments

Comments
 (0)