Skip to content

Commit da01faa

Browse files
authored
ZJIT: Remove try_num_bits (#14272)
1 parent 3ff1ca0 commit da01faa

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

zjit/src/backend/lir.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,15 @@ impl Opnd
147147
}
148148
}
149149

150-
/// Return Some(Opnd) with a given num_bits if self has num_bits.
151-
/// None if self doesn't have a num_bits field.
152-
pub fn try_num_bits(&self, num_bits: u8) -> Option<Opnd> {
153-
assert!(num_bits == 8 || num_bits == 16 || num_bits == 32 || num_bits == 64);
154-
match *self {
155-
Opnd::Reg(reg) => Some(Opnd::Reg(reg.with_num_bits(num_bits))),
156-
Opnd::Mem(Mem { base, disp, .. }) => Some(Opnd::Mem(Mem { base, disp, num_bits })),
157-
Opnd::VReg { idx, .. } => Some(Opnd::VReg { idx, num_bits }),
158-
_ => None,
159-
}
160-
}
161-
162-
/// Return Opnd with a given num_bits if self has num_bits.
163-
/// Panic otherwise. This should be used only when you know which Opnd self is.
150+
/// Return Opnd with a given num_bits if self has num_bits. Panic otherwise.
164151
#[track_caller]
165152
pub fn with_num_bits(&self, num_bits: u8) -> Opnd {
166-
if let Some(opnd) = self.try_num_bits(num_bits) {
167-
opnd
168-
} else {
169-
unreachable!("with_num_bits should not be used on: {self:?}");
153+
assert!(num_bits == 8 || num_bits == 16 || num_bits == 32 || num_bits == 64);
154+
match *self {
155+
Opnd::Reg(reg) => Opnd::Reg(reg.with_num_bits(num_bits)),
156+
Opnd::Mem(Mem { base, disp, .. }) => Opnd::Mem(Mem { base, disp, num_bits }),
157+
Opnd::VReg { idx, .. } => Opnd::VReg { idx, num_bits },
158+
_ => unreachable!("with_num_bits should not be used for: {self:?}"),
170159
}
171160
}
172161

zjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,8 @@ fn gen_guard_type(jit: &mut JITState, asm: &mut Assembler, val: lir::Opnd, guard
11831183
asm.jne(side_exit(jit, state, GuardType(guard_type)));
11841184
} else if guard_type.is_subtype(types::StaticSymbol) {
11851185
// Static symbols have (val & 0xff) == RUBY_SYMBOL_FLAG
1186-
// Use 8-bit comparison like YJIT does
1187-
debug_assert!(val.try_num_bits(8).is_some(), "GuardType should not be used for a known constant, but val was: {val:?}");
1186+
// Use 8-bit comparison like YJIT does. GuardType should not be used
1187+
// for a known VALUE, which with_num_bits() does not support.
11881188
asm.cmp(val.with_num_bits(8), Opnd::UImm(RUBY_SYMBOL_FLAG as u64));
11891189
asm.jne(side_exit(jit, state, GuardType(guard_type)));
11901190
} else if guard_type.is_subtype(types::NilClass) {

0 commit comments

Comments
 (0)