Skip to content

Commit 4ce1446

Browse files
committed
RISC-V: Use symbolic instructions on inline assembly (part 1)
While many intrinsics use `.insn` to generate raw machine code from numbers, all ratified instructions can be symbolic using `.option` directives. By saving the assembler environment with `.option push` then modifying the architecture with `.option arch`, we can temporarily enable certain extensions (as we use `.option pop` immediately after the target instruction, surrounding environment is completely intact in this commit; *almost* completely intact in general). This commit modifies the `pause` *hint* intrinsic to use symbolic *instruction* because we want to expose it even if the Zihintpause extension is unavailable on the target.
1 parent db9f604 commit 4ce1446

File tree

1 file changed

+6
-1
lines changed
  • crates/core_arch/src/riscv_shared

1 file changed

+6
-1
lines changed

crates/core_arch/src/riscv_shared/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ use crate::arch::asm;
4444
#[inline]
4545
#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
4646
pub fn pause() {
47+
// Use `.option` directives to expose this HINT instruction
48+
// (no-op if not supported by the hardware) without `#[target_feature]`.
4749
unsafe {
4850
asm!(
49-
".insn i 0x0F, 0, x0, x0, 0x010",
51+
".option push",
52+
".option arch, +zihintpause",
53+
"pause",
54+
".option pop",
5055
options(nomem, nostack, preserves_flags)
5156
);
5257
}

0 commit comments

Comments
 (0)