Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions fearless_simd/src/generated/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ impl Simd for WasmSimd128 {
}
#[inline(always)]
fn mul_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
todo!()
let low = i16x8_extmul_low_i8x16(a.into(), b.into());
let high = i16x8_extmul_high_i8x16(a.into(), b.into());
u8x16_shuffle::<0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30>(low, high)
.simd_into(self)
}
#[inline(always)]
fn and_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
Expand Down Expand Up @@ -265,7 +268,10 @@ impl Simd for WasmSimd128 {
}
#[inline(always)]
fn mul_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
todo!()
let low = u16x8_extmul_low_u8x16(a.into(), b.into());
let high = u16x8_extmul_high_u8x16(a.into(), b.into());
u8x16_shuffle::<0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30>(low, high)
.simd_into(self)
}
#[inline(always)]
fn and_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
Expand Down
53 changes: 28 additions & 25 deletions fearless_simd_gen/src/mk_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,36 @@ fn mk_simd_impl(level: Level) -> TokenStream {
}
OpSig::Binary => {
let args = [quote! { a.into() }, quote! { b.into() }];
if method == "mul"
&& (vec_ty
== (&VecType {
scalar: ScalarType::Unsigned,
scalar_bits: 8,
len: 16,
})
|| vec_ty
== (&VecType {
scalar: ScalarType::Int,
scalar_bits: 8,
len: 16,
}))
{
quote! {
#[inline(always)]
fn #method_ident(self, a: #ty<Self>, b: #ty<Self>) -> #ret_ty {
// TODO: WASM doesn't have `i8x16_mul` or `u8x16_mul`.
todo!()
match method {
"mul" if vec_ty.scalar_bits == 8 && vec_ty.len == 16 => {
let (extmul_low, extmul_high) = match vec_ty.scalar {
ScalarType::Unsigned => (
quote! { u16x8_extmul_low_u8x16 },
quote! { u16x8_extmul_high_u8x16 },
),
ScalarType::Int => (
quote! { i16x8_extmul_low_i8x16 },
quote! { i16x8_extmul_high_i8x16 },
),
_ => unreachable!(),
};

quote! {
#[inline(always)]
fn #method_ident(self, a: #ty<Self>, b: #ty<Self>) -> #ret_ty {
let low = #extmul_low(a.into(), b.into());
let high = #extmul_high(a.into(), b.into());
u8x16_shuffle::<0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30>(low, high).simd_into(self)
}
}
}
} else {
let expr = Wasm.expr(method, vec_ty, &args);
quote! {
#[inline(always)]
fn #method_ident(self, a: #ty<Self>, b: #ty<Self>) -> #ret_ty {
#expr.simd_into(self)
_ => {
let expr = Wasm.expr(method, vec_ty, &args);
quote! {
#[inline(always)]
fn #method_ident(self, a: #ty<Self>, b: #ty<Self>) -> #ret_ty {
#expr.simd_into(self)
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions fearless_simd_tests/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ test_wasm_simd_parity! {
}
}

test_wasm_simd_parity! {
fn mul_u8x16() {
|s| -> [u8; 16] {
let a = u8x16::from_slice(s, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
let b = u8x16::from_slice(s, &[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]);
(a * b).into()
}
}
}

test_wasm_simd_parity! {
fn mul_i8x16() {
|s| -> [i8; 16] {
let a = i8x16::from_slice(s, &[0, -0, 3, -3, 0, -0, 3, -3, 0, -0, 3, -3, 0, -0, 3, -3]);
let b = i8x16::from_slice(s, &[0, 0, 0, 0, -0, -0, -0, -0, 3, 3, 3, 3, -3, -3, -3, -3]);
(a * b).into()
}
}
}

test_wasm_simd_parity! {
fn splat_f32x4() {
|s| -> [f32; 4] {
Expand Down