Files
rust/tests/ui/simd/repr_packed.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
Rust
Raw Normal View History

//@ ignore-backends: gcc
2023-10-24 02:01:47 -04:00
//@ run-pass
#![feature(repr_simd, core_intrinsics)]
2023-10-24 02:01:47 -04:00
#![allow(non_camel_case_types)]
2025-07-12 02:33:42 -07:00
#[path = "../../auxiliary/minisimd.rs"]
mod minisimd;
use minisimd::*;
2025-07-12 02:33:42 -07:00
use std::intrinsics::simd::simd_add;
2023-10-24 02:01:47 -04:00
fn check_size_align<T, const N: usize>() {
use std::mem;
2025-07-12 02:33:42 -07:00
assert_eq!(mem::size_of::<PackedSimd<T, N>>(), mem::size_of::<[T; N]>());
assert_eq!(mem::size_of::<PackedSimd<T, N>>() % mem::align_of::<PackedSimd<T, N>>(), 0);
2023-10-24 02:01:47 -04:00
}
fn check_ty<T>() {
check_size_align::<T, 1>();
check_size_align::<T, 2>();
check_size_align::<T, 3>();
check_size_align::<T, 4>();
check_size_align::<T, 8>();
check_size_align::<T, 9>();
check_size_align::<T, 15>();
}
fn main() {
check_ty::<u8>();
check_ty::<i16>();
check_ty::<u32>();
check_ty::<i64>();
check_ty::<usize>();
check_ty::<f32>();
check_ty::<f64>();
unsafe {
2024-06-01 14:17:16 -04:00
// powers-of-two have no padding and have the same layout as #[repr(simd)]
2025-07-12 02:33:42 -07:00
let x: PackedSimd<f64, 4> =
simd_add(
PackedSimd::<f64, 4>([0., 1., 2., 3.]),
PackedSimd::<f64, 4>([2., 2., 2., 2.]),
);
assert_eq!(x.into_array(), [2., 3., 4., 5.]);
2023-10-24 22:21:42 -04:00
2024-06-01 14:17:16 -04:00
// non-powers-of-two should have padding (which is removed by #[repr(packed)]),
// but the intrinsic handles it
2025-07-12 02:33:42 -07:00
let x: PackedSimd<f64, 3> =
simd_add(
PackedSimd::<f64, 3>([0., 1., 2.]),
PackedSimd::<f64, 3>([2., 2., 2.]),
);
let arr: [f64; 3] = x.into_array();
assert_eq!(arr, [2., 3., 4.]);
2023-10-24 02:01:47 -04:00
}
}