Changeset 295766 in webkit for trunk/Source/JavaScriptCore/offlineasm
- Timestamp:
- Jun 22, 2022, 7:56:36 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/offlineasm/arm64.rb
r294787 r295766 228 228 class Address 229 229 def arm64Operand(kind) 230 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 4095 231 "[#{base.arm64Operand(:quad)}, \##{offset.value}]" 230 case kind 231 when :quad, :ptr, :double 232 if $currentSettings["ADDRESS64"] 233 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 32760 234 else 235 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 16380 236 end 237 when :word, :int, :float 238 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 16380 239 else 240 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value < -255 or offset.value > 4095 241 end 242 offset.value.zero? \ 243 ? "[#{base.arm64Operand(:quad)}]" 244 : "[#{base.arm64Operand(:quad)}, \##{offset.value}]" 232 245 end 233 246 … … 238 251 239 252 def arm64EmitLea(destination, kind) 240 $asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, \##{offset.value}" 253 offset.value.zero? \ 254 ? ($asm.puts "mov #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}") 255 : ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, \##{offset.value}") 241 256 end 242 257 end … … 245 260 def arm64Operand(kind) 246 261 raise "Invalid offset #{offset.value} at #{codeOriginString}" if offset.value != 0 247 "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}, lsl \##{scaleShift}]" 262 scaleShift.zero? \ 263 ? "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}]" 264 : "[#{base.arm64Operand(:quad)}, #{index.arm64Operand(:quad)}, lsl \##{scaleShift}]" 248 265 end 249 266 250 267 def arm64EmitLea(destination, kind) 251 $asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}, lsl \##{scaleShift}" 268 scaleShift.zero? \ 269 ? ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}") 270 : ($asm.puts "add #{destination.arm64Operand(kind)}, #{base.arm64Operand(kind)}, #{index.arm64Operand(kind)}, lsl \##{scaleShift}") 252 271 end 253 272 end … … 265 284 # 266 285 286 def isMalformedArm64LoadAStoreAddress(opcode, operand) 287 malformed = false 288 if operand.is_a? Address 289 case opcode 290 when "loadp", "storep", "loadq", "storeq" 291 if $currentSettings["ADDRESS64"] 292 malformed ||= (not (-255..32760).include? operand.offset.value) 293 malformed ||= (not (operand.offset.value % 8).zero?) 294 else 295 malformed ||= (not (-255..16380).include? operand.offset.value) 296 end 297 when "loadd", "stored" 298 malformed ||= (not (-255..32760).include? operand.offset.value) 299 malformed ||= (not (operand.offset.value % 8).zero?) 300 when "loadi", "loadis", "storei" 301 malformed ||= (not (-255..16380).include? operand.offset.value) 302 else 303 # This is just a conservative estimate of the max offset. 304 malformed ||= (not (-255..4095).include? operand.offset.value) 305 end 306 end 307 malformed 308 end 309 267 310 def arm64LowerMalformedLoadStoreAddresses(list) 268 311 newList = [] 269 270 def isAddressMalformed(opcode, operand)271 malformed = false272 if operand.is_a? Address273 malformed ||= (not (-255..4095).include? operand.offset.value)274 if opcode =~ /q$/ and $currentSettings["ADDRESS64"]275 malformed ||= operand.offset.value % 8276 end277 end278 malformed279 end280 312 281 313 list.each { 282 314 | node | 283 315 if node.is_a? Instruction 284 if node.opcode =~ /^store/ and is AddressMalformed(node.opcode, node.operands[1])316 if node.opcode =~ /^store/ and isMalformedArm64LoadAStoreAddress(node.opcode, node.operands[1]) 285 317 address = node.operands[1] 286 318 tmp = Tmp.new(codeOrigin, :gpr) 287 319 newList << Instruction.new(node.codeOrigin, "move", [address.offset, tmp]) 288 320 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) 289 elsif node.opcode =~ /^load/ and is AddressMalformed(node.opcode, node.operands[0])321 elsif node.opcode =~ /^load/ and isMalformedArm64LoadAStoreAddress(node.opcode, node.operands[0]) 290 322 address = node.operands[0] 291 323 tmp = Tmp.new(codeOrigin, :gpr) … … 400 432 (node.opcode =~ /^lea/ or address.scale == 1 or address.scale == size) 401 433 elsif address.is_a? Address 402 (-255..4095).include? address.offset.value434 not isMalformedArm64LoadAStoreAddress(node.opcode, address) 403 435 else 404 436 false … … 444 476 | node, address | 445 477 case node.opcode 446 when /^load/ 447 true 448 when /^store/ 449 not (address.is_a? Address and address.offset.value < 0) 478 when /^load/, /^store/ 479 not address.is_a? Address or not isMalformedArm64LoadAStoreAddress(node.opcode, address) 450 480 when /^lea/ 451 481 true … … 656 686 657 687 def emitARM64MoveImmediate(value, target) 658 first = true659 isNegative = value <0688 numberOfFilledHalfWords = 0 689 numberOfZeroHalfWords = 0 660 690 [48, 32, 16, 0].each { 661 691 | shift | 662 692 currentValue = (value >> shift) & 0xffff 663 next if currentValue == (isNegative ? 0xffff : 0) and (shift != 0 or !first) 693 if currentValue == 0xffff 694 numberOfFilledHalfWords += 1 695 end 696 if currentValue == 0 697 numberOfZeroHalfWords += 1 698 end 699 } 700 fillOtherHalfWordsWithOnes = (numberOfFilledHalfWords > numberOfZeroHalfWords) 701 702 first = true 703 [48, 32, 16, 0].each { 704 | shift | 705 currentValue = (value >> shift) & 0xffff 706 next if currentValue == (fillOtherHalfWordsWithOnes ? 0xffff : 0) and (shift != 0 or !first) 664 707 if first 665 if isNegative 666 $asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}, lsl \##{shift}" 667 else 668 $asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}" 708 if fillOtherHalfWordsWithOnes 709 shift.zero? \ 710 ? ($asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}") 711 : ($asm.puts "movn #{target.arm64Operand(:quad)}, \##{(~currentValue) & 0xffff}, lsl \##{shift}") 712 else 713 shift.zero? \ 714 ? ($asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}") 715 : ($asm.puts "movz #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}") 669 716 end 670 717 first = false 671 718 else 672 $asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}" 719 shift.zero? \ 720 ? ($asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}") 721 : ($asm.puts "movk #{target.arm64Operand(:quad)}, \##{currentValue}, lsl \##{shift}") 673 722 end 674 723 }
Note:
See TracChangeset
for help on using the changeset viewer.