Skip to content

Commit

Permalink
Add codegen test
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Nov 18, 2023
1 parent fe95e63 commit ea4c3cb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/codegen/simd/repr-packed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![crate_type = "lib"]
#![feature(repr_simd, platform_intrinsics)]

#[repr(simd, packed)]
pub struct Simd<T, const N: usize>([T; N]);

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct FullSimd<T, const N: usize>([T; N]);

extern "platform-intrinsic" {
fn simd_mul<T>(a: T, b: T) -> T;
}

// non-powers-of-two have padding and need to be expanded to full vectors
fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> {
unsafe {
let mut tmp = core::mem::MaybeUninit::<FullSimd<T, N>>::uninit();
std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1);
tmp.assume_init()
}
}

// CHECK-LABEL: @square_packed
#[no_mangle]
pub fn square_packed(x: Simd<f32, 3>) -> FullSimd<f32, 3> {
// CHECK: load <3 x float>, ptr %x, align 4
let x = load(x);
unsafe { simd_mul(x, x) }
}

0 comments on commit ea4c3cb

Please sign in to comment.