about summary refs log tree commit diff
path: root/library/stdarch/crates/std_detect/src/detect
AgeCommit message (Collapse)AuthorLines
2025-07-22Move `std_detect` from `library/stdarch` to `library`Jakub Beránek-4451/+0
2025-07-14Merge pull request #1837 from heiher/loong32Amanieu d'Antras-3/+6
loongarch: Add basic support for LoongArch32
2025-07-07std_detect: RISC-V Linux: Ergonomic querying with `riscv_hwprobe`Tsukasa OI-41/+42
Originally, we used an array of `riscv_hwprobe` directly and indexed using raw numbers, making correspondence between the index and the query key less obvious. We also frequently used `out[idx].key != -1` to test whether the key is supported by the `riscv_hwprobe` system call (on the Linux kernel version we are testing) but we'd better to integrate with an operation to retrieve the value. This commit improves the ergonomics of feature querying by: 1. Utilizing macros to a. enable indexing by identifier names and b. encapsulate accesses to the `riscv_hwprobe` array to query and 2. New method `riscv_hwprobe::get()` returning `Option<u64>`, integrating availability checking and value retrieval. It also removes `has_ima` for now because it's redundant if we only need to test for single base behavior.
2025-07-07Update stabilization version of certain x86 intrinsics to 1.89Amanieu d'Antras-5/+5
These were left as `CURRENT_RUSTC_VERSION` in the submodule.
2025-07-03std_detect: Tidying of slice lengthTsukasa OI-2/+1
We don't need to put the length of the `riscv_hwprobe` array into a variable. This commit removes that variable and gives the length of the output slice to the `__riscv_hwprobe` directly.
2025-06-28loongarch: Add basic support for LoongArch32WANG Rui-3/+6
2025-06-19s390x: add feature detection for the z17 target featuresFolkert de Vries-56/+97
2025-06-09Darwin AArch64 detection updateLaine Taffin Altman-0/+8
Synchronizes the lists of detectable features with macOS 15.5 “Sequoia” as of June 9, 2025.
2025-06-09add s390x z17 target featuresFolkert de Vries-0/+15
2025-06-01RISC-V: Linux 6.15 `riscv_hwprobe` supportTsukasa OI-3/+35
This commit adds support for `riscv_hwprobe` on the Linux kernel 6.15. It adds feature detection of 8 extensions (4 of them are new in this). Existing RISC-V Extensions: 1. "Zicntr" 2. "Zihpm" 3. "Zalrsc" 4. "Zaamo" New RISC-V Extensions: 5. "Zicbom" 6. "Zfbfmin" 7. "Zvfbfmin" 8. "Zvfbfwma"
2025-05-31Stabilize `sha512`, `sm3` and `sm4` intrinsics and runtime detectionsayantn-3/+3
2025-05-31Stabilize keylocker intrinsics and runtime detectionsayantn-2/+2
2025-05-30RISC-V: Linux: Imply Zicntr from the IMA base behaviorTsukasa OI-6/+4
As the author confirmed as in: <https://lists.infradead.org/pipermail/linux-riscv/2025-May/070844.html>, runtime detection of the Zicntr extension (as in the Linux kernel 6.15) is currently (and technically) redundant on the current base IMA behavior (although can be meaningful if new base behavior is added). This commit implies the Zicntr extension from the base IMA behavior.
2025-05-30Add back `std_detect_env_override`sayantn-2/+67
2025-05-30Check cfg on features that stage0 compiler supportTsukasa OI-20/+0
Since the bootstrap compiler of Rust is bumped to the commit 5dadfd5c417f0b66816cb7ca662859e2c8751fb3 (version 1.88.0-beta.3 2025-05-11), some features should be safe to enable cfg checks. RISC-V Features: * "zicsr" * "zicntr" * "zihpm" * "zifencei" * "zihintntl" * "zihintpause" * "zimop" * "zicboz" * "zicond" * "ztso" * "zfa" * "zca" * "zcb" * "zcmop" * "b" x86 Features: * "amx-avx512" * "amx-fp8" * "amx-movrs" * "amx-tf32" * "amx-transpose"
2025-05-26std_detect: RISC-V platform guide documentation (non-table part)Tsukasa OI-0/+15
This is a partial revert of a revert, making the commit e907456b2e10622ccd854a3bba8d02ce170b5dbb come around again for non-table part.
2025-05-17Correct rustc version for the stabilization of runtime detection of VEX ↵sayantn-5/+5
variants of avx512
2025-05-17Stabilize runtime detection of VEX variants of avx512sayantn-5/+5
2025-05-12Partially stabilize LoongArch target featuresWANG Rui-9/+9
2025-05-03fix - aarch64_be testsJames Barford-Evans-0/+3
2025-05-01Require `fma` and `f16c` for `avx512f` in `std_detect`sayantn-4/+10
2025-05-01Revert "std_detect: RISC-V platform guide documentation"Tsukasa OI-126/+78
This reverts commit e907456b2e10622ccd854a3bba8d02ce170b5dbb. This is due to a CI failure (technically broken HTML with duplicate IDs) caused by this commit (visibly fine but invalid per the HTML specification and detected by the LinkCheck tool on the Rust CI process). The author independently working on a rustdoc enhancement to enable writing multiple references to a single footnote. Once that change makes it to the stage0 compiler (the next beta), the original change will be acceptable again (postponed for possibly the version 1.89 cycle).
2025-04-23std_detect: RISC-V platform guide documentationTsukasa OI-78/+126
Since there's no architectural feature detection on RISC-V (unlike `CPUID` on x86 architectures and some system registers on Arm/AArch64), runtime feature detection entirely depends on the platform-specific facility. As a result, availability of each feature heavily depends on the platform and its version. To help users make a decision for feature checking on a RISC-V system, this commit adds a platform guide with minimum supported platform versions. Note: It intentionally omits the description of the reverse implication related to *extension groups* (such like implication of `B` *from* its members: `Zba`, `Zbb` and `Zbs` extensions) because it currently does not synchronize well with the `-Ctarget-feature` compiler option (due to missing reverse implication checks using `cfg` and due to constraints of the current Rust's feature handling). Instead, it only describes forward implications (like `D` implying `F`) due to the fact that it relatively synchronizes well between Rust and `stdarch` for this kind of feature handling (not fully synchronized though). Still, an extension group is considered "supported" once the platform/version supports runtime detection of all members in it.
2025-04-23Add power9 and power8 target-featuresLuca Barbato-1/+35
2025-04-20Remove `cupid` dependency and `env-override-no-avx` CI runsayantn-66/+2
2025-04-20std_detect: Remove /proc/cpuinfo-based detectionTaiki Endo-506/+5
2025-04-16Revert "std_detect: Do not use libc::getauxval on 32-bit Android"Taiki Endo-2/+1
This reverts commit 85572dc298f5222902c9b200cebf5d045e769a83.
2025-04-16std_detect: Remove RV32E support attempt on Linux (RISC-V)Tsukasa OI-3/+0
Because the current lowest requirements to run the Linux kernel on RISC-V is RV{32,64}IMA (with 32 general purpose registers) plus some features, RV32E (with only 16 GPRs) is not currently supported. Since it's not sure whether current implemented method will work for future Linux versions even if the minimum requirements are lowered, the support for RV32E (to be more specific, an attempt to do that) is removed for now.
2025-04-16RISC-V: Remove privileged extensions for nowTsukasa OI-30/+0
Until in-kernel feature detection is implemented, runtime detection of privileged extensions is temporally removed along with features themselves since none of such privileged features are stable. Co-Authored-By: Taiki Endo <te316e89@gmail.com> Co-Authored-By: Amanieu d'Antras <amanieu@gmail.com>
2025-04-16RISC-V: `riscv_hwprobe`-based feature detection on Linux / AndroidTsukasa OI-15/+474
This commit implements `riscv_hwprobe`-based feature detection as available on newer versions of the Linux kernel. It also queries whether the vector extensions are enabled using `prctl` but this is not supported on QEMU's userland emulator (as of version 9.2.3) and use the auxiliary vector as a fallback. Currently, all extensions discoverable from the Linux kernel version 6.14 and related extension groups (except "Supm", which reports the existence of `prctl`-based pointer masking control and too OS-dependent) are implemented. Co-Authored-By: Taiki Endo <te316e89@gmail.com>
2025-04-16RISC-V: OS-independent implication logicTsukasa OI-12/+158
This commit adds the OS-independent extension implication logic for RISC-V. It implements: 1. Regular implication (A → B) a. "the extension A implies the extension B" b. "the extension A requires the extension B" c. "the extension A depends on the extension B" 2. Extension group or shorthand (A == B1 & B2...) a. "the extension A is shorthand for other extensions: B1, B2..." b. "the extension A comprises instructions provided by B1, B2..." This is implemented as (A → B1 & B2... + B1 & B2... → A) where the former is a regular implication as required by specifications and the latter is a "reverse" implication to improve usability. and prepares for: 3. Implication with multiple requirements (A1 & A2... → B) a. "A1 + A2 implies B" b. (implicitly used to implement reverse implication of case 2) Although it uses macros and iterators, good optimizers turn the series of implications into fast bit-manipulation operations. In the case 2 (extension group or shorthand; where a superset extension is just a collection of other subextensions and provides no features by a superset itself), specifications do specify that an extension group implies its members but not vice versa. However, implying an extension group from its members would improve usability on the feature detection (especially when the feature provider does not provide existence of such extension group but provides existence of its members). Similar "reverse implication" on RISC-V is implemented on LLVM. Case 3 is implicitly used to implement reverse implication of case 2 but there's another use case: implication with multiple requirements like "Zcf" and "Zcd" extensions (not yet implemented in this crate for now). To handle extension groups perfectly, we need to loop implication several times (until they converge; normally 2 times and up to 4 times when we add most of `riscv_hwprobe`-based features). To make implementation of that loop possible, `cache::Initializer` is modified to implement `PartialEq` and `Eq`.
2025-04-16RISC-V: Add placeholder for the "B" extensionTsukasa OI-2/+5
The "B" extension is once abandoned (instead, it is ratified as a collection of "Zb*" extensions). However, it is later redefined and ratified as a superset of "Zba", "Zbb" and "Zbs" extensions (but not "Zbc" carry-less multiplication for limited benefits and implementation cost). Although non-functional (because feature detection is not yet implemented), it provides the foundation to implement this extension (along with straightforward documentation showing subsets of "B").
2025-04-16RISC-V: Add two "A" extension subsetsTsukasa OI-1/+10
The "A" extension comprises instructions provided by the "Zaamo" and "Zalrsc" extensions. To prepare for the "Zacas" extension (which provides compare-and-swap instructions and discoverable from Linux) which depends on the "Zaamo" extension, it would be better to support those subsets.
2025-04-16RISC-V: Use `target_arch` for RV(32|64) detectionTsukasa OI-4/+6
As Taiki Endo pointed out, there's a problem if we continue using `target_pointer_width` values to detect an architecture because: * There are separate `target_arch`s already and * There is an experimental ABI (not ratified though): RV64ILP32. cf. <https://lpc.events/event/17/contributions/1475/attachments/1186/2442/rv64ilp32_%20Run%20ILP32%20on%20RV64%20ISA.pdf> Co-Authored-By: Taiki Endo <te316e89@gmail.com>
2025-04-16RISC-V: Remove `enable_features`Tsukasa OI-45/+13
This commit prepares common infrastructure for extension implication by removing `enable_features` closure which makes each feature test longer (because it needs extra `value` argument each time we test a feature). It comes with the overhead to enable each feature separately but later mitigated by the OS-independent extension implication logic.
2025-04-16RISC-V: tidying: Make auxvec-based enablement a blockTsukasa OI-0/+1
Because this function will be no longer auxvec-only, this commit adds a comment to mark auxvec-based part. It *does not* add a comment to "base ISA" part because it may also use `riscv_hwprobe`-based results.
2025-04-16RISC-V: tidying: Handling of base ISATsukasa OI-10/+14
This commit makes handling of the base ISA a separate block. Co-Authored-By: Taiki Endo <te316e89@gmail.com>
2025-04-16RISC-V: tidying: Prefer more canonical referenceTsukasa OI-1/+1
1. Use canonical kernel.org repository instead of the GitHub mirror. 2. Refer to the fixed commit to guarantee access. 3. Use `uapi` part to ensure that the feature detection is primarily intended for user-mode programs.
2025-04-12RISC-V: tidying: Fix separation of I-related extensionsTsukasa OI-1/+1
The author intended to split: 1. Former "I" extensions 2. Other "I"-related extensions but incorrectly separated between "Zihpm" (a supplement of "Zicntr" which is a former "I" extension) and "Zifencei" (a former "I" extension) while the author intended making a separation between "Zifencei" and "Zihintpause" (not a part of "I"). This commit fixes the separation.
2025-04-12RISC-V: doc: tidying: Move link to the ISA ManualTsukasa OI-2/+2
Not only moving the link to the end of the section, this commit changes the link so that we can reach to the *ratified* ISA manuals (note that, while the original URL (GitHub) is a good place to browse the latest draft, it's not easy to know which is the ratified version; even "Releases" page is not helpful since it's regularly updated).
2025-04-12RISC-V: doc: Updated status and clarificationTsukasa OI-24/+21
Some extensions are ratified at least on the ISA specification version 20240411. This commit moves such extensions. This commit also changes that: 1. Lower indentation of "Zk*" and "Zbk*" extensions to avoid extension groups from being misleading inside this section. 2. Raise indentation of "Zfhmin" and "Zhinxmin" extensions to show that they are a strict subset of "Zfh" and "Zhinx" (respectively). 3. Clarify that "s" is not an extension but a feature notifying the existence of the supervisor-level ISA. 4. Clarify that "h" is not just an existence of the hypervisor-level ISA but is also an extension name ("H").
2025-04-12RISC-V: doc: Capitalize some words for consistencyTsukasa OI-5/+5
RISC-V extension names are capitalized for consistency.
2025-04-10Disable cfg check for the recently-merged target features to allow stdarch ↵sayantn-1/+11
update
2025-04-07Add feature detection for new amx variants and movrssayantn-9/+42
2025-04-06RISC-V: check cfg (batch 1)Tsukasa OI-5/+0
rust-lang/rust#138823 added five new extensions as compiler target features. This commit reflects that fact and now checks static target features on `std::arch::is_riscv_feature_detected!` as well. * "Zicsr" * "Zicntr" * "Zihpm" * "Zifencei" * "Zihintpause"
2025-03-26std_detect: Move cfgs into getauxval helper functionTaiki Endo-94/+35
2025-03-26std_detect: Always avoid dlsym on *-linux-{musl,ohos}* targetsTaiki Endo-8/+22
2025-03-24tentatively remove the "B" RISC-V extension from the documentationTsukasa OI-1/+1
Although the "B" extension is redefined and ratified, keeping this in the documentation as-is have two issues: * "B" extension is not added to `riscv.rs` yet (to be added later). * "B" extension is ratified as a combination of "Zba", "Zbb" and "Zbs" extensions and "Zbc" is *not* a part of "B" itself (despite that it is listed under "B"), which makes the documentation misleading. This commit tentatively removes the reference to the "B" extension and replaced with "Bit Manipulation Extensions" without an extension name.
2025-03-24reword RISC-V feature documentationTsukasa OI-43/+43
As the version 20240411 of the RISC-V ISA Manual changed wording to describe many of the standard extensions, this commit largely follows this scheme in general. In many cases, words "Standard Extension" are replaced with "Extension" following the latest ratified ISA Manual. Some RISC-V extensions had tentative summary but it also fixes that (e.g. "Zihintpause"). Following extensions are described in parity with corresponding extensions using floating-point registers: * "Zfinx" Extension for Single-Precision Floating-Point in Integer Registers * "Zdinx" Extension for Double-Precision Floating-Point in Integer Registers * "Zhinx" Extension for Half-Precision Floating-Point in Integer Registers * "Zhinxmin" Extension for Minimal Half-Precision Floating-Point in Integer Registers Following extensions are named against the ISA Manual naming but considered inconsistency inside the ISA manual: * "Zfhmin" Extension for Minimal Half-Precision Floating-Point ISA Manual: "Zfhmin" Standard Extension for Minimal Half-Precision Floating-Point * "V" Extension for Vector Operations ISA Manual: "V" Standard Extension for Vector Operations Following extension is removed from the latest ratified ISA Manual but named like others: * "Zam" Extension for Misaligned Atomics "Zb*" extensions are described like "Extension for ..." using partial summary per extension (including cryptography-related "Zbk*" extensions). "Zk*" extensions are described like "Cryptography Extension for ..." using partial summary per extension (e.g. 'Zkne - NIST Suite: AES Encryption' in the ISA Manual to '"Zkne" Cryptography Extension for NIST Suite: AES Encryption') except following extensions: * "Zkr" Entropy Source Extension Following the general rule will make the description redundant. * "Zk" Cryptography Extension for Standard scalar cryptography The last word "extension" is removed as seemed redundant. Link: <https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154769/RISC-V+Technical+Specifications> (ISA Specifications, Version 20240411; published in May 2024)
2025-03-24reorder all RISC-V features for maintenanceTsukasa OI-51/+59
All RISC-V Features are reordered for better maintainability. The author has a plan to add many RISC-V ratified extensions (mainly discoverable from Linux) and this is a part of preparation. Sections are divided as follows: * Base ISAs * "I"-related * Extensions formerly a part of the base "I" extension but divided later (now all of them are ratified). * Other user-mode extensions "Zi*". * "M"-related (currently "M" only) * "A"-related "A", "Za*" and "Ztso" which is named differently but absolutely related to memory operations. * Base FP extensions * Base FP extensions using integer registers * "C"-related (currently "C" only) * "B"-related (except cryptography-related "Zbk*") * Scalar cryptography extensions (including "Zbk*") * Base Vector extensions (currently "V" only) * Ratified privileged extensions * Non-extensions and non-ratified extensions which is *not* going to be ratified, at least in the draft form The last section needs some explanation. "S" is not an extension (although some buggy implementations such as QEMU up to 7.0 emitted this character as well as "U" as an extension) and the DeviceTree parser in the Linux kernel explicitly workarounds this issue. There's no plan for ratification of the single-letter "J" extension (there's a room for redefinition like the "B" extension but unlikely). Instead, pointer masking extensions including "Supm" is one of the results of the task group discussing J extension*s*. There's also an instruction in the "Zfa" extension which accelerates FP-to-int conversion matching JavaScript semantics. "P" is being actively discussed (and will result in a single-letter "P" extension and various "Zp*" extensions) but it seems there needs some time until ratification. And there's one Rust-specific issue: Rust implements Packed-SIMD intrinsics based on an early draft of the "P" extension and they are *very unlikely* kept as-is. For instance, `add16` does not follow standard RISC-V instruction naming (ADD16 is the name from the Andes' proposal) and going to be renamed. Before moving "P" to above, we have to clearly understand what the final "P" extension will be and resolve existing intrinsics.