work to move large constants
This commit is contained in:
parent
c92b165a3f
commit
16b3cacc8d
@ -69,7 +69,7 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def calculate_u8_with_rr(arg)
|
def calculate_u8_with_rr(arg)
|
||||||
parts = arg.value.to_s(2).rjust(32,'0').scan(/^(0*)(.+?)0*$/).flatten
|
parts = arg.integer.to_s(2).rjust(32,'0').scan(/^(0*)(.+?)0*$/).flatten
|
||||||
pre_zeros = parts[0].length
|
pre_zeros = parts[0].length
|
||||||
imm_len = parts[1].length
|
imm_len = parts[1].length
|
||||||
if ((pre_zeros+imm_len) % 2 == 1)
|
if ((pre_zeros+imm_len) % 2 == 1)
|
||||||
|
@ -12,16 +12,37 @@ module Arm
|
|||||||
|
|
||||||
@immediate = 0
|
@immediate = 0
|
||||||
@rn = :r0 # register zero = zero bit pattern
|
@rn = :r0 # register zero = zero bit pattern
|
||||||
# NO-OP -> pass raise inspect if to.is_a?(Virtual::Value) and
|
@from = Virtual::IntegerConstant.new( @from ) if( @from.is_a? Fixnum )
|
||||||
# from.is_a?(Virtual::Value) and
|
|
||||||
# !@attributes[:shift_lsr] and
|
|
||||||
# to.symbol == from.symbol
|
|
||||||
raise "uups " if @to.symbol == :rr1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# arm intrucions are pretty sensible, and always 4 bytes (thumb not supported)
|
# arm intrucions are pretty sensible, and always 4 bytes (thumb not supported)
|
||||||
|
# but not all constants fit into the part of the instruction that is left after the instruction code,
|
||||||
|
# so large moves have to be split into two instrucitons. we handle this here, just this instruciton looks
|
||||||
|
# longer
|
||||||
def length
|
def length
|
||||||
4
|
is_simple ? 4 : 8
|
||||||
|
end
|
||||||
|
|
||||||
|
# a constant (the one we want to move) can either be < 256 or be rotated in a funny arm way
|
||||||
|
# if neither works (not simple !) we need two instructions to make the move
|
||||||
|
def is_simple
|
||||||
|
right = @from
|
||||||
|
if right.is_a?(Virtual::ObjectConstant)
|
||||||
|
r_pos = assembler.position_for(right)
|
||||||
|
# do pc relative addressing with the difference to the instuction
|
||||||
|
# 8 is for the funny pipeline adjustment (ie pc pointing to fetch and not execute)
|
||||||
|
right = Virtual::IntegerConstant.new( r_pos - self.position - 8 )
|
||||||
|
end
|
||||||
|
if (right.is_a?(Virtual::IntegerConstant))
|
||||||
|
if (right.integer.fits_u8?)
|
||||||
|
return true
|
||||||
|
elsif (calculate_u8_with_rr(right))
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble(io, assembler)
|
def assemble(io, assembler)
|
||||||
@ -29,17 +50,17 @@ module Arm
|
|||||||
rn = @rn
|
rn = @rn
|
||||||
operand = @operand
|
operand = @operand
|
||||||
immediate = @immediate
|
immediate = @immediate
|
||||||
|
complex = false
|
||||||
right = @from
|
right = @from
|
||||||
if right.is_a?(Virtual::ObjectConstant)
|
if right.is_a?(Virtual::ObjectConstant)
|
||||||
|
r_pos = assembler.position_for(right)
|
||||||
# do pc relative addressing with the difference to the instuction
|
# do pc relative addressing with the difference to the instuction
|
||||||
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
|
# 8 is for the funny pipeline adjustment (ie pc pointing to fetch and not execute)
|
||||||
right = Virtual::IntegerConstant.new( right.position - self.position - 8 )
|
right = Virtual::IntegerConstant.new( r_pos - self.position - 8 )
|
||||||
|
puts "Position #{r_pos} from #{self.position} = #{right}"
|
||||||
|
right = Virtual::IntegerConstant.new(r_pos) if right.integer > 255
|
||||||
rn = :pc
|
rn = :pc
|
||||||
end
|
end
|
||||||
if( right.is_a? Fixnum )
|
|
||||||
right = Virtual::IntegerConstant.new( right )
|
|
||||||
end
|
|
||||||
if (right.is_a?(Virtual::IntegerConstant))
|
if (right.is_a?(Virtual::IntegerConstant))
|
||||||
if (right.integer.fits_u8?)
|
if (right.integer.fits_u8?)
|
||||||
# no shifting needed
|
# no shifting needed
|
||||||
@ -61,7 +82,7 @@ module Arm
|
|||||||
op = shift_handling
|
op = shift_handling
|
||||||
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
||||||
val = shift(operand , 0)
|
val = shift(operand , 0)
|
||||||
val |= shift(op , 0) # any barral action, is already shifted
|
val |= shift(op , 0) # any barrel action, is already shifted
|
||||||
val |= shift(reg_code(@to) , 12)
|
val |= shift(reg_code(@to) , 12)
|
||||||
val |= shift(reg_code(rn) , 12+4)
|
val |= shift(reg_code(rn) , 12+4)
|
||||||
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
||||||
|
@ -233,6 +233,10 @@ module Register
|
|||||||
return assemble_String(sc)
|
return assemble_String(sc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position_for object
|
||||||
|
s = get_slot(object)
|
||||||
|
s.position
|
||||||
|
end
|
||||||
private
|
private
|
||||||
def get_slot(object)
|
def get_slot(object)
|
||||||
slot = @objects[object.object_id]
|
slot = @objects[object.object_id]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user