1212#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
1313#[ inline( always) ]
1414pub unsafe fn __wfi ( ) {
15- asm ! ( "WFI" : : : : "volatile" )
15+ hint ( HINT_WFI ) ;
1616}
1717
1818/// Generates a WFE (wait for event) hint instruction, or nothing.
@@ -25,7 +25,7 @@ pub unsafe fn __wfi() {
2525#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
2626#[ inline( always) ]
2727pub unsafe fn __wfe ( ) {
28- asm ! ( "WFE" : : : : "volatile" )
28+ hint ( HINT_WFE ) ;
2929}
3030
3131/// Generates a SEV (send a global event) hint instruction.
@@ -37,7 +37,7 @@ pub unsafe fn __wfe() {
3737#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
3838#[ inline( always) ]
3939pub unsafe fn __sev ( ) {
40- asm ! ( "SEV" : : : : "volatile" )
40+ hint ( HINT_SEV ) ;
4141}
4242
4343/// Generates a send a local event hint instruction.
@@ -49,7 +49,7 @@ pub unsafe fn __sev() {
4949#[ cfg( target_arch = "aarch64" ) ]
5050#[ inline( always) ]
5151pub unsafe fn __sevl ( ) {
52- asm ! ( "SEVL" : : : : "volatile" )
52+ hint ( HINT_SEVL ) ;
5353}
5454
5555/// Generates a YIELD hint instruction.
@@ -62,7 +62,7 @@ pub unsafe fn __sevl() {
6262#[ cfg( any( target_feature = "v6k" , target_arch = "aarch64" ) ) ]
6363#[ inline( always) ]
6464pub unsafe fn __yield ( ) {
65- asm ! ( "YIELD" : : : : "volatile" )
65+ hint ( HINT_YIELD ) ;
6666}
6767
6868/// Generates a DBG instruction.
@@ -111,5 +111,19 @@ pub unsafe fn __dbg(imm4: u32) {
111111/// will increase execution time.
112112#[ inline( always) ]
113113pub unsafe fn __nop ( ) {
114- asm ! ( "NOP" : : : : "volatile" )
114+ hint ( HINT_NOP ) ;
115115}
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