summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ruby_vm/mjit')
-rw-r--r--lib/ruby_vm/mjit/compiler.rb35
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb124
-rw-r--r--lib/ruby_vm/mjit/jit_state.rb11
-rw-r--r--lib/ruby_vm/mjit/x86_assembler.rb5
4 files changed, 169 insertions, 6 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index 396e93cb04..b24cfe6a7b 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -155,6 +155,41 @@ module RubyVM::MJIT
case insn.name
when :putnil then @insn_compiler.putnil(jit, ctx, asm)
when :leave then @insn_compiler.leave(jit, ctx, asm)
+ # throw
+ # jump
+ # branchif
+ # branchunless
+ # branchnil
+ # once
+ # opt_case_dispatch
+ # opt_plus
+ # opt_minus
+ # opt_mult
+ # opt_div
+ # opt_mod
+ # opt_eq
+ # opt_neq
+ # opt_lt
+ # opt_le
+ # opt_gt
+ # opt_ge
+ # opt_ltlt
+ # opt_and
+ # opt_or
+ # opt_aref
+ # opt_aset
+ # opt_aset_with
+ # opt_aref_with
+ # opt_length
+ # opt_size
+ # opt_empty_p
+ # opt_succ
+ # opt_not
+ # opt_regexpmatch2
+ # invokebuiltin
+ # opt_invokebuiltin_delegate
+ # opt_invokebuiltin_delegate_leave
+ when :getlocal_WC_0 then @insn_compiler.getlocal_WC_0(jit, ctx, asm)
else CantCompile
end
end
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index 73a260575e..091afaa214 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -4,6 +4,26 @@ module RubyVM::MJIT
# sp: rbx
# scratch regs: rax
class InsnCompiler
+ # 3/101
+
+ # nop
+ # getlocal
+ # setlocal
+ # getblockparam
+ # setblockparam
+ # getblockparamproxy
+ # getspecial
+ # setspecial
+ # getinstancevariable
+ # setinstancevariable
+ # getclassvariable
+ # setclassvariable
+ # opt_getconstant_path
+ # getconstant
+ # setconstant
+ # getglobal
+ # setglobal
+
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::X86Assembler]
@@ -13,6 +33,49 @@ module RubyVM::MJIT
KeepCompiling
end
+ # putself
+ # putobject
+ # putspecialobject
+ # putstring
+ # concatstrings
+ # anytostring
+ # toregexp
+ # intern
+ # newarray
+ # newarraykwsplat
+ # duparray
+ # duphash
+ # expandarray
+ # concatarray
+ # splatarray
+ # newhash
+ # newrange
+ # pop
+ # dup
+ # dupn
+ # swap
+ # opt_reverse
+ # topn
+ # setn
+ # adjuststack
+ # defined
+ # checkmatch
+ # checkkeyword
+ # checktype
+ # defineclass
+ # definemethod
+ # definesmethod
+ # send
+ # opt_send_without_block
+ # objtostring
+ # opt_str_freeze
+ # opt_nil_p
+ # opt_str_uminus
+ # opt_newarray_max
+ # opt_newarray_min
+ # invokesuper
+ # invokeblock
+
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::X86Assembler]
@@ -40,6 +103,67 @@ module RubyVM::MJIT
EndBlock
end
+ # throw
+ # jump
+ # branchif
+ # branchunless
+ # branchnil
+ # once
+ # opt_case_dispatch
+ # opt_plus
+ # opt_minus
+ # opt_mult
+ # opt_div
+ # opt_mod
+ # opt_eq
+ # opt_neq
+ # opt_lt
+ # opt_le
+ # opt_gt
+ # opt_ge
+ # opt_ltlt
+ # opt_and
+ # opt_or
+ # opt_aref
+ # opt_aset
+ # opt_aset_with
+ # opt_aref_with
+ # opt_length
+ # opt_size
+ # opt_empty_p
+ # opt_succ
+ # opt_not
+ # opt_regexpmatch2
+ # invokebuiltin
+ # opt_invokebuiltin_delegate
+ # opt_invokebuiltin_delegate_leave
+
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::X86Assembler]
+ def getlocal_WC_0(jit, ctx, asm)
+ # Get operands
+ idx = jit.operand(0)
+ level = 0
+
+ # Get EP
+ asm.mov(:rax, [CFP, C.rb_control_frame_t.offsetof(:ep)])
+
+ # Get a local variable
+ asm.mov(:rax, [:rax, -idx * C.VALUE.size])
+
+ # Push it to the stack
+ asm.mov([SP, C.VALUE.size * ctx.stack_size], :rax)
+ ctx.stack_size += 1
+ KeepCompiling
+ end
+
+ # getlocal_WC_1
+ # setlocal_WC_0
+ # setlocal_WC_1
+ # putobject_INT2FIX_0_
+ # putobject_INT2FIX_1_
+
private
def assert_eq!(left, right)
diff --git a/lib/ruby_vm/mjit/jit_state.rb b/lib/ruby_vm/mjit/jit_state.rb
index 819ecc128b..0a35a516ca 100644
--- a/lib/ruby_vm/mjit/jit_state.rb
+++ b/lib/ruby_vm/mjit/jit_state.rb
@@ -1,4 +1,9 @@
-class RubyVM::MJIT::JITState < Struct.new(
- :pc, # @param [Integer]
-)
+module RubyVM::MJIT
+ class JITState < Struct.new(
+ :pc, # @param [Integer]
+ )
+ def operand(index)
+ C.VALUE.new(pc)[index + 1]
+ end
+ end
end
diff --git a/lib/ruby_vm/mjit/x86_assembler.rb b/lib/ruby_vm/mjit/x86_assembler.rb
index 12f65f5432..1eef272eb4 100644
--- a/lib/ruby_vm/mjit/x86_assembler.rb
+++ b/lib/ruby_vm/mjit/x86_assembler.rb
@@ -256,7 +256,7 @@ module RubyVM::MJIT
@bytes.push(mod_rm)
end
if disp
- if disp < 0 || disp > 0xff # TODO: support displacement in 2 or 4 bytes as well
+ unless imm8?(disp) # TODO: support displacement in 2 or 4 bytes as well
raise NotImplementedError, "not-implemented disp: #{disp}"
end
@bytes.push(disp)
@@ -344,8 +344,7 @@ module RubyVM::MJIT
end
def imm8?(imm)
- raise "negative imm not supported: #{imm}" if imm.negative? # TODO: support this
- imm <= 0x7f # TODO: consider uimm
+ (-0x80..0x7f).include?(imm)
end
def imm32?(imm)