Skip to content

Commit c623489

Browse files
committed
Add codegen test
1 parent 20413b1 commit c623489

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/codegen/simd/repr-packed.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(repr_simd, platform_intrinsics)]
5+
6+
#[repr(simd, packed)]
7+
pub struct Simd<T, const N: usize>([T; N]);
8+
9+
#[repr(simd)]
10+
#[derive(Copy, Clone)]
11+
pub struct FullSimd<T, const N: usize>([T; N]);
12+
13+
extern "platform-intrinsic" {
14+
fn simd_mul<T>(a: T, b: T) -> T;
15+
}
16+
17+
// non-powers-of-two have padding and need to be expanded to full vectors
18+
fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
19+
unsafe {
20+
let mut tmp = core::mem::MaybeUninit::<FullSimd<T, N>>::uninit();
21+
std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1);
22+
tmp.assume_init()
23+
}
24+
}
25+
26+
// CHECK-LABEL: @square_packed
27+
#[no_mangle]
28+
pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
29+
// CHECK: align 4 dereferenceable(12) %x
30+
let x = load(x);
31+
unsafe { simd_mul(x, x) }
32+
}

0 commit comments

Comments
 (0)