Skip to main content

tract_linalg/generic/
unicast.rs

1pub use tract_data::internal::f16;
2routine_unicast_rust!(generic;
3    f32,
4    SUnicastMul4,
5    4,
6    4,
7    fn run(a: &mut [f32], b: &[f32]) {
8        debug_assert!(a.len() == b.len());
9        debug_assert!(a.len() % Self::nr() == 0);
10        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
11        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
12        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a *= b)
13    },
14    op(Mul)
15);
16
17routine_unicast_rust!(generic;
18    f32,
19    SUnicastAdd4,
20    4,
21    4,
22    fn run(a: &mut [f32], b: &[f32]) {
23        debug_assert!(a.len() == b.len());
24        debug_assert!(a.len() % Self::nr() == 0);
25        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
26        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
27        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a += b)
28    },
29    op(Add)
30);
31
32routine_unicast_rust!(generic;
33    f32,
34    SUnicastSub4,
35    4,
36    4,
37    fn run(a: &mut [f32], b: &[f32]) {
38        debug_assert!(a.len() == b.len());
39        debug_assert!(a.len() % Self::nr() == 0);
40        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
41        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
42        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a -= b)
43    },
44    op(Sub)
45);
46
47routine_unicast_rust!(generic;
48    f32,
49    SUnicastSubF4,
50    4,
51    4,
52    fn run(a: &mut [f32], b: &[f32]) {
53        debug_assert!(a.len() == b.len());
54        debug_assert!(a.len() % Self::nr() == 0);
55        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
56        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
57        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a = *b - *a)
58    },
59    op(SubF)
60);
61
62routine_unicast_rust!(generic;
63    f32,
64    SUnicastMin4,
65    4,
66    4,
67    fn run(a: &mut [f32], b: &[f32]) {
68        debug_assert!(a.len() == b.len());
69        debug_assert!(a.len() % Self::nr() == 0);
70        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
71        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
72        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a = a.min(*b))
73    },
74    op(Min)
75);
76
77routine_unicast_rust!(generic;
78    f32,
79    SUnicastMax4,
80    4,
81    4,
82    fn run(a: &mut [f32], b: &[f32]) {
83        debug_assert!(a.len() == b.len());
84        debug_assert!(a.len() % Self::nr() == 0);
85        debug_assert!(a.as_ptr() as usize % Self::alignment_bytes() == 0);
86        debug_assert!(b.as_ptr() as usize % Self::alignment_bytes() == 0);
87        a.iter_mut().zip(b.iter()).for_each(|(a, b)| *a = a.max(*b))
88    },
89    op(Max)
90);