Skip to content

Commit 1ece49d

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

File tree

4 files changed

+457
-8
lines changed

4 files changed

+457
-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

+83
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,85 @@ 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+
// zvl*b: Minimum Vector Length Standard Extensions
225+
226+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkb: "zvkb";
227+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
228+
/// Vector Bit-manipulation used in Cryptography
229+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvbb: "zvbb";
230+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
231+
/// Vector basic bit-manipulation instructions
232+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvbc: "zvbc";
233+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
234+
/// Vector Carryless Multiplication
235+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkg: "zvkg";
236+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
237+
/// Vector GCM instructions for Cryptography
238+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkned: "zvkned";
239+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
240+
/// Vector AES Encryption & Decryption (Single Round)
241+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknha: "zvknha";
242+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
243+
/// Vector SHA-2 (SHA-256 only))
244+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknhb: "zvknhb";
245+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
246+
/// Vector SHA-2 (SHA-256 and SHA-512)
247+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksed: "zvksed";
248+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
249+
/// SM4 Block Cipher Instructions
250+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksh: "zvksh";
251+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
252+
/// SM3 Hash Function Instructions
253+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkn: "zvkn";
254+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
255+
/// Shorthand for 'Zvkned', 'Zvknhb', 'Zvkb', and 'Zvkt'
256+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknc: "zvknc";
257+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
258+
/// Shorthand for 'Zvkn' and 'Zvbc'
259+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkng: "zvkng";
260+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
261+
/// Shorthand for 'Zvkn' and 'Zvkg'
262+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvks: "zvks";
263+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
264+
/// Shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt'
265+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksc: "zvksc";
266+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
267+
/// Shorthand for 'Zvks' and 'Zvbc'
268+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksg: "zvksg";
269+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
270+
/// Shorthand for 'Zvks' and 'Zvkg'
271+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkt: "zvkt";
272+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
273+
/// Vector Data-Independent Execution Latency
274+
275+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_scalar_mem: "unaligned-scalar-mem";
276+
/// Has reasonably performant unaligned scalar
277+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_vector_mem: "unaligned-vector-mem";
278+
without cfg check: true; // FIXME: added in https://github.com/rust-lang/rust/pull/138742
279+
/// Has reasonably performant unaligned vector
197280
198281
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] svnapot: "svnapot";
199282
without cfg check: true;

0 commit comments

Comments
 (0)