summaryrefslogtreecommitdiff
path: root/Build/source/libs/luajit/LuaJIT-src/src/vm_mips64.dasc
blob: c06270a0afc4f188d4165594811be872e967405b (plain)
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
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
|// Low-level VM code for MIPS64 CPUs.
|// Bytecode interpreter, fast functions and helper functions.
|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
|//
|// Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.
|// Sponsored by Cisco Systems, Inc.
|
|.arch mips64
|.section code_op, code_sub
|
|.actionlist build_actionlist
|.globals GLOB_
|.globalnames globnames
|.externnames extnames
|
|// Note: The ragged indentation of the instructions is intentional.
|//       The starting columns indicate data dependencies.
|
|//-----------------------------------------------------------------------
|
|// Fixed register assignments for the interpreter.
|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra
|
|.macro .FPU, a, b
|.if FPU
|  a, b
|.endif
|.endmacro
|
|// The following must be C callee-save (but BASE is often refetched).
|.define BASE,		r16	// Base of current Lua stack frame.
|.define KBASE,		r17	// Constants of current Lua function.
|.define PC,		r18	// Next PC.
|.define DISPATCH,	r19	// Opcode dispatch table.
|.define LREG,		r20	// Register holding lua_State (also in SAVE_L).
|.define MULTRES,	r21	// Size of multi-result: (nresults+1)*8.
|
|.define JGL,		r30	// On-trace: global_State + 32768.
|
|// Constants for type-comparisons, stores and conversions. C callee-save.
|.define TISNIL,	r30
|.define TISNUM,	r22
|.if FPU
|.define TOBIT,		f30	// 2^52 + 2^51.
|.endif
|
|// The following temporaries are not saved across C calls, except for RA.
|.define RA,		r23	// Callee-save.
|.define RB,		r8
|.define RC,		r9
|.define RD,		r10
|.define INS,		r11
|
|.define AT,		r1	// Assembler temporary.
|.define TMP0,		r12
|.define TMP1,		r13
|.define TMP2,		r14
|.define TMP3,		r15
|
|// MIPS n64 calling convention.
|.define CFUNCADDR,	r25
|.define CARG1,		r4
|.define CARG2,		r5
|.define CARG3,		r6
|.define CARG4,		r7
|.define CARG5,		r8
|.define CARG6,		r9
|.define CARG7,		r10
|.define CARG8,		r11
|
|.define CRET1,		r2
|.define CRET2,		r3
|
|.if FPU
|.define FARG1,		f12
|.define FARG2,		f13
|.define FARG3,		f14
|.define FARG4,		f15
|.define FARG5,		f16
|.define FARG6,		f17
|.define FARG7,		f18
|.define FARG8,		f19
|
|.define FRET1,		f0
|.define FRET2,		f2
|.endif
|
|// Stack layout while in interpreter. Must match with lj_frame.h.
|.if FPU		// MIPS64 hard-float.
|
|.define CFRAME_SPACE,	192	// Delta for sp.
|
|//----- 16 byte aligned, <-- sp entering interpreter
|.define SAVE_ERRF,	188(sp)	// 32 bit values.
|.define SAVE_NRES,	184(sp)
|.define SAVE_CFRAME,	176(sp)	// 64 bit values.
|.define SAVE_L,	168(sp)
|.define SAVE_PC,	160(sp)
|//----- 16 byte aligned
|.define SAVE_GPR_,	80	// .. 80+10*8: 64 bit GPR saves.
|.define SAVE_FPR_,	16	// .. 16+8*8: 64 bit FPR saves.
|
|.else			// MIPS64 soft-float
|
|.define CFRAME_SPACE,	128	// Delta for sp.
|
|//----- 16 byte aligned, <-- sp entering interpreter
|.define SAVE_ERRF,	124(sp)	// 32 bit values.
|.define SAVE_NRES,	120(sp)
|.define SAVE_CFRAME,	112(sp)	// 64 bit values.
|.define SAVE_L,	104(sp)
|.define SAVE_PC,	96(sp)
|//----- 16 byte aligned
|.define SAVE_GPR_,	16	// .. 16+10*8: 64 bit GPR saves.
|
|.endif
|
|.define TMPX,		8(sp)	// Unused by interpreter, temp for JIT code.
|.define TMPD,		0(sp)
|//----- 16 byte aligned
|
|.define TMPD_OFS,	0
|
|.define SAVE_MULTRES,	TMPD
|
|//-----------------------------------------------------------------------
|
|.macro saveregs
|  daddiu sp, sp, -CFRAME_SPACE
|  sd ra, SAVE_GPR_+9*8(sp)
|  sd r30, SAVE_GPR_+8*8(sp)
|   .FPU sdc1 f31, SAVE_FPR_+7*8(sp)
|  sd r23, SAVE_GPR_+7*8(sp)
|   .FPU sdc1 f30, SAVE_FPR_+6*8(sp)
|  sd r22, SAVE_GPR_+6*8(sp)
|   .FPU sdc1 f29, SAVE_FPR_+5*8(sp)
|  sd r21, SAVE_GPR_+5*8(sp)
|   .FPU sdc1 f28, SAVE_FPR_+4*8(sp)
|  sd r20, SAVE_GPR_+4*8(sp)
|   .FPU sdc1 f27, SAVE_FPR_+3*8(sp)
|  sd r19, SAVE_GPR_+3*8(sp)
|   .FPU sdc1 f26, SAVE_FPR_+2*8(sp)
|  sd r18, SAVE_GPR_+2*8(sp)
|   .FPU sdc1 f25, SAVE_FPR_+1*8(sp)
|  sd r17, SAVE_GPR_+1*8(sp)
|   .FPU sdc1 f24, SAVE_FPR_+0*8(sp)
|  sd r16, SAVE_GPR_+0*8(sp)
|.endmacro
|
|.macro restoreregs_ret
|  ld ra, SAVE_GPR_+9*8(sp)
|  ld r30, SAVE_GPR_+8*8(sp)
|  ld r23, SAVE_GPR_+7*8(sp)
|   .FPU ldc1 f31, SAVE_FPR_+7*8(sp)
|  ld r22, SAVE_GPR_+6*8(sp)
|   .FPU ldc1 f30, SAVE_FPR_+6*8(sp)
|  ld r21, SAVE_GPR_+5*8(sp)
|   .FPU ldc1 f29, SAVE_FPR_+5*8(sp)
|  ld r20, SAVE_GPR_+4*8(sp)
|   .FPU ldc1 f28, SAVE_FPR_+4*8(sp)
|  ld r19, SAVE_GPR_+3*8(sp)
|   .FPU ldc1 f27, SAVE_FPR_+3*8(sp)
|  ld r18, SAVE_GPR_+2*8(sp)
|   .FPU ldc1 f26, SAVE_FPR_+2*8(sp)
|  ld r17, SAVE_GPR_+1*8(sp)
|   .FPU ldc1 f25, SAVE_FPR_+1*8(sp)
|  ld r16, SAVE_GPR_+0*8(sp)
|   .FPU ldc1 f24, SAVE_FPR_+0*8(sp)
|  jr ra
|  daddiu sp, sp, CFRAME_SPACE
|.endmacro
|
|// Type definitions. Some of these are only used for documentation.
|.type L,		lua_State,	LREG
|.type GL,		global_State
|.type TVALUE,		TValue
|.type GCOBJ,		GCobj
|.type STR,		GCstr
|.type TAB,		GCtab
|.type LFUNC,		GCfuncL
|.type CFUNC,		GCfuncC
|.type PROTO,		GCproto
|.type UPVAL,		GCupval
|.type NODE,		Node
|.type NARGS8,		int
|.type TRACE,		GCtrace
|.type SBUF,		SBuf
|
|//-----------------------------------------------------------------------
|
|// Trap for not-yet-implemented parts.
|.macro NYI; .long 0xf0f0f0f0; .endmacro
|
|// Macros to mark delay slots.
|.macro ., a; a; .endmacro
|.macro ., a,b; a,b; .endmacro
|.macro ., a,b,c; a,b,c; .endmacro
|.macro ., a,b,c,d; a,b,c,d; .endmacro
|
|.define FRAME_PC,	-8
|.define FRAME_FUNC,	-16
|
|//-----------------------------------------------------------------------
|
|// Endian-specific defines.
|.if ENDIAN_LE
|.define HI,		4
|.define LO,		0
|.define OFS_RD,	2
|.define OFS_RA,	1
|.define OFS_OP,	0
|.else
|.define HI,		0
|.define LO,		4
|.define OFS_RD,	0
|.define OFS_RA,	2
|.define OFS_OP,	3
|.endif
|
|// Instruction decode.
|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro
|.macro decode_OP8a, dst, ins; andi dst, ins, 0xff; .endmacro
|.macro decode_OP8b, dst; sll dst, dst, 3; .endmacro
|.macro decode_RC8a, dst, ins; srl dst, ins, 13; .endmacro
|.macro decode_RC8b, dst; andi dst, dst, 0x7f8; .endmacro
|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro
|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro
|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro
|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro
|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro
|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro
|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro
|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro
|
|// Instruction fetch.
|.macro ins_NEXT1
|  lw INS, 0(PC)
|   daddiu PC, PC, 4
|.endmacro
|// Instruction decode+dispatch.
|.macro ins_NEXT2
|  decode_OP8a TMP1, INS
|  decode_OP8b TMP1
|  daddu TMP0, DISPATCH, TMP1
|   decode_RD8a RD, INS
|  ld AT, 0(TMP0)
|   decode_RA8a RA, INS
|   decode_RD8b RD
|  jr AT
|   decode_RA8b RA
|.endmacro
|.macro ins_NEXT
|  ins_NEXT1
|  ins_NEXT2
|.endmacro
|
|// Instruction footer.
|.if 1
|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
|  .define ins_next, ins_NEXT
|  .define ins_next_, ins_NEXT
|  .define ins_next1, ins_NEXT1
|  .define ins_next2, ins_NEXT2
|.else
|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
|  // Affects only certain kinds of benchmarks (and only with -j off).
|  .macro ins_next
|    b ->ins_next
|  .endmacro
|  .macro ins_next1
|  .endmacro
|  .macro ins_next2
|    b ->ins_next
|  .endmacro
|  .macro ins_next_
|  ->ins_next:
|    ins_NEXT
|  .endmacro
|.endif
|
|// Call decode and dispatch.
|.macro ins_callt
|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
|  ld PC, LFUNC:RB->pc
|  lw INS, 0(PC)
|   daddiu PC, PC, 4
|  decode_OP8a TMP1, INS
|   decode_RA8a RA, INS
|  decode_OP8b TMP1
|   decode_RA8b RA
|  daddu TMP0, DISPATCH, TMP1
|  ld TMP0, 0(TMP0)
|  jr TMP0
|   daddu RA, RA, BASE
|.endmacro
|
|.macro ins_call
|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
|  sd PC, FRAME_PC(BASE)
|  ins_callt
|.endmacro
|
|//-----------------------------------------------------------------------
|
|.macro branch_RD
|  srl TMP0, RD, 1
|  lui AT, (-(BCBIAS_J*4 >> 16) & 65535)
|  addu TMP0, TMP0, AT
|  daddu PC, PC, TMP0
|.endmacro
|
|// Assumes DISPATCH is relative to GL.
#define DISPATCH_GL(field)      (GG_DISP2G + (int)offsetof(global_State, field))
#define DISPATCH_J(field)       (GG_DISP2J + (int)offsetof(jit_State, field))
#define GG_DISP2GOT             (GG_OFS(got) - GG_OFS(dispatch))
#define DISPATCH_GOT(name)      (GG_DISP2GOT + sizeof(void*)*LJ_GOT_##name)
|
#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
|
|.macro load_got, func
|  ld CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)
|.endmacro
|// Much faster. Sadly, there's no easy way to force the required code layout.
|// .macro call_intern, func; bal extern func; .endmacro
|.macro call_intern, func; jalr CFUNCADDR; .endmacro
|.macro call_extern; jalr CFUNCADDR; .endmacro
|.macro jmp_extern; jr CFUNCADDR; .endmacro
|
|.macro hotcheck, delta, target
|  dsrl TMP1, PC, 1
|  andi TMP1, TMP1, 126
|  daddu TMP1, TMP1, DISPATCH
|  lhu TMP2, GG_DISP2HOT(TMP1)
|  addiu TMP2, TMP2, -delta
|  bltz TMP2, target
|.  sh TMP2, GG_DISP2HOT(TMP1)
|.endmacro
|
|.macro hotloop
|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop
|.endmacro
|
|.macro hotcall
|  hotcheck HOTCOUNT_CALL, ->vm_hotcall
|.endmacro
|
|// Set current VM state. Uses TMP0.
|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
|
|// Move table write barrier back. Overwrites mark and tmp.
|.macro barrierback, tab, mark, tmp, target
|  ld tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
|   andi mark, mark, ~LJ_GC_BLACK & 255		// black2gray(tab)
|  sd tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
|   sb mark, tab->marked
|  b target
|.  sd tmp, tab->gclist
|.endmacro
|
|// Clear type tag. Isolate lowest 14+32+1=47 bits of reg.
|.macro cleartp, reg; dextm reg, reg, 0, 14; .endmacro
|.macro cleartp, dst, reg; dextm dst, reg, 0, 14; .endmacro
|
|// Set type tag: Merge 17 type bits into bits [15+32=47, 31+32+1=64) of dst.
|.macro settp, dst, tp; dinsu dst, tp, 15, 31; .endmacro
|
|// Extract (negative) type tag.
|.macro gettp, dst, src; dsra dst, src, 47; .endmacro
|
|// Macros to check the TValue type and extract the GCobj. Branch on failure.
|.macro checktp, reg, tp, target
|  gettp AT, reg
|  daddiu AT, AT, tp
|  bnez AT, target
|.  cleartp reg
|.endmacro
|.macro checktp, dst, reg, tp, target
|  gettp AT, reg
|  daddiu AT, AT, tp
|  bnez AT, target
|.  cleartp dst, reg
|.endmacro
|.macro checkstr, reg, target; checktp reg, -LJ_TSTR, target; .endmacro
|.macro checktab, reg, target; checktp reg, -LJ_TTAB, target; .endmacro
|.macro checkfunc, reg, target; checktp reg, -LJ_TFUNC, target; .endmacro
|.macro checkint, reg, target	// Caveat: has delay slot!
|  gettp AT, reg
|  bne AT, TISNUM, target
|.endmacro
|.macro checknum, reg, target	// Caveat: has delay slot!
|  gettp AT, reg
|  sltiu AT, AT, LJ_TISNUM
|  beqz AT, target
|.endmacro
|
|.macro mov_false, reg
|  lu reg, 0x8000
|  dsll reg, reg, 32
|  not reg, reg
|.endmacro
|.macro mov_true, reg
|  li reg, 0x0001
|  dsll reg, reg, 48
|  not reg, reg
|.endmacro
|
|//-----------------------------------------------------------------------

/* Generate subroutines used by opcodes and other parts of the VM. */
/* The .code_sub section should be last to help static branch prediction. */
static void build_subroutines(BuildCtx *ctx)
{
  |.code_sub
  |
  |//-----------------------------------------------------------------------
  |//-- Return handling ----------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_returnp:
  |  // See vm_return. Also: TMP2 = previous base.
  |  andi AT, PC, FRAME_P
  |  beqz AT, ->cont_dispatch
  |
  |  // Return from pcall or xpcall fast func.
  |.  mov_true TMP1
  |  ld PC, FRAME_PC(TMP2)		// Fetch PC of previous frame.
  |  move BASE, TMP2			// Restore caller base.
  |  // Prepending may overwrite the pcall frame, so do it at the end.
  |   sd TMP1, -8(RA)			// Prepend true to results.
  |   daddiu RA, RA, -8
  |
  |->vm_returnc:
  |   addiu RD, RD, 8			// RD = (nresults+1)*8.
  |  andi TMP0, PC, FRAME_TYPE
  |   beqz RD, ->vm_unwind_c_eh
  |.   li CRET1, LUA_YIELD
  |  beqz TMP0, ->BC_RET_Z		// Handle regular return to Lua.
  |.  move MULTRES, RD
  |
  |->vm_return:
  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
  |  // TMP0 = PC & FRAME_TYPE
  |   li TMP2, -8
  |  xori AT, TMP0, FRAME_C
  |   and TMP2, PC, TMP2
  |  bnez AT, ->vm_returnp
  |   dsubu TMP2, BASE, TMP2		// TMP2 = previous base.
  |
  |  addiu TMP1, RD, -8
  |   sd TMP2, L->base
  |    li_vmstate C
  |   lw TMP2, SAVE_NRES
  |   daddiu BASE, BASE, -16
  |    st_vmstate
  |  beqz TMP1, >2
  |.   sll TMP2, TMP2, 3
  |1:
  |  addiu TMP1, TMP1, -8
  |   ld CRET1, 0(RA)
  |    daddiu RA, RA, 8
  |   sd CRET1, 0(BASE)
  |  bnez TMP1, <1
  |.  daddiu BASE, BASE, 8
  |
  |2:
  |  bne TMP2, RD, >6
  |3:
  |.  sd BASE, L->top			// Store new top.
  |
  |->vm_leave_cp:
  |  ld TMP0, SAVE_CFRAME		// Restore previous C frame.
  |   move CRET1, r0			// Ok return status for vm_pcall.
  |  sd TMP0, L->cframe
  |
  |->vm_leave_unw:
  |  restoreregs_ret
  |
  |6:
  |  ld TMP1, L->maxstack
  |  slt AT, TMP2, RD
  |  bnez AT, >7			// Less results wanted?
  |  // More results wanted. Check stack size and fill up results with nil.
  |.  slt AT, BASE, TMP1
  |  beqz AT, >8
  |.  nop
  |  sd TISNIL, 0(BASE)
  |  addiu RD, RD, 8
  |  b <2
  |.  daddiu BASE, BASE, 8
  |
  |7:  // Less results wanted.
  |  subu TMP0, RD, TMP2
  |  dsubu TMP0, BASE, TMP0		// Either keep top or shrink it.
  |  b <3
  |.  movn BASE, TMP0, TMP2		// LUA_MULTRET+1 case?
  |
  |8:  // Corner case: need to grow stack for filling up results.
  |  // This can happen if:
  |  // - A C function grows the stack (a lot).
  |  // - The GC shrinks the stack in between.
  |  // - A return back from a lua_call() with (high) nresults adjustment.
  |  load_got lj_state_growstack
  |   move MULTRES, RD
  |  srl CARG2, TMP2, 3
  |  call_intern lj_state_growstack	// (lua_State *L, int n)
  |.  move CARG1, L
  |    lw TMP2, SAVE_NRES
  |  ld BASE, L->top			// Need the (realloced) L->top in BASE.
  |   move RD, MULTRES
  |  b <2
  |.   sll TMP2, TMP2, 3
  |
  |->vm_unwind_c:			// Unwind C stack, return from vm_pcall.
  |  // (void *cframe, int errcode)
  |  move sp, CARG1
  |  move CRET1, CARG2
  |->vm_unwind_c_eh:			// Landing pad for external unwinder.
  |  ld L, SAVE_L
  |   li TMP0, ~LJ_VMST_C
  |  ld GL:TMP1, L->glref
  |  b ->vm_leave_unw
  |.  sw TMP0, GL:TMP1->vmstate
  |
  |->vm_unwind_ff:			// Unwind C stack, return from ff pcall.
  |  // (void *cframe)
  |  li AT, -4
  |  and sp, CARG1, AT
  |->vm_unwind_ff_eh:			// Landing pad for external unwinder.
  |  ld L, SAVE_L
  |     .FPU lui TMP3, 0x59c0		// TOBIT = 2^52 + 2^51 (float).
  |     li TISNIL, LJ_TNIL
  |    li TISNUM, LJ_TISNUM
  |  ld BASE, L->base
  |   ld DISPATCH, L->glref		// Setup pointer to dispatch table.
  |     .FPU mtc1 TMP3, TOBIT
  |  mov_false TMP1
  |    li_vmstate INTERP
  |  ld PC, FRAME_PC(BASE)		// Fetch PC of previous frame.
  |     .FPU cvt.d.s TOBIT, TOBIT
  |  daddiu RA, BASE, -8		// Results start at BASE-8.
  |   daddiu DISPATCH, DISPATCH, GG_G2DISP
  |  sd TMP1, 0(RA)			// Prepend false to error message.
  |    st_vmstate
  |  b ->vm_returnc
  |.  li RD, 16				// 2 results: false + error message.
  |
  |//-----------------------------------------------------------------------
  |//-- Grow stack for calls -----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_growstack_c:			// Grow stack for C function.
  |  b >2
  |.  li CARG2, LUA_MINSTACK
  |
  |->vm_growstack_l:			// Grow stack for Lua function.
  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
  |  daddu RC, BASE, RC
  |   dsubu RA, RA, BASE
  |  sd BASE, L->base
  |   daddiu PC, PC, 4			// Must point after first instruction.
  |  sd RC, L->top
  |   srl CARG2, RA, 3
  |2:
  |  // L->base = new base, L->top = top
  |  load_got lj_state_growstack
  |   sd PC, SAVE_PC
  |  call_intern lj_state_growstack	// (lua_State *L, int n)
  |.  move CARG1, L
  |  ld BASE, L->base
  |  ld RC, L->top
  |  ld LFUNC:RB, FRAME_FUNC(BASE)
  |  dsubu RC, RC, BASE
  |  cleartp LFUNC:RB
  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
  |  ins_callt				// Just retry the call.
  |
  |//-----------------------------------------------------------------------
  |//-- Entry points into the assembler VM ---------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_resume:				// Setup C frame and resume thread.
  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
  |  saveregs
  |  move L, CARG1
  |    ld DISPATCH, L->glref		// Setup pointer to dispatch table.
  |  move BASE, CARG2
  |    lbu TMP1, L->status
  |   sd L, SAVE_L
  |  li PC, FRAME_CP
  |  daddiu TMP0, sp, CFRAME_RESUME
  |    daddiu DISPATCH, DISPATCH, GG_G2DISP
  |   sw r0, SAVE_NRES
  |   sw r0, SAVE_ERRF
  |   sd CARG1, SAVE_PC			// Any value outside of bytecode is ok.
  |   sd r0, SAVE_CFRAME
  |    beqz TMP1, >3
  |. sd TMP0, L->cframe
  |
  |  // Resume after yield (like a return).
  |  sd L, DISPATCH_GL(cur_L)(DISPATCH)
  |  move RA, BASE
  |   ld BASE, L->base
  |   ld TMP1, L->top
  |  ld PC, FRAME_PC(BASE)
  |     .FPU  lui TMP3, 0x59c0		// TOBIT = 2^52 + 2^51 (float).
  |   dsubu RD, TMP1, BASE
  |     .FPU  mtc1 TMP3, TOBIT
  |    sb r0, L->status
  |     .FPU  cvt.d.s TOBIT, TOBIT
  |    li_vmstate INTERP
  |   daddiu RD, RD, 8
  |    st_vmstate
  |   move MULTRES, RD
  |  andi TMP0, PC, FRAME_TYPE
  |    li TISNIL, LJ_TNIL
  |  beqz TMP0, ->BC_RET_Z
  |.    li TISNUM, LJ_TISNUM
  |  b ->vm_return
  |.  nop
  |
  |->vm_pcall:				// Setup protected C frame and enter VM.
  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
  |  saveregs
  |  sw CARG4, SAVE_ERRF
  |  b >1
  |.  li PC, FRAME_CP
  |
  |->vm_call:				// Setup C frame and enter VM.
  |  // (lua_State *L, TValue *base, int nres1)
  |  saveregs
  |  li PC, FRAME_C
  |
  |1:  // Entry point for vm_pcall above (PC = ftype).
  |  ld TMP1, L:CARG1->cframe
  |    move L, CARG1
  |   sw CARG3, SAVE_NRES
  |    ld DISPATCH, L->glref		// Setup pointer to dispatch table.
  |   sd CARG1, SAVE_L
  |     move BASE, CARG2
  |    daddiu DISPATCH, DISPATCH, GG_G2DISP
  |   sd CARG1, SAVE_PC			// Any value outside of bytecode is ok.
  |  sd TMP1, SAVE_CFRAME
  |  sd sp, L->cframe			// Add our C frame to cframe chain.
  |
  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
  |  sd L, DISPATCH_GL(cur_L)(DISPATCH)
  |  ld TMP2, L->base			// TMP2 = old base (used in vmeta_call).
  |     .FPU lui TMP3, 0x59c0		// TOBIT = 2^52 + 2^51 (float).
  |   ld TMP1, L->top
  |     .FPU mtc1 TMP3, TOBIT
  |  daddu PC, PC, BASE
  |   dsubu NARGS8:RC, TMP1, BASE
  |     li TISNUM, LJ_TISNUM
  |  dsubu PC, PC, TMP2			// PC = frame delta + frame type
  |     .FPU cvt.d.s TOBIT, TOBIT
  |    li_vmstate INTERP
  |     li TISNIL, LJ_TNIL
  |    st_vmstate
  |
  |->vm_call_dispatch:
  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
  |  ld LFUNC:RB, FRAME_FUNC(BASE)
  |  checkfunc LFUNC:RB, ->vmeta_call
  |
  |->vm_call_dispatch_f:
  |  ins_call
  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
  |
  |->vm_cpcall:				// Setup protected C frame, call C.
  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
  |  saveregs
  |  move L, CARG1
  |   ld TMP0, L:CARG1->stack
  |  sd CARG1, SAVE_L
  |   ld TMP1, L->top
  |     ld DISPATCH, L->glref		// Setup pointer to dispatch table.
  |  sd CARG1, SAVE_PC			// Any value outside of bytecode is ok.
  |   dsubu TMP0, TMP0, TMP1		// Compute -savestack(L, L->top).
  |    ld TMP1, L->cframe
  |     daddiu DISPATCH, DISPATCH, GG_G2DISP
  |   sw TMP0, SAVE_NRES		// Neg. delta means cframe w/o frame.
  |  sw r0, SAVE_ERRF			// No error function.
  |    sd TMP1, SAVE_CFRAME
  |    sd sp, L->cframe			// Add our C frame to cframe chain.
  |     sd L, DISPATCH_GL(cur_L)(DISPATCH)
  |  jalr CARG4			// (lua_State *L, lua_CFunction func, void *ud)
  |.  move CFUNCADDR, CARG4
  |  move BASE, CRET1
  |  bnez CRET1, <3			// Else continue with the call.
  |.  li PC, FRAME_CP
  |  b ->vm_leave_cp			// No base? Just remove C frame.
  |.  nop
  |
  |//-----------------------------------------------------------------------
  |//-- Metamethod handling ------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
  |// stack, so BASE doesn't need to be reloaded across these calls.
  |
  |//-- Continuation dispatch ----------------------------------------------
  |
  |->cont_dispatch:
  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
  |  ld TMP0, -32(BASE)			// Continuation.
  |   move RB, BASE
  |   move BASE, TMP2			// Restore caller BASE.
  |    ld LFUNC:TMP1, FRAME_FUNC(TMP2)
  |.if FFI
  |  sltiu AT, TMP0, 2
  |.endif
  |     ld PC, -24(RB)			// Restore PC from [cont|PC].
  |    cleartp LFUNC:TMP1
  |   daddu TMP2, RA, RD
  |    ld TMP1, LFUNC:TMP1->pc
  |.if FFI
  |  bnez AT, >1
  |.endif
  |.  sd TISNIL, -8(TMP2)		// Ensure one valid arg.
  |  // BASE = base, RA = resultptr, RB = meta base
  |  jr TMP0				// Jump to continuation.
  |.  ld KBASE, PC2PROTO(k)(TMP1)
  |
  |.if FFI
  |1:
  |  bnez TMP0, ->cont_ffi_callback	// cont = 1: return from FFI callback.
  |  // cont = 0: tailcall from C function.
  |.  daddiu TMP1, RB, -32
  |  b ->vm_call_tail
  |.  dsubu RC, TMP1, BASE
  |.endif
  |
  |->cont_cat:				// RA = resultptr, RB = meta base
  |  lw INS, -4(PC)
  |   daddiu CARG2, RB, -32
  |  ld CRET1, 0(RA)
  |  decode_RB8a MULTRES, INS
  |   decode_RA8a RA, INS
  |  decode_RB8b MULTRES
  |   decode_RA8b RA
  |  daddu TMP1, BASE, MULTRES
  |   sd BASE, L->base
  |   dsubu CARG3, CARG2, TMP1
  |  bne TMP1, CARG2, ->BC_CAT_Z
  |.  sd CRET1, 0(CARG2)
  |  daddu RA, BASE, RA
  |  b ->cont_nop
  |.  sd CRET1, 0(RA)
  |
  |//-- Table indexing metamethods -----------------------------------------
  |
  |->vmeta_tgets1:
  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
  |  li TMP0, LJ_TSTR
  |  settp STR:RC, TMP0
  |  b >1
  |.  sd STR:RC, 0(CARG3)
  |
  |->vmeta_tgets:
  |  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
  |  li TMP0, LJ_TTAB
  |   li TMP1, LJ_TSTR
  |  settp TAB:RB, TMP0
  |   daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
  |  sd TAB:RB, 0(CARG2)
  |   settp STR:RC, TMP1
  |  b >1
  |.  sd STR:RC, 0(CARG3)
  |
  |->vmeta_tgetb:			// TMP0 = index
  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
  |  settp TMP0, TISNUM
  |  sd TMP0, 0(CARG3)
  |
  |->vmeta_tgetv:
  |1:
  |  load_got lj_meta_tget
  |  sd BASE, L->base
  |  sd PC, SAVE_PC
  |  call_intern lj_meta_tget		// (lua_State *L, TValue *o, TValue *k)
  |.  move CARG1, L
  |  // Returns TValue * (finished) or NULL (metamethod).
  |  beqz CRET1, >3
  |.  daddiu TMP1, BASE, -FRAME_CONT
  |  ld CARG1, 0(CRET1)
  |  ins_next1
  |  sd CARG1, 0(RA)
  |  ins_next2
  |
  |3:  // Call __index metamethod.
  |  // BASE = base, L->top = new base, stack = cont/func/t/k
  |  ld BASE, L->top
  |  sd PC, -24(BASE)			// [cont|PC]
  |   dsubu PC, BASE, TMP1
  |  ld LFUNC:RB, FRAME_FUNC(BASE)	// Guaranteed to be a function here.
  |  cleartp LFUNC:RB
  |  b ->vm_call_dispatch_f
  |.  li NARGS8:RC, 16			// 2 args for func(t, k).
  |
  |->vmeta_tgetr:
  |  load_got lj_tab_getinth
  |  call_intern lj_tab_getinth		// (GCtab *t, int32_t key)
  |.  nop
  |  // Returns cTValue * or NULL.
  |  beqz CRET1, ->BC_TGETR_Z
  |.  move CARG2, TISNIL
  |  b ->BC_TGETR_Z
  |.  ld CARG2, 0(CRET1)
  |
  |//-----------------------------------------------------------------------
  |
  |->vmeta_tsets1:
  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
  |  li TMP0, LJ_TSTR
  |  settp STR:RC, TMP0
  |  b >1
  |.  sd STR:RC, 0(CARG3)
  |
  |->vmeta_tsets:
  |  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
  |  li TMP0, LJ_TTAB
  |   li TMP1, LJ_TSTR
  |  settp TAB:RB, TMP0
  |   daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
  |  sd TAB:RB, 0(CARG2)
  |   settp STR:RC, TMP1
  |  b >1
  |.  sd STR:RC, 0(CARG3)
  |
  |->vmeta_tsetb:			// TMP0 = index
  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
  |  settp TMP0, TISNUM
  |  sd TMP0, 0(CARG3)
  |
  |->vmeta_tsetv:
  |1:
  |  load_got lj_meta_tset
  |  sd BASE, L->base
  |  sd PC, SAVE_PC
  |  call_intern lj_meta_tset		// (lua_State *L, TValue *o, TValue *k)
  |.  move CARG1, L
  |  // Returns TValue * (finished) or NULL (metamethod).
  |  beqz CRET1, >3
  |.  ld CARG1, 0(RA)
  |  // NOBARRIER: lj_meta_tset ensures the table is not black.
  |  ins_next1
  |  sd CARG1, 0(CRET1)
  |  ins_next2
  |
  |3:  // Call __newindex metamethod.
  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
  |  daddiu TMP1, BASE, -FRAME_CONT
  |  ld BASE, L->top
  |  sd PC, -24(BASE)			// [cont|PC]
  |   dsubu PC, BASE, TMP1
  |  ld LFUNC:RB, FRAME_FUNC(BASE)	// Guaranteed to be a function here.
  |  cleartp LFUNC:RB
  |  sd CARG1, 16(BASE)			// Copy value to third argument.
  |  b ->vm_call_dispatch_f
  |.  li NARGS8:RC, 24			// 3 args for func(t, k, v)
  |
  |->vmeta_tsetr:
  |  load_got lj_tab_setinth
  |  sd BASE, L->base
  |  sd PC, SAVE_PC
  |  call_intern lj_tab_setinth	// (lua_State *L, GCtab *t, int32_t key)
  |.  move CARG1, L
  |  // Returns TValue *.
  |  b ->BC_TSETR_Z
  |.  nop
  |
  |//-- Comparison metamethods ---------------------------------------------
  |
  |->vmeta_comp:
  |  // RA/RD point to o1/o2.
  |  move CARG2, RA
  |  move CARG3, RD
  |  load_got lj_meta_comp
  |  daddiu PC, PC, -4
  |  sd BASE, L->base
  |  sd PC, SAVE_PC
  |  decode_OP1 CARG4, INS
  |  call_intern lj_meta_comp	// (lua_State *L, TValue *o1, *o2, int op)
  |.  move CARG1, L
  |  // Returns 0/1 or TValue * (metamethod).
  |3:
  |  sltiu AT, CRET1, 2
  |  beqz AT, ->vmeta_binop
  |   negu TMP2, CRET1
  |4:
  |  lhu RD, OFS_RD(PC)
  |   daddiu PC, PC, 4
  |   lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)
  |  sll RD, RD, 2
  |  addu RD, RD, TMP1
  |  and RD, RD, TMP2
  |  daddu PC, PC, RD
  |->cont_nop:
  |  ins_next
  |
  |->cont_ra:				// RA = resultptr
  |  lbu TMP1, -4+OFS_RA(PC)
  |   ld CRET1, 0(RA)
  |  sll TMP1, TMP1, 3
  |  daddu TMP1, BASE, TMP1
  |  b ->cont_nop
  |.   sd CRET1, 0(TMP1)
  |
  |->cont_condt:			// RA = resultptr
  |  ld TMP0, 0(RA)
  |  gettp TMP0, TMP0
  |  sltiu AT, TMP0, LJ_TISTRUECOND
  |  b <4
  |.  negu TMP2, AT			// Branch if result is true.
  |
  |->cont_condf:			// RA = resultptr
  |  ld TMP0, 0(RA)
  |  gettp TMP0, TMP0
  |  sltiu AT, TMP0, LJ_TISTRUECOND
  |  b <4
  |.  addiu TMP2, AT, -1		// Branch if result is false.
  |
  |->vmeta_equal:
  |  // CARG1/CARG2 point to o1/o2. TMP0 is set to 0/1.
  |  load_got lj_meta_equal
  |   cleartp LFUNC:CARG3, CARG2
  |  cleartp LFUNC:CARG2, CARG1
  |    move CARG4, TMP0
  |  daddiu PC, PC, -4
  |   sd BASE, L->base
  |   sd PC, SAVE_PC
  |  call_intern lj_meta_equal	// (lua_State *L, GCobj *o1, *o2, int ne)
  |.  move CARG1, L
  |  // Returns 0/1 or TValue * (metamethod).
  |  b <3
  |.  nop
  |
  |->vmeta_equal_cd:
  |.if FFI
  |  load_got lj_meta_equal_cd
  |  move CARG2, INS
  |  daddiu PC, PC, -4
  |   sd BASE, L->base
  |   sd PC, SAVE_PC
  |  call_intern lj_meta_equal_cd	// (lua_State *L, BCIns op)
  |.  move CARG1, L
  |  // Returns 0/1 or TValue * (metamethod).
  |  b <3
  |.  nop
  |.endif
  |
  |->vmeta_istype:
  |  load_got lj_meta_istype
  |  daddiu PC, PC, -4
  |   sd BASE, L->base
  |   srl CARG2, RA, 3
  |   srl CARG3, RD, 3
  |  sd PC, SAVE_PC
  |  call_intern lj_meta_istype	// (lua_State *L, BCReg ra, BCReg tp)
  |.  move CARG1, L
  |  b ->cont_nop
  |.  nop
  |
  |//-- Arithmetic metamethods ---------------------------------------------
  |
  |->vmeta_unm:
  |  move RC, RB
  |
  |->vmeta_arith:
  |  load_got lj_meta_arith
  |   sd BASE, L->base
  |  move CARG2, RA
  |   sd PC, SAVE_PC
  |  move CARG3, RB
  |  move CARG4, RC
  |  decode_OP1 CARG5, INS	// CARG5 == RB.
  |  call_intern lj_meta_arith	// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
  |.  move CARG1, L
  |  // Returns NULL (finished) or TValue * (metamethod).
  |  beqz CRET1, ->cont_nop
  |.  nop
  |
  |  // Call metamethod for binary op.
  |->vmeta_binop:
  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
  |  dsubu TMP1, CRET1, BASE
  |   sd PC, -24(CRET1)			// [cont|PC]
  |   move TMP2, BASE
  |  daddiu PC, TMP1, FRAME_CONT
  |   move BASE, CRET1
  |  b ->vm_call_dispatch
  |.  li NARGS8:RC, 16			// 2 args for func(o1, o2).
  |
  |->vmeta_len:
  |  // CARG2 already set by BC_LEN.
#if LJ_52
  |  move MULTRES, CARG1
#endif
  |  load_got lj_meta_len
  |   sd BASE, L->base
  |   sd PC, SAVE_PC
  |  call_intern lj_meta_len		// (lua_State *L, TValue *o)
  |.  move CARG1, L
  |  // Returns NULL (retry) or TValue * (metamethod base).
#if LJ_52
  |  bnez CRET1, ->vmeta_binop		// Binop call for compatibility.
  |.  nop
  |  b ->BC_LEN_Z
  |.  move CARG1, MULTRES
#else
  |  b ->vmeta_binop			// Binop call for compatibility.
  |.  nop
#endif
  |
  |//-- Call metamethod ----------------------------------------------------
  |
  |->vmeta_call:			// Resolve and call __call metamethod.
  |  // TMP2 = old base, BASE = new base, RC = nargs*8
  |  load_got lj_meta_call
  |   sd TMP2, L->base			// This is the callers base!
  |  daddiu CARG2, BASE, -16
  |   sd PC, SAVE_PC
  |  daddu CARG3, BASE, RC
  |   move MULTRES, NARGS8:RC
  |  call_intern lj_meta_call	// (lua_State *L, TValue *func, TValue *top)
  |.  move CARG1, L
  |  ld LFUNC:RB, FRAME_FUNC(BASE)	// Guaranteed to be a function here.
  |   daddiu NARGS8:RC, MULTRES, 8	// Got one more argument now.
  |  cleartp LFUNC:RB
  |  ins_call
  |
  |->vmeta_callt:			// Resolve __call for BC_CALLT.
  |  // BASE = old base, RA = new base, RC = nargs*8
  |  load_got lj_meta_call
  |   sd BASE, L->base
  |  daddiu CARG2, RA, -16
  |   sd PC, SAVE_PC
  |  daddu CARG3, RA, RC
  |   move MULTRES, NARGS8:RC
  |  call_intern lj_meta_call		// (lua_State *L, TValue *func, TValue *top)
  |.  move CARG1, L
  |   ld RB, FRAME_FUNC(RA)		// Guaranteed to be a function here.
  |  ld TMP1, FRAME_PC(BASE)
  |  daddiu NARGS8:RC, MULTRES, 8	// Got one more argument now.
  |  b ->BC_CALLT_Z
  |.  cleartp LFUNC:CARG3, RB
  |
  |//-- Argument coercion for 'for' statement ------------------------------
  |
  |->vmeta_for:
  |  load_got lj_meta_for
  |   sd BASE, L->base
  |  move CARG2, RA
  |   sd PC, SAVE_PC
  |  move MULTRES, INS
  |  call_intern lj_meta_for	// (lua_State *L, TValue *base)
  |.  move CARG1, L
  |.if JIT
  |  decode_OP1 TMP0, MULTRES
  |  li AT, BC_JFORI
  |.endif
  |  decode_RA8a RA, MULTRES
  |   decode_RD8a RD, MULTRES
  |  decode_RA8b RA
  |.if JIT
  |  beq TMP0, AT, =>BC_JFORI
  |.  decode_RD8b RD
  |  b =>BC_FORI
  |.  nop
  |.else
  |  b =>BC_FORI
  |.  decode_RD8b RD
  |.endif
  |
  |//-----------------------------------------------------------------------
  |//-- Fast functions -----------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |.macro .ffunc, name
  |->ff_ .. name:
  |.endmacro
  |
  |.macro .ffunc_1, name
  |->ff_ .. name:
  |  beqz NARGS8:RC, ->fff_fallback
  |.  ld CARG1, 0(BASE)
  |.endmacro
  |
  |.macro .ffunc_2, name
  |->ff_ .. name:
  |  sltiu AT, NARGS8:RC, 16
  |  ld CARG1, 0(BASE)
  |  bnez AT, ->fff_fallback
  |.  ld CARG2, 8(BASE)
  |.endmacro
  |
  |.macro .ffunc_n, name	// Caveat: has delay slot!
  |->ff_ .. name:
  |  ld CARG1, 0(BASE)
  |  beqz NARGS8:RC, ->fff_fallback
  |  // Either ldc1 or the 1st instruction of checknum is in the delay slot.
  |  .FPU ldc1 FARG1, 0(BASE)
  |  checknum CARG1, ->fff_fallback
  |.endmacro
  |
  |.macro .ffunc_nn, name	// Caveat: has delay slot!
  |->ff_ .. name:
  |  ld CARG1, 0(BASE)
  |    sltiu AT, NARGS8:RC, 16
  |   ld CARG2, 8(BASE)
  |  bnez AT, ->fff_fallback
  |.  gettp TMP0, CARG1
  |   gettp TMP1, CARG2
  |  sltiu TMP0, TMP0, LJ_TISNUM
  |   sltiu TMP1, TMP1, LJ_TISNUM
  |  .FPU ldc1 FARG1, 0(BASE)
  |  and TMP0, TMP0, TMP1
  |   .FPU ldc1 FARG2, 8(BASE)
  |  beqz TMP0, ->fff_fallback
  |.endmacro
  |
  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!
  |.macro ffgccheck
  |  ld TMP0, DISPATCH_GL(gc.total)(DISPATCH)
  |  ld TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
  |  dsubu AT, TMP0, TMP1
  |  bgezal AT, ->fff_gcstep
  |.endmacro
  |
  |//-- Base library: checks -----------------------------------------------
  |.ffunc_1 assert
  |  gettp AT, CARG1
  |  sltiu AT, AT, LJ_TISTRUECOND
  |  beqz AT, ->fff_fallback
  |.  daddiu RA, BASE, -16
  |  ld PC, FRAME_PC(BASE)
  |  addiu RD, NARGS8:RC, 8		// Compute (nresults+1)*8.
  |  daddu TMP2, RA, RD
  |  daddiu TMP1, BASE, 8
  |  beq BASE, TMP2, ->fff_res		// Done if exactly 1 argument.
  |.  sd CARG1, 0(RA)
  |1:
  |  ld CRET1, 0(TMP1)
  |  sd CRET1, -16(TMP1)
  |  bne TMP1, TMP2, <1
  |.  daddiu TMP1, TMP1, 8
  |  b ->fff_res
  |.  nop
  |
  |.ffunc_1 type
  |  gettp TMP0, CARG1
  |  sltu TMP1, TISNUM, TMP0
  |  not TMP2, TMP0
  |  li TMP3, ~LJ_TISNUM
  |  movz TMP2, TMP3, TMP1
  |  dsll TMP2, TMP2, 3
  |  daddu TMP2, CFUNC:RB, TMP2
  |  b ->fff_restv
  |.  ld CARG1, CFUNC:TMP2->upvalue
  |
  |//-- Base library: getters and setters ---------------------------------
  |
  |.ffunc_1 getmetatable
  |  gettp TMP2, CARG1
  |  daddiu TMP0, TMP2, -LJ_TTAB
  |  daddiu TMP1, TMP2, -LJ_TUDATA
  |  movn TMP0, TMP1, TMP0
  |  bnez TMP0, >6
  |.  cleartp TAB:CARG1
  |1:  // Field metatable must be at same offset for GCtab and GCudata!
  |  ld TAB:RB, TAB:CARG1->metatable
  |2:
  |  ld STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
  |  beqz TAB:RB, ->fff_restv
  |.  li CARG1, LJ_TNIL
  |  lw TMP0, TAB:RB->hmask
  |   lw TMP1, STR:RC->hash
  |    ld NODE:TMP2, TAB:RB->node
  |  and TMP1, TMP1, TMP0		// idx = str->hash & tab->hmask
  |  dsll TMP0, TMP1, 5
  |  dsll TMP1, TMP1, 3
  |  dsubu TMP1, TMP0, TMP1
  |  daddu NODE:TMP2, NODE:TMP2, TMP1	// node = tab->node + (idx*32-idx*8)
  |  li CARG4, LJ_TSTR
  |  settp STR:RC, CARG4		// Tagged key to look for.
  |3:  // Rearranged logic, because we expect _not_ to find the key.
  |  ld TMP0, NODE:TMP2->key
  |   ld CARG1, NODE:TMP2->val
  |    ld NODE:TMP2, NODE:TMP2->next
  |  beq RC, TMP0, >5
  |.  li AT, LJ_TTAB
  |  bnez NODE:TMP2, <3
  |.  nop
  |4:
  |  move CARG1, RB
  |  b ->fff_restv			// Not found, keep default result.
  |.  settp CARG1, AT
  |5:
  |  bne CARG1, TISNIL, ->fff_restv
  |.  nop
  |  b <4				// Ditto for nil value.
  |.  nop
  |
  |6:
  |  sltiu AT, TMP2, LJ_TISNUM
  |  movn TMP2, TISNUM, AT
  |  dsll TMP2, TMP2, 3
  |   dsubu TMP0, DISPATCH, TMP2
  |  b <2
  |.  ld TAB:RB, DISPATCH_GL(gcroot[GCROOT_BASEMT])-8(TMP0)
  |
  |.ffunc_2 setmetatable
  |  // Fast path: no mt for table yet and not clearing the mt.
  |  checktp TMP1, CARG1, -LJ_TTAB, ->fff_fallback
  |  gettp TMP3, CARG2
  |   ld TAB:TMP0, TAB:TMP1->metatable
  |   lbu TMP2, TAB:TMP1->marked
  |  daddiu AT, TMP3, -LJ_TTAB
  |   cleartp TAB:CARG2
  |  or AT, AT, TAB:TMP0
  |  bnez AT, ->fff_fallback
  |.  andi AT, TMP2, LJ_GC_BLACK	// isblack(table)
  |  beqz AT, ->fff_restv
  |.  sd TAB:CARG2, TAB:TMP1->metatable
  |  barrierback TAB:TMP1, TMP2, TMP0, ->fff_restv
  |
  |.ffunc rawget
  |  ld CARG2, 0(BASE)
  |  sltiu AT, NARGS8:RC, 16
  |  load_got lj_tab_get
  |  gettp TMP0, CARG2
  |   cleartp CARG2
  |  daddiu TMP0, TMP0, -LJ_TTAB
  |  or AT, AT, TMP0
  |  bnez AT, ->fff_fallback
  |.  daddiu CARG3, BASE, 8
  |  call_intern lj_tab_get	// (lua_State *L, GCtab *t, cTValue *key)
  |.  move CARG1, L
  |  b ->fff_restv
  |.  ld CARG1, 0(CRET1)
  |
  |//-- Base library: conversions ------------------------------------------
  |
  |.ffunc tonumber
  |  // Only handles the number case inline (without a base argument).
  |  ld CARG1, 0(BASE)
  |  xori AT, NARGS8:RC, 8		// Exactly one number argument.
  |  gettp TMP1, CARG1
  |  sltu TMP0, TISNUM, TMP1
  |  or AT, AT, TMP0
  |  bnez AT, ->fff_fallback
  |.  nop
  |  b ->fff_restv
  |.  nop
  |
  |.ffunc_1 tostring
  |  // Only handles the string or number case inline.
  |  gettp TMP0, CARG1
  |  daddiu AT, TMP0, -LJ_TSTR
  |  // A __tostring method in the string base metatable is ignored.
  |  beqz AT, ->fff_restv	// String key?
  |  // Handle numbers inline, unless a number base metatable is present.
  |.  ld TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
  |  sltu TMP0, TISNUM, TMP0
  |  or TMP0, TMP0, TMP1
  |  bnez TMP0, ->fff_fallback
  |.  sd BASE, L->base			// Add frame since C call can throw.
  |  ffgccheck
  |.  sd PC, SAVE_PC			// Redundant (but a defined value).
  |  load_got lj_strfmt_number
  |  move CARG1, L
  |  call_intern lj_strfmt_number	// (lua_State *L, cTValue *o)
  |.  move CARG2, BASE
  |  // Returns GCstr *.
  |  li AT, LJ_TSTR
  |  settp CRET1, AT
  |  b ->fff_restv
  |.  move CARG1, CRET1
  |
  |//-- Base library: iterators -------------------------------------------
  |
  |.ffunc_1 next
  |  checktp CARG2, CARG1, -LJ_TTAB, ->fff_fallback
  |  daddu TMP2, BASE, NARGS8:RC
  |  sd TISNIL, 0(TMP2)			// Set missing 2nd arg to nil.
  |  ld PC, FRAME_PC(BASE)
  |  load_got lj_tab_next
  |   sd BASE, L->base			// Add frame since C call can throw.
  |   sd BASE, L->top			// Dummy frame length is ok.
  |  daddiu CARG3, BASE, 8
  |   sd PC, SAVE_PC
  |  call_intern lj_tab_next		// (lua_State *L, GCtab *t, TValue *key)
  |.  move CARG1, L
  |  // Returns 0 at end of traversal.
  |  beqz CRET1, ->fff_restv		// End of traversal: return nil.
  |.  move CARG1, TISNIL
  |  ld TMP0, 8(BASE)
  |    daddiu RA, BASE, -16
  |  ld TMP2, 16(BASE)
  |  sd TMP0, 0(RA)
  |  sd TMP2, 8(RA)
  |  b ->fff_res
  |.  li RD, (2+1)*8
  |
  |.ffunc_1 pairs
  |  checktp TAB:TMP1, CARG1, -LJ_TTAB, ->fff_fallback
  |  ld PC, FRAME_PC(BASE)
#if LJ_52
  |  ld TAB:TMP2, TAB:TMP1->metatable
  |  ld TMP0, CFUNC:RB->upvalue[0]
  |  bnez TAB:TMP2, ->fff_fallback
#else
  |  ld TMP0, CFUNC:RB->upvalue[0]
#endif
  |.  daddiu RA, BASE, -16
  |  sd TISNIL, 0(BASE)
  |   sd CARG1, -8(BASE)
  |    sd TMP0, 0(RA)
  |  b ->fff_res
  |.  li RD, (3+1)*8
  |
  |.ffunc_2 ipairs_aux
  |  checktab CARG1, ->fff_fallback
  |   checkint CARG2, ->fff_fallback
  |.  lw TMP0, TAB:CARG1->asize
  |   ld TMP1, TAB:CARG1->array
  |    ld PC, FRAME_PC(BASE)
  |  sextw TMP2, CARG2
  |  addiu TMP2, TMP2, 1
  |  sltu AT, TMP2, TMP0
  |    daddiu RA, BASE, -16
  |   zextw TMP0, TMP2
  |   settp TMP0, TISNUM
  |  beqz AT, >2			// Not in array part?
  |.  sd TMP0, 0(RA)
  |  dsll TMP3, TMP2, 3
  |  daddu TMP3, TMP1, TMP3
  |  ld TMP1, 0(TMP3)
  |1:
  |  beq TMP1, TISNIL, ->fff_res	// End of iteration, return 0 results.
  |.  li RD, (0+1)*8
  |  sd TMP1, -8(BASE)
  |  b ->fff_res
  |.  li RD, (2+1)*8
  |2:  // Check for empty hash part first. Otherwise call C function.
  |  lw TMP0, TAB:CARG1->hmask
  |  load_got lj_tab_getinth
  |  beqz TMP0, ->fff_res
  |.  li RD, (0+1)*8
  |  call_intern lj_tab_getinth		// (GCtab *t, int32_t key)
  |.  move CARG2, TMP2
  |  // Returns cTValue * or NULL.
  |  beqz CRET1, ->fff_res
  |.  li RD, (0+1)*8
  |  b <1
  |.  ld TMP1, 0(CRET1)
  |
  |.ffunc_1 ipairs
  |  checktp TAB:TMP1, CARG1, -LJ_TTAB, ->fff_fallback
  |  ld PC, FRAME_PC(BASE)
#if LJ_52
  |  ld TAB:TMP2, TAB:TMP1->metatable
  |  ld CFUNC:TMP0, CFUNC:RB->upvalue[0]
  |  bnez TAB:TMP2, ->fff_fallback
#else
  |  ld TMP0, CFUNC:RB->upvalue[0]
#endif
  |  daddiu RA, BASE, -16
  |  dsll AT, TISNUM, 47
  |  sd CARG1, -8(BASE)
  |   sd AT, 0(BASE)
  |    sd CFUNC:TMP0, 0(RA)
  |  b ->fff_res
  |.  li RD, (3+1)*8
  |
  |//-- Base library: catch errors ----------------------------------------
  |
  |.ffunc pcall
  |  daddiu NARGS8:RC, NARGS8:RC, -8
  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
  |  bltz NARGS8:RC, ->fff_fallback
  |.   move TMP2, BASE
  |   daddiu BASE, BASE, 16
  |  // Remember active hook before pcall.
  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
  |  andi TMP3, TMP3, 1
  |  daddiu PC, TMP3, 16+FRAME_PCALL
  |  beqz NARGS8:RC, ->vm_call_dispatch
  |1:
  |.  daddu TMP0, BASE, NARGS8:RC
  |2:
  |  ld TMP1, -16(TMP0)
  |  sd TMP1, -8(TMP0)
  |  daddiu TMP0, TMP0, -8
  |  bne TMP0, BASE, <2
  |.  nop
  |  b ->vm_call_dispatch
  |.  nop
  |
  |.ffunc xpcall
  |  daddiu NARGS8:RC, NARGS8:RC, -16
  |  ld CARG1, 0(BASE)
  |   ld CARG2, 8(BASE)
  |    bltz NARGS8:RC, ->fff_fallback
  |.    lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)
  |  gettp AT, CARG2
  |  daddiu AT, AT, -LJ_TFUNC
  |  bnez AT, ->fff_fallback		// Traceback must be a function.
  |.   move TMP2, BASE
  |   daddiu BASE, BASE, 24
  |  // Remember active hook before pcall.
  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
  |   sd CARG2, 0(TMP2)			// Swap function and traceback.
  |  andi TMP3, TMP3, 1
  |   sd CARG1, 8(TMP2)
  |  beqz NARGS8:RC, ->vm_call_dispatch
  |.  daddiu PC, TMP3, 24+FRAME_PCALL
  |  b <1
  |.  nop
  |
  |//-- Coroutine library --------------------------------------------------
  |
  |.macro coroutine_resume_wrap, resume
  |.if resume
  |.ffunc_1 coroutine_resume
  |  checktp CARG1, CARG1, -LJ_TTHREAD, ->fff_fallback
  |.else
  |.ffunc coroutine_wrap_aux
  |  ld L:CARG1, CFUNC:RB->upvalue[0].gcr
  |  cleartp L:CARG1
  |.endif
  |  lbu TMP0, L:CARG1->status
  |   ld TMP1, L:CARG1->cframe
  |    ld CARG2, L:CARG1->top
  |    ld TMP2, L:CARG1->base
  |  addiu AT, TMP0, -LUA_YIELD
  |    daddu CARG3, CARG2, TMP0
  |   daddiu TMP3, CARG2, 8
  |  bgtz AT, ->fff_fallback		// st > LUA_YIELD?
  |.  movn CARG2, TMP3, AT
  |   xor TMP2, TMP2, CARG3
  |  bnez TMP1, ->fff_fallback		// cframe != 0?
  |.  or AT, TMP2, TMP0
  |  ld TMP0, L:CARG1->maxstack
  |  beqz AT, ->fff_fallback		// base == top && st == 0?
  |.  ld PC, FRAME_PC(BASE)
  |  daddu TMP2, CARG2, NARGS8:RC
  |  sltu AT, TMP0, TMP2
  |  bnez AT, ->fff_fallback		// Stack overflow?
  |.  sd PC, SAVE_PC
  |   sd BASE, L->base
  |1:
  |.if resume
  |  daddiu BASE, BASE, 8		// Keep resumed thread in stack for GC.
  |  daddiu NARGS8:RC, NARGS8:RC, -8
  |  daddiu TMP2, TMP2, -8
  |.endif
  |  sd TMP2, L:CARG1->top
  |  daddu TMP1, BASE, NARGS8:RC
  |  move CARG3, CARG2
  |  sd BASE, L->top
  |2:  // Move args to coroutine.
  |   ld CRET1, 0(BASE)
  |  sltu AT, BASE, TMP1
  |  beqz AT, >3
  |.  daddiu BASE, BASE, 8
  |   sd CRET1, 0(CARG3)
  |  b <2
  |.  daddiu CARG3, CARG3, 8
  |3:
  |  bal ->vm_resume			// (lua_State *L, TValue *base, 0, 0)
  |.  move L:RA, L:CARG1
  |  // Returns thread status.
  |4:
  |  ld TMP2, L:RA->base
  |   sltiu AT, CRET1, LUA_YIELD+1
  |  ld TMP3, L:RA->top
  |    li_vmstate INTERP
  |  ld BASE, L->base
  |    sd L, DISPATCH_GL(cur_L)(DISPATCH)
  |    st_vmstate
  |   beqz AT, >8
  |. dsubu RD, TMP3, TMP2
  |   ld TMP0, L->maxstack
  |  beqz RD, >6			// No results?
  |.  daddu TMP1, BASE, RD
  |  sltu AT, TMP0, TMP1
  |  bnez AT, >9			// Need to grow stack?
  |.  daddu TMP3, TMP2, RD
  |  sd TMP2, L:RA->top			// Clear coroutine stack.
  |  move TMP1, BASE
  |5:  // Move results from coroutine.
  |   ld CRET1, 0(TMP2)
  |  daddiu TMP2, TMP2, 8
  |  sltu AT, TMP2, TMP3
  |   sd CRET1, 0(TMP1)
  |  bnez AT, <5
  |.  daddiu TMP1, TMP1, 8
  |6:
  |  andi TMP0, PC, FRAME_TYPE
  |.if resume
  |  mov_true TMP1
  |   daddiu RA, BASE, -8
  |  sd TMP1, -8(BASE)			// Prepend true to results.
  |  daddiu RD, RD, 16
  |.else
  |  move RA, BASE
  |  daddiu RD, RD, 8
  |.endif
  |7:
  |  sd PC, SAVE_PC
  |  beqz TMP0, ->BC_RET_Z
  |.  move MULTRES, RD
  |  b ->vm_return
  |.  nop
  |
  |8:  // Coroutine returned with error (at co->top-1).
  |.if resume
  |  daddiu TMP3, TMP3, -8
  |   mov_false TMP1
  |  ld CRET1, 0(TMP3)
  |   sd TMP3, L:RA->top		// Remove error from coroutine stack.
  |    li RD, (2+1)*8
  |   sd TMP1, -8(BASE)			// Prepend false to results.
  |    daddiu RA, BASE, -8
  |  sd CRET1, 0(BASE)			// Copy error message.
  |  b <7
  |.  andi TMP0, PC, FRAME_TYPE
  |.else
  |  load_got lj_ffh_coroutine_wrap_err
  |  move CARG2, L:RA
  |  call_intern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)
  |.  move CARG1, L
  |.endif
  |
  |9:  // Handle stack expansion on return from yield.
  |  load_got lj_state_growstack
  |  srl CARG2, RD, 3
  |  call_intern lj_state_growstack	// (lua_State *L, int n)
  |.  move CARG1, L
  |  b <4
  |.  li CRET1, 0
  |.endmacro
  |
  |  coroutine_resume_wrap 1		// coroutine.resume
  |  coroutine_resume_wrap 0		// coroutine.wrap
  |
  |.ffunc coroutine_yield
  |  ld TMP0, L->cframe
  |   daddu TMP1, BASE, NARGS8:RC
  |   sd BASE, L->base
  |  andi TMP0, TMP0, CFRAME_RESUME
  |   sd TMP1, L->top
  |  beqz TMP0, ->fff_fallback
  |.   li CRET1, LUA_YIELD
  |  sd r0, L->cframe
  |  b ->vm_leave_unw
  |.   sb CRET1, L->status
  |
  |//-- Math library -------------------------------------------------------
  |
  |.ffunc_1 math_abs
  |  gettp CARG2, CARG1
  |  daddiu AT, CARG2, -LJ_TISNUM
  |  bnez AT, >1
  |.  sextw TMP1, CARG1
  |  sra TMP0, TMP1, 31			// Extract sign.
  |  xor TMP1, TMP1, TMP0
  |  dsubu CARG1, TMP1, TMP0
  |  dsll TMP3, CARG1, 32
  |  bgez TMP3, ->fff_restv
  |.  settp CARG1, TISNUM
  |  li CARG1, 0x41e0			// 2^31 as a double.
  |  b ->fff_restv
  |.  dsll CARG1, CARG1, 48
  |1:
  |  sltiu AT, CARG2, LJ_TISNUM
  |  beqz AT, ->fff_fallback
  |.  dextm CARG1, CARG1, 0, 30
  |// fallthrough
  |
  |->fff_restv:
  |  // CARG1 = TValue result.
  |  ld PC, FRAME_PC(BASE)
  |  daddiu RA, BASE, -16
  |   sd CARG1, -16(BASE)
  |->fff_res1:
  |  // RA = results, PC = return.
  |  li RD, (1+1)*8
  |->fff_res:
  |  // RA = results, RD = (nresults+1)*8, PC = return.
  |  andi TMP0, PC, FRAME_TYPE
  |  bnez TMP0, ->vm_return
  |.  move MULTRES, RD
  |  lw INS, -4(PC)
  |  decode_RB8a RB, INS
  |  decode_RB8b RB
  |5:
  |  sltu AT, RD, RB
  |  bnez AT, >6			// More results expected?
  |.  decode_RA8a TMP0, INS
  |  decode_RA8b TMP0
  |  ins_next1
  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.
  |   dsubu BASE, RA, TMP0
  |  ins_next2
  |
  |6:  // Fill up results with nil.
  |  daddu TMP1, RA, RD
  |   daddiu RD, RD, 8
  |  b <5
  |.  sd TISNIL, -8(TMP1)
  |
  |.macro math_extern, func
  |  .ffunc_n math_ .. func
  |  load_got func
  |  call_extern
  |.  nop
  |  b ->fff_resn
  |.  nop
  |.endmacro
  |
  |.macro math_extern2, func
  |  .ffunc_nn math_ .. func
  |.  load_got func
  |  call_extern
  |.  nop
  |  b ->fff_resn
  |.  nop
  |.endmacro
  |
  |// TODO: Return integer type if result is integer (own sf implementation).
  |.macro math_round, func
  |->ff_math_ .. func:
  |  ld CARG1, 0(BASE)
  |  beqz NARGS8:RC, ->fff_fallback
  |.  gettp TMP0, CARG1
  |  beq TMP0, TISNUM, ->fff_restv
  |.  sltu AT, TMP0, TISNUM
  |  beqz AT, ->fff_fallback
  |.if FPU
  |.  ldc1 FARG1, 0(BASE)
  |  bal ->vm_ .. func
  |.  nop
  |.else
  |.  load_got func
  |  call_extern
  |.  nop
  |.endif
  |  b ->fff_resn
  |.  nop
  |.endmacro
  |
  |  math_round floor
  |  math_round ceil
  |
  |.ffunc math_log
  |  li AT, 8
  |  bne NARGS8:RC, AT, ->fff_fallback	// Exactly 1 argument.
  |.  ld CARG1, 0(BASE)
  |  checknum CARG1, ->fff_fallback
  |.  load_got log
  |.if FPU
  |  call_extern
  |.  ldc1 FARG1, 0(BASE)
  |.else
  |  call_extern
  |.  nop
  |.endif
  |  b ->fff_resn
  |.  nop
  |
  |  math_extern log10
  |  math_extern exp
  |  math_extern sin
  |  math_extern cos
  |  math_extern tan
  |  math_extern asin
  |  math_extern acos
  |  math_extern atan
  |  math_extern sinh
  |  math_extern cosh
  |  math_extern tanh
  |  math_extern2 pow
  |  math_extern2 atan2
  |  math_extern2 fmod
  |
  |.if FPU
  |.ffunc_n math_sqrt
  |.  sqrt.d FRET1, FARG1
  |// fallthrough to ->fff_resn
  |.else
  |  math_extern sqrt
  |.endif
  |
  |->fff_resn:
  |  ld PC, FRAME_PC(BASE)
  |  daddiu RA, BASE, -16
  |  b ->fff_res1
  |.if FPU
  |.  sdc1 FRET1, 0(RA)
  |.else
  |.  sd CRET1, 0(RA)
  |.endif
  |
  |
  |.ffunc_2 math_ldexp
  |  checknum CARG1, ->fff_fallback
  |  checkint CARG2, ->fff_fallback
  |.  load_got ldexp
  |  .FPU ldc1 FARG1, 0(BASE)
  |  call_extern
  |.  lw CARG2, 8+LO(BASE)
  |  b ->fff_resn
  |.  nop
  |
  |.ffunc_n math_frexp
  |  load_got frexp
  |   ld PC, FRAME_PC(BASE)
  |  call_extern
  |.  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
  |   lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)
  |  daddiu RA, BASE, -16
  |.if FPU
  |   mtc1 TMP1, FARG2
  |  sdc1 FRET1, 0(RA)
  |   cvt.d.w FARG2, FARG2
  |   sdc1 FARG2, 8(RA)
  |.else
  |  sd CRET1, 0(RA)
  |  zextw TMP1, TMP1
  |  settp TMP1, TISNUM
  |  sd TMP1, 8(RA)
  |.endif
  |  b ->fff_res
  |.  li RD, (2+1)*8
  |
  |.ffunc_n math_modf
  |  load_got modf
  |   ld PC, FRAME_PC(BASE)
  |  call_extern
  |.  daddiu CARG2, BASE, -16
  |  daddiu RA, BASE, -16
  |.if FPU
  |  sdc1 FRET1, -8(BASE)
  |.else
  |  sd CRET1, -8(BASE)
  |.endif
  |  b ->fff_res
  |.  li RD, (2+1)*8
  |
  |.macro math_minmax, name, intins, fpins
  |  .ffunc_1 name
  |  daddu TMP3, BASE, NARGS8:RC
  |  checkint CARG1, >5
  |.  daddiu TMP2, BASE, 8
  |1:  // Handle integers.
  |  beq TMP2, TMP3, ->fff_restv
  |.  ld CARG2, 0(TMP2)
  |  checkint CARG2, >3
  |.  sextw CARG1, CARG1
  |  lw CARG2, LO(TMP2)
  |.  slt AT, CARG1, CARG2
  |  intins CARG1, CARG2, AT
  |  daddiu TMP2, TMP2, 8
  |  zextw CARG1, CARG1
  |  b <1
  |.  settp CARG1, TISNUM
  |
  |3:  // Convert intermediate result to number and continue with number loop.
  |  checknum CARG2, ->fff_fallback
  |.if FPU
  |.  mtc1 CARG1, FRET1
  |  cvt.d.w FRET1, FRET1
  |  b >7
  |.  ldc1 FARG1, 0(TMP2)
  |.else
  |.  nop
  |  bal ->vm_sfi2d_1
  |.  nop
  |  b >7
  |.  nop
  |.endif
  |
  |5:
  |  .FPU ldc1 FRET1, 0(BASE)
  |  checknum CARG1, ->fff_fallback
  |6:  // Handle numbers.
  |.  ld CARG2, 0(TMP2)
  |  beq TMP2, TMP3, ->fff_resn
  |.if FPU
  |  ldc1 FARG1, 0(TMP2)
  |.else
  |  move CRET1, CARG1
  |.endif
  |  checknum CARG2, >8
  |.  nop
  |7:
  |.if FPU
  |  c.olt.d FRET1, FARG1
  |  fpins FRET1, FARG1
  |.else
  |  bal ->vm_sfcmpolt
  |.  nop
  |  intins CARG1, CARG2, CRET1
  |.endif
  |  b <6
  |.  daddiu TMP2, TMP2, 8
  |
  |8:  // Convert integer to number and continue with number loop.
  |  checkint CARG2, ->fff_fallback
  |.if FPU
  |.  lwc1 FARG1, LO(TMP2)
  |  b <7
  |.  cvt.d.w FARG1, FARG1
  |.else
  |.  lw CARG2, LO(TMP2)
  |  bal ->vm_sfi2d_2
  |.  nop
  |  b <7
  |.  nop
  |.endif
  |
  |.endmacro
  |
  |  math_minmax math_min, movz, movf.d
  |  math_minmax math_max, movn, movt.d
  |
  |//-- String library -----------------------------------------------------
  |
  |.ffunc string_byte			// Only handle the 1-arg case here.
  |  ld CARG1, 0(BASE)
  |  gettp TMP0, CARG1
  |  xori AT, NARGS8:RC, 8
  |  daddiu TMP0, TMP0, -LJ_TSTR
  |  or AT, AT, TMP0
  |  bnez AT, ->fff_fallback		// Need exactly 1 string argument.
  |.  cleartp STR:CARG1
  |  lw TMP0, STR:CARG1->len
  |    daddiu RA, BASE, -16
  |    ld PC, FRAME_PC(BASE)
  |  sltu RD, r0, TMP0
  |   lbu TMP1, STR:CARG1[1]		// Access is always ok (NUL at end).
  |  addiu RD, RD, 1
  |  sll RD, RD, 3			// RD = ((str->len != 0)+1)*8
  |  settp TMP1, TISNUM
  |  b ->fff_res
  |.  sd TMP1, 0(RA)
  |
  |.ffunc string_char			// Only handle the 1-arg case here.
  |  ffgccheck
  |.  nop
  |  ld CARG1, 0(BASE)
  |  gettp TMP0, CARG1
  |  xori AT, NARGS8:RC, 8		// Exactly 1 argument.
  |  daddiu TMP0, TMP0, -LJ_TISNUM	// Integer.
  |  li TMP1, 255
  |   sextw CARG1, CARG1
  |  or AT, AT, TMP0
  |   sltu TMP1, TMP1, CARG1		// !(255 < n).
  |   or AT, AT, TMP1
  |  bnez AT, ->fff_fallback
  |.  li CARG3, 1
  |  daddiu CARG2, sp, TMPD_OFS
  |  sb CARG1, TMPD
  |->fff_newstr:
  |  load_got lj_str_new
  |   sd BASE, L->base
  |   sd PC, SAVE_PC
  |  call_intern lj_str_new		// (lua_State *L, char *str, size_t l)
  |.  move CARG1, L
  |  // Returns GCstr *.
  |  ld BASE, L->base
  |->fff_resstr:
  |  li AT, LJ_TSTR
  |  settp CRET1, AT
  |  b ->fff_restv
  |.  move CARG1, CRET1
  |
  |.ffunc string_sub
  |  ffgccheck
  |.  nop
  |  addiu AT, NARGS8:RC, -16
  |  ld TMP0, 0(BASE)
  |  bltz AT, ->fff_fallback
  |.  gettp TMP3, TMP0
  |  cleartp STR:CARG1, TMP0
  |  ld CARG2, 8(BASE)
  |  beqz AT, >1
  |.  li CARG4, -1
  |  ld CARG3, 16(BASE)
  |  checkint CARG3, ->fff_fallback
  |.  sextw CARG4, CARG3
  |1:
  |  checkint CARG2, ->fff_fallback
  |.  li AT, LJ_TSTR
  |  bne TMP3, AT, ->fff_fallback
  |.  sextw CARG3, CARG2
  |  lw CARG2, STR:CARG1->len
  |  // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end
  |  slt AT, CARG4, r0
  |  addiu TMP0, CARG2, 1
  |  addu TMP1, CARG4, TMP0
  |   slt TMP3, CARG3, r0
  |  movn CARG4, TMP1, AT		// if (end < 0) end += len+1
  |   addu TMP1, CARG3, TMP0
  |   movn CARG3, TMP1, TMP3		// if (start < 0) start += len+1
  |   li TMP2, 1
  |  slt AT, CARG4, r0
  |   slt TMP3, r0, CARG3
  |  movn CARG4, r0, AT			// if (end < 0) end = 0
  |   movz CARG3, TMP2, TMP3		// if (start < 1) start = 1
  |  slt AT, CARG2, CARG4
  |  movn CARG4, CARG2, AT		// if (end > len) end = len
  |   daddu CARG2, STR:CARG1, CARG3
  |  subu CARG3, CARG4, CARG3		// len = end - start
  |   daddiu CARG2, CARG2, sizeof(GCstr)-1
  |  bgez CARG3, ->fff_newstr
  |.  addiu CARG3, CARG3, 1		// len++
  |->fff_emptystr:  // Return empty string.
  |  li AT, LJ_TSTR
  |  daddiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty)
  |  b ->fff_restv
  |.  settp CARG1, AT
  |
  |.macro ffstring_op, name
  |  .ffunc string_ .. name
  |  ffgccheck
  |.  nop
  |  beqz NARGS8:RC, ->fff_fallback
  |.  ld CARG2, 0(BASE)
  |  checkstr STR:CARG2, ->fff_fallback
  |  daddiu SBUF:CARG1, DISPATCH, DISPATCH_GL(tmpbuf)
  |  load_got lj_buf_putstr_ .. name
  |  ld TMP0, SBUF:CARG1->b
  |   sd L, SBUF:CARG1->L
  |   sd BASE, L->base
  |  sd TMP0, SBUF:CARG1->p
  |  call_intern extern lj_buf_putstr_ .. name
  |.  sd PC, SAVE_PC
  |  load_got lj_buf_tostr
  |  call_intern lj_buf_tostr
  |.  move SBUF:CARG1, SBUF:CRET1
  |  b ->fff_resstr
  |.  ld BASE, L->base
  |.endmacro
  |
  |ffstring_op reverse
  |ffstring_op lower
  |ffstring_op upper
  |
  |//-- Bit library --------------------------------------------------------
  |
  |->vm_tobit_fb:
  |  beqz TMP1, ->fff_fallback
  |.if FPU
  |.  ldc1 FARG1, 0(BASE)
  |  add.d FARG1, FARG1, TOBIT
  |  mfc1 CRET1, FARG1
  |  jr ra
  |.  zextw CRET1, CRET1
  |.else
  |// FP number to bit conversion for soft-float.
  |->vm_tobit:
  |  dsll TMP0, CARG1, 1
  |  li CARG3, 1076
  |  dsrl AT, TMP0, 53
  |  dsubu CARG3, CARG3, AT
  |  sltiu AT, CARG3, 54
  |  beqz AT, >1
  |.  dextm TMP0, TMP0, 0, 20
  |  dinsu TMP0, AT, 21, 21
  |  slt AT, CARG1, r0
  |  dsrlv CRET1, TMP0, CARG3
  |  dsubu TMP0, r0, CRET1
  |  movn CRET1, TMP0, AT
  |  jr ra
  |.  zextw CRET1, CRET1
  |1:
  |  jr ra
  |.  move CRET1, r0
  |.endif
  |
  |.macro .ffunc_bit, name
  |  .ffunc_1 bit_..name
  |  gettp TMP0, CARG1
  |  beq TMP0, TISNUM, >6
  |.  zextw CRET1, CARG1
  |  bal ->vm_tobit_fb
  |.  sltiu TMP1, TMP0, LJ_TISNUM
  |6:
  |.endmacro
  |
  |.macro .ffunc_bit_op, name, bins
  |  .ffunc_bit name
  |  daddiu TMP2, BASE, 8
  |  daddu TMP3, BASE, NARGS8:RC
  |1:
  |  beq TMP2, TMP3, ->fff_resi
  |.  ld CARG1, 0(TMP2)
  |  gettp TMP0, CARG1
  |.if FPU
  |  bne TMP0, TISNUM, >2
  |.  daddiu TMP2, TMP2, 8
  |  zextw CARG1, CARG1
  |  b <1
  |.  bins CRET1, CRET1, CARG1
  |2:
  |   ldc1 FARG1, -8(TMP2)
  |  sltiu AT, TMP0, LJ_TISNUM
  |  beqz AT, ->fff_fallback
  |.  add.d FARG1, FARG1, TOBIT
  |  mfc1 CARG1, FARG1
  |  zextw CARG1, CARG1
  |  b <1
  |.  bins CRET1, CRET1, CARG1
  |.else
  |  beq TMP0, TISNUM, >2
  |.  move CRET2, CRET1
  |  bal ->vm_tobit_fb
  |.  sltiu TMP1, TMP0, LJ_TISNUM
  |  move CARG1, CRET2
  |2:
  |  zextw CARG1, CARG1
  |  bins CRET1, CRET1, CARG1
  |  b <1
  |.  daddiu TMP2, TMP2, 8
  |.endif
  |.endmacro
  |
  |.ffunc_bit_op band, and
  |.ffunc_bit_op bor, or
  |.ffunc_bit_op bxor, xor
  |
  |.ffunc_bit bswap
  |  dsrl TMP0, CRET1, 8
  |   dsrl TMP1, CRET1, 24
  |  andi TMP2, TMP0, 0xff00
  |   dins TMP1, CRET1, 24, 31
  |  dins TMP2, TMP0, 16, 23
  |  b ->fff_resi
  |.  or CRET1, TMP1, TMP2
  |
  |.ffunc_bit bnot
  |  not CRET1, CRET1
  |  b ->fff_resi
  |.  zextw CRET1, CRET1
  |
  |.macro .ffunc_bit_sh, name, shins, shmod
  |  .ffunc_2 bit_..name
  |  gettp TMP0, CARG1
  |  beq TMP0, TISNUM, >1
  |.  nop
  |  bal ->vm_tobit_fb
  |.  sltiu TMP1, TMP0, LJ_TISNUM
  |  move CARG1, CRET1
  |1:
  |  gettp TMP0, CARG2
  |  bne TMP0, TISNUM, ->fff_fallback
  |.  zextw CARG2, CARG2
  |  sextw CARG1, CARG1
  |.if shmod == 1
  |  negu CARG2, CARG2
  |.endif
  |  shins CRET1, CARG1, CARG2
  |  b ->fff_resi
  |.  zextw CRET1, CRET1
  |.endmacro
  |
  |.ffunc_bit_sh lshift, sllv, 0
  |.ffunc_bit_sh rshift, srlv, 0
  |.ffunc_bit_sh arshift, srav, 0
  |.ffunc_bit_sh rol, rotrv, 1
  |.ffunc_bit_sh ror, rotrv, 0
  |
  |.ffunc_bit tobit
  |->fff_resi:
  |  ld PC, FRAME_PC(BASE)
  |  daddiu RA, BASE, -16
  |  settp CRET1, TISNUM
  |  b ->fff_res1
  |.  sd CRET1, -16(BASE)
  |
  |//-----------------------------------------------------------------------
  |->fff_fallback:			// Call fast function fallback handler.
  |  // BASE = new base, RB = CFUNC, RC = nargs*8
  |  ld TMP3, CFUNC:RB->f
  |    daddu TMP1, BASE, NARGS8:RC
  |   ld PC, FRAME_PC(BASE)		// Fallback may overwrite PC.
  |    daddiu TMP0, TMP1, 8*LUA_MINSTACK
  |     ld TMP2, L->maxstack
  |   sd PC, SAVE_PC			// Redundant (but a defined value).
  |  sltu AT, TMP2, TMP0
  |     sd BASE, L->base
  |    sd TMP1, L->top
  |  bnez AT, >5			// Need to grow stack.
  |.  move CFUNCADDR, TMP3
  |  jalr TMP3				// (lua_State *L)
  |.  move CARG1, L
  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.
  |  ld BASE, L->base
  |   sll RD, CRET1, 3
  |  bgtz CRET1, ->fff_res		// Returned nresults+1?
  |.  daddiu RA, BASE, -16
  |1:  // Returned 0 or -1: retry fast path.
  |   ld LFUNC:RB, FRAME_FUNC(BASE)
  |  ld TMP0, L->top
  |   cleartp LFUNC:RB
  |  bnez CRET1, ->vm_call_tail		// Returned -1?
  |.  dsubu NARGS8:RC, TMP0, BASE
  |  ins_callt				// Returned 0: retry fast path.
  |
  |// Reconstruct previous base for vmeta_call during tailcall.
  |->vm_call_tail:
  |  andi TMP0, PC, FRAME_TYPE
  |   li AT, -4
  |  bnez TMP0, >3
  |.  and TMP1, PC, AT
  |  lbu TMP1, OFS_RA(PC)
  |  sll TMP1, TMP1, 3
  |  addiu TMP1, TMP1, 16
  |3:
  |  b ->vm_call_dispatch		// Resolve again for tailcall.
  |.  dsubu TMP2, BASE, TMP1
  |
  |5:  // Grow stack for fallback handler.
  |  load_got lj_state_growstack
  |  li CARG2, LUA_MINSTACK
  |  call_intern lj_state_growstack	// (lua_State *L, int n)
  |.  move CARG1, L
  |  ld BASE, L->base
  |  b <1
  |.  li CRET1, 0			// Force retry.
  |
  |->fff_gcstep:			// Call GC step function.
  |  // BASE = new base, RC = nargs*8
  |  move MULTRES, ra
  |  load_got lj_gc_step
  |   sd BASE, L->base
  |  daddu TMP0, BASE, NARGS8:RC
  |   sd PC, SAVE_PC			// Redundant (but a defined value).
  |  sd TMP0, L->top
  |  call_intern lj_gc_step		// (lua_State *L)
  |.  move CARG1, L
  |   ld BASE, L->base
  |  move ra, MULTRES
  |    ld TMP0, L->top
  |  ld CFUNC:RB, FRAME_FUNC(BASE)
  |  cleartp CFUNC:RB
  |  jr ra
  |.  dsubu NARGS8:RC, TMP0, BASE
  |
  |//-----------------------------------------------------------------------
  |//-- Special dispatch targets -------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_record:				// Dispatch target for recording phase.
  |.if JIT
  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
  |  andi AT, TMP3, HOOK_VMEVENT	// No recording while in vmevent.
  |  bnez AT, >5
  |  // Decrement the hookcount for consistency, but always do the call.
  |.  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
  |  andi AT, TMP3, HOOK_ACTIVE
  |  bnez AT, >1
  |.  addiu TMP2, TMP2, -1
  |  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
  |  beqz AT, >1
  |.  nop
  |  b >1
  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
  |.endif
  |
  |->vm_rethook:			// Dispatch target for return hooks.
  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
  |  andi AT, TMP3, HOOK_ACTIVE		// Hook already active?
  |  beqz AT, >1
  |5:  // Re-dispatch to static ins.
  |.  ld AT, GG_DISP2STATIC(TMP0)	// Assumes TMP0 holds DISPATCH+OP*4.
  |  jr AT
  |.  nop
  |
  |->vm_inshook:			// Dispatch target for instr/line hooks.
  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
  |  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
  |  andi AT, TMP3, HOOK_ACTIVE		// Hook already active?
  |  bnez AT, <5
  |.  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
  |  beqz AT, <5
  |.  addiu TMP2, TMP2, -1
  |  beqz TMP2, >1
  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
  |  andi AT, TMP3, LUA_MASKLINE
  |  beqz AT, <5
  |1:
  |.  load_got lj_dispatch_ins
  |   sw MULTRES, SAVE_MULTRES
  |  move CARG2, PC
  |   sd BASE, L->base
  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
  |  call_intern lj_dispatch_ins	// (lua_State *L, const BCIns *pc)
  |.  move CARG1, L
  |3:
  |  ld BASE, L->base
  |4:  // Re-dispatch to static ins.
  |  lw INS, -4(PC)
  |  decode_OP8a TMP1, INS
  |  decode_OP8b TMP1
  |  daddu TMP0, DISPATCH, TMP1
  |   decode_RD8a RD, INS
  |  ld AT, GG_DISP2STATIC(TMP0)
  |   decode_RA8a RA, INS
  |   decode_RD8b RD
  |  jr AT
  |   decode_RA8b RA
  |
  |->cont_hook:				// Continue from hook yield.
  |  daddiu PC, PC, 4
  |  b <4
  |.  lw MULTRES, -24+LO(RB)		// Restore MULTRES for *M ins.
  |
  |->vm_hotloop:			// Hot loop counter underflow.
  |.if JIT
  |  ld LFUNC:TMP1, FRAME_FUNC(BASE)
  |   daddiu CARG1, DISPATCH, GG_DISP2J
  |  cleartp LFUNC:TMP1
  |   sd PC, SAVE_PC
  |  ld TMP1, LFUNC:TMP1->pc
  |   move CARG2, PC
  |   sd L, DISPATCH_J(L)(DISPATCH)
  |  lbu TMP1, PC2PROTO(framesize)(TMP1)
  |  load_got lj_trace_hot
  |   sd BASE, L->base
  |  dsll TMP1, TMP1, 3
  |  daddu TMP1, BASE, TMP1
  |  call_intern lj_trace_hot		// (jit_State *J, const BCIns *pc)
  |.  sd TMP1, L->top
  |  b <3
  |.  nop
  |.endif
  |
  |
  |->vm_callhook:			// Dispatch target for call hooks.
  |.if JIT
  |  b >1
  |.endif
  |.  move CARG2, PC
  |
  |->vm_hotcall:			// Hot call counter underflow.
  |.if JIT
  |  ori CARG2, PC, 1
  |1:
  |.endif
  |  load_got lj_dispatch_call
  |  daddu TMP0, BASE, RC
  |   sd PC, SAVE_PC
  |   sd BASE, L->base
  |  dsubu RA, RA, BASE
  |   sd TMP0, L->top
  |  call_intern lj_dispatch_call	// (lua_State *L, const BCIns *pc)
  |.  move CARG1, L
  |  // Returns ASMFunction.
  |  ld BASE, L->base
  |   ld TMP0, L->top
  |   sd r0, SAVE_PC			// Invalidate for subsequent line hook.
  |  dsubu NARGS8:RC, TMP0, BASE
  |  daddu RA, BASE, RA
  |  ld LFUNC:RB, FRAME_FUNC(BASE)
  |  cleartp LFUNC:RB
  |  jr CRET1
  |.  lw INS, -4(PC)
  |
  |->cont_stitch:			// Trace stitching.
  |.if JIT
  |  // RA = resultptr, RB = meta base
  |  lw INS, -4(PC)
  |    ld TRACE:TMP2, -40(RB)		// Save previous trace.
  |  decode_RA8a RC, INS
  |   daddiu AT, MULTRES, -8
  |    cleartp TRACE:TMP2
  |  decode_RA8b RC
  |   beqz AT, >2
  |. daddu RC, BASE, RC			// Call base.
  |1:  // Move results down.
  |  ld CARG1, 0(RA)
  |   daddiu AT, AT, -8
  |    daddiu RA, RA, 8
  |  sd CARG1, 0(RC)
  |   bnez AT, <1
  |.   daddiu RC, RC, 8
  |2:
  |   decode_RA8a RA, INS
  |    decode_RB8a RB, INS
  |   decode_RA8b RA
  |    decode_RB8b RB
  |   daddu RA, RA, RB
  |   daddu RA, BASE, RA
  |3:
  |   sltu AT, RC, RA
  |   bnez AT, >9			// More results wanted?
  |.   nop
  |
  |  lhu TMP3, TRACE:TMP2->traceno
  |  lhu RD, TRACE:TMP2->link
  |  beq RD, TMP3, ->cont_nop		// Blacklisted.
  |.  load_got lj_dispatch_stitch
  |  bnez RD, =>BC_JLOOP		// Jump to stitched trace.
  |.  sll RD, RD, 3
  |
  |  // Stitch a new trace to the previous trace.
  |  sw TMP3, DISPATCH_J(exitno)(DISPATCH)
  |  sd L, DISPATCH_J(L)(DISPATCH)
  |  sd BASE, L->base
  |  daddiu CARG1, DISPATCH, GG_DISP2J
  |  call_intern lj_dispatch_stitch	// (jit_State *J, const BCIns *pc)
  |.  move CARG2, PC
  |  b ->cont_nop
  |.  ld BASE, L->base
  |
  |9:
  |  sd TISNIL, 0(RC)
  |  b <3
  |.  daddiu RC, RC, 8
  |.endif
  |
  |->vm_profhook:			// Dispatch target for profiler hook.
#if LJ_HASPROFILE
  |  load_got lj_dispatch_profile
  |   sw MULTRES, SAVE_MULTRES
  |  move CARG2, PC
  |   sd BASE, L->base
  |  call_intern lj_dispatch_profile	// (lua_State *L, const BCIns *pc)
  |.  move CARG1, L
  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.
  |  daddiu PC, PC, -4
  |  b ->cont_nop
  |.  ld BASE, L->base
#endif
  |
  |//-----------------------------------------------------------------------
  |//-- Trace exit handler -------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |.macro savex_, a, b
  |.if FPU
  |  sdc1 f..a, a*8(sp)
  |  sdc1 f..b, b*8(sp)
  |  sd r..a, 32*8+a*8(sp)
  |  sd r..b, 32*8+b*8(sp)
  |.else
  |  sd r..a, a*8(sp)
  |  sd r..b, b*8(sp)
  |.endif
  |.endmacro
  |
  |->vm_exit_handler:
  |.if JIT
  |.if FPU
  |  daddiu sp, sp, -(32*8+32*8)
  |.else
  |  daddiu sp, sp, -(32*8)
  |.endif
  |  savex_ 0, 1
  |  savex_ 2, 3
  |  savex_ 4, 5
  |  savex_ 6, 7
  |  savex_ 8, 9
  |  savex_ 10, 11
  |  savex_ 12, 13
  |  savex_ 14, 15
  |  savex_ 16, 17
  |  savex_ 18, 19
  |  savex_ 20, 21
  |  savex_ 22, 23
  |  savex_ 24, 25
  |  savex_ 26, 27
  |  savex_ 28, 30
  |.if FPU
  |  sdc1 f29, 29*8(sp)
  |  sdc1 f31, 31*8(sp)
  |  sd r0, 32*8+31*8(sp)		// Clear RID_TMP.
  |  daddiu TMP2, sp, 32*8+32*8		// Recompute original value of sp.
  |  sd TMP2, 32*8+29*8(sp)		// Store sp in RID_SP
  |.else
  |  sd r0, 31*8(sp)			// Clear RID_TMP.
  |  daddiu TMP2, sp, 32*8		// Recompute original value of sp.
  |  sd TMP2, 29*8(sp)			// Store sp in RID_SP
  |.endif
  |  li_vmstate EXIT
  |  daddiu DISPATCH, JGL, -GG_DISP2G-32768
  |  lw TMP1, 0(TMP2)			// Load exit number.
  |  st_vmstate
  |  ld L, DISPATCH_GL(cur_L)(DISPATCH)
  |   ld BASE, DISPATCH_GL(jit_base)(DISPATCH)
  |  load_got lj_trace_exit
  |  sd L, DISPATCH_J(L)(DISPATCH)
  |  sw ra, DISPATCH_J(parent)(DISPATCH)  // Store trace number.
  |   sd BASE, L->base
  |  sw TMP1, DISPATCH_J(exitno)(DISPATCH)  // Store exit number.
  |  daddiu CARG1, DISPATCH, GG_DISP2J
  |   sd r0, DISPATCH_GL(jit_base)(DISPATCH)
  |  call_intern lj_trace_exit		// (jit_State *J, ExitState *ex)
  |.  move CARG2, sp
  |  // Returns MULTRES (unscaled) or negated error code.
  |  ld TMP1, L->cframe
  |  li AT, -4
  |   ld BASE, L->base
  |  and sp, TMP1, AT
  |   ld PC, SAVE_PC			// Get SAVE_PC.
  |  b >1
  |.  sd L, SAVE_L			// Set SAVE_L (on-trace resume/yield).
  |.endif
  |->vm_exit_interp:
  |.if JIT
  |  // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.
  |  ld L, SAVE_L
  |   daddiu DISPATCH, JGL, -GG_DISP2G-32768
  |  sd BASE, L->base
  |1:
  |  bltz CRET1, >9			// Check for error from exit.
  |.  ld LFUNC:RB, FRAME_FUNC(BASE)
  |    .FPU lui TMP3, 0x59c0		// TOBIT = 2^52 + 2^51 (float).
  |  dsll MULTRES, CRET1, 3
  |  cleartp LFUNC:RB
  |  sw MULTRES, SAVE_MULTRES
  |    li TISNIL, LJ_TNIL
  |     li TISNUM, LJ_TISNUM		// Setup type comparison constants.
  |    .FPU mtc1 TMP3, TOBIT
  |  ld TMP1, LFUNC:RB->pc
  |   sd r0, DISPATCH_GL(jit_base)(DISPATCH)
  |  ld KBASE, PC2PROTO(k)(TMP1)
  |    .FPU cvt.d.s TOBIT, TOBIT
  |  // Modified copy of ins_next which handles function header dispatch, too.
  |  lw INS, 0(PC)
  |   daddiu PC, PC, 4
  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1
  |    sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
  |  decode_OP8a TMP1, INS
  |  decode_OP8b TMP1
  |    sltiu TMP2, TMP1, BC_FUNCF*8
  |  daddu TMP0, DISPATCH, TMP1
  |   decode_RD8a RD, INS
  |  ld AT, 0(TMP0)
  |   decode_RA8a RA, INS
  |    beqz TMP2, >2
  |.  decode_RA8b RA
  |  jr AT
  |.  decode_RD8b RD
  |2:
  |  sltiu TMP2, TMP1, (BC_FUNCC+2)*8	// Fast function?
  |  bnez TMP2, >3
  |.  ld TMP1, FRAME_PC(BASE)
  |  // Check frame below fast function.
  |  andi TMP0, TMP1, FRAME_TYPE
  |  bnez TMP0, >3			// Trace stitching continuation?
  |.  nop
  |  // Otherwise set KBASE for Lua function below fast function.
  |  lw TMP2, -4(TMP1)
  |  decode_RA8a TMP0, TMP2
  |  decode_RA8b TMP0
  |  dsubu TMP1, BASE, TMP0
  |  ld LFUNC:TMP2, -32(TMP1)
  |  cleartp LFUNC:TMP2
  |  ld TMP1, LFUNC:TMP2->pc
  |  ld KBASE, PC2PROTO(k)(TMP1)
  |3:
  |  daddiu RC, MULTRES, -8
  |  jr AT
  |.  daddu RA, RA, BASE
  |
  |9:  // Rethrow error from the right C frame.
  |  load_got lj_err_throw
  |  negu CARG2, CRET1
  |  call_intern lj_err_throw		// (lua_State *L, int errcode)
  |.  move CARG1, L
  |.endif
  |
  |//-----------------------------------------------------------------------
  |//-- Math helper functions ----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// Hard-float round to integer.
  |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.
  |.macro vm_round_hf, func
  |  lui TMP0, 0x4330			// Hiword of 2^52 (double).
  |  dsll TMP0, TMP0, 32
  |  dmtc1 TMP0, f4
  |  abs.d FRET2, FARG1			// |x|
  |    dmfc1 AT, FARG1
  |  c.olt.d 0, FRET2, f4
  |   add.d FRET1, FRET2, f4		// (|x| + 2^52) - 2^52
  |  bc1f 0, >1				// Truncate only if |x| < 2^52.
  |.  sub.d FRET1, FRET1, f4
  |    slt AT, AT, r0
  |.if "func" == "ceil"
  |   lui TMP0, 0xbff0			// Hiword of -1 (double). Preserves -0.
  |.else
  |   lui TMP0, 0x3ff0			// Hiword of +1 (double).
  |.endif
  |.if "func" == "trunc"
  |   dsll TMP0, TMP0, 32
  |   dmtc1 TMP0, f4
  |  c.olt.d 0, FRET2, FRET1		// |x| < result?
  |   sub.d FRET2, FRET1, f4
  |  movt.d FRET1, FRET2, 0		// If yes, subtract +1.
  |  neg.d FRET2, FRET1
  |  jr ra
  |.  movn.d FRET1, FRET2, AT		// Merge sign bit back in.
  |.else
  |  neg.d FRET2, FRET1
  |   dsll TMP0, TMP0, 32
  |   dmtc1 TMP0, f4
  |  movn.d FRET1, FRET2, AT		// Merge sign bit back in.
  |.if "func" == "ceil"
  |  c.olt.d 0, FRET1, FARG1		// x > result?
  |.else
  |  c.olt.d 0, FARG1, FRET1		// x < result?
  |.endif
  |   sub.d FRET2, FRET1, f4		// If yes, subtract +-1.
  |  jr ra
  |.  movt.d FRET1, FRET2, 0
  |.endif
  |1:
  |  jr ra
  |.  mov.d FRET1, FARG1
  |.endmacro
  |
  |.macro vm_round, func
  |.if FPU
  |  vm_round_hf, func
  |.endif
  |.endmacro
  |
  |->vm_floor:
  |  vm_round floor
  |->vm_ceil:
  |  vm_round ceil
  |->vm_trunc:
  |.if JIT
  |  vm_round trunc
  |.endif
  |
  |// Soft-float integer to number conversion.
  |.macro sfi2d, ARG
  |.if not FPU
  |  beqz ARG, >9			// Handle zero first.
  |.  sra TMP0, ARG, 31
  |  xor TMP1, ARG, TMP0
  |  dsubu TMP1, TMP1, TMP0		// Absolute value in TMP1.
  |  dclz ARG, TMP1
  |  addiu ARG, ARG, -11
  |  li AT, 0x3ff+63-11-1
  |   dsllv TMP1, TMP1, ARG		// Align mantissa left with leading 1.
  |  subu ARG, AT, ARG			// Exponent - 1.
  |  ins ARG, TMP0, 11, 11		// Sign | Exponent.
  |  dsll ARG, ARG, 52			// Align left.
  |  jr ra
  |.  daddu ARG, ARG, TMP1		// Add mantissa, increment exponent.
  |9:
  |  jr ra
  |.  nop
  |.endif
  |.endmacro
  |
  |// Input CARG1. Output: CARG1. Temporaries: AT, TMP0, TMP1.
  |->vm_sfi2d_1:
  |  sfi2d CARG1
  |
  |// Input CARG2. Output: CARG2. Temporaries: AT, TMP0, TMP1.
  |->vm_sfi2d_2:
  |  sfi2d CARG2
  |
  |// Soft-float comparison. Equivalent to c.eq.d.
  |// Input: CARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1.
  |->vm_sfcmpeq:
  |.if not FPU
  |  dsll AT, CARG1, 1
  |  dsll TMP0, CARG2, 1
  |  or TMP1, AT, TMP0
  |  beqz TMP1, >8			// Both args +-0: return 1.
  |.  lui TMP1, 0xffe0
  |  dsll TMP1, TMP1, 32
  |   sltu AT, TMP1, AT
  |   sltu TMP0, TMP1, TMP0
  |  or TMP1, AT, TMP0
  |  bnez TMP1, >9			// Either arg is NaN: return 0;
  |.  xor AT, CARG1, CARG2
  |  jr ra
  |.  sltiu CRET1, AT, 1		// Same values: return 1.
  |8:
  |  jr ra
  |.  li CRET1, 1
  |9:
  |  jr ra
  |.  li CRET1, 0
  |.endif
  |
  |// Soft-float comparison. Equivalent to c.ult.d and c.olt.d.
  |// Input: CARG1, CARG2. Output: CRET1. Temporaries: AT, TMP0, TMP1, CRET2.
  |->vm_sfcmpult:
  |.if not FPU
  |  b >1
  |.  li CRET2, 1
  |.endif
  |
  |->vm_sfcmpolt:
  |.if not FPU
  |  li CRET2, 0
  |1:
  |  dsll AT, CARG1, 1
  |  dsll TMP0, CARG2, 1
  |  or TMP1, AT, TMP0
  |  beqz TMP1, >8			// Both args +-0: return 0.
  |.  lui TMP1, 0xffe0
  |  dsll TMP1, TMP1, 32
  |   sltu AT, TMP1, AT
  |   sltu TMP0, TMP1, TMP0
  |  or TMP1, AT, TMP0
  |  bnez TMP1, >9			// Either arg is NaN: return 0 or 1;
  |.  and AT, CARG1, CARG2
  |  bltz AT, >5			// Both args negative?
  |.  nop
  |  jr ra
  |.  slt CRET1, CARG1, CARG2
  |5:  // Swap conditions if both operands are negative.
  |  jr ra
  |.  slt CRET1, CARG2, CARG1
  |8:
  |  jr ra
  |.  nop
  |9:
  |  jr ra
  |.  move CRET1, CRET2
  |.endif
  |
  |// Soft-float comparison. Equivalent to c.ole.d a, b or c.ole.d b, a.
  |// Input: CARG1, CARG2, TMP3. Output: CRET1. Temporaries: AT, TMP0, TMP1.
  |->vm_sfcmpolex:
  |.if not FPU
  |  dsll AT, CARG1, 1
  |  dsll TMP0, CARG2, 1
  |  or TMP1, AT, TMP0
  |  beqz TMP1, >8			// Both args +-0: return 1.
  |.  lui TMP1, 0xffe0
  |  dsll TMP1, TMP1, 32
  |   sltu AT, TMP1, AT
  |   sltu TMP0, TMP1, TMP0
  |  or TMP1, AT, TMP0
  |  bnez TMP1, >9			// Either arg is NaN: return 0;
  |.  and AT, CARG1, CARG2
  |  xor AT, AT, TMP3
  |  bltz AT, >5			// Both args negative?
  |.  nop
  |  jr ra
  |.  slt CRET1, CARG2, CARG1
  |5:  // Swap conditions if both operands are negative.
  |  jr ra
  |.  slt CRET1, CARG1, CARG2
  |8:
  |  jr ra
  |.  li CRET1, 1
  |9:
  |  jr ra
  |.  li CRET1, 0
  |.endif
  |
  |//-----------------------------------------------------------------------
  |//-- Miscellaneous functions --------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |//-----------------------------------------------------------------------
  |//-- FFI helper functions -----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// Handler for callback functions. Callback slot number in r1, g in r2.
  |->vm_ffi_callback:
  |.if FFI
  |.type CTSTATE, CTState, PC
  |  saveregs
  |  ld CTSTATE, GL:r2->ctype_state
  |   daddiu DISPATCH, r2, GG_G2DISP
  |  load_got lj_ccallback_enter
  |  sw r1, CTSTATE->cb.slot
  |  sd CARG1, CTSTATE->cb.gpr[0]
  |  .FPU sdc1 FARG1, CTSTATE->cb.fpr[0]
  |  sd CARG2, CTSTATE->cb.gpr[1]
  |  .FPU sdc1 FARG2, CTSTATE->cb.fpr[1]
  |  sd CARG3, CTSTATE->cb.gpr[2]
  |  .FPU sdc1 FARG3, CTSTATE->cb.fpr[2]
  |  sd CARG4, CTSTATE->cb.gpr[3]
  |  .FPU sdc1 FARG4, CTSTATE->cb.fpr[3]
  |  sd CARG5, CTSTATE->cb.gpr[4]
  |  .FPU sdc1 FARG5, CTSTATE->cb.fpr[4]
  |  sd CARG6, CTSTATE->cb.gpr[5]
  |  .FPU sdc1 FARG6, CTSTATE->cb.fpr[5]
  |  sd CARG7, CTSTATE->cb.gpr[6]
  |  .FPU sdc1 FARG7, CTSTATE->cb.fpr[6]
  |  sd CARG8, CTSTATE->cb.gpr[7]
  |  .FPU sdc1 FARG8, CTSTATE->cb.fpr[7]
  |  daddiu TMP0, sp, CFRAME_SPACE
  |  sd TMP0, CTSTATE->cb.stack
  |  sd r0, SAVE_PC			// Any value outside of bytecode is ok.
  |   move CARG2, sp
  |  call_intern lj_ccallback_enter	// (CTState *cts, void *cf)
  |.  move CARG1, CTSTATE
  |  // Returns lua_State *.
  |  ld BASE, L:CRET1->base
  |  ld RC, L:CRET1->top
  |   move L, CRET1
  |     .FPU lui TMP3, 0x59c0		// TOBIT = 2^52 + 2^51 (float).
  |  ld LFUNC:RB, FRAME_FUNC(BASE)
  |     .FPU mtc1 TMP3, TOBIT
  |      li TISNIL, LJ_TNIL
  |       li TISNUM, LJ_TISNUM
  |    li_vmstate INTERP
  |  subu RC, RC, BASE
  |   cleartp LFUNC:RB
  |    st_vmstate
  |     .FPU cvt.d.s TOBIT, TOBIT
  |  ins_callt
  |.endif
  |
  |->cont_ffi_callback:			// Return from FFI callback.
  |.if FFI
  |  load_got lj_ccallback_leave
  |  ld CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)
  |   sd BASE, L->base
  |   sd RB, L->top
  |  sd L, CTSTATE->L
  |  move CARG2, RA
  |  call_intern lj_ccallback_leave	// (CTState *cts, TValue *o)
  |.  move CARG1, CTSTATE
  |  .FPU ldc1 FRET1, CTSTATE->cb.fpr[0]
  |  ld CRET1, CTSTATE->cb.gpr[0]
  |  .FPU ldc1 FRET2, CTSTATE->cb.fpr[1]
  |  b ->vm_leave_unw
  |.  ld CRET2, CTSTATE->cb.gpr[1]
  |.endif
  |
  |->vm_ffi_call:			// Call C function via FFI.
  |  // Caveat: needs special frame unwinding, see below.
  |.if FFI
  |  .type CCSTATE, CCallState, CARG1
  |  lw TMP1, CCSTATE->spadj
  |   lbu CARG2, CCSTATE->nsp
  |  move TMP2, sp
  |  dsubu sp, sp, TMP1
  |  sd ra, -8(TMP2)
  |   sll CARG2, CARG2, 3
  |  sd r16, -16(TMP2)
  |  sd CCSTATE, -24(TMP2)
  |  move r16, TMP2
  |  daddiu TMP1, CCSTATE, offsetof(CCallState, stack)
  |  move TMP2, sp
  |  beqz CARG2, >2
  |.  daddu TMP3, TMP1, CARG2
  |1:
  |   ld TMP0, 0(TMP1)
  |  daddiu TMP1, TMP1, 8
  |  sltu AT, TMP1, TMP3
  |   sd TMP0, 0(TMP2)
  |  bnez AT, <1
  |.  daddiu TMP2, TMP2, 8
  |2:
  |  ld CFUNCADDR, CCSTATE->func
  |  .FPU ldc1 FARG1, CCSTATE->gpr[0]
  |  ld CARG2, CCSTATE->gpr[1]
  |  .FPU ldc1 FARG2, CCSTATE->gpr[1]
  |  ld CARG3, CCSTATE->gpr[2]
  |  .FPU ldc1 FARG3, CCSTATE->gpr[2]
  |  ld CARG4, CCSTATE->gpr[3]
  |  .FPU ldc1 FARG4, CCSTATE->gpr[3]
  |  ld CARG5, CCSTATE->gpr[4]
  |  .FPU ldc1 FARG5, CCSTATE->gpr[4]
  |  ld CARG6, CCSTATE->gpr[5]
  |  .FPU ldc1 FARG6, CCSTATE->gpr[5]
  |  ld CARG7, CCSTATE->gpr[6]
  |  .FPU ldc1 FARG7, CCSTATE->gpr[6]
  |  ld CARG8, CCSTATE->gpr[7]
  |  .FPU ldc1 FARG8, CCSTATE->gpr[7]
  |  jalr CFUNCADDR
  |.  ld CARG1, CCSTATE->gpr[0]		// Do this last, since CCSTATE is CARG1.
  |  ld CCSTATE:TMP1, -24(r16)
  |  ld TMP2, -16(r16)
  |  ld ra, -8(r16)
  |  sd CRET1, CCSTATE:TMP1->gpr[0]
  |  sd CRET2, CCSTATE:TMP1->gpr[1]
  |.if FPU
  |  sdc1 FRET1, CCSTATE:TMP1->fpr[0]
  |  sdc1 FRET2, CCSTATE:TMP1->fpr[1]
  |.else
  |  sd CARG1, CCSTATE:TMP1->gpr[2]	// 2nd FP struct field for soft-float.
  |.endif
  |  move sp, r16
  |  jr ra
  |.  move r16, TMP2
  |.endif
  |// Note: vm_ffi_call must be the last function in this object file!
  |
  |//-----------------------------------------------------------------------
}

/* Generate the code for a single instruction. */
static void build_ins(BuildCtx *ctx, BCOp op, int defop)
{
  int vk = 0;
  |=>defop:

  switch (op) {

  /* -- Comparison ops ---------------------------------------------------- */

  /* Remember: all ops branch for a true comparison, fall through otherwise. */

  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
    |  // RA = src1*8, RD = src2*8, JMP with RD = target
    |.macro bc_comp, FRA, FRD, ARGRA, ARGRD, movop, fmovop, fcomp, sfcomp
    |  daddu RA, BASE, RA
    |   daddu RD, BASE, RD
    |  ld ARGRA, 0(RA)
    |   ld ARGRD, 0(RD)
    |    lhu TMP2, OFS_RD(PC)
    |  gettp CARG3, ARGRA
    |   gettp CARG4, ARGRD
    |  bne CARG3, TISNUM, >2
    |.   daddiu PC, PC, 4
    |  bne CARG4, TISNUM, >5
    |.   decode_RD4b TMP2
    |  sextw ARGRA, ARGRA
    |   sextw ARGRD, ARGRD
    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  slt AT, CARG1, CARG2
    |    addu TMP2, TMP2, TMP3
    |  movop TMP2, r0, AT
    |1:
    |  daddu PC, PC, TMP2
    |  ins_next
    |
    |2:  // RA is not an integer.
    |  sltiu AT, CARG3, LJ_TISNUM
    |  beqz AT, ->vmeta_comp
    |.   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  sltiu AT, CARG4, LJ_TISNUM
    |  beqz AT, >4
    |.   decode_RD4b TMP2
    |.if FPU
    |  ldc1 FRA, 0(RA)
    |   ldc1 FRD, 0(RD)
    |.endif
    |3:  // RA and RD are both numbers.
    |.if FPU
    |  fcomp f20, f22
    |   addu TMP2, TMP2, TMP3
    |  b <1
    |.  fmovop TMP2, r0
    |.else
    |  bal sfcomp
    |.   addu TMP2, TMP2, TMP3
    |  b <1
    |.  movop TMP2, r0, CRET1
    |.endif
    |
    |4:  // RA is a number, RD is not a number.
    |  bne CARG4, TISNUM, ->vmeta_comp
    |  // RA is a number, RD is an integer. Convert RD to a number.
    |.if FPU
    |.  lwc1 FRD, LO(RD)
    |  ldc1 FRA, 0(RA)
    |  b <3
    |.  cvt.d.w FRD, FRD
    |.else
    |.if "ARGRD" == "CARG1"
    |.  sextw CARG1, CARG1
    |  bal ->vm_sfi2d_1
    |.  nop
    |.else
    |.  sextw CARG2, CARG2
    |  bal ->vm_sfi2d_2
    |.  nop
    |.endif
    |  b <3
    |.  nop
    |.endif
    |
    |5:  // RA is an integer, RD is not an integer
    |  sltiu AT, CARG4, LJ_TISNUM
    |  beqz AT, ->vmeta_comp
    |.  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  // RA is an integer, RD is a number. Convert RA to a number.
    |.if FPU
    |   lwc1 FRA, LO(RA)
    |   ldc1 FRD, 0(RD)
    |  b <3
    |   cvt.d.w FRA, FRA
    |.else
    |.if "ARGRA" == "CARG1"
    |  bal ->vm_sfi2d_1
    |.  sextw CARG1, CARG1
    |.else
    |  bal ->vm_sfi2d_2
    |.  sextw CARG2, CARG2
    |.endif
    |  b <3
    |.  nop
    |.endif
    |.endmacro
    |
    if (op == BC_ISLT) {
      |  bc_comp f20, f22, CARG1, CARG2, movz, movf, c.olt.d, ->vm_sfcmpolt
    } else if (op == BC_ISGE) {
      |  bc_comp f20, f22, CARG1, CARG2, movn, movt, c.olt.d, ->vm_sfcmpolt
    } else if (op == BC_ISLE) {
      |  bc_comp f22, f20, CARG2, CARG1, movn, movt, c.ult.d, ->vm_sfcmpult
    } else {
      |  bc_comp f22, f20, CARG2, CARG1, movz, movf, c.ult.d, ->vm_sfcmpult
    }
    break;

  case BC_ISEQV: case BC_ISNEV:
    vk = op == BC_ISEQV;
    |  // RA = src1*8, RD = src2*8, JMP with RD = target
    |  daddu RA, BASE, RA
    |    daddiu PC, PC, 4
    |   daddu RD, BASE, RD
    |  ld CARG1, 0(RA)
    |    lhu TMP2, -4+OFS_RD(PC)
    |   ld CARG2, 0(RD)
    |  gettp CARG3, CARG1
    |   gettp CARG4, CARG2
    |  sltu AT, TISNUM, CARG3
    |   sltu TMP1, TISNUM, CARG4
    |  or AT, AT, TMP1
    if (vk) {
      |  beqz AT, ->BC_ISEQN_Z
    } else {
      |  beqz AT, ->BC_ISNEN_Z
    }
    |  // Either or both types are not numbers.
    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |.if FFI
    |.  li AT, LJ_TCDATA
    |  beq CARG3, AT, ->vmeta_equal_cd
    |.endif
    |   decode_RD4b TMP2
    |.if FFI
    |  beq CARG4, AT, ->vmeta_equal_cd
    |.  nop
    |.endif
    |  bne CARG1, CARG2, >2
    |.  addu TMP2, TMP2, TMP3
    |  // Tag and value are equal.
    if (vk) {
      |->BC_ISEQV_Z:
      |  daddu PC, PC, TMP2
    }
    |1:
    |  ins_next
    |
    |2:  // Check if the tags are the same and it's a table or userdata.
    |  xor AT, CARG3, CARG4			// Same type?
    |  sltiu TMP0, CARG3, LJ_TISTABUD+1		// Table or userdata?
    |  movn TMP0, r0, AT
    if (vk) {
      |  beqz TMP0, <1
    } else {
      |  beqz TMP0, ->BC_ISEQV_Z  // Reuse code from opposite instruction.
    }
    |  // Different tables or userdatas. Need to check __eq metamethod.
    |  // Field metatable must be at same offset for GCtab and GCudata!
    |.  cleartp TAB:TMP1, CARG1
    |  ld TAB:TMP3, TAB:TMP1->metatable
    if (vk) {
      |  beqz TAB:TMP3, <1		// No metatable?
      |.  nop
      |  lbu TMP3, TAB:TMP3->nomm
      |  andi TMP3, TMP3, 1<<MM_eq
      |  bnez TMP3, >1			// Or 'no __eq' flag set?
    } else {
      |  beqz TAB:TMP3,->BC_ISEQV_Z	// No metatable?
      |.  nop
      |  lbu TMP3, TAB:TMP3->nomm
      |  andi TMP3, TMP3, 1<<MM_eq
      |  bnez TMP3, ->BC_ISEQV_Z	// Or 'no __eq' flag set?
    }
    |.  nop
    |  b ->vmeta_equal			// Handle __eq metamethod.
    |.  li TMP0, 1-vk			// ne = 0 or 1.
    break;

  case BC_ISEQS: case BC_ISNES:
    vk = op == BC_ISEQS;
    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target
    |  daddu RA, BASE, RA
    |   daddiu PC, PC, 4
    |  ld CARG1, 0(RA)
    |   dsubu RD, KBASE, RD
    |    lhu TMP2, -4+OFS_RD(PC)
    |   ld CARG2, -8(RD)		// KBASE-8-str_const*8
    |.if FFI
    |  gettp TMP0, CARG1
    |  li AT, LJ_TCDATA
    |.endif
    |  li TMP1, LJ_TSTR
    |   decode_RD4b TMP2
    |.if FFI
    |  beq TMP0, AT, ->vmeta_equal_cd
    |.endif
    |.  settp CARG2, TMP1
    |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  xor TMP1, CARG1, CARG2
    |   addu TMP2, TMP2, TMP3
    if (vk) {
      |  movn TMP2, r0, TMP1
    } else {
      |  movz TMP2, r0, TMP1
    }
    |  daddu PC, PC, TMP2
    |  ins_next
    break;

  case BC_ISEQN: case BC_ISNEN:
    vk = op == BC_ISEQN;
    |  // RA = src*8, RD = num_const*8, JMP with RD = target
    |  daddu RA, BASE, RA
    |   daddu RD, KBASE, RD
    |  ld CARG1, 0(RA)
    |   ld CARG2, 0(RD)
    |    lhu TMP2, OFS_RD(PC)
    |  gettp CARG3, CARG1
    |   gettp CARG4, CARG2
    |    daddiu PC, PC, 4
    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    if (vk) {
      |->BC_ISEQN_Z:
    } else {
      |->BC_ISNEN_Z:
    }
    |  bne CARG3, TISNUM, >3
    |.   decode_RD4b TMP2
    |  bne CARG4, TISNUM, >6
    |.   addu TMP2, TMP2, TMP3
    |  xor AT, CARG1, CARG2
    if (vk) {
      | movn TMP2, r0, AT
      |1:
      |  daddu PC, PC, TMP2
      |2:
    } else {
      |  movz TMP2, r0, AT
      |1:
      |2:
      |  daddu PC, PC, TMP2
    }
    |  ins_next
    |
    |3:  // RA is not an integer.
    |  sltu AT, CARG3, TISNUM
    |.if FFI
    |  beqz AT, >8
    |.else
    |  beqz AT, <2
    |.endif
    |.   addu TMP2, TMP2, TMP3
    |  sltu AT, CARG4, TISNUM
    |.if FPU
    |  ldc1 f20, 0(RA)
    |   ldc1 f22, 0(RD)
    |.endif
    |  beqz AT, >5
    |.  nop
    |4:  // RA and RD are both numbers.
    |.if FPU
    |  c.eq.d f20, f22
    |  b <1
    if (vk) {
      |.  movf TMP2, r0
    } else {
      |.  movt TMP2, r0
    }
    |.else
    |  bal ->vm_sfcmpeq
    |.  nop
    |  b <1
    if (vk) {
      |.  movz TMP2, r0, CRET1
    } else {
      |.  movn TMP2, r0, CRET1
    }
    |.endif
    |
    |5:  // RA is a number, RD is not a number.
    |.if FFI
    |  bne CARG4, TISNUM, >9
    |.else
    |  bne CARG4, TISNUM, <2
    |.endif
    |  // RA is a number, RD is an integer. Convert RD to a number.
    |.if FPU
    |.  lwc1 f22, LO(RD)
    |  b <4
    |.  cvt.d.w f22, f22
    |.else
    |.  sextw CARG2, CARG2
    |  bal ->vm_sfi2d_2
    |.  nop
    |  b <4
    |.  nop
    |.endif
    |
    |6:  // RA is an integer, RD is not an integer
    |  sltu AT, CARG4, TISNUM
    |.if FFI
    |  beqz AT, >9
    |.else
    |  beqz AT, <2
    |.endif
    |  // RA is an integer, RD is a number. Convert RA to a number.
    |.if FPU
    |.  lwc1 f20, LO(RA)
    |   ldc1 f22, 0(RD)
    |  b <4
    |   cvt.d.w f20, f20
    |.else
    |.  sextw CARG1, CARG1
    |  bal ->vm_sfi2d_1
    |.  nop
    |  b <4
    |.  nop
    |.endif
    |
    |.if FFI
    |8:
    |  li AT, LJ_TCDATA
    |  bne CARG3, AT, <2
    |.  nop
    |  b ->vmeta_equal_cd
    |.  nop
    |9:
    |  li AT, LJ_TCDATA
    |  bne CARG4, AT, <2
    |.  nop
    |  b ->vmeta_equal_cd
    |.  nop
    |.endif
    break;

  case BC_ISEQP: case BC_ISNEP:
    vk = op == BC_ISEQP;
    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
    |  daddu RA, BASE, RA
    |   srl TMP1, RD, 3
    |  ld TMP0, 0(RA)
    |    lhu TMP2, OFS_RD(PC)
    |   not TMP1, TMP1
    |  gettp TMP0, TMP0
    |    daddiu PC, PC, 4
    |.if FFI
    |  li AT, LJ_TCDATA
    |  beq TMP0, AT, ->vmeta_equal_cd
    |.endif
    |.  xor TMP0, TMP0, TMP1
    |  decode_RD4b TMP2
    |  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  addu TMP2, TMP2, TMP3
    if (vk) {
      |  movn TMP2, r0, TMP0
    } else {
      |  movz TMP2, r0, TMP0
    }
    |  daddu PC, PC, TMP2
    |  ins_next
    break;

  /* -- Unary test and copy ops ------------------------------------------- */

  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target
    |  daddu RD, BASE, RD
    |   lhu TMP2, OFS_RD(PC)
    |  ld TMP0, 0(RD)
    |   daddiu PC, PC, 4
    |  gettp TMP0, TMP0
    |  sltiu TMP0, TMP0, LJ_TISTRUECOND
    if (op == BC_IST || op == BC_ISF) {
      |   decode_RD4b TMP2
      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
      |   addu TMP2, TMP2, TMP3
      if (op == BC_IST) {
	|  movz TMP2, r0, TMP0
      } else {
	|  movn TMP2, r0, TMP0
      }
      |  daddu PC, PC, TMP2
    } else {
      |  ld CRET1, 0(RD)
      if (op == BC_ISTC) {
	|  beqz TMP0, >1
      } else {
	|  bnez TMP0, >1
      }
      |.  daddu RA, BASE, RA
      |   decode_RD4b TMP2
      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
      |   addu TMP2, TMP2, TMP3
      |  sd CRET1, 0(RA)
      |   daddu PC, PC, TMP2
      |1:
    }
    |  ins_next
    break;

  case BC_ISTYPE:
    |  // RA = src*8, RD = -type*8
    |  daddu TMP2, BASE, RA
    |  srl TMP1, RD, 3
    |  ld TMP0, 0(TMP2)
    |  ins_next1
    |  gettp TMP0, TMP0
    |  daddu AT, TMP0, TMP1
    |  bnez AT, ->vmeta_istype
    |.  ins_next2
    break;
  case BC_ISNUM:
    |  // RA = src*8, RD = -(TISNUM-1)*8
    |  daddu TMP2, BASE, RA
    |  ld TMP0, 0(TMP2)
    |  ins_next1
    |  checknum TMP0, ->vmeta_istype
    |.  ins_next2
    break;

  /* -- Unary ops --------------------------------------------------------- */

  case BC_MOV:
    |  // RA = dst*8, RD = src*8
    |  daddu RD, BASE, RD
    |   daddu RA, BASE, RA
    |  ld CRET1, 0(RD)
    |  ins_next1
    |  sd CRET1, 0(RA)
    |  ins_next2
    break;
  case BC_NOT:
    |  // RA = dst*8, RD = src*8
    |  daddu RD, BASE, RD
    |   daddu RA, BASE, RA
    |  ld TMP0, 0(RD)
    |   li AT, LJ_TTRUE
    |  gettp TMP0, TMP0
    |  sltu TMP0, AT, TMP0
    |  addiu TMP0, TMP0, 1
    |  dsll TMP0, TMP0, 47
    |  not TMP0, TMP0
    |  ins_next1
    |   sd TMP0, 0(RA)
    |  ins_next2
    break;
  case BC_UNM:
    |  // RA = dst*8, RD = src*8
    |  daddu RB, BASE, RD
    |  ld CARG1, 0(RB)
    |    daddu RA, BASE, RA
    |  gettp CARG3, CARG1
    |  bne CARG3, TISNUM, >2
    |.  lui TMP1, 0x8000
    |  sextw CARG1, CARG1
    |  beq CARG1, TMP1, ->vmeta_unm	// Meta handler deals with -2^31.
    |.  negu CARG1, CARG1
    |  zextw CARG1, CARG1
    |  settp CARG1, TISNUM
    |1:
    |  ins_next1
    |   sd CARG1, 0(RA)
    |  ins_next2
    |2:
    |  sltiu AT, CARG3, LJ_TISNUM
    |  beqz AT, ->vmeta_unm
    |.  dsll TMP1, TMP1, 32
    |  b <1
    |.  xor CARG1, CARG1, TMP1
    break;
  case BC_LEN:
    |  // RA = dst*8, RD = src*8
    |  daddu CARG2, BASE, RD
    |   daddu RA, BASE, RA
    |  ld TMP0, 0(CARG2)
    |  gettp TMP1, TMP0
    |  daddiu AT, TMP1, -LJ_TSTR
    |  bnez AT, >2
    |.  cleartp STR:CARG1, TMP0
    |   lw CRET1, STR:CARG1->len
    |1:
    |  settp CRET1, TISNUM
    |  ins_next1
    |  sd CRET1, 0(RA)
    |  ins_next2
    |2:
    |  daddiu AT, TMP1, -LJ_TTAB
    |  bnez AT, ->vmeta_len
    |.  nop
#if LJ_52
    |  ld TAB:TMP2, TAB:CARG1->metatable
    |  bnez TAB:TMP2, >9
    |.  nop
    |3:
#endif
    |->BC_LEN_Z:
    |  load_got lj_tab_len
    |  call_intern lj_tab_len		// (GCtab *t)
    |.  nop
    |  // Returns uint32_t (but less than 2^31).
    |  b <1
    |.  nop
#if LJ_52
    |9:
    |  lbu TMP0, TAB:TMP2->nomm
    |  andi TMP0, TMP0, 1<<MM_len
    |  bnez TMP0, <3			// 'no __len' flag set: done.
    |.  nop
    |  b ->vmeta_len
    |.  nop
#endif
    break;

  /* -- Binary ops -------------------------------------------------------- */

    |.macro fpmod, a, b, c
    |  bal ->vm_floor		// floor(b/c)
    |.  div.d FARG1, b, c
    |  mul.d a, FRET1, c
    |  sub.d a, b, a		// b - floor(b/c)*c
    |.endmacro

    |.macro sfpmod
    |  daddiu sp, sp, -16
    |
    |  load_got __divdf3
    |  sd CARG1, 0(sp)
    |  call_extern
    |.  sd CARG2, 8(sp)
    |
    |  load_got floor
    |  call_extern
    |.  move CARG1, CRET1
    |
    |  load_got __muldf3
    |  move CARG1, CRET1
    |  call_extern
    |.  ld CARG2, 8(sp)
    |
    |  load_got __subdf3
    |  ld CARG1, 0(sp)
    |  call_extern
    |.  move CARG2, CRET1
    |
    |  daddiu sp, sp, 16
    |.endmacro

    |.macro ins_arithpre, label
    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
    ||switch (vk) {
    ||case 0:
    |   decode_RB8a RB, INS
    |   decode_RB8b RB
    |    decode_RDtoRC8 RC, RD
    |   // RA = dst*8, RB = src1*8, RC = num_const*8
    |   daddu RB, BASE, RB
    |.if "label" ~= "none"
    |   b label
    |.endif
    |.   daddu RC, KBASE, RC
    ||  break;
    ||case 1:
    |   decode_RB8a RC, INS
    |   decode_RB8b RC
    |    decode_RDtoRC8 RB, RD
    |   // RA = dst*8, RB = num_const*8, RC = src1*8
    |   daddu RC, BASE, RC
    |.if "label" ~= "none"
    |   b label
    |.endif
    |.   daddu RB, KBASE, RB
    ||  break;
    ||default:
    |   decode_RB8a RB, INS
    |   decode_RB8b RB
    |    decode_RDtoRC8 RC, RD
    |   // RA = dst*8, RB = src1*8, RC = src2*8
    |   daddu RB, BASE, RB
    |.if "label" ~= "none"
    |   b label
    |.endif
    |.   daddu RC, BASE, RC
    ||  break;
    ||}
    |.endmacro
    |
    |.macro ins_arith, intins, fpins, fpcall, label
    |  ins_arithpre none
    |
    |.if "label" ~= "none"
    |label:
    |.endif
    |
    |// Used in 5.
    |  ld CARG1, 0(RB)
    |   ld CARG2, 0(RC)
    |  gettp TMP0, CARG1
    |   gettp TMP1, CARG2
    |
    |.if "intins" ~= "div"
    |
    |  // Check for two integers.
    |  sextw CARG3, CARG1
    |  bne TMP0, TISNUM, >5
    |.  sextw CARG4, CARG2
    |  bne TMP1, TISNUM, >5
    |
    |.if "intins" == "addu"
    |.  intins CRET1, CARG3, CARG4
    |  xor TMP1, CRET1, CARG3		// ((y^a) & (y^b)) < 0: overflow.
    |  xor TMP2, CRET1, CARG4
    |  and TMP1, TMP1, TMP2
    |  bltz TMP1, ->vmeta_arith
    |.  daddu RA, BASE, RA
    |.elif "intins" == "subu"
    |.  intins CRET1, CARG3, CARG4
    |  xor TMP1, CRET1, CARG3		// ((y^a) & (a^b)) < 0: overflow.
    |  xor TMP2, CARG3, CARG4
    |  and TMP1, TMP1, TMP2
    |  bltz TMP1, ->vmeta_arith
    |.  daddu RA, BASE, RA
    |.elif "intins" == "mult"
    |.  intins CARG3, CARG4
    |  mflo CRET1
    |  mfhi TMP2
    |  sra TMP1, CRET1, 31
    |  bne TMP1, TMP2, ->vmeta_arith
    |.  daddu RA, BASE, RA
    |.else
    |.  load_got lj_vm_modi
    |  beqz CARG4, ->vmeta_arith
    |.  daddu RA, BASE, RA
    |  move CARG1, CARG3
    |  call_extern
    |.  move CARG2, CARG4
    |.endif
    |
    |  zextw CRET1, CRET1
    |  settp CRET1, TISNUM
    |  ins_next1
    |  sd CRET1, 0(RA)
    |3:
    |  ins_next2
    |
    |.endif
    |
    |5:  // Check for two numbers.
    |  .FPU ldc1 f20, 0(RB)
    |  sltu AT, TMP0, TISNUM
    |   sltu TMP0, TMP1, TISNUM
    |  .FPU ldc1 f22, 0(RC)
    |   and AT, AT, TMP0
    |   beqz AT, ->vmeta_arith
    |.   daddu RA, BASE, RA
    |
    |.if FPU
    |  fpins FRET1, f20, f22
    |.elif "fpcall" == "sfpmod"
    |  sfpmod
    |.else
    |  load_got fpcall
    |  call_extern
    |.  nop
    |.endif
    |
    |  ins_next1
    |.if "intins" ~= "div"
    |  b <3
    |.endif
    |.if FPU
    |.  sdc1 FRET1, 0(RA)
    |.else
    |.  sd CRET1, 0(RA)
    |.endif
    |.if "intins" == "div"
    |  ins_next2
    |.endif
    |
    |.endmacro

  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
    |  ins_arith addu, add.d, __adddf3, none
    break;
  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
    |  ins_arith subu, sub.d, __subdf3, none
    break;
  case BC_MULVN: case BC_MULNV: case BC_MULVV:
    |  ins_arith mult, mul.d, __muldf3, none
    break;
  case BC_DIVVN:
    |  ins_arith div, div.d, __divdf3, ->BC_DIVVN_Z
    break;
  case BC_DIVNV: case BC_DIVVV:
    |  ins_arithpre ->BC_DIVVN_Z
    break;
  case BC_MODVN:
    |  ins_arith modi, fpmod, sfpmod, ->BC_MODVN_Z
    break;
  case BC_MODNV: case BC_MODVV:
    |  ins_arithpre ->BC_MODVN_Z
    break;
  case BC_POW:
    |  ins_arithpre none
    |  ld CARG1, 0(RB)
    |   ld CARG2, 0(RC)
    |  gettp TMP0, CARG1
    |   gettp TMP1, CARG2
    |  sltiu TMP0, TMP0, LJ_TISNUM
    |   sltiu TMP1, TMP1, LJ_TISNUM
    |  and AT, TMP0, TMP1
    |  load_got pow
    |  beqz AT, ->vmeta_arith
    |.  daddu RA, BASE, RA
    |.if FPU
    |  ldc1 FARG1, 0(RB)
    |  ldc1 FARG2, 0(RC)
    |.endif
    |  call_extern
    |.  nop
    |  ins_next1
    |.if FPU
    |  sdc1 FRET1, 0(RA)
    |.else
    |  sd CRET1, 0(RA)
    |.endif
    |  ins_next2
    break;

  case BC_CAT:
    |  // RA = dst*8, RB = src_start*8, RC = src_end*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RDtoRC8 RC, RD
    |  dsubu CARG3, RC, RB
    |   sd BASE, L->base
    |  daddu CARG2, BASE, RC
    |  move MULTRES, RB
    |->BC_CAT_Z:
    |  load_got lj_meta_cat
    |  srl CARG3, CARG3, 3
    |   sd PC, SAVE_PC
    |  call_intern lj_meta_cat		// (lua_State *L, TValue *top, int left)
    |.  move CARG1, L
    |  // Returns NULL (finished) or TValue * (metamethod).
    |  bnez CRET1, ->vmeta_binop
    |.  ld BASE, L->base
    |  daddu RB, BASE, MULTRES
    |  ld CRET1, 0(RB)
    |   daddu RA, BASE, RA
    |  ins_next1
    |  sd CRET1, 0(RA)
    |  ins_next2
    break;

  /* -- Constant ops ------------------------------------------------------ */

  case BC_KSTR:
    |  // RA = dst*8, RD = str_const*8 (~)
    |  dsubu TMP1, KBASE, RD
    |  ins_next1
    |   li TMP2, LJ_TSTR
    |  ld TMP0, -8(TMP1)		// KBASE-8-str_const*8
    |  daddu RA, BASE, RA
    |   settp TMP0, TMP2
    |  sd TMP0, 0(RA)
    |  ins_next2
    break;
  case BC_KCDATA:
    |.if FFI
    |  // RA = dst*8, RD = cdata_const*8 (~)
    |  dsubu TMP1, KBASE, RD
    |  ins_next1
    |  ld TMP0, -8(TMP1)		// KBASE-8-cdata_const*8
    |   li TMP2, LJ_TCDATA
    |  daddu RA, BASE, RA
    |   settp TMP0, TMP2
    |  sd TMP0, 0(RA)
    |  ins_next2
    |.endif
    break;
  case BC_KSHORT:
    |  // RA = dst*8, RD = int16_literal*8
    |   sra RD, INS, 16
    |  daddu RA, BASE, RA
    |   zextw RD, RD
    |  ins_next1
    |   settp RD, TISNUM
    |   sd RD, 0(RA)
    |  ins_next2
    break;
  case BC_KNUM:
    |  // RA = dst*8, RD = num_const*8
    |  daddu RD, KBASE, RD
    |   daddu RA, BASE, RA
    |  ld CRET1, 0(RD)
    |  ins_next1
    |  sd CRET1, 0(RA)
    |  ins_next2
    break;
  case BC_KPRI:
    |  // RA = dst*8, RD = primitive_type*8 (~)
    |   daddu RA, BASE, RA
    |  dsll TMP0, RD, 44
    |  not TMP0, TMP0
    |  ins_next1
    |   sd TMP0, 0(RA)
    |  ins_next2
    break;
  case BC_KNIL:
    |  // RA = base*8, RD = end*8
    |  daddu RA, BASE, RA
    |  sd TISNIL, 0(RA)
    |   daddiu RA, RA, 8
    |  daddu RD, BASE, RD
    |1:
    |  sd TISNIL, 0(RA)
    |  slt AT, RA, RD
    |  bnez AT, <1
    |.  daddiu RA, RA, 8
    |  ins_next_
    break;

  /* -- Upvalue and function ops ------------------------------------------ */

  case BC_UGET:
    |  // RA = dst*8, RD = uvnum*8
    |  ld LFUNC:RB, FRAME_FUNC(BASE)
    |   daddu RA, BASE, RA
    |  cleartp LFUNC:RB
    |  daddu RD, RD, LFUNC:RB
    |  ld UPVAL:RB, LFUNC:RD->uvptr
    |  ins_next1
    |  ld TMP1, UPVAL:RB->v
    |  ld CRET1, 0(TMP1)
    |   sd CRET1, 0(RA)
    |  ins_next2
    break;
  case BC_USETV:
    |  // RA = uvnum*8, RD = src*8
    |  ld LFUNC:RB, FRAME_FUNC(BASE)
    |   daddu RD, BASE, RD
    |  cleartp LFUNC:RB
    |  daddu RA, RA, LFUNC:RB
    |  ld UPVAL:RB, LFUNC:RA->uvptr
    |   ld CRET1, 0(RD)
    |  lbu TMP3, UPVAL:RB->marked
    |   ld CARG2, UPVAL:RB->v
    |  andi TMP3, TMP3, LJ_GC_BLACK	// isblack(uv)
    |  lbu TMP0, UPVAL:RB->closed
    |   gettp TMP2, CRET1
    |   sd CRET1, 0(CARG2)
    |  li AT, LJ_GC_BLACK|1
    |  or TMP3, TMP3, TMP0
    |  beq TMP3, AT, >2			// Upvalue is closed and black?
    |.  daddiu TMP2, TMP2, -(LJ_TNUMX+1)
    |1:
    |  ins_next
    |
    |2:  // Check if new value is collectable.
    |  sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)
    |  beqz AT, <1			// tvisgcv(v)
    |.  cleartp GCOBJ:CRET1, CRET1
    |  lbu TMP3, GCOBJ:CRET1->gch.marked
    |  andi TMP3, TMP3, LJ_GC_WHITES	// iswhite(v)
    |  beqz TMP3, <1
    |.  load_got lj_gc_barrieruv
    |  // Crossed a write barrier. Move the barrier forward.
    |  call_intern lj_gc_barrieruv	// (global_State *g, TValue *tv)
    |.  daddiu CARG1, DISPATCH, GG_DISP2G
    |  b <1
    |.  nop
    break;
  case BC_USETS:
    |  // RA = uvnum*8, RD = str_const*8 (~)
    |  ld LFUNC:RB, FRAME_FUNC(BASE)
    |   dsubu TMP1, KBASE, RD
    |  cleartp LFUNC:RB
    |  daddu RA, RA, LFUNC:RB
    |  ld UPVAL:RB, LFUNC:RA->uvptr
    |   ld STR:TMP1, -8(TMP1)		// KBASE-8-str_const*8
    |  lbu TMP2, UPVAL:RB->marked
    |   ld CARG2, UPVAL:RB->v
    |   lbu TMP3, STR:TMP1->marked
    |  andi AT, TMP2, LJ_GC_BLACK	// isblack(uv)
    |   lbu TMP2, UPVAL:RB->closed
    |   li TMP0, LJ_TSTR
    |   settp TMP1, TMP0
    |  bnez AT, >2
    |.  sd TMP1, 0(CARG2)
    |1:
    |  ins_next
    |
    |2:  // Check if string is white and ensure upvalue is closed.
    |  beqz TMP2, <1
    |.  andi AT, TMP3, LJ_GC_WHITES	// iswhite(str)
    |  beqz AT, <1
    |.  load_got lj_gc_barrieruv
    |  // Crossed a write barrier. Move the barrier forward.
    |  call_intern lj_gc_barrieruv	// (global_State *g, TValue *tv)
    |.  daddiu CARG1, DISPATCH, GG_DISP2G
    |  b <1
    |.  nop
    break;
  case BC_USETN:
    |  // RA = uvnum*8, RD = num_const*8
    |  ld LFUNC:RB, FRAME_FUNC(BASE)
    |   daddu RD, KBASE, RD
    |  cleartp LFUNC:RB
    |  daddu RA, RA, LFUNC:RB
    |  ld UPVAL:RB, LFUNC:RA->uvptr
    |   ld CRET1, 0(RD)
    |  ld TMP1, UPVAL:RB->v
    |  ins_next1
    |   sd CRET1, 0(TMP1)
    |  ins_next2
    break;
  case BC_USETP:
    |  // RA = uvnum*8, RD = primitive_type*8 (~)
    |  ld LFUNC:RB, FRAME_FUNC(BASE)
    |   dsll TMP0, RD, 44
    |  cleartp LFUNC:RB
    |  daddu RA, RA, LFUNC:RB
    |   not TMP0, TMP0
    |  ld UPVAL:RB, LFUNC:RA->uvptr
    |  ins_next1
    |  ld TMP1, UPVAL:RB->v
    |   sd TMP0, 0(TMP1)
    |  ins_next2
    break;

  case BC_UCLO:
    |  // RA = level*8, RD = target
    |  ld TMP2, L->openupval
    |  branch_RD			// Do this first since RD is not saved.
    |  load_got lj_func_closeuv
    |   sd BASE, L->base
    |  beqz TMP2, >1
    |.  move CARG1, L
    |  call_intern lj_func_closeuv	// (lua_State *L, TValue *level)
    |.  daddu CARG2, BASE, RA
    |  ld BASE, L->base
    |1:
    |  ins_next
    break;

  case BC_FNEW:
    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
    |  load_got lj_func_newL_gc
    |  dsubu TMP1, KBASE, RD
    |  ld CARG3, FRAME_FUNC(BASE)
    |   ld CARG2, -8(TMP1)		// KBASE-8-tab_const*8
    |    sd BASE, L->base
    |    sd PC, SAVE_PC
    |  cleartp CARG3
    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)
    |  call_intern lj_func_newL_gc
    |.  move CARG1, L
    |  // Returns GCfuncL *.
    |   li TMP0, LJ_TFUNC
    |  ld BASE, L->base
    |  ins_next1
    |   settp CRET1, TMP0
    |  daddu RA, BASE, RA
    |   sd CRET1, 0(RA)
    |  ins_next2
    break;

  /* -- Table ops --------------------------------------------------------- */

  case BC_TNEW:
  case BC_TDUP:
    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
    |  ld TMP0, DISPATCH_GL(gc.total)(DISPATCH)
    |  ld TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
    |   sd BASE, L->base
    |   sd PC, SAVE_PC
    |  sltu AT, TMP0, TMP1
    |  beqz AT, >5
    |1:
    if (op == BC_TNEW) {
      |  load_got lj_tab_new
      |  srl CARG2, RD, 3
      |  andi CARG2, CARG2, 0x7ff
      |  li TMP0, 0x801
      |  addiu AT, CARG2, -0x7ff
      |   srl CARG3, RD, 14
      |  movz CARG2, TMP0, AT
      |  // (lua_State *L, int32_t asize, uint32_t hbits)
      |  call_intern lj_tab_new
      |.  move CARG1, L
      |  // Returns Table *.
    } else {
      |  load_got lj_tab_dup
      |  dsubu TMP1, KBASE, RD
      |  move CARG1, L
      |  call_intern lj_tab_dup		// (lua_State *L, Table *kt)
      |.  ld CARG2, -8(TMP1)		// KBASE-8-str_const*8
      |  // Returns Table *.
    }
    |   li TMP0, LJ_TTAB
    |  ld BASE, L->base
    |  ins_next1
    |  daddu RA, BASE, RA
    |   settp CRET1, TMP0
    |   sd CRET1, 0(RA)
    |  ins_next2
    |5:
    |  load_got lj_gc_step_fixtop
    |  move MULTRES, RD
    |  call_intern lj_gc_step_fixtop	// (lua_State *L)
    |.  move CARG1, L
    |  b <1
    |.  move RD, MULTRES
    break;

  case BC_GGET:
    |  // RA = dst*8, RD = str_const*8 (~)
  case BC_GSET:
    |  // RA = src*8, RD = str_const*8 (~)
    |  ld LFUNC:TMP2, FRAME_FUNC(BASE)
    |   dsubu TMP1, KBASE, RD
    |   ld STR:RC, -8(TMP1)		// KBASE-8-str_const*8
    |  cleartp LFUNC:TMP2
    |  ld TAB:RB, LFUNC:TMP2->env
    if (op == BC_GGET) {
      |  b ->BC_TGETS_Z
    } else {
      |  b ->BC_TSETS_Z
    }
    |.  daddu RA, BASE, RA
    break;

  case BC_TGETV:
    |  // RA = dst*8, RB = table*8, RC = key*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RDtoRC8 RC, RD
    |  daddu CARG2, BASE, RB
    |   daddu CARG3, BASE, RC
    |  ld TAB:RB, 0(CARG2)
    |   ld TMP2, 0(CARG3)
    |   daddu RA, BASE, RA
    |  checktab TAB:RB, ->vmeta_tgetv
    |   gettp TMP3, TMP2
    |  bne TMP3, TISNUM, >5		// Integer key?
    |.  lw TMP0, TAB:RB->asize
    |  sextw TMP2, TMP2
    |   ld TMP1, TAB:RB->array
    |  sltu AT, TMP2, TMP0
    |   sll TMP2, TMP2, 3
    |  beqz AT, ->vmeta_tgetv		// Integer key and in array part?
    |.  daddu TMP2, TMP1, TMP2
    |  ld AT, 0(TMP2)
    |  beq AT, TISNIL, >2
    |.   ld CRET1, 0(TMP2)
    |1:
    |  ins_next1
    |   sd CRET1, 0(RA)
    |  ins_next2
    |
    |2:  // Check for __index if table value is nil.
    |  ld TAB:TMP2, TAB:RB->metatable
    |  beqz TAB:TMP2, <1		// No metatable: done.
    |.  nop
    |  lbu TMP0, TAB:TMP2->nomm
    |  andi TMP0, TMP0, 1<<MM_index
    |  bnez TMP0, <1			// 'no __index' flag set: done.
    |.  nop
    |  b ->vmeta_tgetv
    |.  nop
    |
    |5:
    |  li AT, LJ_TSTR
    |  bne TMP3, AT, ->vmeta_tgetv
    |.  cleartp RC, TMP2
    |  b ->BC_TGETS_Z			// String key?
    |.  nop
    break;
  case BC_TGETS:
    |  // RA = dst*8, RB = table*8, RC = str_const*8 (~)
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RC8a RC, INS
    |  daddu CARG2, BASE, RB
    |   decode_RC8b RC
    |  ld TAB:RB, 0(CARG2)
    |   dsubu CARG3, KBASE, RC
    |  daddu RA, BASE, RA
    |   ld STR:RC, -8(CARG3)		// KBASE-8-str_const*8
    |  checktab TAB:RB, ->vmeta_tgets1
    |->BC_TGETS_Z:
    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
    |  lw TMP0, TAB:RB->hmask
    |   lw TMP1, STR:RC->hash
    |    ld NODE:TMP2, TAB:RB->node
    |  and TMP1, TMP1, TMP0		// idx = str->hash & tab->hmask
    |  sll TMP0, TMP1, 5
    |  sll TMP1, TMP1, 3
    |  subu TMP1, TMP0, TMP1
    |   li TMP3, LJ_TSTR
    |  daddu NODE:TMP2, NODE:TMP2, TMP1	// node = tab->node + (idx*32-idx*8)
    |   settp STR:RC, TMP3		// Tagged key to look for.
    |1:
    |  ld CARG1, NODE:TMP2->key
    |   ld CRET1, NODE:TMP2->val
    |    ld NODE:TMP1, NODE:TMP2->next
    |  bne CARG1, RC, >4
    |.  ld TAB:TMP3, TAB:RB->metatable
    |  beq CRET1, TISNIL, >5		// Key found, but nil value?
    |.  nop
    |3:
    |  ins_next1
    |   sd CRET1, 0(RA)
    |  ins_next2
    |
    |4:  // Follow hash chain.
    |  bnez NODE:TMP1, <1
    |.  move NODE:TMP2, NODE:TMP1
    |  // End of hash chain: key not found, nil result.
    |
    |5:  // Check for __index if table value is nil.
    |  beqz TAB:TMP3, <3		// No metatable: done.
    |.  move CRET1, TISNIL
    |  lbu TMP0, TAB:TMP3->nomm
    |  andi TMP0, TMP0, 1<<MM_index
    |  bnez TMP0, <3			// 'no __index' flag set: done.
    |.  nop
    |  b ->vmeta_tgets
    |.  nop
    break;
  case BC_TGETB:
    |  // RA = dst*8, RB = table*8, RC = index*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |  daddu CARG2, BASE, RB
    |   decode_RDtoRC8 RC, RD
    |  ld TAB:RB, 0(CARG2)
    |   daddu RA, BASE, RA
    |  srl TMP0, RC, 3
    |  checktab TAB:RB, ->vmeta_tgetb
    |  lw TMP1, TAB:RB->asize
    |   ld TMP2, TAB:RB->array
    |  sltu AT, TMP0, TMP1
    |  beqz AT, ->vmeta_tgetb
    |.  daddu RC, TMP2, RC
    |  ld AT, 0(RC)
    |  beq AT, TISNIL, >5
    |.  ld CRET1, 0(RC)
    |1:
    |  ins_next1
    |   sd CRET1, 0(RA)
    |  ins_next2
    |
    |5:  // Check for __index if table value is nil.
    |  ld TAB:TMP2, TAB:RB->metatable
    |  beqz TAB:TMP2, <1		// No metatable: done.
    |.  nop
    |  lbu TMP1, TAB:TMP2->nomm
    |  andi TMP1, TMP1, 1<<MM_index
    |  bnez TMP1, <1			// 'no __index' flag set: done.
    |.  nop
    |  b ->vmeta_tgetb			// Caveat: preserve TMP0 and CARG2!
    |.  nop
    break;
  case BC_TGETR:
    |  // RA = dst*8, RB = table*8, RC = key*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RDtoRC8 RC, RD
    |  daddu RB, BASE, RB
    |   daddu RC, BASE, RC
    |  ld TAB:CARG1, 0(RB)
    |   lw CARG2, LO(RC)
    |    daddu RA, BASE, RA
    |  cleartp TAB:CARG1
    |  lw TMP0, TAB:CARG1->asize
    |   ld TMP1, TAB:CARG1->array
    |  sltu AT, CARG2, TMP0
    |   sll TMP2, CARG2, 3
    |  beqz AT, ->vmeta_tgetr		// In array part?
    |.  daddu CRET1, TMP1, TMP2
    |   ld CARG2, 0(CRET1)
    |->BC_TGETR_Z:
    |  ins_next1
    |   sd CARG2, 0(RA)
    |  ins_next2
    break;

  case BC_TSETV:
    |  // RA = src*8, RB = table*8, RC = key*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RDtoRC8 RC, RD
    |  daddu CARG2, BASE, RB
    |   daddu CARG3, BASE, RC
    |  ld RB, 0(CARG2)
    |   ld TMP2, 0(CARG3)
    |  daddu RA, BASE, RA
    |  checktab RB, ->vmeta_tsetv
    |  checkint TMP2, >5
    |.  sextw RC, TMP2
    |  lw TMP0, TAB:RB->asize
    |   ld TMP1, TAB:RB->array
    |  sltu AT, RC, TMP0
    |   sll TMP2, RC, 3
    |  beqz AT, ->vmeta_tsetv		// Integer key and in array part?
    |.  daddu TMP1, TMP1, TMP2
    |  ld TMP0, 0(TMP1)
    |   lbu TMP3, TAB:RB->marked
    |  beq TMP0, TISNIL, >3
    |.  ld CRET1, 0(RA)
    |1:
    |   andi AT, TMP3, LJ_GC_BLACK	// isblack(table)
    |  bnez AT, >7
    |.  sd CRET1, 0(TMP1)
    |2:
    |  ins_next
    |
    |3:  // Check for __newindex if previous value is nil.
    |  ld TAB:TMP2, TAB:RB->metatable
    |  beqz TAB:TMP2, <1		// No metatable: done.
    |.  nop
    |  lbu TMP2, TAB:TMP2->nomm
    |  andi TMP2, TMP2, 1<<MM_newindex
    |  bnez TMP2, <1			// 'no __newindex' flag set: done.
    |.  nop
    |  b ->vmeta_tsetv
    |.  nop
    |
    |5:
    |  gettp AT, TMP2
    |  daddiu AT, AT, -LJ_TSTR
    |  bnez AT, ->vmeta_tsetv
    |.  nop
    |  b ->BC_TSETS_Z			// String key?
    |.  cleartp STR:RC, TMP2
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMP3, TMP0, <2
    break;
  case BC_TSETS:
    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |  daddu CARG2, BASE, RB
    |   decode_RC8a RC, INS
    |    ld TAB:RB, 0(CARG2)
    |   decode_RC8b RC
    |   dsubu CARG3, KBASE, RC
    |   ld RC, -8(CARG3)		// KBASE-8-str_const*8
    |  daddu RA, BASE, RA
    |   cleartp STR:RC
    |  checktab TAB:RB, ->vmeta_tsets1
    |->BC_TSETS_Z:
    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8
    |  lw TMP0, TAB:RB->hmask
    |   lw TMP1, STR:RC->hash
    |    ld NODE:TMP2, TAB:RB->node
    |   sb r0, TAB:RB->nomm		// Clear metamethod cache.
    |  and TMP1, TMP1, TMP0		// idx = str->hash & tab->hmask
    |  sll TMP0, TMP1, 5
    |  sll TMP1, TMP1, 3
    |  subu TMP1, TMP0, TMP1
    |   li TMP3, LJ_TSTR
    |  daddu NODE:TMP2, NODE:TMP2, TMP1	// node = tab->node + (idx*32-idx*8)
    |   settp STR:RC, TMP3		// Tagged key to look for.
    |.if FPU
    |   ldc1 f20, 0(RA)
    |.else
    |   ld CRET1, 0(RA)
    |.endif
    |1:
    |  ld TMP0, NODE:TMP2->key
    |   ld CARG2, NODE:TMP2->val
    |    ld NODE:TMP1, NODE:TMP2->next
    |  bne TMP0, RC, >5
    |.    lbu TMP3, TAB:RB->marked
    |   beq CARG2, TISNIL, >4		// Key found, but nil value?
    |.   ld TAB:TMP0, TAB:RB->metatable
    |2:
    |  andi AT, TMP3, LJ_GC_BLACK	// isblack(table)
    |  bnez AT, >7
    |.if FPU
    |.  sdc1 f20, NODE:TMP2->val
    |.else
    |.  sd CRET1, NODE:TMP2->val
    |.endif
    |3:
    |  ins_next
    |
    |4:  // Check for __newindex if previous value is nil.
    |  beqz TAB:TMP0, <2		// No metatable: done.
    |.  nop
    |  lbu TMP0, TAB:TMP0->nomm
    |  andi TMP0, TMP0, 1<<MM_newindex
    |  bnez TMP0, <2			// 'no __newindex' flag set: done.
    |.  nop
    |  b ->vmeta_tsets
    |.  nop
    |
    |5:  // Follow hash chain.
    |  bnez NODE:TMP1, <1
    |.  move NODE:TMP2, NODE:TMP1
    |  // End of hash chain: key not found, add a new one
    |
    |  // But check for __newindex first.
    |  ld TAB:TMP2, TAB:RB->metatable
    |  beqz TAB:TMP2, >6		// No metatable: continue.
    |.  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
    |  lbu TMP0, TAB:TMP2->nomm
    |  andi TMP0, TMP0, 1<<MM_newindex
    |  beqz TMP0, ->vmeta_tsets		// 'no __newindex' flag NOT set: check.
    |6:
    |  load_got lj_tab_newkey
    |  sd RC, 0(CARG3)
    |   sd BASE, L->base
    |  move CARG2, TAB:RB
    |   sd PC, SAVE_PC
    |  call_intern lj_tab_newkey	// (lua_State *L, GCtab *t, TValue *k
    |.  move CARG1, L
    |  // Returns TValue *.
    |  ld BASE, L->base
    |.if FPU
    |  b <3				// No 2nd write barrier needed.
    |.  sdc1 f20, 0(CRET1)
    |.else
    |  ld CARG1, 0(RA)
    |  b <3				// No 2nd write barrier needed.
    |.  sd CARG1, 0(CRET1)
    |.endif
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMP3, TMP0, <3
    break;
  case BC_TSETB:
    |  // RA = src*8, RB = table*8, RC = index*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |  daddu CARG2, BASE, RB
    |   decode_RDtoRC8 RC, RD
    |  ld TAB:RB, 0(CARG2)
    |   daddu RA, BASE, RA
    |  srl TMP0, RC, 3
    |  checktab RB, ->vmeta_tsetb
    |  lw TMP1, TAB:RB->asize
    |   ld TMP2, TAB:RB->array
    |  sltu AT, TMP0, TMP1
    |  beqz AT, ->vmeta_tsetb
    |.  daddu RC, TMP2, RC
    |  ld TMP1, 0(RC)
    |   lbu TMP3, TAB:RB->marked
    |  beq TMP1, TISNIL, >5
    |1:
    |.  ld CRET1, 0(RA)
    |  andi AT, TMP3, LJ_GC_BLACK	// isblack(table)
    |  bnez AT, >7
    |.   sd CRET1, 0(RC)
    |2:
    |  ins_next
    |
    |5:  // Check for __newindex if previous value is nil.
    |  ld TAB:TMP2, TAB:RB->metatable
    |  beqz TAB:TMP2, <1		// No metatable: done.
    |.  nop
    |  lbu TMP1, TAB:TMP2->nomm
    |  andi TMP1, TMP1, 1<<MM_newindex
    |  bnez TMP1, <1			// 'no __newindex' flag set: done.
    |.  nop
    |  b ->vmeta_tsetb			// Caveat: preserve TMP0 and CARG2!
    |.  nop
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMP3, TMP0, <2
    break;
  case BC_TSETR:
    |  // RA = dst*8, RB = table*8, RC = key*8
    |  decode_RB8a RB, INS
    |  decode_RB8b RB
    |   decode_RDtoRC8 RC, RD
    |  daddu CARG1, BASE, RB
    |   daddu CARG3, BASE, RC
    |  ld TAB:CARG2, 0(CARG1)
    |   lw CARG3, LO(CARG3)
    |  cleartp TAB:CARG2
    |  lbu TMP3, TAB:CARG2->marked
    |   lw TMP0, TAB:CARG2->asize
    |    ld TMP1, TAB:CARG2->array
    |  andi AT, TMP3, LJ_GC_BLACK	// isblack(table)
    |  bnez AT, >7
    |.  daddu RA, BASE, RA
    |2:
    |  sltu AT, CARG3, TMP0
    |   sll TMP2, CARG3, 3
    |  beqz AT, ->vmeta_tsetr		// In array part?
    |.  daddu CRET1, TMP1, TMP2
    |->BC_TSETR_Z:
    |  ld CARG1, 0(RA)
    |  ins_next1
    |  sd CARG1, 0(CRET1)
    |  ins_next2
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:CARG2, TMP3, TMP0, <2
    break;

  case BC_TSETM:
    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)
    |  daddu RA, BASE, RA
    |1:
    |   daddu TMP3, KBASE, RD
    |  ld TAB:CARG2, -8(RA)		// Guaranteed to be a table.
    |    addiu TMP0, MULTRES, -8
    |   lw TMP3, LO(TMP3)		// Integer constant is in lo-word.
    |    beqz TMP0, >4			// Nothing to copy?
    |.    srl CARG3, TMP0, 3
    |  cleartp CARG2
    |  addu CARG3, CARG3, TMP3
    |  lw TMP2, TAB:CARG2->asize
    |   sll TMP1, TMP3, 3
    |    lbu TMP3, TAB:CARG2->marked
    |   ld CARG1, TAB:CARG2->array
    |  sltu AT, TMP2, CARG3
    |  bnez AT, >5
    |.  daddu TMP2, RA, TMP0
    |   daddu TMP1, TMP1, CARG1
    |  andi TMP0, TMP3, LJ_GC_BLACK	// isblack(table)
    |3:  // Copy result slots to table.
    |   ld CRET1, 0(RA)
    |    daddiu RA, RA, 8
    |  sltu AT, RA, TMP2
    |   sd CRET1, 0(TMP1)
    |  bnez AT, <3
    |.   daddiu TMP1, TMP1, 8
    |  bnez TMP0, >7
    |.  nop
    |4:
    |  ins_next
    |
    |5:  // Need to resize array part.
    |  load_got lj_tab_reasize
    |   sd BASE, L->base
    |   sd PC, SAVE_PC
    |  move BASE, RD
    |  call_intern lj_tab_reasize	// (lua_State *L, GCtab *t, int nasize)
    |.  move CARG1, L
    |  // Must not reallocate the stack.
    |  move RD, BASE
    |  b <1
    |.  ld BASE, L->base	// Reload BASE for lack of a saved register.
    |
    |7:  // Possible table write barrier for any value. Skip valiswhite check.
    |  barrierback TAB:CARG2, TMP3, TMP0, <4
    break;

  /* -- Calls and vararg handling ----------------------------------------- */

  case BC_CALLM:
    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
    |  decode_RDtoRC8 NARGS8:RC, RD
    |  b ->BC_CALL_Z
    |.  addu NARGS8:RC, NARGS8:RC, MULTRES
    break;
  case BC_CALL:
    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
    |  decode_RDtoRC8 NARGS8:RC, RD
    |->BC_CALL_Z:
    |  move TMP2, BASE
    |  daddu BASE, BASE, RA
    |   ld LFUNC:RB, 0(BASE)
    |   daddiu BASE, BASE, 16
    |  addiu NARGS8:RC, NARGS8:RC, -8
    |  checkfunc RB, ->vmeta_call
    |  ins_call
    break;

  case BC_CALLMT:
    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8
    |  addu NARGS8:RD, NARGS8:RD, MULTRES	// BC_CALLT gets RC from RD.
    |  // Fall through. Assumes BC_CALLT follows.
    break;
  case BC_CALLT:
    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8
    |  daddu RA, BASE, RA
    |  ld RB, 0(RA)
    |   move NARGS8:RC, RD
    |    ld TMP1, FRAME_PC(BASE)
    |   daddiu RA, RA, 16
    |  addiu NARGS8:RC, NARGS8:RC, -8
    |  checktp CARG3, RB, -LJ_TFUNC, ->vmeta_callt
    |->BC_CALLT_Z:
    |  andi TMP0, TMP1, FRAME_TYPE	// Caveat: preserve TMP0 until the 'or'.
    |   lbu TMP3, LFUNC:CARG3->ffid
    |  bnez TMP0, >7
    |.  xori TMP2, TMP1, FRAME_VARG
    |1:
    |  sd RB, FRAME_FUNC(BASE)		// Copy function down, but keep PC.
    |  sltiu AT, TMP3, 2		// (> FF_C) Calling a fast function?
    |  move TMP2, BASE
    |  move RB, CARG3
    |  beqz NARGS8:RC, >3
    |.  move TMP3, NARGS8:RC
    |2:
    |   ld CRET1, 0(RA)
    |    daddiu RA, RA, 8
    |  addiu TMP3, TMP3, -8
    |   sd CRET1, 0(TMP2)
    |  bnez TMP3, <2
    |.   daddiu TMP2, TMP2, 8
    |3:
    |  or TMP0, TMP0, AT
    |  beqz TMP0, >5
    |.  nop
    |4:
    |  ins_callt
    |
    |5:  // Tailcall to a fast function with a Lua frame below.
    |  lw INS, -4(TMP1)
    |  decode_RA8a RA, INS
    |  decode_RA8b RA
    |  dsubu TMP1, BASE, RA
    |  ld TMP1, -32(TMP1)
    |  cleartp LFUNC:TMP1
    |  ld TMP1, LFUNC:TMP1->pc
    |  b <4
    |.  ld KBASE, PC2PROTO(k)(TMP1)	// Need to prepare KBASE.
    |
    |7:  // Tailcall from a vararg function.
    |  andi AT, TMP2, FRAME_TYPEP
    |  bnez AT, <1			// Vararg frame below?
    |.  dsubu TMP2, BASE, TMP2		// Relocate BASE down.
    |  move BASE, TMP2
    |  ld TMP1, FRAME_PC(TMP2)
    |  b <1
    |.  andi TMP0, TMP1, FRAME_TYPE
    break;

  case BC_ITERC:
    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
    |  move TMP2, BASE			// Save old BASE fir vmeta_call.
    |  daddu BASE, BASE, RA
    |  ld RB, -24(BASE)
    |   ld CARG1, -16(BASE)
    |    ld CARG2, -8(BASE)
    |  li NARGS8:RC, 16			// Iterators get 2 arguments.
    |  sd RB, 0(BASE)			// Copy callable.
    |   sd CARG1, 16(BASE)		// Copy state.
    |    sd CARG2, 24(BASE)		// Copy control var.
    |   daddiu BASE, BASE, 16
    |  checkfunc RB, ->vmeta_call
    |  ins_call
    break;

  case BC_ITERN:
    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
    |.if JIT
    |  // NYI: add hotloop, record BC_ITERN.
    |.endif
    |  daddu RA, BASE, RA
    |  ld TAB:RB, -16(RA)
    |   lw RC, -8+LO(RA)		// Get index from control var.
    |  cleartp TAB:RB
    |   daddiu PC, PC, 4
    |  lw TMP0, TAB:RB->asize
    |   ld TMP1, TAB:RB->array
    |  dsll CARG3, TISNUM, 47
    |1:  // Traverse array part.
    |  sltu AT, RC, TMP0
    |  beqz AT, >5			// Index points after array part?
    |.  sll TMP3, RC, 3
    |  daddu TMP3, TMP1, TMP3
    |  ld CARG1, 0(TMP3)
    |     lhu RD, -4+OFS_RD(PC)
    |   or TMP2, RC, CARG3
    |  beq CARG1, TISNIL, <1		// Skip holes in array part.
    |.  addiu RC, RC, 1
    |   sd TMP2, 0(RA)
    |  sd CARG1, 8(RA)
    |   or TMP0, RC, CARG3
    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |     decode_RD4b RD
    |     daddu RD, RD, TMP3
    |   sw TMP0, -8+LO(RA)		// Update control var.
    |     daddu PC, PC, RD
    |3:
    |  ins_next
    |
    |5:  // Traverse hash part.
    |  lw TMP1, TAB:RB->hmask
    |  subu RC, RC, TMP0
    |   ld TMP2, TAB:RB->node
    |6:
    |  sltu AT, TMP1, RC		// End of iteration? Branch to ITERL+1.
    |  bnez AT, <3
    |.  sll TMP3, RC, 5
    |   sll RB, RC, 3
    |   subu TMP3, TMP3, RB
    |  daddu NODE:TMP3, TMP3, TMP2
    |  ld CARG1, 0(NODE:TMP3)
    |     lhu RD, -4+OFS_RD(PC)
    |  beq CARG1, TISNIL, <6		// Skip holes in hash part.
    |.  addiu RC, RC, 1
    |  ld CARG2, NODE:TMP3->key
    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
    |  sd CARG1, 8(RA)
    |    addu RC, RC, TMP0
    |     decode_RD4b RD
    |     addu RD, RD, TMP3
    |  sd CARG2, 0(RA)
    |     daddu PC, PC, RD
    |  b <3
    |.  sw RC, -8+LO(RA)		// Update control var.
    break;

  case BC_ISNEXT:
    |  // RA = base*8, RD = target (points to ITERN)
    |  daddu RA, BASE, RA
    |    srl TMP0, RD, 1
    |  ld CFUNC:CARG1, -24(RA)
    |    daddu TMP0, PC, TMP0
    |   ld CARG2, -16(RA)
    |   ld CARG3, -8(RA)
    |    lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)
    |  checkfunc CFUNC:CARG1, >5
    |  gettp CARG2, CARG2
    |  daddiu CARG2, CARG2, -LJ_TTAB
    |  lbu TMP1, CFUNC:CARG1->ffid
    |  daddiu CARG3, CARG3, -LJ_TNIL
    |  or AT, CARG2, CARG3
    |  daddiu TMP1, TMP1, -FF_next_N
    |  or AT, AT, TMP1
    |  bnez AT, >5
    |.  lui TMP1, 0xfffe
    |  daddu PC, TMP0, TMP2
    |  ori TMP1, TMP1, 0x7fff
    |  dsll TMP1, TMP1, 32
    |  sd TMP1, -8(RA)
    |1:
    |  ins_next
    |5:  // Despecialize bytecode if any of the checks fail.
    |  li TMP3, BC_JMP
    |   li TMP1, BC_ITERC
    |  sb TMP3, -4+OFS_OP(PC)
    |   daddu PC, TMP0, TMP2
    |  b <1
    |.  sb TMP1, OFS_OP(PC)
    break;

  case BC_VARG:
    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
    |  ld TMP0, FRAME_PC(BASE)
    |  decode_RDtoRC8 RC, RD
    |   decode_RB8a RB, INS
    |  daddu RC, BASE, RC
    |   decode_RB8b RB
    |   daddu RA, BASE, RA
    |  daddiu RC, RC, FRAME_VARG
    |   daddu TMP2, RA, RB
    |  daddiu TMP3, BASE, -16		// TMP3 = vtop
    |  dsubu RC, RC, TMP0		// RC = vbase
    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.
    |  beqz RB, >5			// Copy all varargs?
    |.  dsubu TMP1, TMP3, RC
    |  daddiu TMP2, TMP2, -16
    |1:  // Copy vararg slots to destination slots.
    |  ld CARG1, 0(RC)
    |  sltu AT, RC, TMP3
    |    daddiu RC, RC, 8
    |  movz CARG1, TISNIL, AT
    |  sd CARG1, 0(RA)
    |  sltu AT, RA, TMP2
    |  bnez AT, <1
    |.   daddiu RA, RA, 8
    |3:
    |  ins_next
    |
    |5:  // Copy all varargs.
    |  ld TMP0, L->maxstack
    |  blez TMP1, <3			// No vararg slots?
    |.  li MULTRES, 8			// MULTRES = (0+1)*8
    |  daddu TMP2, RA, TMP1
    |  sltu AT, TMP0, TMP2
    |  bnez AT, >7
    |.  daddiu MULTRES, TMP1, 8
    |6:
    |  ld CRET1, 0(RC)
    |   daddiu RC, RC, 8
    |  sd CRET1, 0(RA)
    |  sltu AT, RC, TMP3
    |  bnez AT, <6			// More vararg slots?
    |.  daddiu RA, RA, 8
    |  b <3
    |.  nop
    |
    |7:  // Grow stack for varargs.
    |  load_got lj_state_growstack
    |   sd RA, L->top
    |  dsubu RA, RA, BASE
    |   sd BASE, L->base
    |  dsubu BASE, RC, BASE		// Need delta, because BASE may change.
    |   sd PC, SAVE_PC
    |  srl CARG2, TMP1, 3
    |  call_intern lj_state_growstack	// (lua_State *L, int n)
    |.  move CARG1, L
    |  move RC, BASE
    |  ld BASE, L->base
    |  daddu RA, BASE, RA
    |  daddu RC, BASE, RC
    |  b <6
    |.  daddiu TMP3, BASE, -16
    break;

  /* -- Returns ----------------------------------------------------------- */

  case BC_RETM:
    |  // RA = results*8, RD = extra_nresults*8
    |  addu RD, RD, MULTRES		// MULTRES >= 8, so RD >= 8.
    |  // Fall through. Assumes BC_RET follows.
    break;

  case BC_RET:
    |  // RA = results*8, RD = (nresults+1)*8
    |  ld PC, FRAME_PC(BASE)
    |   daddu RA, BASE, RA
    |    move MULTRES, RD
    |1:
    |  andi TMP0, PC, FRAME_TYPE
    |  bnez TMP0, ->BC_RETV_Z
    |.  xori TMP1, PC, FRAME_VARG
    |
    |->BC_RET_Z:
    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
    |   lw INS, -4(PC)
    |    daddiu TMP2, BASE, -16
    |    daddiu RC, RD, -8
    |  decode_RA8a TMP0, INS
    |   decode_RB8a RB, INS
    |  decode_RA8b TMP0
    |   decode_RB8b RB
    |   daddu TMP3, TMP2, RB
    |  beqz RC, >3
    |.  dsubu BASE, TMP2, TMP0
    |2:
    |   ld CRET1, 0(RA)
    |    daddiu RA, RA, 8
    |  daddiu RC, RC, -8
    |   sd CRET1, 0(TMP2)
    |  bnez RC, <2
    |.   daddiu TMP2, TMP2, 8
    |3:
    |  daddiu TMP3, TMP3, -8
    |5:
    |  sltu AT, TMP2, TMP3
    |  bnez AT, >6
    |.  ld LFUNC:TMP1, FRAME_FUNC(BASE)
    |  ins_next1
    |  cleartp LFUNC:TMP1
    |  ld TMP1, LFUNC:TMP1->pc
    |  ld KBASE, PC2PROTO(k)(TMP1)
    |  ins_next2
    |
    |6:  // Fill up results with nil.
    |  sd TISNIL, 0(TMP2)
    |  b <5
    |.  daddiu TMP2, TMP2, 8
    |
    |->BC_RETV_Z:  // Non-standard return case.
    |  andi TMP2, TMP1, FRAME_TYPEP
    |  bnez TMP2, ->vm_return
    |.  nop
    |  // Return from vararg function: relocate BASE down.
    |  dsubu BASE, BASE, TMP1
    |  b <1
    |.  ld PC, FRAME_PC(BASE)
    break;

  case BC_RET0: case BC_RET1:
    |  // RA = results*8, RD = (nresults+1)*8
    |  ld PC, FRAME_PC(BASE)
    |   daddu RA, BASE, RA
    |    move MULTRES, RD
    |  andi TMP0, PC, FRAME_TYPE
    |  bnez TMP0, ->BC_RETV_Z
    |.  xori TMP1, PC, FRAME_VARG
    |  lw INS, -4(PC)
    |   daddiu TMP2, BASE, -16
    if (op == BC_RET1) {
      |  ld CRET1, 0(RA)
    }
    |  decode_RB8a RB, INS
    |   decode_RA8a RA, INS
    |  decode_RB8b RB
    |   decode_RA8b RA
    |   dsubu BASE, TMP2, RA
    if (op == BC_RET1) {
      |  sd CRET1, 0(TMP2)
    }
    |5:
    |  sltu AT, RD, RB
    |  bnez AT, >6
    |.  ld TMP1, FRAME_FUNC(BASE)
    |  ins_next1
    |  cleartp LFUNC:TMP1
    |  ld TMP1, LFUNC:TMP1->pc
    |  ld KBASE, PC2PROTO(k)(TMP1)
    |  ins_next2
    |
    |6:  // Fill up results with nil.
    |  daddiu TMP2, TMP2, 8
    |  daddiu RD, RD, 8
    |  b <5
    if (op == BC_RET1) {
      |.  sd TISNIL, 0(TMP2)
    } else {
      |.  sd TISNIL, -8(TMP2)
    }
    break;

  /* -- Loops and branches ------------------------------------------------ */

  case BC_FORL:
    |.if JIT
    |  hotloop
    |.endif
    |  // Fall through. Assumes BC_IFORL follows.
    break;

  case BC_JFORI:
  case BC_JFORL:
#if !LJ_HASJIT
    break;
#endif
  case BC_FORI:
  case BC_IFORL:
    |  // RA = base*8, RD = target (after end of loop or start of loop)
    vk = (op == BC_IFORL || op == BC_JFORL);
    |  daddu RA, BASE, RA
    |  ld CARG1, FORL_IDX*8(RA)		// IDX CARG1 - CARG3 type
    |  gettp CARG3, CARG1
    if (op != BC_JFORL) {
      |  srl RD, RD, 1
      |  lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)
      |  daddu TMP2, RD, TMP2
    }
    if (!vk) {
      |  ld CARG2, FORL_STOP*8(RA)	// STOP CARG2 - CARG4 type
      |  ld CRET1, FORL_STEP*8(RA)	// STEP CRET1 - CRET2 type
      |  gettp CARG4, CARG2
      |  bne CARG3, TISNUM, >5
      |.  gettp CRET2, CRET1
      |  bne CARG4, TISNUM, ->vmeta_for
      |.  sextw CARG3, CARG1
      |  bne CRET2, TISNUM, ->vmeta_for
      |.  sextw CARG2, CARG2
      |  dext AT, CRET1, 31, 0
      |  slt CRET1, CARG2, CARG3
      |  slt TMP1, CARG3, CARG2
      |  movn CRET1, TMP1, AT
    } else {
      |  bne CARG3, TISNUM, >5
      |.  ld CARG2, FORL_STEP*8(RA)	// STEP CARG2 - CARG4 type
      |    ld CRET1, FORL_STOP*8(RA)	// STOP CRET1 - CRET2 type
      |  sextw TMP3, CARG1
      |   sextw CARG2, CARG2
      |    sextw CRET1, CRET1
      |  addu CARG1, TMP3, CARG2
      |  xor TMP0, CARG1, TMP3
      |  xor TMP1, CARG1, CARG2
      |  and TMP0, TMP0, TMP1
      |  slt TMP1, CARG1, CRET1
      |  slt CRET1, CRET1, CARG1
      |  slt AT, CARG2, r0
      |   slt TMP0, TMP0, r0		// ((y^a) & (y^b)) < 0: overflow.
      |  movn CRET1, TMP1, AT
      |   or CRET1, CRET1, TMP0
      |  zextw CARG1, CARG1
      |  settp CARG1, TISNUM
    }
    |1:
    if (op == BC_FORI) {
      |  movz TMP2, r0, CRET1
      |  daddu PC, PC, TMP2
    } else if (op == BC_JFORI) {
      |  daddu PC, PC, TMP2
      |  lhu RD, -4+OFS_RD(PC)
    } else if (op == BC_IFORL) {
      |  movn TMP2, r0, CRET1
      |  daddu PC, PC, TMP2
    }
    if (vk) {
      |  sd CARG1, FORL_IDX*8(RA)
    }
    |  ins_next1
    |  sd CARG1, FORL_EXT*8(RA)
    |2:
    if (op == BC_JFORI) {
      |  beqz CRET1, =>BC_JLOOP
      |.  decode_RD8b RD
    } else if (op == BC_JFORL) {
      |  beqz CRET1, =>BC_JLOOP
    }
    |  ins_next2
    |
    |5:  // FP loop.
    |.if FPU
    if (!vk) {
      |  ldc1 f0, FORL_IDX*8(RA)
      |   ldc1 f2, FORL_STOP*8(RA)
      |  sltiu TMP0, CARG3, LJ_TISNUM
      |  sltiu TMP1, CARG4, LJ_TISNUM
      |  sltiu AT, CRET2, LJ_TISNUM
      |   ld TMP3, FORL_STEP*8(RA)
      |  and TMP0, TMP0, TMP1
      |  and AT, AT, TMP0
      |  beqz AT, ->vmeta_for
      |.  slt TMP3, TMP3, r0
      |  c.ole.d 0, f0, f2
      |  c.ole.d 1, f2, f0
      |  li CRET1, 1
      |  movt CRET1, r0, 0
      |  movt AT, r0, 1
      |  b <1
      |.  movn CRET1, AT, TMP3
    } else {
      |  ldc1 f0, FORL_IDX*8(RA)
      |   ldc1 f4, FORL_STEP*8(RA)
      |    ldc1 f2, FORL_STOP*8(RA)
      |   ld TMP3, FORL_STEP*8(RA)
      |  add.d f0, f0, f4
      |  c.ole.d 0, f0, f2
      |  c.ole.d 1, f2, f0
      |   slt TMP3, TMP3, r0
      |  li CRET1, 1
      |  li AT, 1
      |  movt CRET1, r0, 0
      |  movt AT, r0, 1
      |  movn CRET1, AT, TMP3
      if (op == BC_IFORL) {
	|  movn TMP2, r0, CRET1
	|  daddu PC, PC, TMP2
      }
      |  sdc1 f0, FORL_IDX*8(RA)
      |  ins_next1
      |  b <2
      |.  sdc1 f0, FORL_EXT*8(RA)
    }
    |.else
    if (!vk) {
      |  sltiu TMP0, CARG3, LJ_TISNUM
      |  sltiu TMP1, CARG4, LJ_TISNUM
      |  sltiu AT, CRET2, LJ_TISNUM
      |  and TMP0, TMP0, TMP1
      |  and AT, AT, TMP0
      |  beqz AT, ->vmeta_for
      |.  nop
      |  bal ->vm_sfcmpolex
      |.  lw TMP3, FORL_STEP*8+HI(RA)
      |  b <1
      |.  nop
    } else {
      |  load_got __adddf3
      |  call_extern
      |.  sw TMP2, TMPD
      |  ld CARG2, FORL_STOP*8(RA)
      |  move CARG1, CRET1
      if ( op == BC_JFORL ) {
	|  lhu RD, -4+OFS_RD(PC)
	|  decode_RD8b RD
      }
      |  bal ->vm_sfcmpolex
      |.  lw TMP3, FORL_STEP*8+HI(RA)
      |  b <1
      |.  lw TMP2, TMPD
    }
    |.endif
    break;

  case BC_ITERL:
    |.if JIT
    |  hotloop
    |.endif
    |  // Fall through. Assumes BC_IITERL follows.
    break;

  case BC_JITERL:
#if !LJ_HASJIT
    break;
#endif
  case BC_IITERL:
    |  // RA = base*8, RD = target
    |  daddu RA, BASE, RA
    |  ld TMP1, 0(RA)
    |  beq TMP1, TISNIL, >1		// Stop if iterator returned nil.
    |.  nop
    if (op == BC_JITERL) {
      |  b =>BC_JLOOP
      |.  sd TMP1, -8(RA)
    } else {
      |  branch_RD			// Otherwise save control var + branch.
      |  sd TMP1, -8(RA)
    }
    |1:
    |  ins_next
    break;

  case BC_LOOP:
    |  // RA = base*8, RD = target (loop extent)
    |  // Note: RA/RD is only used by trace recorder to determine scope/extent
    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.
    |.if JIT
    |  hotloop
    |.endif
    |  // Fall through. Assumes BC_ILOOP follows.
    break;

  case BC_ILOOP:
    |  // RA = base*8, RD = target (loop extent)
    |  ins_next
    break;

  case BC_JLOOP:
    |.if JIT
    |  // RA = base*8 (ignored), RD = traceno*8
    |  ld TMP1, DISPATCH_J(trace)(DISPATCH)
    |   li AT, 0
    |  daddu TMP1, TMP1, RD
    |  // Traces on MIPS don't store the trace number, so use 0.
    |   sd AT, DISPATCH_GL(vmstate)(DISPATCH)
    |  ld TRACE:TMP2, 0(TMP1)
    |   sd BASE, DISPATCH_GL(jit_base)(DISPATCH)
    |  ld TMP2, TRACE:TMP2->mcode
    |   sd L, DISPATCH_GL(tmpbuf.L)(DISPATCH)
    |  jr TMP2
    |.  daddiu JGL, DISPATCH, GG_DISP2G+32768
    |.endif
    break;

  case BC_JMP:
    |  // RA = base*8 (only used by trace recorder), RD = target
    |  branch_RD
    |  ins_next
    break;

  /* -- Function headers -------------------------------------------------- */

  case BC_FUNCF:
    |.if JIT
    |  hotcall
    |.endif
  case BC_FUNCV:  /* NYI: compiled vararg functions. */
    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
    break;

  case BC_JFUNCF:
#if !LJ_HASJIT
    break;
#endif
  case BC_IFUNCF:
    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
    |  ld TMP2, L->maxstack
    |   lbu TMP1, -4+PC2PROTO(numparams)(PC)
    |    ld KBASE, -4+PC2PROTO(k)(PC)
    |  sltu AT, TMP2, RA
    |  bnez AT, ->vm_growstack_l
    |.  sll TMP1, TMP1, 3
    if (op != BC_JFUNCF) {
      |  ins_next1
    }
    |2:
    |  sltu AT, NARGS8:RC, TMP1		// Check for missing parameters.
    |  bnez AT, >3
    |.  daddu AT, BASE, NARGS8:RC
    if (op == BC_JFUNCF) {
      |  decode_RD8a RD, INS
      |  b =>BC_JLOOP
      |.  decode_RD8b RD
    } else {
      |  ins_next2
    }
    |
    |3:  // Clear missing parameters.
    |  sd TISNIL, 0(AT)
    |  b <2
    |.  addiu NARGS8:RC, NARGS8:RC, 8
    break;

  case BC_JFUNCV:
#if !LJ_HASJIT
    break;
#endif
    |  NYI  // NYI: compiled vararg functions
    break;  /* NYI: compiled vararg functions. */

  case BC_IFUNCV:
    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
    |   li TMP0, LJ_TFUNC
    |   daddu TMP1, BASE, RC
    |  ld TMP2, L->maxstack
    |   settp LFUNC:RB, TMP0
    |  daddu TMP0, RA, RC
    |   sd LFUNC:RB, 0(TMP1)		// Store (tagged) copy of LFUNC.
    |   daddiu TMP3, RC, 16+FRAME_VARG
    |  sltu AT, TMP0, TMP2
    |    ld KBASE, -4+PC2PROTO(k)(PC)
    |  beqz AT, ->vm_growstack_l
    |.  sd TMP3, 8(TMP1)		// Store delta + FRAME_VARG.
    |  lbu TMP2, -4+PC2PROTO(numparams)(PC)
    |   move RA, BASE
    |   move RC, TMP1
    |  ins_next1
    |  beqz TMP2, >3
    |.  daddiu BASE, TMP1, 16
    |1:
    |  ld TMP0, 0(RA)
    |  sltu AT, RA, RC			// Less args than parameters?
    |  move CARG1, TMP0
    |  movz TMP0, TISNIL, AT		// Clear missing parameters.
    |  movn CARG1, TISNIL, AT		// Clear old fixarg slot (help the GC).
    |    addiu TMP2, TMP2, -1
    |  sd TMP0, 16(TMP1)
    |    daddiu TMP1, TMP1, 8
    |  sd CARG1, 0(RA)
    |  bnez TMP2, <1
    |.   daddiu RA, RA, 8
    |3:
    |  ins_next2
    break;

  case BC_FUNCC:
  case BC_FUNCCW:
    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
    if (op == BC_FUNCC) {
      |  ld CFUNCADDR, CFUNC:RB->f
    } else {
      |  ld CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)
    }
    |  daddu TMP1, RA, NARGS8:RC
    |  ld TMP2, L->maxstack
    |   daddu RC, BASE, NARGS8:RC
    |  sd BASE, L->base
    |  sltu AT, TMP2, TMP1
    |   sd RC, L->top
    |    li_vmstate C
    if (op == BC_FUNCCW) {
      |  ld CARG2, CFUNC:RB->f
    }
    |  bnez AT, ->vm_growstack_c	// Need to grow stack.
    |.  move CARG1, L
    |  jalr CFUNCADDR			// (lua_State *L [, lua_CFunction f])
    |.   st_vmstate
    |  // Returns nresults.
    |  ld BASE, L->base
    |   sll RD, CRET1, 3
    |  ld TMP1, L->top
    |    li_vmstate INTERP
    |  ld PC, FRAME_PC(BASE)		// Fetch PC of caller.
    |   dsubu RA, TMP1, RD		// RA = L->top - nresults*8
    |    sd L, DISPATCH_GL(cur_L)(DISPATCH)
    |  b ->vm_returnc
    |.   st_vmstate
    break;

  /* ---------------------------------------------------------------------- */

  default:
    fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
    exit(2);
    break;
  }
}

static int build_backend(BuildCtx *ctx)
{
  int op;

  dasm_growpc(Dst, BC__MAX);

  build_subroutines(ctx);

  |.code_op
  for (op = 0; op < BC__MAX; op++)
    build_ins(ctx, (BCOp)op, op);

  return BC__MAX;
}

/* Emit pseudo frame-info for all assembler functions. */
static void emit_asm_debug(BuildCtx *ctx)
{
  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
  int i;
  switch (ctx->mode) {
  case BUILD_elfasm:
    fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
    fprintf(ctx->fp,
	".Lframe0:\n"
	"\t.4byte .LECIE0-.LSCIE0\n"
	".LSCIE0:\n"
	"\t.4byte 0xffffffff\n"
	"\t.byte 0x1\n"
	"\t.string \"\"\n"
	"\t.uleb128 0x1\n"
	"\t.sleb128 -4\n"
	"\t.byte 31\n"
	"\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
	"\t.align 2\n"
	".LECIE0:\n\n");
    fprintf(ctx->fp,
	".LSFDE0:\n"
	"\t.4byte .LEFDE0-.LASFDE0\n"
	".LASFDE0:\n"
	"\t.4byte .Lframe0\n"
	"\t.8byte .Lbegin\n"
	"\t.8byte %d\n"
	"\t.byte 0xe\n\t.uleb128 %d\n"
	"\t.byte 0x9f\n\t.sleb128 2*5\n"
	"\t.byte 0x9e\n\t.sleb128 2*6\n",
	fcofs, CFRAME_SIZE);
    for (i = 23; i >= 16; i--)
      fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2*(30-i));
#if !LJ_SOFTFP
    for (i = 31; i >= 24; i--)
      fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 2*(46-i));
#endif
    fprintf(ctx->fp,
	"\t.align 2\n"
	".LEFDE0:\n\n");
#if LJ_HASFFI
    fprintf(ctx->fp,
	".LSFDE1:\n"
	"\t.4byte .LEFDE1-.LASFDE1\n"
	".LASFDE1:\n"
	"\t.4byte .Lframe0\n"
	"\t.4byte lj_vm_ffi_call\n"
	"\t.4byte %d\n"
	"\t.byte 0x9f\n\t.uleb128 2*1\n"
	"\t.byte 0x90\n\t.uleb128 2*2\n"
	"\t.byte 0xd\n\t.uleb128 0x10\n"
	"\t.align 2\n"
	".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
#endif
#if !LJ_NO_UNWIND
    /* NYI */
#endif
    break;
  default:
    break;
  }
}