| 1 |
use core::arch::wasm32::*; |
| 2 |
|
| 3 |
pub const fn v128_from_f32x4(a: [f32; 4]) -> v128 { |
| 4 |
f32x4(a[0], a[1], a[2], a[3]) |
| 5 |
} |
| 6 |
|
| 7 |
/// Calculates the vector 3 dot product and returns answer in x lane of v128. |
| 8 |
#[inline(always)] |
| 9 |
pub(crate) fn dot3_in_x(lhs: v128, rhs: v128) -> v128 { |
| 10 |
let x2_y2_z2_w2 = f32x4_mul(lhs, rhs); |
| 11 |
let y2_0_0_0 = i32x4_shuffle::<1, 0, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2); |
| 12 |
let z2_0_0_0 = i32x4_shuffle::<2, 0, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2); |
| 13 |
let x2y2_0_0_0 = f32x4_add(x2_y2_z2_w2, y2_0_0_0); |
| 14 |
f32x4_add(x2y2_0_0_0, z2_0_0_0) |
| 15 |
} |
| 16 |
|
| 17 |
/// Calculates the vector 4 dot product and returns answer in x lane of v128. |
| 18 |
#[inline(always)] |
| 19 |
pub(crate) fn dot4_in_x(lhs: v128, rhs: v128) -> v128 { |
| 20 |
let x2_y2_z2_w2 = f32x4_mul(lhs, rhs); |
| 21 |
let z2_w2_0_0 = i32x4_shuffle::<2, 3, 0, 0>(x2_y2_z2_w2, x2_y2_z2_w2); |
| 22 |
let x2z2_y2w2_0_0 = f32x4_add(x2_y2_z2_w2, z2_w2_0_0); |
| 23 |
let y2w2_0_0_0 = i32x4_shuffle::<1, 0, 0, 0>(x2z2_y2w2_0_0, x2z2_y2w2_0_0); |
| 24 |
f32x4_add(x2z2_y2w2_0_0, y2w2_0_0_0) |
| 25 |
} |
| 26 |
|
| 27 |
#[inline] |
| 28 |
pub(crate) fn dot3(lhs: v128, rhs: v128) -> f32 { |
| 29 |
f32x4_extract_lane::<0>(dot3_in_x(lhs, rhs)) |
| 30 |
} |
| 31 |
|
| 32 |
#[inline] |
| 33 |
pub(crate) fn dot3_into_v128(lhs: v128, rhs: v128) -> v128 { |
| 34 |
let dot_in_x = dot3_in_x(lhs, rhs); |
| 35 |
i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x) |
| 36 |
} |
| 37 |
|
| 38 |
#[inline] |
| 39 |
pub(crate) fn dot4(lhs: v128, rhs: v128) -> f32 { |
| 40 |
f32x4_extract_lane::<0>(dot4_in_x(lhs, rhs)) |
| 41 |
} |
| 42 |
|
| 43 |
#[inline] |
| 44 |
pub(crate) fn dot4_into_v128(lhs: v128, rhs: v128) -> v128 { |
| 45 |
let dot_in_x = dot4_in_x(lhs, rhs); |
| 46 |
i32x4_shuffle::<0, 0, 0, 0>(dot_in_x, dot_in_x) |
| 47 |
} |