From 81e19b7d9988ced02c80a19ef2ec0f3b7cd8c456 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 18 Mar 2023 21:20:37 -0700 Subject: [PATCH] RJIT: Implement getglobal --- lib/ruby_vm/rjit/insn_compiler.rb | 24 +++++++++++++++++++++--- rjit_c.rb | 4 ++++ tool/rjit/bindgen.rb | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb index aff61afc65..326607d9c4 100644 --- a/lib/ruby_vm/rjit/insn_compiler.rb +++ b/lib/ruby_vm/rjit/insn_compiler.rb @@ -18,7 +18,7 @@ module RubyVM::RJIT asm.incr_counter(:rjit_insns_count) asm.comment("Insn: #{insn.name}") - # 78/102 + # 79/102 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -35,7 +35,7 @@ module RubyVM::RJIT when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm) when :getconstant then getconstant(jit, ctx, asm) # setconstant - # getglobal + when :getglobal then getglobal(jit, ctx, asm) # setglobal when :putnil then putnil(jit, ctx, asm) when :putself then putself(jit, ctx, asm) @@ -649,7 +649,25 @@ module RubyVM::RJIT end # setconstant - # getglobal + + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] + def getglobal(jit, ctx, asm) + gid = jit.operand(0) + + # Save the PC and SP because we might make a Ruby call for warning + jit_prepare_routine_call(jit, ctx, asm) + + asm.mov(C_ARGS[0], gid) + asm.call(C.rb_gvar_get) + + top = ctx.stack_push + asm.mov(top, C_RET) + + KeepCompiling + end + # setglobal # @param jit [RubyVM::RJIT::JITState] diff --git a/rjit_c.rb b/rjit_c.rb index 32731ba4d0..3b2072873f 100644 --- a/rjit_c.rb +++ b/rjit_c.rb @@ -505,6 +505,10 @@ module RubyVM::RJIT # :nodoc: all Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_get_symbol_id) } end + def C.rb_gvar_get + Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_gvar_get) } + end + def C.rb_hash_aref Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_hash_aref) } end diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb index ad2e5f9e1e..639031afe1 100755 --- a/tool/rjit/bindgen.rb +++ b/tool/rjit/bindgen.rb @@ -536,6 +536,7 @@ generator = BindingGenerator.new( rb_reg_match_post rb_reg_match_last rb_reg_nth_match + rb_gvar_get ], types: %w[ CALL_DATA