rust-lang / stdarch

Rust's standard library vendor-specific APIs and run-time feature detection
https://doc.rust-lang.org/stable/core/arch/
Apache License 2.0
601 stars 267 forks source link

x86 AVX intrinsics inconsistency #1580

Closed sayantn closed 3 months ago

sayantn commented 3 months ago

When AVX512 was introduced, it introduced many new instructions for 128 and 256 bit vectors, too. When Intel decided to make AVX512 for servers only, they introduced new instruction sets AVX-VNNI, AVX-IFMA, AVX-NE-CONVERT, AVX-VNNI-INT8 and AVX-VNNI-INT16 for desktop computers. But currently, in Rust, we have no way to check for these features (we can't do all of AVX-NE-CONVERT due to the lack of f16 type yet). LLVM does have these intrinsics and code generation features. Also, Rust doesn't have SHA512, SM3 and SM4 intrinsics (LLVM has the intrinsics). These will be very important as all these intrinsics will be available in Arrow Lake and Lunar Lake, which will be of major importance in 2025.

New target-features:

We would need to introduce these target-features and port the existing intrinsics to them.

New Intrinsic Families:

After f16 is stabilized, we would need to do AVX512-FP16 and F16C too (and complete AVX-NE-CONVERT).

Also, there is an inconsistency between is_x86_feature_detected and cfg(target_feature). For "backported" AVX512 intrinsics, like GFNI, VAES, VPCLMULQDQ (and probably VNNI AND IFMA, too), cfg(target_feature) can detect the feature in CPU, but the detect macro is unable to. This happens in AlderLake and RaptorLake, but it will also be an issue in ArrowLake and LunarLake.