@@ -16,6 +16,12 @@ pub trait SimdUint: Copy + Sealed {
16
16
#[ must_use]
17
17
fn cast < T : SimdCast > ( self ) -> Self :: Cast < T > ;
18
18
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
+
19
25
/// Lanewise saturating add.
20
26
///
21
27
/// # Examples
@@ -74,7 +80,7 @@ pub trait SimdUint: Copy + Sealed {
74
80
}
75
81
76
82
macro_rules! impl_trait {
77
- { $( $ty: ty ) ,* } => {
83
+ { $( $ty: ident ( $signed : ident ) ) ,* } => {
78
84
$(
79
85
impl <const LANES : usize > Sealed for Simd <$ty, LANES >
80
86
where
@@ -95,6 +101,12 @@ macro_rules! impl_trait {
95
101
unsafe { intrinsics:: simd_as( self ) }
96
102
}
97
103
104
+ #[ inline]
105
+ fn wrapping_neg( self ) -> Self {
106
+ use crate :: simd:: SimdInt ;
107
+ ( -self . cast:: <$signed>( ) ) . cast( )
108
+ }
109
+
98
110
#[ inline]
99
111
fn saturating_add( self , second: Self ) -> Self {
100
112
// Safety: `self` is a vector
@@ -153,4 +165,4 @@ macro_rules! impl_trait {
153
165
}
154
166
}
155
167
156
- impl_trait ! { u8 , u16 , u32 , u64 , usize }
168
+ impl_trait ! { u8 ( i8 ) , u16 ( i16 ) , u32 ( i32 ) , u64 ( i64 ) , usize ( isize ) }
0 commit comments