@@ -251,6 +251,50 @@ where
251251 Rotate :: < OFFSET > :: swizzle ( self )
252252 }
253253
254+ /// Shifts the vector elements to the left by `OFFSET`, filling in with
255+ /// `padding` from the right.
256+ #[ inline]
257+ #[ must_use = "method returns a new vector and does not mutate the original inputs" ]
258+ pub fn shift_elements_left < const OFFSET : usize > ( self , padding : T ) -> Self {
259+ struct Shift < const OFFSET : usize > ;
260+
261+ impl < const OFFSET : usize , const N : usize > Swizzle < N > for Shift < OFFSET > {
262+ const INDEX : [ usize ; N ] = const {
263+ let mut index = [ N ; N ] ;
264+ let mut i = 0 ;
265+ while i + OFFSET < N {
266+ index[ i] = i + OFFSET ;
267+ i += 1 ;
268+ }
269+ index
270+ } ;
271+ }
272+
273+ Shift :: < OFFSET > :: concat_swizzle ( self , Simd :: splat ( padding) )
274+ }
275+
276+ /// Shifts the vector elements to the right by `OFFSET`, filling in with
277+ /// `padding` from the left.
278+ #[ inline]
279+ #[ must_use = "method returns a new vector and does not mutate the original inputs" ]
280+ pub fn shift_elements_right < const OFFSET : usize > ( self , padding : T ) -> Self {
281+ struct Shift < const OFFSET : usize > ;
282+
283+ impl < const OFFSET : usize , const N : usize > Swizzle < N > for Shift < OFFSET > {
284+ const INDEX : [ usize ; N ] = const {
285+ let mut index = [ N ; N ] ;
286+ let mut i = OFFSET ;
287+ while i < N {
288+ index[ i] = i - OFFSET ;
289+ i += 1 ;
290+ }
291+ index
292+ } ;
293+ }
294+
295+ Shift :: < OFFSET > :: concat_swizzle ( self , Simd :: splat ( padding) )
296+ }
297+
254298 /// Interleave two vectors.
255299 ///
256300 /// The resulting vectors contain elements taken alternatively from `self` and `other`, first
@@ -451,6 +495,36 @@ where
451495 unsafe { Self :: from_int_unchecked ( self . to_int ( ) . rotate_elements_right :: < OFFSET > ( ) ) }
452496 }
453497
498+ /// Shifts the mask elements to the left by `OFFSET`, filling in with
499+ /// `padding` from the right.
500+ #[ inline]
501+ #[ must_use = "method returns a new mask and does not mutate the original inputs" ]
502+ pub fn shift_elements_left < const OFFSET : usize > ( self , padding : bool ) -> Self {
503+ // Safety: swizzles are safe for masks
504+ unsafe {
505+ Self :: from_int_unchecked ( self . to_int ( ) . shift_elements_left :: < OFFSET > ( if padding {
506+ T :: TRUE
507+ } else {
508+ T :: FALSE
509+ } ) )
510+ }
511+ }
512+
513+ /// Shifts the mask elements to the right by `OFFSET`, filling in with
514+ /// `padding` from the left.
515+ #[ inline]
516+ #[ must_use = "method returns a new mask and does not mutate the original inputs" ]
517+ pub fn shift_elements_right < const OFFSET : usize > ( self , padding : bool ) -> Self {
518+ // Safety: swizzles are safe for masks
519+ unsafe {
520+ Self :: from_int_unchecked ( self . to_int ( ) . shift_elements_right :: < OFFSET > ( if padding {
521+ T :: TRUE
522+ } else {
523+ T :: FALSE
524+ } ) )
525+ }
526+ }
527+
454528 /// Interleave two masks.
455529 ///
456530 /// The resulting masks contain elements taken alternatively from `self` and `other`, first
0 commit comments