Skip to content

Commit c570fcb

Browse files
authored
Rollup merge of rust-lang#92574 - luojia65:riscv-kernel-dev-rust, r=Amanieu
Add RISC-V detection macro and more architecture instructions This pull request includes: - Update `stdarch` dependency to include ratified RISC-V supervisor and hypervisor instruction intrinsics which is useful in Rust kernel development - Add macro `is_riscv_feature_detected!` - Modify impl of `core::hint::spin_loop` to comply with latest version of `core::arch` After this update, users may now develop RISC-V kernels and user applications more freely. r? `@Amanieu`
2 parents 051d591 + 06f4453 commit c570fcb

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

library/core/src/hint.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ pub fn spin_loop() {
123123
}
124124
}
125125

126+
// RISC-V platform spin loop hint implementation
127+
{
128+
// RISC-V RV32 and RV64 share the same PAUSE instruction, but they are located in different
129+
// modules in `core::arch`.
130+
// In this case, here we call `pause` function in each core arch module.
131+
#[cfg(target_arch = "riscv32")]
132+
{
133+
crate::arch::riscv32::pause();
134+
}
135+
#[cfg(target_arch = "riscv64")]
136+
{
137+
crate::arch::riscv64::pause();
138+
}
139+
}
140+
126141
#[cfg(any(target_arch = "aarch64", all(target_arch = "arm", target_feature = "v6")))]
127142
{
128143
#[cfg(target_arch = "aarch64")]
@@ -137,11 +152,6 @@ pub fn spin_loop() {
137152
unsafe { crate::arch::arm::__yield() };
138153
}
139154
}
140-
141-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
142-
{
143-
crate::arch::riscv::pause();
144-
}
145155
}
146156

147157
/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ pub use std_detect::*;
556556
pub use std_detect::{
557557
is_aarch64_feature_detected, is_arm_feature_detected, is_mips64_feature_detected,
558558
is_mips_feature_detected, is_powerpc64_feature_detected, is_powerpc_feature_detected,
559+
is_riscv_feature_detected,
559560
};
560561

561562
// Re-export macros defined in libcore.

0 commit comments

Comments
 (0)