Skip to content

Commit b337e9b

Browse files
authored
Simplify impl_shift_amount macro (#1550)
simplify impl_shift_amount macro
1 parent 2510004 commit b337e9b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

crates/ir/src/primitive.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,15 @@ pub trait IntoShiftAmount: Sized {
390390
}
391391

392392
macro_rules! impl_shift_amount {
393-
( $( ($ty:ty, $bits:literal, $ty16:ty, $shamt:ty) ),* $(,)? ) => {
393+
( $( ($ty:ty, $ty16:ty, $shamt:ty) ),* $(,)? ) => {
394394
$(
395395
impl IntoShiftAmount for $ty {
396396
type Output = ShiftAmount<$shamt>;
397397
type Input = $shamt;
398398

399399
fn into_shift_amount(input: Self::Input) -> Option<Self::Output> {
400-
let value = (input % $bits) as $ty16;
400+
const BITS: $shamt = (::core::mem::size_of::<$ty>() * 8) as $shamt;
401+
let value = (input % BITS) as $ty16;
401402
if value == 0 {
402403
return None
403404
}
@@ -409,14 +410,14 @@ macro_rules! impl_shift_amount {
409410
}
410411
impl_shift_amount! {
411412
// used by scalar types such as `i32` and `i64`
412-
(i32, 32, i16, i32),
413-
(i64, 64, i16, i64),
413+
(i32, i16, i32),
414+
(i64, i16, i64),
414415

415416
// used by SIMD types such as `i8x16`, `i16x8`, `i32x4` and `i64x2`
416-
(u8 , 8, u16, u32),
417-
(u16, 16, u16, u32),
418-
(u32, 32, u16, u32),
419-
(u64, 64, u16, u32),
417+
( u8, u16, u32),
418+
(u16, u16, u32),
419+
(u32, u16, u32),
420+
(u64, u16, u32),
420421
}
421422

422423
/// A 64-bit offset in Wasmi bytecode.

0 commit comments

Comments
 (0)