Modified: trunk/Source/_javascript_Core/offlineasm/arm64.rb (295765 => 295766)
--- trunk/Source/_javascript_Core/offlineasm/arm64.rb 2022-06-23 02:54:49 UTC (rev 295765)
+++ trunk/Source/_javascript_Core/offlineasm/arm64.rb 2022-06-23 02:56:36 UTC (rev 295766)
@@ -227,8 +227,21 @@
class Address
def arm64Operand(kind)
- raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 4095
- "[#{base.arm64Operand(:quad)}, \##{offset.value}]"
+ case kind
+ when :quad, :ptr, :double
+ if $currentSettings["ADDRESS64"]
+ raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 32760
+ else
+ raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 16380
+ end
+ when :word, :int, :float
+ raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 16380
+ else
+ raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 4095
+ end
+ offset.value.zero? \
+ ? "[#{base.arm64Operand(:quad)}]"
+ : "[#{base.arm64Operand(:quad)}, \##{offset.value}]"
end
def arm64SimpleAddressOperand(kind)
@@ -237,7 +250,9 @@
end
def arm64EmitLea(destination, kind)
- $asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, \##{offset.value}"
+ offset.value.zero? \
+ ? ($asm.puts "mov #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}")
+ : ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, \##{offset.value}")
end
end
@@ -244,11 +259,15 @@
class BaseIndex
def arm64Operand(kind)
raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value != 0
- "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}, lsl \##{scaleShift}]"
+ scaleShift.zero? \
+ ? "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}]"
+ : "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}, lsl \##{scaleShift}]"
end
def arm64EmitLea(destination, kind)
- $asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}, lsl \##{scaleShift}"
+ scaleShift.zero? \
+ ? ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}")
+ : ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}, lsl \##{scaleShift}")
end
end
@@ -264,29 +283,42 @@
# Actual lowering code follows.
#
-def arm64LowerMalformedLoadStoreAddresses(list)
- newList = []
-
- def isAddressMalformed(opcode, operand)
- malformed = false
- if operand.is_a? Address
+def isMalformedArm64LoadAStoreAddress(opcode, operand)
+ malformed = false
+ if operand.is_a? Address
+ case opcode
+ when "loadp", "storep", "loadq", "storeq"
+ if $currentSettings["ADDRESS64"]
+ malformed ||= (not (-255..32760).include? operand.offset.value)
+ malformed ||= (not (operand.offset.value % 8).zero?)
+ else
+ malformed ||= (not (-255..16380).include? operand.offset.value)
+ end
+ when "loadd", "stored"
+ malformed ||= (not (-255..32760).include? operand.offset.value)
+ malformed ||= (not (operand.offset.value % 8).zero?)
+ when "loadi", "loadis", "storei"
+ malformed ||= (not (-255..16380).include? operand.offset.value)
+ else
+ # This is just a conservative estimate of the max offset.
malformed ||= (not (-255..4095).include? operand.offset.value)
- if opcode =~ /q$/ and $currentSettings["ADDRESS64"]
- malformed ||= operand.offset.value % 8
- end
end
- malformed
end
+ malformed
+end
+def arm64LowerMalformedLoadStoreAddresses(list)
+ newList = []
+
list.each {
| node |
if node.is_a? Instruction
- if node.opcode =~ /^store/ and isAddressMalformed(node.opcode, node.operands[1])
+ if node.opcode =~ /^store/ and isMalformedArm64LoadAStoreAddress(node.opcode, node.operands[1])
address = node.operands[1]
tmp = Tmp.new(codeOrigin, :gpr)
newList << Instruction.new(node.codeOrigin, "move", [address.offset, tmp])
newList << Instruction.new(node.codeOrigin, node.opcode, [node.operands[0], BaseIndex.new(node.codeOrigin, address.base, tmp, Immediate.new(codeOrigin, 1), Immediate.new(codeOrigin, 0))], node.annotation)
- elsif node.opcode =~ /^load/ and isAddressMalformed(node.opcode, node.operands[0])
+ elsif node.opcode =~ /^load/ and isMalformedArm64LoadAStoreAddress(node.opcode, node.operands[0])
address = node.operands[0]
tmp = Tmp.new(codeOrigin, :gpr)
newList << Instruction.new(node.codeOrigin, "move", [address.offset, tmp])
@@ -399,7 +431,7 @@
address.offset.value == 0 and
(node.opcode =~ /^lea/ or address.scale == 1 or address.scale == size)
elsif address.is_a? Address
- (-255..4095).include? address.offset.value
+ not isMalformedArm64LoadAStoreAddress(node.opcode, address)
else
false
end
@@ -443,10 +475,8 @@
result = riscLowerMalformedAddresses(result) {
| node, address |
case node.opcode
- when /^load/
- true
- when /^store/
- not (address.is_a? Address and address.offset.value < 0)
+ when /^load/, /^store/
+ not address.is_a? Address or not isMalformedArm64LoadAStoreAddress(node.opcode, address)
when /^lea/
true
when /^atomic/
@@ -655,21 +685,40 @@
end
def emitARM64MoveImmediate(value, target)
+ numberOfFilledHalfWords = 0
+ numberOfZeroHalfWords = 0
+ [48, 32, 16, 0].each {
+ | shift |
+ currentValue = (value >> shift) & 0xffff
+ if currentValue == 0xffff
+ numberOfFilledHalfWords += 1
+ end
+ if currentValue == 0
+ numberOfZeroHalfWords += 1
+ end
+ }
+ fillOtherHalfWordsWithOnes = (numberOfFilledHalfWords > numberOfZeroHalfWords)
+
first = true
- isNegative = value < 0
[48, 32, 16, 0].each {
| shift |
currentValue = (value >> shift) & 0xffff
- next if currentValue == (isNegative ? 0xffff : 0) and (shift != 0 or !first)
+ next if currentValue == (fillOtherHalfWordsWithOnes ? 0xffff : 0) and (shift != 0 or !first)
if first
- if isNegative
- $asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}, lsl \##{shift}"
+ if fillOtherHalfWordsWithOnes
+ shift.zero? \
+ ? ($asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}")
+ : ($asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}, lsl \##{shift}")
else
- $asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}"
+ shift.zero? \
+ ? ($asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}")
+ : ($asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}")
end
first = false
else
- $asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}"
+ shift.zero? \
+ ? ($asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}")
+ : ($asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}")
end
}
end