Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions zjit/src/backend/lir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,15 @@ impl Opnd
}
}

/// Return Some(Opnd) with a given num_bits if self has num_bits.
/// None if self doesn't have a num_bits field.
pub fn try_num_bits(&self, num_bits: u8) -> Option<Opnd> {
assert!(num_bits == 8 || num_bits == 16 || num_bits == 32 || num_bits == 64);
match *self {
Opnd::Reg(reg) => Some(Opnd::Reg(reg.with_num_bits(num_bits))),
Opnd::Mem(Mem { base, disp, .. }) => Some(Opnd::Mem(Mem { base, disp, num_bits })),
Opnd::VReg { idx, .. } => Some(Opnd::VReg { idx, num_bits }),
_ => None,
}
}

/// Return Opnd with a given num_bits if self has num_bits.
/// Panic otherwise. This should be used only when you know which Opnd self is.
/// Return Opnd with a given num_bits if self has num_bits. Panic otherwise.
#[track_caller]
pub fn with_num_bits(&self, num_bits: u8) -> Opnd {
if let Some(opnd) = self.try_num_bits(num_bits) {
opnd
} else {
unreachable!("with_num_bits should not be used on: {self:?}");
assert!(num_bits == 8 || num_bits == 16 || num_bits == 32 || num_bits == 64);
match *self {
Opnd::Reg(reg) => Opnd::Reg(reg.with_num_bits(num_bits)),
Opnd::Mem(Mem { base, disp, .. }) => Opnd::Mem(Mem { base, disp, num_bits }),
Opnd::VReg { idx, .. } => Opnd::VReg { idx, num_bits },
_ => unreachable!("with_num_bits should not be used for: {self:?}"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,8 @@ fn gen_guard_type(jit: &mut JITState, asm: &mut Assembler, val: lir::Opnd, guard
asm.jne(side_exit(jit, state, GuardType(guard_type)));
} else if guard_type.is_subtype(types::StaticSymbol) {
// Static symbols have (val & 0xff) == RUBY_SYMBOL_FLAG
// Use 8-bit comparison like YJIT does
debug_assert!(val.try_num_bits(8).is_some(), "GuardType should not be used for a known constant, but val was: {val:?}");
// Use 8-bit comparison like YJIT does. GuardType should not be used
// for a known VALUE, which with_num_bits() does not support.
asm.cmp(val.with_num_bits(8), Opnd::UImm(RUBY_SYMBOL_FLAG as u64));
asm.jne(side_exit(jit, state, GuardType(guard_type)));
} else if guard_type.is_subtype(types::NilClass) {
Expand Down
Loading