diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2023-04-18 13:53:37 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2023-04-18 17:16:22 -0700 |
commit | bdffcd6df30d7f21cf1a3a174672e82074800451 (patch) | |
tree | 21e7fc3a34f6dc3c8bc1198de32dfa036d23a665 | |
parent | b816ea87725d85b0b9cf9628603245041a2d5123 (diff) | |
download | ruby-bdffcd6df30d7f21cf1a3a174672e82074800451.tar.gz |
Update RJIT to support newarray_send
This also adds max / hash support
-rw-r--r-- | lib/ruby_vm/rjit/insn_compiler.rb | 69 | ||||
-rw-r--r-- | rjit_c.c | 2 | ||||
-rw-r--r-- | rjit_c.rb | 8 | ||||
-rwxr-xr-x | tool/rjit/bindgen.rb | 2 |
4 files changed, 78 insertions, 3 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb index 1788b20c3a..f9debaa40b 100644 --- a/lib/ruby_vm/rjit/insn_compiler.rb +++ b/lib/ruby_vm/rjit/insn_compiler.rb @@ -91,8 +91,7 @@ module RubyVM::RJIT when :opt_str_freeze then opt_str_freeze(jit, ctx, asm) when :opt_nil_p then opt_nil_p(jit, ctx, asm) # opt_str_uminus - # opt_newarray_max - when :opt_newarray_min then opt_newarray_min(jit, ctx, asm) + when :opt_newarray_send then opt_newarray_send(jit, ctx, asm) when :invokesuper then invokesuper(jit, ctx, asm) when :invokeblock then invokeblock(jit, ctx, asm) when :leave then leave(jit, ctx, asm) @@ -1510,7 +1509,21 @@ module RubyVM::RJIT end # opt_str_uminus - # opt_newarray_max + + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] + def opt_newarray_send(jit, ctx, asm) + type = C.ID2SYM jit.operand(1) + + case type + when :min then opt_newarray_min(jit, ctx, asm) + when :max then opt_newarray_max(jit, ctx, asm) + when :hash then opt_newarray_hash(jit, ctx, asm) + else + return CantCompile + end + end # @param jit [RubyVM::RJIT::JITState] # @param ctx [RubyVM::RJIT::Context] @@ -1540,6 +1553,56 @@ module RubyVM::RJIT # @param jit [RubyVM::RJIT::JITState] # @param ctx [RubyVM::RJIT::Context] # @param asm [RubyVM::RJIT::Assembler] + def opt_newarray_max(jit, ctx, asm) + num = jit.operand(0) + + # Save the PC and SP because we may allocate + jit_prepare_routine_call(jit, ctx, asm) + + offset_magnitude = C.VALUE.size * num + values_opnd = ctx.sp_opnd(-offset_magnitude) + asm.lea(:rax, values_opnd) + + asm.mov(C_ARGS[0], EC) + asm.mov(C_ARGS[1], num) + asm.mov(C_ARGS[2], :rax) + asm.call(C.rb_vm_opt_newarray_max) + + ctx.stack_pop(num) + stack_ret = ctx.stack_push(Type::Unknown) + asm.mov(stack_ret, C_RET) + + KeepCompiling + end + + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] + def opt_newarray_hash(jit, ctx, asm) + num = jit.operand(0) + + # Save the PC and SP because we may allocate + jit_prepare_routine_call(jit, ctx, asm) + + offset_magnitude = C.VALUE.size * num + values_opnd = ctx.sp_opnd(-offset_magnitude) + asm.lea(:rax, values_opnd) + + asm.mov(C_ARGS[0], EC) + asm.mov(C_ARGS[1], num) + asm.mov(C_ARGS[2], :rax) + asm.call(C.rb_vm_opt_newarray_hash) + + ctx.stack_pop(num) + stack_ret = ctx.stack_push(Type::Unknown) + asm.mov(stack_ret, C_RET) + + KeepCompiling + end + + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] def invokesuper(jit, ctx, asm) cd = C.rb_call_data.new(jit.operand(0)) block = jit.operand(1) @@ -517,6 +517,8 @@ extern VALUE rb_vm_concat_array(VALUE ary1, VALUE ary2st); extern VALUE rb_vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, VALUE allow_nil); extern VALUE rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic); extern VALUE rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr); +extern VALUE rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr); +extern VALUE rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr); extern VALUE rb_vm_splat_array(VALUE flag, VALUE array); extern bool rb_simple_iseq_p(const rb_iseq_t *iseq); extern bool rb_vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE v); @@ -724,6 +724,14 @@ module RubyVM::RJIT # :nodoc: all Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_ic_hit_p) } end + def C.rb_vm_opt_newarray_hash + Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_hash) } + end + + def C.rb_vm_opt_newarray_max + Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_max) } + end + def C.rb_vm_opt_newarray_min Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_min) } end diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb index 5c9fcfdf4e..1dd3b78bd5 100755 --- a/tool/rjit/bindgen.rb +++ b/tool/rjit/bindgen.rb @@ -539,6 +539,8 @@ generator = BindingGenerator.new( rb_vm_getclassvariable rb_vm_ic_hit_p rb_vm_opt_newarray_min + rb_vm_opt_newarray_max + rb_vm_opt_newarray_hash rb_vm_setinstancevariable rb_vm_splat_array rjit_full_cfunc_return |