257 Commits

Author SHA1 Message Date
Tsukasa OI
5feb3c989e resolve clippy::doc_lazy_continuation
This commit adds indentation as suggested by the Clippy warning.
2025-03-24 23:27:46 +00:00
Tsukasa OI
be20f62a20 silence clippy::eq_op while checking
This error occurs when the RISC-V "A" Extension is being tested.
2025-03-24 23:27:31 +00:00
Taiki Endo
1c136ddc5a std_detect: Support detecting more features on AArch64 Windows 2025-03-24 23:25:59 +00:00
sayantn
a9135c1634 Temporary fix: change the feature gate of VEX variants 2025-03-24 23:23:59 +00:00
WANG Rui
ad03413c39 std_detect: Add target features for LoongArch v1.1 2025-03-20 22:26:36 +00:00
Tsukasa OI
c0fc23f2d8 Fix: stabilized version of RISC-V feature macro
RISC-V runtime feature detection macro is stabilized on Rust 1.78.0,
not Rust 1.76.0.
2025-03-20 21:54:50 +00:00
Eduardo Sánchez Muñoz
b8d25bdefa Remove some allow(unsafe_op_in_unsafe_fn)s and use target_feature 1.1 in examples 2025-02-25 01:11:47 +00:00
Folkert de Vries
67468b20ff add newly-added s390x features to is_s390x_feature_detected 2025-02-23 23:53:36 +00:00
sayantn
2a6953d38a Add runtime feature detection for keylocker 2025-02-13 10:54:53 +00:00
Eric Huss
d9ec0157da Format with style edition 2024 2025-02-09 12:57:14 -08:00
Eric Huss
699a872630 Update all crates to Rust 2024 2025-02-09 12:31:33 -08:00
Eric Huss
844a604bf0 Allow unsafe_op_in_unsafe_fn
Because stdarch has a really large number of unsafe functions with
single-line calls, `unsafe_op_in_unsafe_fn` would end up adding a lot of
noise, so for now we will allow it to migrate to 2024.
2025-02-09 12:31:30 -08:00
Eric Huss
64e9ca74a8 Apply missing_unsafe_on_extern 2025-02-09 09:12:30 -08:00
sayantn
efb7cf80b9 Move all x86 std_detect tests to x86-specific.rs to reduce duplication 2025-02-07 22:09:48 +00:00
Folkert de Vries
b5babcfac2 add is_s390x_feature_detected 2025-01-16 20:39:13 +00:00
Laine Taffin Altman
dbdcef3f3c Expand feature detection on AArch64 Darwin
This reflects the currently available set of sysctl values as of macOS 15, on 2024-12-21.  Features not (yet) exposed by `is_aarch64_feature_detected` have been left in comments to document their existence for the future.
2024-12-23 10:54:10 +00:00
Nicholas Nethercote
ddf10db1a3 Fix the features macro.
The first rule of the `features` macro looks like this:
```
macro_rules! features {
    (
      @TARGET: $target:ident;
      @CFG: $cfg:meta;
      @MACRO_NAME: $macro_name:ident;
      @MACRO_ATTRS: $(#[$macro_attrs:meta])*
      $(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; $(#[$deprecate_attr:meta];)?)*
      $(@NO_RUNTIME_DETECTION: $nort_feature:tt; )*
      $(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt;
          $(without cfg check: $feature_cfg_check:literal;)?
          $(implied by target_features: [$($target_feature_lit:tt),*];)?
          $(#[$feature_comment:meta])*)*
    ) => {
```
Notice all the `tt` specifiers. They are used because they are forwarded
to another macro. Only `ident`, `lifetime`, and `tt` specifiers can be
forwarded this way.

But there is an exception: `$feature_lit:tt`, which was added recently.
In theory it should cause an error like this:
```
error: no rules expected `literal` metavariable
   --> /home/njn/dev/rust3/library/stdarch/crates/std_detect/src/detect/macros.rs:54:91
    |
51  | /         macro_rules! $macro_name {
52  | |             $(
53  | |                 ($feature_lit) => {
54  | |                     $crate::detect_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? ...
    | |                                                                                           ^^^^^^^^^^^^^^^^^^ no rules expected this token in macro call
...   |
88  | |             };
89  | |         }
    | |_________- in this expansion of `is_x86_feature_detected!`
    |
   ::: std/tests/run-time-detect.rs:145:27
    |
145 |       println!("tsc: {:?}", is_x86_feature_detected!("tsc"));
    |                             ------------------------------- in this macro invocation
    |
note: while trying to match keyword `true`
   --> /home/njn/dev/rust3/library/stdarch/crates/std_detect/src/detect/macros.rs:12:55
    |
12  |     ($feature:tt, $feature_lit:tt, without cfg check: true) => {
    |                                                       ^^^^
    = note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
    = note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
```
(The URL at the end of the error has more details about this forwarding
limitation.)

In practice it doesn't cause this error. I'm not sure why, but the
existing macro implementation in rustc is far from perfect, so it's
believable that it does the wrong thing here.

Why does this matter? Because https://github.com/rust-lang/rust/pull/124141
is modifying the macro implementation, and when that PR is applied the
error *does* occur. (It's one of several cases I have found where the
existing compiler accepts code it shouldn't, but #124141 causes that
code to be rejected.)

Fortunately the fix is simple: replace the `literal` specifier with `tt`.
2024-11-30 21:32:50 +00:00
Urgau
91c0dabca3 Enable without cfg check test in std_detect 2024-11-30 00:01:44 +00:00
Urgau
7956142f92 Add compile-time tests against unexpected target features cfgs 2024-11-08 06:17:06 +08:00
Urgau
f62e1daa2d Mark feature with missing corresponding target feature cfgs as such
Computed by diffing of:
$ rg "[ ]+@FEATURE: .*: \"(.*)\";" -r '$1' --no-filename \
  crates/std_detect/src/detect/ | sort | uniq

With (from the main Rust repo[^1]):
$ rg "target_feature" tests/ui/check-cfg/well-known-values.stderr

[^1]: e8c698bb3b/tests/ui/check-cfg/well-known-values.stderr (L177)
2024-11-08 06:17:06 +08:00
Urgau
a6a49cfd90 Add ability to declare a feature without cfg checking
This is necessary to avoid `unexpected_cfgs` warnings for unexpected/
missing target features, in user code.
2024-11-08 06:17:06 +08:00
Kajetan Puchalski
168479a4a5 std_detect: Add pauth-lr aarch64 target feature
Add feature detection for aarch64 FEAT_PAuth_LR.
There is currently no Linux cpuinfo support so the OS-specific lines are
commented out.
2024-10-27 02:59:49 +08:00
Yuri Astrakhan
0760ed6ca7 Minor linting 2024-09-30 13:00:24 -04:00
Kajetan Puchalski
485ded6369 std_detect: Add sme-b16b16 as an explicit aarch64 target feature
LLVM 20 split out what used to be called b16b16 and correspond to aarch64
FEAT_SVE_B16B16 into sve-b16b16 and sme-b16b16.
Add sme-b16b16 as an explicit feature and update the detection accordingly.
2024-09-18 12:48:54 -04:00
Taiki Endo
24b5e3c99e Use C string literal 2024-09-18 05:58:40 -04:00
Taiki Endo
9e5b3f5c8c std_detect: Fix link in mips.rs 2024-09-18 05:30:10 -04:00
Taiki Endo
720973b1b4 std_detect: Use elf_aux_info on FreeBSD 2024-09-18 05:07:32 -04:00
Mads Marquart
8a511191a0 Enable feature detection on all Apple/Darwin targets
Tested in the simulator and on the device I had lying around, a 1st
generation iPad Mini (which isn't Aarch64, but shows that the
`sysctlbyname` calls still work even there, even if they return false).

`sysctlbyname` _should_ be safe to use without causing rejections from
the app store, as its usage is documented in:
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics

Also, the standard library will use these soon anyhow, so this shouldn't
affect the situation:
https://github.com/rust-lang/rust/pull/129019
2024-09-14 04:25:01 +01:00
Kajetan Puchalski
351ec5744c std_detect: Update aarch64 feature dependencies to LLVM upstream
Feature dependencies for newer aarch64 fetaures differ between LLVM 18
in the Rust tree and upstream LLVM 19.
This commit updates those dependencies to reflect new LLVM upstream
changes.
2024-07-25 15:18:37 +01:00
Kajetan Puchalski
41dc17d3e5 std_detect: Sort aarch64 features
Alphabetically sort the list of aarch64 features.
The list was getting a bit too chaotic so it was worth properly
sorting.
2024-07-25 15:18:37 +01:00
Kajetan Puchalski
ef538bc614 std_detect: Add aarch64/linux/LLVM SME features
Add detection for SME features supported by LLVM and the Linux Kernel.
Include commented-out hwcap fields for features supported by Linux but not by LLVM.

This commit adds feature detection for the following features:

- FEAT_SME
- FEAT_SME_F16F16
- FEAT_SME_F64F64
- FEAT_SME_F8F16
- FEAT_SME_F8F32
- FEAT_SME_FA64
- FEAT_SME_I16I64
- FEAT_SME_LUTv2
- FEAT_SME2
- FEAT_SME2p1
- FEAT_SSVE_FP8DOT2
- FEAT_SSVE_FP8DOT4
- FEAT_SSVE_FP8FMA

Linux features: https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h
LLVM features: llvm-project/llvm/lib/Target/AArch64/AArch64.td
2024-07-25 15:18:37 +01:00
Kajetan Puchalski
dfc5dfc8ef std_detect: Add aarch64/linux/LLVM features
Add detection for various aarch64 CPU features already supported by LLVM and Linux.

This commit adds feature detection for the following features:

- FEAT_CSSC
- FEAT_ECV
- FEAT_FAMINMAX
- FEAT_FLAGM2
- FEAT_FP8
- FEAT_FP8DOT2
- FEAT_FP8DOT4
- FEAT_FP8FMA
- FEAT_HBC
- FEAT_LSE128
- FEAT_LUT
- FEAT_MOPS
- FEAT_LRCPC3
- FEAT_SVE_B16B16
- FEAT_SVE2p1
- FEAT_WFxT

It also adds feature detection for FEAT_FPMR. It is somewhat of a
special case because FPMR only exists as a feature in LLVM 18, it has
been removed from the LLVM upstream. On that account the intention is
for it to be detectable at runtime through stdarch but not have a
corresponding compile-time Rust target feature.

Linux features: https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h
LLVM features: llvm-project/llvm/lib/Target/AArch64/AArch64.td
2024-07-25 15:18:37 +01:00
sayantn
94153c46e9 Implemented runtime detection of xop target-feature 2024-07-06 18:55:26 +02:00
sayantn
d67ca1fe09 Added runtime detection
Cannot do a `cupid` test because they don't support `amx`.
2024-07-06 18:28:25 +02:00
sayantn
268ac7fe92 Add detection for SHA512, SM3 and SM4
Cannot cross-verify with `cupid` because they do not have these features yet.
2024-07-06 11:29:28 +02:00
Jubilee Young
8b77e779cb Remove has_cpuid 2024-06-29 19:38:42 +02:00
sayantn
1f779b7b40 Added runtime detection
Expanded the cache size to 93 (we will need this in near future)
Fixed detection of VAES, GFNI and VPCLMULQDQ
Could not test with `cupid` because they do not support these yet
2024-06-23 10:36:46 +02:00
Daniel Paoliello
130bc86694 Remove libc dependency on Windows by using Win32 to get env vars 2024-05-07 20:50:51 +02:00
Ben Kimock
2a21235f7a Don't depend on libc for cfg(windows) 2024-04-22 01:24:03 +02:00
Daniel Paoliello
a00a70eacb arm64ec 2024-03-13 22:30:36 +00:00
WANG Rui
1fbe4dddec std_detect: loongarch: Add runtime detectable features from LLVM
* f
* d
* frecipe
* lbt
2024-03-07 23:00:39 +00:00
WANG Rui
5fd2d04ef7 std_detect: loongarch: Remove features not supported by LLVM 2024-03-07 23:00:39 +00:00
Mingzhuo Yin
012e4ce580 check sub-leaf to detect avx512bf16
Signed-off-by: Mingzhuo Yin <yinmingzhuo@gmail.com>
2024-03-05 23:16:09 +00:00
Mingzhuo Yin
210913f1c4 fix: invalid bit for detecting avx512 feature
Signed-off-by: Mingzhuo Yin <yinmingzhuo@gmail.com>
2024-03-05 23:16:09 +00:00
usamoi
8531e289b0 feat: std_detect avx512fp16
Signed-off-by: usamoi <usamoi@outlook.com>
2024-02-24 16:07:04 +00:00
Adam Gemmell
e54a6d71bf Improve feature detect for combined aarch64 features
LLVM's `ssbs` and `mte` target_features represent two Arm features.
Linux's HWCAP also represents the same two features, so this is just a
documentation update.

LLVM's `ras` target_feature represents two Arm features - FEAT_RAS and FEAT_RASv1p1. There is no runtime detection for this, so this is a no-op in stdarch.

LLVM's `aes` feature covers both `FEAT_AES` and `FEAT_PMULL`, but Linux
exposes seperate feature bits. This patch makes the `aes` target_feature
correctly shortcut runtime `pmull` detection and also makes the `aes`
feature check for `pmull` at runtime to bring it in line with the
target_feature behaviour. In practice I think this makes the two runtime
features identical since the ID_AA64ISAR0_EL1 register does not allow
for PMULL without AES.
2024-02-16 18:21:34 +00:00
daxpedda
1e8274d34d Remove last mention of stdsimd 2024-02-14 15:08:29 +00:00
Makoto Kato
d51ea0d261 Add CPU detection for macOS/aarch64. 2024-01-16 02:57:10 +00:00
Amanieu d'Antras
76d52cdd68 Fix std_detect not being an unstable crate
More fallout from #1486
2024-01-05 11:14:38 +00:00
Amanieu d'Antras
fd973c2765 Fix std build failure on non-x86 architectures
This is more fallout from #1486
2024-01-04 13:00:34 +00:00