diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 966a5f3002..d82f3de95e 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -3066,3 +3066,11 @@ assert_equal '10', %q{ a.length } + +# checktype +assert_equal 'false', %q{ + def function() + [1, 2] in [Integer, String] + end + function() +} diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index cb4b23e26e..b34cc7409a 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -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(); @@ -2235,42 +2234,37 @@ 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 { @@ -2278,6 +2272,7 @@ fn gen_checktype( } } +/* fn gen_concatstrings( jit: &mut JITState, ctx: &mut Context, @@ -5979,7 +5974,7 @@ fn get_gen_fn(opcode: VALUE) -> Option { 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),