Skip to content

Commit b87f17c

Browse files
authored
cmov: clippy fixups for portable backend (#1341)
These weren't being detected/applied since clippy runs on x86. Maybe we need `cfg` to override the backend.
1 parent 8b33b63 commit b87f17c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

cmov/src/portable.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ use crate::{Cmov, CmovEq, Condition};
1010

1111
impl Cmov for u16 {
1212
#[inline]
13-
fn cmovnz(&mut self, value: &Self, condition: Condition) {
14-
let mut tmp = *self as u32;
15-
tmp.cmovnz(&(*value as u32), condition);
16-
*self = tmp as u16;
13+
fn cmovnz(&mut self, value: &u16, condition: Condition) {
14+
let mut tmp = u32::from(*self);
15+
tmp.cmovnz(&(*value).into(), condition);
16+
*self = (tmp & 0xFFFF) as u16;
1717
}
1818

1919
#[inline]
20-
fn cmovz(&mut self, value: &Self, condition: Condition) {
21-
let mut tmp = *self as u32;
22-
tmp.cmovz(&(*value as u32), condition);
23-
*self = tmp as u16;
20+
fn cmovz(&mut self, value: &u16, condition: Condition) {
21+
let mut tmp = u32::from(*self);
22+
tmp.cmovz(&(*value).into(), condition);
23+
*self = (tmp & 0xFFFF) as u16;
2424
}
2525
}
2626

2727
impl CmovEq for u16 {
2828
#[inline]
2929
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
30-
(*self as u32).cmovne(&(*rhs as u32), input, output);
30+
u32::from(*self).cmovne(&(*rhs).into(), input, output);
3131
}
3232

3333
#[inline]
3434
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
35-
(*self as u32).cmoveq(&(*rhs as u32), input, output);
35+
u32::from(*self).cmoveq(&(*rhs).into(), input, output);
3636
}
3737
}
3838

@@ -104,12 +104,12 @@ fn testeq64(x: u64, y: u64) -> Condition {
104104

105105
/// Returns `0` if `x` is equal to `y`, otherwise returns `1` (32-bit version)
106106
fn testne32(x: u32, y: u32) -> Condition {
107-
testnz32(x ^ y) as Condition
107+
(testnz32(x ^ y) & 0xFF) as Condition
108108
}
109109

110110
/// Returns `0` if `x` is equal to `y`, otherwise returns `1` (64-bit version)
111111
fn testne64(x: u64, y: u64) -> Condition {
112-
testnz64(x ^ y) as Condition
112+
(testnz64(x ^ y) & 0xFF) as Condition
113113
}
114114

115115
/// Returns `0` if `x` is `0`, otherwise returns `1` (32-bit version)
@@ -126,12 +126,12 @@ fn testnz64(mut x: u64) -> u64 {
126126

127127
/// Return a [`u32::MAX`] mask if `condition` is non-zero, otherwise return zero for a zero input.
128128
fn masknz32(condition: Condition) -> u32 {
129-
testnz32(condition as u32).wrapping_neg()
129+
testnz32(condition.into()).wrapping_neg()
130130
}
131131

132132
/// Return a [`u64::MAX`] mask if `condition` is non-zero, otherwise return zero for a zero input.
133133
fn masknz64(condition: Condition) -> u64 {
134-
testnz64(condition as u64).wrapping_neg()
134+
testnz64(condition.into()).wrapping_neg()
135135
}
136136

137137
#[cfg(test)]

0 commit comments

Comments
 (0)