From 20413b1947a3c70b8b4fc4c9ec4b153435a54d38 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Tue, 24 Oct 2023 22:21:42 -0400 Subject: [PATCH] Add test using non-power-of-two vector --- tests/ui/simd/repr_packed.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/ui/simd/repr_packed.rs b/tests/ui/simd/repr_packed.rs index bfe9a2433f6..df2d59a58b8 100644 --- a/tests/ui/simd/repr_packed.rs +++ b/tests/ui/simd/repr_packed.rs @@ -6,6 +6,9 @@ #[repr(simd, packed)] struct Simd([T; N]); +#[repr(simd)] +struct FullSimd([T; N]); + fn check_size_align() { use std::mem; assert_eq!(mem::size_of::>(), mem::size_of::<[T; N]>()); @@ -37,9 +40,20 @@ fn main() { unsafe { // powers-of-two have no padding and work as usual - // non-powers-of-two have padding and need to be expanded to full vectors let x: Simd = simd_add(Simd::([0., 1., 2., 3.]), Simd::([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(v: Simd) -> FullSimd { + unsafe { + let mut tmp = core::mem::MaybeUninit::>::uninit(); + std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1); + tmp.assume_init() + } + } + let x: FullSimd = + simd_add(load(Simd::([0., 1., 2.])), load(Simd::([2., 2., 2.]))); + assert_eq!(x.0, [2., 3., 4.]); } }