Skip to content

Commit ff93763

Browse files
japaricgnzlbg
authored andcommitted
acle::hints: use llvm.{arm,aarch64.hint}
addresses #557 (comment)
1 parent 8fac3a7 commit ff93763

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/core_arch/src/acle/hints.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#[cfg(any(target_feature = "v6k", target_arch = "aarch64"))]
1313
#[inline(always)]
1414
pub 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)]
2727
pub 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)]
3939
pub 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)]
5151
pub 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)]
6464
pub 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)]
113113
pub 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

Comments
 (0)