@@ -191,10 +191,29 @@ pub trait SimdInt: Copy + Sealed {
191191
192192 /// Returns the cumulative bitwise "xor" across the lanes of the vector.
193193 fn reduce_xor ( self ) -> Self :: Scalar ;
194+
195+ /// Reverses the byte order of each element.
196+ fn swap_bytes ( self ) -> Self ;
197+
198+ /// Reverses the order of bits in each elemnent.
199+ /// The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
200+ fn reverse_bits ( self ) -> Self ;
201+
202+ /// Returns the number of leading zeros in the binary representation of each element.
203+ fn leading_zeros ( self ) -> Self ;
204+
205+ /// Returns the number of trailing zeros in the binary representation of each element.
206+ fn trailing_zeros ( self ) -> Self ;
207+
208+ /// Returns the number of leading ones in the binary representation of each element.
209+ fn leading_ones ( self ) -> Self ;
210+
211+ /// Returns the number of trailing ones in the binary representation of each element.
212+ fn trailing_ones ( self ) -> Self ;
194213}
195214
196215macro_rules! impl_trait {
197- { $( $ty: ty ) ,* } => {
216+ { $( $ty: ident ( $unsigned : ident ) ) ,* } => {
198217 $(
199218 impl <const LANES : usize > Sealed for Simd <$ty, LANES >
200219 where
@@ -307,9 +326,45 @@ macro_rules! impl_trait {
307326 // Safety: `self` is an integer vector
308327 unsafe { intrinsics:: simd_reduce_xor( self ) }
309328 }
329+
330+ #[ inline]
331+ fn swap_bytes( self ) -> Self {
332+ // Safety: `self` is an integer vector
333+ unsafe { intrinsics:: simd_bswap( self ) }
334+ }
335+
336+ #[ inline]
337+ fn reverse_bits( self ) -> Self {
338+ // Safety: `self` is an integer vector
339+ unsafe { intrinsics:: simd_bitreverse( self ) }
340+ }
341+
342+ #[ inline]
343+ fn leading_zeros( self ) -> Self {
344+ // Safety: `self` is an integer vector
345+ unsafe { intrinsics:: simd_ctlz( self ) }
346+ }
347+
348+ #[ inline]
349+ fn trailing_zeros( self ) -> Self {
350+ // Safety: `self` is an integer vector
351+ unsafe { intrinsics:: simd_cttz( self ) }
352+ }
353+
354+ #[ inline]
355+ fn leading_ones( self ) -> Self {
356+ use crate :: simd:: SimdUint ;
357+ self . cast:: <$unsigned>( ) . leading_ones( ) . cast( )
358+ }
359+
360+ #[ inline]
361+ fn trailing_ones( self ) -> Self {
362+ use crate :: simd:: SimdUint ;
363+ self . cast:: <$unsigned>( ) . trailing_ones( ) . cast( )
364+ }
310365 }
311366 ) *
312367 }
313368}
314369
315- impl_trait ! { i8 , i16 , i32 , i64 , isize }
370+ impl_trait ! { i8 ( u8 ) , i16 ( u16 ) , i32 ( u32 ) , i64 ( u64 ) , isize ( usize ) }
0 commit comments