@@ -24,17 +24,17 @@ pub const _PREFETCH_LOCALITY2: i32 = 2;
2424/// See [`prefetch`](fn._prefetch.html).
2525pub const _PREFETCH_LOCALITY3: i32 = 3 ;
2626
27- /// Fetch the cache line that contains address `p` using the given `rw ` and `locality `.
27+ /// Fetch the cache line that contains address `p` using the given `RW ` and `LOCALITY `.
2828///
29- /// The `rw ` must be one of:
29+ /// The `RW ` must be one of:
3030///
3131/// * [`_PREFETCH_READ`](constant._PREFETCH_READ.html): the prefetch is preparing
3232/// for a read.
3333///
3434/// * [`_PREFETCH_WRITE`](constant._PREFETCH_WRITE.html): the prefetch is preparing
3535/// for a write.
3636///
37- /// The `locality ` must be one of:
37+ /// The `LOCALITY ` must be one of:
3838///
3939/// * [`_PREFETCH_LOCALITY0`](constant._PREFETCH_LOCALITY0.html): Streaming or
4040/// non-temporal prefetch, for data that is used only once.
@@ -55,35 +55,19 @@ pub const _PREFETCH_LOCALITY3: i32 = 3;
5555///
5656/// [Arm's documentation](https://developer.arm.com/documentation/den0024/a/the-a64-instruction-set/memory-access-instructions/prefetching-memory?lang=en)
5757#[ inline( always) ]
58- #[ cfg_attr( test, assert_instr( "prfm pldl1strm" , rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY0) ) ]
59- #[ cfg_attr( test, assert_instr( "prfm pldl3keep" , rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY1) ) ]
60- #[ cfg_attr( test, assert_instr( "prfm pldl2keep" , rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY2) ) ]
61- #[ cfg_attr( test, assert_instr( "prfm pldl1keep" , rw = _PREFETCH_READ, locality = _PREFETCH_LOCALITY3) ) ]
62- #[ cfg_attr( test, assert_instr( "prfm pstl1strm" , rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY0) ) ]
63- #[ cfg_attr( test, assert_instr( "prfm pstl3keep" , rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY1) ) ]
64- #[ cfg_attr( test, assert_instr( "prfm pstl2keep" , rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY2) ) ]
65- #[ cfg_attr( test, assert_instr( "prfm pstl1keep" , rw = _PREFETCH_WRITE, locality = _PREFETCH_LOCALITY3) ) ]
66- #[ rustc_args_required_const( 1 , 2 ) ]
67- pub unsafe fn _prefetch ( p : * const i8 , rw : i32 , locality : i32 ) {
58+ #[ cfg_attr( test, assert_instr( "prfm pldl1strm" , RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY0) ) ]
59+ #[ cfg_attr( test, assert_instr( "prfm pldl3keep" , RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY1) ) ]
60+ #[ cfg_attr( test, assert_instr( "prfm pldl2keep" , RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY2) ) ]
61+ #[ cfg_attr( test, assert_instr( "prfm pldl1keep" , RW = _PREFETCH_READ, LOCALITY = _PREFETCH_LOCALITY3) ) ]
62+ #[ cfg_attr( test, assert_instr( "prfm pstl1strm" , RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY0) ) ]
63+ #[ cfg_attr( test, assert_instr( "prfm pstl3keep" , RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY1) ) ]
64+ #[ cfg_attr( test, assert_instr( "prfm pstl2keep" , RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY2) ) ]
65+ #[ cfg_attr( test, assert_instr( "prfm pstl1keep" , RW = _PREFETCH_WRITE, LOCALITY = _PREFETCH_LOCALITY3) ) ]
66+ #[ rustc_legacy_const_generics( 1 , 2 ) ]
67+ // FIXME: Replace this with the standard ACLE __pld/__pldx/__pli/__plix intrinsics
68+ pub unsafe fn _prefetch < const RW : i32 , const LOCALITY : i32 > ( p : * const i8 ) {
6869 // We use the `llvm.prefetch` instrinsic with `cache type` = 1 (data cache).
69- // `rw` and `strategy` are based on the function parameters.
70- macro_rules! pref {
71- ( $rdwr: expr, $local: expr) => {
72- match ( $rdwr, $local) {
73- ( 0 , 0 ) => prefetch( p, 0 , 0 , 1 ) ,
74- ( 0 , 1 ) => prefetch( p, 0 , 1 , 1 ) ,
75- ( 0 , 2 ) => prefetch( p, 0 , 2 , 1 ) ,
76- ( 0 , 3 ) => prefetch( p, 0 , 3 , 1 ) ,
77- ( 1 , 0 ) => prefetch( p, 1 , 0 , 1 ) ,
78- ( 1 , 1 ) => prefetch( p, 1 , 1 , 1 ) ,
79- ( 1 , 2 ) => prefetch( p, 1 , 2 , 1 ) ,
80- ( 1 , 3 ) => prefetch( p, 1 , 3 , 1 ) ,
81- ( _, _) => panic!(
82- "Illegal (rw, locality) pair in prefetch, value ({}, {})." ,
83- $rdwr, $local
84- ) ,
85- }
86- } ;
87- }
88- pref ! ( rw, locality) ;
70+ static_assert_imm1 ! ( RW ) ;
71+ static_assert_imm2 ! ( LOCALITY ) ;
72+ prefetch ( p, RW , LOCALITY , 1 ) ;
8973}
0 commit comments