File tree Expand file tree Collapse file tree 4 files changed +29
-15
lines changed Expand file tree Collapse file tree 4 files changed +29
-15
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ impl<const N: usize> LaneCount<N> {
18
18
/// Only SIMD vectors with supported lane counts are constructable.
19
19
pub trait SupportedLaneCount : Sealed {
20
20
#[ doc( hidden) ]
21
- type BitMask : Copy + Default + AsRef < [ u8 ] > + AsMut < [ u8 ] > ;
21
+ type BitMask : Copy + AsRef < [ u8 ] > + AsMut < [ u8 ] > ;
22
+ #[ doc( hidden) ]
23
+ const EMPTY_BIT_MASK : Self :: BitMask ;
24
+ #[ doc( hidden) ]
25
+ const FULL_BIT_MASK : Self :: BitMask ;
22
26
}
23
27
24
28
impl < const N : usize > Sealed for LaneCount < N > { }
@@ -28,6 +32,15 @@ macro_rules! supported_lane_count {
28
32
$(
29
33
impl SupportedLaneCount for LaneCount <$lanes> {
30
34
type BitMask = [ u8 ; ( $lanes + 7 ) / 8 ] ;
35
+ const EMPTY_BIT_MASK : Self :: BitMask = [ 0 ; ( $lanes + 7 ) / 8 ] ;
36
+ const FULL_BIT_MASK : Self :: BitMask = {
37
+ const LEN : usize = ( $lanes + 7 ) / 8 ;
38
+ let mut array = [ !0u8 ; LEN ] ;
39
+ if $lanes % 8 > 0 {
40
+ array[ LEN - 1 ] = ( !0 ) >> ( 8 - $lanes % 8 ) ;
41
+ }
42
+ array
43
+ } ;
31
44
}
32
45
) +
33
46
} ;
Original file line number Diff line number Diff line change @@ -139,7 +139,8 @@ where
139
139
{
140
140
/// Constructs a mask by setting all elements to the given value.
141
141
#[ inline]
142
- pub fn splat ( value : bool ) -> Self {
142
+ #[ rustc_const_unstable( feature = "portable_simd" , issue = "86656" ) ]
143
+ pub const fn splat ( value : bool ) -> Self {
143
144
Self ( mask_impl:: Mask :: splat ( value) )
144
145
}
145
146
Original file line number Diff line number Diff line change @@ -78,17 +78,16 @@ where
78
78
{
79
79
#[ inline]
80
80
#[ must_use = "method returns a new mask and does not mutate the original value" ]
81
- pub ( crate ) fn splat ( value : bool ) -> Self {
82
- let mut mask = <LaneCount < N > as SupportedLaneCount >:: BitMask :: default ( ) ;
83
- if value {
84
- mask. as_mut ( ) . fill ( u8:: MAX )
85
- } else {
86
- mask. as_mut ( ) . fill ( u8:: MIN )
87
- }
88
- if N % 8 > 0 {
89
- * mask. as_mut ( ) . last_mut ( ) . unwrap ( ) &= u8:: MAX >> ( 8 - N % 8 ) ;
90
- }
91
- Self ( mask, PhantomData )
81
+ #[ rustc_const_unstable( feature = "portable_simd" , issue = "86656" ) ]
82
+ pub ( crate ) const fn splat ( value : bool ) -> Self {
83
+ Self (
84
+ if value {
85
+ <LaneCount < N > as SupportedLaneCount >:: FULL_BIT_MASK
86
+ } else {
87
+ <LaneCount < N > as SupportedLaneCount >:: EMPTY_BIT_MASK
88
+ } ,
89
+ PhantomData ,
90
+ )
92
91
}
93
92
94
93
#[ inline]
@@ -131,7 +130,7 @@ where
131
130
132
131
#[ inline]
133
132
pub ( crate ) fn from_bitmask_integer ( bitmask : u64 ) -> Self {
134
- let mut bytes = <LaneCount < N > as SupportedLaneCount >:: BitMask :: default ( ) ;
133
+ let mut bytes = <LaneCount < N > as SupportedLaneCount >:: BitMask :: EMPTY_BIT_MASK ;
135
134
let len = bytes. as_mut ( ) . len ( ) ;
136
135
bytes
137
136
. as_mut ( )
Original file line number Diff line number Diff line change @@ -102,7 +102,8 @@ where
102
102
{
103
103
#[ inline]
104
104
#[ must_use = "method returns a new mask and does not mutate the original value" ]
105
- pub ( crate ) fn splat ( value : bool ) -> Self {
105
+ #[ rustc_const_unstable( feature = "portable_simd" , issue = "86656" ) ]
106
+ pub ( crate ) const fn splat ( value : bool ) -> Self {
106
107
Self ( Simd :: splat ( if value { T :: TRUE } else { T :: FALSE } ) )
107
108
}
108
109
You can’t perform that action at this time.
0 commit comments