diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2024-05-20 01:09:29 -0400 |
|---|---|---|
| committer | Caleb Zulawski <caleb.zulawski@gmail.com> | 2024-05-20 01:09:29 -0400 |
| commit | 86158f581d20948507bef65e6162e3bbf5f4fa91 (patch) | |
| tree | 4e9a96982519fac2fdb654a9790420defa138276 /tests | |
| parent | 959a67a7f2215d80b55e765d6c4b3f5a711ad484 (diff) | |
| download | rust-86158f581d20948507bef65e6162e3bbf5f4fa91.tar.gz rust-86158f581d20948507bef65e6162e3bbf5f4fa91.zip | |
Make repr(packed) vectors work with SIMD intrinsics
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/simd/repr_packed.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/tests/ui/simd/repr_packed.rs b/tests/ui/simd/repr_packed.rs index 411bba3454e..52c794563de 100644 --- a/tests/ui/simd/repr_packed.rs +++ b/tests/ui/simd/repr_packed.rs @@ -6,9 +6,6 @@ #[repr(simd, packed)] struct Simd<T, const N: usize>([T; N]); -#[repr(simd)] -struct FullSimd<T, const N: usize>([T; N]); - fn check_size_align<T, const N: usize>() { use std::mem; assert_eq!(mem::size_of::<Simd<T, N>>(), mem::size_of::<[T; N]>()); @@ -44,16 +41,9 @@ fn main() { simd_add(Simd::<f64, 4>([0., 1., 2., 3.]), Simd::<f64, 4>([2., 2., 2., 2.])); assert_eq!(std::mem::transmute::<_, [f64; 4]>(x), [2., 3., 4., 5.]); - // non-powers-of-two have padding and need to be expanded to full vectors - fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> { - unsafe { - let mut tmp = core::mem::MaybeUninit::<FullSimd<T, N>>::uninit(); - std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1); - tmp.assume_init() - } - } - let x: FullSimd<f64, 3> = - simd_add(load(Simd::<f64, 3>([0., 1., 2.])), load(Simd::<f64, 3>([2., 2., 2.]))); - assert_eq!(x.0, [2., 3., 4.]); + // non-powers-of-two have padding and lesser alignment, but the intrinsic handles it + let x: Simd<f64, 3> = simd_add(Simd::<f64, 3>([0., 1., 2.]), Simd::<f64, 3>([2., 2., 2.])); + let arr: [f64; 3] = x.0; + assert_eq!(arr, [2., 3., 4.]); } } |
