Skip to content

Commit 20413b1

Browse files
committed
Add test using non-power-of-two vector
1 parent 329412d commit 20413b1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/ui/simd/repr_packed.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#[repr(simd, packed)]
77
struct Simd<T, const N: usize>([T; N]);
88

9+
#[repr(simd)]
10+
struct FullSimd<T, const N: usize>([T; N]);
11+
912
fn check_size_align<T, const N: usize>() {
1013
use std::mem;
1114
assert_eq!(mem::size_of::<Simd<T, N>>(), mem::size_of::<[T; N]>());
@@ -37,9 +40,20 @@ fn main() {
3740

3841
unsafe {
3942
// powers-of-two have no padding and work as usual
40-
// non-powers-of-two have padding and need to be expanded to full vectors
4143
let x: Simd<f64, 4> =
4244
simd_add(Simd::<f64, 4>([0., 1., 2., 3.]), Simd::<f64, 4>([2., 2., 2., 2.]));
4345
assert_eq!(std::mem::transmute::<_, [f64; 4]>(x), [2., 3., 4., 5.]);
46+
47+
// non-powers-of-two have padding and need to be expanded to full vectors
48+
fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
49+
unsafe {
50+
let mut tmp = core::mem::MaybeUninit::<FullSimd<T, N>>::uninit();
51+
std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1);
52+
tmp.assume_init()
53+
}
54+
}
55+
let x: FullSimd<f64, 3> =
56+
simd_add(load(Simd::<f64, 3>([0., 1., 2.])), load(Simd::<f64, 3>([2., 2., 2.])));
57+
assert_eq!(x.0, [2., 3., 4.]);
4458
}
4559
}

0 commit comments

Comments
 (0)