diff options
author | Takashi Kokubun <[email protected]> | 2023-02-21 00:11:56 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 23:28:59 -0800 |
commit | a666079404cbd74315743471998d8e35e11f8eef (patch) | |
tree | ce1f7c74573aba49d8a618cf16000a3c50c0fa75 | |
parent | 4106487ae8983e8afadef2a56018635645d2b9bb (diff) |
Implement topn
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7448
-rw-r--r-- | lib/ruby_vm/mjit/insn_compiler.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index ce280a0688..094ffa832d 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -23,7 +23,7 @@ module RubyVM::MJIT asm.incr_counter(:mjit_insns_count) asm.comment("Insn: #{insn.name}") - # 53/101 + # 54/101 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -65,7 +65,7 @@ module RubyVM::MJIT when :dupn then dupn(jit, ctx, asm) # swap # opt_reverse - # topn + when :topn then topn(jit, ctx, asm) when :setn then setn(jit, ctx, asm) when :adjuststack then adjuststack(jit, ctx, asm) # defined @@ -481,7 +481,20 @@ module RubyVM::MJIT # swap # opt_reverse - # topn + + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::Assembler] + def topn(jit, ctx, asm) + n = jit.operand(0) + + top_n_val = ctx.stack_opnd(n) + loc0 = ctx.stack_push + asm.mov(:rax, top_n_val) + asm.mov(loc0, :rax) + + KeepCompiling + end # @param jit [RubyVM::MJIT::JITState] # @param ctx [RubyVM::MJIT::Context] |