summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-19 13:41:04 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-19 13:41:04 -0700
commit95c4ced39eb0d25925724456b222a56206b633db (patch)
tree6fae0c5498bfa99102b1b674ff92510a18e1c712
parentcd5a8d01605e2235fe6deaa4f60c212ffaeb4d04 (diff)
RJIT: Optimize Array#empty?
-rw-r--r--lib/ruby_vm/rjit/insn_compiler.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb
index 62b4f5c58f..58028d51ab 100644
--- a/lib/ruby_vm/rjit/insn_compiler.rb
+++ b/lib/ruby_vm/rjit/insn_compiler.rb
@@ -2908,6 +2908,25 @@ module RubyVM::RJIT
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
+ def jit_rb_ary_empty_p(jit, ctx, asm, argc, _known_recv_class)
+ array_reg = :rax
+ asm.mov(array_reg, ctx.stack_pop(1))
+ len_opnd = jit_array_len(asm, array_reg, :rcx)
+
+ asm.test(:rcx, :rcx)
+ asm.mov(:rax, Qfalse)
+ asm.mov(:rcx, Qtrue)
+ asm.cmovz(:rax, :rcx)
+
+ out_opnd = ctx.stack_push
+ asm.mov(out_opnd, :rax)
+
+ return true
+ end
+
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
def jit_rb_ary_push(jit, ctx, asm, argc, _known_recv_class)
return false if argc != 1
asm.comment('rb_ary_push')
@@ -2978,7 +2997,7 @@ module RubyVM::RJIT
register_cfunc_method(String, :+@, :jit_rb_str_uplus)
# rb_ary_empty_p() method in array.c
- #register_cfunc_method(Array, :empty?, :jit_rb_ary_empty_p)
+ register_cfunc_method(Array, :empty?, :jit_rb_ary_empty_p)
#register_cfunc_method(Kernel, :respond_to?, :jit_obj_respond_to)
#register_cfunc_method(Kernel, :block_given?, :jit_rb_f_block_given_p)