@@ -153,7 +153,7 @@ impl CmovEq for u128 {
153153 }
154154}
155155
156- // Impl `Cmov*` by first casting to unsigned then using the unsigned `Cmov` impls
156+ /// Impl `Cmov*` by first casting to unsigned then using the unsigned `Cmov` impls
157157// TODO(tarcieri): use `cast_unsigned`/`cast_signed` to get rid of the `=> u*`
158158macro_rules! impl_cmov_traits_for_signed_ints {
159159 ( $( $int: ty => $uint: ty) ,+ ) => {
@@ -190,3 +190,62 @@ macro_rules! impl_cmov_traits_for_signed_ints {
190190}
191191
192192impl_cmov_traits_for_signed_ints ! ( i8 => u8 , i16 => u16 , i32 => u32 , i64 => u64 , i128 => u128 ) ;
193+
194+ macro_rules! impl_cmov_traits_for_size_type {
195+ ( $size: ty, $int16: ty, $int32: ty, $int64: ty) => {
196+ #[ cfg( any(
197+ target_pointer_width = "16" ,
198+ target_pointer_width = "32" ,
199+ target_pointer_width = "64"
200+ ) ) ]
201+ impl Cmov for $size {
202+ #[ cfg( target_pointer_width = "16" ) ]
203+ #[ inline]
204+ fn cmovnz( & mut self , other: & Self , condition: Condition ) {
205+ ( * self as $int16) . cmovnz( & ( * other as $int16) , condition) ;
206+ }
207+
208+ #[ cfg( target_pointer_width = "32" ) ]
209+ #[ inline]
210+ fn cmovnz( & mut self , other: & Self , condition: Condition ) {
211+ ( * self as $int32) . cmovnz( & ( * other as $int32) , condition) ;
212+ }
213+
214+ #[ cfg( target_pointer_width = "64" ) ]
215+ #[ allow( clippy:: cast_possible_truncation) ]
216+ #[ inline]
217+ fn cmovnz( & mut self , other: & Self , condition: Condition ) {
218+ ( * self as $int64) . cmovnz( & ( * other as $int64) , condition) ;
219+ }
220+ }
221+
222+ #[ cfg( any(
223+ target_pointer_width = "16" ,
224+ target_pointer_width = "32" ,
225+ target_pointer_width = "64"
226+ ) ) ]
227+ impl CmovEq for $size {
228+ #[ cfg( target_pointer_width = "16" ) ]
229+ #[ inline]
230+ fn cmovne( & self , rhs: & Self , input: Condition , output: & mut Condition ) {
231+ ( * self as $int16) . cmovne( & ( * rhs as $int16) , input, output) ;
232+ }
233+
234+ #[ cfg( target_pointer_width = "32" ) ]
235+ #[ inline]
236+ fn cmovne( & self , rhs: & Self , input: Condition , output: & mut Condition ) {
237+ ( * self as $int32) . cmovne( & ( * rhs as $int32) , input, output) ;
238+ }
239+
240+ #[ cfg( target_pointer_width = "64" ) ]
241+ #[ allow( clippy:: cast_possible_truncation) ]
242+ #[ inline]
243+ fn cmovne( & self , rhs: & Self , input: Condition , output: & mut Condition ) {
244+ ( * self as $int64) . cmovne( & ( * rhs as $int64) , input, output) ;
245+ }
246+ }
247+ } ;
248+ }
249+
250+ impl_cmov_traits_for_size_type ! ( isize , i16 , i32 , i64 ) ;
251+ impl_cmov_traits_for_size_type ! ( usize , u16 , u32 , u64 ) ;
0 commit comments