summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/insn_compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-03-02 23:21:28 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 23:28:59 -0800
commit34f2ab1f3c389e7d802128706008db2d8445fc3f (patch)
tree20e367c1a4d3c8813ef0f7ba28dc537778da1339 /lib/ruby_vm/mjit/insn_compiler.rb
parentd38069264918e7d0c5aff223414ba45dced92c66 (diff)
Optimize Integer#/
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib/ruby_vm/mjit/insn_compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index 625f01b13c..e68c68e3a9 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -1694,8 +1694,9 @@ module RubyVM::MJIT
asm.mov(:rax, Qfalse)
asm.mov(:rcx, Qtrue)
asm.cmovz(:rax, :rcx)
- asm.mov(ctx.stack_push, :rax)
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, :rax)
true
end
@@ -1738,13 +1739,11 @@ module RubyVM::MJIT
def jit_rb_int_mul(jit, ctx, asm, argc)
return false if argc != 1
return false unless two_fixnums_on_stack?(jit)
- asm.comment('rb_int_mul')
side_exit = side_exit(jit, ctx)
guard_two_fixnums(jit, ctx, asm, side_exit)
- jit_prepare_routine_call(jit, ctx, asm)
-
+ asm.comment('rb_int_mul')
y_opnd = ctx.stack_pop
x_opnd = ctx.stack_pop
asm.mov(C_ARGS[0], x_opnd)
@@ -1753,7 +1752,29 @@ module RubyVM::MJIT
ret_opnd = ctx.stack_push
asm.mov(ret_opnd, C_RET)
+ true
+ end
+
+ def jit_rb_int_div(jit, ctx, asm, argc)
+ return false if argc != 1
+ return false unless two_fixnums_on_stack?(jit)
+ side_exit = side_exit(jit, ctx)
+ guard_two_fixnums(jit, ctx, asm, side_exit)
+
+ asm.comment('rb_int_div')
+ y_opnd = ctx.stack_pop
+ x_opnd = ctx.stack_pop
+ asm.mov(:rax, y_opnd)
+ asm.cmp(:rax, C.to_value(0))
+ asm.je(side_exit)
+
+ asm.mov(C_ARGS[0], x_opnd)
+ asm.mov(C_ARGS[1], :rax)
+ asm.call(C.rb_fix_div_fix)
+
+ ret_opnd = ctx.stack_push
+ asm.mov(ret_opnd, C_RET)
true
end
@@ -1774,7 +1795,6 @@ module RubyVM::MJIT
ret_opnd = ctx.stack_push
asm.mov(ret_opnd, C_RET)
-
true
end
@@ -1789,6 +1809,7 @@ module RubyVM::MJIT
register_cfunc_method(Integer, :==, :jit_rb_int_equal)
register_cfunc_method(Integer, :===, :jit_rb_int_equal)
register_cfunc_method(Integer, :*, :jit_rb_int_mul)
+ register_cfunc_method(Integer, :/, :jit_rb_int_div)
register_cfunc_method(Array, :<<, :jit_rb_ary_push)
end