Skip to content

Commit 4b1bbca

Browse files
authored
cmov: clippy cleanups (#1348)
Fixes `clippy::cast_possible_truncation` lint and runs clippy against all targets.
1 parent 2ced04e commit 4b1bbca

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

.github/workflows/workspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
toolchain: 1.92.0 # Pinned to prevent breakages
2929
components: clippy
30-
- run: cargo clippy --workspace --all-features --lib --bins --tests -- -D warnings
30+
- run: cargo clippy --workspace --all-features --all-targets --lib --bins --tests -- -Dwarnings
3131

3232
rustfmt:
3333
runs-on: ubuntu-latest

cmov/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,53 +110,49 @@ impl CmovEq for u8 {
110110
}
111111
}
112112

113-
// TODO(tarcieri): address truncation lint
114-
#[allow(clippy::cast_possible_truncation)]
115113
impl Cmov for u128 {
116114
#[inline]
117115
fn cmovnz(&mut self, value: &Self, condition: Condition) {
118-
let mut lo = (*self & u128::from(u64::MAX)) as u64;
116+
let mut lo = (*self & 0xFFFF_FFFF_FFFF_FFFF) as u64;
119117
let mut hi = (*self >> 64) as u64;
120118

121-
lo.cmovnz(&((*value & u128::from(u64::MAX)) as u64), condition);
119+
lo.cmovnz(&((*value & 0xFFFF_FFFF_FFFF_FFFF) as u64), condition);
122120
hi.cmovnz(&((*value >> 64) as u64), condition);
123121

124122
*self = u128::from(lo) | (u128::from(hi) << 64);
125123
}
126124

127125
#[inline]
128126
fn cmovz(&mut self, value: &Self, condition: Condition) {
129-
let mut lo = (*self & u128::from(u64::MAX)) as u64;
127+
let mut lo = (*self & 0xFFFF_FFFF_FFFF_FFFF) as u64;
130128
let mut hi = (*self >> 64) as u64;
131129

132-
lo.cmovz(&((*value & u128::from(u64::MAX)) as u64), condition);
130+
lo.cmovz(&((*value & 0xFFFF_FFFF_FFFF_FFFF) as u64), condition);
133131
hi.cmovz(&((*value >> 64) as u64), condition);
134132

135133
*self = u128::from(lo) | (u128::from(hi) << 64);
136134
}
137135
}
138136

139-
// TODO(tarcieri): address truncation lint
140-
#[allow(clippy::cast_possible_truncation)]
141137
impl CmovEq for u128 {
142138
#[inline]
143139
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
144-
let lo = (*self & u128::from(u64::MAX)) as u64;
140+
let lo = (*self & 0xFFFF_FFFF_FFFF_FFFF) as u64;
145141
let hi = (*self >> 64) as u64;
146142

147143
let mut tmp = 1u8;
148-
lo.cmovne(&((*rhs & u128::from(u64::MAX)) as u64), 0, &mut tmp);
144+
lo.cmovne(&((*rhs & 0xFFFF_FFFF_FFFF_FFFF) as u64), 0, &mut tmp);
149145
hi.cmovne(&((*rhs >> 64) as u64), 0, &mut tmp);
150146
tmp.cmoveq(&0, input, output);
151147
}
152148

153149
#[inline]
154150
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
155-
let lo = (*self & u128::from(u64::MAX)) as u64;
151+
let lo = (*self & 0xFFFF_FFFF_FFFF_FFFF) as u64;
156152
let hi = (*self >> 64) as u64;
157153

158154
let mut tmp = 1u8;
159-
lo.cmovne(&((*rhs & u128::from(u64::MAX)) as u64), 0, &mut tmp);
155+
lo.cmovne(&((*rhs & 0xFFFF_FFFF_FFFF_FFFF) as u64), 0, &mut tmp);
160156
hi.cmovne(&((*rhs >> 64) as u64), 0, &mut tmp);
161157
tmp.cmoveq(&1, input, output);
162158
}

0 commit comments

Comments
 (0)