Closed
Description
The existing code copies/converts one bool at a time, unvectorized by llvm.
https://rust.godbolt.org/z/GdTx63axx
#![feature(repr_simd)]
#![feature(platform_intrinsics)]
extern "platform-intrinsic" {
fn simd_ne<T, U>(a: T, b: T) -> U;
fn simd_cast<T, U>(v: T) -> U;
}
#[repr(simd)]
pub struct Simd<T, const N: usize>(pub [T; N]);
pub fn from_array_new(v: [bool; 16]) -> Simd<i32, 16> {
unsafe {
let v: [u8; 16] = std::mem::transmute(v);
let bools: Simd<i8, 16> = simd_ne(Simd(v), Simd([0u8; 16]));
simd_cast(bools)
}
}
pub fn from_array_current(v: [bool; 16]) -> Simd<i32, 16> {
let mut retval = Simd([0; 16]);
for i in 0..16 {
retval.0[i] = if v[i] { -1 } else { 0 };
}
retval
}