Skip to content

Commit

Permalink
Rename num_bits to bitw and de-pub the relevant attribute.
Browse files Browse the repository at this point in the history
This brings this part of the AOT IR in line with recent changes to the
JIT IR.
  • Loading branch information
ltratt committed Jan 22, 2025
1 parent e6a10cf commit a5034b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions ykrt/src/compile/jitc_yk/aot_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,29 +1591,29 @@ pub(crate) fn const_int_bytes_to_string(num_bits: u32, bytes: &[u8]) -> String {
#[deku_derive(DekuRead)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct IntegerTy {
pub(crate) num_bits: u32,
bitw: u32,
}

impl IntegerTy {
/// Create a new integer type with the specified number of bits.
#[cfg(test)]
pub(crate) fn new(num_bits: u32) -> Self {
debug_assert!(num_bits > 0 && num_bits <= 0x800000);
Self { num_bits }
pub(crate) fn new(bitw: u32) -> Self {
debug_assert!(bitw > 0 && bitw <= 0x800000);
Self { bitw }
}

/// Return the number of bits (1..2^23 (inc.)) this integer spans.
pub(crate) fn num_bits(&self) -> u32 {
debug_assert!(self.num_bits > 0 && self.num_bits <= 0x800000);
self.num_bits
pub(crate) fn bitw(&self) -> u32 {
debug_assert!(self.bitw > 0 && self.bitw <= 0x800000);
self.bitw
}

/// Return the number of bytes required to store this integer type.
///
/// Padding for alignment is not included.
#[cfg(test)]
pub(crate) fn byte_size(&self) -> usize {
let bits = self.num_bits();
let bits = self.bitw();
let mut ret = bits / 8;
// If it wasn't an exactly byte-sized thing, round up to the next byte.
if bits % 8 != 0 {
Expand All @@ -1624,13 +1624,13 @@ impl IntegerTy {

/// Format a constant integer value that is of the type described by `self`.
fn const_to_string(&self, c: &ConstVal) -> String {
const_int_bytes_to_string(self.num_bits, c.bytes())
const_int_bytes_to_string(self.bitw, c.bytes())
}
}

impl Display for IntegerTy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "i{}", self.num_bits)
write!(f, "i{}", self.bitw)
}
}

Expand Down Expand Up @@ -2022,7 +2022,7 @@ mod tests {
let bytes = ToBytes::to_ne_bytes(&num).as_ref().to_vec();

// Construct an IR constant and check it stringifies ok.
let it = IntegerTy { num_bits };
let it = IntegerTy { bitw: num_bits };
let c = ConstVal {
tyidx: TyIdx::new(0),
bytes,
Expand Down Expand Up @@ -2125,7 +2125,7 @@ mod tests {
let mut m = Module::default();

let i8_tyidx = TyIdx::new(m.types.len());
m.types.push(Ty::Integer(IntegerTy { num_bits: 8 }));
m.types.push(Ty::Integer(IntegerTy { bitw: 8 }));
let void_tyidx = TyIdx::new(m.types.len());
m.types.push(Ty::Void);

Expand Down
14 changes: 7 additions & 7 deletions ykrt/src/compile/jitc_yk/trace_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<Register: Send + Sync + 'static> TraceBuilder<Register> {
} = inst
{
let width_bits = match self.aot_mod.type_(*tyidx) {
aot_ir::Ty::Integer(it) => it.num_bits(),
aot_ir::Ty::Integer(x) => x.bitw(),
_ => unreachable!(),
};
let width_bytes = usize::try_from(width_bits.div_ceil(8)).unwrap();
Expand Down Expand Up @@ -347,10 +347,10 @@ impl<Register: Send + Sync + 'static> TraceBuilder<Register> {
let aot_const = aot_const.unwrap_val();
let bytes = aot_const.bytes();
match self.aot_mod.type_(aot_const.tyidx()) {
aot_ir::Ty::Integer(aot_ir::IntegerTy { num_bits }) => {
aot_ir::Ty::Integer(x) => {
// FIXME: It would be better if the AOT IR had converted these integers in advance
// rather than doing this dance here.
let x = match num_bits {
let v = match x.bitw() {
1 | 8 => {
debug_assert_eq!(bytes.len(), 1);
u64::from(bytes[0])
Expand All @@ -370,10 +370,10 @@ impl<Register: Send + Sync + 'static> TraceBuilder<Register> {
bytes[7],
])
}
_ => todo!("{}", num_bits),
_ => todo!("{}", x.bitw()),
};
let jit_tyidx = self.jit_mod.insert_ty(jit_ir::Ty::Integer(*num_bits))?;
Ok(jit_ir::Const::Int(jit_tyidx, x))
let jit_tyidx = self.jit_mod.insert_ty(jit_ir::Ty::Integer(x.bitw()))?;
Ok(jit_ir::Const::Int(jit_tyidx, v))
}
aot_ir::Ty::Float(fty) => {
let jit_tyidx = self.jit_mod.insert_ty(jit_ir::Ty::Float(fty.clone()))?;
Expand Down Expand Up @@ -422,7 +422,7 @@ impl<Register: Send + Sync + 'static> TraceBuilder<Register> {
fn handle_type(&mut self, aot_type: &aot_ir::Ty) -> Result<jit_ir::TyIdx, CompilationError> {
let jit_ty = match aot_type {
aot_ir::Ty::Void => jit_ir::Ty::Void,
aot_ir::Ty::Integer(it) => jit_ir::Ty::Integer(it.num_bits()),
aot_ir::Ty::Integer(x) => jit_ir::Ty::Integer(x.bitw()),
aot_ir::Ty::Ptr => jit_ir::Ty::Ptr,
aot_ir::Ty::Func(ft) => {
let mut jit_args = Vec::new();
Expand Down

0 comments on commit a5034b9

Please sign in to comment.