finally get rid of the fixme in div10

create (load/reduce) the int once and transfer.
Save a cruicial 2 instructions

Also expanded the variable name possibilities with _self, __const , _1 and _2
This commit is contained in:
Torsten Ruger 2018-08-15 18:18:21 +03:00
parent 15337e10be
commit 252ae6de72
4 changed files with 46 additions and 35 deletions

View File

@ -56,7 +56,7 @@ module Risc
def infer_type( name ) def infer_type( name )
as_string = name.to_s as_string = name.to_s
parts = as_string.split("_") parts = as_string.split("_")
if(parts.last == "reg" or parts.last == "obj" or parts.last == "tmp") if( ["reg" , "obj" , "tmp" , "self" , "const", "1" , "2"].include?( parts.last ) )
parts.pop parts.pop
as_string = parts.join("_") as_string = parts.join("_")
end end

View File

@ -102,24 +102,27 @@ module Risc
return compiler return compiler
end end
# old helper function for div10 (which doesn't use builder yet) # as the name suggests, this devides the integer (self) by ten
def add_receiver(builder) #
message = Risc.message_reg # This version is lifted from some arm assembler tricks and is _much_
ret_type = builder.compiler.receiver_type # faster than the general div versions. I think it was about three
ret = builder.compiler.use_reg( ret_type ).set_builder(builder) # times less instructions. Useful for itos
builder.add_slot_to_reg(" load self" , message , :receiver , ret ) #
builder.add_slot_to_reg( "int -> fix" , ret , Parfait::Integer.integer_index , ret) # In fact it is possible to generate specific div function for any given
return ret # integer and some are even more faster (as eg div4).
end
def div10( context ) def div10( context )
s = "div_10 " s = "div_10 "
compiler = compiler_for(:Integer,:div10 ,{}) compiler = compiler_for(:Integer,:div10 ,{})
builder = compiler.compiler_builder(compiler.source) builder = compiler.compiler_builder(compiler.source)
#FIX: this could load receiver once, reduce and then transfer twice builder.build do
me = add_receiver( builder ) integer_self! << message[:receiver]
tmp = add_receiver( builder ) integer_self.reduce_int
q = add_receiver( builder ) integer_tmp! << integer_self
integer_reg! << integer_self
end
me = builder.integer_self
tmp = builder.integer_tmp
q = builder.integer_reg
const = compiler.use_reg :fixnum , value: 1 const = compiler.use_reg :fixnum , value: 1
builder.add_load_data( s , 1 , const ) builder.add_load_data( s , 1 , const )
# int tmp = self >> 1 # int tmp = self >> 1

View File

@ -14,32 +14,31 @@ module Risc
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
SlotToReg, FunctionCall, SlotToReg, SlotToReg, SlotToReg, # 20 SlotToReg, FunctionCall, SlotToReg, SlotToReg, Transfer, # 20
SlotToReg, SlotToReg, SlotToReg, LoadData, OperatorInstruction, Transfer, LoadData, OperatorInstruction, LoadData, OperatorInstruction,
LoadData, OperatorInstruction, OperatorInstruction, LoadData, Transfer, # 30 OperatorInstruction, LoadData, Transfer, OperatorInstruction, OperatorInstruction, # 30
Branch, OperatorInstruction, OperatorInstruction, LoadData, Transfer, Branch, LoadData, Transfer, OperatorInstruction, OperatorInstruction,
OperatorInstruction, OperatorInstruction, LoadData, Transfer, OperatorInstruction, # 40 LoadData, Transfer, OperatorInstruction, OperatorInstruction, LoadData, # 40
OperatorInstruction, LoadData, OperatorInstruction, LoadData, Branch, OperatorInstruction, LoadData, Transfer, OperatorInstruction, Branch,
Transfer, OperatorInstruction, OperatorInstruction, Transfer, LoadData, # 50 OperatorInstruction, Transfer, LoadData, OperatorInstruction, LoadData, # 50
OperatorInstruction, LoadData, OperatorInstruction, OperatorInstruction, LoadConstant, OperatorInstruction, OperatorInstruction, LoadConstant, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, Branch, RegToSlot, # 60 RegToSlot, RegToSlot, RegToSlot, Branch, SlotToReg, # 60
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 70 RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 70
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg, # 80 RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 80
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg, Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 90 SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 90
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, SlotToReg, SlotToReg, Syscall, NilClass, ]
NilClass, ]
assert_equal 2 , get_return assert_equal 2 , get_return
end end
def test_load_space def test_load_space
load_ins = main_ticks 55 load_ins = main_ticks 53
assert_load load_ins, Parfait::Space assert_load load_ins, Parfait::Space
end end
def test_load_to def test_load_to
to = main_ticks 56 to = main_ticks 54
assert_slot_to_reg to , :r5 , 5 ,:r2 assert_slot_to_reg to , :r5 , 5 ,:r2
end end
def test_load_25 def test_load_25
@ -48,7 +47,7 @@ module Risc
assert_equal 25 , @interpreter.get_register(load_ins.register).value assert_equal 25 , @interpreter.get_register(load_ins.register).value
end end
def test_return_class def test_return_class
ret = main_ticks(72) ret = main_ticks(70)
assert_equal FunctionReturn , ret.class assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register ) link = @interpreter.get_register( ret.register )
assert_equal Fixnum , link.class assert_equal Fixnum , link.class

View File

@ -31,6 +31,15 @@ module Risc
def test_caller_obj def test_caller_obj
assert_equal :Message , @builder.infer_type(:caller_obj).class_name assert_equal :Message , @builder.infer_type(:caller_obj).class_name
end end
def test_caller_const
assert_equal :Message , @builder.infer_type(:caller_const).class_name
end
def test_caller_self
assert_equal :Message , @builder.infer_type(:caller_self).class_name
end
def test_caller_1
assert_equal :Message , @builder.infer_type(:caller_1).class_name
end
def test_message def test_message
assert_equal :Message , @builder.infer_type(:message).class_name assert_equal :Message , @builder.infer_type(:message).class_name
end end