core/stdarch/crates/core_arch/src/riscv64/mod.rs
1//! RISC-V RV64 specific intrinsics
2use crate::arch::asm;
3
4mod zk;
5
6#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
7pub use zk::*;
8
9/// Loads virtual machine memory by unsigned word integer
10///
11/// This instruction performs an explicit memory access as though `V=1`;
12/// i.e., with the address translation and protection, and the endianness, that apply to memory
13/// accesses in either VS-mode or VU-mode.
14///
15/// This operation is not available under RV32 base instruction set.
16///
17/// This function is unsafe for it accesses the virtual supervisor or user via a `HLV.WU`
18/// instruction which is effectively a dereference to any memory address.
19#[inline]
20#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
21pub unsafe fn hlv_wu(src: *const u32) -> u32 {
22 let value: u32;
23 asm!(
24 ".insn i 0x73, 0x4, {}, {}, 0x681",
25 lateout(reg) value,
26 in(reg) src,
27 options(readonly, nostack, preserves_flags)
28 );
29 value
30}
31
32/// Loads virtual machine memory by double integer
33///
34/// This instruction performs an explicit memory access as though `V=1`;
35/// i.e., with the address translation and protection, and the endianness, that apply to memory
36/// accesses in either VS-mode or VU-mode.
37///
38/// This operation is not available under RV32 base instruction set.
39///
40/// This function is unsafe for it accesses the virtual supervisor or user via a `HLV.D`
41/// instruction which is effectively a dereference to any memory address.
42#[inline]
43#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
44pub unsafe fn hlv_d(src: *const i64) -> i64 {
45 let value: i64;
46 asm!(
47 ".insn i 0x73, 0x4, {}, {}, 0x6C0",
48 lateout(reg) value,
49 in(reg) src,
50 options(readonly, nostack, preserves_flags)
51 );
52 value
53}
54
55/// Stores virtual machine memory by double integer
56///
57/// This instruction performs an explicit memory access as though `V=1`;
58/// i.e., with the address translation and protection, and the endianness, that apply to memory
59/// accesses in either VS-mode or VU-mode.
60///
61/// This function is unsafe for it accesses the virtual supervisor or user via a `HSV.D`
62/// instruction which is effectively a dereference to any memory address.
63#[inline]
64#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
65pub unsafe fn hsv_d(dst: *mut i64, src: i64) {
66 asm!(
67 ".insn r 0x73, 0x4, 0x37, x0, {}, {}",
68 in(reg) dst,
69 in(reg) src,
70 options(nostack, preserves_flags)
71 );
72}