@@ -25,6 +25,24 @@ macro_rules! cmov {
25
25
} ;
26
26
}
27
27
28
+ macro_rules! cmov_eq {
29
+ ( $xor: expr, $instruction: expr, $lhs: expr, $rhs: expr, $condition: expr, $dst: expr) => {
30
+ let mut tmp = * $dst as u16 ;
31
+ unsafe {
32
+ asm! {
33
+ $xor,
34
+ $instruction,
35
+ inout( reg) * $lhs => _,
36
+ in( reg) * $rhs,
37
+ inlateout( reg) tmp,
38
+ in( reg) $condition as u16 ,
39
+ options( pure, nomem, nostack) ,
40
+ } ;
41
+ }
42
+ * $dst = tmp as u8 ;
43
+ } ;
44
+ }
45
+
28
46
impl Cmov for u16 {
29
47
#[ inline]
30
48
fn cmovnz ( & mut self , value : & Self , condition : Condition ) {
@@ -40,12 +58,26 @@ impl Cmov for u16 {
40
58
impl CmovEq for u16 {
41
59
#[ inline]
42
60
fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
43
- output. cmovz ( & input, ( self ^ rhs) as u8 ) ;
61
+ cmov_eq ! (
62
+ "xor {0:x}, {1:x}" ,
63
+ "cmovz {2:e}, {3:e}" ,
64
+ self ,
65
+ rhs,
66
+ input,
67
+ output
68
+ ) ;
44
69
}
45
70
46
71
#[ inline]
47
72
fn cmovne ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
48
- output. cmovnz ( & input, ( self ^ rhs) as u8 ) ;
73
+ cmov_eq ! (
74
+ "xor {0:x}, {1:x}" ,
75
+ "cmovnz {2:e}, {3:e}" ,
76
+ self ,
77
+ rhs,
78
+ input,
79
+ output
80
+ ) ;
49
81
}
50
82
}
51
83
@@ -64,12 +96,26 @@ impl Cmov for u32 {
64
96
impl CmovEq for u32 {
65
97
#[ inline]
66
98
fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
67
- output. cmovz ( & input, ( self ^ rhs) as u8 ) ;
99
+ cmov_eq ! (
100
+ "xor {0:e}, {1:e}" ,
101
+ "cmovz {2:e}, {3:e}" ,
102
+ self ,
103
+ rhs,
104
+ input,
105
+ output
106
+ ) ;
68
107
}
69
108
70
109
#[ inline]
71
110
fn cmovne ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
72
- output. cmovnz ( & input, ( self ^ rhs) as u8 ) ;
111
+ cmov_eq ! (
112
+ "xor {0:e}, {1:e}" ,
113
+ "cmovnz {2:e}, {3:e}" ,
114
+ self ,
115
+ rhs,
116
+ input,
117
+ output
118
+ ) ;
73
119
}
74
120
}
75
121
@@ -140,11 +186,25 @@ impl Cmov for u64 {
140
186
impl CmovEq for u64 {
141
187
#[ inline]
142
188
fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
143
- output. cmovz ( & input, ( self ^ rhs) as u8 ) ;
189
+ cmov_eq ! (
190
+ "xor {0:r}, {1:r}" ,
191
+ "cmovz {2:r}, {3:r}" ,
192
+ self ,
193
+ rhs,
194
+ input,
195
+ output
196
+ ) ;
144
197
}
145
198
146
199
#[ inline]
147
200
fn cmovne ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
148
- output. cmovnz ( & input, ( self ^ rhs) as u8 ) ;
201
+ cmov_eq ! (
202
+ "xor {0:r}, {1:r}" ,
203
+ "cmovnz {2:r}, {3:r}" ,
204
+ self ,
205
+ rhs,
206
+ input,
207
+ output
208
+ ) ;
149
209
}
150
210
}
0 commit comments