Skip to content

Commit

Permalink
Port opt_mod to the new backend IR (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Aug 26, 2022
1 parent d9806c5 commit 1d92fa4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
46 changes: 30 additions & 16 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,42 @@ def foo(n)
}

# opt_lt
assert_equal 'true', %q{1 < 2}
assert_equal 'false', %q{1 < 1}
assert_equal 'true', %q{"1" < "2"}
assert_equal 'false', %q{"1" < "1"}
assert_equal 'true', %q{def foo = 1 < 2; foo}
assert_equal 'false', %q{def foo = 1 < 1; foo}
assert_equal 'true', %q{def foo = "1" < "2"; foo}
assert_equal 'false', %q{def foo = "1" < "1"; foo}

# opt_le
assert_equal 'true', %q{1 <= 1}
assert_equal 'false', %q{1 <= 0}
assert_equal 'true', %q{"1" <= "1"}
assert_equal 'false', %q{"1" <= "0"}
assert_equal 'true', %q{def foo = 1 <= 1; foo}
assert_equal 'false', %q{def foo = 1 <= 0; foo}
assert_equal 'true', %q{def foo = "1" <= "1"; foo}
assert_equal 'false', %q{def foo = "1" <= "0"; foo}

# opt_ge
assert_equal 'true', %q{1 >= 1}
assert_equal 'false', %q{0 >= 1}
assert_equal 'true', %q{"1" >= "1"}
assert_equal 'false', %q{"0" >= "1"}
assert_equal 'true', %q{def foo = 1 >= 1; foo}
assert_equal 'false', %q{def foo = 0 >= 1; foo}
assert_equal 'true', %q{def foo = "1" >= "1"; foo}
assert_equal 'false', %q{def foo = "0" >= "1"; foo}

# opt_gt
assert_equal 'true', %q{2 > 1}
assert_equal 'false', %q{1 > 1}
assert_equal 'true', %q{"2" > "1"}
assert_equal 'false', %q{"1" > "1"}
assert_equal 'true', %q{def foo = 2 > 1; foo}
assert_equal 'false', %q{def foo = 1 > 1; foo}
assert_equal 'true', %q{def foo = "2" > "1"; foo}
assert_equal 'false', %q{def foo = "1" > "1"; foo}

# opt_mod
assert_equal '1', %q{
def foo
5 % 2
end
foo
}
assert_equal '01', %q{
def foo
"%02d" % 1
end
foo
}

# opt_mult
assert_equal '6', %q{
Expand Down
27 changes: 10 additions & 17 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2971,16 +2971,15 @@ fn gen_opt_div(
gen_opt_send_without_block(jit, ctx, asm, ocb)
}

/*
fn gen_opt_mod(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
) -> CodegenStatus {
// Defer compilation so we can specialize on a runtime `self`
if !jit_at_current_insn(jit) {
defer_compilation(jit, ctx, cb, ocb);
defer_compilation(jit, ctx, asm, ocb);
return EndBlock;
}

Expand All @@ -2997,33 +2996,29 @@ fn gen_opt_mod(
}

// Check that both operands are fixnums
guard_two_fixnums(ctx, cb, side_exit);
guard_two_fixnums(ctx, asm, side_exit);

// Get the operands and destination from the stack
let arg1 = ctx.stack_pop(1);
let arg0 = ctx.stack_pop(1);

mov(cb, C_ARG_REGS[0], arg0);
mov(cb, C_ARG_REGS[1], arg1);
// Check for arg0 % 0
cmp(cb, C_ARG_REGS[1], imm_opnd(VALUE::fixnum_from_usize(0).as_i64()));
je_ptr(cb, side_exit);
asm.cmp(arg1, Opnd::Imm(VALUE::fixnum_from_usize(0).as_i64()));
asm.je(side_exit.into());

// Call rb_fix_mod_fix(VALUE recv, VALUE obj)
call_ptr(cb, REG0, rb_fix_mod_fix as *const u8);
let ret = asm.ccall(rb_fix_mod_fix as *const u8, vec![arg0, arg1]);

// Push the return value onto the stack
let stack_ret = ctx.stack_push(Type::Unknown);
mov(cb, stack_ret, RAX);
asm.mov(stack_ret, ret);

KeepCompiling
} else {
// Delegate to send, call the method on the recv
gen_opt_send_without_block(jit, ctx, cb, ocb)
gen_opt_send_without_block(jit, ctx, asm, ocb)
}
}
*/

fn gen_opt_ltlt(
jit: &mut JITState,
Expand Down Expand Up @@ -5976,11 +5971,9 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_opt_le => Some(gen_opt_le),
YARVINSN_opt_gt => Some(gen_opt_gt),
YARVINSN_opt_ge => Some(gen_opt_ge),
/*
YARVINSN_opt_mod => Some(gen_opt_mod),
YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
*/
//YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
//YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
YARVINSN_splatarray => Some(gen_splatarray),
YARVINSN_newrange => Some(gen_newrange),
YARVINSN_putstring => Some(gen_putstring),
Expand Down

0 comments on commit 1d92fa4

Please sign in to comment.