diff --git a/lib/cretonne/meta/isa/riscv/recipes.py b/lib/cretonne/meta/isa/riscv/recipes.py index afffb2c0aa..87dce643eb 100644 --- a/lib/cretonne/meta/isa/riscv/recipes.py +++ b/lib/cretonne/meta/isa/riscv/recipes.py @@ -171,8 +171,8 @@ U = EncRecipe( UJ = EncRecipe( 'UJ', Jump, size=4, ins=(), outs=(), branch_range=(0, 21), emit=''' - let dest = func.offsets[destination] as i64; - let disp = dest - sink.offset() as i64; + let dest = i64::from(func.offsets[destination]); + let disp = dest - i64::from(sink.offset()); put_uj(bits, disp, 0, sink); ''') @@ -190,8 +190,8 @@ SB = EncRecipe( ins=(GPR, GPR), outs=(), branch_range=(0, 13), emit=''' - let dest = func.offsets[destination] as i64; - let disp = dest - sink.offset() as i64; + let dest = i64::from(func.offsets[destination]); + let disp = dest - i64::from(sink.offset()); put_sb(bits, disp, in_reg0, in_reg1, sink); ''') @@ -201,8 +201,8 @@ SBzero = EncRecipe( ins=(GPR), outs=(), branch_range=(0, 13), emit=''' - let dest = func.offsets[destination] as i64; - let disp = dest - sink.offset() as i64; + let dest = i64::from(func.offsets[destination]); + let disp = dest - i64::from(sink.offset()); put_sb(bits, disp, in_reg0, 0, sink); ''') diff --git a/lib/cretonne/src/ir/immediates.rs b/lib/cretonne/src/ir/immediates.rs index 72763c558e..2ab486f864 100644 --- a/lib/cretonne/src/ir/immediates.rs +++ b/lib/cretonne/src/ir/immediates.rs @@ -87,7 +87,7 @@ fn parse_i64(s: &str) -> Result { return Err("Too many hexadecimal digits"); } // This can't overflow given the digit limit. - value = (value << 4) | digit as u64; + value = (value << 4) | u64::from(digit); } None => { // Allow embedded underscores, but fail on anything else. @@ -107,7 +107,7 @@ fn parse_i64(s: &str) -> Result { None => return Err("Too large decimal number"), Some(v) => value = v, } - match value.checked_add(digit as u64) { + match value.checked_add(u64::from(digit)) { None => return Err("Too large decimal number"), Some(v) => value = v, } @@ -221,7 +221,7 @@ impl Into for Offset32 { impl Into for Offset32 { fn into(self) -> i64 { - self.0 as i64 + i64::from(self.0) } } @@ -241,7 +241,7 @@ impl Display for Offset32 { // Always include a sign. write!(f, "{}", if self.0 < 0 { '-' } else { '+' })?; - let val = (self.0 as i64).abs(); + let val = i64::from(self.0).abs(); if val < 10_000 { write!(f, "{}", val) } else { @@ -259,7 +259,9 @@ impl FromStr for Offset32 { if !(s.starts_with('-') || s.starts_with('+')) { return Err("Offset must begin with sign"); } - parse_i64(s).and_then(|x| if i32::MIN as i64 <= x && x <= i32::MAX as i64 { + parse_i64(s).and_then(|x| if i64::from(i32::MIN) as i64 <= x && + x <= i64::from(i32::MAX) + { Ok(Offset32::new(x as i32)) } else { Err("Offset out of range") @@ -288,7 +290,7 @@ impl Into for Uoffset32 { impl Into for Uoffset32 { fn into(self) -> i64 { - self.0 as i64 + i64::from(self.0) } } @@ -310,7 +312,7 @@ impl Display for Uoffset32 { write!(f, "+{}", self.0) } else { write!(f, "+")?; - write_hex(self.0 as i64, f) + write_hex(i64::from(self.0), f) } } @@ -324,7 +326,7 @@ impl FromStr for Uoffset32 { if !s.starts_with('+') { return Err("Unsigned offset must begin with '+' sign"); } - parse_i64(s).and_then(|x| if 0 <= x && x <= u32::MAX as i64 { + parse_i64(s).and_then(|x| if 0 <= x && x <= i64::from(u32::MAX) { Ok(Uoffset32::new(x as u32)) } else { Err("Offset out of range") @@ -386,7 +388,13 @@ fn format_float(bits: u64, w: u8, t: u8, f: &mut Formatter) -> fmt::Result { write!(f, "0.0") } else { // Subnormal. - write!(f, "0x0.{0:01$x}p{2}", left_t_bits, digits as usize, emin) + write!( + f, + "0x0.{0:01$x}p{2}", + left_t_bits, + usize::from(digits), + emin + ) } } else if e_bits == max_e_bits { // Always print a `+` or `-` sign for these special values. @@ -414,7 +422,7 @@ fn format_float(bits: u64, w: u8, t: u8, f: &mut Formatter) -> fmt::Result { } } else { // Normal number. - write!(f, "0x1.{0:01$x}p{2}", left_t_bits, digits as usize, e) + write!(f, "0x1.{0:01$x}p{2}", left_t_bits, usize::from(digits), e) } } @@ -511,7 +519,7 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result { if digits > 16 { return Err("Too many digits"); } - significand = (significand << 4) | digit as u64; + significand = (significand << 4) | u64::from(digit); } None => return Err("Invalid character"), } @@ -596,7 +604,7 @@ impl Ieee32 { impl Display for Ieee32 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let bits: u32 = self.0; - format_float(bits as u64, 8, 23, f) + format_float(u64::from(bits), 8, 23, f) } } diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index 19ef8efa29..b37646afbf 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -463,7 +463,7 @@ impl OpcodeConstraints { /// Get the offset into `TYPE_SETS` for the controlling type variable. /// Returns `None` if the instruction is not polymorphic. fn typeset_offset(self) -> Option { - let offset = self.typeset_offset as usize; + let offset = usize::from(self.typeset_offset); if offset < TYPE_SETS.len() { Some(offset) } else { diff --git a/lib/cretonne/src/ir/types.rs b/lib/cretonne/src/ir/types.rs index 275ec70c9b..5b6f0fe7fb 100644 --- a/lib/cretonne/src/ir/types.rs +++ b/lib/cretonne/src/ir/types.rs @@ -194,12 +194,12 @@ impl Type { /// Get the total number of bits used to represent this type. pub fn bits(self) -> u16 { - self.lane_bits() as u16 * self.lane_count() + u16::from(self.lane_bits()) * self.lane_count() } /// Get the number of bytes used to store this type in memory. pub fn bytes(self) -> u32 { - (self.bits() as u32 + 7) / 8 + (u32::from(self.bits()) + 7) / 8 } /// Get a SIMD vector type with `n` times more lanes than this one. @@ -213,7 +213,7 @@ impl Type { return None; } let log2_lanes: u32 = n.trailing_zeros(); - let new_type = self.0 as u32 + (log2_lanes << 4); + let new_type = u32::from(self.0) + (log2_lanes << 4); if new_type < 0x90 { Some(Type(new_type as u8)) } else { @@ -234,7 +234,7 @@ impl Type { /// Index of this type, for use with hash tables etc. pub fn index(self) -> usize { - self.0 as usize + usize::from(self.0) } /// True iff: diff --git a/lib/cretonne/src/isa/constraints.rs b/lib/cretonne/src/isa/constraints.rs index e38b044535..c5f1d4bd16 100644 --- a/lib/cretonne/src/isa/constraints.rs +++ b/lib/cretonne/src/isa/constraints.rs @@ -105,7 +105,7 @@ impl BranchRange { /// /// This method does not detect if the range is larger than 2 GB. pub fn contains(self, branch: CodeOffset, dest: CodeOffset) -> bool { - let d = dest.wrapping_sub(branch + self.origin as CodeOffset) as i32; + let d = dest.wrapping_sub(branch + CodeOffset::from(self.origin)) as i32; let s = 32 - self.bits; d == d << s >> s } diff --git a/lib/cretonne/src/isa/encoding.rs b/lib/cretonne/src/isa/encoding.rs index cfb429ba1e..b82137a6b8 100644 --- a/lib/cretonne/src/isa/encoding.rs +++ b/lib/cretonne/src/isa/encoding.rs @@ -124,7 +124,7 @@ impl EncInfo { pub fn bytes(&self, enc: Encoding) -> CodeOffset { self.sizing .get(enc.recipe()) - .map(|s| s.bytes as CodeOffset) + .map(|s| CodeOffset::from(s.bytes)) .unwrap_or(0) } diff --git a/lib/cretonne/src/isa/intel/abi.rs b/lib/cretonne/src/isa/intel/abi.rs index 58ca657dc4..707d42b8d9 100644 --- a/lib/cretonne/src/isa/intel/abi.rs +++ b/lib/cretonne/src/isa/intel/abi.rs @@ -28,7 +28,7 @@ struct Args { impl Args { fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize) -> Args { Args { - pointer_bytes: bits as u32 / 8, + pointer_bytes: u32::from(bits) / 8, pointer_bits: bits, pointer_type: ir::Type::int(bits).unwrap(), gpr, diff --git a/lib/cretonne/src/isa/registers.rs b/lib/cretonne/src/isa/registers.rs index e156de331e..a43d5cfd62 100644 --- a/lib/cretonne/src/isa/registers.rs +++ b/lib/cretonne/src/isa/registers.rs @@ -174,7 +174,7 @@ impl RegClassData { /// Get a specific register unit in this class. pub fn unit(&self, offset: usize) -> RegUnit { - let uoffset = offset * self.width as usize; + let uoffset = offset * usize::from(self.width); self.first + uoffset as RegUnit } @@ -209,7 +209,7 @@ impl EntityRef for RegClassIndex { } fn index(self) -> usize { - self.0 as usize + usize::from(self.0) } } diff --git a/lib/cretonne/src/isa/riscv/abi.rs b/lib/cretonne/src/isa/riscv/abi.rs index f4ab75fde9..0859a53f31 100644 --- a/lib/cretonne/src/isa/riscv/abi.rs +++ b/lib/cretonne/src/isa/riscv/abi.rs @@ -26,7 +26,7 @@ impl Args { fn new(bits: u16, enable_e: bool) -> Args { Args { pointer_bits: bits, - pointer_bytes: bits as u32 / 8, + pointer_bytes: u32::from(bits) / 8, pointer_type: Type::int(bits).unwrap(), regs: 0, reg_limit: if enable_e { 6 } else { 8 }, diff --git a/lib/cretonne/src/regalloc/pressure.rs b/lib/cretonne/src/regalloc/pressure.rs index 7a4f1f715b..28cf15f48f 100644 --- a/lib/cretonne/src/regalloc/pressure.rs +++ b/lib/cretonne/src/regalloc/pressure.rs @@ -142,8 +142,8 @@ impl Pressure { /// /// This is the out-of-line slow path for `check_avail()`. fn check_avail_aliased(&self, entry: &TopRC) -> RegClassMask { - let first = entry.first_toprc as usize; - let num = entry.num_toprcs as usize; + let first = usize::from(entry.first_toprc); + let num = usize::from(entry.num_toprcs); let width = entry.width as u32; let ulimit = entry.limit * width; diff --git a/lib/cretonne/src/settings.rs b/lib/cretonne/src/settings.rs index 9738c422af..999d305439 100644 --- a/lib/cretonne/src/settings.rs +++ b/lib/cretonne/src/settings.rs @@ -212,7 +212,7 @@ pub mod detail { /// Get enumerators corresponding to a `Details::Enum`. pub fn enums(&self, last: u8, enumerators: u16) -> &[&'static str] { let from = enumerators as usize; - let len = last as usize + 1; + let len = usize::from(last) + 1; &self.enumerators[from..from + len] } @@ -230,7 +230,7 @@ pub mod detail { Detail::Enum { last, enumerators } => { if byte <= last { let tags = self.enums(last, enumerators); - write!(f, "\"{}\"", tags[byte as usize]) + write!(f, "\"{}\"", tags[usize::from(byte)]) } else { write!(f, "{}", byte) } diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index d35ee6bcb4..259d462298 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -1115,7 +1115,7 @@ impl<'a> Parser<'a> { if bytes < 0 { return err!(self.loc, "negative stack slot size"); } - if bytes > u32::MAX as i64 { + if bytes > i64::from(u32::MAX) { return err!(self.loc, "stack slot too large"); } let mut data = StackSlotData::new(kind, bytes as u32);