Skip to content

Commit ea4c3cb

Browse files
committed
Add codegen test
1 parent fe95e63 commit ea4c3cb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/codegen/simd/repr-packed.rs

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

0 commit comments

Comments
 (0)