Skip to content

Commit ac50346

Browse files
authored
cmov: reorder impl blocks: Cmov then CmovEq (#1349)
Similar change to #1344, first doing all the impls of `Cmov`, then moving on to the impls of `CmovEq`, rather than alternating them for each core unsigned integer type.
1 parent 4b1bbca commit ac50346

3 files changed

Lines changed: 76 additions & 76 deletions

File tree

cmov/src/aarch64.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,31 @@ impl Cmov for u16 {
9898
}
9999
}
100100

101-
impl CmovEq for u16 {
101+
impl Cmov for u32 {
102102
#[inline]
103-
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
104-
cseleq32!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
103+
fn cmovnz(&mut self, value: &Self, condition: Condition) {
104+
csel32!("csel {1:w}, {2:w}, {3:w}, NE", self, value, condition);
105105
}
106106

107107
#[inline]
108-
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
109-
cseleq32!("csel {3:w}, {4:w}, {5:w}, EQ", self, rhs, input, output);
108+
fn cmovz(&mut self, value: &Self, condition: Condition) {
109+
csel32!("csel {1:w}, {2:w}, {3:w}, EQ", self, value, condition);
110110
}
111111
}
112112

113-
impl Cmov for u32 {
113+
impl Cmov for u64 {
114114
#[inline]
115115
fn cmovnz(&mut self, value: &Self, condition: Condition) {
116-
csel32!("csel {1:w}, {2:w}, {3:w}, NE", self, value, condition);
116+
csel64!("csel {1:x}, {2:x}, {3:x}, NE", self, value, condition);
117117
}
118118

119119
#[inline]
120120
fn cmovz(&mut self, value: &Self, condition: Condition) {
121-
csel32!("csel {1:w}, {2:w}, {3:w}, EQ", self, value, condition);
121+
csel64!("csel {1:x}, {2:x}, {3:x}, EQ", self, value, condition);
122122
}
123123
}
124124

125-
impl CmovEq for u32 {
125+
impl CmovEq for u16 {
126126
#[inline]
127127
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
128128
cseleq32!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
@@ -134,15 +134,15 @@ impl CmovEq for u32 {
134134
}
135135
}
136136

137-
impl Cmov for u64 {
137+
impl CmovEq for u32 {
138138
#[inline]
139-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
140-
csel64!("csel {1:x}, {2:x}, {3:x}, NE", self, value, condition);
139+
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
140+
cseleq32!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
141141
}
142142

143143
#[inline]
144-
fn cmovz(&mut self, value: &Self, condition: Condition) {
145-
csel64!("csel {1:x}, {2:x}, {3:x}, EQ", self, value, condition);
144+
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
145+
cseleq32!("csel {3:w}, {4:w}, {5:w}, EQ", self, rhs, input, output);
146146
}
147147
}
148148

cmov/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,6 @@ impl Cmov for u8 {
9898
}
9999
}
100100

101-
impl CmovEq for u8 {
102-
#[inline]
103-
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
104-
u16::from(*self).cmoveq(&u16::from(*rhs), input, output);
105-
}
106-
107-
#[inline]
108-
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
109-
u16::from(*self).cmovne(&u16::from(*rhs), input, output);
110-
}
111-
}
112-
113101
impl Cmov for u128 {
114102
#[inline]
115103
fn cmovnz(&mut self, value: &Self, condition: Condition) {
@@ -134,6 +122,18 @@ impl Cmov for u128 {
134122
}
135123
}
136124

125+
impl CmovEq for u8 {
126+
#[inline]
127+
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
128+
u16::from(*self).cmoveq(&u16::from(*rhs), input, output);
129+
}
130+
131+
#[inline]
132+
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
133+
u16::from(*self).cmovne(&u16::from(*rhs), input, output);
134+
}
135+
}
136+
137137
impl CmovEq for u128 {
138138
#[inline]
139139
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {

cmov/src/x86.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,56 @@ impl Cmov for u16 {
5757
}
5858
}
5959

60+
impl Cmov for u32 {
61+
#[inline]
62+
fn cmovnz(&mut self, value: &Self, condition: Condition) {
63+
cmov!("cmovnz {1:e}, {2:e}", self, value, condition);
64+
}
65+
66+
#[inline]
67+
fn cmovz(&mut self, value: &Self, condition: Condition) {
68+
cmov!("cmovz {1:e}, {2:e}", self, value, condition);
69+
}
70+
}
71+
72+
#[cfg(target_arch = "x86")]
73+
impl Cmov for u64 {
74+
#[inline]
75+
fn cmovnz(&mut self, value: &Self, condition: Condition) {
76+
let mut lo = (*self & u32::MAX as u64) as u32;
77+
let mut hi = (*self >> 32) as u32;
78+
79+
lo.cmovnz(&((*value & u32::MAX as u64) as u32), condition);
80+
hi.cmovnz(&((*value >> 32) as u32), condition);
81+
82+
*self = (lo as u64) | (hi as u64) << 32;
83+
}
84+
85+
#[inline]
86+
fn cmovz(&mut self, value: &Self, condition: Condition) {
87+
let mut lo = (*self & u32::MAX as u64) as u32;
88+
let mut hi = (*self >> 32) as u32;
89+
90+
lo.cmovz(&((*value & u32::MAX as u64) as u32), condition);
91+
hi.cmovz(&((*value >> 32) as u32), condition);
92+
93+
*self = (lo as u64) | (hi as u64) << 32;
94+
}
95+
}
96+
97+
#[cfg(target_arch = "x86_64")]
98+
impl Cmov for u64 {
99+
#[inline]
100+
fn cmovnz(&mut self, value: &Self, condition: Condition) {
101+
cmov!("cmovnz {1:r}, {2:r}", self, value, condition);
102+
}
103+
104+
#[inline]
105+
fn cmovz(&mut self, value: &Self, condition: Condition) {
106+
cmov!("cmovz {1:r}, {2:r}", self, value, condition);
107+
}
108+
}
109+
60110
impl CmovEq for u16 {
61111
#[inline]
62112
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
@@ -83,18 +133,6 @@ impl CmovEq for u16 {
83133
}
84134
}
85135

86-
impl Cmov for u32 {
87-
#[inline]
88-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
89-
cmov!("cmovnz {1:e}, {2:e}", self, value, condition);
90-
}
91-
92-
#[inline]
93-
fn cmovz(&mut self, value: &Self, condition: Condition) {
94-
cmov!("cmovz {1:e}, {2:e}", self, value, condition);
95-
}
96-
}
97-
98136
impl CmovEq for u32 {
99137
#[inline]
100138
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
@@ -121,31 +159,6 @@ impl CmovEq for u32 {
121159
}
122160
}
123161

124-
#[cfg(target_arch = "x86")]
125-
impl Cmov for u64 {
126-
#[inline]
127-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
128-
let mut lo = (*self & u32::MAX as u64) as u32;
129-
let mut hi = (*self >> 32) as u32;
130-
131-
lo.cmovnz(&((*value & u32::MAX as u64) as u32), condition);
132-
hi.cmovnz(&((*value >> 32) as u32), condition);
133-
134-
*self = (lo as u64) | (hi as u64) << 32;
135-
}
136-
137-
#[inline]
138-
fn cmovz(&mut self, value: &Self, condition: Condition) {
139-
let mut lo = (*self & u32::MAX as u64) as u32;
140-
let mut hi = (*self >> 32) as u32;
141-
142-
lo.cmovz(&((*value & u32::MAX as u64) as u32), condition);
143-
hi.cmovz(&((*value >> 32) as u32), condition);
144-
145-
*self = (lo as u64) | (hi as u64) << 32;
146-
}
147-
}
148-
149162
#[cfg(target_arch = "x86")]
150163
impl CmovEq for u64 {
151164
#[inline]
@@ -171,19 +184,6 @@ impl CmovEq for u64 {
171184
}
172185
}
173186

174-
#[cfg(target_arch = "x86_64")]
175-
impl Cmov for u64 {
176-
#[inline]
177-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
178-
cmov!("cmovnz {1:r}, {2:r}", self, value, condition);
179-
}
180-
181-
#[inline]
182-
fn cmovz(&mut self, value: &Self, condition: Condition) {
183-
cmov!("cmovz {1:r}, {2:r}", self, value, condition);
184-
}
185-
}
186-
187187
#[cfg(target_arch = "x86_64")]
188188
impl CmovEq for u64 {
189189
#[inline]

0 commit comments

Comments
 (0)