@@ -144,14 +144,31 @@ where
144
144
/// assert_eq!(v.as_array(), &[8, 8, 8, 8]);
145
145
/// ```
146
146
#[ inline]
147
- pub fn splat ( value : T ) -> Self {
148
- // This is preferred over `[value; N]`, since it's explicitly a splat:
149
- // https://github.com/rust-lang/rust/issues/97804
150
- struct Splat ;
151
- impl < const N : usize > Swizzle < N > for Splat {
152
- const INDEX : [ usize ; N ] = [ 0 ; N ] ;
147
+ pub const fn splat ( value : T ) -> Self {
148
+ const fn splat_const < T , const N : usize > ( value : T ) -> Simd < T , N >
149
+ where
150
+ T : SimdElement ,
151
+ LaneCount < N > : SupportedLaneCount ,
152
+ {
153
+ Simd :: from_array ( [ value; N ] )
153
154
}
154
- Splat :: swizzle :: < T , 1 > ( Simd :: < T , 1 > :: from ( [ value] ) )
155
+
156
+ fn splat_rt < T , const N : usize > ( value : T ) -> Simd < T , N >
157
+ where
158
+ T : SimdElement ,
159
+ LaneCount < N > : SupportedLaneCount ,
160
+ {
161
+ // This is preferred over `[value; N]`, since it's explicitly a splat:
162
+ // https://github.com/rust-lang/rust/issues/97804
163
+ struct Splat ;
164
+ impl < const N : usize > Swizzle < N > for Splat {
165
+ const INDEX : [ usize ; N ] = [ 0 ; N ] ;
166
+ }
167
+
168
+ Splat :: swizzle :: < T , 1 > ( Simd :: < T , 1 > :: from ( [ value] ) )
169
+ }
170
+
171
+ core:: intrinsics:: const_eval_select ( ( value, ) , splat_const, splat_rt)
155
172
}
156
173
157
174
/// Returns an array reference containing the entire SIMD vector.
0 commit comments