Changeset 148790 in webkit for trunk/Source/JavaScriptCore/offlineasm/x86.rb
- Timestamp:
- Apr 20, 2013, 3:27:33 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/offlineasm/x86.rb
r147794 r148790 1 1 # Copyright (C) 2012 Apple Inc. All rights reserved. 2 # Copyright (C) 2013 Digia Plc. and/or its subsidiary(-ies) 2 3 # 3 4 # Redistribution and use in source and binary forms, with or without … … 35 36 end 36 37 38 def useX87 39 case $activeBackend 40 when "X86" 41 true 42 when "X86_64" 43 false 44 else 45 raise "bad value for $activeBackend: #{$activeBackend}" 46 end 47 end 48 37 49 class SpecialRegister < NoChildren 38 50 def x86Operand(kind) … … 256 268 def x86Operand(kind) 257 269 raise unless kind == :double 270 raise if useX87 258 271 case name 259 272 when "ft0", "fa0", "fr" … … 272 285 raise "Bad register #{name} for X86 at #{codeOriginString}" 273 286 end 287 end 288 def x87DefaultStackPosition 289 case name 290 when "ft0", "fr" 291 0 292 when "ft1" 293 1 294 when "ft2", "ft3", "ft4", "ft5" 295 raise "Unimplemented register #{name} for X86 at #{codeOriginString}" 296 else 297 raise "Bad register #{name} for X86 at #{codeOriginString}" 298 end 299 end 300 def x87Operand(offset) 301 raise unless useX87 302 raise unless offset == 0 or offset == 1 303 "%st(#{x87DefaultStackPosition + offset})" 274 304 end 275 305 def x86CallOperand(kind) … … 423 453 isX64 ? "q" : raise 424 454 when :double 425 "sd"455 not useX87 ? "sd" : raise 426 456 else 427 457 raise … … 479 509 480 510 def handleX86DoubleBranch(branchOpcode, mode) 481 case mode 482 when :normal 483 $asm.puts "ucomisd #{operands[1].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 484 when :reverse 485 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 486 else 487 raise mode.inspect 511 if useX87 512 handleX87Compare(mode) 513 else 514 case mode 515 when :normal 516 $asm.puts "ucomisd #{operands[1].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 517 when :reverse 518 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 519 else 520 raise mode.inspect 521 end 488 522 end 489 523 $asm.puts "#{branchOpcode} #{operands[2].asmLabel}" … … 585 619 $asm.puts "#{branchOpcode} #{jumpTarget.asmLabel}" 586 620 end 587 621 588 622 def handleX86Add(kind) 589 623 if operands.size == 3 and operands[1] == operands[2] … … 651 685 end 652 686 687 def handleX87Compare(mode) 688 case mode 689 when :normal 690 if (operands[0].x87DefaultStackPosition == 0) 691 $asm.puts "fucomi #{operands[1].x87Operand(0)}" 692 else 693 $asm.puts "fld #{operands[0].x87Operand(0)}" 694 $asm.puts "fucomip #{operands[1].x87Operand(1)}" 695 end 696 when :reverse 697 if (operands[1].x87DefaultStackPosition == 0) 698 $asm.puts "fucomi #{operands[0].x87Operand(0)}" 699 else 700 $asm.puts "fld #{operands[1].x87Operand(0)}" 701 $asm.puts "fucomip #{operands[0].x87Operand(1)}" 702 end 703 else 704 raise mode.inspect 705 end 706 end 707 708 def handleX87BinOp(opcode, opcodereverse) 709 if (operands[1].x87DefaultStackPosition == 0) 710 $asm.puts "#{opcode} #{operands[0].x87Operand(0)}, %st" 711 elsif (operands[0].x87DefaultStackPosition == 0) 712 $asm.puts "#{opcodereverse} %st, #{operands[1].x87Operand(0)}" 713 else 714 $asm.puts "fld #{operands[0].x87Operand(0)}" 715 $asm.puts "#{opcodereverse}p %st, #{operands[1].x87Operand(1)}" 716 end 717 end 718 653 719 def lowerX86 654 720 raise unless $activeBackend == "X86" … … 750 816 when "storeb" 751 817 $asm.puts "movb #{x86Operands(:byte, :byte)}" 752 when "loadd", "moved", "stored" 753 $asm.puts "movsd #{x86Operands(:double, :double)}" 818 when "loadd" 819 if useX87 820 $asm.puts "fldl #{operands[0].x86Operand(:double)}" 821 $asm.puts "fstp #{operands[1].x87Operand(1)}" 822 else 823 $asm.puts "movsd #{x86Operands(:double, :double)}" 824 end 825 when "moved" 826 if useX87 827 if (operands[0].x87DefaultStackPosition == 0) 828 $asm.puts "fst #{operands[1].x87Operand(0)}" 829 else 830 $asm.puts "fld #{operands[0].x87Operand(0)}" 831 $asm.puts "fstp #{operands[1].x87Operand(1)}" 832 end 833 else 834 $asm.puts "movsd #{x86Operands(:double, :double)}" 835 end 836 when "stored" 837 if useX87 838 if (operands[0].x87DefaultStackPosition == 0) 839 $asm.puts "fstl #{operands[1].x86Operand(:double)}" 840 else 841 $asm.puts "fld #{operands[0].x87Operand(0)}" 842 $asm.puts "fstpl #{operands[1].x86Operand(:double)}" 843 end 844 else 845 $asm.puts "movsd #{x86Operands(:double, :double)}" 846 end 754 847 when "addd" 755 $asm.puts "addsd #{x86Operands(:double, :double)}" 848 if useX87 849 handleX87BinOp("fadd", "fadd") 850 else 851 $asm.puts "addsd #{x86Operands(:double, :double)}" 852 end 853 when "muld" 854 if useX87 855 handleX87BinOp("fmul", "fmul") 856 else 857 $asm.puts "mulsd #{x86Operands(:double, :double)}" 858 end 859 when "subd" 860 if useX87 861 handleX87BinOp("fsub", "fsubr") 862 else 863 $asm.puts "subsd #{x86Operands(:double, :double)}" 864 end 756 865 when "divd" 757 $asm.puts "divsd #{x86Operands(:double, :double)}"758 when "subd"759 $asm.puts "subsd #{x86Operands(:double, :double)}"760 when "muld"761 $asm.puts "mulsd #{x86Operands(:double, :double)}"866 if useX87 867 handleX87BinOp("fdiv", "fdivr") 868 else 869 $asm.puts "divsd #{x86Operands(:double, :double)}" 870 end 762 871 when "sqrtd" 763 $asm.puts "sqrtsd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 872 if useX87 873 $asm.puts "fld #{operands[0].x87Operand(0)}" 874 $asm.puts "fsqrtl" 875 $asm.puts "fstp #{operands[1].x87Operand(1)}" 876 else 877 $asm.puts "sqrtsd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 878 end 764 879 when "ci2d" 765 $asm.puts "cvtsi2sd #{operands[0].x86Operand(:int)}, #{operands[1].x86Operand(:double)}" 880 if useX87 881 sp = RegisterID.new(nil, "sp") 882 $asm.puts "movl #{operands[0].x86Operand(:int)}, -4(#{sp.x86Operand(:ptr)})" 883 $asm.puts "fildl -4(#{sp.x86Operand(:ptr)})" 884 $asm.puts "fstp #{operands[1].x87Operand(1)}" 885 else 886 $asm.puts "cvtsi2sd #{operands[0].x86Operand(:int)}, #{operands[1].x86Operand(:double)}" 887 end 766 888 when "bdeq" 767 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 889 if useX87 890 handleX87Compare(:normal) 891 else 892 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 893 end 768 894 if operands[0] == operands[1] 769 895 # This is just a jump ordered, which is a jnp. … … 788 914 handleX86DoubleBranch("je", :normal) 789 915 when "bdnequn" 790 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 916 if useX87 917 handleX87Compare(:normal) 918 else 919 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 920 end 791 921 if operands[0] == operands[1] 792 922 # This is just a jump unordered, which is a jp. … … 810 940 handleX86DoubleBranch("jbe", :normal) 811 941 when "btd2i" 942 # FIXME: unused and unimplemented for x87 943 raise if useX87 812 944 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 813 945 $asm.puts "cmpl $0x80000000 #{operands[1].x86Operand(:int)}" 814 946 $asm.puts "je #{operands[2].asmLabel}" 815 947 when "td2i" 948 # FIXME: unused and unimplemented for x87 949 raise if useX87 816 950 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 817 951 when "bcd2i" 818 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 819 $asm.puts "testl #{operands[1].x86Operand(:int)}, #{operands[1].x86Operand(:int)}" 820 $asm.puts "je #{operands[2].asmLabel}" 821 $asm.puts "cvtsi2sd #{operands[1].x86Operand(:int)}, %xmm7" 822 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, %xmm7" 823 $asm.puts "jp #{operands[2].asmLabel}" 824 $asm.puts "jne #{operands[2].asmLabel}" 952 if useX87 953 sp = RegisterID.new(nil, "sp") 954 if (operands[0].x87DefaultStackPosition == 0) 955 $asm.puts "fistl -4(#{sp.x86Operand(:ptr)})" 956 else 957 $asm.puts "fld #{operands[0].x87Operand(0)}" 958 $asm.puts "fistpl -4(#{sp.x86Operand(:ptr)})" 959 end 960 $asm.puts "movl -4(#{sp.x86Operand(:ptr)}), #{operands[1].x86Operand(:int)}" 961 $asm.puts "testl #{operands[1].x86Operand(:int)}, #{operands[1].x86Operand(:int)}" 962 $asm.puts "je #{operands[2].asmLabel}" 963 $asm.puts "fildl -4(#{sp.x86Operand(:ptr)})" 964 $asm.puts "fucomip #{operands[0].x87Operand(1)}" 965 $asm.puts "jp #{operands[2].asmLabel}" 966 $asm.puts "jne #{operands[2].asmLabel}" 967 else 968 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 969 $asm.puts "testl #{operands[1].x86Operand(:int)}, #{operands[1].x86Operand(:int)}" 970 $asm.puts "je #{operands[2].asmLabel}" 971 $asm.puts "cvtsi2sd #{operands[1].x86Operand(:int)}, %xmm7" 972 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, %xmm7" 973 $asm.puts "jp #{operands[2].asmLabel}" 974 $asm.puts "jne #{operands[2].asmLabel}" 975 end 825 976 when "movdz" 826 $asm.puts "xorpd #{operands[0].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 977 if useX87 978 $asm.puts "fldzl" 979 $asm.puts "fstp #{operands[0].x87Operand(1)}" 980 else 981 $asm.puts "xorpd #{operands[0].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 982 end 827 983 when "pop" 828 984 $asm.puts "pop #{operands[0].x86Operand(:ptr)}" … … 1118 1274 $asm.puts "idivl #{operands[0].x86Operand(:int)}" 1119 1275 when "fii2d" 1120 $asm.puts "movd #{operands[0].x86Operand(:int)}, #{operands[2].x86Operand(:double)}" 1121 $asm.puts "movd #{operands[1].x86Operand(:int)}, %xmm7" 1122 $asm.puts "psllq $32, %xmm7" 1123 $asm.puts "por %xmm7, #{operands[2].x86Operand(:double)}" 1276 if useX87 1277 sp = RegisterID.new(nil, "sp") 1278 $asm.puts "movl #{operands[0].x86Operand(:int)}, -8(#{sp.x86Operand(:ptr)})" 1279 $asm.puts "movl #{operands[1].x86Operand(:int)}, -4(#{sp.x86Operand(:ptr)})" 1280 $asm.puts "fldl -8(#{sp.x86Operand(:ptr)})" 1281 $asm.puts "fstp #{operands[2].x87Operand(1)}" 1282 else 1283 $asm.puts "movd #{operands[0].x86Operand(:int)}, #{operands[2].x86Operand(:double)}" 1284 $asm.puts "movd #{operands[1].x86Operand(:int)}, %xmm7" 1285 $asm.puts "psllq $32, %xmm7" 1286 $asm.puts "por %xmm7, #{operands[2].x86Operand(:double)}" 1287 end 1124 1288 when "fd2ii" 1125 $asm.puts "movd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 1126 $asm.puts "movsd #{operands[0].x86Operand(:double)}, %xmm7" 1127 $asm.puts "psrlq $32, %xmm7" 1128 $asm.puts "movd %xmm7, #{operands[2].x86Operand(:int)}" 1289 if useX87 1290 sp = RegisterID.new(nil, "sp") 1291 if (operands[0].x87DefaultStackPosition == 0) 1292 $asm.puts "fstl -8(#{sp.x86Operand(:ptr)})" 1293 else 1294 $asm.puts "fld #{operands[0].x87Operand(0)}" 1295 $asm.puts "fstpl -8(#{sp.x86Operand(:ptr)})" 1296 end 1297 $asm.puts "movl -8(#{sp.x86Operand(:ptr)}), #{operands[1].x86Operand(:int)}" 1298 $asm.puts "movl -4(#{sp.x86Operand(:ptr)}), #{operands[2].x86Operand(:int)}" 1299 else 1300 $asm.puts "movd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 1301 $asm.puts "movsd #{operands[0].x86Operand(:double)}, %xmm7" 1302 $asm.puts "psrlq $32, %xmm7" 1303 $asm.puts "movd %xmm7, #{operands[2].x86Operand(:int)}" 1304 end 1129 1305 when "fq2d" 1130 $asm.puts "movd #{operands[0].x86Operand(:quad)}, #{operands[1].x86Operand(:double)}" 1306 if useX87 1307 sp = RegisterID.new(nil, "sp") 1308 $asm.puts "movq #{operands[0].x86Operand(:quad)}, -8(#{sp.x86Operand(:ptr)})" 1309 $asm.puts "fldl -8(#{sp.x86Operand(:ptr)})" 1310 $asm.puts "fstp #{operands[1].x87Operand(1)}" 1311 else 1312 $asm.puts "movq #{operands[0].x86Operand(:quad)}, #{operands[1].x86Operand(:double)}" 1313 end 1131 1314 when "fd2q" 1132 $asm.puts "movd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:quad)}" 1315 if useX87 1316 sp = RegisterID.new(nil, "sp") 1317 if (operands[0].x87DefaultStackPosition == 0) 1318 $asm.puts "fstl -8(#{sp.x86Operand(:ptr)})" 1319 else 1320 $asm.puts "fld #{operands[0].x87Operand(0)}" 1321 $asm.puts "fstpl -8(#{sp.x86Operand(:ptr)})" 1322 end 1323 $asm.puts "movq -8(#{sp.x86Operand(:ptr)}), #{operands[1].x86Operand(:quad)}" 1324 else 1325 $asm.puts "movq #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:quad)}" 1326 end 1133 1327 when "bo" 1134 1328 $asm.puts "jo #{operands[0].asmLabel}" … … 1143 1337 when "leap" 1144 1338 $asm.puts "lea#{x86Suffix(:ptr)} #{operands[0].x86AddressOperand(:ptr)}, #{operands[1].x86Operand(:ptr)}" 1339 when "resetX87Stack" 1340 if useX87 1341 2.times { 1342 | offset | 1343 $asm.puts "ffree %st(#{offset})" 1344 } 1345 end 1145 1346 else 1146 1347 lowerDefault
Note:
See TracChangeset
for help on using the changeset viewer.