@@ -16,6 +16,12 @@ pub trait SimdUint: Copy + Sealed {
1616 #[ must_use]
1717 fn cast < T : SimdCast > ( self ) -> Self :: Cast < T > ;
1818
19+ /// Wrapping negation.
20+ ///
21+ /// Like [`u32::wrapping_neg`], all applications of this function will wrap, with the exception
22+ /// of `-0`.
23+ fn wrapping_neg ( self ) -> Self ;
24+
1925 /// Lanewise saturating add.
2026 ///
2127 /// # Examples
@@ -74,7 +80,7 @@ pub trait SimdUint: Copy + Sealed {
7480}
7581
7682macro_rules! impl_trait {
77- { $( $ty: ty ) ,* } => {
83+ { $( $ty: ident ( $signed : ident ) ) ,* } => {
7884 $(
7985 impl <const LANES : usize > Sealed for Simd <$ty, LANES >
8086 where
@@ -95,6 +101,12 @@ macro_rules! impl_trait {
95101 unsafe { intrinsics:: simd_as( self ) }
96102 }
97103
104+ #[ inline]
105+ fn wrapping_neg( self ) -> Self {
106+ use crate :: simd:: SimdInt ;
107+ ( -self . cast:: <$signed>( ) ) . cast( )
108+ }
109+
98110 #[ inline]
99111 fn saturating_add( self , second: Self ) -> Self {
100112 // Safety: `self` is a vector
@@ -153,4 +165,4 @@ macro_rules! impl_trait {
153165 }
154166}
155167
156- impl_trait ! { u8 , u16 , u32 , u64 , usize }
168+ impl_trait ! { u8 ( i8 ) , u16 ( i16 ) , u32 ( i32 ) , u64 ( i64 ) , usize ( isize ) }
0 commit comments