//@ run-pass #![feature(repr_simd, intrinsics)] #![allow(non_camel_case_types)] #[repr(simd, packed)] struct Simd([T; N]); fn check_size_align() { use std::mem; assert_eq!(mem::size_of::>(), mem::size_of::<[T; N]>()); assert_eq!(mem::size_of::>() % mem::align_of::>(), 0); } fn check_ty() { check_size_align::(); check_size_align::(); check_size_align::(); check_size_align::(); check_size_align::(); check_size_align::(); check_size_align::(); } extern "rust-intrinsic" { fn simd_add(a: T, b: T) -> T; } fn main() { check_ty::(); check_ty::(); check_ty::(); check_ty::(); check_ty::(); check_ty::(); check_ty::(); unsafe { // powers-of-two have no padding and have the same layout as #[repr(simd)] 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 should have padding (which is removed by #[repr(packed)]), // but the intrinsic handles it let x: Simd = simd_add(Simd::([0., 1., 2.]), Simd::([2., 2., 2.])); let arr: [f64; 3] = x.0; assert_eq!(arr, [2., 3., 4.]); } }