Skip to content

Commit 2adc17a

Browse files
authored
More RISC-V instructions in core::arch (#1271)
1 parent 293d4bc commit 2adc17a

File tree

5 files changed

+558
-18
lines changed

5 files changed

+558
-18
lines changed

crates/core_arch/src/core_arch_docs.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ others at:
185185
* [`x86_64`]
186186
* [`arm`]
187187
* [`aarch64`]
188-
* [`riscv`]
188+
* [`riscv32`]
189+
* [`riscv64`]
189190
* [`mips`]
190191
* [`mips64`]
191192
* [`powerpc`]
@@ -197,7 +198,8 @@ others at:
197198
[`x86_64`]: x86_64/index.html
198199
[`arm`]: arm/index.html
199200
[`aarch64`]: aarch64/index.html
200-
[`riscv`]: riscv/index.html
201+
[`riscv32`]: riscv32/index.html
202+
[`riscv64`]: riscv64/index.html
201203
[`mips`]: mips/index.html
202204
[`mips64`]: mips64/index.html
203205
[`powerpc`]: powerpc/index.html

crates/core_arch/src/mod.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,28 @@ pub mod arch {
5656
pub use crate::core_arch::aarch64::*;
5757
}
5858

59-
/// Platform-specific intrinsics for the `riscv` platform.
59+
/// Platform-specific intrinsics for the `riscv32` platform.
6060
///
6161
/// See the [module documentation](../index.html) for more details.
62-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", doc))]
63-
#[doc(cfg(any(target_arch = "riscv32", target_arch = "riscv64")))]
62+
#[cfg(any(target_arch = "riscv32", doc))]
63+
#[doc(cfg(any(target_arch = "riscv32")))]
6464
#[unstable(feature = "stdsimd", issue = "27731")]
65-
pub mod riscv {
66-
pub use crate::core_arch::riscv::*;
65+
pub mod riscv32 {
66+
pub use crate::core_arch::riscv_shared::*;
67+
}
68+
69+
/// Platform-specific intrinsics for the `riscv64` platform.
70+
///
71+
/// See the [module documentation](../index.html) for more details.
72+
#[cfg(any(target_arch = "riscv64", doc))]
73+
#[doc(cfg(any(target_arch = "riscv64")))]
74+
#[unstable(feature = "stdsimd", issue = "27731")]
75+
pub mod riscv64 {
76+
pub use crate::core_arch::riscv64::*;
77+
// RISC-V RV64 supports all RV32 instructions as well in current specifications (2022-01-05).
78+
// Module `riscv_shared` includes instructions available under all RISC-V platforms,
79+
// i.e. RISC-V RV32 instructions.
80+
pub use crate::core_arch::riscv_shared::*;
6781
}
6882

6983
/// Platform-specific intrinsics for the `wasm32` platform.
@@ -264,7 +278,11 @@ mod arm;
264278

265279
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", doc))]
266280
#[doc(cfg(any(target_arch = "riscv32", target_arch = "riscv64")))]
267-
mod riscv;
281+
mod riscv_shared;
282+
283+
#[cfg(any(target_arch = "riscv64", doc))]
284+
#[doc(cfg(any(target_arch = "riscv64")))]
285+
mod riscv64;
268286

269287
#[cfg(any(target_family = "wasm", doc))]
270288
#[doc(cfg(target_family = "wasm"))]

crates/core_arch/src/riscv/mod.rs

-10
This file was deleted.

crates/core_arch/src/riscv64/mod.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! RISC-V RV64 specific intrinsics
2+
use crate::arch::asm;
3+
4+
/// Loads virtual machine memory by unsigned word integer
5+
///
6+
/// This instruction performs an explicit memory access as though `V=1`;
7+
/// i.e., with the address translation and protection, and the endianness, that apply to memory
8+
/// accesses in either VS-mode or VU-mode.
9+
///
10+
/// This operation is not available under RV32 base instruction set.
11+
///
12+
/// This function is unsafe for it accesses the virtual supervisor or user via a `HLV.WU`
13+
/// instruction which is effectively an unreference to any memory address.
14+
#[inline]
15+
pub unsafe fn hlv_wu(src: *const u32) -> u32 {
16+
let value: u32;
17+
asm!(".insn i 0x73, 0x4, {}, {}, 0x681", out(reg) value, in(reg) src, options(readonly, nostack));
18+
value
19+
}
20+
21+
/// Loads virtual machine memory by unsigned double integer
22+
///
23+
/// This instruction performs an explicit memory access as though `V=1`;
24+
/// i.e., with the address translation and protection, and the endianness, that apply to memory
25+
/// accesses in either VS-mode or VU-mode.
26+
///
27+
/// This operation is not available under RV32 base instruction set.
28+
///
29+
/// This function is unsafe for it accesses the virtual supervisor or user via a `HLV.D`
30+
/// instruction which is effectively an unreference to any memory address.
31+
#[inline]
32+
pub unsafe fn hlv_d(src: *const i64) -> i64 {
33+
let value: i64;
34+
asm!(".insn i 0x73, 0x4, {}, {}, 0x6C0", out(reg) value, in(reg) src, options(readonly, nostack));
35+
value
36+
}
37+
38+
/// Stores virtual machine memory by double integer
39+
///
40+
/// This instruction performs an explicit memory access as though `V=1`;
41+
/// i.e., with the address translation and protection, and the endianness, that apply to memory
42+
/// accesses in either VS-mode or VU-mode.
43+
///
44+
/// This function is unsafe for it accesses the virtual supervisor or user via a `HSV.D`
45+
/// instruction which is effectively an unreference to any memory address.
46+
#[inline]
47+
pub unsafe fn hsv_d(dst: *mut i64, src: i64) {
48+
asm!(".insn r 0x73, 0x4, 0x37, x0, {}, {}", in(reg) dst, in(reg) src, options(nostack));
49+
}

0 commit comments

Comments
 (0)