Skip to content

Commit 7f2cd50

Browse files
committed
Add a separate function for a non-temporal read prefetch
1 parent 206dca8 commit 7f2cd50

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

library/core/src/hint.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,6 @@ pub fn select_unpredictable<T>(condition: bool, true_val: T, false_val: T) -> T
834834
#[non_exhaustive]
835835
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
836836
pub enum Locality {
837-
/// Data is unlikely to be reused soon.
838-
///
839-
/// Typically bypasses the caches so they are not polluted.
840-
NonTemporal = 0,
841837
/// Data is expected to be reused eventually.
842838
///
843839
/// Typically prefetches into L3 cache (if the CPU supports it).
@@ -880,15 +876,28 @@ pub enum Locality {
880876
#[unstable(feature = "hint_prefetch", issue = "146941")]
881877
pub const fn prefetch_read_data<T>(ptr: *const T, locality: Locality) {
882878
match locality {
883-
Locality::NonTemporal => {
884-
intrinsics::prefetch_read_data::<T, { Locality::NonTemporal as i32 }>(ptr)
885-
}
886879
Locality::L3 => intrinsics::prefetch_read_data::<T, { Locality::L3 as i32 }>(ptr),
887880
Locality::L2 => intrinsics::prefetch_read_data::<T, { Locality::L2 as i32 }>(ptr),
888881
Locality::L1 => intrinsics::prefetch_read_data::<T, { Locality::L1 as i32 }>(ptr),
889882
}
890883
}
891884

885+
/// Prefetch the cache line containing `ptr` for a single future read, but attempt to avoid
886+
/// polluting the cache.
887+
///
888+
/// A strategically placed prefetch can reduce cache miss latency if the data is accessed
889+
/// soon after, but may also increase bandwidth usage or evict other cache lines.
890+
///
891+
/// A prefetch is a *hint*, and may be ignored on certain targets or by the hardware.
892+
///
893+
/// Passing a dangling or invalid pointer is permitted: the memory will not
894+
/// actually be dereferenced, and no faults are raised.
895+
#[inline(always)]
896+
#[unstable(feature = "hint_prefetch", issue = "146941")]
897+
pub const fn prefetch_read_data_non_temporal<T>(ptr: *const T) {
898+
intrinsics::prefetch_read_data::<T, 0>(ptr)
899+
}
900+
892901
/// Prefetch the cache line containing `ptr` for a future write.
893902
///
894903
/// A strategically placed prefetch can reduce cache miss latency if the data is accessed
@@ -901,9 +910,6 @@ pub const fn prefetch_read_data<T>(ptr: *const T, locality: Locality) {
901910
#[unstable(feature = "hint_prefetch", issue = "146941")]
902911
pub const fn prefetch_write_data<T>(ptr: *mut T, locality: Locality) {
903912
match locality {
904-
Locality::NonTemporal => {
905-
intrinsics::prefetch_write_data::<T, { Locality::NonTemporal as i32 }>(ptr)
906-
}
907913
Locality::L3 => intrinsics::prefetch_write_data::<T, { Locality::L3 as i32 }>(ptr),
908914
Locality::L2 => intrinsics::prefetch_write_data::<T, { Locality::L2 as i32 }>(ptr),
909915
Locality::L1 => intrinsics::prefetch_write_data::<T, { Locality::L1 as i32 }>(ptr),
@@ -922,9 +928,6 @@ pub const fn prefetch_write_data<T>(ptr: *mut T, locality: Locality) {
922928
#[unstable(feature = "hint_prefetch", issue = "146941")]
923929
pub const fn prefetch_read_instruction<T>(ptr: *const T, locality: Locality) {
924930
match locality {
925-
Locality::NonTemporal => {
926-
intrinsics::prefetch_read_instruction::<T, { Locality::NonTemporal as i32 }>(ptr)
927-
}
928931
Locality::L3 => intrinsics::prefetch_read_instruction::<T, { Locality::L3 as i32 }>(ptr),
929932
Locality::L2 => intrinsics::prefetch_read_instruction::<T, { Locality::L2 as i32 }>(ptr),
930933
Locality::L1 => intrinsics::prefetch_read_instruction::<T, { Locality::L1 as i32 }>(ptr),

0 commit comments

Comments
 (0)