Skip to content

Commit

Permalink
Kill pow().
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Dec 20, 2023
1 parent ac7f75e commit 4f0e033
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ykrt/src/compile/jitc_yk/jit_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pub enum Operand {

impl Operand {
pub(crate) fn new(kind: OpKind, val: u64) -> Self {
if val < 2u64.pow(u32::try_from(SHORT_OPERAND_VALUE_SIZE).unwrap()) {
// check if the operand's value can fit in a short operand.
if val & (u64::MAX << SHORT_OPERAND_VALUE_SIZE) == 0 {
Self::Short(ShortOperand::new(kind, val))
} else {
todo!()
Expand Down Expand Up @@ -418,4 +419,17 @@ mod tests {
debug_assert_eq!(inst.operand(1), Operand::Short(ShortOperand(0)));
debug_assert_eq!(inst.operand(2), Operand::Short(ShortOperand(0x3ffff)));
}

#[test]
fn does_fit_short_operand() {
for i in 0..SHORT_OPERAND_VALUE_SIZE {
Operand::new(OpKind::Local, 1 << i);
}
}

#[test]
#[should_panic]
fn doesnt_fit_short_operand() {
Operand::new(OpKind::Local, 1 << SHORT_OPERAND_VALUE_SIZE);
}
}

0 comments on commit 4f0e033

Please sign in to comment.