Permalink
Browse files

Switched to intcode (each opcode is 32bits now)

  • Loading branch information...
1 parent 50a5d05 commit b8728aba607a19d4a018c879ac9e141791e16ffe @evanphx evanphx committed Jul 19, 2007
View
@@ -208,7 +208,7 @@ namespace :build do
task :loader do
i = "kernel/loader.rb"
- o = "runtime/loader.rbc"
+ o = ENV['OUTPUT'] || "runtime/loader.rbc"
if @compiler
system "shotgun/rubinius -I#{@compiler} compile #{i} #{o}"
@@ -28,4 +28,19 @@ def each
yield get_byte(i)
end
end
+
+ def dup_into(other)
+ Ruby.primitive 32 # :bytes_dup_into
+ end
+
+ def dup(cls=nil)
+ cls ||= self.class
+ obj = cls.new(self.size)
+ dup_into obj
+ return obj
+ end
+
+ def inspect
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{size} bytes>"
+ end
end
View
@@ -2,7 +2,7 @@ module Rubinius
# This const controls what the lowest version of compiled methods we can
# allow is. This allows us to cut off compability at some point, or just
# increment when major changes are made to the compiler.
- CompiledMethodVersion = 3
+ CompiledMethodVersion = 4
end
module Compile
View
@@ -41,6 +41,16 @@ def reset(literals=[], state=RsLocalState.new)
@state = state
end
+ def add(*args)
+ @current_op += args.size
+ if args.size == 1
+ @output << args.first
+ else
+ @output << args
+ end
+ end
+
+ # OpWidth = 4
CacheSlotsPerEntry = 4
CacheSlotsForConst = 1
@@ -51,13 +61,11 @@ def next_cache_index(count)
end
def add_cache_index
- @current_op += 5
- @output << [:set_cache_index, next_cache_index(CacheSlotsPerEntry)]
+ add :set_cache_index, next_cache_index(CacheSlotsPerEntry)
end
def add_const_cache_index
- @current_op += 5
- @output << [:set_cache_index, next_cache_index(CacheSlotsForConst)]
+ add :set_cache_index, next_cache_index(CacheSlotsForConst)
end
attr_reader :labels, :source_lines, :primitive, :literals
@@ -328,122 +336,100 @@ def parse_push(what)
if what[0] == ?&
lbl = @labels[what[1..-1].to_sym]
raise "Unknown label '#{lbl}'" unless lbl
- @output << [:push_int, lbl]
+ add :push_int, lbl
elsif what[0] == ?@
lit = find_literal(what.to_sym)
- @output << [:push_ivar, lit]
+ add :push_ivar, lit
elsif what.to_i.to_s == what
num = what.to_i
if num == -1
- @current_op += 1
- @output << :meta_push_neg_1
+ add :meta_push_neg_1
elsif num == 0
- @current_op += 1
- @output << :meta_push_0
+ add :meta_push_0
elsif num == 1
- @current_op += 1
- @output << :meta_push_1
+ add :meta_push_1
elsif num == 2
- @current_op += 1
- @output << :meta_push_2
+ add :meta_push_2
else
- @current_op += 5
- @output << [:push_int, num]
+ add :push_int, num
end
return
elsif idx = parse_aref(what)
- @output << [:push_int, idx]
- @output << :fetch_field
- @current_op += 1
+ add :push_int, idx
+ add :fetch_field
elsif what[0] == ?:
lit = find_literal(what[1..-1].to_sym)
- @output << [:push_literal, lit]
+ add :push_literal, lit
else
case what
when "true", true
- @output << :push_true
- @current_op += 1
+ add :push_true
return
when "false", false
- @output << :push_false
- @current_op += 1
+ add :push_false
return
when "nil", nil
- @output << :push_nil
- @current_op += 1
+ add :push_nil
return
when "self", :self
- @output << :push_self
- @current_op += 1
+ add :push_self
else
if cnt = parse_lvar(what)
if Array === cnt
- @output << [:push_local_depth, cnt[0], cnt[1]]
- @current_op += 9
+ add :push_local_depth, cnt[0], cnt[1]
else
- @output << [:push_local, cnt]
- @current_op += 5
+ add :push_local, cnt
end
elsif info = parse_ivar(what)
- @output << [:push_local, info.first]
- @output << [:push_ivar, info.last]
- @current_op += 10
+ add :push_local, info.first
+ add :push_ivar, info.last
elsif cnt = parse_const(what)
add_const_cache_index
- @output << [:push_const, cnt]
- @current_op += 5
+ add :push_const, cnt
else
raise "Unknown push argument '#{what}'"
end
end
return
end
- @current_op += 5
end
def parse_set(what)
if cnt = parse_lvar(what)
if Array === cnt
- @output << [:set_local_depth, cnt[0], cnt[1]]
- @current_op += 9
+ add :set_local_depth, cnt[0], cnt[1]
else
- @output << [:set_local, cnt]
- @current_op += 5
+ add :set_local, cnt
end
elsif info = parse_ivar(what)
- @output << [:push_local, info.first]
- @output << [:set_ivar, info.last]
- @current_op += 10
+ add :push_local, info.first
+ add :set_ivar, info.last
elsif what[0] == ?@
lit = find_literal(what.to_sym)
- @output << [:set_ivar, lit]
- @current_op += 5
+ add :set_ivar, lit
elsif idx = parse_aref(what)
- @output << [:push_int, idx]
- @output << :store_field
- @current_op += 6
+ add :push_int, idx
+ add :store_field
elsif cnt = parse_const(what)
- @output << [:set_const, cnt]
- @current_op += 5
+ add :set_const, cnt
elsif what.index("::")
parent, chld = what.split("::", 2)
if cnt = parse_const(parent)
add_const_cache_index
- @output << [:push_const, cnt]
+ add :push_const, cnt
else
raise "Invalid lhs to double colon (#{parent})"
end
if cnt = parse_const(chld)
- @output << [:set_const_at, cnt]
+ add :set_const_at, cnt
else
raise "Invalid rhs to double colon (#{chld})"
end
- @current_op += 10
elsif what.index("+") == 0
if cnt = parse_const(what[1..-1])
- @output << [:set_const_at, cnt]
+ add :set_const_at, cnt
else
raise "Unknown + argument (#{what})"
end
@@ -459,8 +445,7 @@ def parse_operation(*parts)
end
if Simple.include?(op)
- @output << op
- @current_op += 1
+ add op
return
end
@@ -469,8 +454,7 @@ def parse_operation(*parts)
return
elsif [:goto, :goto_if_true, :goto_if_false].include?(op)
label = parts.shift.to_sym
- @output << [op, @labels[label]]
- @current_op += 5
+ add op, @labels[label]
return
elsif op == :push
parse_push parts.shift
@@ -480,8 +464,7 @@ def parse_operation(*parts)
idx = find_literal(sym)
add_const_cache_index if op == :find_const
add_cache_index if op == :send_method
- @output << [op, idx]
- @current_op += 5
+ add op, idx
return
elsif op == :push
parse_push parts.shift
@@ -490,29 +473,26 @@ def parse_operation(*parts)
sym = parts.shift.to_sym
idx = find_literal(sym)
add_cache_index
- @output << [op, idx, parts.shift.to_i]
- @current_op += 9
+ add op, idx, parts.shift.to_i
return
elsif [:"&send", :send].include?(op)
sym = parts.shift.to_sym
idx = find_literal(sym)
add_cache_index
- @current_op += 5
if args = parts.shift
if args.to_i.to_s == args
meth = (op == :send ? :send_stack : :send_stack_with_block)
elsif args == "+"
meth = :send_with_arg_register
- @output << [meth, idx]
+ add meth, idx
return
else
raise "Unknown send argument type '#{args}'"
end
na = args.to_i
- @output << [meth, idx, na]
- @current_op += 4
+ add meth, idx, na
else
- @output << [:send_method, idx]
+ add :send_method, idx
end
return
elsif op == :super
@@ -521,36 +501,33 @@ def parse_operation(*parts)
add_cache_index
args = parts.shift
if args == "+"
- @current_op += 5
- @output << [:send_super_with_arg_register, idx]
- else
- @current_op += 9
- @output << [:send_super_stack_with_block, idx, args.to_i]
+ add :send_super_with_arg_register, idx
+ else
+ add :send_super_stack_with_block, idx, args.to_i
end
return
elsif op == :send_primitive
sym = parts.shift.to_sym
idx = primitive_to_index(sym)
num_args = parts.shift.to_i
- @current_op += 9
- @output << [:send_primitive, idx, num_args]
+ add :send_primitive, idx, num_args
return
elsif op == :check_argcount
- @output << [op, parts.shift.to_i, parts.shift.to_i]
- @current_op += 9
+ req = parts.shift.to_i
+ add op, req, parts.shift.to_i
return
end
if Bytecode::InstructionEncoder::OpCodes.include?(op)
- @current_op += 1
- if Bytecode::InstructionEncoder::TwoInt.include?(op)
- @current_op += 8
- @output << [op, parts.shift.to_i, parts.shift.to_i]
- elsif Bytecode::InstructionEncoder::IntArg.include?(op)
- @current_op += 4
- @output << [op, parts.first.to_i]
+ if Bytecode::InstructionEncoder::IntArg.include?(op)
+ if Bytecode::InstructionEncoder::TwoInt.include?(op)
+ fir = parts.shift.to_i
+ add op, fir, parts.shift.to_i
+ else
+ add op, parts.shift.to_i
+ end
else
- @output << op
+ add op
end
return
end
View
@@ -286,7 +286,7 @@ def instruction_width(op)
op = OpCodes[op]
end
- width = 1
+ width = 4
if IntArg.include?(op)
width += 4
elsif TwoInt.include?(op)
@@ -330,7 +330,7 @@ def encode(kind, *args)
end
def process_args(kind, opcode, args)
- str = opcode.chr
+ str = [opcode].pack("N")
# puts "#{kind} args. (#{str.inspect})"
# puts args.inspect if ENV["DEBUG_ASSEMBLER"]
View
2 lib/bytecode/primitive_names.rb 100644 → 100755
@@ -32,7 +32,7 @@ class Compiler
:create_pipe,
:gettimeofday,
:strftime,
- nil,
+ :bytes_dup_into,
:activate_as_script,
:stat_file,
:io_open,
@@ -28,8 +28,8 @@ def to_cmethod
enc = Bytecode::InstructionEncoder.new
bc = enc.encode_stream stream
lcls = @state.number_of_locals
-
- cmeth = CompiledMethod.new.from_string bc.data, lcls, @required
+ iseq = bc.data.dup(InstructionSequence)
+ cmeth = CompiledMethod.new.from_string iseq, lcls, @required
cmeth.exceptions = asm.exceptions_as_tuple
idx = nil
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -10,10 +10,7 @@ MARCH=$(shell uname -m)
WARNINGS = -Wall
DEBUG = -g -ggdb3
-# basic optimizations should be overridable
-CFLAGS ?= -O2
-
-CFLAGS += $(WARNINGS) $(DEBUG)
+CFLAGS = $(WARNINGS) $(DEBUG)
CPPFLAGS += `pkg-config glib-2.0 --cflags`
View
@@ -47,7 +47,7 @@ ifdef DEV
OPTIMIZATIONS=
else
INLINE_OPTS=-finline-limit=2000 --param max-inline-insns-single=3500 --param large-function-growth=2000 --param inline-unit-growth=1000
- OPTIMIZATIONS=-ffast-math -funroll-loops -finline-functions -fno-omit-frame-pointer $(INLINE_OPTS)
+ OPTIMIZATIONS=-O2 -ffast-math -funroll-loops -finline-functions -fno-omit-frame-pointer $(INLINE_OPTS)
endif
ifeq ($(CPU), powerpc)
OPTIMIZATIONS+=-falign-loops=16
Oops, something went wrong.

0 comments on commit b8728ab

Please sign in to comment.