@@ -135,6 +135,44 @@ impl CmovEq for u128 {
135135 }
136136}
137137
138+ // Impl `Cmov*` by first casting to unsigned then using the unsigned `Cmov` impls
139+ // TODO(tarcieri): use `cast_unsigned`/`cast_signed` to get rid of the `=> u*`
140+ macro_rules! impl_cmov_traits_for_signed_ints {
141+ ( $( $int: ty => $uint: ty) ,+ ) => {
142+ $(
143+ impl Cmov for $int {
144+ #[ inline]
145+ fn cmovnz( & mut self , value: & Self , condition: Condition ) {
146+ let mut tmp = * self as $uint;
147+ tmp. cmovnz( & ( * value as $uint) , condition) ;
148+ * self = tmp as $int;
149+ }
150+
151+ #[ inline]
152+ fn cmovz( & mut self , value: & Self , condition: Condition ) {
153+ let mut tmp = * self as $uint;
154+ tmp. cmovz( & ( * value as $uint) , condition) ;
155+ * self = tmp as $int;
156+ }
157+ }
158+
159+ impl CmovEq for $int {
160+ #[ inline]
161+ fn cmoveq( & self , rhs: & Self , input: Condition , output: & mut Condition ) {
162+ ( * self as $uint) . cmoveq( & ( * rhs as $uint) , input, output) ;
163+ }
164+
165+ #[ inline]
166+ fn cmovne( & self , rhs: & Self , input: Condition , output: & mut Condition ) {
167+ ( * self as $uint) . cmovne( & ( * rhs as $uint) , input, output) ;
168+ }
169+ }
170+ ) +
171+ } ;
172+ }
173+
174+ impl_cmov_traits_for_signed_ints ! ( i8 => u8 , i16 => u16 , i32 => u32 , i64 => u64 , i128 => u128 ) ;
175+
138176impl < T : CmovEq > CmovEq for [ T ] {
139177 fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
140178 let mut tmp = 1u8 ;
0 commit comments