Skip to content

Commit

Permalink
Port gen_checktype to the new IR assembler backend (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
fresh-eggs authored and k0kubun committed Aug 25, 2022
1 parent a2bbf82 commit df5c10c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
8 changes: 8 additions & 0 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def foo()
foo()
}

# checktype
assert_equal 'false', %q{
def function()
[1, 2] in [Integer, String]
end
function()
}




Expand Down
39 changes: 17 additions & 22 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,11 +2217,10 @@ fn gen_defined(
KeepCompiling
}

/*
fn gen_checktype(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let type_val = jit_get_arg(jit, 0).as_u32();
Expand All @@ -2235,49 +2234,45 @@ fn gen_checktype(
match val_type.known_value_type() {
Some(value_type) => {
if value_type == type_val {
jit_putobject(jit, ctx, cb, Qtrue);
jit_putobject(jit, ctx, asm, Qtrue);
return KeepCompiling;
} else {
jit_putobject(jit, ctx, cb, Qfalse);
jit_putobject(jit, ctx, asm, Qfalse);
return KeepCompiling;
}
},
_ => (),
}

mov(cb, REG0, val);
mov(cb, REG1, uimm_opnd(Qfalse.as_u64()));
let ret = cb.new_label("ret".to_string());
let ret = asm.new_label("ret");

if !val_type.is_heap() {
// if (SPECIAL_CONST_P(val)) {
// Return Qfalse via REG1 if not on heap
test(cb, REG0, uimm_opnd(RUBY_IMMEDIATE_MASK as u64));
jnz_label(cb, ret);
cmp(cb, REG0, uimm_opnd(Qnil.as_u64()));
jbe_label(cb, ret);
asm.test(val, Opnd::UImm(RUBY_IMMEDIATE_MASK as u64));
asm.jnz(ret);
asm.cmp(val, Opnd::UImm(Qnil.into()));
asm.jbe(ret);
}

// Check type on object
mov(cb, REG0, mem_opnd(64, REG0, RUBY_OFFSET_RBASIC_FLAGS));
and(cb, REG0, uimm_opnd(RUBY_T_MASK as u64));
cmp(cb, REG0, uimm_opnd(type_val as u64));
mov(cb, REG0, uimm_opnd(Qtrue.as_u64()));
// REG1 contains Qfalse from above
cmove(cb, REG1, REG0);
let object_type = asm.and(
Opnd::mem(64, val, RUBY_OFFSET_RBASIC_FLAGS),
Opnd::UImm(RUBY_T_MASK.into()));
asm.cmp(object_type, Opnd::UImm(type_val.into()));
let ret_opnd = asm.csel_e(Opnd::UImm(Qfalse.into()), Opnd::UImm(Qtrue.into()));

cb.write_label(ret);
asm.write_label(ret);
let stack_ret = ctx.stack_push(Type::UnknownImm);
mov(cb, stack_ret, REG1);
cb.link_labels();
asm.mov(stack_ret, ret_opnd);

KeepCompiling
} else {
CantCompile
}
}

/*
fn gen_concatstrings(
jit: &mut JITState,
ctx: &mut Context,
Expand Down Expand Up @@ -5979,7 +5974,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_duphash => Some(gen_duphash),
YARVINSN_newarray => Some(gen_newarray),
YARVINSN_duparray => Some(gen_duparray),
//YARVINSN_checktype => Some(gen_checktype),
YARVINSN_checktype => Some(gen_checktype),
YARVINSN_opt_lt => Some(gen_opt_lt),
/*
YARVINSN_opt_le => Some(gen_opt_le),
Expand Down

0 comments on commit df5c10c

Please sign in to comment.