]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | //! Vertical (lane-wise) vector `min` and `max` for integer vectors. |
2 | ||
3 | macro_rules! impl_ops_vector_int_min_max { | |
4 | ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { | |
5 | impl $id { | |
6 | /// Minimum of two vectors. | |
7 | /// | |
8 | /// Returns a new vector containing the minimum value of each of | |
9 | /// the input vector lanes. | |
10 | #[inline] | |
11 | pub fn min(self, x: Self) -> Self { | |
12 | self.lt(x).select(self, x) | |
13 | } | |
14 | ||
15 | /// Maximum of two vectors. | |
16 | /// | |
17 | /// Returns a new vector containing the maximum value of each of | |
18 | /// the input vector lanes. | |
19 | #[inline] | |
20 | pub fn max(self, x: Self) -> Self { | |
21 | self.gt(x).select(self, x) | |
22 | } | |
23 | } | |
24 | test_if!{$test_tt: | |
25 | paste::item! { | |
26 | pub mod [<$id _ops_vector_min_max>] { | |
27 | use super::*; | |
28 | #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] | |
29 | fn min_max() { | |
30 | let o = $id::splat(1 as $elem_ty); | |
31 | let t = $id::splat(2 as $elem_ty); | |
32 | ||
33 | let mut m = o; | |
34 | for i in 0..$id::lanes() { | |
35 | if i % 2 == 0 { | |
36 | m = m.replace(i, 2 as $elem_ty); | |
37 | } | |
38 | } | |
39 | assert_eq!(o.min(t), o); | |
40 | assert_eq!(t.min(o), o); | |
41 | assert_eq!(m.min(o), o); | |
42 | assert_eq!(o.min(m), o); | |
43 | assert_eq!(m.min(t), m); | |
44 | assert_eq!(t.min(m), m); | |
45 | ||
46 | assert_eq!(o.max(t), t); | |
47 | assert_eq!(t.max(o), t); | |
48 | assert_eq!(m.max(o), m); | |
49 | assert_eq!(o.max(m), m); | |
50 | assert_eq!(m.max(t), t); | |
51 | assert_eq!(t.max(m), t); | |
52 | } | |
53 | } | |
54 | } | |
55 | } | |
56 | }; | |
57 | } |