Skip to content

feat(cpufeatures): Extend ARM64 and x86 feature detection - #1565

Open
reneleonhardt wants to merge 3 commits into
RustCrypto:masterfrom
reneleonhardt:feat/cpufeatures-arm64-x86-detection
Open

reneleonhardt wants to merge 3 commits into
RustCrypto:masterfrom
reneleonhardt:feat/cpufeatures-arm64-x86-detection

Conversation

@reneleonhardt

Copy link
Copy Markdown

Summary

  • Add 45 ARM64 and x86 feature detectors for no_std use
  • Check CPU prerequisites, OS register state and CPUID limits
  • Read ARM64 HWCAP2 and x86 extended and XSAVE leaves only when needed
  • Make Apple capability queries safe and return false for missing keys
  • Run Linux ARM64 CI tests natively and remove unused macOS target setup

Closes #865

Refs #1112 and #1532 (avx512vnni support)

New flags

Family Flags
ARM64 bf16, crc, cssc, faminmax, fcma, fhm, frintts, i8mm, jsconv, lse2, lut, mops, neon, rand
ARM64 SVE f32mm, f64mm, sve, sve-b16b16, sve2, sve2-aes, sve2-bitperm, sve2-sha3, sve2-sm4, sve2p1
x86 prerequisites cmpxchg16b, f16c, fxsr, lahfsahf, lzcnt, movbe
x86 register state xsave, xsavec, xsaveopt, xsaves
x86 memory hints ermsb, prfchw
AVX2 extensions avxifma, avxneconvert, avxvnni, avxvnniint16, avxvnniint8
AVX-512 extensions avx512bf16, avx512fp16, avx512vnni, avx512vp2intersect

MOPS runtime detection returns false on Apple because no public capability key is documented.

Validation

  • Test sparse masks, missing prerequisites, CPUID bounds, register state and sysctl replies
  • Check unsafe query boundaries with compile-fail tests and pure guards with Miri
  • Test Rust 1.85 (MSRV) and 1.99.1, including no_std with libc 0.2.155
  • Check other ARM64 targets, Clippy, documentation, formatting, spelling and the locked workspace

Add NEON and more vector, scalar and memory feature detectors.

Read the second capability word only when needed. Check all required bits, including Rust's FP16 and SVE requirements.

Make Apple capability queries safe. Return false for missing keys. Keep MOPS runtime detection false on Apple without a documented capability key. Use compiler feature checks on targets without runtime detection.

Test sparse masks, missing bits, cached queries and combined queries. Test sysctl names and results with an injected reader. Run pure guards under Miri.
Add SIMD prerequisites, AVX2 and AVX-512 extensions, XSAVE variants and ERMSB/PREFETCHW memory hints.

Check CPUID limits before reading leaves and subleaves. Read extended and XSAVE data only when needed.

Check CPU prerequisites and OS register state. XSAVE needs CPU and OS support but does not require AVX register state. Require an unsafe context to check register state from supplied CPUID data.

Test sparse flags, missing prerequisites, CPUID limits, cached queries and combined queries. Check each required register-state bit. Test unsafe query boundaries with compile-fail tests.

Run pure guards under Miri with unsigned CPUID inputs. Keep runtime detection disabled under Miri.
Use Ubuntu ARM64 runners for both compiler versions. Remove Docker and QEMU setup.

Remove the unused macOS x86 target download. Keep the same test and compiler matrix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpufeatures: additional AVX-512 features

1 participant