Skip to content

Commit

Permalink
Make short operand value size check more comprehensible.
Browse files Browse the repository at this point in the history
As requested here:
ykjit#930 (comment)
  • Loading branch information
vext01 committed Jan 9, 2024
1 parent 26790c5 commit d9e9cce
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ykrt/src/compile/jitc_yk/jit_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SHORT_OPERAND_SIZE: u64 = 18;
const SHORT_OPERAND_KIND_SIZE: u64 = 3;
const SHORT_OPERAND_KIND_MASK: u64 = 7;
const SHORT_OPERAND_VALUE_SIZE: u64 = 15;
const SHORT_OPERAND_MAX_VALUE: u64 = !(u64::MAX << SHORT_OPERAND_VALUE_SIZE);
const SHORT_OPERAND_MASK: u64 = 0x3ffff;
/// Bit fiddling for instructions.
const INSTR_ISSHORT_SIZE: u64 = 1;
Expand Down Expand Up @@ -95,7 +96,7 @@ pub enum Operand {
impl Operand {
pub(crate) fn new(kind: OpKind, val: u64) -> Self {
// check if the operand's value can fit in a short operand.
if val & (u64::MAX << SHORT_OPERAND_VALUE_SIZE) == 0 {
if val <= SHORT_OPERAND_MAX_VALUE {
Self::Short(ShortOperand::new(kind, val))
} else {
todo!()
Expand Down

0 comments on commit d9e9cce

Please sign in to comment.