Skip to content

Commit

Permalink
RJIT: Implement getglobal
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 19, 2023
1 parent 9f8e914 commit 81e19b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/ruby_vm/rjit/insn_compiler.rb
Expand Up @@ -18,7 +18,7 @@ def compile(jit, ctx, asm, insn)
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)
Expand All @@ -35,7 +35,7 @@ def compile(jit, ctx, asm, insn)
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)
Expand Down Expand Up @@ -649,7 +649,25 @@ def getconstant(jit, ctx, asm)
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]
Expand Down
4 changes: 4 additions & 0 deletions rjit_c.rb
Expand Up @@ -505,6 +505,10 @@ def C.rb_get_symbol_id
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
Expand Down
1 change: 1 addition & 0 deletions tool/rjit/bindgen.rb
Expand Up @@ -536,6 +536,7 @@ def push_target(target)
rb_reg_match_post
rb_reg_match_last
rb_reg_nth_match
rb_gvar_get
],
types: %w[
CALL_DATA
Expand Down

0 comments on commit 81e19b7

Please sign in to comment.