1 use crate::simd::intrinsics;
2 use crate::simd::{LaneCount, Mask, MaskElement, Simd, SimdElement, SupportedLaneCount};
4 impl<T, const LANES: usize> Mask<T, LANES>
7 LaneCount<LANES>: SupportedLaneCount,
9 /// Choose lanes from two vectors.
11 /// For each lane in the mask, choose the corresponding lane from `true_values` if
12 /// that lane mask is true, and `false_values` if that lane mask is false.
15 /// # #![feature(portable_simd)]
16 /// # #[cfg(feature = "std")] use core_simd::{Simd, Mask};
17 /// # #[cfg(not(feature = "std"))] use core::simd::{Simd, Mask};
18 /// let a = Simd::from_array([0, 1, 2, 3]);
19 /// let b = Simd::from_array([4, 5, 6, 7]);
20 /// let mask = Mask::from_array([true, false, false, true]);
21 /// let c = mask.select(a, b);
22 /// assert_eq!(c.to_array(), [0, 5, 6, 3]);
25 #[must_use = "method returns a new vector and does not mutate the original inputs"]
28 true_values: Simd<U, LANES>,
29 false_values: Simd<U, LANES>,
32 U: SimdElement<Mask = T>,
34 unsafe { intrinsics::simd_select(self.to_int(), true_values, false_values) }
37 /// Choose lanes from two masks.
39 /// For each lane in the mask, choose the corresponding lane from `true_values` if
40 /// that lane mask is true, and `false_values` if that lane mask is false.
43 /// # #![feature(portable_simd)]
44 /// # #[cfg(feature = "std")] use core_simd::Mask;
45 /// # #[cfg(not(feature = "std"))] use core::simd::Mask;
46 /// let a = Mask::<i32, 4>::from_array([true, true, false, false]);
47 /// let b = Mask::<i32, 4>::from_array([false, false, true, true]);
48 /// let mask = Mask::<i32, 4>::from_array([true, false, false, true]);
49 /// let c = mask.select_mask(a, b);
50 /// assert_eq!(c.to_array(), [true, false, true, false]);
53 #[must_use = "method returns a new mask and does not mutate the original inputs"]
54 pub fn select_mask(self, true_values: Self, false_values: Self) -> Self {
55 self & true_values | !self & false_values