Skip to content

Commit

Permalink
Merge pull request ruby#116 from Shopify/opt-mult
Browse files Browse the repository at this point in the history
Implement opt_{mult,div}
  • Loading branch information
maximecb committed Jul 7, 2021
2 parents 6ed39d5 + 991e4d5 commit cfe5d2c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
20 changes: 20 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ def mod(a, b)
mod(7, 5)
}

# Test for opt_mult
assert_equal '12', %q{
def mult(a, b)
a * b
end
mult(6, 2)
mult(6, 2)
}

# Test for opt_div
assert_equal '3', %q{
def div(a, b)
a / b
end
div(6, 2)
div(6, 2)
}

# BOP redefined methods work when JIT compiled
assert_equal 'false', %q{
def less_than x
Expand Down
18 changes: 17 additions & 1 deletion yjit_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ gen_opt_aset(jitstate_t *jit, ctx_t *ctx)
x86opnd_t arg1 = ctx_stack_pop(ctx, 1);
x86opnd_t arg0 = ctx_stack_pop(ctx, 1);

// Call rb_vm_opt_mod(VALUE recv, VALUE obj)
// Call rb_vm_opt_aset(VALUE recv, VALUE obj)
yjit_save_regs(cb);
mov(cb, C_ARG_REGS[0], arg0);
mov(cb, C_ARG_REGS[1], arg1);
Expand Down Expand Up @@ -1931,6 +1931,20 @@ gen_opt_plus(jitstate_t* jit, ctx_t* ctx)
return YJIT_KEEP_COMPILING;
}

static codegen_status_t
gen_opt_mult(jitstate_t* jit, ctx_t* ctx)
{
// Delegate to send, call the method on the recv
return gen_opt_send_without_block(jit, ctx);
}

static codegen_status_t
gen_opt_div(jitstate_t* jit, ctx_t* ctx)
{
// Delegate to send, call the method on the recv
return gen_opt_send_without_block(jit, ctx);
}

VALUE rb_vm_opt_mod(VALUE recv, VALUE obj);

static codegen_status_t
Expand Down Expand Up @@ -3460,6 +3474,8 @@ yjit_init_codegen(void)
yjit_reg_op(BIN(opt_or), gen_opt_or);
yjit_reg_op(BIN(opt_minus), gen_opt_minus);
yjit_reg_op(BIN(opt_plus), gen_opt_plus);
yjit_reg_op(BIN(opt_mult), gen_opt_mult);
yjit_reg_op(BIN(opt_div), gen_opt_div);
yjit_reg_op(BIN(opt_mod), gen_opt_mod);
yjit_reg_op(BIN(opt_ltlt), gen_opt_ltlt);
yjit_reg_op(BIN(opt_nil_p), gen_opt_nil_p);
Expand Down

0 comments on commit cfe5d2c

Please sign in to comment.