Skip to content

Commit ced2f2a

Browse files
authored
cmov: group impl blocks by trait in portable backend (#1344)
Orders the impls so the `Cmov` impls for `u16`, `u32`, and `u64` come first, followed by the respective `CmovEq` impls.
1 parent 65f1aec commit ced2f2a

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

cmov/src/portable.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,52 @@ impl Cmov for u16 {
2626
}
2727
}
2828

29-
// Uses `CmovEq` impl for `u32`
30-
impl CmovEq for u16 {
29+
impl Cmov for u32 {
3130
#[inline]
32-
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
33-
u32::from(*self).cmovne(&(*rhs).into(), input, output);
31+
fn cmovnz(&mut self, value: &Self, condition: Condition) {
32+
*self = masksel(*self, *value, masknz32(condition.into()));
3433
}
3534

3635
#[inline]
37-
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
38-
u32::from(*self).cmoveq(&(*rhs).into(), input, output);
36+
fn cmovz(&mut self, value: &Self, condition: Condition) {
37+
*self = masksel(*self, *value, !masknz32(condition.into()));
3938
}
4039
}
4140

42-
impl Cmov for u32 {
41+
impl Cmov for u64 {
4342
#[inline]
4443
fn cmovnz(&mut self, value: &Self, condition: Condition) {
45-
*self = masksel(*self, *value, masknz32(condition.into()));
44+
*self = masksel(*self, *value, masknz64(condition.into()));
4645
}
4746

4847
#[inline]
4948
fn cmovz(&mut self, value: &Self, condition: Condition) {
50-
*self = masksel(*self, *value, !masknz32(condition.into()));
49+
*self = masksel(*self, *value, !masknz64(condition.into()));
5150
}
5251
}
5352

54-
impl CmovEq for u32 {
53+
// Uses `CmovEq` impl for `u32`
54+
impl CmovEq for u16 {
5555
#[inline]
5656
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
57-
*output = masksel(*output, input, (maskne32(*self, *rhs) & 0xFF) as u8);
57+
u32::from(*self).cmovne(&(*rhs).into(), input, output);
5858
}
5959

6060
#[inline]
6161
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
62-
*output = masksel(*output, input, (maskeq32(*self, *rhs) & 0xFF) as u8);
62+
u32::from(*self).cmoveq(&(*rhs).into(), input, output);
6363
}
6464
}
6565

66-
impl Cmov for u64 {
66+
impl CmovEq for u32 {
6767
#[inline]
68-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
69-
*self = masksel(*self, *value, masknz64(condition.into()));
68+
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
69+
*output = masksel(*output, input, (maskne32(*self, *rhs) & 0xFF) as u8);
7070
}
7171

7272
#[inline]
73-
fn cmovz(&mut self, value: &Self, condition: Condition) {
74-
*self = masksel(*self, *value, !masknz64(condition.into()));
73+
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
74+
*output = masksel(*output, input, (maskeq32(*self, *rhs) & 0xFF) as u8);
7575
}
7676
}
7777

@@ -88,21 +88,25 @@ impl CmovEq for u64 {
8888
}
8989

9090
/// Returns `u32::MAX` if `x` is equal to `y`, otherwise returns `0` (32-bit version)
91+
#[inline]
9192
fn maskeq32(x: u32, y: u32) -> u32 {
9293
!maskne32(x, y)
9394
}
9495

9596
/// Returns `u32::MAX` if `x` is equal to `y`, otherwise returns `0` (64-bit version)
97+
#[inline]
9698
fn maskeq64(x: u64, y: u64) -> u64 {
9799
!maskne64(x, y)
98100
}
99101

100102
/// Returns `0` if `x` is equal to `y`, otherwise returns `1` (32-bit version)
103+
#[inline]
101104
fn maskne32(x: u32, y: u32) -> u32 {
102105
masknz32(x ^ y)
103106
}
104107

105108
/// Returns `0` if `x` is equal to `y`, otherwise returns `1` (64-bit version)
109+
#[inline]
106110
fn maskne64(x: u64, y: u64) -> u64 {
107111
masknz64(x ^ y)
108112
}

0 commit comments

Comments
 (0)