1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693
|
/*
* Copyright (C) 2019-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "WasmAirIRGeneratorBase.h"
#include "WasmThunks.h"
#include <cstddef>
#if USE(JSVALUE64) && ENABLE(WEBASSEMBLY_B3JIT)
namespace JSC { namespace Wasm {
////////////////////////////////////////////////////////////////////////////////
// 64-bit AirIRGenerator
////////////////////////////////////////////////////////////////////////////////
class TypedTmp {
public:
constexpr TypedTmp()
: m_tmp()
, m_type(Types::Void)
{
}
TypedTmp(Tmp tmp, Type type)
: m_tmp(tmp)
, m_type(type)
{
}
TypedTmp(const TypedTmp&) = default;
TypedTmp(TypedTmp&&) = default;
TypedTmp& operator=(TypedTmp&&) = default;
TypedTmp& operator=(const TypedTmp&) = default;
bool operator==(const TypedTmp& other) const
{
return m_tmp == other.m_tmp && m_type == other.m_type;
}
explicit operator bool() const { return !!tmp(); }
operator Tmp() const { return tmp(); }
operator Arg() const { return Arg(tmp()); }
Tmp tmp() const { return m_tmp; }
Type type() const { return m_type; }
TypedTmp coerce(Type type) const
{
return TypedTmp(m_tmp, type);
}
void dump(PrintStream& out) const
{
out.print("(", m_tmp, ", ", m_type.kind, ", ", m_type.index, ")");
}
private:
Tmp m_tmp;
Type m_type;
};
class AirIRGenerator64 : public AirIRGeneratorBase<AirIRGenerator64, TypedTmp> {
public:
friend AirIRGeneratorBase<AirIRGenerator64, TypedTmp>;
using ExpressionType = TypedTmp;
static ExpressionType emptyExpression() { return { }; };
AirIRGenerator64(const ModuleInformation&, Callee&, B3::Procedure&, Vector<UnlinkedWasmToWasmCall>&, MemoryMode, unsigned functionIndex, std::optional<bool> hasExceptionHandlers, TierUpCount*, const TypeDefinition&, unsigned& osrEntryScratchBufferSize);
static constexpr bool tierSupportsSIMD = true;
static constexpr bool generatesB3OriginData = true;
static constexpr bool supportsPinnedStateRegisters = true;
void finalizeEntrypoints();
void emitMaterializeConstant(Type, uint64_t value, TypedTmp& dest);
void emitMaterializeConstant(BasicBlock*, Type, uint64_t value, TypedTmp& dest);
ExpressionType addConstant(Type, uint64_t);
ExpressionType addConstant(BasicBlock*, Type, uint64_t);
ExpressionType addConstant(v128_t);
ExpressionType addConstantZero(Type);
ExpressionType addConstantZero(BasicBlock*, Type);
// This pair of operations is used when we need to call into a JIT operation with
// some arbitrary wasm value--we need a TypedTmp with a uniform size, and all
// wasm values can be stuffed into an i64
//
// `emitCoerceFromI64` is pretty unsafe--nothing checks that the source tmp makes
// any sense as the requested type; proceed with caution.
void emitCoerceToI64(const TypedTmp& src, TypedTmp& result);
void emitCoerceFromI64(Type, const TypedTmp& src, TypedTmp& result);
// References
PartialResult WARN_UNUSED_RETURN addRefIsNull(ExpressionType value, ExpressionType& result);
// Memory
PartialResult WARN_UNUSED_RETURN load(LoadOpType, ExpressionType pointer, ExpressionType& result, uint32_t offset);
PartialResult WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
// GC
PartialResult WARN_UNUSED_RETURN addI31New(ExpressionType value, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI31GetS(ExpressionType ref, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI31GetU(ExpressionType ref, ExpressionType& result);
// SIMD
void notifyFunctionUsesSIMD() { ASSERT(m_info.usesSIMD(m_functionIndex)); }
PartialResult WARN_UNUSED_RETURN addSIMDLoad(ExpressionType pointer, uint32_t offset, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDStore(ExpressionType value, ExpressionType pointer, uint32_t offset);
PartialResult WARN_UNUSED_RETURN addSIMDSplat(SIMDLane, ExpressionType scalar, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDShuffle(v128_t imm, ExpressionType a, ExpressionType b, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDShift(SIMDLaneOperation, SIMDInfo, ExpressionType v, ExpressionType shift, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDExtmul(SIMDLaneOperation, SIMDInfo, ExpressionType lhs, ExpressionType rhs, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDLoadSplat(SIMDLaneOperation, ExpressionType pointer, uint32_t offset, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDLoadLane(SIMDLaneOperation, ExpressionType pointer, ExpressionType vector, uint32_t offset, uint8_t laneIndex, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDStoreLane(SIMDLaneOperation, ExpressionType pointer, ExpressionType vector, uint32_t offset, uint8_t laneIndex);
PartialResult WARN_UNUSED_RETURN addSIMDLoadExtend(SIMDLaneOperation, ExpressionType pointer, uint32_t offset, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addSIMDLoadPad(SIMDLaneOperation, ExpressionType pointer, uint32_t offset, ExpressionType& result);
// SIMD generated
#define DEFINE_AIR_OP_FOR_SIGNED_OP(OP) \
ALWAYS_INLINE constexpr B3::Air::Opcode airOpForSIMD##OP(SIMDInfo info) { \
switch (info.signMode) { \
case SIMDSignMode::Unsigned: \
switch (info.lane) { \
case SIMDLane::i8x16: return B3::Air::Vector##OP##UnsignedInt8; \
case SIMDLane::i16x8: return B3::Air::Vector##OP##UnsignedInt16; \
default: break; \
} \
break; \
case SIMDSignMode::Signed: \
switch (info.lane) { \
case SIMDLane::i8x16: return B3::Air::Vector##OP##SignedInt8; \
case SIMDLane::i16x8: return B3::Air::Vector##OP##SignedInt16; \
default: break; \
} \
break; \
case SIMDSignMode::None: \
switch (info.lane) { \
case SIMDLane::i32x4: return B3::Air::Vector##OP##Int32; \
case SIMDLane::i64x2: return B3::Air::Vector##OP##Int64; \
case SIMDLane::f32x4: return B3::Air::Vector##OP##Float32; \
case SIMDLane::f64x2: return B3::Air::Vector##OP##Float64; \
default: break; \
} \
break; \
} \
RELEASE_ASSERT_NOT_REACHED(); \
return Oops; \
}
#define DEFINE_AIR_OP_FOR_UNSIGNED_OP(OP) \
ALWAYS_INLINE constexpr B3::Air::Opcode airOpForSIMD##OP(SIMDInfo info) { \
switch (info.signMode) { \
case SIMDSignMode::None: \
switch (info.lane) { \
case SIMDLane::i8x16: return B3::Air::Vector##OP##Int8; \
case SIMDLane::i16x8: return B3::Air::Vector##OP##Int16; \
case SIMDLane::i32x4: return B3::Air::Vector##OP##Int32; \
case SIMDLane::i64x2: return B3::Air::Vector##OP##Int64; \
case SIMDLane::f32x4: return B3::Air::Vector##OP##Float32; \
case SIMDLane::f64x2: return B3::Air::Vector##OP##Float64; \
default: break; \
} \
break; \
default: break; \
} \
RELEASE_ASSERT_NOT_REACHED(); \
return Oops; \
}
#define AIR_OP_CASE(OP) \
else if (op == SIMDLaneOperation::OP) airOp = B3::Air::Vector##OP;
#define AIR_OP_CASES() \
B3::Air::Opcode airOp = B3::Air::Oops; \
if (false) { }
DEFINE_AIR_OP_FOR_SIGNED_OP(ExtractLane)
auto addExtractLane(SIMDInfo info, uint8_t lane, ExpressionType v, ExpressionType& result) -> PartialResult
{
auto airOp = airOpForSIMDExtractLane(info);
result = tmpForType(simdScalarType(info.lane));
if (isValidForm(airOp, Arg::Imm, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::imm(lane), v, result);
return { };
}
if (isValidForm(airOp, Arg::Imm, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::imm(lane), Arg::simdInfo(info), v, result);
return { };
}
RELEASE_ASSERT_NOT_REACHED();
return { };
}
DEFINE_AIR_OP_FOR_UNSIGNED_OP(ReplaceLane)
auto addReplaceLane(SIMDInfo info, uint8_t imm, ExpressionType v, ExpressionType s, ExpressionType& result) -> PartialResult
{
auto airOp = airOpForSIMDReplaceLane(info);
result = tmpForType(Types::V128);
append(MoveVector, v, result);
append(airOp, Arg::imm(imm), s, result);
return { };
}
auto addSIMDI_V(SIMDLaneOperation op, SIMDInfo info, ExpressionType v, ExpressionType& result) -> PartialResult
{
AIR_OP_CASES()
AIR_OP_CASE(Bitmask)
AIR_OP_CASE(AnyTrue)
AIR_OP_CASE(AllTrue)
result = tmpForType(Types::I32);
if (isValidForm(airOp, Arg::Tmp, Arg::Tmp)) {
append(airOp, v, result);
return { };
}
if (isValidForm(airOp, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::simdInfo(info), v, result);
return { };
}
if (isValidForm(airOp, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::simdInfo(info), v, result, tmpForType(Types::V128));
return { };
}
RELEASE_ASSERT_NOT_REACHED();
return { };
}
auto addSIMDV_V(SIMDLaneOperation op, SIMDInfo info, ExpressionType v, ExpressionType& result) -> PartialResult
{
AIR_OP_CASES()
AIR_OP_CASE(Demote)
AIR_OP_CASE(Promote)
AIR_OP_CASE(Abs)
AIR_OP_CASE(Popcnt)
AIR_OP_CASE(Ceil)
AIR_OP_CASE(Floor)
AIR_OP_CASE(Trunc)
AIR_OP_CASE(Nearest)
AIR_OP_CASE(Sqrt)
AIR_OP_CASE(ExtaddPairwise)
AIR_OP_CASE(Convert)
AIR_OP_CASE(ConvertLow)
AIR_OP_CASE(ExtendHigh)
AIR_OP_CASE(ExtendLow)
AIR_OP_CASE(TruncSat)
AIR_OP_CASE(Not)
AIR_OP_CASE(Neg)
else if (op == SIMDLaneOperation::RelaxedTruncSat) airOp = B3::Air::VectorTruncSat;
result = tmpForType(Types::V128);
if (isX86()) {
if (airOp == B3::Air::VectorPopcnt) {
ASSERT(info.lane == SIMDLane::i8x16);
// x86_64 does not natively support vector lanewise popcount, so we emulate it using multiple
// masks.
v128_t bottomNibbleConst;
v128_t popcntConst;
bottomNibbleConst.u64x2[0] = 0x0f0f0f0f0f0f0f0f;
bottomNibbleConst.u64x2[1] = 0x0f0f0f0f0f0f0f0f;
popcntConst.u64x2[0] = 0x0302020102010100;
popcntConst.u64x2[1] = 0x0403030203020201;
TypedTmp bottomNibbleMask = addConstant(bottomNibbleConst), popcntMask = addConstant(popcntConst);
TypedTmp tmp = tmpForType(Types::V128);
result = tmpForType(Types::V128);
append(VectorAndnot, Arg::simdInfo(SIMDLane::v128), v, bottomNibbleMask, tmp);
append(VectorAnd, Arg::simdInfo(SIMDLane::v128), v, bottomNibbleMask, result);
append(VectorUshr8, Arg::simdInfo(SIMDLane::i16x8), tmp, Arg::imm(4), tmp);
append(VectorSwizzle, popcntMask, result, result);
append(VectorSwizzle, popcntMask, tmp, tmp);
append(VectorAdd, Arg::simdInfo(SIMDLane::i8x16), result, tmp, result);
return { };
}
if (airOp == B3::Air::VectorNot) {
// x86_64 has no vector bitwise NOT instruction, so we expand vxv.not v into vxv.xor -1, v
// here to give B3/Air a chance to optimize out repeated usage of the mask.
v128_t mask;
mask.u64x2[0] = 0xffffffffffffffff;
mask.u64x2[1] = 0xffffffffffffffff;
TypedTmp ones = addConstant(mask);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), ones, v, result);
return { };
}
if (airOp == B3::Air::VectorNeg) {
// x86_64 has no vector negate instruction. For integer vectors, we can replicate negation by
// subtracting from zero. For floating-point vectors, we need to toggle the sign using packed
// XOR.
switch (info.lane) {
case SIMDLane::i8x16:
case SIMDLane::i16x8:
case SIMDLane::i32x4:
case SIMDLane::i64x2: {
TypedTmp zero = addConstant(v128_t());
append(VectorSub, Arg::simdInfo(info), zero, v, result);
break;
}
case SIMDLane::f32x4: {
TypedTmp gptmp = tmpForType(Types::I32);
TypedTmp fptmp = tmpForType(Types::V128);
append(Move, Arg::bigImm(0x80000000), gptmp);
append(Move32ToFloat, gptmp, fptmp);
append(VectorSplatFloat32, fptmp, fptmp);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), v, fptmp, result);
break;
}
case SIMDLane::f64x2: {
TypedTmp gptmp = tmpForType(Types::I64);
TypedTmp fptmp = tmpForType(Types::V128);
append(Move, Arg::bigImm(0x8000000000000000), gptmp);
append(Move64ToDouble, gptmp, fptmp);
append(VectorSplatFloat64, fptmp, fptmp);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), v, fptmp, result);
break;
}
default:
RELEASE_ASSERT_NOT_REACHED();
}
return { };
}
if (airOp == B3::Air::VectorAbs && info.lane == SIMDLane::i64x2) {
append(VectorAbsInt64, v, result, tmpForType(Types::V128));
return { };
}
if (airOp == B3::Air::VectorConvert && info.signMode == SIMDSignMode::Unsigned) {
append(VectorConvertUnsigned, v, result, tmpForType(Types::V128));
return { };
}
if (airOp == B3::Air::VectorConvertLow) {
if (info.signMode == SIMDSignMode::Signed)
append(VectorConvertLowSignedInt32, v, result);
else
append(VectorConvertLowUnsignedInt32, v, result, tmpForType(Types::I64), tmpForType(Types::V128));
return { };
}
if (airOp == B3::Air::VectorTruncSat) {
switch (info.lane) {
case SIMDLane::f64x2:
if (info.signMode == SIMDSignMode::Signed)
append(VectorTruncSatSignedFloat64, v, result, tmpForType(Types::I64), tmpForType(Types::V128));
else
append(VectorTruncSatUnsignedFloat64, v, result, tmpForType(Types::I64), tmpForType(Types::V128));
return { };
case SIMDLane::f32x4:
if (info.signMode == SIMDSignMode::Signed)
append(airOp, Arg::simdInfo(info), v, result, tmpForType(Types::I64), tmpForType(Types::V128), tmpForType(Types::V128));
else
append(VectorTruncSatUnsignedFloat32, v, result, tmpForType(Types::I64), tmpForType(Types::V128), tmpForType(Types::V128));
return { };
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
}
if (isX86() && airOp == VectorExtaddPairwise) {
append(airOp, Arg::simdInfo(info), v, result, tmpForType(Types::I64), tmpForType(Types::V128));
return { };
}
if (isValidForm(airOp, Arg::Tmp, Arg::Tmp)) {
append(airOp, v, result);
return { };
}
if (isValidForm(airOp, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::simdInfo(info), v, result);
return { };
}
RELEASE_ASSERT_NOT_REACHED();
return { };
}
auto addSIMDBitwiseSelect(ExpressionType v1, ExpressionType v2, ExpressionType c, ExpressionType& result) -> PartialResult
{
auto airOp = B3::Air::VectorBitwiseSelect;
result = tmpForType(Types::V128);
append(MoveVector, c, result);
append(airOp, v1, v2, result);
return { };
}
auto addSIMDRelOp(SIMDLaneOperation, SIMDInfo info, ExpressionType lhs, ExpressionType rhs, Arg relOp, ExpressionType& result) -> PartialResult
{
AIR_OP_CASES()
else if (scalarTypeIsFloatingPoint(info.lane))
airOp = B3::Air::CompareFloatingPointVector;
else if (scalarTypeIsIntegral(info.lane))
airOp = B3::Air::CompareIntegerVector;
result = tmpForType(Types::V128);
if (isValidForm(airOp, Arg::DoubleCond, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, relOp, Arg::simdInfo(info), lhs, rhs, result);
return { };
}
if constexpr (isX86()) {
if (isValidForm(airOp, Arg::RelCond, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
// On Intel, the best codegen for a bitwise-complement of an integer vector is to
// XOR with a vector of all ones. This is necessary here since Intel also doesn't
// directly implement most relational conditions between vectors: the cases below
// are best emitted as inversions of conditions that are supported.
v128_t allOnes;
allOnes.u64x2[0] = 0xffffffffffffffff;
allOnes.u64x2[1] = 0xffffffffffffffff;
auto scratch = tmpForType(Types::V128);
switch (relOp.asRelationalCondition()) {
case MacroAssembler::NotEqual:
append(airOp, Arg::relCond(MacroAssembler::Equal), Arg::simdInfo(info), lhs, rhs, result, scratch);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), result, addConstant(allOnes), result);
break;
case MacroAssembler::Above:
append(airOp, Arg::relCond(MacroAssembler::BelowOrEqual), Arg::simdInfo(info), lhs, rhs, result, scratch);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), result, addConstant(allOnes), result);
break;
case MacroAssembler::Below:
append(airOp, Arg::relCond(MacroAssembler::AboveOrEqual), Arg::simdInfo(info), lhs, rhs, result, scratch);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), result, addConstant(allOnes), result);
break;
case MacroAssembler::GreaterThanOrEqual:
if (info.lane == SIMDLane::i64x2) {
// Note: rhs and lhs are reversed here, we are semantically negating LessThan. GreaterThan is
// just better supported on AVX.
append(airOp, Arg::relCond(MacroAssembler::GreaterThan), Arg::simdInfo(info), rhs, lhs, result, scratch);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), result, addConstant(allOnes), result);
} else
append(airOp, relOp, Arg::simdInfo(info), lhs, rhs, result, scratch);
break;
case MacroAssembler::LessThanOrEqual:
if (info.lane == SIMDLane::i64x2) {
append(airOp, Arg::relCond(MacroAssembler::GreaterThan), Arg::simdInfo(info), lhs, rhs, result, scratch);
append(VectorXor, Arg::simdInfo({ SIMDLane::v128, SIMDSignMode::None }), result, addConstant(allOnes), result);
} else
append(airOp, relOp, Arg::simdInfo(info), lhs, rhs, result, scratch);
break;
default:
append(airOp, relOp, Arg::simdInfo(info), lhs, rhs, result, scratch);
}
return { };
}
}
if (isValidForm(airOp, Arg::RelCond, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, relOp, Arg::simdInfo(info), lhs, rhs, result);
return { };
}
RELEASE_ASSERT_NOT_REACHED();
return { };
}
auto fixupOutOfBoundsIndicesForSwizzle(ExpressionType& a, ExpressionType& b, ExpressionType& result) -> PartialResult
{
ASSERT(isX86() && result.type() == Types::V128);
// Let each byte mask be 112 (0x70) then after VectorAddSat
// each index > 15 would set the saturated index's bit 7 to 1,
// whose corresponding byte will be zero cleared in VectorSwizzle.
// https://github.com/WebAssembly/simd/issues/93
v128_t mask;
mask.u64x2[0] = 0x7070707070707070;
mask.u64x2[1] = 0x7070707070707070;
auto saturatedIndexes = addConstant(mask);
append(VectorAddSat, Arg::simdInfo(SIMDInfo { SIMDLane::i8x16, SIMDSignMode::Unsigned }), saturatedIndexes, b, saturatedIndexes);
append(B3::Air::VectorSwizzle, a, saturatedIndexes, result);
return { };
}
auto addSIMDV_VV(SIMDLaneOperation op, SIMDInfo info, ExpressionType a, ExpressionType b, ExpressionType& result) -> PartialResult
{
AIR_OP_CASES()
AIR_OP_CASE(And)
AIR_OP_CASE(Andnot)
AIR_OP_CASE(AvgRound)
AIR_OP_CASE(DotProduct)
AIR_OP_CASE(Add)
AIR_OP_CASE(Mul)
AIR_OP_CASE(MulSat)
AIR_OP_CASE(Sub)
AIR_OP_CASE(Div)
AIR_OP_CASE(Pmax)
AIR_OP_CASE(Pmin)
AIR_OP_CASE(Or)
AIR_OP_CASE(Swizzle)
AIR_OP_CASE(Xor)
AIR_OP_CASE(Narrow)
AIR_OP_CASE(AddSat)
AIR_OP_CASE(SubSat)
AIR_OP_CASE(Max)
AIR_OP_CASE(Min)
// Relaxed SIMD redirecting to non-relaxed:
else if (op == SIMDLaneOperation::RelaxedSwizzle) airOp = B3::Air::VectorSwizzle;
result = tmpForType(Types::V128);
if (isX86() && airOp == B3::Air::VectorMulSat) {
append(airOp, a, b, result, tmpForType(Types::I64), tmpForType(Types::V128));
return { };
}
if (isX86() && airOp == B3::Air::VectorSwizzle) {
fixupOutOfBoundsIndicesForSwizzle(a, b, result);
return { };
}
if (isValidForm(airOp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, a, b, result);
return { };
}
if (isValidForm(airOp, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::simdInfo(info), a, b, result);
return { };
}
if (isValidForm(airOp, Arg::Tmp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, a, b, result, tmpForType(Types::V128));
return { };
}
if (isValidForm(airOp, Arg::SIMDInfo, Arg::Tmp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(airOp, Arg::simdInfo(info), a, b, result, tmpForType(Types::V128));
return { };
}
ASSERT_NOT_REACHED();
return { };
}
auto addSIMDRelaxedFMA(SIMDLaneOperation op, SIMDInfo info, ExpressionType m1, ExpressionType m2, ExpressionType add, ExpressionType& result) -> PartialResult
{
B3::Air::Opcode airOp = B3::Air::Oops;
if (op == SIMDLaneOperation::RelaxedMAdd)
airOp = B3::Air::VectorFusedMulAdd;
else if (op == SIMDLaneOperation::RelaxedNMAdd)
airOp = B3::Air::VectorFusedNegMulAdd;
else {
RELEASE_ASSERT_NOT_REACHED();
return { };
}
result = tmpForType(Types::V128);
auto scratch = tmpForType(Types::V128);
append(airOp, Arg::simdInfo(info), m1, m2, add, result, scratch);
return { };
}
// Control flow
PartialResult WARN_UNUSED_RETURN addReturn(const ControlData&, const Stack& returnValues);
PartialResult WARN_UNUSED_RETURN addThrow(unsigned exceptionIndex, Vector<ExpressionType>& args, Stack&);
PartialResult WARN_UNUSED_RETURN addRethrow(unsigned, ControlType&);
// Calls
CallPatchpointData WARN_UNUSED_RETURN emitCallPatchpoint(BasicBlock*, B3::Type, const ResultList&, const Vector<TypedTmp>& tmpArgs, const CallInformation&, Vector<ConstrainedTmp> patchArgs = { });
CallPatchpointData WARN_UNUSED_RETURN emitTailCallPatchpoint(BasicBlock*, const Checked<int32_t>& tailCallStackOffsetFromFP, const Vector<ArgumentLocation>&, const Vector<TypedTmp>& tmpArgs, Vector<ConstrainedTmp> patchArgs = { });
PartialResult addShift(Type, B3::Air::Opcode, ExpressionType value, ExpressionType shift, ExpressionType& result);
PartialResult addIntegerSub(B3::Air::Opcode, ExpressionType lhs, ExpressionType rhs, ExpressionType& result);
PartialResult addFloatingPointAbs(B3::Air::Opcode, ExpressionType value, ExpressionType& result);
PartialResult addFloatingPointBinOp(Type, B3::Air::Opcode, ExpressionType lhs, ExpressionType rhs, ExpressionType& result);
PartialResult addCompare(Type, MacroAssembler::RelationalCondition, ExpressionType lhs, ExpressionType rhs, ExpressionType& result);
// Misc. operations that require 64-bit-only patchpoints
PartialResult WARN_UNUSED_RETURN addF64ConvertUI64(ExpressionType arg, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addF32ConvertUI64(ExpressionType arg, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI64Ctz(ExpressionType arg, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addF64ConvertUI32(ExpressionType arg0, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI64And(ExpressionType arg0, ExpressionType arg1, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI64Eqz(ExpressionType arg0, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI64Or(ExpressionType arg0, ExpressionType arg1, ExpressionType& result);
PartialResult WARN_UNUSED_RETURN addI64ExtendSI32(ExpressionType, ExpressionType&);
PartialResult WARN_UNUSED_RETURN addI64Extend8S(ExpressionType, ExpressionType&);
PartialResult WARN_UNUSED_RETURN addI64Extend16S(ExpressionType, ExpressionType&);
PartialResult WARN_UNUSED_RETURN addI64Extend32S(ExpressionType, ExpressionType&);
Tmp emitCatchImpl(CatchKind, ControlType&, unsigned exceptionIndex = 0);
template <size_t inlineCapacity>
Box<PatchpointExceptionHandle> preparePatchpointForExceptions(B3::PatchpointValue*, Vector<ConstrainedTmp, inlineCapacity>& args);
private:
TypedTmp g32() { return { newTmp(B3::GP), Types::I32 }; }
TypedTmp g64() { return { newTmp(B3::GP), Types::I64 }; }
decltype(auto) gPtr() { return g64(); }
TypedTmp gExternref() { return { newTmp(B3::GP), Types::Externref }; }
TypedTmp gFuncref() { return { newTmp(B3::GP), Types::Funcref }; }
TypedTmp gRef(Type type) { return { newTmp(B3::GP), type }; }
TypedTmp f32() { return { newTmp(B3::FP), Types::F32 }; }
TypedTmp f64() { return { newTmp(B3::FP), Types::F64 }; }
TypedTmp v128() { return { newTmp(B3::FP), Types::V128 }; }
static auto constexpr AddPtr = Add64;
static auto constexpr MulPtr = Mul64;
static auto constexpr UrshiftPtr = Urshift64;
static auto constexpr LeaPtr = Lea64;
static auto constexpr BranchTestPtr = BranchTest64;
static auto constexpr BranchPtr = Branch64;
static Arg extractArg(const TypedTmp& tmp) { return tmp.tmp(); }
static Arg extractArg(const Tmp& tmp) { return Arg(tmp); }
static Arg extractArg(const Arg& arg) { return arg; }
Tmp extractJSValuePointer(const TypedTmp& tmp) const { return tmp.tmp(); }
void emitZeroInitialize(ExpressionType);
void emitZeroInitialize(BasicBlock*, ExpressionType);
template <typename Taken>
void emitCheckI64Zero(ExpressionType, Taken&&);
template<typename Then>
void emitCheckForNullReference(const ExpressionType& ref, Then&&);
void emitBranchForNullReference(const ExpressionType&);
Inst makeBranchNotInt32(const ExpressionType&);
Inst makeBranchNotCell(const ExpressionType&);
B3::Type toB3ResultType(BlockSignature);
static B3::Air::Opcode moveOpForValueType(Type type)
{
switch (type.kind) {
case TypeKind::I32:
return Move32;
case TypeKind::I64:
case TypeKind::Externref:
case TypeKind::Funcref:
case TypeKind::Ref:
case TypeKind::RefNull:
return Move;
case TypeKind::F32:
return MoveFloat;
case TypeKind::F64:
return MoveDouble;
case TypeKind::V128:
return MoveVector;
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
B3::Air::Arg materializeAddrArg(Tmp base, size_t offset, Width width)
{
if (Arg::isValidAddrForm(Move, offset, width))
return Arg::addr(base, offset);
auto temp = g64();
append(Move, Arg::bigImm(offset), temp);
append(Add64, temp, base, temp);
return Arg::addr(temp);
}
B3::Air::Arg materializeSimpleAddrArg(Tmp base, size_t offset)
{
auto temp = g64();
append(Move, Arg::bigImm(offset), temp);
append(Add64, temp, base, temp);
return Arg::simpleAddr(temp);
}
void emitLoad(Tmp base, size_t offset, const TypedTmp& result)
{
emitLoad(moveOpForValueType(result.type()), toB3Type(result.type()), base, offset, result.tmp());
}
void emitLoad(B3::Air::Opcode op, B3::Type type, Tmp base, size_t offset, Tmp result)
{
append(op, materializeAddrArg(base, offset, B3::widthForType(type)), result);
}
void emitStore(const TypedTmp& value, Tmp base, size_t offset)
{
append(moveOpForValueType(value.type()), value, materializeAddrArg(base, offset, B3::widthForType(toB3Type(value.type()))));
}
void appendCCallArg(B3::Air::Inst& inst, const TypedTmp& tmp)
{
inst.args.append(tmp.tmp());
}
// emitMoveWithoutTypeCheck is like emitMove, but does not assert anything
// about the wasm types of `src` and `dst` (in no-assert builds, they are the same)
void emitMoveWithoutTypeCheck(const TypedTmp& src, const TypedTmp& dst)
{
if (src == dst)
return;
append(moveOpForValueType(src.type()), src, dst);
}
void emitMove(const TypedTmp& src, const TypedTmp& dst)
{
ASSERT(isSubtype(src.type(), dst.type()));
emitMoveWithoutTypeCheck(src, dst);
}
void emitMove(const ValueLocation& location, const TypedTmp& dest)
{
if (location.isStack())
emitLoad(Tmp(GPRInfo::callFrameRegister), location.offsetFromFP(), dest);
else if (location.isFPR())
append(moveOpForValueType(dest.type()), Tmp(location.fpr()), dest);
else
append(moveOpForValueType(dest.type()), Tmp(location.jsr().gpr()), dest);
}
void emitMove(const ArgumentLocation& arg, const TypedTmp& dest)
{
emitMove(arg.location, dest);
}
ExpressionType emitCheckAndPreparePointer(ExpressionType pointer, uint32_t offset, uint32_t sizeOfOp);
ExpressionType emitLoadOp(LoadOpType, ExpressionType pointer, uint32_t offset);
void emitStoreOp(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
void sanitizeAtomicResult(ExtAtomicOpType, TypedTmp source, TypedTmp dest);
void sanitizeAtomicResult(ExtAtomicOpType, TypedTmp result);
TypedTmp appendGeneralAtomic(ExtAtomicOpType, B3::Air::Opcode nonAtomicOpcode, B3::Commutativity, Arg input, Arg addrArg, TypedTmp result);
TypedTmp appendStrongCAS(ExtAtomicOpType, TypedTmp expected, TypedTmp value, Arg addrArg, TypedTmp result);
template <typename IntType>
void emitModOrDiv(bool isDiv, ExpressionType lhs, ExpressionType rhs, ExpressionType& result);
PartialResult addUncheckedFloatingPointTruncation(FloatingPointTruncationKind, ExpressionType arg, ExpressionType out);
bool useSignalingMemory() const
{
return m_mode == MemoryMode::Signaling;
}
};
AirIRGenerator64::AirIRGenerator64(const ModuleInformation& info, Callee& callee, B3::Procedure& procedure, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls, MemoryMode mode, unsigned functionIndex, std::optional<bool> hasExceptionHandlers, TierUpCount* tierUp, const TypeDefinition& originalSignature, unsigned& osrEntryScratchBufferSize)
: AirIRGeneratorBase(info, callee, procedure, unlinkedWasmToWasmCalls, mode, functionIndex, hasExceptionHandlers, tierUp, originalSignature, osrEntryScratchBufferSize)
{
}
void AirIRGenerator64::emitZeroInitialize(ExpressionType value)
{
emitZeroInitialize(m_currentBlock, value);
}
void AirIRGenerator64::emitZeroInitialize(BasicBlock* block, ExpressionType value)
{
auto const type = value.type();
switch (type.kind) {
case TypeKind::Externref:
case TypeKind::Funcref:
case TypeKind::Ref:
case TypeKind::RefNull:
append(block, Move, Arg::imm(JSValue::encode(jsNull())), value);
break;
case TypeKind::I32:
case TypeKind::I64: {
append(block, Move, Arg::imm(0), value);
break;
}
case TypeKind::F32:
case TypeKind::F64: {
append(block, type.isF32() ? MoveZeroToFloat : MoveZeroToDouble, value);
break;
}
case TypeKind::V128: {
append(block, MoveZeroToVector, value);
break;
}
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
template<typename Taken>
void AirIRGenerator64::emitCheckI64Zero(ExpressionType value, Taken&& taken)
{
emitCheck([&] {
return Inst(BranchTest64, nullptr, Arg::resCond(MacroAssembler::Zero), value, value);
}, std::forward<Taken>(taken));
}
template<typename Taken>
void AirIRGenerator64::emitCheckForNullReference(const TypedTmp& ref, Taken&& taken)
{
auto tmpForNull = g64();
append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmpForNull);
emitCheck([&] {
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::Equal), ref, tmpForNull);
}, std::forward<Taken>(taken));
}
void AirIRGenerator64::emitBranchForNullReference(const TypedTmp& ref)
{
auto tmpForNull = g64();
append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmpForNull);
append(Branch64, Arg::relCond(MacroAssembler::Equal), ref, tmpForNull);
}
Inst AirIRGenerator64::makeBranchNotInt32(const TypedTmp& value)
{
auto tmpForTag = g64();
append(Move, Arg::bigImm(JSValue::NumberTag), tmpForTag);
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::Below), value, tmpForTag);
}
Inst AirIRGenerator64::makeBranchNotCell(const ExpressionType& maybeCell)
{
auto tmpForCellMask = g64();
append(Move, Arg::bigImm(JSValue::NotCellMask), tmpForCellMask);
return Inst(BranchTest64, nullptr, Arg::resCond(MacroAssembler::NonZero), maybeCell, tmpForCellMask);
}
B3::Type AirIRGenerator64::toB3ResultType(BlockSignature returnType)
{
auto signature = returnType->as<FunctionSignature>();
if (signature->returnsVoid())
return B3::Void;
if (signature->returnCount() == 1)
return toB3Type(signature->returnType(0));
auto result = m_tupleMap.ensure(returnType, [&] {
Vector<B3::Type> result;
for (unsigned i = 0; i < signature->returnCount(); ++i) {
Type type = signature->returnType(i);
result.append(toB3Type(type));
}
return m_proc.addTuple(WTFMove(result));
});
return result.iterator->value;
}
void AirIRGenerator64::emitMaterializeConstant(Type type, uint64_t value, TypedTmp& dest)
{
emitMaterializeConstant(m_currentBlock, type, value, dest);
}
void AirIRGenerator64::emitMaterializeConstant(BasicBlock* block, Type type, uint64_t value, TypedTmp& dest)
{
switch (type.kind) {
case TypeKind::I32:
case TypeKind::I64:
case TypeKind::Externref:
case TypeKind::Funcref:
case TypeKind::Ref:
case TypeKind::RefNull:
append(block, Move, Arg::bigImm(value), dest);
break;
case TypeKind::F32:
case TypeKind::F64: {
if (value == 0)
append(block, type.isF32() ? MoveZeroToFloat : MoveZeroToDouble, dest);
else {
auto tmp = g64();
append(block, Move, Arg::bigImm(value), tmp);
append(block, type.isF32() ? Move32ToFloat : Move64ToDouble, tmp, dest);
}
break;
}
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
auto AirIRGenerator64::addConstant(Type type, uint64_t value) -> ExpressionType
{
return addConstant(m_currentBlock, type, value);
}
auto AirIRGenerator64::addConstant(BasicBlock* block, Type type, uint64_t value) -> ExpressionType
{
auto result = tmpForType(type);
emitMaterializeConstant(block, type, value, result);
return result;
}
auto AirIRGenerator64::addConstant(v128_t value) -> ExpressionType
{
auto result = tmpForType(Types::V128);
if (!value.u64x2[0] && !value.u64x2[1])
return addConstantZero(Types::V128);
if (value.u64x2[0] == 0xffffffffffffffff && value.u64x2[1] == 0xffffffffffffffff) {
if constexpr (isX86())
append(CompareIntegerVector, Arg::relCond(MacroAssembler::RelationalCondition::Equal), Arg::simdInfo({ SIMDLane::i32x4, SIMDSignMode::None }), result, result, result, tmpForType(Types::V128));
else
append(CompareIntegerVector, Arg::relCond(MacroAssembler::RelationalCondition::Equal), Arg::simdInfo({ SIMDLane::i32x4, SIMDSignMode::None }), result, result, result);
return result;
}
// FIXME: this is bad, we should load
auto a = g64();
append(Move, Arg::bigImm(value.u64x2[0]), a);
append(MoveZeroToVector, result);
append(VectorReplaceLaneInt64, Arg::imm(0), a, result);
append(Move, Arg::bigImm(value.u64x2[1]), a);
append(VectorReplaceLaneInt64, Arg::imm(1), a, result);
return result;
}
auto AirIRGenerator64::addConstantZero(Type type) -> ExpressionType
{
return addConstantZero(m_currentBlock, type);
}
auto AirIRGenerator64::addConstantZero(BasicBlock* block, Type type) -> ExpressionType
{
auto result = tmpForType(type);
emitZeroInitialize(block, result);
return result;
}
void AirIRGenerator64::emitCoerceToI64(const TypedTmp& src, TypedTmp& result)
{
switch (src.type().kind) {
case TypeKind::F32: {
auto result32 = g32();
result = g64();
append(MoveFloatTo32, src, result32);
append(Move32, result32, result);
}
break;
case TypeKind::F64:
result = g64();
append(MoveDoubleTo64, src, result);
break;
case TypeKind::I32:
result = g64();
append(Move32, src, result);
break;
case TypeKind::I64:
case TypeKind::Externref:
case TypeKind::Funcref:
case TypeKind::Ref:
case TypeKind::RefNull:
result = src.coerce(Types::I64);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
}
void AirIRGenerator64::emitCoerceFromI64(Type type, const TypedTmp& src, TypedTmp& result)
{
switch (type.kind) {
case TypeKind::I32:
result = g32();
append(Move32, src, result);
break;
case TypeKind::F32:
result = f32();
append(Move32ToFloat, src, result);
break;
case TypeKind::F64:
result = f64();
append(Move64ToDouble, src, result);
break;
case TypeKind::I64:
case TypeKind::Externref:
case TypeKind::Funcref:
case TypeKind::Ref:
case TypeKind::RefNull:
result = src.coerce(type);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
}
auto AirIRGenerator64::addRefIsNull(ExpressionType value, ExpressionType& result) -> PartialResult
{
ASSERT(value.tmp());
result = tmpForType(Types::I32);
auto tmp = g64();
append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmp);
append(Compare64, Arg::relCond(MacroAssembler::Equal), value, tmp, result);
return { };
}
inline AirIRGenerator64::ExpressionType AirIRGenerator64::emitCheckAndPreparePointer(ExpressionType pointer, uint32_t offset, uint32_t sizeOfOperation)
{
static_assert(GPRInfo::wasmBaseMemoryPointer != InvalidGPRReg);
auto result = g64();
switch (m_mode) {
case MemoryMode::BoundsChecking: {
// In bound checking mode, while shared wasm memory partially relies on signal handler too, we need to perform bound checking
// to ensure that no memory access exceeds the current memory size.
static_assert(GPRInfo::wasmBoundsCheckingSizeRegister != InvalidGPRReg);
ASSERT(sizeOfOperation + offset > offset);
auto temp = g64();
append(Move, Arg::bigImm(static_cast<uint64_t>(sizeOfOperation) + offset - 1), temp);
if constexpr (isARM64())
append(AddZeroExtend64, temp, pointer, temp);
else {
append(Move32, pointer, result);
append(Add64, result, temp);
}
emitCheck([&] {
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::AboveOrEqual), temp, Tmp(GPRInfo::wasmBoundsCheckingSizeRegister));
}, [=, this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::OutOfBoundsMemoryAccess);
});
break;
}
case MemoryMode::Signaling: {
// We've virtually mapped 4GiB+redzone for this memory. Only the user-allocated pages are addressable, contiguously in range [0, current],
// and everything above is mapped PROT_NONE. We don't need to perform any explicit bounds check in the 4GiB range because WebAssembly register
// memory accesses are 32-bit. However WebAssembly register + offset accesses perform the addition in 64-bit which can push an access above
// the 32-bit limit (the offset is unsigned 32-bit). The redzone will catch most small offsets, and we'll explicitly bounds check any
// register + large offset access. We don't think this will be generated frequently.
//
// We could check that register + large offset doesn't exceed 4GiB+redzone since that's technically the limit we need to avoid overflowing the
// PROT_NONE region, but it's better if we use a smaller immediate because it can codegens better. We know that anything equal to or greater
// than the declared 'maximum' will trap, so we can compare against that number. If there was no declared 'maximum' then we still know that
// any access equal to or greater than 4GiB will trap, no need to add the redzone.
if constexpr (!isARM64())
append(Move32, pointer, result);
if (offset >= Memory::fastMappedRedzoneBytes()) {
uint64_t maximum = m_info.memory.maximum() ? m_info.memory.maximum().bytes() : std::numeric_limits<uint32_t>::max();
auto temp = g64();
append(Move, Arg::bigImm(static_cast<uint64_t>(sizeOfOperation) + offset - 1), temp);
if constexpr (isARM64())
append(AddZeroExtend64, temp, pointer, temp);
else
append(Add64, result, temp);
auto sizeMax = addConstant(Types::I64, maximum);
emitCheck([&] {
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::AboveOrEqual), temp, sizeMax);
}, [=, this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::OutOfBoundsMemoryAccess);
});
}
break;
}
}
if constexpr (isARM64())
append(AddZeroExtend64, Tmp(GPRInfo::wasmBaseMemoryPointer), pointer, result);
else
append(Add64, Tmp(GPRInfo::wasmBaseMemoryPointer), result);
return result;
}
inline TypedTmp AirIRGenerator64::emitLoadOp(LoadOpType op, ExpressionType pointer, uint32_t uoffset)
{
uint32_t offset = fixupPointerPlusOffset(pointer, uoffset);
TypedTmp result;
Arg addrArg = materializeAddrArg(pointer, offset, widthForBytes(sizeOfLoadOp(op)));
switch (op) {
case LoadOpType::I32Load8S: {
result = g32();
appendEffectful(Load8SignedExtendTo32, addrArg, result);
break;
}
case LoadOpType::I64Load8S: {
result = g64();
appendEffectful(Load8SignedExtendTo32, addrArg, result);
append(SignExtend32To64, result, result);
break;
}
case LoadOpType::I32Load8U: {
result = g32();
appendEffectful(Load8, addrArg, result);
break;
}
case LoadOpType::I64Load8U: {
result = g64();
appendEffectful(Load8, addrArg, result);
break;
}
case LoadOpType::I32Load16S: {
result = g32();
appendEffectful(Load16SignedExtendTo32, addrArg, result);
break;
}
case LoadOpType::I64Load16S: {
result = g64();
appendEffectful(Load16SignedExtendTo32, addrArg, result);
append(SignExtend32To64, result, result);
break;
}
case LoadOpType::I32Load16U: {
result = g32();
appendEffectful(Load16, addrArg, result);
break;
}
case LoadOpType::I64Load16U: {
result = g64();
appendEffectful(Load16, addrArg, result);
break;
}
case LoadOpType::I32Load:
result = g32();
appendEffectful(Move32, addrArg, result);
break;
case LoadOpType::I64Load32U: {
result = g64();
appendEffectful(Move32, addrArg, result);
break;
}
case LoadOpType::I64Load32S: {
result = g64();
appendEffectful(Move32, addrArg, result);
append(SignExtend32To64, result, result);
break;
}
case LoadOpType::I64Load: {
result = g64();
appendEffectful(Move, addrArg, result);
break;
}
case LoadOpType::F32Load: {
result = f32();
appendEffectful(MoveFloat, addrArg, result);
break;
}
case LoadOpType::F64Load: {
result = f64();
appendEffectful(MoveDouble, addrArg, result);
break;
}
}
return result;
}
auto AirIRGenerator64::load(LoadOpType op, ExpressionType pointer, ExpressionType& result, uint32_t offset) -> PartialResult
{
ASSERT(pointer.tmp().isGP());
if (UNLIKELY(sumOverflows<uint32_t>(offset, sizeOfLoadOp(op)))) {
// FIXME: Even though this is provably out of bounds, it's not a validation error, so we have to handle it
// as a runtime exception. However, this may change: https://bugs.webkit.org/show_bug.cgi?id=166435
auto* patch = addPatchpoint(B3::Void);
patch->setGenerator([this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::OutOfBoundsMemoryAccess);
});
emitPatchpoint(patch, Tmp());
// We won't reach here, so we just pick a random reg.
switch (op) {
case LoadOpType::I32Load8S:
case LoadOpType::I32Load16S:
case LoadOpType::I32Load:
case LoadOpType::I32Load16U:
case LoadOpType::I32Load8U:
result = g32();
break;
case LoadOpType::I64Load8S:
case LoadOpType::I64Load8U:
case LoadOpType::I64Load16S:
case LoadOpType::I64Load32U:
case LoadOpType::I64Load32S:
case LoadOpType::I64Load:
case LoadOpType::I64Load16U:
result = g64();
break;
case LoadOpType::F32Load:
result = f32();
break;
case LoadOpType::F64Load:
result = f64();
break;
}
} else
result = emitLoadOp(op, emitCheckAndPreparePointer(pointer, offset, sizeOfLoadOp(op)), offset);
return { };
}
inline void AirIRGenerator64::emitStoreOp(StoreOpType op, ExpressionType pointer, ExpressionType value, uint32_t uoffset)
{
uint32_t offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeAddrArg(pointer, offset, widthForBytes(sizeOfStoreOp(op)));
switch (op) {
case StoreOpType::I64Store8:
case StoreOpType::I32Store8:
append(Store8, value, addrArg);
return;
case StoreOpType::I64Store16:
case StoreOpType::I32Store16:
append(Store16, value, addrArg);
return;
case StoreOpType::I64Store32:
case StoreOpType::I32Store:
append(Move32, value, addrArg);
return;
case StoreOpType::I64Store:
append(Move, value, addrArg);
return;
case StoreOpType::F32Store:
append(MoveFloat, value, addrArg);
return;
case StoreOpType::F64Store:
append(MoveDouble, value, addrArg);
return;
}
RELEASE_ASSERT_NOT_REACHED();
}
auto AirIRGenerator64::store(StoreOpType op, ExpressionType pointer, ExpressionType value, uint32_t offset) -> PartialResult
{
ASSERT(pointer.tmp().isGP());
if (UNLIKELY(sumOverflows<uint32_t>(offset, sizeOfStoreOp(op)))) {
// FIXME: Even though this is provably out of bounds, it's not a validation error, so we have to handle it
// as a runtime exception. However, this may change: https://bugs.webkit.org/show_bug.cgi?id=166435
auto* throwException = addPatchpoint(B3::Void);
throwException->setGenerator([this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::OutOfBoundsMemoryAccess);
});
emitPatchpoint(throwException, Tmp());
} else
emitStoreOp(op, emitCheckAndPreparePointer(pointer, offset, sizeOfStoreOp(op)), value, offset);
return { };
}
void AirIRGenerator64::sanitizeAtomicResult(ExtAtomicOpType op, TypedTmp source, TypedTmp dest)
{
ASSERT(source.type() == dest.type());
switch (source.type().kind) {
case TypeKind::I64: {
switch (accessWidth(op)) {
case Width8:
append(ZeroExtend8To32, source, dest);
return;
case Width16:
append(ZeroExtend16To32, source, dest);
return;
case Width32:
append(Move32, source, dest);
return;
case Width64:
if (source == dest)
return;
append(Move, source, dest);
return;
case Width128:
RELEASE_ASSERT_NOT_REACHED();
return;
}
return;
}
case TypeKind::I32:
switch (accessWidth(op)) {
case Width8:
append(ZeroExtend8To32, source, dest);
return;
case Width16:
append(ZeroExtend16To32, source, dest);
return;
case Width32:
case Width64:
if (source == dest)
return;
append(Move, source, dest);
return;
case Width128:
RELEASE_ASSERT_NOT_REACHED();
return;
}
return;
default:
RELEASE_ASSERT_NOT_REACHED();
return;
}
}
void AirIRGenerator64::sanitizeAtomicResult(ExtAtomicOpType op, TypedTmp result)
{
sanitizeAtomicResult(op, result, result);
}
TypedTmp AirIRGenerator64::appendGeneralAtomic(ExtAtomicOpType op, B3::Air::Opcode opcode, B3::Commutativity commutativity, Arg input, Arg address, TypedTmp oldValue)
{
Width accessWidth = Wasm::accessWidth(op);
auto newTmp = [&]() {
if (accessWidth == Width64)
return g64();
return g32();
};
auto tmp = [&](Arg arg) -> TypedTmp {
if (arg.isTmp())
return TypedTmp(arg.tmp(), accessWidth == Width64 ? Types::I64 : Types::I32);
TypedTmp result = newTmp();
append(Move, arg, result);
return result;
};
auto imm = [&](Arg arg) {
if (arg.isImm())
return arg;
return Arg();
};
auto bitImm = [&](Arg arg) {
if (arg.isBitImm())
return arg;
return Arg();
};
Tmp newValue = opcode == B3::Air::Nop ? tmp(input) : newTmp();
// We need a CAS loop or a LL/SC loop. Using prepare/attempt jargon, we want:
//
// Block #reloop:
// Prepare
// opcode
// Attempt
// Successors: Then:#done, Else:#reloop
// Block #done:
// Move oldValue, result
auto* beginBlock = m_currentBlock;
auto* reloopBlock = m_code.addBlock();
auto* doneBlock = m_code.addBlock();
append(B3::Air::Jump);
beginBlock->setSuccessors(reloopBlock);
m_currentBlock = reloopBlock;
B3::Air::Opcode prepareOpcode;
if (isX86()) {
switch (accessWidth) {
case Width8:
prepareOpcode = Load8SignedExtendTo32;
break;
case Width16:
prepareOpcode = Load16SignedExtendTo32;
break;
case Width32:
prepareOpcode = Move32;
break;
case Width64:
prepareOpcode = Move;
break;
case Width128:
RELEASE_ASSERT_NOT_REACHED();
}
} else {
RELEASE_ASSERT(isARM64());
prepareOpcode = OPCODE_FOR_WIDTH(LoadLinkAcq, accessWidth);
}
appendEffectful(prepareOpcode, address, oldValue);
if (opcode != B3::Air::Nop) {
// FIXME: If we ever have to write this again, we need to find a way to share the code with
// appendBinOp.
// https://bugs.webkit.org/show_bug.cgi?id=169249
if (commutativity == B3::Commutative && imm(input) && isValidForm(opcode, Arg::Imm, Arg::Tmp, Arg::Tmp))
append(opcode, imm(input), oldValue, newValue);
else if (imm(input) && isValidForm(opcode, Arg::Tmp, Arg::Imm, Arg::Tmp))
append(opcode, oldValue, imm(input), newValue);
else if (commutativity == B3::Commutative && bitImm(input) && isValidForm(opcode, Arg::BitImm, Arg::Tmp, Arg::Tmp))
append(opcode, bitImm(input), oldValue, newValue);
else if (isValidForm(opcode, Arg::Tmp, Arg::Tmp, Arg::Tmp))
append(opcode, oldValue, tmp(input), newValue);
else {
append(Move, oldValue, newValue);
if (imm(input) && isValidForm(opcode, Arg::Imm, Arg::Tmp))
append(opcode, imm(input), newValue);
else
append(opcode, tmp(input), newValue);
}
}
if (isX86()) {
#if CPU(X86) || CPU(X86_64)
Tmp eax(X86Registers::eax);
B3::Air::Opcode casOpcode = OPCODE_FOR_WIDTH(BranchAtomicStrongCAS, accessWidth);
append(Move, oldValue, eax);
appendEffectful(casOpcode, Arg::statusCond(MacroAssembler::Success), eax, newValue, address);
#endif
} else {
RELEASE_ASSERT(isARM64());
TypedTmp boolResult = newTmp();
appendEffectful(OPCODE_FOR_WIDTH(StoreCondRel, accessWidth), newValue, address, boolResult);
append(BranchTest32, Arg::resCond(MacroAssembler::Zero), boolResult, boolResult);
}
reloopBlock->setSuccessors(doneBlock, reloopBlock);
m_currentBlock = doneBlock;
return oldValue;
}
TypedTmp AirIRGenerator64::appendStrongCAS(ExtAtomicOpType op, TypedTmp expected, TypedTmp value, Arg address, TypedTmp valueResultTmp)
{
Width accessWidth = Wasm::accessWidth(op);
auto newTmp = [&]() {
if (accessWidth == Width64)
return g64();
return g32();
};
auto tmp = [&](Arg arg) -> TypedTmp {
if (arg.isTmp())
return TypedTmp(arg.tmp(), accessWidth == Width64 ? Types::I64 : Types::I32);
TypedTmp result = newTmp();
append(Move, arg, result);
return result;
};
Tmp successBoolResultTmp = newTmp();
Tmp expectedValueTmp = tmp(expected);
Tmp newValueTmp = tmp(value);
if (isX86()) {
#if CPU(X86) || CPU(X86_64)
Tmp eax(X86Registers::eax);
append(Move, expectedValueTmp, eax);
appendEffectful(OPCODE_FOR_WIDTH(AtomicStrongCAS, accessWidth), eax, newValueTmp, address);
append(Move, eax, valueResultTmp);
#endif
return valueResultTmp;
}
if (isARM64_LSE()) {
append(Move, expectedValueTmp, valueResultTmp);
appendEffectful(OPCODE_FOR_WIDTH(AtomicStrongCAS, accessWidth), valueResultTmp, newValueTmp, address);
return valueResultTmp;
}
RELEASE_ASSERT(isARM64());
// We wish to emit:
//
// Block #reloop:
// LoadLink
// Branch NotEqual
// Successors: Then:#fail, Else: #store
// Block #store:
// StoreCond
// Xor $1, %result <--- only if !invert
// Jump
// Successors: #done
// Block #fail:
// Move $invert, %result
// Jump
// Successors: #done
// Block #done:
auto* reloopBlock = m_code.addBlock();
auto* storeBlock = m_code.addBlock();
auto* strongFailBlock = m_code.addBlock();
auto* doneBlock = m_code.addBlock();
auto* beginBlock = m_currentBlock;
append(B3::Air::Jump);
beginBlock->setSuccessors(reloopBlock);
m_currentBlock = reloopBlock;
appendEffectful(OPCODE_FOR_WIDTH(LoadLinkAcq, accessWidth), address, valueResultTmp);
append(OPCODE_FOR_CANONICAL_WIDTH(Branch, accessWidth), Arg::relCond(MacroAssembler::NotEqual), valueResultTmp, expectedValueTmp);
reloopBlock->setSuccessors(B3::Air::FrequentedBlock(strongFailBlock), storeBlock);
m_currentBlock = storeBlock;
appendEffectful(OPCODE_FOR_WIDTH(StoreCondRel, accessWidth), newValueTmp, address, successBoolResultTmp);
append(BranchTest32, Arg::resCond(MacroAssembler::Zero), successBoolResultTmp, successBoolResultTmp);
storeBlock->setSuccessors(doneBlock, reloopBlock);
m_currentBlock = strongFailBlock;
{
TypedTmp tmp = newTmp();
appendEffectful(OPCODE_FOR_WIDTH(StoreCondRel, accessWidth), valueResultTmp, address, tmp);
append(BranchTest32, Arg::resCond(MacroAssembler::Zero), tmp, tmp);
}
strongFailBlock->setSuccessors(B3::Air::FrequentedBlock(doneBlock), reloopBlock);
m_currentBlock = doneBlock;
return valueResultTmp;
}
auto AirIRGenerator64::addI31New(ExpressionType value, ExpressionType& result) -> PartialResult
{
auto tmp1 = g32();
result = gRef(Type { TypeKind::Ref, static_cast<TypeIndex>(TypeKind::I31ref) });
append(Move, Arg::bigImm(0x7fffffff), tmp1);
append(And32, tmp1, value, tmp1);
append(Move, Arg::bigImm(JSValue::NumberTag), result);
append(Or64, result, tmp1, result);
return { };
}
auto AirIRGenerator64::addI31GetS(ExpressionType ref, ExpressionType& result) -> PartialResult
{
// Trap on null reference.
auto tmpForNull = g64();
append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmpForNull);
emitCheck([&] {
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::Equal), ref, tmpForNull);
}, [=, this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::NullI31Get);
});
auto tmpForShift = g32();
result = g32();
append(Move, Arg::imm(1), tmpForShift);
append(Move32, ref, result);
addShift(Types::I32, Lshift32, result, tmpForShift, result);
addShift(Types::I32, Rshift32, result, tmpForShift, result);
return { };
}
auto AirIRGenerator64::addI31GetU(ExpressionType ref, ExpressionType& result) -> PartialResult
{
// Trap on null reference.
auto tmpForNull = g64();
append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmpForNull);
emitCheck([&] {
return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::Equal), ref, tmpForNull);
}, [=, this] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
this->emitThrowException(jit, ExceptionType::NullI31Get);
});
result = g32();
append(Move32, ref, result);
return { };
}
auto AirIRGenerator64::addSIMDLoad(ExpressionType pointer, uint32_t uoffset, ExpressionType& result) -> PartialResult
{
result = v128();
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(Width128)), offset, Width128);
appendEffectful(MoveVector, addrArg, result);
return { };
}
auto AirIRGenerator64::addSIMDStore(ExpressionType value, ExpressionType pointer, uint32_t uoffset) -> PartialResult
{
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(Width128)), offset, Width128);
appendEffectful(MoveVector, value, addrArg);
return { };
}
auto AirIRGenerator64::addSIMDSplat(SIMDLane lane, ExpressionType scalar, ExpressionType& result) -> PartialResult
{
B3::Air::Opcode op;
switch (lane) {
case SIMDLane::i8x16:
op = VectorSplatInt8;
break;
case SIMDLane::i16x8:
op = VectorSplatInt16;
break;
case SIMDLane::i32x4:
op = VectorSplatInt32;
break;
case SIMDLane::i64x2:
op = VectorSplatInt64;
break;
case SIMDLane::f32x4:
op = VectorSplatFloat32;
break;
case SIMDLane::f64x2:
op = VectorSplatFloat64;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
result = v128();
append(op, scalar, result.tmp());
return { };
}
auto AirIRGenerator64::addSIMDShift(SIMDLaneOperation op, SIMDInfo info, ExpressionType v, ExpressionType shift, ExpressionType& result) -> PartialResult
{
result = v128();
int32_t mask = (elementByteSize(info.lane) * CHAR_BIT) - 1;
if (isARM64()) {
Tmp shiftAmount = newTmp(B3::GP);
Tmp shiftVector = newTmp(B3::FP);
append(And32, Arg::bitImm(mask), shift.tmp(), shiftAmount);
if (op == SIMDLaneOperation::Shr) {
// ARM64 doesn't have a version of this instruction for right shift. Instead, if the input to
// left shift is negative, it's a right shift by the absolute value of that amount.
append(Neg32, shiftAmount);
}
append(VectorSplatInt8, shiftAmount, shiftVector);
append(info.signMode == SIMDSignMode::Signed ? VectorSshl : VectorUshl, Arg::simdInfo(info), v.tmp(), shiftVector, result.tmp());
return { };
} else if (isX86()) {
Tmp shiftAmount = newTmp(B3::GP);
Tmp shiftVector = newTmp(B3::FP);
append(Move, shift.tmp(), shiftAmount);
append(And32, Arg::imm(mask), shiftAmount);
if (op == SIMDLaneOperation::Shr && info.signMode == SIMDSignMode::Signed && info.lane == SIMDLane::i64x2) {
// x86 has no SIMD 64-bit signed right shift instruction, so we scalarize it here.
#if CPU(X86_64)
Tmp shiftRCX = Tmp(X86Registers::ecx);
Tmp lower = newTmp(B3::GP);
Tmp upper = newTmp(B3::GP);
append(Move, shiftAmount, shiftRCX);
append(VectorExtractLaneInt64, Arg::imm(0), v, lower);
append(VectorExtractLaneInt64, Arg::imm(1), v, upper);
append(Rshift64, shiftRCX, lower);
append(Rshift64, shiftRCX, upper);
append(VectorReplaceLaneInt64, Arg::imm(0), lower, result);
append(VectorReplaceLaneInt64, Arg::imm(1), upper, result);
#endif
return { };
}
// Unlike ARM, x86 expects the shift provided as a *scalar*, stored in the lower 64 bits of a vector register.
// So, we don't need to splat the shift amount like we do on ARM.
append(Move64ToDouble, shiftAmount, shiftVector);
// 8-bit shifts are pretty involved to implement on Intel, so they get their own instruction type with extra temps.
if (op == SIMDLaneOperation::Shl && info.lane == SIMDLane::i8x16) {
append(VectorUshl8, v, shiftVector, result, tmpForType(Types::V128), tmpForType(Types::V128));
return { };
}
if (op == SIMDLaneOperation::Shr && info.lane == SIMDLane::i8x16) {
append(info.signMode == SIMDSignMode::Signed ? VectorSshr8 : VectorUshr8, v, shiftVector, result, tmpForType(Types::V128), tmpForType(Types::V128));
return { };
}
if (op == SIMDLaneOperation::Shl)
append(VectorUshl, Arg::simdInfo(info), v.tmp(), shiftVector, result.tmp());
else
append(info.signMode == SIMDSignMode::Signed ? VectorSshr : VectorUshr, Arg::simdInfo(info), v.tmp(), shiftVector, result.tmp());
return { };
}
RELEASE_ASSERT_NOT_REACHED();
return { };
}
auto AirIRGenerator64::addSIMDExtmul(SIMDLaneOperation op, SIMDInfo info, ExpressionType lhs, ExpressionType rhs, ExpressionType& result) -> PartialResult
{
ASSERT(info.signMode != SIMDSignMode::None);
result = v128();
auto lhsTmp = newTmp(B3::FP);
auto rhsTmp = newTmp(B3::FP);
auto extOp = op == SIMDLaneOperation::ExtmulLow ? VectorExtendLow : VectorExtendHigh;
append(extOp, Arg::simdInfo(info), lhs.tmp(), lhsTmp);
append(extOp, Arg::simdInfo(info), rhs.tmp(), rhsTmp);
append(VectorMul, Arg::simdInfo(info), lhsTmp, rhsTmp, result.tmp());
return { };
}
auto AirIRGenerator64::addSIMDShuffle(v128_t imm, ExpressionType a, ExpressionType b, ExpressionType& result) -> PartialResult
{
result = v128();
if constexpr (isX86()) {
v128_t leftImm = imm;
v128_t rightImm = imm;
for (unsigned i = 0; i < 16; ++i) {
if (leftImm.u8x16[i] > 15)
leftImm.u8x16[i] = 0xFF; // Force OOB
if (rightImm.u8x16[i] < 16 || rightImm.u8x16[i] > 31)
rightImm.u8x16[i] = 0xFF; // Force OOB
}
// Store each byte (w/ index < 16) of `a` to result
// and zero clear each byte (w/ index > 15) in result.
auto left = v128();
auto leftImmConst = addConstant(leftImm);
append(B3::Air::VectorSwizzle, a, leftImmConst, left);
// Store each byte (w/ index - 16 >= 0) of `b` to result2
// and zero clear each byte (w/ index - 16 < 0) in result2.
auto right = v128();
auto rightImmConst = addConstant(rightImm);
append(B3::Air::VectorSwizzle, b, rightImmConst, right);
append(VectorOr, Arg::simdInfo(SIMDInfo { SIMDLane::v128, SIMDSignMode::None }), left, right, result);
return { };
}
if constexpr (!isARM64())
UNREACHABLE_FOR_PLATFORM();
#if CPU(ARM64)
// The tbl instruction requires these values to be adjacent.
Tmp n(ARM64Registers::q30);
Tmp m(ARM64Registers::q31);
#else
Tmp n;
Tmp m;
#endif
append(MoveVector, a, n);
append(MoveVector, b, m);
append(VectorSwizzle2, n, m, addConstant(imm), result);
return { };
}
auto AirIRGenerator64::addSIMDLoadSplat(SIMDLaneOperation op, ExpressionType pointer, uint32_t uoffset, ExpressionType& result) -> PartialResult
{
B3::Air::Opcode opcode;
Width width;
switch (op) {
case SIMDLaneOperation::LoadSplat8:
opcode = VectorLoad8Splat;
width = Width8;
break;
case SIMDLaneOperation::LoadSplat16:
opcode = VectorLoad16Splat;
width = Width16;
break;
case SIMDLaneOperation::LoadSplat32:
opcode = VectorLoad32Splat;
width = Width32;
break;
case SIMDLaneOperation::LoadSplat64:
opcode = VectorLoad64Splat;
width = Width64;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
result = v128();
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeSimpleAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(width)), offset);
if (isX86() && op == SIMDLaneOperation::LoadSplat8)
appendEffectful(opcode, addrArg, result, tmpForType(Types::V128));
else
appendEffectful(opcode, addrArg, result);
return { };
}
auto AirIRGenerator64::addSIMDLoadLane(SIMDLaneOperation op, ExpressionType pointer, ExpressionType vector, uint32_t uoffset, uint8_t laneIndex, ExpressionType& result) -> PartialResult
{
B3::Air::Opcode opcode;
Width width;
switch (op) {
case SIMDLaneOperation::LoadLane8:
opcode = VectorLoad8Lane;
width = Width8;
break;
case SIMDLaneOperation::LoadLane16:
opcode = VectorLoad16Lane;
width = Width16;
break;
case SIMDLaneOperation::LoadLane32:
opcode = VectorLoad32Lane;
width = Width32;
break;
case SIMDLaneOperation::LoadLane64:
opcode = VectorLoad64Lane;
width = Width64;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
result = v128();
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeSimpleAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(width)), offset);
append(MoveVector, vector, result);
appendEffectful(opcode, addrArg, Arg::imm(laneIndex), result);
return { };
}
auto AirIRGenerator64::addSIMDStoreLane(SIMDLaneOperation op, ExpressionType pointer, ExpressionType vector, uint32_t uoffset, uint8_t laneIndex) -> PartialResult
{
B3::Air::Opcode opcode;
Width width;
switch (op) {
case SIMDLaneOperation::StoreLane8:
opcode = VectorStore8Lane;
width = Width8;
break;
case SIMDLaneOperation::StoreLane16:
opcode = VectorStore16Lane;
width = Width16;
break;
case SIMDLaneOperation::StoreLane32:
opcode = VectorStore32Lane;
width = Width32;
break;
case SIMDLaneOperation::StoreLane64:
opcode = VectorStore64Lane;
width = Width64;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeSimpleAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(width)), offset);
appendEffectful(opcode, vector, addrArg, Arg::imm(laneIndex));
return { };
}
auto AirIRGenerator64::addSIMDLoadExtend(SIMDLaneOperation op, ExpressionType pointer, uint32_t uoffset, ExpressionType& result) -> PartialResult
{
SIMDLane lane;
SIMDSignMode signMode;
switch (op) {
case SIMDLaneOperation::LoadExtend8U:
lane = SIMDLane::i16x8;
signMode = SIMDSignMode::Unsigned;
break;
case SIMDLaneOperation::LoadExtend8S:
lane = SIMDLane::i16x8;
signMode = SIMDSignMode::Signed;
break;
case SIMDLaneOperation::LoadExtend16U:
lane = SIMDLane::i32x4;
signMode = SIMDSignMode::Unsigned;
break;
case SIMDLaneOperation::LoadExtend16S:
lane = SIMDLane::i32x4;
signMode = SIMDSignMode::Signed;
break;
case SIMDLaneOperation::LoadExtend32U:
lane = SIMDLane::i64x2;
signMode = SIMDSignMode::Unsigned;
break;
case SIMDLaneOperation::LoadExtend32S:
lane = SIMDLane::i64x2;
signMode = SIMDSignMode::Signed;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
result = v128();
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(Width64)), offset, Width64);
appendEffectful(MoveDouble, addrArg, result);
append(VectorExtendLow, Arg::simdInfo({ lane, signMode }), result, result);
return { };
}
auto AirIRGenerator64::addSIMDLoadPad(SIMDLaneOperation op, ExpressionType pointer, uint32_t uoffset, ExpressionType& result) -> PartialResult
{
B3::Air::Opcode airOp;
Width width;
switch (op) {
case SIMDLaneOperation::LoadPad32:
width = Width32;
airOp = MoveFloat;
break;
case SIMDLaneOperation::LoadPad64:
width = Width64;
airOp = MoveDouble;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
result = v128();
auto offset = fixupPointerPlusOffset(pointer, uoffset);
Arg addrArg = materializeAddrArg(emitCheckAndPreparePointer(pointer, offset, bytesForWidth(Width64)), offset, width);
appendEffectful(airOp, addrArg, result);
return { };
}
void AirIRGenerator64::finalizeEntrypoints()
{
unsigned numEntrypoints = Checked<unsigned>(1) + m_catchEntrypoints.size() + m_loopEntryVariableData.size();
m_proc.setNumEntrypoints(numEntrypoints);
m_code.setPrologueForEntrypoint(0, Ref<B3::Air::PrologueGenerator>(*m_prologueGenerator));
for (unsigned i = 1 + m_catchEntrypoints.size(); i < numEntrypoints; ++i)
m_code.setPrologueForEntrypoint(i, Ref<B3::Air::PrologueGenerator>(*m_prologueGenerator));
if (m_catchEntrypoints.size()) {
Ref<B3::Air::PrologueGenerator> catchPrologueGenerator = createSharedTask<B3::Air::PrologueGeneratorFunction>([](CCallHelpers& jit, B3::Air::Code& code) {
AllowMacroScratchRegisterUsage allowScratch(jit);
jit.addPtr(CCallHelpers::TrustedImm32(-code.frameSize()), GPRInfo::callFrameRegister, CCallHelpers::stackPointerRegister);
jit.probe(tagCFunction<JITProbePtrTag>(code.usesSIMD() ? buildEntryBufferForCatchSIMD : buildEntryBufferForCatchNoSIMD), nullptr, code.usesSIMD() ? SavedFPWidth::SaveVectors : SavedFPWidth::DontSaveVectors);
});
for (unsigned i = 0; i < m_catchEntrypoints.size(); ++i)
m_code.setPrologueForEntrypoint(1 + i, catchPrologueGenerator.copyRef());
}
BasicBlock::SuccessorList successors;
successors.append(m_mainEntrypointStart);
successors.appendVector(m_catchEntrypoints);
ASSERT(!m_loopEntryVariableData.size() || !m_proc.usesSIMD());
for (auto& pair : m_loopEntryVariableData) {
BasicBlock* loopBody = pair.first;
BasicBlock* entry = m_code.addBlock();
successors.append(entry);
m_currentBlock = entry;
auto& temps = pair.second;
m_osrEntryScratchBufferSize = std::max(m_osrEntryScratchBufferSize, static_cast<unsigned>(temps.size()));
Tmp basePtr = Tmp(GPRInfo::argumentGPR0);
for (size_t i = 0; i < temps.size(); ++i) {
size_t offset = static_cast<size_t>(i) * sizeof(uint64_t);
self().emitLoad(basePtr, offset, temps[i]);
}
append(Jump);
entry->setSuccessors(loopBody);
}
RELEASE_ASSERT(numEntrypoints == successors.size());
m_rootBlock->successors() = successors;
}
Tmp AirIRGenerator64::emitCatchImpl(CatchKind kind, ControlType& data, unsigned exceptionIndex)
{
m_currentBlock = m_code.addBlock();
m_catchEntrypoints.append(m_currentBlock);
if (ControlType::isTry(data)) {
if (kind == CatchKind::Catch)
data.convertTryToCatch(++m_callSiteIndex, g64());
else
data.convertTryToCatchAll(++m_callSiteIndex, g64());
}
// We convert from "try" to "catch" ControlType above. This doesn't
// happen if ControlType is already a "catch". This can happen when
// we have multiple catches like "try {} catch(A){} catch(B){}...CatchAll(E){}".
// We just convert the first ControlType to a catch, then the others will
// use its fields.
ASSERT(ControlType::isAnyCatch(data));
HandlerType handlerType = kind == CatchKind::Catch ? HandlerType::Catch : HandlerType::CatchAll;
m_exceptionHandlers.append({ handlerType, data.tryStart(), data.tryEnd(), 0, m_tryCatchDepth, exceptionIndex });
restoreWebAssemblyGlobalState(m_info.memory, instanceValue(), m_currentBlock);
unsigned indexInBuffer = 0;
unsigned valueSize = m_proc.usesSIMD() ? 2 : 1;
auto loadFromScratchBuffer = [&] (TypedTmp result) {
size_t offset = valueSize * sizeof(uint64_t) * indexInBuffer;
++indexInBuffer;
Tmp bufferPtr = Tmp(GPRInfo::argumentGPR0);
emitLoad(bufferPtr, offset, result);
};
append(Move, Tmp(GPRInfo::argumentGPR1), data.exception());
forEachLiveValue([&] (TypedTmp tmp) {
// We set our current ControlEntry's exception below after the patchpoint, it's
// not in the incoming buffer of live values.
auto toIgnore = data.exception();
if (tmp.tmp() != toIgnore.tmp())
loadFromScratchBuffer(tmp);
});
return Tmp(GPRInfo::argumentGPR2);
}
auto AirIRGenerator64::addReturn(const ControlData& data, const Stack& returnValues) -> PartialResult
{
CallInformation wasmCallInfo = wasmCallingConvention().callInformationFor(*data.signature(), CallRole::Callee);
if (!wasmCallInfo.results.size()) {
append(RetVoid);
return { };
}
B3::PatchpointValue* patch = addPatchpoint(B3::Void);
patch->setGenerator([] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
params.code().emitEpilogue(jit);
});
patch->effects.terminal = true;
ASSERT(returnValues.size() >= wasmCallInfo.results.size());
unsigned offset = returnValues.size() - wasmCallInfo.results.size();
Vector<ConstrainedTmp, 8> returnConstraints;
for (unsigned i = 0; i < wasmCallInfo.results.size(); ++i) {
B3::ValueRep rep = wasmCallInfo.results[i].location;
TypedTmp tmp = returnValues[offset + i];
if (rep.isStack()) {
Arg arg = Arg::addr(Tmp(GPRInfo::callFrameRegister), rep.offsetFromFP());
B3::Air::Opcode opcode = moveForType(toB3Type(tmp.type()));
Width width = tmp.type().width();
if (arg.isValidForm(opcode, width))
append(opcode, tmp, arg);
else {
auto immTmp = self().gPtr();
auto newPtr = self().gPtr();
append(Move, Arg::bigImm(arg.offset()), immTmp);
append(AddPtr, Tmp(GPRInfo::callFrameRegister), immTmp, newPtr);
append(opcode, tmp, Arg::addr(newPtr));
}
continue;
}
ASSERT(rep.isReg());
if (data.signature()->as<FunctionSignature>()->returnType(i).isI32())
append(Move32, tmp, tmp);
returnConstraints.append(ConstrainedTmp(tmp, rep));
}
emitPatchpoint(m_currentBlock, patch, ResultList { }, WTFMove(returnConstraints));
return { };
}
auto AirIRGenerator64::addThrow(unsigned exceptionIndex, Vector<ExpressionType>& args, Stack&) -> PartialResult
{
B3::PatchpointValue* patch = addPatchpoint(B3::Void);
patch->effects.terminal = true;
patch->clobber(RegisterSetBuilder::registersToSaveForJSCall(m_proc.usesSIMD() ? RegisterSetBuilder::allRegisters() : RegisterSetBuilder::allScalarRegisters()));
Vector<ConstrainedTmp, 8> patchArgs;
patchArgs.append(ConstrainedTmp(instanceValue(), B3::ValueRep::reg(GPRInfo::argumentGPR0)));
for (unsigned i = 0; i < args.size(); ++i) {
// Note: SIMD values can appear here, but should never be read at runtime because this will throw an un-catchable TypeError instead.
// Nonetheless, they may clobber important things if they aren't treated as doubles.
auto arg = args[i];
if (args[i].type().isV128())
arg = TypedTmp(args[i].tmp(), Types::F64);
patchArgs.append(ConstrainedTmp(arg, B3::ValueRep::stackArgument(i * sizeof(EncodedJSValue))));
}
auto handle = preparePatchpointForExceptions(patch, patchArgs);
patch->setGenerator([this, exceptionIndex, handle] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
AllowMacroScratchRegisterUsage allowScratch(jit);
if (handle)
handle->generate(jit, params, this);
emitThrowImpl(jit, exceptionIndex);
});
emitPatchpoint(m_currentBlock, patch, Tmp(), WTFMove(patchArgs));
return { };
}
auto AirIRGenerator64::addRethrow(unsigned, ControlType& data) -> PartialResult
{
B3::PatchpointValue* patch = addPatchpoint(B3::Void);
patch->clobber(RegisterSetBuilder::registersToSaveForJSCall(m_proc.usesSIMD() ? RegisterSetBuilder::allRegisters() : RegisterSetBuilder::allScalarRegisters()));
patch->effects.terminal = true;
Vector<ConstrainedTmp, 3> patchArgs;
patchArgs.append(ConstrainedTmp(instanceValue(), B3::ValueRep::reg(GPRInfo::argumentGPR0)));
patchArgs.append(ConstrainedTmp(data.exception(), B3::ValueRep::reg(GPRInfo::argumentGPR1)));
auto handle = preparePatchpointForExceptions(patch, patchArgs);
patch->setGenerator([this, handle] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
AllowMacroScratchRegisterUsage allowScratch(jit);
if (handle)
handle->generate(jit, params, this);
emitRethrowImpl(jit);
});
emitPatchpoint(m_currentBlock, patch, Tmp(), WTFMove(patchArgs));
return { };
}
auto AirIRGenerator64::emitCallPatchpoint(BasicBlock* block, B3::Type returnType, const ResultList& results, const Vector<TypedTmp>& tmpArgs, const CallInformation& wasmCalleeInfo, Vector<ConstrainedTmp> patchArgs) -> CallPatchpointData
{
auto* patchpoint = addPatchpoint(returnType);
patchpoint->effects.writesPinned = true;
patchpoint->effects.readsPinned = true;
patchpoint->clobberEarly(RegisterSetBuilder::macroClobberedGPRs());
patchpoint->clobberLate(RegisterSetBuilder::registersToSaveForJSCall(m_proc.usesSIMD() ? RegisterSetBuilder::allRegisters() : RegisterSetBuilder::allScalarRegisters()));
size_t offset = patchArgs.size();
Checked<size_t> newSize = checkedSum<size_t>(patchArgs.size(), tmpArgs.size());
RELEASE_ASSERT(!newSize.hasOverflowed());
patchArgs.grow(newSize);
const Vector<ArgumentLocation>& constrainedArgLocations = wasmCalleeInfo.params;
for (unsigned i = 0; i < tmpArgs.size(); ++i)
patchArgs[i + offset] = ConstrainedTmp(tmpArgs[i], constrainedArgLocations[i]);
const Vector<ArgumentLocation, 1>& constrainedResultLocations = wasmCalleeInfo.results;
if (patchpoint->type() != B3::Void) {
Vector<B3::ValueRep, 1> resultConstraints;
for (auto resultLocation : constrainedResultLocations)
resultConstraints.append(B3::ValueRep(resultLocation.location));
patchpoint->resultConstraints = WTFMove(resultConstraints);
}
auto exceptionHandle = preparePatchpointForExceptions(patchpoint, patchArgs);
emitPatchpoint(block, patchpoint, results, WTFMove(patchArgs));
return { patchpoint, WTFMove(exceptionHandle) };
}
auto AirIRGenerator64::emitTailCallPatchpoint(BasicBlock* block, const Checked<int32_t>& tailCallStackOffsetFromFP, const Vector<ArgumentLocation>& constrainedArgLocations, const Vector<TypedTmp>& tmpArgs, Vector<ConstrainedTmp> patchArgs) -> CallPatchpointData
{
// Layout of stack right before tail call F -> G
//
//
// | ...... | | ...... |
// +----------------------------+ <-- 0x5501ff4ff0 +----------------------------+ <-- 0x5501ff4ff0
// | F.argN | | +--------------------> | G.argM | |
// +----------------------------+ | lower address | +----------------------------+ | lower address
// | F.arg1 | v | | arg1 | v
// +----------------------------+ | +----------------------------+
// | F.arg0 | | | arg0 |
// +----------------------------+ | +----------------------------+
// | F.this | | | this' |
// +----------------------------+ | +----------------------------+
// | argumentCountIncludingThis | | | A.C.I.T.' |
// +----------------------------+ | +----------------------------+
// | F.callee (aka F, unused in wasm) | | | G.callee |
// +----------------------------+ | +----------------------------+
// | F.codeBlock | (shuffleStackArgs...) | G.codeBlock |
// +----------------------------+ | +----------------------------+
// | return-address after F | | | return-address after F |
// +----------------------------+ | SP at G prologue -> +----------------------------+
// | F.caller.FP | | | F.caller.FP |
// +----------------------------+ <- F.FP | G.FP after G prologue-> +----------------------------+
// | callee saves | | | callee saves |
// +----------------------------+ <----+ argM to G ------------------+ +----------------------------+
// | F.local0 | | .... | G.local0 |
// +----------------------------+ | arg0 to G +----------------------------+
// | F.local1 | | | G.local1 |
// +----------------------------+ | +----------------------------+
// | F.localN | | | G.localM |
// +----------------------------| | +----------------------------+
// | ...... | | | ...... |
// +----------------------------| <- SP | SP after G prologue-> +----------------------------+
// |
// +- New tmp stack slots are eventually allocated here
//
// See https://leaningtech.com/fantastic-tail-calls-and-how-to-implement-them/ for a more in-depth explanation.
auto shuffleStackArg = [this, block, tailCallStackOffsetFromFP] (Tmp tmp, int32_t offsetFromSP) -> void {
Checked<int32_t> offsetFromFP = tailCallStackOffsetFromFP + offsetFromSP;
if (offsetFromFP < 0) {
StackSlot* stackSlot = m_code.addStackSlot(sizeof(Register), StackSlotKind::Locked);
stackSlot->setOffsetFromFP(offsetFromFP);
append(block, tmp.isGP() ? Move : MoveDouble, tmp, Arg::stack(stackSlot));
return;
}
append(block, tmp.isGP() ? Move : MoveDouble, tmp, Arg::addr(Tmp(GPRInfo::callFrameRegister), offsetFromFP));
};
auto tmp = g64();
append(block, Move, Arg::addr(Tmp(MacroAssembler::framePointerRegister), CallFrame::returnPCOffset()), tmp);
shuffleStackArg(tmp, -static_cast<int32_t>(sizeof(Register)));
append(block, Move, Arg::addr(Tmp(MacroAssembler::framePointerRegister)), tmp);
auto* patchpoint = addPatchpoint(B3::Void);
patchpoint->effects.terminal = true;
patchpoint->effects.readsPinned = true;
patchpoint->effects.writesPinned = true;
RegisterSetBuilder clobbers;
clobbers.merge(RegisterSetBuilder::calleeSaveRegisters());
clobbers.exclude(RegisterSetBuilder::stackRegisters());
patchpoint->clobber(clobbers);
patchpoint->clobberEarly(RegisterSetBuilder::macroClobberedGPRs());
for (unsigned i = 0; i < tmpArgs.size(); ++i) {
TypedTmp tmp = tmpArgs[i];
RELEASE_ASSERT(!tmp.type().isV128());
if (constrainedArgLocations[i].location.isStackArgument()) {
shuffleStackArg(tmp, constrainedArgLocations[i].location.offsetFromSP());
continue;
}
patchArgs.append(ConstrainedTmp(tmp, constrainedArgLocations[i]));
}
patchArgs.append({ tmp, B3::ValueRep(MacroAssembler::framePointerRegister) });
emitPatchpoint(block, patchpoint, Tmp { }, WTFMove(patchArgs));
return { patchpoint, nullptr };
}
template<typename IntType>
void AirIRGenerator64::emitModOrDiv(bool isDiv, ExpressionType lhs, ExpressionType rhs, ExpressionType& result)
{
static_assert(sizeof(IntType) == 4 || sizeof(IntType) == 8);
result = sizeof(IntType) == 4 ? g32() : g64();
bool isSigned = std::is_signed<IntType>::value;
if (isARM64()) {
B3::Air::Opcode div;
switch (sizeof(IntType)) {
case 4:
div = isSigned ? Div32 : UDiv32;
break;
case 8:
div = isSigned ? Div64 : UDiv64;
break;
}
append(div, lhs, rhs, result);
if (!isDiv) {
append(sizeof(IntType) == 4 ? Mul32 : Mul64, result, rhs, result);
append(sizeof(IntType) == 4 ? Sub32 : Sub64, lhs, result, result);
}
return;
}
#if CPU(X86_64)
Tmp eax(X86Registers::eax);
Tmp edx(X86Registers::edx);
if (isSigned) {
B3::Air::Opcode convertToDoubleWord;
B3::Air::Opcode div;
switch (sizeof(IntType)) {
case 4:
convertToDoubleWord = X86ConvertToDoubleWord32;
div = X86Div32;
break;
case 8:
convertToDoubleWord = X86ConvertToQuadWord64;
div = X86Div64;
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
// We implement "res = Div<Chill>/Mod<Chill>(num, den)" as follows:
//
// if (den + 1 <=_unsigned 1) {
// if (!den) {
// res = 0;
// goto done;
// }
// if (num == -2147483648) {
// res = isDiv ? num : 0;
// goto done;
// }
// }
// res = num (/ or %) dev;
// done:
BasicBlock* denIsGood = m_code.addBlock();
BasicBlock* denMayBeBad = m_code.addBlock();
BasicBlock* denNotZero = m_code.addBlock();
BasicBlock* continuation = m_code.addBlock();
auto temp = sizeof(IntType) == 4 ? g32() : g64();
auto one = addConstant(sizeof(IntType) == 4 ? Types::I32 : Types::I64, 1);
append(sizeof(IntType) == 4 ? Add32 : Add64, rhs, one, temp);
append(sizeof(IntType) == 4 ? Branch32 : Branch64, Arg::relCond(MacroAssembler::Above), temp, one);
m_currentBlock->setSuccessors(denIsGood, denMayBeBad);
append(denMayBeBad, Xor64, result, result);
append(denMayBeBad, sizeof(IntType) == 4 ? BranchTest32 : BranchTest64, Arg::resCond(MacroAssembler::Zero), rhs, rhs);
denMayBeBad->setSuccessors(continuation, denNotZero);
auto min = addConstant(denNotZero, sizeof(IntType) == 4 ? Types::I32 : Types::I64, std::numeric_limits<IntType>::min());
if (isDiv)
append(denNotZero, sizeof(IntType) == 4 ? Move32 : Move, min, result);
// Otherwise, result is zero, as set above...
append(denNotZero, sizeof(IntType) == 4 ? Branch32 : Branch64, Arg::relCond(MacroAssembler::Equal), lhs, min);
denNotZero->setSuccessors(continuation, denIsGood);
auto divResult = isDiv ? eax : edx;
append(denIsGood, Move, lhs, eax);
append(denIsGood, convertToDoubleWord, eax, edx);
append(denIsGood, div, eax, edx, rhs);
append(denIsGood, sizeof(IntType) == 4 ? Move32 : Move, divResult, result);
append(denIsGood, Jump);
denIsGood->setSuccessors(continuation);
m_currentBlock = continuation;
return;
}
B3::Air::Opcode div = sizeof(IntType) == 4 ? X86UDiv32 : X86UDiv64;
Tmp divResult = isDiv ? eax : edx;
append(Move, lhs, eax);
append(Xor64, edx, edx);
append(div, eax, edx, rhs);
append(sizeof(IntType) == 4 ? Move32 : Move, divResult, result);
#else
RELEASE_ASSERT_NOT_REACHED();
#endif
}
auto AirIRGenerator64::addShift(Type type, B3::Air::Opcode op, ExpressionType value, ExpressionType shift, ExpressionType& result) -> PartialResult
{
ASSERT(type.isI64() || type.isI32());
result = tmpForType(type);
if (isValidForm(op, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(op, value, shift, result);
return { };
}
#if CPU(X86_64)
Tmp ecx = Tmp(X86Registers::ecx);
append(Move, value, result);
append(Move, shift, ecx);
append(op, ecx, result);
#else
RELEASE_ASSERT_NOT_REACHED();
#endif
return { };
}
auto AirIRGenerator64::addIntegerSub(B3::Air::Opcode op, ExpressionType lhs, ExpressionType rhs, ExpressionType& result) -> PartialResult
{
ASSERT(op == Sub32 || op == Sub64);
result = op == Sub32 ? g32() : g64();
if (isValidForm(op, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(op, lhs, rhs, result);
return { };
}
RELEASE_ASSERT(isX86());
// Sub a, b
// means
// b = b Sub a
append(Move, lhs, result);
append(op, rhs, result);
return { };
}
auto AirIRGenerator64::addFloatingPointAbs(B3::Air::Opcode op, ExpressionType value, ExpressionType& result) -> PartialResult
{
RELEASE_ASSERT(op == AbsFloat || op == AbsDouble);
result = op == AbsFloat ? f32() : f64();
if (isValidForm(op, Arg::Tmp, Arg::Tmp)) {
append(op, value, result);
return { };
}
RELEASE_ASSERT(isX86());
if (op == AbsFloat) {
auto constant = g32();
append(Move, Arg::imm(static_cast<uint32_t>(~(1ull << 31))), constant);
append(Move32ToFloat, constant, result);
append(AndFloat, value, result);
} else {
auto constant = g64();
append(Move, Arg::bigImm(~(1ull << 63)), constant);
append(Move64ToDouble, constant, result);
append(AndDouble, value, result);
}
return { };
}
auto AirIRGenerator64::addFloatingPointBinOp(Type type, B3::Air::Opcode op, ExpressionType lhs, ExpressionType rhs, ExpressionType& result) -> PartialResult
{
ASSERT(type.isF32() || type.isF64());
result = tmpForType(type);
if (isValidForm(op, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
append(op, lhs, rhs, result);
return { };
}
RELEASE_ASSERT(isX86());
// Op a, b
// means
// b = b Op a
append(moveOpForValueType(type), lhs, result);
append(op, rhs, result);
return { };
}
auto AirIRGenerator64::addCompare(Type type, MacroAssembler::RelationalCondition cond, ExpressionType lhs, ExpressionType rhs, ExpressionType& result) -> PartialResult
{
ASSERT(type.isI32() || type.isI64());
result = g32();
if (type.isI32()) {
append(Compare32, Arg::relCond(cond), lhs, rhs, result);
return { };
}
append(Compare64, Arg::relCond(cond), lhs, rhs, result);
return { };
}
template <size_t inlineCapacity>
Box<PatchpointExceptionHandle> AirIRGenerator64::preparePatchpointForExceptions(B3::PatchpointValue* patch, Vector<ConstrainedTmp, inlineCapacity>& args)
{
++m_callSiteIndex;
if (!m_tryCatchDepth)
return Box<PatchpointExceptionHandle>::create(m_hasExceptionHandlers);
unsigned numLiveValues = 0;
forEachLiveValue([&] (auto tmp) {
++numLiveValues;
args.append(ConstrainedTmp(tmp, B3::ValueRep::LateColdAny));
});
patch->effects.exitsSideways = true;
return Box<PatchpointExceptionHandle>::create(m_hasExceptionHandlers, m_callSiteIndex, numLiveValues);
}
auto AirIRGenerator64::addI64Ctz(ExpressionType arg, ExpressionType& result) -> PartialResult
{
auto* patchpoint = addPatchpoint(B3::Int64);
patchpoint->effects = B3::Effects::none();
patchpoint->setGenerator([=](auto& jit, const B3::StackmapGenerationParams& params) {
jit.countTrailingZeros64(params[1].gpr(), params[0].gpr());
});
result = g64();
emitPatchpoint(patchpoint, result, arg);
return { };
}
auto AirIRGenerator64::addF64ConvertUI64(ExpressionType arg, ExpressionType& result) -> PartialResult
{
auto* patchpoint = addPatchpoint(B3::Double);
patchpoint->effects = B3::Effects::none();
if (isX86())
patchpoint->numGPScratchRegisters = 1;
patchpoint->clobber(RegisterSetBuilder::macroClobberedGPRs());
patchpoint->setGenerator([=](CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
AllowMacroScratchRegisterUsage allowScratch(jit);
#if CPU(X86_64)
jit.convertUInt64ToDouble(params[1].gpr(), params[0].fpr(), params.gpScratch(0));
#else
jit.convertUInt64ToDouble(params[1].gpr(), params[0].fpr());
#endif
});
result = f64();
emitPatchpoint(patchpoint, result, arg);
return { };
}
auto AirIRGenerator64::addF32ConvertUI64(ExpressionType arg, ExpressionType& result) -> PartialResult
{
auto* patchpoint = addPatchpoint(B3::Float);
patchpoint->effects = B3::Effects::none();
if (isX86())
patchpoint->numGPScratchRegisters = 1;
patchpoint->clobber(RegisterSetBuilder::macroClobberedGPRs());
patchpoint->setGenerator([=](CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
AllowMacroScratchRegisterUsage allowScratch(jit);
#if CPU(X86_64)
jit.convertUInt64ToFloat(params[1].gpr(), params[0].fpr(), params.gpScratch(0));
#else
jit.convertUInt64ToFloat(params[1].gpr(), params[0].fpr());
#endif
});
result = f32();
emitPatchpoint(patchpoint, result, arg);
return { };
}
auto AirIRGenerator64::addUncheckedFloatingPointTruncation(FloatingPointTruncationKind kind, ExpressionType arg, ExpressionType result) -> PartialResult
{
auto* patchpoint = addPatchpoint(toB3Type(result.type()));
patchpoint->effects = B3::Effects::none();
patchpoint->setGenerator([=](CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
switch (kind) {
case FloatingPointTruncationKind::F32ToI32:
jit.truncateFloatToInt32(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F32ToU32:
jit.truncateFloatToUint32(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F32ToI64:
jit.truncateFloatToInt64(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F32ToU64: {
AllowMacroScratchRegisterUsageIf allowScratch(jit, isX86());
FPRReg scratch = InvalidFPRReg;
FPRReg constant = InvalidFPRReg;
if (isX86()) {
scratch = params.fpScratch(0);
constant = params[2].fpr();
}
jit.truncateFloatToUint64(params[1].fpr(), params[0].gpr(), scratch, constant);
break;
}
case FloatingPointTruncationKind::F64ToI32:
jit.truncateDoubleToInt32(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F64ToU32:
jit.truncateDoubleToUint32(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F64ToI64:
jit.truncateDoubleToInt64(params[1].fpr(), params[0].gpr());
break;
case FloatingPointTruncationKind::F64ToU64: {
AllowMacroScratchRegisterUsageIf allowScratch(jit, isX86());
FPRReg scratch = InvalidFPRReg;
FPRReg constant = InvalidFPRReg;
if (isX86()) {
scratch = params.fpScratch(0);
constant = params[2].fpr();
}
jit.truncateDoubleToUint64(params[1].fpr(), params[0].gpr(), scratch, constant);
break;
}
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
});
if (isX86()) {
switch (kind) {
case FloatingPointTruncationKind::F32ToU64: {
auto signBitConstant = addConstant(Types::F32, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max())));
patchpoint->clobber(RegisterSetBuilder::macroClobberedGPRs());
patchpoint->numFPScratchRegisters = 1;
emitPatchpoint(
m_currentBlock, patchpoint,
Vector<TypedTmp, 8>::from(result),
Vector<ConstrainedTmp, 2>::from(arg, signBitConstant)
);
return { };
}
case FloatingPointTruncationKind::F64ToU64: {
auto signBitConstant = addConstant(Types::F64, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max())));
patchpoint->clobber(RegisterSetBuilder::macroClobberedGPRs());
patchpoint->numFPScratchRegisters = 1;
emitPatchpoint(
m_currentBlock, patchpoint,
Vector<TypedTmp, 8>::from(result),
Vector<ConstrainedTmp, 2>::from(arg, signBitConstant)
);
return { };
}
default:
break;
}
}
emitPatchpoint(patchpoint, result, arg);
return { };
}
auto AirIRGenerator64::addF64ConvertUI32(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = f64();
auto temp = g64();
append(Move32, arg0, temp);
append(ConvertInt64ToDouble, temp, result);
return { };
}
auto AirIRGenerator64::addI64And(ExpressionType arg0, ExpressionType arg1, ExpressionType& result) -> PartialResult
{
result = g64();
append(And64, arg0, arg1, result);
return { };
}
auto AirIRGenerator64::addI64Eqz(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = g32();
append(Test64, Arg::resCond(MacroAssembler::Zero), arg0, arg0, result);
return { };
}
auto AirIRGenerator64::addI64Or(ExpressionType arg0, ExpressionType arg1, ExpressionType& result) -> PartialResult
{
result = g64();
append(Or64, arg0, arg1, result);
return { };
}
auto AirIRGenerator64::addI64ExtendSI32(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = g64();
append(SignExtend32To64, arg0, result);
return { };
}
auto AirIRGenerator64::addI64Extend8S(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = g64();
append(SignExtend8To64, arg0, result);
return { };
}
auto AirIRGenerator64::addI64Extend16S(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = g64();
append(SignExtend16To64, arg0, result);
return { };
}
auto AirIRGenerator64::addI64Extend32S(ExpressionType arg0, ExpressionType& result) -> PartialResult
{
result = g64();
append(SignExtend32To64, arg0, result);
return { };
}
Expected<std::unique_ptr<InternalFunction>, String> parseAndCompileAir(CompilationContext& compilationContext, Callee& callee, const FunctionData& function, const TypeDefinition& signature, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls, const ModuleInformation& info, MemoryMode mode, uint32_t functionIndex, std::optional<bool> hasExceptionHandlers, TierUpCount* tierUp)
{
Wasm::Thunks::singleton().stub(Wasm::catchInWasmThunkGenerator);
return parseAndCompileAirImpl<AirIRGenerator64>(compilationContext, callee, function, signature, unlinkedWasmToWasmCalls, info, mode, functionIndex, hasExceptionHandlers, tierUp);
}
} } // namespace JSC::Wasm
#endif // USE(JSVALUE64)
|