diff options
| author | Luca Versari <veluca@google.com> | 2025-08-18 15:09:45 +0200 |
|---|---|---|
| committer | Luca Versari <veluca@google.com> | 2025-08-22 01:26:26 +0200 |
| commit | 291da71b2ae2e5d313739a7d6a8ffa634f408db5 (patch) | |
| tree | 61a65575461bc4d16394c51ba93dff879b32a39b /tests/assembly-llvm/force-target-feature.rs | |
| parent | 6ba0ce40941eee1ca02e9ba49c791ada5158747a (diff) | |
| download | rust-291da71b2ae2e5d313739a7d6a8ffa634f408db5.tar.gz rust-291da71b2ae2e5d313739a7d6a8ffa634f408db5.zip | |
Add an experimental unsafe(force_target_feature) attribute.
This uses the feature gate for https://github.com/rust-lang/rust/issues/143352, but is described in https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to the experiment.
Diffstat (limited to 'tests/assembly-llvm/force-target-feature.rs')
| -rw-r--r-- | tests/assembly-llvm/force-target-feature.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/assembly-llvm/force-target-feature.rs b/tests/assembly-llvm/force-target-feature.rs new file mode 100644 index 00000000000..c11060d8d6d --- /dev/null +++ b/tests/assembly-llvm/force-target-feature.rs @@ -0,0 +1,33 @@ +//@ only-x86_64 +//@ assembly-output: emit-asm +//@ compile-flags: -C opt-level=3 -C target-feature=-avx2 +//@ ignore-sgx Tests incompatible with LVI mitigations + +#![feature(effective_target_features)] + +use std::arch::x86_64::{__m256i, _mm256_add_epi32, _mm256_setzero_si256}; +use std::ops::Add; + +#[derive(Clone, Copy)] +struct AvxU32(__m256i); + +impl Add<AvxU32> for AvxU32 { + type Output = Self; + + #[no_mangle] + #[inline(never)] + #[unsafe(force_target_feature(enable = "avx2"))] + fn add(self, oth: AvxU32) -> AvxU32 { + // CHECK-LABEL: add: + // CHECK-NOT: callq + // CHECK: vpaddd + // CHECK: retq + Self(_mm256_add_epi32(self.0, oth.0)) + } +} + +fn main() { + assert!(is_x86_feature_detected!("avx2")); + let v = AvxU32(unsafe { _mm256_setzero_si256() }); + v + v; +} |
