Changeset 147794 in webkit for trunk/Source/JavaScriptCore/offlineasm/x86.rb
- Timestamp:
- Apr 5, 2013, 1:41:01 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/offlineasm/x86.rb
r147729 r147794 35 35 end 36 36 37 def useX8738 case $activeBackend39 when "X86"40 true41 when "X86_64"42 false43 else44 raise "bad value for $activeBackend: #{$activeBackend}"45 end46 end47 48 37 class SpecialRegister < NoChildren 49 38 def x86Operand(kind) … … 267 256 def x86Operand(kind) 268 257 raise unless kind == :double 269 raise if useX87270 258 case name 271 259 when "ft0", "fa0", "fr" … … 281 269 when "ft5" 282 270 "%xmm5" 283 else284 raise "Bad register #{name} for X86 at #{codeOriginString}"285 end286 end287 def x87Operand(offset)288 raise unless useX87289 raise unless offset == 0 or offset == 1290 case name291 when "ft0", "fa0", "fr"292 "%st(#{0 + offset})"293 when "ft1", "fa1"294 "%st(#{1 + offset})"295 when "ft2", "fa2"296 "%st(#{2 + offset})"297 when "ft3", "fa3"298 "%st(#{3 + offset})"299 when "ft4"300 "%st(#{4 + offset})"301 when "ft5"302 "%st(#{5 + offset})"303 271 else 304 272 raise "Bad register #{name} for X86 at #{codeOriginString}" … … 455 423 isX64 ? "q" : raise 456 424 when :double 457 not useX87 ? "sd" : raise425 "sd" 458 426 else 459 427 raise … … 511 479 512 480 def handleX86DoubleBranch(branchOpcode, mode) 513 if useX87 514 case mode 515 when :normal 516 $asm.puts "fld #{operands[0].x87Operand(0)}" 517 $asm.puts "fucomip #{operands[1].x87Operand(1)}" 518 when :reverse 519 $asm.puts "fld #{operands[1].x87Operand(0)}" 520 $asm.puts "fucomip #{operands[0].x87Operand(1)}" 521 else 522 raise mode.inspect 523 end 524 else 525 case mode 526 when :normal 527 $asm.puts "ucomisd #{operands[1].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 528 when :reverse 529 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 530 else 531 raise mode.inspect 532 end 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 533 488 end 534 489 $asm.puts "#{branchOpcode} #{operands[2].asmLabel}" … … 795 750 when "storeb" 796 751 $asm.puts "movb #{x86Operands(:byte, :byte)}" 797 when "loadd" 798 if useX87 799 $asm.puts "fldl #{operands[0].x86Operand(:double)}" 800 $asm.puts "fstp #{operands[1].x87Operand(1)}" 801 else 802 $asm.puts "movsd #{x86Operands(:double, :double)}" 803 end 804 when "moved" 805 if useX87 806 $asm.puts "fld #{operands[0].x87Operand(0)}" 807 $asm.puts "fstp #{operands[0].x87Operand(1)}" 808 else 809 $asm.puts "movsd #{x86Operands(:double, :double)}" 810 end 811 when "stored" 812 if useX87 813 $asm.puts "fld #{operands[0].x87Operand(0)}" 814 $asm.puts "fstpl #{operands[1].x86Operand(:double)}" 815 else 816 $asm.puts "movsd #{x86Operands(:double, :double)}" 817 end 752 when "loadd", "moved", "stored" 753 $asm.puts "movsd #{x86Operands(:double, :double)}" 818 754 when "addd" 819 if useX87 820 $asm.puts "fld #{operands[0].x87Operand(0)}" 821 $asm.puts "faddp %st, #{operands[1].x87Operand(1)}" 822 else 823 $asm.puts "addsd #{x86Operands(:double, :double)}" 824 end 755 $asm.puts "addsd #{x86Operands(:double, :double)}" 825 756 when "divd" 826 if useX87 827 $asm.puts "fld #{operands[0].x87Operand(0)}" 828 $asm.puts "fdivrp %st, #{operands[1].x87Operand(1)}" 829 else 830 $asm.puts "divsd #{x86Operands(:double, :double)}" 831 end 757 $asm.puts "divsd #{x86Operands(:double, :double)}" 832 758 when "subd" 833 if useX87 834 $asm.puts "fld #{operands[0].x87Operand(0)}" 835 $asm.puts "fsubrp %st, #{operands[1].x87Operand(1)}" 836 else 837 $asm.puts "subsd #{x86Operands(:double, :double)}" 838 end 759 $asm.puts "subsd #{x86Operands(:double, :double)}" 839 760 when "muld" 840 if useX87 841 $asm.puts "fld #{operands[0].x87Operand(0)}" 842 $asm.puts "fmulp %st, #{operands[1].x87Operand(1)}" 843 else 844 $asm.puts "mulsd #{x86Operands(:double, :double)}" 845 end 761 $asm.puts "mulsd #{x86Operands(:double, :double)}" 846 762 when "sqrtd" 847 if useX87 848 $asm.puts "fld #{operands[0].x87Operand(0)}" 849 $asm.puts "fsqrtl" 850 $asm.puts "fstp #{operands[1].x87Operand(1)}" 851 else 852 $asm.puts "sqrtsd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 853 end 763 $asm.puts "sqrtsd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 854 764 when "ci2d" 855 if useX87 856 if isX64 857 $asm.puts "sub#{x86Suffix(:ptr)} $4, %rsp" 858 $asm.puts "movl #{operands[0].x86Operand(:int)}, 0(%rsp)" 859 $asm.puts "fildl 0(%rsp)" 860 $asm.puts "add#{x86Suffix(:ptr)} $4, %rsp" 861 else 862 $asm.puts "sub#{x86Suffix(:ptr)} $4, %esp" 863 $asm.puts "movl #{operands[0].x86Operand(:int)}, 0(%esp)" 864 $asm.puts "fildl 0(%esp)" 865 $asm.puts "add#{x86Suffix(:ptr)} $4, %esp" 866 end 867 $asm.puts "fstp #{operands[1].x87Operand(1)}" 868 else 869 $asm.puts "cvtsi2sd #{operands[0].x86Operand(:int)}, #{operands[1].x86Operand(:double)}" 870 end 765 $asm.puts "cvtsi2sd #{operands[0].x86Operand(:int)}, #{operands[1].x86Operand(:double)}" 871 766 when "bdeq" 872 if useX87 873 $asm.puts "fld #{operands[1].x87Operand(0)}" 874 $asm.puts "fucomip #{operands[0].x87Operand(1)}" 875 else 876 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 877 end 767 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 878 768 if operands[0] == operands[1] 879 769 # This is just a jump ordered, which is a jnp. … … 898 788 handleX86DoubleBranch("je", :normal) 899 789 when "bdnequn" 900 if useX87 901 $asm.puts "fld #{operands[1].x87Operand(0)}" 902 $asm.puts "fucomip #{operands[0].x87Operand(1)}" 903 else 904 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 905 end 790 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:double)}" 906 791 if operands[0] == operands[1] 907 792 # This is just a jump unordered, which is a jp. … … 925 810 handleX86DoubleBranch("jbe", :normal) 926 811 when "btd2i" 927 # FIXME: unused and unimplemented for x87928 raise if useX87929 812 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 930 813 $asm.puts "cmpl $0x80000000 #{operands[1].x86Operand(:int)}" 931 814 $asm.puts "je #{operands[2].asmLabel}" 932 815 when "td2i" 933 # FIXME: unused and unimplemented for x87934 raise if useX87935 816 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 936 817 when "bcd2i" 937 if useX87 938 raise if isX64 939 $asm.puts "fld #{operands[0].x87Operand(0)}" 940 $asm.puts "sub#{x86Suffix(:ptr)} $4, %esp" 941 $asm.puts "fistl 0(%esp)" 942 $asm.puts "ficomp 0(%esp)" 943 $asm.puts "popl #{operands[1].x86Operand(:int)}" 944 $asm.puts "jp #{operands[2].asmLabel}" 945 $asm.puts "jne #{operands[2].asmLabel}" 946 else 947 $asm.puts "cvttsd2si #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 948 $asm.puts "testl #{operands[1].x86Operand(:int)}, #{operands[1].x86Operand(:int)}" 949 $asm.puts "je #{operands[2].asmLabel}" 950 $asm.puts "cvtsi2sd #{operands[1].x86Operand(:int)}, %xmm7" 951 $asm.puts "ucomisd #{operands[0].x86Operand(:double)}, %xmm7" 952 $asm.puts "jp #{operands[2].asmLabel}" 953 $asm.puts "jne #{operands[2].asmLabel}" 954 end 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}" 955 825 when "movdz" 956 if useX87 957 $asm.puts "fldzl" 958 $asm.puts "fstp #{operands[0].x87Operand(1)}" 959 else 960 $asm.puts "xorpd #{operands[0].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 961 end 826 $asm.puts "xorpd #{operands[0].x86Operand(:double)}, #{operands[0].x86Operand(:double)}" 962 827 when "pop" 963 828 $asm.puts "pop #{operands[0].x86Operand(:ptr)}" … … 1253 1118 $asm.puts "idivl #{operands[0].x86Operand(:int)}" 1254 1119 when "fii2d" 1255 if useX87 1256 raise if isX64 1257 $asm.puts "sub#{x86Suffix(:ptr)} $8, %esp" 1258 $asm.puts "movl #{operands[0].x86Operand(:int)}, 0(%esp)" 1259 $asm.puts "movl #{operands[1].x86Operand(:int)}, 4(%esp)" 1260 $asm.puts "fldl 0(%esp)" 1261 $asm.puts "add#{x86Suffix(:ptr)} $8, %esp" 1262 $asm.puts "fstp #{operands[2].x87Operand(1)}" 1263 else 1264 $asm.puts "movd #{operands[0].x86Operand(:int)}, #{operands[2].x86Operand(:double)}" 1265 $asm.puts "movd #{operands[1].x86Operand(:int)}, %xmm7" 1266 $asm.puts "psllq $32, %xmm7" 1267 $asm.puts "por %xmm7, #{operands[2].x86Operand(:double)}" 1268 end 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)}" 1269 1124 when "fd2ii" 1270 if useX87 1271 raise if isX64 1272 $asm.puts "fld #{operands[0].x87Operand(0)}" 1273 $asm.puts "sub#{x86Suffix(:ptr)} $8, %esp" 1274 $asm.puts "fstpl 0(%esp)" 1275 $asm.puts "movl 0(%esp), #{operands[1].x86Operand(:int)}" 1276 $asm.puts "movl 4(%esp), #{operands[2].x86Operand(:int)}" 1277 $asm.puts "add#{x86Suffix(:ptr)} $8, %esp" 1278 else 1279 $asm.puts "movd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:int)}" 1280 $asm.puts "movsd #{operands[0].x86Operand(:double)}, %xmm7" 1281 $asm.puts "psrlq $32, %xmm7" 1282 $asm.puts "movd %xmm7, #{operands[2].x86Operand(:int)}" 1283 end 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)}" 1284 1129 when "fq2d" 1285 if useX87 1286 raise unless isX64 1287 $asm.puts "push #{operands[0].x86Operand(:quad)}" 1288 $asm.puts "fldl 0(%rsp)" 1289 $asm.puts "add#{x86Suffix(:ptr)} $8, %rsp" 1290 $asm.puts "fstp #{operands[1].x87Operand(1)}" 1291 else 1292 $asm.puts "movq #{operands[0].x86Operand(:quad)}, #{operands[1].x86Operand(:double)}" 1293 end 1130 $asm.puts "movd #{operands[0].x86Operand(:quad)}, #{operands[1].x86Operand(:double)}" 1294 1131 when "fd2q" 1295 if useX87 1296 raise unless isX64 1297 $asm.puts "fld #{operands[0].x87Operand(0)}" 1298 $asm.puts "sub#{x86Suffix(:ptr)} $8, %rsp" 1299 $asm.puts "fstpl 0(%rsp)" 1300 $asm.puts "pop #{operands[1].x86Operand(:quad)}" 1301 else 1302 $asm.puts "movq #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:quad)}" 1303 end 1132 $asm.puts "movd #{operands[0].x86Operand(:double)}, #{operands[1].x86Operand(:quad)}" 1304 1133 when "bo" 1305 1134 $asm.puts "jo #{operands[0].asmLabel}"
Note:
See TracChangeset
for help on using the changeset viewer.