@@ -834,10 +834,6 @@ pub fn select_unpredictable<T>(condition: bool, true_val: T, false_val: T) -> T
834
834
#[ non_exhaustive]
835
835
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
836
836
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 ,
841
837
/// Data is expected to be reused eventually.
842
838
///
843
839
/// Typically prefetches into L3 cache (if the CPU supports it).
@@ -865,6 +861,7 @@ pub enum Locality {
865
861
/// # Examples
866
862
///
867
863
/// ```
864
+ /// #![feature(hint_prefetch)]
868
865
/// use std::hint::{Locality, prefetch_read_data};
869
866
/// use std::mem::size_of_val;
870
867
///
@@ -880,15 +877,28 @@ pub enum Locality {
880
877
#[ unstable( feature = "hint_prefetch" , issue = "146941" ) ]
881
878
pub const fn prefetch_read_data < T > ( ptr : * const T , locality : Locality ) {
882
879
match locality {
883
- Locality :: NonTemporal => {
884
- intrinsics:: prefetch_read_data :: < T , { Locality :: NonTemporal as i32 } > ( ptr)
885
- }
886
880
Locality :: L3 => intrinsics:: prefetch_read_data :: < T , { Locality :: L3 as i32 } > ( ptr) ,
887
881
Locality :: L2 => intrinsics:: prefetch_read_data :: < T , { Locality :: L2 as i32 } > ( ptr) ,
888
882
Locality :: L1 => intrinsics:: prefetch_read_data :: < T , { Locality :: L1 as i32 } > ( ptr) ,
889
883
}
890
884
}
891
885
886
+ /// Prefetch the cache line containing `ptr` for a single future read, but attempt to avoid
887
+ /// polluting the cache.
888
+ ///
889
+ /// A strategically placed prefetch can reduce cache miss latency if the data is accessed
890
+ /// soon after, but may also increase bandwidth usage or evict other cache lines.
891
+ ///
892
+ /// A prefetch is a *hint*, and may be ignored on certain targets or by the hardware.
893
+ ///
894
+ /// Passing a dangling or invalid pointer is permitted: the memory will not
895
+ /// actually be dereferenced, and no faults are raised.
896
+ #[ inline( always) ]
897
+ #[ unstable( feature = "hint_prefetch" , issue = "146941" ) ]
898
+ pub const fn prefetch_read_data_non_temporal < T > ( ptr : * const T ) {
899
+ intrinsics:: prefetch_read_data :: < T , 0 > ( ptr)
900
+ }
901
+
892
902
/// Prefetch the cache line containing `ptr` for a future write.
893
903
///
894
904
/// A strategically placed prefetch can reduce cache miss latency if the data is accessed
@@ -898,12 +908,10 @@ pub const fn prefetch_read_data<T>(ptr: *const T, locality: Locality) {
898
908
///
899
909
/// Passing a dangling or invalid pointer is permitted: the memory will not
900
910
/// actually be dereferenced, and no faults are raised.
911
+ #[ inline( always) ]
901
912
#[ unstable( feature = "hint_prefetch" , issue = "146941" ) ]
902
913
pub const fn prefetch_write_data < T > ( ptr : * mut T , locality : Locality ) {
903
914
match locality {
904
- Locality :: NonTemporal => {
905
- intrinsics:: prefetch_write_data :: < T , { Locality :: NonTemporal as i32 } > ( ptr)
906
- }
907
915
Locality :: L3 => intrinsics:: prefetch_write_data :: < T , { Locality :: L3 as i32 } > ( ptr) ,
908
916
Locality :: L2 => intrinsics:: prefetch_write_data :: < T , { Locality :: L2 as i32 } > ( ptr) ,
909
917
Locality :: L1 => intrinsics:: prefetch_write_data :: < T , { Locality :: L1 as i32 } > ( ptr) ,
@@ -919,12 +927,10 @@ pub const fn prefetch_write_data<T>(ptr: *mut T, locality: Locality) {
919
927
///
920
928
/// Passing a dangling or invalid pointer is permitted: the memory will not
921
929
/// actually be dereferenced, and no faults are raised.
930
+ #[ inline( always) ]
922
931
#[ unstable( feature = "hint_prefetch" , issue = "146941" ) ]
923
932
pub const fn prefetch_read_instruction < T > ( ptr : * const T , locality : Locality ) {
924
933
match locality {
925
- Locality :: NonTemporal => {
926
- intrinsics:: prefetch_read_instruction :: < T , { Locality :: NonTemporal as i32 } > ( ptr)
927
- }
928
934
Locality :: L3 => intrinsics:: prefetch_read_instruction :: < T , { Locality :: L3 as i32 } > ( ptr) ,
929
935
Locality :: L2 => intrinsics:: prefetch_read_instruction :: < T , { Locality :: L2 as i32 } > ( ptr) ,
930
936
Locality :: L1 => intrinsics:: prefetch_read_instruction :: < T , { Locality :: L1 as i32 } > ( ptr) ,
0 commit comments