12
12
#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
13
13
#[ inline( always) ]
14
14
pub unsafe fn __wfi ( ) {
15
- asm ! ( "WFI" : : : : "volatile" )
15
+ hint ( HINT_WFI ) ;
16
16
}
17
17
18
18
/// Generates a WFE (wait for event) hint instruction, or nothing.
@@ -25,7 +25,7 @@ pub unsafe fn __wfi() {
25
25
#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
26
26
#[ inline( always) ]
27
27
pub unsafe fn __wfe ( ) {
28
- asm ! ( "WFE" : : : : "volatile" )
28
+ hint ( HINT_WFE ) ;
29
29
}
30
30
31
31
/// Generates a SEV (send a global event) hint instruction.
@@ -37,7 +37,7 @@ pub unsafe fn __wfe() {
37
37
#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
38
38
#[ inline( always) ]
39
39
pub unsafe fn __sev ( ) {
40
- asm ! ( "SEV" : : : : "volatile" )
40
+ hint ( HINT_SEV ) ;
41
41
}
42
42
43
43
/// Generates a send a local event hint instruction.
@@ -49,7 +49,7 @@ pub unsafe fn __sev() {
49
49
#[ cfg( target_arch = "aarch64" ) ]
50
50
#[ inline( always) ]
51
51
pub unsafe fn __sevl ( ) {
52
- asm ! ( "SEVL" : : : : "volatile" )
52
+ hint ( HINT_SEVL ) ;
53
53
}
54
54
55
55
/// Generates a YIELD hint instruction.
@@ -62,7 +62,7 @@ pub unsafe fn __sevl() {
62
62
#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
63
63
#[ inline( always) ]
64
64
pub unsafe fn __yield ( ) {
65
- asm ! ( "YIELD" : : : : "volatile" )
65
+ hint ( HINT_YIELD ) ;
66
66
}
67
67
68
68
/// Generates a DBG instruction.
@@ -111,5 +111,19 @@ pub unsafe fn __dbg(imm4: u32) {
111
111
/// will increase execution time.
112
112
#[ inline( always) ]
113
113
pub unsafe fn __nop ( ) {
114
- asm ! ( "NOP" : : : : "volatile" )
114
+ hint ( HINT_NOP ) ;
115
115
}
116
+
117
+ extern "C" {
118
+ #[ cfg_attr( target_arch = "aarch64" , link_name = "llvm.aarch64.hint" ) ]
119
+ #[ cfg_attr( target_arch = "arm" , link_name = "llvm.arm.hint" ) ]
120
+ fn hint ( _: i32 ) ;
121
+ }
122
+
123
+ // from LLVM 7.0.1's lib/Target/ARM/{ARMInstrThumb,ARMInstrInfo,ARMInstrThumb2}.td
124
+ const HINT_NOP : i32 = 0 ;
125
+ const HINT_YIELD : i32 = 1 ;
126
+ const HINT_WFE : i32 = 2 ;
127
+ const HINT_WFI : i32 = 3 ;
128
+ const HINT_SEV : i32 = 4 ;
129
+ const HINT_SEVL : i32 = 5 ;
0 commit comments