11use super :: sealed:: Sealed ;
22use crate :: simd:: {
3- intrinsics, LaneCount , Mask , Simd , SimdCast , SimdElement , SimdPartialOrd , SupportedLaneCount ,
3+ intrinsics, LaneCount , Mask , Simd , SimdCast , SimdElement , SimdPartialOrd , SimdUint ,
4+ SupportedLaneCount ,
45} ;
56
67/// Operations on SIMD vectors of signed integers.
@@ -11,6 +12,9 @@ pub trait SimdInt: Copy + Sealed {
1112 /// Scalar type contained by this SIMD vector type.
1213 type Scalar ;
1314
15+ /// A SIMD vector of unsigned integers with the same element size.
16+ type Unsigned ;
17+
1418 /// A SIMD vector with a different element type.
1519 type Cast < T : SimdElement > ;
1620
@@ -200,20 +204,20 @@ pub trait SimdInt: Copy + Sealed {
200204 fn reverse_bits ( self ) -> Self ;
201205
202206 /// Returns the number of leading zeros in the binary representation of each element.
203- fn leading_zeros ( self ) -> Self ;
207+ fn leading_zeros ( self ) -> Self :: Unsigned ;
204208
205209 /// Returns the number of trailing zeros in the binary representation of each element.
206- fn trailing_zeros ( self ) -> Self ;
210+ fn trailing_zeros ( self ) -> Self :: Unsigned ;
207211
208212 /// Returns the number of leading ones in the binary representation of each element.
209- fn leading_ones ( self ) -> Self ;
213+ fn leading_ones ( self ) -> Self :: Unsigned ;
210214
211215 /// Returns the number of trailing ones in the binary representation of each element.
212- fn trailing_ones ( self ) -> Self ;
216+ fn trailing_ones ( self ) -> Self :: Unsigned ;
213217}
214218
215219macro_rules! impl_trait {
216- { $( $ty: ty ) ,* } => {
220+ { $( $ty: ident ( $unsigned : ident ) ) ,* } => {
217221 $(
218222 impl <const LANES : usize > Sealed for Simd <$ty, LANES >
219223 where
@@ -227,6 +231,7 @@ macro_rules! impl_trait {
227231 {
228232 type Mask = Mask <<$ty as SimdElement >:: Mask , LANES >;
229233 type Scalar = $ty;
234+ type Unsigned = Simd <$unsigned, LANES >;
230235 type Cast <T : SimdElement > = Simd <T , LANES >;
231236
232237 #[ inline]
@@ -340,29 +345,27 @@ macro_rules! impl_trait {
340345 }
341346
342347 #[ inline]
343- fn leading_zeros( self ) -> Self {
344- // Safety: `self` is an integer vector
345- unsafe { intrinsics:: simd_ctlz( self ) }
348+ fn leading_zeros( self ) -> Self :: Unsigned {
349+ self . cast:: <$unsigned>( ) . leading_zeros( )
346350 }
347351
348352 #[ inline]
349- fn trailing_zeros( self ) -> Self {
350- // Safety: `self` is an integer vector
351- unsafe { intrinsics:: simd_cttz( self ) }
353+ fn trailing_zeros( self ) -> Self :: Unsigned {
354+ self . cast:: <$unsigned>( ) . trailing_zeros( )
352355 }
353356
354357 #[ inline]
355- fn leading_ones( self ) -> Self {
356- ( ! self ) . leading_zeros ( )
358+ fn leading_ones( self ) -> Self :: Unsigned {
359+ self . cast :: <$unsigned> ( ) . leading_ones ( )
357360 }
358361
359362 #[ inline]
360- fn trailing_ones( self ) -> Self {
361- ( ! self ) . trailing_zeros ( )
363+ fn trailing_ones( self ) -> Self :: Unsigned {
364+ self . cast :: <$unsigned> ( ) . trailing_ones ( )
362365 }
363366 }
364367 ) *
365368 }
366369}
367370
368- impl_trait ! { i8 , i16 , i32 , i64 , isize }
371+ impl_trait ! { i8 ( u8 ) , i16 ( u16 ) , i32 ( u32 ) , i64 ( u64 ) , isize ( usize ) }
0 commit comments