Skip to content

Commit 3203fd5

Browse files
committed
std_detect: Use riscv_hwprobe on RISC-V Linux/Android
1 parent 65712f3 commit 3203fd5

File tree

4 files changed

+459
-8
lines changed

4 files changed

+459
-8
lines changed

crates/std_detect/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ crate from working on applications in which `std` is not available.
5656
[`cupid`](https://crates.io/crates/cupid) crate.
5757

5858
* Linux/Android:
59-
* `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `riscv{32,64}`, `loongarch64`, `s390x`:
59+
* `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `loongarch64`, `s390x`:
6060
`std_detect` supports these on Linux by querying ELF auxiliary vectors (using `getauxval`
6161
when available), and if that fails, by querying `/proc/cpuinfo`.
6262
* `arm64`: partial support for doing run-time feature detection by directly
6363
querying `mrs` is implemented for Linux >= 4.11, but not enabled by default.
64+
* `riscv{32,64}`:
65+
`std_detect` supports these on Linux by querying `riscv_hwprobe`, and
66+
by querying ELF auxiliary vectors (using `getauxval` when available).
6467

6568
* FreeBSD:
6669
* `arm32`, `powerpc64`: `std_detect` supports these on FreeBSD by querying ELF

crates/std_detect/src/detect/arch/riscv.rs

+84
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ features! {
125125
126126
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] a: "a";
127127
/// "A" Extension for Atomic Instructions
128+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zacas: "zacas";
129+
/// Atomic Compare-And-Swap Instructions
130+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zawrs: "zawrs";
131+
/// Wait on Reservation Set
128132
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zam: "zam";
129133
without cfg check: true;
130134
/// "Zam" Extension for Misaligned Atomics
@@ -194,6 +198,86 @@ features! {
194198
195199
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] v: "v";
196200
/// "V" Extension for Vector Operations
201+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvfh: "zvfh";
202+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
203+
/// Vector Extension for Half-Precision Floating-Point
204+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvfhmin: "zvfhmin";
205+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
206+
/// Vector Extension for Minimal Half-Precision Floating-Point
207+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zve32x: "zve32x";
208+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
209+
/// Vector Extensions for Embedded Processors
210+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zve32f: "zve32f";
211+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
212+
/// Vector Extensions for Embedded Processors
213+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zve64x: "zve64x";
214+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
215+
/// Vector Extensions for Embedded Processors
216+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zve64f: "zve64f";
217+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
218+
/// Vector Extensions for Embedded Processors
219+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zve64d: "zve64d";
220+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
221+
/// Vector Extensions for Embedded Processors
222+
223+
// FIXME: we can implement this by getting the current vlen
224+
// i.e., "csrr {vlen}, vlenb" + "slli {vlen}, {vlen}, 3"
225+
// zvl*b: Minimum Vector Length Standard Extensions
226+
227+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkb: "zvkb";
228+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
229+
/// Vector Bit-manipulation used in Cryptography
230+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvbb: "zvbb";
231+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
232+
/// Vector basic bit-manipulation instructions
233+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvbc: "zvbc";
234+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
235+
/// Vector Carryless Multiplication
236+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkg: "zvkg";
237+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
238+
/// Vector GCM instructions for Cryptography
239+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkned: "zvkned";
240+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
241+
/// Vector AES Encryption & Decryption (Single Round)
242+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknha: "zvknha";
243+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
244+
/// Vector SHA-2 (SHA-256 only))
245+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknhb: "zvknhb";
246+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
247+
/// Vector SHA-2 (SHA-256 and SHA-512)
248+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksed: "zvksed";
249+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
250+
/// SM4 Block Cipher Instructions
251+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksh: "zvksh";
252+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
253+
/// SM3 Hash Function Instructions
254+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkn: "zvkn";
255+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
256+
/// Shorthand for 'Zvkned', 'Zvknhb', 'Zvkb', and 'Zvkt'
257+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknc: "zvknc";
258+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
259+
/// Shorthand for 'Zvkn' and 'Zvbc'
260+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkng: "zvkng";
261+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
262+
/// Shorthand for 'Zvkn' and 'Zvkg'
263+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvks: "zvks";
264+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
265+
/// Shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt'
266+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksc: "zvksc";
267+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
268+
/// Shorthand for 'Zvks' and 'Zvbc'
269+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksg: "zvksg";
270+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
271+
/// Shorthand for 'Zvks' and 'Zvkg'
272+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkt: "zvkt";
273+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
274+
/// Vector Data-Independent Execution Latency
275+
276+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_scalar_mem: "unaligned-scalar-mem";
277+
/// Has reasonably performant unaligned scalar
278+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_vector_mem: "unaligned-vector-mem";
279+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
280+
/// Has reasonably performant unaligned vector
197281
198282
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] svnapot: "svnapot";
199283
without cfg check: true;

0 commit comments

Comments
 (0)