1 use core::simd::{num::SimdFloat, *};
2
3 /// Calculates the vector 3 dot product and returns answer in x lane of f32x4.
4 #[inline(always)]
dot3_in_x(lhs: f32x4, rhs: f32x4) -> f32x45 pub(crate) fn dot3_in_x(lhs: f32x4, rhs: f32x4) -> f32x4 {
6 let x2_y2_z2_w2 = lhs * rhs;
7 let y2_0_0_0 = simd_swizzle!(x2_y2_z2_w2, [1, 0, 0, 0]);
8 let z2_0_0_0 = simd_swizzle!(x2_y2_z2_w2, [2, 0, 0, 0]);
9 let x2y2_0_0_0 = x2_y2_z2_w2 + y2_0_0_0;
10 x2y2_0_0_0 + z2_0_0_0
11 }
12
13 /// Calculates the vector 4 dot product and returns answer in x lane of f32x4.
14 #[inline(always)]
dot4_in_x(lhs: f32x4, rhs: f32x4) -> f32x415 pub(crate) fn dot4_in_x(lhs: f32x4, rhs: f32x4) -> f32x4 {
16 let x2_y2_z2_w2 = lhs * rhs;
17 let z2_w2_0_0 = simd_swizzle!(x2_y2_z2_w2, [2, 3, 0, 0]);
18 let x2z2_y2w2_0_0 = x2_y2_z2_w2 + z2_w2_0_0;
19 let y2w2_0_0_0 = simd_swizzle!(x2z2_y2w2_0_0, [1, 0, 0, 0]);
20 x2z2_y2w2_0_0 + y2w2_0_0_0
21 }
22
23 #[inline]
dot3(lhs: f32x4, rhs: f32x4) -> f3224 pub(crate) fn dot3(lhs: f32x4, rhs: f32x4) -> f32 {
25 dot3_in_x(lhs, rhs)[0]
26 }
27
28 #[inline]
dot3_into_f32x4(lhs: f32x4, rhs: f32x4) -> f32x429 pub(crate) fn dot3_into_f32x4(lhs: f32x4, rhs: f32x4) -> f32x4 {
30 let dot_in_x = dot3_in_x(lhs, rhs);
31 simd_swizzle!(dot_in_x, [0, 0, 0, 0])
32 }
33
34 #[inline]
dot4(lhs: f32x4, rhs: f32x4) -> f3235 pub(crate) fn dot4(lhs: f32x4, rhs: f32x4) -> f32 {
36 dot4_in_x(lhs, rhs)[0]
37 }
38
39 #[inline]
dot4_into_f32x4(lhs: f32x4, rhs: f32x4) -> f32x440 pub(crate) fn dot4_into_f32x4(lhs: f32x4, rhs: f32x4) -> f32x4 {
41 let dot_in_x = dot4_in_x(lhs, rhs);
42 simd_swizzle!(dot_in_x, [0, 0, 0, 0])
43 }
44
45 #[inline(always)]
f32x4_bitand(a: f32x4, b: f32x4) -> f32x446 pub(crate) fn f32x4_bitand(a: f32x4, b: f32x4) -> f32x4 {
47 let a = a.to_bits();
48 let b = b.to_bits();
49 f32x4::from_bits(a & b)
50 }
51
52 #[inline(always)]
f32x4_bitxor(a: f32x4, b: f32x4) -> f32x453 pub(crate) fn f32x4_bitxor(a: f32x4, b: f32x4) -> f32x4 {
54 let a = a.to_bits();
55 let b = b.to_bits();
56 f32x4::from_bits(a ^ b)
57 }
58