diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-02 22:52:32 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-05 23:28:59 -0800 |
| commit | 2ecf77ce205d9732c8c1fcfbf031835c4d53ebbd (patch) | |
| tree | b0d704d7e637c2ed6aceb7ffe9d921775e5a69d5 /lib | |
| parent | 92efd0569a1da349f8bc7f8214e3a780fd0c575a (diff) | |
Optimize Integer#===
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby_vm/mjit/insn_compiler.rb | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index 42f95cee1e..6141b6de8d 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -1686,7 +1686,7 @@ module RubyVM::MJIT # @param asm [RubyVM::MJIT::Assembler] def jit_rb_obj_not(jit, ctx, asm, argc) return false if argc != 0 - asm.comment('jit_rb_obj_not') + asm.comment('rb_obj_not') recv = ctx.stack_pop # This `test` sets ZF only for Qnil and Qfalse, which let cmovz set. @@ -1702,10 +1702,35 @@ module RubyVM::MJIT # @param jit [RubyVM::MJIT::JITState] # @param ctx [RubyVM::MJIT::Context] # @param asm [RubyVM::MJIT::Assembler] + def jit_rb_int_equal(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) + + # Compare the arguments + asm.comment('rb_int_equal') + arg1 = ctx.stack_pop(1) + arg0 = ctx.stack_pop(1) + asm.mov(:rax, arg1) + asm.cmp(arg0, :rax) + asm.mov(:rax, Qfalse) + asm.mov(:rcx, Qtrue) + asm.cmove(:rax, :rcx) + + stack_ret = ctx.stack_push + asm.mov(stack_ret, :rax) + true + end + + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::Assembler] def jit_rb_int_mul(jit, ctx, asm, argc) return false if argc != 1 return false unless two_fixnums_on_stack?(jit) - asm.comment('jit_rb_int_mul') + asm.comment('rb_int_mul') side_exit = side_exit(jit, ctx) guard_two_fixnums(jit, ctx, asm, side_exit) @@ -1730,6 +1755,9 @@ module RubyVM::MJIT def register_cfunc_codegen_funcs register_cfunc_method(BasicObject, :!, :jit_rb_obj_not) + + register_cfunc_method(Integer, :==, :jit_rb_int_equal) + register_cfunc_method(Integer, :===, :jit_rb_int_equal) register_cfunc_method(Integer, :*, :jit_rb_int_mul) end |
