Stabilize 29 RISC-V target features (`riscv_ratified_v2`)
This commit stabilizes RISC-V target features with following constraints:
* Describes a ratified extension.
* Implemented on Rust 1.88.0 or before.
Waiting for four+ version cycles seems sufficient.
* Does not disrupt current rustc's target feature (cf. rust-lang/rust#140570) + ABI (cf. rust-lang/rust#132618) handling.
It excludes `E` and all floating point-arithmetic extensions. The `Zfinx` family does not involve floating point registers but not stabilizing for now to avoid possible confusion between the `F` extension family.
* Not vector-related (floating point and integer).
While integer vector subsets should not cause any ABI issues (as they don't use ABI-dependent floating point registers), we need to discuss before stabilizing them.
* Supported by the lowest LLVM version supported by rustc (LLVM 20).
List of target features to be stabilized:
1. `b`
2. `za64rs` (no-RT)
3. `za128rs` (no-RT)
4. `zaamo`
5. `zabha`
6. `zacas`
7. `zalrsc`
8. `zama16b` (no-RT)
9. `zawrs`
10. `zca`
11. `zcb`
12. `zcmop`
13. `zic64b` (no-RT)
14. `zicbom`
15. `zicbop` (no-RT)
16. `zicboz`
17. `ziccamoa` (no-RT)
18. `ziccif` (no-RT)
19. `zicclsm` (no-RT)
20. `ziccrse` (no-RT)
21. `zicntr`
22. `zicond`
23. `zicsr`
24. `zifencei`
25. `zihintntl`
26. `zihintpause`
27. `zihpm`
28. `zimop`
29. `ztso`
Of which, 20 of them (29 minus 9 "no-RT" target features) support runtime detection through `std::arch::is_riscv_feature_detected!()`.
Corresponding PR for the Reference: rust-lang/reference#1987
|
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| README.md | ||
std::detect - Rust's standard library run-time CPU feature detection
The private std::detect module implements run-time feature detection in Rust's
standard library. This allows detecting whether the CPU the binary runs on
supports certain features, like SIMD instructions.
Usage
std::detect APIs are available as part of libstd. Prefer using it via the
standard library than through this crate. Unstable features of std::detect are
available on nightly Rust behind various feature-gates.
If you need run-time feature detection in #[no_std] environments, Rust core
library cannot help you. By design, Rust core is platform independent, but
performing run-time feature detection requires a certain level of cooperation
from the platform.
You can then manually include std_detect as a dependency to get similar
run-time feature detection support than the one offered by Rust's standard
library. We intend to make std_detect more flexible and configurable in this
regard to better serve the needs of #[no_std] targets.
Features
-
std_detect_dlsym_getauxval(enabled by default, requireslibc): Enable to uselibc::dlsymto query whethergetauxvalis linked into the binary. When this is not the case, this feature allows other fallback methods to perform run-time feature detection. When this feature is disabled,std_detectassumes thatgetauxvalis linked to the binary. If that is not the case the behavior is undefined.Note: This feature is ignored on
*-linux-{gnu,musl,ohos}*and*-android*targets because we can safely assumegetauxvalis linked to the binary.*-linux-gnu*targets (since Rust 1.64) have glibc requirements higher than glibc 2.16 that addedgetauxval.*-linux-musl*targets (at least since Rust 1.15) use musl newer than musl 1.1.0 that addedgetauxval*-linux-ohos*targets use a fork of musl 1.2*-android*targets (since Rust 1.68) have the minimum supported API level higher than Android 4.3 (API level 18) that addedgetauxval.
-
std_detect_file_io(enabled by default, requiresstd): Enable to perform run-time feature detection using file APIs (e.g./proc/self/auxv, etc.) if other more performant methods fail. This feature requireslibstdas a dependency, preventing the crate from working on applications in whichstdis not available.
Platform support
-
All
x86/x86_64targets are supported on all platforms by querying thecpuidinstruction directly for the features supported by the hardware and the operating system.std_detectassumes that the binary is an user-space application. -
Linux/Android:
arm{32, 64},mips{32,64}{,el},powerpc{32,64}{,le},loongarch{32,64},s390x:std_detectsupports these on Linux by querying ELF auxiliary vectors (usinggetauxvalwhen available), and if that fails, by querying/proc/self/auxv.arm64: partial support for doing run-time feature detection by directly queryingmrsis implemented for Linux >= 4.11, but not enabled by default.riscv{32,64}:std_detectsupports these on Linux by queryingriscv_hwprobe, and by querying ELF auxiliary vectors (usinggetauxvalwhen available).
-
FreeBSD:
arm32,powerpc64:std_detectsupports these on FreeBSD by querying ELF auxiliary vectors usingelf_aux_info.arm64: run-time feature detection is implemented by directly queryingmrs.
-
OpenBSD:
powerpc64:std_detectsupports these on OpenBSD by querying ELF auxiliary vectors usingelf_aux_info.arm64: run-time feature detection is implemented by queryingsysctl.
-
Windows:
arm64: run-time feature detection is implemented by queryingIsProcessorFeaturePresent.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in std_detect by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.