Skip to content

Commit

Permalink
Rollup merge of #110402 - scottmcm:align-tz, r=fee1-dead
Browse files Browse the repository at this point in the history
Remove the loop in `Align::from_bytes`

Perf is almost certainly irrelevant, but might as well simplify it, since `trailing_zeros` does exactly what's needed.
  • Loading branch information
fee1-dead authored Apr 16, 2023
2 parents 5e2fcbc + 99fd9cb commit 9c2a26d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,12 @@ impl Align {
format!("`{}` is too large", align)
}

let mut bytes = align;
let mut pow2: u8 = 0;
while (bytes & 1) == 0 {
pow2 += 1;
bytes >>= 1;
}
if bytes != 1 {
let tz = align.trailing_zeros();
if align != (1 << tz) {
return Err(not_power_of_2(align));
}

let pow2 = tz as u8;
if pow2 > Self::MAX.pow2 {
return Err(too_large(align));
}
Expand Down

0 comments on commit 9c2a26d

Please sign in to comment.