1
+ use crate :: { LaneCount , Mask , MaskElement , Simd , SimdElement , SupportedLaneCount } ;
2
+
1
3
mod sealed {
2
4
pub trait Sealed { }
3
5
}
@@ -9,79 +11,75 @@ pub trait Select<Mask>: Sealed {
9
11
fn select ( mask : Mask , true_values : Self , false_values : Self ) -> Self ;
10
12
}
11
13
12
- macro_rules! impl_select {
13
- {
14
- $mask: ident ( $bits_ty: ident) : $( $type: ident) ,*
15
- } => {
16
- $(
17
- impl <const LANES : usize > Sealed for crate :: $type<LANES > where crate :: LaneCount <LANES >: crate :: SupportedLaneCount { }
18
- impl <const LANES : usize > Select <crate :: $mask<LANES >> for crate :: $type<LANES >
19
- where
20
- crate :: LaneCount <LANES >: crate :: SupportedLaneCount ,
21
- {
22
- #[ doc( hidden) ]
23
- #[ inline]
24
- fn select( mask: crate :: $mask<LANES >, true_values: Self , false_values: Self ) -> Self {
25
- unsafe { crate :: intrinsics:: simd_select( mask. to_int( ) , true_values, false_values) }
26
- }
27
- }
28
- ) *
14
+ impl < Element , const LANES : usize > Sealed for Simd < Element , LANES >
15
+ where
16
+ Element : SimdElement ,
17
+ LaneCount < LANES > : SupportedLaneCount ,
18
+ {
19
+ }
29
20
30
- impl <const LANES : usize > Sealed for crate :: $mask<LANES >
31
- where
32
- crate :: LaneCount <LANES >: crate :: SupportedLaneCount ,
33
- { }
21
+ impl < Element , const LANES : usize > Select < Mask < Element :: Mask , LANES > > for Simd < Element , LANES >
22
+ where
23
+ Element : SimdElement ,
24
+ LaneCount < LANES > : SupportedLaneCount ,
25
+ {
26
+ #[ inline]
27
+ fn select ( mask : Mask < Element :: Mask , LANES > , true_values : Self , false_values : Self ) -> Self {
28
+ unsafe { crate :: intrinsics:: simd_select ( mask. to_int ( ) , true_values, false_values) }
29
+ }
30
+ }
34
31
35
- impl <const LANES : usize > Select <Self > for crate :: $mask<LANES >
36
- where
37
- crate :: LaneCount <LANES >: crate :: SupportedLaneCount ,
38
- {
39
- #[ doc( hidden) ]
40
- #[ inline]
41
- fn select( mask: Self , true_values: Self , false_values: Self ) -> Self {
42
- mask & true_values | !mask & false_values
43
- }
44
- }
32
+ impl < Element , const LANES : usize > Sealed for Mask < Element , LANES >
33
+ where
34
+ Element : MaskElement ,
35
+ LaneCount < LANES > : SupportedLaneCount ,
36
+ {
37
+ }
45
38
46
- impl <const LANES : usize > crate :: $mask<LANES >
47
- where
48
- crate :: LaneCount <LANES >: crate :: SupportedLaneCount ,
49
- {
50
- /// Choose lanes from two vectors.
51
- ///
52
- /// For each lane in the mask, choose the corresponding lane from `true_values` if
53
- /// that lane mask is true, and `false_values` if that lane mask is false.
54
- ///
55
- /// ```
56
- /// # #![feature(portable_simd)]
57
- /// # use core_simd::{Mask32, SimdI32};
58
- /// let a = SimdI32::from_array([0, 1, 2, 3]);
59
- /// let b = SimdI32::from_array([4, 5, 6, 7]);
60
- /// let mask = Mask32::from_array([true, false, false, true]);
61
- /// let c = mask.select(a, b);
62
- /// assert_eq!(c.to_array(), [0, 5, 6, 3]);
63
- /// ```
64
- ///
65
- /// `select` can also be used on masks:
66
- /// ```
67
- /// # #![feature(portable_simd)]
68
- /// # use core_simd::Mask32;
69
- /// let a = Mask32::from_array([true, true, false, false]);
70
- /// let b = Mask32::from_array([false, false, true, true]);
71
- /// let mask = Mask32::from_array([true, false, false, true]);
72
- /// let c = mask.select(a, b);
73
- /// assert_eq!(c.to_array(), [true, false, true, false]);
74
- /// ```
75
- #[ inline]
76
- pub fn select<S : Select <Self >>( self , true_values: S , false_values: S ) -> S {
77
- S :: select( self , true_values, false_values)
78
- }
79
- }
39
+ impl < Element , const LANES : usize > Select < Self > for Mask < Element , LANES >
40
+ where
41
+ Element : MaskElement ,
42
+ LaneCount < LANES > : SupportedLaneCount ,
43
+ {
44
+ #[ doc( hidden) ]
45
+ #[ inline]
46
+ fn select ( mask : Self , true_values : Self , false_values : Self ) -> Self {
47
+ mask & true_values | !mask & false_values
80
48
}
81
49
}
82
50
83
- impl_select ! { Mask8 ( SimdI8 ) : SimdU8 , SimdI8 }
84
- impl_select ! { Mask16 ( SimdI16 ) : SimdU16 , SimdI16 }
85
- impl_select ! { Mask32 ( SimdI32 ) : SimdU32 , SimdI32 , SimdF32 }
86
- impl_select ! { Mask64 ( SimdI64 ) : SimdU64 , SimdI64 , SimdF64 }
87
- impl_select ! { MaskSize ( SimdIsize ) : SimdUsize , SimdIsize }
51
+ impl < Element , const LANES : usize > Mask < Element , LANES >
52
+ where
53
+ Element : MaskElement ,
54
+ LaneCount < LANES > : SupportedLaneCount ,
55
+ {
56
+ /// Choose lanes from two vectors.
57
+ ///
58
+ /// For each lane in the mask, choose the corresponding lane from `true_values` if
59
+ /// that lane mask is true, and `false_values` if that lane mask is false.
60
+ ///
61
+ /// ```
62
+ /// # #![feature(portable_simd)]
63
+ /// # use core_simd::{Mask32, SimdI32};
64
+ /// let a = SimdI32::from_array([0, 1, 2, 3]);
65
+ /// let b = SimdI32::from_array([4, 5, 6, 7]);
66
+ /// let mask = Mask32::from_array([true, false, false, true]);
67
+ /// let c = mask.select(a, b);
68
+ /// assert_eq!(c.to_array(), [0, 5, 6, 3]);
69
+ /// ```
70
+ ///
71
+ /// `select` can also be used on masks:
72
+ /// ```
73
+ /// # #![feature(portable_simd)]
74
+ /// # use core_simd::Mask32;
75
+ /// let a = Mask32::from_array([true, true, false, false]);
76
+ /// let b = Mask32::from_array([false, false, true, true]);
77
+ /// let mask = Mask32::from_array([true, false, false, true]);
78
+ /// let c = mask.select(a, b);
79
+ /// assert_eq!(c.to_array(), [true, false, true, false]);
80
+ /// ```
81
+ #[ inline]
82
+ pub fn select < S : Select < Self > > ( self , true_values : S , false_values : S ) -> S {
83
+ S :: select ( self , true_values, false_values)
84
+ }
85
+ }
0 commit comments