summaryrefslogtreecommitdiff
path: root/ThirdParty/tolua_runtime/luajit-2.1/src/vm_s390x.dasc
blob: a107be2462f288bbcfb4a385243e106dd2f6625a (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
|// Low-level VM code for IBM z/Architecture (s390x) CPUs in LJ_GC64 mode.
|// Bytecode interpreter, fast functions and helper functions.
|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
|
|// This assembly targets the instruction set available on z10 (and newer)
|// machines.
|
|// ELF ABI registers:
|// r0,r1       |                            | volatile |
|// r2          | parameter and return value | volatile |
|// r3-r5       | parameter                  | volatile |
|// r6          | parameter                  | saved    |
|// r7-r11      |                            | saved    |
|// r12         | GOT pointer (needed?)      | saved    |
|// r13         | literal pool (not needed)  | saved    |
|// r14         | return address             | volatile |
|// r15         | stack pointer              | saved    |
|// f0,f2,f4,f6 | parameter and return value | volatile |
|// f1,f3,f5,f7 |                            | volatile |
|// f8-f15      |                            | saved    |
|// ar0,ar1     | TLS                        | volatile |
|// ar2-ar15    |                            | volatile |
|
|.arch s390x
|.section code_op, code_sub
|
|.actionlist build_actionlist
|.globals GLOB_
|.globalnames globnames
|.externnames extnames
|
|//-----------------------------------------------------------------------
|
|// Fixed register assignments for the interpreter, callee-saved.
|.define KBASE,			r8	// Constants of current Lua function.
|.define PC,			r9	// Next PC.
|.define DISPATCH,		r10	// Opcode dispatch table.
|.define ITYPE,			r11	// Temporary used for type information.
|.define BASE,			r13	// Base of current Lua stack frame.
|
|// The following temporaries are not saved across C calls, except for RB.
|.define RA,			r4	// Overlaps CARG3.
|.define RB,			r7	// Must be callee-save.
|.define RC,			r5	// Overlaps CARG4.
|.define RD,			r6	// Overlaps CARG5.
|
|// Calling conventions. Also used as temporaries.
|.define CARG1,			r2
|.define CARG2,			r3
|.define CARG3,			r4
|.define CARG4,			r5
|.define CARG5,			r6
|
|.define FARG1,			f0
|.define FARG2,			f2
|.define FARG3,			f4
|.define FARG4,			f6
|
|.define CRET1,			r2
|
|.define TMPR0,			r0
|.define TMPR1,			r1
|.define OP,			r2
|
|// Stack layout while in interpreter. Must match with lj_frame.h.
|.define CFRAME_SPACE,	240	// Delta for sp, 8 byte aligned.
|
|// Register save area.
|.define SAVE_GPRS,	288(sp)	// Save area for r6-r15 (10*8 bytes).
|.define SAVE_GPRS_P,	48(sp)  // Save area for r6-r15 (10*8 bytes) in prologue (before stack frame is allocated).
|
|// Argument save area.
|.define SAVE_ERRF,	280(sp) // Argument 4, in r5.
|.define SAVE_NRES,	272(sp)	// Argument 3, in r4. Size is 4-bytes.
|.define SAVE_CFRAME,	264(sp)	// Argument 2, in r3.
|.define SAVE_L,	256(sp)	// Argument 1, in r2.
|.define RESERVED,	248(sp)	// Reserved for compiler use.
|.define BACKCHAIN,	240(sp)	// <- sp entering interpreter.
|
|// Interpreter stack frame.
|.define SAVE_FPR15,	232(sp)
|.define SAVE_FPR14,	224(sp)
|.define SAVE_FPR13,	216(sp)
|.define SAVE_FPR12,	208(sp)
|.define SAVE_FPR11,	200(sp)
|.define SAVE_FPR10,	192(sp)
|.define SAVE_FPR9,	184(sp)
|.define SAVE_FPR8,	176(sp)
|.define SAVE_PC,	168(sp)
|.define SAVE_MULTRES,	160(sp)
|.define SAVE_TMP,	160(sp) // Overlaps SAVE_MULTRES
|.define SAVE_TMP_HI,	164(sp) // High 32-bits (to avoid SAVE_MULTRES).
|
|// Callee save area (allocated by interpreter).
|.define CALLEESAVE,	000(sp) // <- sp in interpreter.
|
|.macro saveregs
|  stmg r6, r15, SAVE_GPRS_P
|  lay sp, -CFRAME_SPACE(sp)	// Allocate stack frame.
|  std f8, SAVE_FPR8		// f8-f15 are callee-saved.
|  std f9, SAVE_FPR9
|  std f10, SAVE_FPR10
|  std f11, SAVE_FPR11
|  std f12, SAVE_FPR12
|  std f13, SAVE_FPR13
|  std f14, SAVE_FPR14
|  std f15, SAVE_FPR15
|.endmacro
|
|.macro restoreregs
|  ld f8, SAVE_FPR8		// f8-f15 are callee-saved.
|  ld f9, SAVE_FPR9
|  ld f10, SAVE_FPR10
|  ld f11, SAVE_FPR11
|  ld f12, SAVE_FPR12
|  ld f13, SAVE_FPR13
|  ld f14, SAVE_FPR14
|  ld f15, SAVE_FPR15
|  lmg r6, r15, SAVE_GPRS	// Restores the stack pointer.
|.endmacro
|
|// Type definitions. Some of these are only used for documentation.
|.type L,		lua_State
|.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 NARGS,		int
|.type TRACE,		GCtrace
|.type SBUF,		SBuf
|
|//-----------------------------------------------------------------------
|
|// Instruction headers.
|.macro ins_A; .endmacro
|.macro ins_AD; .endmacro
|.macro ins_AJ; .endmacro
|.macro ins_ABC; srlg RB, RD, 8; llgcr RC, RD; .endmacro
|.macro ins_AB_; srlg RB, RD, 8; .endmacro
|.macro ins_A_C; llgcr RC, RD; .endmacro
|.macro ins_AND; lghi TMPR1, -1; xgr RD, TMPR1; .endmacro // RD = ~RD
|
|// Instruction decode+dispatch.
|.macro ins_NEXT
|  llgc OP, 3(PC)
|  llgh RD, 0(PC)
|  llgc RA, 2(PC)
|  sllg TMPR1, OP, 3
|  lg TMPR1, 0(TMPR1, DISPATCH)
|  la PC, 4(PC)
|  br TMPR1
|.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
|.else
|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
|  .macro ins_next
|    j ->ins_next
|  .endmacro
|  .macro ins_next_
|  ->ins_next:
|    ins_NEXT
|  .endmacro
|.endif
|
|// Call decode and dispatch.
|.macro ins_callt
|  // BASE = new base, RB = LFUNC, RD = nargs+1, -8(BASE) = PC
|  lg PC, LFUNC:RB->pc
|  llgc OP, 3(PC)
|  llgc RA, 2(PC)
|  sllg TMPR1, OP, 3
|  la PC, 4(PC)
|  lg TMPR1, 0(TMPR1, DISPATCH)
|  br TMPR1
|.endmacro
|
|.macro ins_call
|  // BASE = new base, RB = LFUNC, RD = nargs+1
|  stg PC, -8(BASE)
|  ins_callt
|.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 PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
|
|//-----------------------------------------------------------------------
|
|// Macros to clear or set tags.
|.macro cleartp, reg
|  nihf reg, 0x7fff
|.endmacro
|.macro settp, reg, tp
|  oihf reg, tp<<15
|.endmacro
|.macro settp, dst, reg, tp
|  llihf dst, tp<<15
|  ogr dst, reg
|.endmacro
|.macro setint, reg
|  settp reg, LJ_TISNUM
|.endmacro
|.macro setint, dst, reg
|  settp dst, reg, LJ_TISNUM
|.endmacro
|
|// Macros to test operand types.
|.macro checktp_nc, reg, tp, target
|  srag ITYPE, reg, 47
|  clfi ITYPE, tp
|  jne target
|.endmacro
|.macro checktp, reg, tp, target
|  srag ITYPE, reg, 47
|  cleartp reg
|  clfi ITYPE, tp
|  jne target
|.endmacro
|.macro checktptp, src, tp, target
|  srag ITYPE, src, 47
|  clfi ITYPE, tp
|  jne target
|.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 checknumx, reg, target, jump
|  srag ITYPE, reg, 47
|  clfi ITYPE, LJ_TISNUM
|  jump target
|.endmacro
|.macro checkint, reg, target; checknumx reg, target, jne; .endmacro
|.macro checkinttp, src, target; checknumx src, target, jne; .endmacro
|.macro checknum, reg, target; checknumx reg, target, jhe; .endmacro
|.macro checknumtp, src, target; checknumx src, target, jhe; .endmacro
|.macro checknumber, src, target; checknumx src, target, jh; .endmacro
|
|.macro load_false, reg; lghi reg, -1; iihl reg, 0x7fff; .endmacro	// assumes LJ_TFALSE == ~(1<<47)
|.macro load_true, reg; lghi reg, -1; iihh reg, 0xfffe; .endmacro	// assumes LJ_TTRUE  == ~(2<<47)
|
|.define PC_OP, -1(PC)
|.define PC_RA, -2(PC)
|.define PC_RB, -4(PC)
|.define PC_RC, -3(PC)
|.define PC_RD, -4(PC)
|
|.macro branchPC, reg
|  // Must not clobber condition code.
|  sllg TMPR1, reg, 2
|  lay PC, (-BCBIAS_J*4)(TMPR1, PC)
|.endmacro
|
|// Set current VM state.
|.macro set_vmstate, st
|  lghi TMPR1, ~LJ_VMST_..st
|  stg TMPR1, DISPATCH_GL(vmstate)(DISPATCH)
|.endmacro
|
|// Synthesize binary floating-point constants.
|.macro bfpconst_tobit, reg, tmp	// Synthesize 2^52 + 2^51.
|  llihh tmp, 0x4338
|  ldgr reg, tmp
|.endmacro
|
|// Move table write barrier back. Overwrites reg.
|.macro barrierback, tab, reg
|  ni tab->marked, ~LJ_GC_BLACK // black2gray(tab)
|  lg reg, (DISPATCH_GL(gc.grayagain))(DISPATCH)
|  stg tab, (DISPATCH_GL(gc.grayagain))(DISPATCH)
|  stg reg, tab->gclist
|.endmacro

#if !LJ_DUALNUM
#error "Only dual-number mode supported for s390x target"
#endif

/* 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:
  |  tmll PC, FRAME_P
  |  je ->cont_dispatch
  |
  |  // Return from pcall or xpcall fast func.
  |  nill PC, -8
  |  sgr BASE, PC			// Restore caller base.
  |  lay RA, -8(RA, PC)			// Rebase RA and prepend one result.
  |  lg PC, -8(BASE)			// Fetch PC of previous frame.
  |  // Prepending may overwrite the pcall frame, so do it at the end.
  |  load_true ITYPE
  |  stg ITYPE, 0(RA, BASE)		// Prepend true to results.
  |
  |->vm_returnc:
  |  aghi RD, 1				// RD = nresults+1
  |  je ->vm_unwind_yield
  |  st RD, SAVE_MULTRES
  |  tmll PC, FRAME_TYPE
  |  je ->BC_RET_Z			// Handle regular return to Lua.
  |
  |->vm_return:
  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return
  |  lghi TMPR1, FRAME_C
  |  xgr PC, TMPR1
  |  tmll PC, FRAME_TYPE
  |  jne ->vm_returnp
  |
  |  // Return to C.
  |  set_vmstate C
  |  nill PC, -8
  |  sgr PC, BASE
  |  lcgr PC, PC			// Previous base = BASE - delta.
  |
  |  aghi RD, -1
  |  je >2
  |1:  // Move results down.
  |  lg RB, 0(BASE, RA)
  |  stg RB, -16(BASE)
  |  la BASE, 8(BASE)
  |  aghi RD, -1
  |  jne <1
  |2:
  |  lg L:RB, SAVE_L
  |  stg PC, L:RB->base
  |3:
  |  llgf RD, SAVE_MULTRES
  |  lgf RA, SAVE_NRES			// RA = wanted nresults+1
  |4:
  |  cgr RA, RD
  |  jne >6				// More/less results wanted?
  |5:
  |  lay BASE, -16(BASE)
  |  stg BASE, L:RB->top
  |
  |->vm_leave_cp:
  |  lg RA, SAVE_CFRAME			// Restore previous C frame.
  |  stg RA, L:RB->cframe
  |  lghi CRET1, 0			// Ok return status for vm_pcall.
  |
  |->vm_leave_unw:
  |  restoreregs
  |  br r14
  |
  |6:
  |  jl >7				// Less results wanted?
  |  // More results wanted. Check stack size and fill up results with nil.
  |  cg BASE, L:RB->maxstack
  |  jh >8
  |  lghi TMPR1, LJ_TNIL
  |  stg TMPR1, -16(BASE)
  |  la BASE, 8(BASE)
  |  aghi RD, 1
  |  j <4
  |
  |7:  // Fewer results wanted.
  |  cghi RA, 0
  |  je <5				// But check for LUA_MULTRET+1.
  |  sgr RA, RD				// Negative result!
  |  sllg TMPR1, RA, 3
  |  la BASE, 0(TMPR1, BASE)		// Correct top.
  |  j <5
  |
  |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.
  |  stg BASE, L:RB->top		// Save current top held in BASE (yes).
  |  st RD, SAVE_MULTRES		// Need to fill only remainder with nil.
  |  lgr CARG2, RA
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_state_growstack	// (lua_State *L, int n)
  |  lg BASE, L:RB->top			// Need the (realloced) L->top in BASE.
  |  j <3
  |
  |->vm_unwind_yield:
  |  lghi CRET1, LUA_YIELD
  |  j ->vm_unwind_c_eh
  |
  |->vm_unwind_c:			// Unwind C stack, return from vm_pcall.
  |  // (void *cframe, int errcode)
  |  lgr sp, CARG1
  |  lgfr CARG2, CRET1			// Error return status for vm_pcall.
  |->vm_unwind_c_eh:			// Landing pad for external unwinder.
  |  lg L:RB, SAVE_L
  |  lg GL:RB, L:RB->glref
  |  lghi TMPR1, ~LJ_VMST_C
  |  stg TMPR1, GL:RB->vmstate
  |  j ->vm_leave_unw
  |
  |->vm_unwind_ff:			// Unwind C stack, return from ff pcall.
  |  // (void *cframe)
  |  nill CARG1, CFRAME_RAWMASK		// Assumes high 48-bits set in CFRAME_RAWMASK.
  |  lgr sp, CARG1
  |->vm_unwind_ff_eh:			// Landing pad for external unwinder.
  |  lg L:RB, SAVE_L
  |  lghi RD, 1+1			// Really 1+2 results, incr. later.
  |  lg BASE, L:RB->base
  |  lg DISPATCH, L:RB->glref		// Setup pointer to dispatch table.
  |  la DISPATCH, GG_G2DISP(DISPATCH)
  |  lg PC, -8(BASE)			// Fetch PC of previous frame.
  |  load_false RA
  |  lg RB, 0(BASE)
  |  stg RA, -16(BASE)			// Prepend false to error message.
  |  stg RB, -8(BASE)
  |  lghi RA, -16			// Results start at BASE+RA = BASE-16.
  |  set_vmstate INTERP
  |  j ->vm_returnc			// Increments RD/MULTRES and returns.
  |
  |//-----------------------------------------------------------------------
  |//-- Grow stack for calls -----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_growstack_c:			// Grow stack for C function.
  |  lghi CARG2, LUA_MINSTACK
  |  j >2
  |
  |->vm_growstack_v:			// Grow stack for vararg Lua function.
  |  aghi RD, -16			// LJ_FR2
  |  j >1
  |
  |->vm_growstack_f:			// Grow stack for fixarg Lua function.
  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -8(RD, BASE)
  |1:
  |  llgc RA, (PC2PROTO(framesize)-4)(PC)
  |  la PC, 4(PC)			// Must point after first instruction.
  |  stg BASE, L:RB->base
  |  stg RD, L:RB->top
  |  stg PC, SAVE_PC
  |  lgr CARG2, RA
  |2:
  |  // RB = L, L->base = new base, L->top = top
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_state_growstack	// (lua_State *L, int n)
  |  lg BASE, L:RB->base
  |  lg RD, L:RB->top
  |  lg LFUNC:RB, -16(BASE)
  |  cleartp LFUNC:RB
  |  sgr RD, BASE
  |  srlg RD, RD, 3
  |  aghi NARGS:RD, 1
  |  // BASE = new base, RB = LFUNC, RD = nargs+1
  |  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
  |  lgr L:RB, CARG1
  |  stg CARG1, SAVE_L
  |  lgr RA, CARG2
  |  lghi PC, FRAME_CP
  |  lghi RD, 0
  |  la KBASE, CFRAME_RESUME(sp)
  |  lg DISPATCH, L:RB->glref		// Setup pointer to dispatch table.
  |  aghi DISPATCH, GG_G2DISP
  |  stg RD, SAVE_PC			// Any value outside of bytecode is ok.
  |  stg RD, SAVE_CFRAME
  |  st RD, SAVE_NRES
  |  stg RD, SAVE_ERRF
  |  stg KBASE, L:RB->cframe
  |  clm RD, 1, L:RB->status
  |  je >2				// Initial resume (like a call).
  |
  |  // Resume after yield (like a return).
  |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)
  |  set_vmstate INTERP
  |  stc RD, L:RB->status
  |  lg BASE, L:RB->base
  |  lg RD, L:RB->top
  |  sgr RD, RA
  |  srlg RD, RD, 3
  |  aghi RD, 1				// RD = nresults+1
  |  sgr RA, BASE			// RA = resultofs
  |  lg PC, -8(BASE)
  |  st RD, SAVE_MULTRES
  |  tmll PC, FRAME_TYPE
  |  je ->BC_RET_Z
  |  j ->vm_return
  |
  |->vm_pcall:				// Setup protected C frame and enter VM.
  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
  |  saveregs
  |  lghi PC, FRAME_CP
  |  llgfr CARG4, CARG4
  |  stg CARG4, SAVE_ERRF
  |  j >1
  |
  |->vm_call:				// Setup C frame and enter VM.
  |  // (lua_State *L, TValue *base, int nres1)
  |  saveregs
  |  lghi PC, FRAME_C
  |
  |1:  // Entry point for vm_pcall above (PC = ftype).
  |  st CARG3, SAVE_NRES
  |  lgr L:RB, CARG1
  |  stg CARG1, SAVE_L
  |  lgr RA, CARG2			// Caveat: RA = CARG3.
  |
  |  lg DISPATCH, L:RB->glref		// Setup pointer to dispatch table.
  |  lg KBASE, L:RB->cframe		// Add our C frame to cframe chain.
  |  stg KBASE, SAVE_CFRAME
  |  stg L:RB, SAVE_PC			// Any value outside of bytecode is ok.
  |  aghi DISPATCH, GG_G2DISP
  |  stg sp, L:RB->cframe
  |
  |2: // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).
  |  stg L:RB, DISPATCH_GL(cur_L)(DISPATCH)
  |  set_vmstate INTERP
  |  lg BASE, L:RB->base		// BASE = old base (used in vmeta_call).
  |  agr PC, RA
  |  sgr PC, BASE			// PC = frame delta + frame type
  |
  |  lg RD, L:RB->top
  |  sgr RD, RA
  |  srlg NARGS:RD, NARGS:RD, 3
  |  aghi NARGS:RD, 1			// RD = nargs+1
  |
  |->vm_call_dispatch:
  |  lg LFUNC:RB, -16(RA)
  |  checkfunc LFUNC:RB, ->vmeta_call	// Ensure KBASE defined and != BASE.
  |
  |->vm_call_dispatch_f:
  |  lgr BASE, RA
  |  ins_call
  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC
  |
  |->vm_cpcall:				// Setup protected C frame, call C.
  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
  |  saveregs
  |  lgr L:RB, CARG1
  |  stg L:RB, SAVE_L
  |  stg L:RB, SAVE_PC			// Any value outside of bytecode is ok.
  |
  |  lg KBASE, L:RB->stack		// Compute -savestack(L, L->top).
  |  sg KBASE, L:RB->top
  |   lg DISPATCH, L:RB->glref	// Setup pointer to dispatch table.
  |  lghi TMPR0, 0
  |  stg TMPR0, SAVE_ERRF		// No error function.
  |  st KBASE, SAVE_NRES		// Neg. delta means cframe w/o frame.
  |   aghi DISPATCH, GG_G2DISP
  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).
  |
  |  lg KBASE, L:RB->cframe		// Add our C frame to cframe chain.
  |  stg KBASE, SAVE_CFRAME
  |  stg sp, L:RB->cframe
  |  stg L:RB, DISPATCH_GL(cur_L)(DISPATCH)
  |
  |  basr r14, CARG4			// (lua_State *L, lua_CFunction func, void *ud)
  |  // TValue * (new base) or NULL returned in r2 (CRET1/).
  |  cghi CRET1, 0
  |  je ->vm_leave_cp			// No base? Just remove C frame.
  |  lgr RA, CRET1
  |  lghi PC, FRAME_CP
  |  j <2				// Else continue with the call.
  |
  |//-----------------------------------------------------------------------
  |//-- Metamethod handling ------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |//-- Continuation dispatch ----------------------------------------------
  |
  |->cont_dispatch:
  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)
  |  agr RA, BASE
  |  nill PC, -8
  |  lgr RB, BASE
  |  sgr BASE, PC			// Restore caller BASE.
  |  sllg TMPR1, RD, 3
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, -8(RA, TMPR1)		// Ensure one valid arg.
  |  lgr RC, RA				// ... in [RC]
  |  lg PC, -24(RB)			// Restore PC from [cont|PC].
  |  lg RA, -32(RB)
  |.if FFI
  |  clfi RA, 1
  |  jle >1
  |.endif
  |  lg LFUNC:KBASE, -16(BASE)
  |  cleartp LFUNC:KBASE
  |  lg KBASE, LFUNC:KBASE->pc
  |  lg KBASE, (PC2PROTO(k))(KBASE)
  |  // BASE = base, RC = result, RB = meta base
  |  br RA				// Jump to continuation.
  |
  |.if FFI
  |1:
  |  je ->cont_ffi_callback		// cont = 1: return from FFI callback.
  |  // cont = 0: Tail call from C function.
  |  sgr RB, BASE
  |  srl RB, 3
  |  ahi RB, -3
  |  llgfr RD, RB
  |  j ->vm_call_tail
  |.endif
  |
  |->cont_cat:				// BASE = base, RC = result, RB = mbase
  |  llgc RA, PC_RB
  |  sllg RA, RA, 3
  |  aghi RB, -32
  |  la RA, 0(RA, BASE)
  |  sgr RA, RB
  |  je ->cont_ra
  |  lcgr RA, RA
  |  srlg RA, RA, 3
  |  lg L:CARG1, SAVE_L
  |  stg BASE, L:CARG1->base
  |  lgfr CARG3, RA			// Caveat: RA == CARG3.
  |  lg TMPR0, 0(RC)
  |  stg TMPR0, 0(RB)
  |  lgr CARG2, RB
  |  j ->BC_CAT_Z
  |
  |//-- Table indexing metamethods -----------------------------------------
  |
  |->vmeta_tgets:
  |  settp STR:RC, LJ_TSTR			// STR:RC = GCstr *
  |  stg STR:RC, SAVE_TMP
  |  la RC, SAVE_TMP
  |  llgc TMPR1, PC_OP
  |  cghi TMPR1, BC_GGET
  |  jne >1
  |  settp TAB:RA, TAB:RB, LJ_TTAB		// TAB:RB = GCtab *
  |  lay RB, (DISPATCH_GL(tmptv))(DISPATCH)	// Store fn->l.env in g->tmptv.
  |  stg TAB:RA, 0(RB)
  |  j >2
  |
  |->vmeta_tgetb:
  |  llgc RC, PC_RC
  |  setint RC
  |  stg RC, SAVE_TMP
  |  la RC, SAVE_TMP
  |  j >1
  |
  |->vmeta_tgetv:
  |  llgc RC, PC_RC			// Reload TValue *k from RC.
  |  sllg RC, RC, 3
  |  la RC, 0(RC, BASE)
  |1:
  |  llgc RB, PC_RB			// Reload TValue *t from RB.
  |  sllg RB, RB, 3
  |  la RB, 0(RB, BASE)
  |2:
  |  lg L:CARG1, SAVE_L
  |  stg BASE, L:CARG1->base
  |  lgr CARG2, RB
  |  lgr CARG3, RC
  |  lgr L:RB, L:CARG1
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_tget	// (lua_State *L, TValue *o, TValue *k)
  |  // TValue * (finished) or NULL (metamethod) returned in r2 (CRET1).
  |  lg BASE, L:RB->base
  |  ltgr RC, CRET1
  |  je >3
  |->cont_ra:				// BASE = base, RC = result
  |  llgc RA, PC_RA
  |  sllg RA, RA, 3
  |  lg RB, 0(RC)
  |  stg RB, 0(RA, BASE)
  |  ins_next
  |
  |3:  // Call __index metamethod.
  |  // BASE = base, L->top = new base, stack = cont/func/t/k
  |  lg RA, L:RB->top
  |  stg PC, -24(RA)			// [cont|PC]
  |  la PC, FRAME_CONT(RA)
  |  sgr PC, BASE
  |  lg LFUNC:RB, -16(RA)		// Guaranteed to be a function here.
  |  lghi NARGS:RD, 2+1			// 2 args for func(t, k).
  |  cleartp LFUNC:RB
  |  j ->vm_call_dispatch_f
  |
  |->vmeta_tgetr:
  |  lgr CARG1, TAB:RB
  |  lgfr CARG2, RC
  |  brasl r14, extern lj_tab_getinth		// (GCtab *t, int32_t key)
  |  // cTValue * or NULL returned in r2 (CRET1).
  |  llgc RA, PC_RA
  |  ltgr RC, CRET1
  |  jne ->BC_TGETR_Z
  |  lghi ITYPE, LJ_TNIL
  |  j ->BC_TGETR2_Z
  |
  |//-----------------------------------------------------------------------
  |
  |->vmeta_tsets:
  |  settp STR:RC, LJ_TSTR			// STR:RC = GCstr *
  |  stg STR:RC, SAVE_TMP
  |  la RC, SAVE_TMP
  |  llgc TMPR0, PC_OP
  |  cghi TMPR0, BC_GSET
  |  jne >1
  |  settp TAB:RA, TAB:RB, LJ_TTAB		// TAB:RB = GCtab *
  |  lay RB, (DISPATCH_GL(tmptv))(DISPATCH)	// Store fn->l.env in g->tmptv.
  |  stg TAB:RA, 0(RB)
  |  j >2
  |
  |->vmeta_tsetb:
  |  llgc RC, PC_RC
  |  setint RC
  |  stg RC, SAVE_TMP
  |  la RC, SAVE_TMP
  |  j >1
  |
  |->vmeta_tsetv:
  |  llgc RC, PC_RC			// Reload TValue *k from RC.
  |  sllg RC, RC, 3
  |  la RC, 0(RC, BASE)
  |1:
  |  llgc RB, PC_RB			// Reload TValue *t from RB.
  |  sllg RB, RB, 3
  |  la RB, 0(RB, BASE)
  |2:
  |  lg L:CARG1, SAVE_L
  |  stg BASE, L:CARG1->base
  |  lgr CARG2, RB
  |  lgr CARG3, RC
  |  lgr L:RB, L:CARG1
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_tset	// (lua_State *L, TValue *o, TValue *k)
  |  // TValue * (finished) or NULL (metamethod) returned in r2 (CRET1).
  |  lg BASE, L:RB->base
  |  ltgr RC, CRET1
  |  je >3
  |  // NOBARRIER: lj_meta_tset ensures the table is not black.
  |  llgc RA, PC_RA
  |  sllg RA, RA, 3
  |  lg RB, 0(RA, BASE)
  |  stg RB, 0(RC)
  |->cont_nop:				// BASE = base, (RC = result)
  |  ins_next
  |
  |3:  // Call __newindex metamethod.
  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
  |  lg RA, L:RB->top
  |  stg PC, -24(RA)			// [cont|PC]
  |  llgc RC, PC_RA
  |  // Copy value to third argument.
  |  sllg RB, RC, 3
  |  lg RB, 0(RB, BASE)
  |  stg RB, 16(RA)
  |  la PC, FRAME_CONT(RA)
  |  sgr PC, BASE
  |  lg LFUNC:RB, -16(RA)		// Guaranteed to be a function here.
  |  lghi NARGS:RD, 3+1			// 3 args for func(t, k, v).
  |  cleartp LFUNC:RB
  |  j ->vm_call_dispatch_f
  |
  |->vmeta_tsetr:
  |  lg L:CARG1, SAVE_L
  |  lgr CARG2, TAB:RB
  |  stg BASE, L:CARG1->base
  |  lgfr CARG3, RC
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)
  |  // TValue * returned in r2 (CRET1).
  |  lgr RC, CRET1
  |  llgc RA, PC_RA
  |  j ->BC_TSETR_Z
  |
  |//-- Comparison metamethods ---------------------------------------------
  |
  |->vmeta_comp:
  |  llgh RD, PC_RD
  |  sllg RD, RD, 3
  |  llgc RA, PC_RA
  |  sllg RA, RA, 3
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  la CARG2, 0(RA, BASE)
  |  la CARG3, 0(RD, BASE)		// Caveat: RA == CARG3
  |  lgr CARG1, L:RB
  |  llgc CARG4, PC_OP
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_comp	// (lua_State *L, TValue *o1, *o2, int op)
  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).
  |3:
  |  lgr RC, CRET1
  |  lg BASE, L:RB->base
  |  clgfi RC, 1
  |  jh ->vmeta_binop
  |4:
  |  la PC, 4(PC)
  |  jl >6
  |5:
  |  llgh RD, PC_RD
  |  branchPC RD
  |6:
  |  ins_next
  |
  |->cont_condt:			// BASE = base, RC = result
  |  la PC, 4(PC)
  |  lg ITYPE, 0(RC)
  |  srag ITYPE, ITYPE, 47
  |  lghi TMPR0, LJ_TISTRUECOND
  |  clr ITYPE, TMPR0		// Branch if result is true.
  |  jl <5
  |  j <6
  |
  |->cont_condf:			// BASE = base, RC = result
  |  lg ITYPE, 0(RC)
  |  srag ITYPE, ITYPE, 47
  |  lghi TMPR0, LJ_TISTRUECOND
  |  clr ITYPE, TMPR0		// Branch if result is false.
  |  j <4
  |
  |->vmeta_equal:
  |  cleartp TAB:RD
  |  lay PC, -4(PC)
  |  lgr CARG2, RA
  |  lgfr CARG4, RB
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  lgr CARG3, RD
  |  lgr CARG1, L:RB
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_equal	// (lua_State *L, GCobj *o1, *o2, int ne)
  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).
  |  j <3
  |
  |->vmeta_equal_cd:
  |.if FFI
  |  lay PC, -4(PC)
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  lgr CARG1, L:RB
  |  llgf CARG2, -4(PC)
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_equal_cd	// (lua_State *L, BCIns ins)
  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).
  |  j <3
  |.endif
  |
  |->vmeta_istype:
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  llgfr CARG2, RA
  |  llgfr CARG3, RD			// Caveat: CARG3 == RA.
  |  lgr L:CARG1, L:RB
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)
  |  lg BASE, L:RB->base
  |  j <6
  |
  |//-- Arithmetic metamethods ---------------------------------------------
  |
  |->vmeta_arith_vno:
  |  llgc RB, PC_RB
  |  llgc RC, PC_RC
  |->vmeta_arith_vn:
  |  sllg RB, RB, 3
  |  sllg RC, RC, 3
  |  la RB, 0(RB, BASE)
  |  la RC, 0(RC, KBASE)
  |  j >1
  |
  |->vmeta_arith_nvo:
  |  llgc RC, PC_RC
  |  llgc RB, PC_RB
  |->vmeta_arith_nv:
  |  sllg RC, RC, 3
  |  sllg RB, RB, 3
  |  la TMPR1, 0(RC, KBASE)
  |  la RC, 0(RB, BASE)
  |  lgr RB, TMPR1
  |  j >1
  |
  |->vmeta_unm:
  |  llgh RD, PC_RD
  |  sllg RD, RD, 3
  |  la RC, 0(RD, BASE)
  |  lgr RB, RC
  |  j >1
  |
  |->vmeta_arith_vvo:
  |  llgc RB, PC_RB
  |  llgc RC, PC_RC
  |->vmeta_arith_vv:
  |  sllg RC, RC, 3
  |  sllg RB, RB, 3
  |  la RB, 0(RB, BASE)
  |  la RC, 0(RC, BASE)
  |1:
  |  llgc RA, PC_RA
  |  sllg RA, RA, 3
  |  la RA, 0(RA, BASE)
  |  llgc CARG5, PC_OP			// Caveat: CARG5 == RD.
  |  lgr CARG2, RA
  |  lgr CARG3, RB			// Caveat: CARG3 == RA.
  |  // lgr CARG4, RC			// Caveat: CARG4 == RC (nop, so commented out).
  |  lg L:CARG1, SAVE_L
  |  stg BASE, L:CARG1->base
  |  lgr L:RB, L:CARG1
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
  |  // NULL (finished) or TValue * (metamethod) returned in r2 (CRET1).
  |  lg BASE, L:RB->base
  |  cghi CRET1, 0
  |  lgr RC, CRET1
  |  je ->cont_nop
  |
  |  // Call metamethod for binary op.
  |->vmeta_binop:
  |  // BASE = base, RC = new base, stack = cont/func/o1/o2
  |  lgr RA, RC
  |  sgr RC, BASE
  |  stg PC, -24(RA)			// [cont|PC]
  |  la PC, FRAME_CONT(RC)
  |  lghi NARGS:RD, 2+1			// 2 args for func(o1, o2).
  |  j ->vm_call_dispatch
  |
  |->vmeta_len:
  |  llgh RD, PC_RD
  |  sllg RD, RD, 3
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  la CARG2, 0(RD, BASE)
  |  lgr L:CARG1, L:RB
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_len	// (lua_State *L, TValue *o)
  |  // NULL (retry) or TValue * (metamethod) returned in r2 (CRET1).
  |  lgr RC, CRET1
  |  lg BASE, L:RB->base
#if LJ_52
  |  cghi RC, 0
  |  jne ->vmeta_binop			// Binop call for compatibility.
  |  llgh RD, PC_RD
  |  sllg RD, RD, 3
  |  lg TAB:CARG1, 0(RD, BASE)
  |  cleartp TAB:CARG1
  |  j ->BC_LEN_Z
#else
  |  j ->vmeta_binop			// Binop call for compatibility.
#endif
  |
  |//-- Call metamethod ----------------------------------------------------
  |
  |->vmeta_call_ra:
  |  la RA, 16(RA, BASE)		// RA previously set to RA*8.
  |->vmeta_call:			// Resolve and call __call metamethod.
  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return
  |  stg NARGS:RD, SAVE_TMP		// Save RA, RC for us (not sure about this).
  |  lgr RB, RA
  |  lg L:CARG1, SAVE_L
  |  stg BASE, L:CARG1->base
  |  lay CARG2, -16(RA)
  |  sllg RD, RD, 3
  |  lay CARG3, -8(RA, RD)		// Caveat: CARG3 == RA.
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_call	// (lua_State *L, TValue *func, TValue *top)
  |  lgr RA, RB
  |  lg L:RB, SAVE_L
  |  lg BASE, L:RB->base
  |  lg NARGS:RD, SAVE_TMP
  |  lg LFUNC:RB, -16(RA)
  |  aghi NARGS:RD, 1			// 32-bit on x64.
  |  // This is fragile. L->base must not move, KBASE must always be defined.
  |  cgr KBASE, BASE			// Continue with CALLT if flag set.
  |  je ->BC_CALLT_Z
  |  cleartp LFUNC:RB
  |  lgr BASE, RA
  |  ins_call				// Otherwise call resolved metamethod.
  |
  |//-- Argument coercion for 'for' statement ------------------------------
  |
  |->vmeta_for:
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  lgr CARG2, RA
  |  lgr CARG1, RB
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_meta_for	// (lua_State *L, TValue *base)
  |  lg BASE, L:RB->base
  |  llgc OP, PC_OP
  |  llgc RA, PC_RA
  |  llgh RD, PC_RD
  |  sllg TMPR1, OP, 3
  |  lg TMPR1, GG_DISP2STATIC(TMPR1, DISPATCH)	// Retry FORI or JFORI.
  |  br TMPR1
  |
  |//-----------------------------------------------------------------------
  |//-- Fast functions -----------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |.macro .ffunc, name
  |->ff_ .. name:
  |.endmacro
  |
  |.macro .ffunc_1, name
  |->ff_ .. name:
  |  clfi NARGS:RD, 1+1; jl ->fff_fallback
  |.endmacro
  |
  |.macro .ffunc_2, name
  |->ff_ .. name:
  |  clfi NARGS:RD, 2+1; jl ->fff_fallback
  |.endmacro
  |
  |.macro .ffunc_n, name, op
  |  .ffunc_1 name
  |  lg TMPR0, 0(BASE)
  |  checknumtp TMPR0, ->fff_fallback
  |  op f0, 0(BASE)
  |.endmacro
  |
  |.macro .ffunc_n, name
  |  .ffunc_n name, ld
  |.endmacro
  |
  |.macro .ffunc_nn, name
  |  .ffunc_2 name
  |  lg TMPR1, 0(BASE)
  |  lg TMPR0, 8(BASE)
  |  ld FARG1, 0(BASE)
  |  ld FARG2, 8(BASE)
  |  checknumtp TMPR1, ->fff_fallback
  |  checknumtp TMPR0, ->fff_fallback
  |.endmacro
  |
  |// Inlined GC threshold check. Caveat: uses label 1.
  |.macro ffgccheck
  |  lg RB, (DISPATCH_GL(gc.total))(DISPATCH)
  |  clg RB, (DISPATCH_GL(gc.threshold))(DISPATCH)
  |  jl >1
  |  brasl r14, ->fff_gcstep
  |1:
  |.endmacro
  |
  |//-- Base library: checks -----------------------------------------------
  |
  |.ffunc_1 assert
  |  lg RB, 0(BASE)
  |  srag ITYPE, RB, 47
  |  clfi ITYPE, LJ_TISTRUECOND; jhe ->fff_fallback
  |  lg PC, -8(BASE)
  |  st RD, SAVE_MULTRES
  |  lg RB, 0(BASE)
  |  stg RB, -16(BASE)
  |  ahi RD, -2
  |  je >2
  |  lgr RA, BASE
  |1:
  |  la RA, 8(RA)
  |  lg RB, 0(RA)
  |  stg RB, -16(RA)
  |  brct RD, <1
  |2:
  |  llgf RD, SAVE_MULTRES
  |  j ->fff_res_
  |
  |.ffunc_1 type
  |  lg RC, 0(BASE)
  |  srag RC, RC, 47
  |  lghi RB, LJ_TISNUM
  |  clgr RC, RB
  |  jnl >1
  |  lgr RC, RB
  |1:
  |  lghi TMPR0, -1
  |  xgr RC, TMPR0
  |2:
  |  lg CFUNC:RB, -16(BASE)
  |  cleartp CFUNC:RB
  |  sllg RC, RC, 3
  |  lg STR:RC, ((char *)(&((GCfuncC *)0)->upvalue))(RC, CFUNC:RB)
  |  lg PC, -8(BASE)
  |  settp STR:RC, LJ_TSTR
  |  stg STR:RC, -16(BASE)
  |  j ->fff_res1
  |
  |//-- Base library: getters and setters ---------------------------------
  |
  |.ffunc_1 getmetatable
  |  lg TAB:RB, 0(BASE)
  |  lg PC, -8(BASE)
  |  checktab TAB:RB, >6
  |1:  // Field metatable must be at same offset for GCtab and GCudata!
  |  lg TAB:RB, TAB:RB->metatable
  |2:
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, -16(BASE)
  |  cghi TAB:RB, 0
  |  je ->fff_res1
  |  settp TAB:RC, TAB:RB, LJ_TTAB
  |  stg TAB:RC, -16(BASE)		// Store metatable as default result.
  |  lg STR:RC, (DISPATCH_GL(gcroot)+8*(GCROOT_MMNAME+MM_metatable))(DISPATCH)
  |  llgf RA, TAB:RB->hmask
  |  n RA, STR:RC->hash
  |  settp STR:RC, LJ_TSTR
  |  mghi RA, #NODE
  |  ag NODE:RA, TAB:RB->node
  |3:  // Rearranged logic, because we expect _not_ to find the key.
  |  cg STR:RC, NODE:RA->key
  |  je >5
  |4:
  |  ltg NODE:RA, NODE:RA->next
  |  jne <3
  |  j ->fff_res1			// Not found, keep default result.
  |5:
  |  lg RB, NODE:RA->val
  |  cghi RB, LJ_TNIL; je ->fff_res1	// Ditto for nil value.
  |  stg RB, -16(BASE)			// Return value of mt.__metatable.
  |  j ->fff_res1
  |
  |6:
  |  clfi ITYPE, LJ_TUDATA; je <1
  |  clfi ITYPE, LJ_TISNUM; jh >7
  |  lhi ITYPE, LJ_TISNUM
  |7:
  |  lhi TMPR0, -1
  |  xr ITYPE, TMPR0 // not ITYPE
  |  llgfr ITYPE, ITYPE
  |  sllg ITYPE, ITYPE, 3
  |  lg TAB:RB, (DISPATCH_GL(gcroot[GCROOT_BASEMT]))(ITYPE, DISPATCH)
  |  j <2
  |
  |.ffunc_2 setmetatable
  |  lg TAB:RB, 0(BASE)
  |  lgr TAB:TMPR1, TAB:RB
  |  checktab TAB:RB, ->fff_fallback
  |  // Fast path: no mt for table yet and not clearing the mt.
  |  lghi TMPR0, 0
  |  cg TMPR0, TAB:RB->metatable; jne ->fff_fallback
  |  lg TAB:RA, 8(BASE)
  |  checktab TAB:RA, ->fff_fallback
  |  stg TAB:RA, TAB:RB->metatable
  |  lg PC, -8(BASE)
  |  stg TAB:TMPR1, -16(BASE)			// Return original table.
  |  tm TAB:RB->marked, LJ_GC_BLACK		// isblack(table)
  |  je >1
  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.
  |  barrierback TAB:RB, RC
  |1:
  |  j ->fff_res1
  |
  |.ffunc_2 rawget
  |  lg TAB:CARG2, 0(BASE)
  |  checktab TAB:CARG2, ->fff_fallback
  |  la CARG3, 8(BASE)
  |  lg CARG1, SAVE_L
  |  brasl r14, extern lj_tab_get	// (lua_State *L, GCtab *t, cTValue *key)
  |  // cTValue * returned in r2 (CRET1).
  |  // Copy table slot.
  |  lg RB, 0(CRET1)
  |  lg PC, -8(BASE)
  |  stg RB, -16(BASE)
  |  j ->fff_res1
  |
  |//-- Base library: conversions ------------------------------------------
  |
  |.ffunc tonumber
  |  // Only handles the number case inline (without a base argument).
  |  clfi NARGS:RD, 1+1; jne ->fff_fallback	// Exactly one argument.
  |  lg RB, 0(BASE)
  |  checknumber RB, ->fff_fallback
  |  lg PC, -8(BASE)
  |  stg RB, -16(BASE)
  |  j ->fff_res1
  |
  |.ffunc_1 tostring
  |  // Only handles the string or number case inline.
  |  lg PC, -8(BASE)
  |  lg STR:RB, 0(BASE)
  |  checktp_nc STR:RB, LJ_TSTR, >3
  |  // A __tostring method in the string base metatable is ignored.
  |2:
  |  stg STR:RB, -16(BASE)
  |  j ->fff_res1
  |3:  // Handle numbers inline, unless a number base metatable is present.
  |  clfi ITYPE, LJ_TISNUM; jh ->fff_fallback_1
  |  lghi TMPR0, 0
  |  cg TMPR0, (DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM]))(DISPATCH)
  |  jne ->fff_fallback
  |  ffgccheck				// Caveat: uses label 1.
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base		// Add frame since C call can throw.
  |  stg PC, SAVE_PC			// Redundant (but a defined value).
  |  lgr CARG2, BASE			// Otherwise: CARG2 == BASE
  |  lgr L:CARG1, L:RB
  |  brasl r14, extern lj_strfmt_number	// (lua_State *L, cTValue *o)
  |  // GCstr returned in r2 (CRET1).
  |  lg BASE, L:RB->base
  |  settp STR:RB, CRET1, LJ_TSTR
  |  j <2
  |
  |//-- Base library: iterators -------------------------------------------
  |
  |.ffunc_1 next
  |  je >2				// Missing 2nd arg?
  |1:
  |  lg CARG2, 0(BASE)
  |  checktab CARG2, ->fff_fallback
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base		// Add frame since C call can throw.
  |  stg BASE, L:RB->top		// Dummy frame length is ok.
  |  lg PC, -8(BASE)
  |  la CARG3, 8(BASE)
  |  lgr CARG1, L:RB
  |  stg PC, SAVE_PC			// Needed for ITERN fallback.
  |  brasl r14, extern lj_tab_next	// (lua_State *L, GCtab *t, TValue *key)
  |  // Flag returned in r2 (CRET1).
  |  lg BASE, L:RB->base
  |  ltr RD, CRET1;  je >3		// End of traversal?
  |  // Copy key and value to results.
  |  lg RB, 8(BASE)
  |  lg RD, 16(BASE)
  |  stg RB, -16(BASE)
  |  stg RD, -8(BASE)
  |->fff_res2:
  |  lghi RD, 1+2
  |  j ->fff_res
  |2:  // Set missing 2nd arg to nil.
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, 8(BASE)
  |  j <1
  |3:  // End of traversal: return nil.
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, -16(BASE)
  |  j ->fff_res1
  |
  |.ffunc_1 pairs
  |  lg TAB:RB, 0(BASE)
  |  lgr TMPR1, TAB:RB
  |  checktab TAB:RB, ->fff_fallback
#if LJ_52
  |  ltg TMPR0, TAB:RB->metatable; jne ->fff_fallback
#endif
  |  lg CFUNC:RD, -16(BASE)
  |  cleartp CFUNC:RD
  |  lg CFUNC:RD, CFUNC:RD->upvalue[0]
  |  settp CFUNC:RD, LJ_TFUNC
  |  lg PC, -8(BASE)
  |  stg CFUNC:RD, -16(BASE)
  |  stg TMPR1, -8(BASE)
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, 0(BASE)
  |  lghi RD, 1+3
  |  j ->fff_res
  |
  |.ffunc_2 ipairs_aux
  |  lg TAB:RB, 0(BASE)
  |  checktab TAB:RB, ->fff_fallback
  |  lg RA, 8(BASE)
  |  checkint RA, ->fff_fallback
  |  lg PC, -8(BASE)
  |  aghi RA, 1
  |  setint ITYPE, RA
  |  stg ITYPE, -16(BASE)
  |  cl RA, TAB:RB->asize;  jhe >2	// Not in array part?
  |  lg RD, TAB:RB->array
  |  lgfr TMPR1, RA
  |  sllg TMPR1, TMPR1, 3
  |  la RD, 0(TMPR1, RD)
  |1:
  |  lg TMPR0, 0(RD)
  |  cghi TMPR0, LJ_TNIL;  je ->fff_res0
  |  // Copy array slot.
  |  stg TMPR0, -8(BASE)
  |  j ->fff_res2
  |2:  // Check for empty hash part first. Otherwise call C function.
  |  lt TMPR0, TAB:RB->hmask; je ->fff_res0
  |  lgr CARG1, TAB:RB
  |  lgfr CARG2, RA
  |  brasl r14, extern lj_tab_getinth	// (GCtab *t, int32_t key)
  |  // cTValue * or NULL returned in r2 (CRET1).
  |  ltgr RD, CRET1
  |  jne <1
  |->fff_res0:
  |  lghi RD, 1+0
  |  j ->fff_res
  |
  |.ffunc_1 ipairs
  |  lg TAB:RB, 0(BASE)
  |  lgr TMPR1, TAB:RB
  |  checktab TAB:RB, ->fff_fallback
#if LJ_52
  |  lghi TMPR0, 0
  |  cg TMPR0, TAB:RB->metatable; jne ->fff_fallback
#endif
  |  lg CFUNC:RD, -16(BASE)
  |  cleartp CFUNC:RD
  |  lg CFUNC:RD, CFUNC:RD->upvalue[0]
  |  settp CFUNC:RD, LJ_TFUNC
  |  lg PC, -8(BASE)
  |  stg CFUNC:RD, -16(BASE)
  |  stg TMPR1, -8(BASE)
  |  llihf RD, LJ_TISNUM<<15
  |  stg RD, 0(BASE)
  |  lghi RD, 1+3
  |  j ->fff_res
  |
  |//-- Base library: catch errors ----------------------------------------
  |
  |.ffunc_1 pcall
  |  la RA, 16(BASE)
  |  aghi NARGS:RD, -1
  |  lghi PC, 16+FRAME_PCALL
  |1:
  |  llgc RB, (DISPATCH_GL(hookmask))(DISPATCH)
  |  srlg RB, RB, HOOK_ACTIVE_SHIFT(r0)
  |  nill RB, 1				// High bits already zero (from load).
  |  agr PC, RB				// Remember active hook before pcall.
  |  // Note: this does a (harmless) copy of the function to the PC slot, too.
  |  lgr KBASE, RD
  |2:
  |  sllg TMPR1, KBASE, 3
  |  lg RB, -24(TMPR1, RA)
  |  stg RB, -16(TMPR1, RA)
  |  aghi KBASE, -1
  |  jh <2
  |  j ->vm_call_dispatch
  |
  |.ffunc_2 xpcall
  |  lg LFUNC:RA, 8(BASE)
  |  checktp_nc LFUNC:RA, LJ_TFUNC, ->fff_fallback
  |  lg LFUNC:RB, 0(BASE)		// Swap function and traceback.
  |  stg LFUNC:RA, 0(BASE)
  |  stg LFUNC:RB, 8(BASE)
  |  la RA, 24(BASE)
  |  aghi NARGS:RD, -2
  |  lghi PC, 24+FRAME_PCALL
  |  j <1
  |
  |//-- Coroutine library --------------------------------------------------
  |
  |.macro coroutine_resume_wrap, resume
  |.if resume
  |.ffunc_1 coroutine_resume
  |  lg L:RB, 0(BASE)
  |  lgr L:TMPR0, L:RB			// Save type for checktptp.
  |  cleartp L:RB
  |.else
  |.ffunc coroutine_wrap_aux
  |  lg CFUNC:RB, -16(BASE)
  |  cleartp CFUNC:RB
  |  lg L:RB, CFUNC:RB->upvalue[0].gcr
  |  cleartp L:RB
  |.endif
  |  lg PC, -8(BASE)
  |  stg PC, SAVE_PC
  |  stg L:RB, SAVE_TMP
  |.if resume
  |  checktptp L:TMPR0, LJ_TTHREAD, ->fff_fallback
  |.endif
  |  ltg TMPR0, L:RB->cframe; jne ->fff_fallback
  |  cli L:RB->status, LUA_YIELD; jh ->fff_fallback
  |  lg RA, L:RB->top
  |  je >1				// Status != LUA_YIELD (i.e. 0)?
  |  cg RA, L:RB->base			// Check for presence of initial func.
  |  je ->fff_fallback
  |  lg PC, -8(RA)			// Move initial function up.
  |  stg PC, 0(RA)
  |  la RA, 8(RA)
  |1:
  |  sllg TMPR1, NARGS:RD, 3
  |.if resume
  |  lay PC, -16(TMPR1, RA)		// Check stack space (-1-thread).
  |.else
  |  lay PC, -8(TMPR1, RA)		// Check stack space (-1).
  |.endif
  |  clg PC, L:RB->maxstack; jh ->fff_fallback
  |  stg PC, L:RB->top
  |
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |.if resume
  |  la BASE, 8(BASE)			// Keep resumed thread in stack for GC.
  |.endif
  |  stg BASE, L:RB->top
  |.if resume
  |  lay RB, -24(TMPR1, BASE)		// RB = end of source for stack move.
  |.else
  |  lay RB, -16(TMPR1, BASE)		// RB = end of source for stack move.
  |.endif
  |  sgr RB, PC			// Relative to PC.
  |
  |  cgr PC, RA
  |  je >3
  |2:  // Move args to coroutine.
  |  lg RC, 0(RB, PC)
  |  stg RC, -8(PC)
  |  lay PC, -8(PC)
  |  cgr PC, RA
  |  jne <2
  |3:
  |  lgr CARG2, RA
  |  lg L:CARG1, SAVE_TMP
  |  lghi CARG3, 0
  |  lghi CARG4, 0
  |  brasl r14, ->vm_resume			// (lua_State *L, TValue *base, 0, 0)
  |
  |  lg L:RB, SAVE_L
  |  lg L:PC, SAVE_TMP
  |  lg BASE, L:RB->base
  |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)
  |  set_vmstate INTERP
  |
  |  clfi CRET1, LUA_YIELD
  |  jh >8
  |4:
  |  lg RA, L:PC->base
  |  lg KBASE, L:PC->top
  |  stg RA, L:PC->top			// Clear coroutine stack.
  |  lgr PC, KBASE
  |  sgr PC, RA
  |  je >6				// No results?
  |  la RD, 0(PC, BASE)
  |  llgfr PC, PC
  |  srlg PC, PC, 3
  |  clg RD, L:RB->maxstack
  |  jh >9				// Need to grow stack?
  |
  |  lgr RB, BASE
  |  sgr RB, RA
  |5:  // Move results from coroutine.
  |  lg RD, 0(RA)
  |  stg RD, 0(RA, RB)
  |  la RA, 8(RA)
  |  cgr RA, KBASE
  |  jne <5
  |6:
  |.if resume
  |  la RD, 2(PC)			// nresults+1 = 1 + true + results.
  |  load_true ITYPE			// Prepend true to results.
  |  stg ITYPE, -8(BASE)
  |.else
  |  la RD, 1(PC)			// nresults+1 = 1 + results.
  |.endif
  |7:
  |  lg PC, SAVE_PC
  |  st RD, SAVE_MULTRES
  |.if resume
  |  lghi RA, -8
  |.else
  |  lghi RA, 0
  |.endif
  |  tmll PC, FRAME_TYPE
  |  je ->BC_RET_Z
  |  j ->vm_return
  |
  |8:  // Coroutine returned with error (at co->top-1).
  |.if resume
  |  load_false ITYPE			// Prepend false to results.
  |  stg ITYPE, -8(BASE)
  |  lg RA, L:PC->top
  |  aghi RA, -8
  |  stg RA, L:PC->top			// Clear error from coroutine stack.
  |  // Copy error message.
  |  lg RD, 0(RA)
  |  stg RD, 0(BASE)
  |  lghi RD, 1+2			// nresults+1 = 1 + false + error.
  |  j <7
  |.else
  |  lgr CARG2, L:PC
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)
  |  // Error function does not return.
  |.endif
  |
  |9:  // Handle stack expansion on return from yield.
  |  lg L:RA, SAVE_TMP
  |  stg KBASE, L:RA->top		// Undo coroutine stack clearing.
  |  lgr CARG2, PC
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_state_growstack	// (lua_State *L, int n)
  |  lg L:PC, SAVE_TMP
  |  lg BASE, L:RB->base
  |  j <4				// Retry the stack move.
  |.endmacro
  |
  |  coroutine_resume_wrap 1		// coroutine.resume
  |  coroutine_resume_wrap 0		// coroutine.wrap
  |
  |.ffunc coroutine_yield
  |  lg L:RB, SAVE_L
  |  lg TMPR0, L:RB->cframe
  |  tmll TMPR0, CFRAME_RESUME
  |  je ->fff_fallback
  |  stg BASE, L:RB->base
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -8(RD, BASE)
  |  stg RD, L:RB->top
  |  lghi RD, 0
  |  stg RD, L:RB->cframe
  |  lghi CRET1, LUA_YIELD
  |  stc CRET1, L:RB->status
  |  j ->vm_leave_unw
  |
  |//-- Math library -------------------------------------------------------
  |
  |.ffunc_1 math_abs
  |  lg RB, 0(BASE)
  |  checkint RB, >3
  |  lpr RB, RB; jo >2
  |->fff_resbit:
  |->fff_resi:
  |  setint RB
  |->fff_resRB:
  |  lg PC, -8(BASE)
  |  stg RB, -16(BASE)
  |  j ->fff_res1
  |2:
  |  llihh RB, 0x41e0	// 2^31
  |  j ->fff_resRB
  |3:
  |  jh ->fff_fallback
  |  nihh RB, 0x7fff	// Clear sign bit.
  |  lg PC, -8(BASE)
  |  stg RB, -16(BASE)
  |  j ->fff_res1
  |
  |.ffunc_n math_sqrt, sqdb
  |->fff_resf0:
  |  lg PC, -8(BASE)
  |  stdy f0, -16(BASE)
  |  // fallthrough
  |
  |->fff_res1:
  |  lghi RD, 1+1
  |->fff_res:
  |  st RD, SAVE_MULTRES
  |->fff_res_:
  |  tmll PC, FRAME_TYPE
  |  jne >7
  |5:
  |  llgc TMPR1, PC_RB
  |  clgr TMPR1, RD			// More results expected?
  |  jh >6
  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.
  |  llgc RA, PC_RA
  |  lcgr RA, RA
  |  sllg RA, RA, 3
  |  lay BASE, -16(RA, BASE)		// base = base - (RA+2)*8
  |  ins_next
  |
  |6:  // Fill up results with nil.
  |  sllg TMPR1, RD, 3
  |  lghi TMPR0, LJ_TNIL
  |  stg TMPR0, -24(TMPR1, BASE)
  |  la RD, 1(RD)
  |  j <5
  |
  |7:  // Non-standard return case.
  |  lghi RA, -16			// Results start at BASE+RA = BASE-16.
  |  j ->vm_return
  |
  |.macro math_round, func
  |  .ffunc math_ .. func
  |  lg RB, 0(BASE)
  |  ld f0, 0(BASE)
  |  checknumx RB, ->fff_resRB, je
  |  jh ->fff_fallback
  |  brasl r14, ->vm_ .. func
  |  cfdbr RB, 0, f0
  |  jo ->fff_resf0
  |  llgfr RB, RB
  |  j ->fff_resi
  |.endmacro
  |
  |  math_round floor
  |  math_round ceil
  |
  |.ffunc math_log
  |  chi NARGS:RD, 1+1; jne ->fff_fallback	// Exactly one argument.
  |  lg TMPR0, 0(BASE)
  |  ld FARG1, 0(BASE)
  |  checknumtp TMPR0, ->fff_fallback
  |  brasl r14, extern log
  |  j ->fff_resf0
  |
  |.macro math_extern, func
  |  .ffunc_n math_ .. func
  |  brasl r14, extern func
  |  j ->fff_resf0
  |.endmacro
  |
  |.macro math_extern2, func
  |  .ffunc_nn math_ .. func
  |  brasl r14, extern func
  |  j ->fff_resf0
  |.endmacro
  |
  |  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
  |
  |.ffunc_2 math_ldexp
  |  lg TMPR0, 0(BASE)
  |  ld FARG1, 0(BASE)
  |  lg CARG1, 8(BASE)
  |  checknumtp TMPR0, ->fff_fallback
  |  checkinttp CARG1, ->fff_fallback
  |  lgfr CARG1, CARG1
  |  brasl r14, extern ldexp	// (double, int)
  |  j ->fff_resf0
  |
  |.ffunc_n math_frexp
  |  la CARG1, SAVE_TMP
  |  brasl r14, extern frexp
  |  llgf RB, SAVE_TMP
  |  lg PC, -8(BASE)
  |  stdy f0, -16(BASE)
  |  setint RB
  |  stg RB, -8(BASE)
  |  lghi RD, 1+2
  |  j ->fff_res
  |
  |.ffunc_n math_modf
  |  lay CARG1, -16(BASE)
  |  brasl r14, extern modf	// (double, double*)
  |  lg PC, -8(BASE)
  |  stdy f0, -8(BASE)
  |  lghi RD, 1+2
  |  j ->fff_res
  |
  |.macro math_minmax, name, cjmp
  |  .ffunc name
  |  lghi RA, 2*8
  |  sllg TMPR1, RD, 3
  |  lg RB, 0(BASE)
  |  ld f0, 0(BASE)
  |  checkint RB, >4
  |1:  // Handle integers.
  |  clgr RA, TMPR1; jhe ->fff_resRB
  |  lg TMPR0, -8(RA, BASE)
  |  checkint TMPR0, >3
  |  cr RB, TMPR0
  |  cjmp >2
  |  lgr RB, TMPR0
  |2:
  |  aghi RA, 8
  |  j <1
  |3:
  |  jh ->fff_fallback
  |  // Convert intermediate result to number and continue below.
  |  cdfbr f0, RB
  |  ldgr f1, TMPR0
  |  j >6
  |4:
  |  jh ->fff_fallback
  |5:  // Handle numbers or integers.
  |  clgr RA, TMPR1; jhe ->fff_resf0
  |  lg RB, -8(RA, BASE)
  |  ldy f1, -8(RA, BASE)
  |  checknumx RB, >6, jl
  |  jh ->fff_fallback
  |  cdfbr f1, RB
  |6:
  |  cdbr f0, f1
  |  cjmp >7
  |  ldr f0, f1
  |7:
  |  aghi RA, 8
  |  j <5
  |.endmacro
  |
  |  math_minmax math_min, jnh
  |  math_minmax math_max, jnl
  |
  |//-- String library -----------------------------------------------------
  |
  |.ffunc string_byte			// Only handle the 1-arg case here.
  |  chi NARGS:RD, 1+1;  jne ->fff_fallback
  |  lg STR:RB, 0(BASE)
  |  checkstr STR:RB, ->fff_fallback
  |  lg PC, -8(BASE)
  |  ltg TMPR0, STR:RB->len
  |  je ->fff_res0			// Return no results for empty string.
  |  llgc RB, STR:RB[1]
  |  j ->fff_resi
  |
  |.ffunc string_char			// Only handle the 1-arg case here.
  |  ffgccheck
  |  chi NARGS:RD, 1+1;  jne ->fff_fallback	// *Exactly* 1 arg.
  |  lg RB, 0(BASE)
  |  checkint RB, ->fff_fallback
  |  clfi RB, 255;  jh ->fff_fallback
  |  strvh RB, SAVE_TMP		// Store [c,0].
  |  lghi TMPR1, 1
  |  la RD, SAVE_TMP			// Points to stack. Little-endian.
  |->fff_newstr:
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  llgfr CARG3, TMPR1			// Zero-extended to size_t.
  |  lgr CARG2, RD
  |  lgr CARG1, L:RB
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_str_new	// (lua_State *L, char *str, size_t l)
  |->fff_resstr:
  |  // GCstr * returned in r2 (CRET1).
  |  lgr STR:RD, CRET1
  |  lg BASE, L:RB->base
  |  lg PC, -8(BASE)
  |  settp STR:RD, LJ_TSTR
  |  stg STR:RD, -16(BASE)
  |  j ->fff_res1
  |
  |.ffunc string_sub
  |  ffgccheck
  |  lghi TMPR1, -1
  |  clfi NARGS:RD, 1+2;  jl ->fff_fallback
  |  jnh >1
  |  lg TMPR1, 16(BASE)
  |  checkint TMPR1, ->fff_fallback
  |1:
  |  lg STR:RB, 0(BASE)
  |  checkstr STR:RB, ->fff_fallback
  |  lg ITYPE, 8(BASE)
  |  lgfr RA, ITYPE
  |  srag ITYPE, ITYPE, 47
  |  cghi ITYPE, LJ_TISNUM
  |  jne ->fff_fallback
  |  llgf RC, STR:RB->len
  |  clr RC, TMPR1			// len < end? (unsigned compare)
  |  jl >5
  |2:
  |  cghi RA, 0				// start <= 0?
  |  jle >7
  |3:
  |  sr TMPR1, RA			// start > end?
  |  jnhe ->fff_emptystr
  |  la RD, (#STR-1)(RA, STR:RB)
  |  ahi TMPR1, 1
  |4:
  |  j ->fff_newstr
  |
  |5:  // Negative end or overflow.
  |  chi TMPR1, 0
  |  jnl >6
  |  ahi TMPR1, 1
  |  ar TMPR1, RC			// end = end+(len+1)
  |  j <2
  |6:  // Overflow.
  |  lr TMPR1, RC			// end = len
  |  j <2
  |
  |7:  // Negative start or underflow.
  |  je >8
  |  agr RA, RC			// start = start+(len+1)
  |  aghi RA, 1
  |  jh <3				// start > 0?
  |8:  // Underflow.
  |  lghi RA, 1				// start = 1
  |  j <3
  |
  |->fff_emptystr:  // Range underflow.
  |  lghi TMPR1, 0
  |  j <4
  |
  |.macro ffstring_op, name
  |  .ffunc_1 string_ .. name
  |  ffgccheck
  |  lg STR:CARG2, 0(BASE)
  |  checkstr STR:CARG2, ->fff_fallback
  |  lg L:RB, SAVE_L
  |   lay SBUF:CARG1, (DISPATCH_GL(tmpbuf))(DISPATCH)
  |  stg BASE, L:RB->base
  |   lg RC, SBUF:CARG1->b
  |   stg L:RB, SBUF:CARG1->L
  |   stg RC, SBUF:CARG1->p
  |  stg PC, SAVE_PC
  |  brasl r14, extern lj_buf_putstr_ .. name
  |  // lgr CARG1, CRET1 (nop, CARG1==CRET1)
  |  brasl r14, extern lj_buf_tostr
  |  j ->fff_resstr
  |.endmacro
  |
  |ffstring_op reverse
  |ffstring_op lower
  |ffstring_op upper
  |
  |//-- Bit library --------------------------------------------------------
  |
  |.macro .ffunc_bit, name, kind, fdef
  |  fdef name
  |.if kind == 2
  |  bfpconst_tobit f1, RB
  |.endif
  |  lg RB, 0(BASE)
  |  ld f0, 0(BASE)
  |  checkint RB, >1
  |.if kind > 0
  |  j >2
  |.else
  |  j ->fff_resbit
  |.endif
  |1:
  |  jh ->fff_fallback
  |.if kind < 2
  |  bfpconst_tobit f1, RB
  |.endif
  |  adbr f0, f1
  |  lgdr RB, f0
  |  llgfr RB, RB
  |2:
  |.endmacro
  |
  |.macro .ffunc_bit, name, kind
  |  .ffunc_bit name, kind, .ffunc_1
  |.endmacro
  |
  |.ffunc_bit bit_tobit, 0
  |  j ->fff_resbit
  |
  |.macro .ffunc_bit_op, name, ins
  |  .ffunc_bit name, 2
  |  lgr TMPR1, NARGS:RD		// Save for fallback.
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -16(RD, BASE)
  |1:
  |  clgr RD, BASE
  |  jle ->fff_resbit
  |  lg RA, 0(RD)
  |  checkint RA, >2
  |  ins RB, RA
  |  aghi RD, -8
  |  j <1
  |2:
  |  jh ->fff_fallback_bit_op
  |  ldgr f0, RA
  |  adbr f0, f1
  |  lgdr RA, f0
  |  ins RB, RA
  |  aghi RD, -8
  |  j <1
  |.endmacro
  |
  |.ffunc_bit_op bit_band, nr
  |.ffunc_bit_op bit_bor, or
  |.ffunc_bit_op bit_bxor, xr
  |
  |.ffunc_bit bit_bswap, 1
  |  lrvr RB, RB
  |  j ->fff_resbit
  |
  |.ffunc_bit bit_bnot, 1
  |  xilf RB, -1
  |  j ->fff_resbit
  |
  |->fff_fallback_bit_op:
  |  lgr NARGS:RD, TMPR1		// Restore for fallback
  |  j ->fff_fallback
  |
  |.macro .ffunc_bit_sh, name, ins
  |  .ffunc_bit name, 1, .ffunc_2
  |  // Note: no inline conversion from number for 2nd argument!
  |  lg RA, 8(BASE)
  |  checkint RA, ->fff_fallback
  |  nill RA, 0x1f	// Limit shift to 5-bits.
  |  ins RB, 0(RA)
  |  j ->fff_resbit
  |.endmacro
  |
  |.ffunc_bit_sh bit_lshift, sll
  |.ffunc_bit_sh bit_rshift, srl
  |.ffunc_bit_sh bit_arshift, sra
  |
  |.ffunc_bit bit_rol, 1, .ffunc_2
  |  // Note: no inline conversion from number for 2nd argument!
  |  lg RA, 8(BASE)
  |  checkint RA, ->fff_fallback
  |  rll RB, RB, 0(RA)
  |  j ->fff_resbit
  |
  |.ffunc_bit bit_ror, 1, .ffunc_2
  |  // Note: no inline conversion from number for 2nd argument!
  |  lg RA, 8(BASE)
  |  checkint RA, ->fff_fallback
  |  lcr RA, RA		// Right rotate equivalent to negative left rotate.
  |  rll RB, RB, 0(RA)
  |  j ->fff_resbit
  |
  |//-----------------------------------------------------------------------
  |
  |->fff_fallback_2:
  |  lghi NARGS:RD, 1+2			// Other args are ignored, anyway.
  |  j ->fff_fallback
  |->fff_fallback_1:
  |  lghi NARGS:RD, 1+1			// Other args are ignored, anyway.
  |->fff_fallback:			// Call fast function fallback handler.
  |  // BASE = new base, RD = nargs+1
  |  lg L:RB, SAVE_L
  |  lg PC, -8(BASE)			// Fallback may overwrite PC.
  |  stg PC, SAVE_PC			// Redundant (but a defined value).
  |  stg BASE, L:RB->base
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -8(RD, BASE)
  |  la RA, (8*LUA_MINSTACK)(RD)	// Ensure enough space for handler.
  |  stg RD, L:RB->top
  |  lg CFUNC:RD, -16(BASE)
  |  cleartp CFUNC:RD
  |  clg RA, L:RB->maxstack
  |  jh >5				// Need to grow stack.
  |  lgr CARG1, L:RB
  |  lg TMPR1, CFUNC:RD->f
  |  basr r14, TMPR1			// (lua_State *L)
  |  lg BASE, L:RB->base
  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.
  |  lgr RD, CRET1
  |  cghi RD, 0; jh ->fff_res	// Returned nresults+1?
  |1:
  |  lg RA, L:RB->top
  |  sgr RA, BASE
  |  srlg RA, RA, 3
  |  cghi RD, 0
  |    la NARGS:RD, 1(RA)
  |    lg LFUNC:RB, -16(BASE)
  |  jne ->vm_call_tail			// Returned -1?
  |  cleartp LFUNC:RB
  |  ins_callt				// Returned 0: retry fast path.
  |
  |// Reconstruct previous base for vmeta_call during tailcall.
  |->vm_call_tail:
  |  lgr RA, BASE
  |  tmll PC, FRAME_TYPE
  |  jne >3
  |  llgc RB, PC_RA
  |  lcgr RB, RB
  |  sllg RB, RB, 3
  |  lay BASE, -16(RB, BASE)		// base = base - (RB+2)*8
  |  j ->vm_call_dispatch		// Resolve again for tailcall.
  |3:
  |  lgr RB, PC
  |  nill RB, -8
  |  sgr BASE, RB
  |  j ->vm_call_dispatch		// Resolve again for tailcall.
  |
  |5:  // Grow stack for fallback handler.
  |  lghi CARG2, LUA_MINSTACK
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_state_growstack	// (lua_State *L, int n)
  |  lg BASE, L:RB->base
  |  lghi RD, 0				// Simulate a return 0.
  |  j <1				// Dumb retry (goes through ff first).
  |
  |->fff_gcstep:			// Call GC step function.
  |  // BASE = new base, RD = nargs+1
  |  stg r14, SAVE_TMP			// Save return address
  |  lg L:RB, SAVE_L
  |  stg PC, SAVE_PC			// Redundant (but a defined value).
  |  stg BASE, L:RB->base
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -8(RD, BASE)
  |  lgr CARG1, L:RB
  |  stg RD, L:RB->top
  |  brasl r14, extern lj_gc_step	// (lua_State *L)
  |  lg BASE, L:RB->base
  |  lg RD, L:RB->top
  |  sgr RD, BASE
  |  srlg RD, RD, 3
  |  aghi NARGS:RD, 1
  |  lg r14, SAVE_TMP			// Restore return address.
  |  br r14
  |
  |//-----------------------------------------------------------------------
  |//-- Special dispatch targets -------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->vm_record:				// Dispatch target for recording phase.
  |  stg r0, 0
  |  stg r0, 0
  |
  |->vm_rethook:			// Dispatch target for return hooks.
  |  llgc RD, (DISPATCH_GL(hookmask))(DISPATCH)
  |  tmll RD, HOOK_ACTIVE
  |  jne >5
  |  j >1
  |
  |->vm_inshook:			// Dispatch target for instr/line hooks.
  |  llgc RD, (DISPATCH_GL(hookmask))(DISPATCH)
  |  tmll RD, HOOK_ACTIVE		// Hook already active?
  |  jne >5
  |
  |  tmll RD, LUA_MASKLINE|LUA_MASKCOUNT
  |  je >5
  |  ly TMPR0, (DISPATCH_GL(hookcount))(DISPATCH)
  |  ahi TMPR0, -1
  |  sty TMPR0, (DISPATCH_GL(hookcount))(DISPATCH)
  |  je >1
  |  tmll RD, LUA_MASKLINE
  |  je >5
  |1:
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  lgr CARG2, PC
  |  lgr CARG1, L:RB
  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
  |  brasl r14, extern lj_dispatch_ins	// (lua_State *L, const BCIns *pc)
  |3:
  |  lg BASE, L:RB->base
  |4:
  |  llgc RA, PC_RA
  |5:
  |  llgc OP, PC_OP
  |  sllg TMPR1, OP, 3
  |  llgh RD, PC_RD
  |  lg TMPR1, GG_DISP2STATIC(TMPR1, DISPATCH)
  |  br TMPR1
  |
  |->cont_hook:				// Continue from hook yield.
  |  stg r0, 0
  |  stg r0, 0
  |
  |->vm_hotloop:			// Hot loop counter underflow.
  |  stg r0, 0
  |  stg r0, 0
  |
  |->vm_callhook:			// Dispatch target for call hooks.
  |  stg PC, SAVE_PC
  |.if JIT
  |  j >1
  |.endif
  |
  |->vm_hotcall:			// Hot call counter underflow.
  |.if JIT
  |  stg PC, SAVE_PC
  |  oill PC, 1				// Marker for hot call.
  |1:
  |.endif
  |  sllg RD, NARGS:RD, 3
  |  lay RD, -8(RD, BASE)
  |  lg L:RB, SAVE_L
  |  stg BASE, L:RB->base
  |  stg RD, L:RB->top
  |  lgr CARG2, PC
  |  lgr CARG1, L:RB
  |  brasl r14, extern lj_dispatch_call	// (lua_State *L, const BCIns *pc)
  |  // ASMFunction returned in r2 (CRET1).
  |  lghi TMPR0, 0
  |  stg TMPR0, SAVE_PC			// Invalidate for subsequent line hook.
  |.if JIT
  |  nill PC, -2
  |.endif
  |  lg BASE, L:RB->base
  |  lg RD, L:RB->top
  |  sgr RD, BASE
  |  lgr RB, CRET1
  |  llgc RA, PC_RA
  |  srl RD, 3
  |  ahi NARGS:RD, 1
  |  llgfr RD, RD
  |  br RB
  |
  |->cont_stitch:			// Trace stitching.
  |  stg r0, 0
  |  stg r0, 0
  |
  |->vm_profhook:			// Dispatch target for profiler hook.
  |  stg r0, 0
  |  stg r0, 0
  |
  |//-----------------------------------------------------------------------
  |//-- Trace exit handler -------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// Called from an exit stub with the exit number on the stack.
  |// The 16 bit exit number is stored with two (sign-extended) push imm8.
  |->vm_exit_handler:
  |  stg r0, 0
  |  stg r0, 0
  |->vm_exit_interp:
  |  stg r0, 0
  |  stg r0, 0
  |
  |//-----------------------------------------------------------------------
  |//-- Math helper functions ----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// FP value rounding. Called by math.floor/math.ceil fast functions.
  |// Value to round is in f0. May clobber f0-f7 and r0. Return address is r14.
  |.macro vm_round, name, mask
  |->name:
  |  lghi r0, 1
  |  cdfbr f1, r0
  |  didbr f0, f2, f1, mask // f0=remainder, f2=quotient.
  |  jnle >1
  |  ldr f0, f2
  |  br r14
  |1: // partial remainder (sanity check)
  |  stg r0, 0
  |.endmacro
  |
  |  vm_round vm_floor, 7 // Round towards -inf.
  |  vm_round vm_ceil,  6 // Round towards +inf.
  |  vm_round vm_trunc, 5 // Round towards 0.
  |
  |// FP modulo x%y. Called by BC_MOD* and vm_arith.
  |->vm_mod: // NYI.
  |  stg r0, 0
  |  stg r0, 0
  |
  |//-----------------------------------------------------------------------
  |//-- Assertions ---------------------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |->assert_bad_for_arg_type:
  |  stg r0, 0
  |  stg r0, 0
#ifdef LUA_USE_ASSERT
#endif
  |
  |//-----------------------------------------------------------------------
  |//-- FFI helper functions -----------------------------------------------
  |//-----------------------------------------------------------------------
  |
  |// Handler for callback functions. Callback slot number in ah/al.
  |->vm_ffi_callback:
  |  stg r0, 0
  |  stg r0, 0
  |
  |->cont_ffi_callback:			// Return from FFI callback.
  |  stg r0, 0
  |  stg r0, 0
  |
  |->vm_ffi_call:			// Call C function via FFI.
  |  // Caveat: needs special frame unwinding, see below.
  |.if FFI
  |  .type CCSTATE, CCallState, r8
  |  stmg r6, r15, 48(sp)
  |  lgr r13, sp			// Use r13 as frame pointer.
  |  lgr CCSTATE, CARG1
  |  lg r7, CCSTATE->func
  |
  |  // Readjust stack.
  |  sgf sp, CCSTATE->spadj
  |
  |  // Copy stack slots.
  |  llgc r1, CCSTATE->nsp
  |  chi r1, 0
  |  jh >2
  |1:
  |  lmg CARG1, CARG5, CCSTATE->gpr[0]
  |  // TODO: conditionally load FPRs?
  |  ld FARG1, CCSTATE->fpr[0]
  |  ld FARG2, CCSTATE->fpr[1]
  |  ld FARG3, CCSTATE->fpr[2]
  |  ld FARG4, CCSTATE->fpr[3]
  |  basr r14, r7
  |
  |  stg CRET1, CCSTATE->gpr[0]
  |  std f0, CCSTATE->fpr[0]
  |
  |  lgr sp, r13
  |  lmg r6, r15, 48(sp)
  |  br r14
  |
  |2:
  |  sll r1, 3
  |  la r10, (offsetof(CCallState, stack))(CCSTATE)	// Source.
  |  la r11, (CCALL_SPS_EXTRA*8)(sp)			// Destination.
  |3:
  |  chi r1, 256
  |  jl >4
  |  mvc 0(256, r11), 0(r10)
  |  la r10, 256(r10)
  |  la r11, 256(r11)
  |  ahi r1, -256
  |  j <3
  |
  |4:
  |  ahi r1, -1
  |  jl <1
  |  larl r9, >5
  |  ex r1, 0(r9)
  |  j <1
  |
  |5:
  |  // exrl target
  |  mvc 0(1, r11), 0(r10)
  |.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;
  (void)vk;
  |// Note: aligning all instructions does not pay off.
  |=>defop:

  switch (op) {

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

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

  |.macro jmp_comp, lt, ge, le, gt, target
  ||switch (op) {
  ||case BC_ISLT:
  |   lt target
  ||break;
  ||case BC_ISGE:
  |   ge target
  ||break;
  ||case BC_ISLE:
  |   le target
  ||break;
  ||case BC_ISGT:
  |   gt target
  ||break;
  ||default: break;  /* Shut up GCC. */
  ||}
  |.endmacro

  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
    |  // RA = src1, RD = src2, JMP with RD = target
    |  ins_AD
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  ld f0, 0(RA, BASE)
    |  ld f1, 0(RD, BASE)
    |  lg RA, 0(RA, BASE)
    |  lg RD, 0(RD, BASE)
    |  srag ITYPE, RA, 47
    |  srag RB, RD, 47
    |
    |  clfi ITYPE, LJ_TISNUM; jne >7
    |  clfi RB, LJ_TISNUM; jne >8
    |  // Both are integers.
    |  la PC, 4(PC)
    |  cr RA, RD
    |  jmp_comp jhe, jl, jh, jle, >9
    |6:
    |  llgh RD, PC_RD
    |  branchPC RD
    |9:
    |  ins_next
    |
    |7:  // RA is not an integer.
    |  jh ->vmeta_comp
    |  // RA is a number.
    |  clfi RB, LJ_TISNUM; jl >1; jne ->vmeta_comp
    |  // RA is a number, RD is an integer.
    |  cdfbr f1, RD
    |  j >1
    |
    |8:  // RA is an integer, RD is not an integer.
    |  jh ->vmeta_comp
    |  // RA is an integer, RD is a number.
    |  cdfbr f0, RA
    |1:
    |  la PC, 4(PC)
    |  cdbr f0, f1
    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
    |  jmp_comp jnl, jl, jnle, jle, <9
    |  j <6
    break;

  case BC_ISEQV: case BC_ISNEV:
    vk = op == BC_ISEQV;
    |  ins_AD	// RA = src1, RD = src2, JMP with RD = target
    |  sllg RD, RD, 3
    |  ld f1, 0(RD, BASE)
    |  lg RD, 0(RD, BASE)
    |  sllg RA, RA, 3
    |  ld f0, 0(RA, BASE)
    |  lg RA, 0(RA, BASE)
    |  la PC, 4(PC)
    |  srag RB, RD, 47
    |  srag ITYPE, RA, 47
    |  clfi RB, LJ_TISNUM; jne >7
    |  clfi ITYPE, LJ_TISNUM; jne >8
    |  cr RD, RA
    if (vk) {
      |  jne >9
    } else {
      |  je >9
    }
    |  llgh RD, PC_RD
    |  branchPC RD
    |9:
    |  ins_next
    |
    |7:  // RD is not an integer.
    |  jh >5
    |  // RD is a number.
    |  clfi ITYPE, LJ_TISNUM; jl >1; jne >5
    |  // RD is a number, RA is an integer.
    |  cdfbr f0, RA
    |  j >1
    |
    |8:  // RD is an integer, RA is not an integer.
    |  jh >5
    |  // RD is an integer, RA is a number.
    |  cdfbr f1, RD
    |  j >1
    |
    |1:
    |  cdbr f0, f1
    |4:
  iseqne_fp:
    if (vk) {
      |  jne >2				// Unordered means not equal.
    } else {
      |  je >1				// Unordered means not equal.
    }
  iseqne_end:
    if (vk) {
      |1:				// EQ: Branch to the target.
      |  llgh RD, PC_RD
      |  branchPC RD
      |2:				// NE: Fallthrough to next instruction.
      |.if not FFI
      |3:
      |.endif
    } else {
      |.if not FFI
      |3:
      |.endif
      |2:				// NE: Branch to the target.
      |  llgh RD, PC_RD
      |  branchPC RD
      |1:				// EQ: Fallthrough to next instruction.
    }
    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||
		       op == BC_ISEQN || op == BC_ISNEN)) {
      |  j <9
    } else {
      |  ins_next
    }
    |
    if (op == BC_ISEQV || op == BC_ISNEV) {
      |5:  // Either or both types are not numbers.
      |.if FFI
      |  clfi RB, LJ_TCDATA; je ->vmeta_equal_cd
      |  clfi ITYPE, LJ_TCDATA; je ->vmeta_equal_cd
      |.endif
      |  cgr RA, RD
      |  je <1				// Same GCobjs or pvalues?
      |  cr RB, ITYPE
      |  jne <2				// Not the same type?
      |  clfi RB, LJ_TISTABUD
      |  jh <2				// Different objects and not table/ud?
      |
      |  // Different tables or userdatas. Need to check __eq metamethod.
      |  // Field metatable must be at same offset for GCtab and GCudata!
      |  cleartp TAB:RA
      |  lg TAB:RB, TAB:RA->metatable
      |  cghi TAB:RB, 0
      |  je <2				// No metatable?
      |  tm TAB:RB->nomm, 1<<MM_eq
      |  jne <2				// Or 'no __eq' flag set?
      if (vk) {
	|  lghi RB, 0			// ne = 0
      } else {
	|  lghi RB, 1			// ne = 1
      }
      |  j ->vmeta_equal		// Handle __eq metamethod.
    } else {
      |.if FFI
      |3:
      |  clfi ITYPE, LJ_TCDATA
      if (LJ_DUALNUM && vk) {
	|  jne <9
      } else {
	|  jne <2
      }
      |  j ->vmeta_equal_cd
      |.endif
    }
    break;
  case BC_ISEQS: case BC_ISNES:
    vk = op == BC_ISEQS;
    |  ins_AND	// RA = src, RD = str const, JMP with RD = target
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  lg RB, 0(RA, BASE)
    |  la PC, 4(PC)
    |  checkstr RB, >3
    |  cg RB, 0(RD, KBASE)
  iseqne_test:
    if (vk) {
      |  jne >2
    } else {
      |  je >1
    }
    goto iseqne_end;
  case BC_ISEQN: case BC_ISNEN:
    vk = op == BC_ISEQN;
    |  ins_AD	// RA = src, RD = num const, JMP with RD = target
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  ld f0, 0(RA, BASE)
    |  lg RB, 0(RA, BASE)
    |  ld f1, 0(RD, KBASE)
    |  lg RD, 0(RD, KBASE)
    |  la PC, 4(PC)
    |  checkint RB, >7
    |  checkint RD, >8
    |  cr RB, RD
    if (vk) {
      |  jne >9
    } else {
      |  je >9
    }
    |  llgh RD, PC_RD
    |  branchPC RD
    |9:
    |  ins_next
    |
    |7:  // RA is not an integer.
    |  jh >3
    |  // RA is a number.
    |  checkint RD, >1
    |  // RA is a number, RD is an integer.
    |  cdfbr f1, RD
    |  j >1
    |
    |8:  // RA is an integer, RD is a number.
    |  cdfbr f0, RB
    |  cdbr f0, f1
    |  j >4
    |1:
    |  cdbr f0, f1
    |4:
    goto iseqne_fp;
  case BC_ISEQP: case BC_ISNEP:
    vk = op == BC_ISEQP;
    |  ins_AND	// RA = src, RD = primitive type (~), JMP with RD = target
    |  sllg RA, RA, 3
    |  lg RB, 0(RA, BASE)
    |  srag RB, RB, 47
    |  la PC, 4(PC)
    |  cr RB, RD
    if (!LJ_HASFFI) goto iseqne_test;
    if (vk) {
      |  jne >3
      |  llgh RD, PC_RD
      |  branchPC RD
      |2:
      |  ins_next
      |3:
      |  cghi RB, LJ_TCDATA; jne <2
      |  j ->vmeta_equal_cd
    } else {
      |  je >2
      |  cghi RB, LJ_TCDATA; je ->vmeta_equal_cd
      |  llgh RD, PC_RD
      |  branchPC RD
      |2:
      |  ins_next
    }
    break;

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

  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
    |  ins_AD	// RA = dst or unused, RD = src, JMP with RD = target
    |  sllg RD, RD, 3
    |  sllg RA, RA, 3
    |  lg ITYPE, 0(RD, BASE)
    |  la PC, 4(PC)
    if (op == BC_ISTC || op == BC_ISFC) {
      |  lgr RB, ITYPE
    }
    |  srag ITYPE, ITYPE, 47
    |  clfi ITYPE, LJ_TISTRUECOND
    if (op == BC_IST || op == BC_ISTC) {
      |  jhe >1
    } else {
      |  jl >1
    }
    if (op == BC_ISTC || op == BC_ISFC) {
      |  stg RB, 0(RA, BASE)
    }
    |  llgh RD, PC_RD
    |  branchPC RD
    |1:					// Fallthrough to the next instruction.
    |  ins_next
    break;

  case BC_ISTYPE:
    |  ins_AD	// RA = src, RD = -type
    |  lghr RD, RD
    |  sllg RA, RA, 3
    |  lg RB, 0(RA, BASE)
    |  srag RB, RB, 47
    |  agr RB, RD
    |  jne ->vmeta_istype
    |  ins_next
    break;
  case BC_ISNUM:
    |  ins_AD	// RA = src, RD = -(TISNUM-1)
    |  sllg TMPR1, RA, 3
    |  lg TMPR1, 0(TMPR1, BASE)
    |  checknumtp TMPR1, ->vmeta_istype
    |  ins_next
    break;
  case BC_MOV:
    |  ins_AD	// RA = dst, RD = src
    |  sllg RD, RD, 3
    |  lg RB, 0(RD, BASE)
    |  sllg RA, RA, 3
    |  stg RB, 0(RA, BASE)
    |  ins_next_
    break;
  case BC_NOT:
    |  ins_AD	// RA = dst, RD = src
    |  sllg RD, RD, 3
    |  sllg RA, RA, 3
    |  lg RB, 0(RD, BASE)
    |  srag RB, RB, 47
    |  load_false RC
    |  cghi RB, LJ_TTRUE
    |  je >1
    |  load_true RC
    |1:
    |  stg RC, 0(RA, BASE)
    |  ins_next
    break;
  case BC_UNM:
    |  ins_AD	// RA = dst, RD = src
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  lg RB, 0(RD, BASE)
    |  checkint RB, >3
    |  lcr RB, RB; jo >2
    |1:
    |  stg RB, 0(RA, BASE)
    |  ins_next
    |2:
    |  llihh RB, 0x41e0 // (double)2^31
    |  j <1
    |3:
    |  jh ->vmeta_unm
    |  // Toggle sign bit.
    |  llihh TMPR0, 0x8000
    |  xgr RB, TMPR0
    |  j <1
    break;
  case BC_LEN:
    |  ins_AD	// RA = dst, RD = src
    |  sllg RD, RD, 3
    |  lg RD, 0(RD, BASE)
    |  checkstr RD, >2
    |  llgf RD, STR:RD->len
    |1:
    |  sllg RA, RA, 3
    |  setint RD
    |  stg RD, 0(RA, BASE)
    |  ins_next
    |2:
    |  cghi ITYPE, LJ_TTAB; jne ->vmeta_len
    |  lgr TAB:CARG1, TAB:RD
#if LJ_52
    |  lg TAB:RB, TAB:RD->metatable
    |  cghi TAB:RB, 0
    |  jne >9
    |3:
#endif
    |->BC_LEN_Z:
    |  brasl r14, extern lj_tab_len	// (GCtab *t)
    |  // Length of table returned in r2 (CRET1).
    |  lgr RD, CRET1
    |  llgc RA, PC_RA
    |  j <1
#if LJ_52
    |9:  // Check for __len.
    |  tm TAB:RB->nomm, 1<<MM_len
    |  jne <3
    |  j ->vmeta_len			// 'no __len' flag NOT set: check.
#endif
    break;

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

    |.macro ins_arithpre
    |  ins_ABC
    |  sllg RB, RB, 3
    |  sllg RC, RC, 3
    |  sllg RA, RA, 3
    |.endmacro
    |
    |.macro ins_arithfp, ins
    |  ins_arithpre
    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
    ||switch (vk) {
    ||case 0:
    |   ld f0, 0(RB, BASE)
    |   ld f1, 0(RC, KBASE)
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, KBASE)
    |   checknumtp RB, ->vmeta_arith_vno
    |   checknumtp RC, ->vmeta_arith_vno
    |   ins f0, f1
    ||  break;
    ||case 1:
    |   ld f1, 0(RB, BASE)
    |   ld f0, 0(RC, KBASE)
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, KBASE)
    |   checknumtp RB, ->vmeta_arith_nvo
    |   checknumtp RC, ->vmeta_arith_nvo
    |   ins f0, f1
    ||  break;
    ||default:
    |   ld f0, 0(RB, BASE)
    |   ld f1, 0(RC, BASE)
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, BASE)
    |   checknumtp RB, ->vmeta_arith_vvo
    |   checknumtp RC, ->vmeta_arith_vvo
    |   ins f0, f1
    ||  break;
    ||}
    |  std f0, 0(RA, BASE)
    |  ins_next
    |.endmacro
    |
    |.macro ins_arithdn, intins
    |  ins_arithpre
    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
    ||switch (vk) {
    ||case 0:
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, KBASE)
    |   checkint RB, ->vmeta_arith_vno
    |   checkint RC, ->vmeta_arith_vno
    |   intins RB, RC; jo ->vmeta_arith_vno
    ||  break;
    ||case 1:
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, KBASE)
    |   checkint RB, ->vmeta_arith_nvo
    |   checkint RC, ->vmeta_arith_nvo
    |   intins RC, RB; jo ->vmeta_arith_nvo
    ||  break;
    ||default:
    |   lg RB, 0(RB, BASE)
    |   lg RC, 0(RC, BASE)
    |   checkint RB, ->vmeta_arith_vvo
    |   checkint RC, ->vmeta_arith_vvo
    |   intins RB, RC; jo ->vmeta_arith_vvo
    ||  break;
    ||}
    ||if (vk == 1) {
    |   // setint RC
    |   stg RC, 0(RA, BASE)
    ||} else {
    |   // setint RB
    |   stg RB, 0(RA, BASE)
    ||}
    |  ins_next
    |.endmacro

    |  // RA = dst, RB = src1 or num const, RC = src2 or num const
  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
    |  ins_arithdn ar
    break;
  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
    |  ins_arithdn sr
    break;
  case BC_MULVN: case BC_MULNV: case BC_MULVV:
    |  ins_arithpre
    |  // For multiplication we use msgfr and check if the result
    |  // fits in an int32_t.
    switch(op) {
    case BC_MULVN:
      |  lg RB, 0(RB, BASE)
      |  lg RC, 0(RC, KBASE)
      |  checkint RB, ->vmeta_arith_vno
      |  checkint RC, ->vmeta_arith_vno
      |  lgfr RB, RB
      |  msgfr RB, RC
      |  lgfr RC, RB
      |  cgr RB, RC; jne ->vmeta_arith_vno
      break;
    case BC_MULNV:
      |  lg RB, 0(RB, BASE)
      |  lg RC, 0(RC, KBASE)
      |  checkint RB, ->vmeta_arith_nvo
      |  checkint RC, ->vmeta_arith_nvo
      |  lgfr RB, RB
      |  msgfr RB, RC
      |  lgfr RC, RB
      |  cgr RB, RC; jne ->vmeta_arith_nvo
      break;
    default:
      |  lg RB, 0(RB, BASE)
      |  lg RC, 0(RC, BASE)
      |  checkint RB, ->vmeta_arith_vvo
      |  checkint RC, ->vmeta_arith_vvo
      |  lgfr RB, RB
      |  msgfr RB, RC
      |  lgfr RC, RB
      |  cgr RB, RC; jne ->vmeta_arith_vvo
      break;
    }
    |  llgfr RB, RB
    |  setint RB
    |  stg RB, 0(RA, BASE)
    |  ins_next
    break;
  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
    |  ins_arithfp ddbr
    break;
  // TODO: implement fast mod operation.
  // x86_64 does floating point mod, however it might be better to use integer mod.
  case BC_MODVN:
    |  j ->vmeta_arith_vno
    break;
  case BC_MODNV:
    |  j ->vmeta_arith_nvo
    break;
  case BC_MODVV:
    |  j ->vmeta_arith_vvo
    break;
  case BC_POW:
    |  ins_ABC
    |  sllg RB, RB, 3
    |  sllg RC, RC, 3
    |  ld FARG1, 0(RB, BASE)
    |  ld FARG2, 0(RC, BASE)
    |  lg TMPR0, 0(RB, BASE)
    |  checknumtp TMPR0, ->vmeta_arith_vvo
    |  lg TMPR0, 0(RC, BASE)
    |  checknumtp TMPR0, ->vmeta_arith_vvo
    |  brasl r14, extern pow	// double pow(double x, double y), result in f0.
    |  llgc RA, PC_RA
    |  sllg RA, RA, 3
    |  std f0, 0(RA, BASE)
    |  ins_next
    break;

  case BC_CAT:
    |  ins_ABC	// RA = dst, RB = src_start, RC = src_end
    |  lg L:CARG1, SAVE_L
    |  stg BASE, L:CARG1->base
    |  lgr CARG3, RC
    |  sgr CARG3, RB
    |  sllg RC, RC, 3
    |  la CARG2, 0(RC, BASE)
    |->BC_CAT_Z:
    |  lgr L:RB, L:CARG1
    |  stg PC, SAVE_PC
    |  brasl r14, extern lj_meta_cat		// (lua_State *L, TValue *top, int left)
    |  // NULL (finished) or TValue * (metamethod) returned in r2 (CRET1).
    |  lg BASE, L:RB->base
    |  ltgr RC, CRET1
    |  jne ->vmeta_binop
    |  llgc RB, PC_RB			// Copy result to Stk[RA] from Stk[RB].
    |  sllg RB, RB, 3
    |  llgc RA, PC_RA
    |  sllg RA, RA, 3
    |  lg RC, 0(RB, BASE)
    |  stg RC, 0(RA, BASE)
    |  ins_next
    break;

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

  case BC_KSTR:
    |  ins_AND	// RA = dst, RD = str const (~)
    |  sllg RD, RD, 3
    |  lg RD, 0(RD, KBASE)
    |  settp RD, LJ_TSTR
    |  sllg RA, RA, 3
    |  stg RD, 0(RA, BASE)
    |  ins_next
    break;
  case BC_KCDATA:
    |.if FFI
    |  ins_AND	// RA = dst, RD = cdata const (~)
    |  sllg RD, RD, 3
    |  sllg RA, RA, 3
    |  lg RD, 0(RD, KBASE)
    |  settp RD, LJ_TCDATA
    |  stg RD, 0(RA, BASE)
    |  ins_next
    |.endif
    break;
  case BC_KSHORT:
    |  ins_AD	// RA = dst, RD = signed int16 literal
    |  // Assumes DUALNUM.
    |  lhr RD, RD			// Sign-extend literal to 32-bits.
    |  setint RD
    |  sllg RA, RA, 3
    |  stg RD, 0(RA, BASE)
    |  ins_next
    break;
  case BC_KNUM:
    |  ins_AD	// RA = dst, RD = num const
    |  sllg RD, RD, 3
    |  ld f0, 0(RD, KBASE)
    |  sllg RA, RA, 3
    |  std f0, 0(RA, BASE)
    |  ins_next
    break;
  case BC_KPRI:
    |  ins_AD	// RA = dst, RD = primitive type (~)
    |  sllg RA, RA, 3
    |  sllg RD, RD, 47
    |  lghi TMPR0, -1
    |  xgr RD, TMPR0 // not
    |  stg RD, 0(RA, BASE)
    |  ins_next
    break;
  case BC_KNIL:
    |  ins_AD	// RA = dst_start, RD = dst_end
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  la RA, 8(RA, BASE)
    |  la RD, 0(RD, BASE)
    |  lghi RB, LJ_TNIL
    |  stg RB, -8(RA)			// Sets minimum 2 slots.
    |1:
    |  stg RB, 0(RA)
    |  la RA, 8(RA)
    |  clgr RA, RD
    |  jle <1
    |  ins_next
    break;

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

  case BC_UGET:
    |  ins_AD	// RA = dst, RD = upvalue #
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  lg LFUNC:RB, -16(BASE)
    |  cleartp LFUNC:RB
    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RD, LFUNC:RB)
    |  lg RB, UPVAL:RB->v
    |  lg RD, 0(RB)
    |  stg RD, 0(RA, BASE)
    |  ins_next
    break;
  case BC_USETV:
#define TV2MARKOFS \
 ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
    |  ins_AD	// RA = upvalue #, RD = src
    |  lg LFUNC:RB, -16(BASE)
    |  cleartp LFUNC:RB
    |  sllg RA, RA, 3
    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)
    |  tm UPVAL:RB->closed, 0xff
    |  lg RB, UPVAL:RB->v
    |  sllg TMPR1, RD, 3
    |  lg RA, 0(TMPR1, BASE)
    |  stg RA, 0(RB)
    |  je >1
    |  // Check barrier for closed upvalue.
    |  tmy TV2MARKOFS(RB), LJ_GC_BLACK		// isblack(uv)
    |  jne >2
    |1:
    |  ins_next
    |
    |2:  // Upvalue is black. Check if new value is collectable and white.
    |  srag RD, RA, 47
    |  ahi RD, -LJ_TISGCV
    |  clfi RD, LJ_TNUMX - LJ_TISGCV		// tvisgcv(v)
    |  jle <1
    |  cleartp GCOBJ:RA
    |  tm GCOBJ:RA->gch.marked, LJ_GC_WHITES	// iswhite(v)
    |  je <1
    |  // Crossed a write barrier. Move the barrier forward.
    |  lgr CARG2, RB
    |  lay GL:CARG1, GG_DISP2G(DISPATCH)
    |  brasl r14, extern lj_gc_barrieruv	// (global_State *g, TValue *tv)
    |  j <1
    break;
#undef TV2MARKOFS
  case BC_USETS:
    |  ins_AND	// RA = upvalue #, RD = str const (~)
    |  lg LFUNC:RB, -16(BASE)
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  cleartp LFUNC:RB
    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)
    |  lg STR:RA, 0(RD, KBASE)
    |  lg RD, UPVAL:RB->v
    |  settp STR:ITYPE, STR:RA, LJ_TSTR
    |  stg STR:ITYPE, 0(RD)
    |  tm UPVAL:RB->marked, LJ_GC_BLACK		// isblack(uv)
    |  jne >2
    |1:
    |  ins_next
    |
    |2:  // Check if string is white and ensure upvalue is closed.
    |  tm GCOBJ:RA->gch.marked, LJ_GC_WHITES	// iswhite(str)
    |  je <1
    |  tm UPVAL:RB->closed, 0xff
    |  je <1
    |  // Crossed a write barrier. Move the barrier forward.
    |  lgr CARG2, RD
    |  lay GL:CARG1, GG_DISP2G(DISPATCH)
    |  brasl r14, extern lj_gc_barrieruv	// (global_State *g, TValue *tv)
    |  j <1
    break;
  case BC_USETN:
    |  ins_AD	// RA = upvalue #, RD = num const
    |  lg LFUNC:RB, -16(BASE)
    |  sllg RA, RA, 3
    |  sllg RD, RD, 3
    |  cleartp LFUNC:RB
    |  ld f0, 0(RD, KBASE)
    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)
    |  lg RA, UPVAL:RB->v
    |  std f0, 0(RA)
    |  ins_next
    break;
  case BC_USETP:
    |  ins_AD	// RA = upvalue #, RD = primitive type (~)
    |  lg LFUNC:RB, -16(BASE)
    |  sllg RA, RA, 3
    |  cleartp LFUNC:RB
    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)
    |  sllg RD, RD, 47
    |  lghi TMPR0, -1
    |  xgr RD, TMPR0
    |  lg RA, UPVAL:RB->v
    |  stg RD, 0(RA)
    |  ins_next
    break;
  case BC_UCLO:
    |  ins_AD	// RA = level, RD = target
    |  branchPC RD				// Do this first to free RD.
    |  lg L:RB, SAVE_L
    |  ltg TMPR0, L:RB->openupval
    |  je >1
    |  stg BASE, L:RB->base
    |  sllg RA, RA, 3
    |  la CARG2, 0(RA, BASE)
    |  lgr L:CARG1, L:RB
    |  brasl r14, extern lj_func_closeuv	// (lua_State *L, TValue *level)
    |  lg BASE, L:RB->base
    |1:
    |  ins_next
    break;

  case BC_FNEW:
    |  ins_AND	// RA = dst, RD = proto const (~) (holding function prototype)
    |  lg L:RB, SAVE_L
    |  stg BASE, L:RB->base
    |  lg CARG3, -16(BASE)
    |  cleartp CARG3
    |  sllg RD, RD, 3
    |  lg CARG2, 0(RD, KBASE)		// Fetch GCproto *.
    |  lgr CARG1, L:RB
    |  stg PC, SAVE_PC
    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)
    |  brasl r14, extern lj_func_newL_gc
    |  // GCfuncL * returned in r2 (CRET1).
    |  lg BASE, L:RB->base
    |  llgc RA, PC_RA
    |  sllg RA, RA, 3
    |  settp LFUNC:CRET1, LJ_TFUNC
    |  stg LFUNC:CRET1, 0(RA, BASE)
    |  ins_next
    break;
  case BC_TNEW:
    |  ins_AD	// RA = dst, RD = hbits|asize
    |  lg L:RB, SAVE_L
    |  stg BASE, L:RB->base
    |  lg RA, (DISPATCH_GL(gc.total))(DISPATCH)
    |  clg RA, (DISPATCH_GL(gc.threshold))(DISPATCH)
    |  stg PC, SAVE_PC
    |  jhe >5
    |1:
    |  srlg CARG3, RD, 11
    |  llill TMPR0, 0x7ff
    |  nr RD, TMPR0
    |  cr RD, TMPR0
    |  je >3
    |2:
    |  lgr L:CARG1, L:RB
    |  llgfr CARG2, RD
    |  brasl r14, extern lj_tab_new  // (lua_State *L, uint32_t asize, uint32_t hbits)
    |  // Table * returned in r2 (CRET1).
    |  lg BASE, L:RB->base
    |  llgc RA, PC_RA
    |  sllg RA, RA, 3
    |  settp TAB:CRET1, LJ_TTAB
    |  stg TAB:CRET1, 0(RA, BASE)
    |  ins_next
    |3:  // Turn 0x7ff into 0x801.
    |  llill RD, 0x801
    |  j <2
    |5:
    |  lgr L:CARG1, L:RB
    |  brasl r14, extern lj_gc_step_fixtop	// (lua_State *L)
    |  llgh RD, PC_RD
    |  j <1
    break;
  case BC_TDUP:
    |  ins_AND	// RA = dst, RD = table const (~) (holding template table)
    |  lg L:RB, SAVE_L
    |  lg RA, (DISPATCH_GL(gc.total))(DISPATCH)
    |  stg PC, SAVE_PC
    |  clg RA, (DISPATCH_GL(gc.threshold))(DISPATCH)
    |  stg BASE, L:RB->base
    |  jhe >3
    |2:
    |  sllg RD, RD, 3
    |  lg TAB:CARG2, 0(RD, KBASE)
    |  lgr L:CARG1, L:RB
    |  brasl r14, extern lj_tab_dup		// (lua_State *L, Table *kt)
    |  // Table * returned in r2 (CRET1).
    |  lg BASE, L:RB->base
    |  llgc RA, PC_RA
    |  settp TAB:CRET1, LJ_TTAB
    |  sllg RA, RA, 3
    |  stg TAB:CRET1, 0(RA, BASE)
    |  ins_next
    |3:
    |  lgr L:CARG1, L:RB
    |  brasl r14, extern lj_gc_step_fixtop	// (lua_State *L)
    |  llgh RD, PC_RD				// Need to reload RD.
    |  lghi TMPR0, -1
    |  xgr RD, TMPR0				// not RD
    |  j <2
    break;

  case BC_GGET:
    |  ins_AND	// RA = dst, RD = str const (~)
    |  lg LFUNC:RB, -16(BASE)
    |  cleartp LFUNC:RB
    |  lg TAB:RB, LFUNC:RB->env
    |  sllg TMPR1, RD, 3
    |  lg STR:RC, 0(TMPR1, KBASE)
    |  j ->BC_TGETS_Z
    break;
  case BC_GSET:
    |  ins_AND	// RA = src, RD = str const (~)
    |  lg LFUNC:RB, -16(BASE)
    |  cleartp LFUNC:RB
    |  lg TAB:RB, LFUNC:RB->env
    |  sllg TMPR1, RD, 3
    |  lg STR:RC, 0(TMPR1, KBASE)
    |  j ->BC_TSETS_Z
    break;

  case BC_TGETV:
    |  ins_ABC	// RA = dst, RB = table, RC = key
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  sllg RC, RC, 3
    |  lg RC, 0(RC, BASE)
    |  checktab TAB:RB, ->vmeta_tgetv
    |
    |  // Integer key?
    |  checkint RC, >5
    |  cl RC, TAB:RB->asize		// Takes care of unordered, too.
    |  jhe ->vmeta_tgetv		// Not in array part? Use fallback.
    |  llgfr RC, RC
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  // Get array slot.
    |  lg ITYPE, 0(RC)
    |  cghi ITYPE, LJ_TNIL		// Avoid overwriting RB in fastpath.
    |  je >2
    |1:
    |  sllg RA, RA, 3
    |  stg ITYPE, 0(RA, BASE)
    |  ins_next
    |
    |2:  // Check for __index if table value is nil.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je <1
    |  tm TAB:TMPR1->nomm, 1<<MM_index
    |  je ->vmeta_tgetv			// 'no __index' flag NOT set: check.
    |  j <1
    |
    |5:  // String key?
    |  cghi ITYPE, LJ_TSTR; jne ->vmeta_tgetv
    |  cleartp STR:RC
    |  j ->BC_TGETS_Z
    break;
  case BC_TGETS:
    |  ins_ABC
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  lghi TMPR1, -1
    |  xgr RC, TMPR1
    |  sllg RC, RC, 3
    |  lg STR:RC, 0(RC, KBASE)
    |  checktab TAB:RB, ->vmeta_tgets
    |->BC_TGETS_Z:	// RB = GCtab *, RC = GCstr *
    |  l TMPR1, TAB:RB->hmask
    |  n TMPR1, STR:RC->hash
    |  lgfr TMPR1, TMPR1
    |  mghi TMPR1, #NODE
    |  ag NODE:TMPR1, TAB:RB->node
    |  settp ITYPE, STR:RC, LJ_TSTR
    |1:
    |  cg ITYPE, NODE:TMPR1->key
    |  jne >4
    |  // Get node value.
    |  lg ITYPE, NODE:TMPR1->val
    |  cghi ITYPE, LJ_TNIL
    |  je >5				// Key found, but nil value?
    |2:
    |  sllg RA, RA, 3
    |  stg ITYPE, 0(RA, BASE)
    |  ins_next
    |
    |4:  // Follow hash chain.
    |  lg NODE:TMPR1, NODE:TMPR1->next
    |  cghi NODE:TMPR1, 0
    |  jne <1
    |  // End of hash chain: key not found, nil result.
    |  lghi ITYPE, LJ_TNIL
    |
    |5:  // Check for __index if table value is nil.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je <2				// No metatable: done.
    |  tm TAB:TMPR1->nomm, 1<<MM_index
    |  jne <2				// 'no __index' flag set: done.
    |  j ->vmeta_tgets			// Caveat: preserve STR:RC.
    break;
  case BC_TGETB:
    |  ins_ABC	// RA = dst, RB = table, RC = byte literal
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  checktab TAB:RB, ->vmeta_tgetb
    |  cl RC, TAB:RB->asize
    |  jhe ->vmeta_tgetb
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  // Get array slot.
    |  lg ITYPE, 0(RC)
    |  cghi ITYPE, LJ_TNIL
    |  je >2
    |1:
    |  sllg RA, RA, 3
    |  stg ITYPE, 0(RA, BASE)
    |  ins_next
    |
    |2:  // Check for __index if table value is nil.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je <1
    |  tm TAB:TMPR1->nomm, 1<<MM_index
    |  je ->vmeta_tgetb			// 'no __index' flag NOT set: check.
    |  j <1
    break;
  case BC_TGETR:
    |  ins_ABC	// RA = dst, RB = table, RC = key
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  cleartp TAB:RB
    |  sllg RC, RC, 3
    |  llgf RC, 4(RC, BASE)		// Load low word (big endian).
    |  cl RC, TAB:RB->asize
    |  jhe ->vmeta_tgetr		// Not in array part? Use fallback.
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  // Get array slot.
    |->BC_TGETR_Z:
    |  lg ITYPE, 0(RC)
    |->BC_TGETR2_Z:
    |  sllg RA, RA, 3
    |  stg ITYPE, 0(RA, BASE)
    |  ins_next
    break;

  case BC_TSETV:
    |  ins_ABC	// RA = src, RB = table, RC = key
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  sllg RC, RC, 3
    |  lg RC, 0(RC, BASE)
    |  checktab TAB:RB, ->vmeta_tsetv
    |
    |  // Integer key?
    |  checkint RC, >5
    |  cl RC, TAB:RB->asize		// Takes care of unordered, too.
    |  jhe ->vmeta_tsetv
    |  llgfr RC, RC
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  lghi TMPR0, LJ_TNIL
    |  cg TMPR0, 0(RC)
    |  je >3				// Previous value is nil?
    |1:
    |  tm TAB:RB->marked, LJ_GC_BLACK	// isblack(table)
    |  jne >7
    |2:  // Set array slot.
    |  sllg RA, RA, 3
    |  lg RB, 0(RA, BASE)
    |  stg RB, 0(RC)
    |  ins_next
    |
    |3:  // Check for __newindex if previous value is nil.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je <1
    |  tm TAB:TMPR1->nomm, 1<<MM_newindex
    |  je ->vmeta_tsetv			// 'no __newindex' flag NOT set: check.
    |  j <1
    |
    |5:  // String key?
    |  cghi ITYPE, LJ_TSTR; jne ->vmeta_tsetv
    |  cleartp STR:RC
    |  j ->BC_TSETS_Z
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMPR1
    |  j <2
    break;
  case BC_TSETS:
    |  ins_ABC	// RA = src, RB = table, RC = str const (~)
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  lghi TMPR0, -1
    |  xgr RC, TMPR0 // ~RC
    |  sllg RC, RC, 3
    |  lg STR:RC, 0(RC, KBASE)
    |  checktab TAB:RB, ->vmeta_tsets
    |->BC_TSETS_Z:	// RB = GCtab *, RC = GCstr *
    |  l TMPR1, TAB:RB->hmask
    |  n TMPR1, STR:RC->hash
    |  lgfr TMPR1, TMPR1
    |  mghi TMPR1, #NODE
    |  mvi TAB:RB->nomm, 0		// Clear metamethod cache.
    |  ag NODE:TMPR1, TAB:RB->node
    |  settp ITYPE, STR:RC, LJ_TSTR
    |1:
    |  cg ITYPE, NODE:TMPR1->key
    |  jne >5
    |  // Ok, key found. Assumes: offsetof(Node, val) == 0
    |  lghi TMPR0, LJ_TNIL
    |  cg TMPR0, 0(TMPR1)
    |  je >4				// Previous value is nil?
    |2:
    |  tm TAB:RB->marked, LJ_GC_BLACK	// isblack(table)
    |  jne >7
    |3:  // Set node value.
    |  sllg RA, RA, 3
    |  lg ITYPE, 0(RA, BASE)
    |  stg ITYPE, 0(TMPR1)
    |  ins_next
    |
    |4:  // Check for __newindex if previous value is nil.
    |  lg TAB:ITYPE, TAB:RB->metatable
    |  cghi TAB:ITYPE, 0
    |  je <2
    |  tm TAB:ITYPE->nomm, 1<<MM_newindex
    |  je ->vmeta_tsets			// 'no __newindex' flag NOT set: check.
    |  j <2
    |
    |5:  // Follow hash chain.
    |  lg NODE:TMPR1, NODE:TMPR1->next
    |  cghi NODE:TMPR1, 0
    |  jne <1
    |  // End of hash chain: key not found, add a new one.
    |
    |  // But check for __newindex first.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je >6				// No metatable: continue.
    |  tm TAB:TMPR1->nomm, 1<<MM_newindex
    |  je ->vmeta_tsets			// 'no __newindex' flag NOT set: check.
    |6:
    |  stg ITYPE, SAVE_TMP
    |  lg L:CARG1, SAVE_L
    |  stg BASE, L:CARG1->base
    |  la CARG3, SAVE_TMP
    |  lgr CARG2, TAB:RB
    |  stg PC, SAVE_PC
    |  brasl r14, extern lj_tab_newkey	// (lua_State *L, GCtab *t, TValue *k)
    |  // Handles write barrier for the new key. TValue * returned in r2 (CRET1).
    |  lgr TMPR1, CRET1
    |  lg L:CRET1, SAVE_L
    |  lg BASE, L:CRET1->base
    |  llgc RA, PC_RA
    |  j <2				// Must check write barrier for value.
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, ITYPE
    |  j <3
    break;
  case BC_TSETB:
    |  ins_ABC	// RA = src, RB = table, RC = byte literal
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  checktab TAB:RB, ->vmeta_tsetb
    |  cl RC, TAB:RB->asize
    |  jhe ->vmeta_tsetb
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  lghi TMPR0, LJ_TNIL
    |  cg TMPR0, 0(RC)
    |  je >3				// Previous value is nil?
    |1:
    |  tm TAB:RB->marked, LJ_GC_BLACK		// isblack(table)
    |  jne >7
    |2:	 // Set array slot.
    |  sllg RA, RA, 3
    |  lg ITYPE, 0(RA, BASE)
    |  stg ITYPE, 0(RC)
    |  ins_next
    |
    |3:  // Check for __newindex if previous value is nil.
    |  lg TAB:TMPR1, TAB:RB->metatable
    |  cghi TAB:TMPR1, 0
    |  je <1
    |  tm TAB:TMPR1->nomm, 1<<MM_newindex
    |  je ->vmeta_tsetb			// 'no __newindex' flag NOT set: check.
    |  j <1
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMPR1
    |  j <2
    break;
  case BC_TSETR:
    |  ins_ABC	// RA = src, RB = table, RC = key
    |  sllg RB, RB, 3
    |  lg TAB:RB, 0(RB, BASE)
    |  cleartp TAB:RB
    |  sllg RC, RC, 3
    |  lg RC, 0(RC, BASE)
    |  tm TAB:RB->marked, LJ_GC_BLACK			// isblack(table)
    |  jne >7
    |2:
    |  cl RC, TAB:RB->asize
    |  jhe ->vmeta_tsetr
    |  llgfr RC, RC
    |  sllg RC, RC, 3
    |  ag RC, TAB:RB->array
    |  // Set array slot.
    |->BC_TSETR_Z:
    |  sllg RA, RA, 3
    |  lg ITYPE, 0(RA, BASE)
    |  stg ITYPE, 0(RC)
    |  ins_next
    |
    |7:  // Possible table write barrier for the value. Skip valiswhite check.
    |  barrierback TAB:RB, TMPR1
    |  j <2
    break;

  case BC_TSETM:
    |  ins_AD	// RA = base (table at base-1), RD = num const (start index)
    |1:
    |  sllg RA, RA, 3
    |  sllg TMPR1, RD, 3
    |  llgf TMPR1, 4(TMPR1, KBASE)	// Integer constant is in lo-word.
    |  la RA, 0(RA, BASE)
    |  lg TAB:RB, -8(RA)		// Guaranteed to be a table.
    |  cleartp TAB:RB
    |  tm TAB:RB->marked, LJ_GC_BLACK		// isblack(table)
    |  jne >7
    |2:
    |  llgf RD, SAVE_MULTRES
    |  aghi RD, -1
    |  je >4				// Nothing to copy?
    |  agr RD, TMPR1			// Compute needed size.
    |  clgf RD, TAB:RB->asize
    |  jh >5				// Doesn't fit into array part?
    |  sgr RD, TMPR1
    |  sllg TMPR1, TMPR1, 3
    |  ag TMPR1, TAB:RB->array
    |3:  // Copy result slots to table.
    |  lg RB, 0(RA)
    |  la RA, 8(RA)
    |  stg RB, 0(TMPR1)
    |  la TMPR1, 8(TMPR1)
    |  brctg RD, <3
    |4:
    |  ins_next
    |
    |5:  // Need to resize array part.
    |  lg L:CARG1, SAVE_L
    |  stg BASE, L:CARG1->base
    |  lgr CARG2, TAB:RB
    |  lgfr CARG3, RD
    |  lgr L:RB, L:CARG1
    |  stg PC, SAVE_PC
    |  brasl r14, extern lj_tab_reasize	// (lua_State *L, GCtab *t, int nasize)
    |  lg BASE, L:RB->base
    |  llgc RA, PC_RA			// Restore RA.
    |  llgh RD, PC_RD			// Restore RD.
    |  j <1				// Retry.
    |
    |7:  // Possible table write barrier for any value. Skip valiswhite check.
    |  barrierback TAB:RB, RD
    |  j <2
    break;

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

  case BC_CALL: case BC_CALLM:
    |  ins_A_C	// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs
    |  sllg RA, RA, 3
    |  lgr RD, RC
    if (op == BC_CALLM) {
      |  agf NARGS:RD, SAVE_MULTRES
    }
    |  lg LFUNC:RB, 0(RA, BASE)
    |  checkfunc LFUNC:RB, ->vmeta_call_ra
    |  la BASE, 16(RA, BASE)
    |  ins_call
    break;

  case BC_CALLMT:
    |  ins_AD	// RA = base, RD = extra_nargs
    |  a NARGS:RD, SAVE_MULTRES
    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.
    break;
  case BC_CALLT:
    |  ins_AD	// RA = base, RD = nargs+1
    |  sllg RA, RA, 3
    |  la RA, 16(RA, BASE)
    |  lgr KBASE, BASE			// Use KBASE for move + vmeta_call hint.
    |  lg LFUNC:RB, -16(RA)
    |  checktp_nc LFUNC:RB, LJ_TFUNC, ->vmeta_call
    |->BC_CALLT_Z:
    |  lg PC, -8(BASE)
    |  tmll PC, FRAME_TYPE
    |  jne >7
    |1:
    |  stg LFUNC:RB, -16(BASE)		// Copy func+tag down, reloaded below.
    |  st NARGS:RD, SAVE_MULTRES
    |  aghi NARGS:RD, -1
    |  je >3
    |2:  // Move args down.
    |  lg RB, 0(RA)
    |  la RA, 8(RA)
    |  stg RB, 0(KBASE)
    |  la KBASE, 8(KBASE)
    |  brctg NARGS:RD, <2
    |
    |  lg LFUNC:RB, -16(BASE)
    |3:
    |  cleartp LFUNC:RB
    |  llgf NARGS:RD, SAVE_MULTRES
    |  llgc TMPR1, LFUNC:RB->ffid
    |  cghi TMPR1, 1			// (> FF_C) Calling a fast function?
    |  jh >5
    |4:
    |  ins_callt
    |
    |5:  // Tailcall to a fast function.
    |  tmll PC, FRAME_TYPE		// Lua frame below?
    |  jne <4
    |  llgc RA, PC_RA
    |  lcgr RA, RA
    |  sllg RA, RA, 3
    |  lg LFUNC:KBASE, -32(RA, BASE)	// Need to prepare KBASE.
    |  cleartp LFUNC:KBASE
    |  lg KBASE, LFUNC:KBASE->pc
    |  lg KBASE, (PC2PROTO(k))(KBASE)
    |  j <4
    |
    |7:  // Tailcall from a vararg function.
    |  aghi PC, -FRAME_VARG
    |  tmll PC, FRAME_TYPEP
    |  jne >8				// Vararg frame below?
    |  sgr BASE, PC			// Need to relocate BASE/KBASE down.
    |  lgr KBASE, BASE
    |  lg PC, -8(BASE)
    |  j <1
    |8:
    |  aghi PC, FRAME_VARG
    |  j <1
    break;

  case BC_ITERC:
    |  ins_A	// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)
    |  sllg RA, RA, 3
    |  la RA, 16(RA, BASE)		// fb = base+2
    |  lg RB, -32(RA)			// Copy state. fb[0] = fb[-4].
    |  lg RC, -24(RA)			// Copy control var. fb[1] = fb[-3].
    |  stg RB, 0(RA)
    |  stg RC, 8(RA)
    |  lg LFUNC:RB, -40(RA)		// Copy callable. fb[-2] = fb[-5]
    |  stg LFUNC:RB, -16(RA)
    |  lghi NARGS:RD, 2+1		// Handle like a regular 2-arg call.
    |  checkfunc LFUNC:RB, ->vmeta_call
    |  lgr BASE, RA
    |  ins_call
    break;

  case BC_ITERN:
    |  ins_A	// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))
    |.if JIT
    |  // NYI: add hotloop, record BC_ITERN.
    |.endif
    |  sllg RA, RA, 3
    |  lg TAB:RB, -16(RA, BASE)
    |  cleartp TAB:RB
    |  llgf RC, -4(RA, BASE)		// Get index from control var.
    |  llgf TMPR1, TAB:RB->asize
    |  la PC, 4(PC)
    |  lg ITYPE, TAB:RB->array
    |1:  // Traverse array part.
    |  clr RC, TMPR1; jhe >5		// Index points after array part?
    |  sllg RD, RC, 3		// Warning: won't work if RD==RC!
    |  lg TMPR0, 0(RD, ITYPE)
    |  cghi TMPR0, LJ_TNIL;  je >4
    |  // Copy array slot to returned value.
    |  lgr RB, TMPR0
    |  stg RB, 8(RA, BASE)
    |  // Return array index as a numeric key.
    |  setint ITYPE, RC
    |  stg ITYPE, 0(RA, BASE)
    |  ahi RC, 1
    |  sty RC, -4(RA, BASE)		// Update control var.
    |2:
    |  llgh RD, PC_RD			// Get target from ITERL.
    |  branchPC RD
    |3:
    |  ins_next
    |
    |4:  // Skip holes in array part.
    |  ahi RC, 1
    |  j <1
    |
    |5:  // Traverse hash part.
    |  sr RC, TMPR1
    |6:
    |  cl RC, TAB:RB->hmask; jh <3	// End of iteration? Branch to ITERL+1.
    |  llgfr ITYPE, RC
    |  mghi ITYPE, #NODE
    |  ag NODE:ITYPE, TAB:RB->node
    |  lghi TMPR0, LJ_TNIL
    |  cg TMPR0, NODE:ITYPE->val; je >7
    |  ar TMPR1, RC
    |  ahi TMPR1, 1
    |  // Copy key and value from hash slot.
    |  lg RB, NODE:ITYPE->key
    |  lg RC, NODE:ITYPE->val
    |  stg RB, 0(RA, BASE)
    |  stg RC, 8(RA, BASE)
    |  sty TMPR1, -4(RA, BASE)
    |  j <2
    |
    |7:  // Skip holes in hash part.
    |  ahi RC, 1
    |  j <6
    break;

  case BC_ISNEXT:
    |  ins_AD	// RA = base, RD = target (points to ITERN)
    |  sllg RA, RA, 3
    |  lg CFUNC:RB, -24(RA, BASE)
    |  checkfunc CFUNC:RB, >5
    |  lg TMPR1, -16(RA, BASE)
    |  checktptp TMPR1, LJ_TTAB, >5
    |  lghi TMPR0, LJ_TNIL
    |  cg TMPR0, -8(RA, BASE); jne >5
    |  llgc TMPR1, CFUNC:RB->ffid
    |  clfi TMPR1, (uint8_t)FF_next_N; jne >5
    |  branchPC RD
    |  llihl TMPR1, 0x7fff
    |  iihh TMPR1, 0xfffe
    |  stg TMPR1, -8(RA, BASE)		// Initialize control var.
    |1:
    |  ins_next
    |5:  // Despecialize bytecode if any of the checks fail.
    |  lghi TMPR0, BC_JMP
    |  stcy  TMPR0, PC_OP
    |  branchPC RD
    |  mvi 3(PC), BC_ITERC
    |  j <1
    break;

  case BC_VARG:
    |  ins_ABC	// RA = base, RB = nresults+1, RC = numparams
    |  sllg RA, RA, 3
    |  sllg RB, RB, 3
    |  sllg RC, RC, 3
    |  la TMPR1, (16+FRAME_VARG)(RC, BASE)
    |  la RA, 0(RA, BASE)
    |  sg TMPR1, -8(BASE)
    |  // Note: TMPR1 may now be even _above_ BASE if nargs was < numparams.
    |  cghi RB, 0
    |  je >5				// Copy all varargs?
    |  lay RB, -8(RA, RB)
    |  clgr TMPR1, BASE			// No vararg slots?
    |  lghi TMPR0, LJ_TNIL
    |  jnl >2
    |1:  // Copy vararg slots to destination slots.
    |  lg RC, -16(TMPR1)
    |  la TMPR1, 8(TMPR1)
    |  stg RC, 0(RA)
    |  la RA, 8(RA)
    |  clgr RA, RB			// All destination slots filled?
    |  jnl >3
    |  clgr TMPR1, BASE			// No more vararg slots?
    |  jl <1
    |2:  // Fill up remainder with nil.
    |  stg TMPR0, 0(RA)
    |  la RA, 8(RA)
    |  clgr RA, RB
    |  jl <2
    |3:
    |  ins_next
    |
    |5:  // Copy all varargs.
    |  lghi TMPR0, 1
    |  st TMPR0, SAVE_MULTRES		// MULTRES = 0+1
    |  lgr RC, BASE
    |  slgr RC, TMPR1
    |  jno <3				// No vararg slots? (borrow or zero)
    |  llgfr RB, RC
    |  srlg RB, RB, 3
    |  ahi RB, 1
    |  st RB, SAVE_MULTRES		// MULTRES = #varargs+1
    |  lg L:RB, SAVE_L
    |  agr RC, RA
    |  clg RC, L:RB->maxstack
    |  jh >7				// Need to grow stack?
    |6:  // Copy all vararg slots.
    |  lg RC, -16(TMPR1)
    |  la TMPR1, 8(TMPR1)
    |  stg RC, 0(RA)
    |  la RA, 8(RA)
    |  clgr TMPR1, BASE			// No more vararg slots?
    |  jl <6
    |  j <3
    |
    |7:  // Grow stack for varargs.
    |  stg BASE, L:RB->base
    |  stg RA, L:RB->top
    |  stg PC, SAVE_PC
    |  sgr TMPR1, BASE			// Need delta, because BASE may change.
    |  st TMPR1, SAVE_TMP_HI
    |  llgf CARG2, SAVE_MULTRES
    |  aghi CARG2, -1
    |  lgr CARG1, L:RB
    |  brasl r14, extern lj_state_growstack	// (lua_State *L, int n)
    |  lg BASE, L:RB->base
    |  lgf TMPR1, SAVE_TMP_HI
    |  lg RA, L:RB->top
    |  agr TMPR1, BASE
    |  j <6
    break;

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

  case BC_RETM:
    |  ins_AD	// RA = results, RD = extra_nresults
    |  agf RD, SAVE_MULTRES			// MULTRES >=1, so RD >=1.
    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.
    break;

  case BC_RET: case BC_RET0: case BC_RET1:
    |  ins_AD	// RA = results, RD = nresults+1
    if (op != BC_RET0) {
      |  sllg RA, RA, 3
    }
    |1:
    |  lg PC, -8(BASE)
    |  st RD, SAVE_MULTRES		// Save nresults+1.
    |  tmll PC, FRAME_TYPE		// Check frame type marker.
    |  jne >7				// Not returning to a fixarg Lua func?
    switch (op) {
    case BC_RET:
      |->BC_RET_Z:
      |  lgr KBASE, BASE		// Use KBASE for result move.
      |  aghi RD, -1
      |  je >3
      |2:  // Move results down.
      |  lg RB, 0(KBASE, RA)
      |  stg RB, -16(KBASE)
      |  la KBASE, 8(KBASE)
      |  brctg RD, <2
      |3:
      |  llgf RD, SAVE_MULTRES		// Note: MULTRES may be >256.
      |  llgc RB, PC_RB
      |5:
      |  cgr RB, RD			// More results expected?
      |  jh >6
      break;
    case BC_RET1:
      |  lg RB, 0(BASE, RA)
      |  stg RB, -16(BASE)
      /* fallthrough */
    case BC_RET0:
      |5:
      |  llgc TMPR1, PC_RB
      |  cgr TMPR1, RD
      |  jh >6
    default:
      break;
    }
    |  llgc RA, PC_RA
    |  lcgr RA, RA
    |  sllg RA, RA, 3
    |  lay BASE, -16(RA, BASE)		// base = base - (RA+2)*8
    |  lg LFUNC:KBASE, -16(BASE)
    |  cleartp LFUNC:KBASE
    |  lg KBASE, LFUNC:KBASE->pc
    |  lg KBASE, PC2PROTO(k)(KBASE)
    |  ins_next
    |
    |6:  // Fill up results with nil.
    |  lghi TMPR1, LJ_TNIL
    if (op == BC_RET) {
      |  stg TMPR1, -16(KBASE)		// Note: relies on shifted base.
      |  la KBASE, 8(KBASE)
    } else {
      |  sllg RC, RD, 3 		// RC used as temp.
      |  stg TMPR1, -24(RC, BASE)
    }
    |  la RD, 1(RD)
    |  j <5
    |
    |7:  // Non-standard return case.
    |  lay RB, -FRAME_VARG(PC)
    |  tmll RB, FRAME_TYPEP
    |  jne ->vm_return
    |  // Return from vararg function: relocate BASE down and RA up.
    |  sgr BASE, RB
    if (op != BC_RET0) {
      |  agr RA, RB
    }
    |  j <1
    break;

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

  |.define FOR_IDX,  0(RA)
  |.define FOR_STOP, 8(RA)
  |.define FOR_STEP, 16(RA)
  |.define FOR_EXT,  24(RA)

  case BC_FORL:
    |.if JIT
    |  hotloop RB
    |.endif
    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.
    break;

  case BC_JFORI:
  case BC_JFORL:
#if !LJ_HASJIT
    break;
#endif
  case BC_FORI:
  case BC_IFORL:
    vk = (op == BC_IFORL || op == BC_JFORL);
    |  ins_AJ	// RA = base, RD = target (after end of loop or start of loop)
    |  sllg RA, RA, 3
    |  la RA, 0(RA, BASE)
    |  lg RB, FOR_IDX
    |  checkint RB, >9
    |  lg TMPR1, FOR_STOP
    if (!vk) {
      |  checkint TMPR1, ->vmeta_for
      |  lg ITYPE, FOR_STEP
      |  chi ITYPE, 0; jl >5
      |  srag ITYPE, ITYPE, 47
      |  cghi ITYPE, LJ_TISNUM; jne ->vmeta_for
    } else {
#ifdef LUA_USE_ASSERT
      |  // lg TMPR1, FOR_STOP
      |  checkinttp TMPR1, ->assert_bad_for_arg_type
      |  lg TMPR0, FOR_STEP
      |  checkinttp TMPR0, ->assert_bad_for_arg_type
#endif
      |  lg ITYPE, FOR_STEP
      |  chi ITYPE, 0; jl >5
      |  ar RB, ITYPE; jo >1
      |  setint RB
      |  stg RB, FOR_IDX
    }
    |  cr RB, TMPR1
    |  stg RB, FOR_EXT
    if (op == BC_FORI) {
      |  jle >7
      |1:
      |6:
      |  branchPC RD
    } else if (op == BC_JFORI) {
      |  branchPC RD
      |  llgh RD, PC_RD
      |  jle =>BC_JLOOP
      |1:
      |6:
    } else if (op == BC_IFORL) {
      |  jh >7
      |6:
      |  branchPC RD
      |1:
    } else {
      |  jle =>BC_JLOOP
      |1:
      |6:
    }
    |7:
    |  ins_next
    |
    |5:  // Invert check for negative step.
    if (!vk) {
      |  srag ITYPE, ITYPE, 47
      |  cghi ITYPE, LJ_TISNUM; jne ->vmeta_for
    } else {
      |  ar RB, ITYPE; jo <1
      |  setint RB
      |  stg RB, FOR_IDX
    }
    |  cr RB, TMPR1
    |  stg RB, FOR_EXT
    if (op == BC_FORI) {
      |  jhe <7
    } else if (op == BC_JFORI) {
      |  branchPC RD
      |  llgh RD, PC_RD
      |  jhe =>BC_JLOOP
    } else if (op == BC_IFORL) {
      |  jl <7
    } else {
      |  jhe =>BC_JLOOP
    }
    |  j <6
    |9:  // Fallback to FP variant.
    if (!vk) {
      |  jhe ->vmeta_for
    }
    if (!vk) {
      |  lg TMPR0, FOR_STOP
      |  checknumtp TMPR0, ->vmeta_for
    } else {
#ifdef LUA_USE_ASSERT
      |  lg TMPR0, FOR_STOP
      |  checknumtp TMPR0, ->assert_bad_for_arg_type
      |  lg TMPR0, FOR_STEP
      |  checknumtp TMPR0, ->assert_bad_for_arg_type
#endif
    }
    |  lg RB, FOR_STEP
    if (!vk) {
      |  checknum RB, ->vmeta_for
    }
    |  ld f0, FOR_IDX
    |  ld f1, FOR_STOP
    if (vk) {
      |  adb f0, FOR_STEP
      |  std f0, FOR_IDX
    }
    |  cghi RB, 0; jl >3
    |  cdbr f1, f0
    |1:
    |  std f0, FOR_EXT
    if (op == BC_FORI) {
      |  jnl <7
    } else if (op == BC_JFORI) {
      |  branchPC RD
      |  llgh RD, PC_RD
      |  jnl =>BC_JLOOP
    } else if (op == BC_IFORL) {
      |  jl <7
    } else {
      |  jnl =>BC_JLOOP
    }
    |  j <6
    |
    |3:  // Invert comparison if step is negative.
    |  cdbr f0, f1
    |  j <1
    break;

  case BC_ITERL:
    |.if JIT
    |  hotloop RB
    |.endif
    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.
    break;

  case BC_JITERL:
#if !LJ_HASJIT
    break;
#endif
  case BC_IITERL:
    |  ins_AJ	// RA = base, RD = target
    |  sllg RA, RA, 3
    |  la RA, 0(RA, BASE)
    |  lg RB, 0(RA)
    |  cghi RB, LJ_TNIL; je >1		// Stop if iterator returned nil.
    if (op == BC_JITERL) {
      |  stg RB, -8(RA)
      |  j =>BC_JLOOP
    } else {
      |  branchPC RD			// Otherwise save control var + branch.
      |  stg RB, -8(RA)
    }
    |1:
    |  ins_next
    break;

  case BC_LOOP:
    |  ins_A	// RA = base, 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 RBd
    |.endif
    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.
    break;

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

  case BC_JLOOP:
    |  stg r0, 0
    |  stg r0, 0
    break;

  case BC_JMP:
    |  ins_AJ	// RA = unused, RD = target
    |  branchPC RD
    |  ins_next
    break;

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

   /*
   ** Reminder: A function may be called with func/args above L->maxstack,
   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,
   ** too. This means all FUNC* ops (including fast functions) must check
   ** for stack overflow _before_ adding more slots!
   */

  case BC_FUNCF:
    |.if JIT
    |  stg r0, 0
    |.endif
  case BC_FUNCV:  /* NYI: compiled vararg functions. */
    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.
    break;

  case BC_JFUNCF:
#if !LJ_HASJIT
    break;
#endif
  case BC_IFUNCF:
    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1
    |  lg KBASE, (PC2PROTO(k)-4)(PC)
    |  lg L:RB, SAVE_L
    |  sllg RA, RA, 3
    |  la RA, 0(RA, BASE)		// Top of frame.
    |  clg RA, L:RB->maxstack
    |  jh ->vm_growstack_f
    |  llgc RA, (PC2PROTO(numparams)-4)(PC)
    |  clgr NARGS:RD, RA		// Check for missing parameters.
    |  jle >3
    |2:
    if (op == BC_JFUNCF) {
      |  llgh RD, PC_RD
      |  j =>BC_JLOOP
    } else {
      |  ins_next
    }
    |
    |3:  // Clear missing parameters.
    |  sllg TMPR1, NARGS:RD, 3
    |  lghi TMPR0, LJ_TNIL
    |4:
    |  stg TMPR0, -8(TMPR1, BASE)
    |  la TMPR1, 8(TMPR1)
    |  la RD, 1(RD)
    |  clgr RD, RA
    |  jle <4
    |  j <2
    break;

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

  case BC_IFUNCV:
    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1
    |  sllg TMPR1, NARGS:RD, 3
    |  la RB, (FRAME_VARG+8)(TMPR1)
    |  la RD, 8(TMPR1, BASE)
    |  lg LFUNC:KBASE, -16(BASE)
    |  stg RB, -8(RD)			// Store delta + FRAME_VARG.
    |  stg LFUNC:KBASE, -16(RD)		// Store copy of LFUNC.
    |  lg L:RB, SAVE_L
    |  sllg RA, RA, 3
    |  la RA, 0(RA, RD)
    |  cg RA, L:RB->maxstack
    |  jh ->vm_growstack_v		// Need to grow stack.
    |  lgr RA, BASE
    |  lgr BASE, RD
    |  llgc RB, (PC2PROTO(numparams)-4)(PC)
    |  cghi RB, 0
    |  je >2
    |  aghi RA, 8
    |  lghi TMPR1, LJ_TNIL
    |1:  // Copy fixarg slots up to new frame.
    |  la RA, 8(RA)
    |  cgr RA, BASE
    |  jnl >3				// Less args than parameters?
    |  lg KBASE, -16(RA)
    |  stg KBASE, 0(RD)
    |  la RD, 8(RD)
    |  stg TMPR1, -16(RA)	// Clear old fixarg slot (help the GC).
    |  brctg RB, <1
    |2:
    if (op == BC_JFUNCV) {
      |  llgh RD, PC_RD
      |  j =>BC_JLOOP
    } else {
      |  lg KBASE, (PC2PROTO(k)-4)(PC)
      |  ins_next
    }
    |
    |3:  // Clear missing parameters.
    |  stg TMPR1, 0(RD)			// TMPR1=LJ_TNIL (-1) here.
    |  la RD, 8(RD)
    |  brctg RB, <3
    |  j <2
    break;

  case BC_FUNCC:
  case BC_FUNCCW:
    |  ins_AD  // BASE = new base, RD = nargs+1
    |  lg CFUNC:RB, -16(BASE)
    |  cleartp CFUNC:RB
    |  lg KBASE, CFUNC:RB->f
    |  lg L:RB, SAVE_L
    |  sllg RD, NARGS:RD, 3
    |  lay RD, -8(RD,BASE)
    |  stg BASE, L:RB->base
    |  la RA, (8*LUA_MINSTACK)(RD)
    |  clg RA, L:RB->maxstack
    |  stg RD, L:RB->top
    |  lgr CARG1, L:RB
    if (op != BC_FUNCC) {
      |  lgr CARG2, KBASE
    }
    |  jh ->vm_growstack_c		// Need to grow stack.
    |  set_vmstate C
    if (op == BC_FUNCC) {
      |  basr r14, KBASE		// (lua_State *L)
    } else {
      |  // (lua_State *L, lua_CFunction f)
      |  lg TMPR1, (DISPATCH_GL(wrapf))(DISPATCH)
      |  basr r14, TMPR1
    }
    |  // nresults returned in r2 (CRET1).
    |  lgr RD, CRET1
    |  lg BASE, L:RB->base
    |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)
    |  set_vmstate INTERP
    |  sllg TMPR1, RD, 3
    |  la RA, 0(TMPR1, BASE)
    |  lcgr RA, RA
    |  ag RA, L:RB->top			// RA = (L->top-(L->base+nresults))*8
    |  lg PC, -8(BASE)			// Fetch PC of caller.
    |  j ->vm_returnc
    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);
  switch (ctx->mode) {
  case BUILD_elfasm:
    fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
    fprintf(ctx->fp,
	".Lframe0:\n"
	"\t.long .LECIE0-.LSCIE0\n"
	".LSCIE0:\n"
	"\t.long 0xffffffff\n"
	"\t.byte 0x1\n"
	"\t.string \"\"\n"
	"\t.uleb128 1\n"
	"\t.sleb128 -8\n"
	"\t.byte 0xe\n"
	"\t.byte 0xc\n\t.uleb128 0xf\n\t.uleb128 160\n"
	"\t.align 8\n"
	".LECIE0:\n\n");
    fprintf(ctx->fp,
	".LSFDE0:\n"
	"\t.long .LEFDE0-.LASFDE0\n"
	".LASFDE0:\n"
	"\t.long .Lframe0\n"
	"\t.quad .Lbegin\n"
	"\t.quad %d\n"
	"\t.byte 0xe\n\t.uleb128 %d\n"		/* def_cfa_offset */
	"\t.byte 0x86\n\t.uleb128 0xe\n"	/* offset r6 */
	"\t.byte 0x87\n\t.uleb128 0xd\n"	/* offset r7 */
	"\t.byte 0x88\n\t.uleb128 0xc\n"	/* offset r8 */
	"\t.byte 0x89\n\t.uleb128 0xb\n"	/* offset r9 */
	"\t.byte 0x8a\n\t.uleb128 0xa\n"	/* offset r10 */
	"\t.byte 0x8b\n\t.uleb128 0x9\n"	/* offset r11 */
	"\t.byte 0x8c\n\t.uleb128 0x8\n"	/* offset r12 */
	"\t.byte 0x8d\n\t.uleb128 0x7\n"	/* offset r13 */
	"\t.byte 0x8e\n\t.uleb128 0x6\n"	/* offset r14 */
	"\t.byte 0x8f\n\t.uleb128 0x5\n"	/* offset r15 */
	"\t.align 8\n"
	".LEFDE0:\n\n", fcofs, CFRAME_SIZE+160);
#if LJ_HASFFI
    fprintf(ctx->fp,
	".LSFDE1:\n"
	"\t.long .LEFDE1-.LASFDE1\n"
	".LASFDE1:\n"
	"\t.long .Lframe0\n"
	"\t.quad lj_vm_ffi_call\n"
	"\t.quad %d\n"
	"\t.byte 0xe\n\t.uleb128 160\n"		/* def_cfa_offset */
	"\t.byte 0xd\n\t.uleb128 0xd\n"		/* def_cfa_register r13 (FP) */
	"\t.byte 0x86\n\t.uleb128 0xe\n"	/* offset r6 */
	"\t.byte 0x87\n\t.uleb128 0xd\n"	/* offset r7 */
	"\t.byte 0x88\n\t.uleb128 0xc\n"	/* offset r8 */
	"\t.byte 0x89\n\t.uleb128 0xb\n"	/* offset r9 */
	"\t.byte 0x8a\n\t.uleb128 0xa\n"	/* offset r10 */
	"\t.byte 0x8b\n\t.uleb128 0x9\n"	/* offset r11 */
	"\t.byte 0x8c\n\t.uleb128 0x8\n"	/* offset r12 */
	"\t.byte 0x8d\n\t.uleb128 0x7\n"	/* offset r13 */
	"\t.byte 0x8e\n\t.uleb128 0x6\n"	/* offset r14 */
	"\t.byte 0x8f\n\t.uleb128 0x5\n"	/* offset r15 */
	"\t.align 8\n"
	".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
#endif
#if !LJ_NO_UNWIND
    fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
    fprintf(ctx->fp,
	".Lframe1:\n"
	"\t.long .LECIE1-.LSCIE1\n"
	".LSCIE1:\n"
	"\t.long 0\n"
	"\t.byte 0x1\n"
	"\t.string \"zPR\"\n"
	"\t.uleb128 0x1\n"
	"\t.sleb128 -8\n"
	"\t.byte 0xe\n"
	"\t.uleb128 6\n"			/* augmentation length */
	"\t.byte 0x1b\n"			/* pcrel|sdata4 */
	"\t.long lj_err_unwind_dwarf-.\n"
	"\t.byte 0x1b\n"			/* pcrel|sdata4 */
	"\t.byte 0xc\n\t.uleb128 0xf\n\t.uleb128 160\n"
	"\t.align 8\n"
	".LECIE1:\n\n");
    fprintf(ctx->fp,
	".LSFDE2:\n"
	"\t.long .LEFDE2-.LASFDE2\n"
	".LASFDE2:\n"
	"\t.long .LASFDE2-.Lframe1\n"
	"\t.long .Lbegin-.\n"
	"\t.long %d\n"
	"\t.uleb128 0\n"			/* augmentation length */
	"\t.byte 0xe\n\t.uleb128 %d\n"		/* def_cfa_offset */
	"\t.byte 0x86\n\t.uleb128 0xe\n"	/* offset r6 */
	"\t.byte 0x87\n\t.uleb128 0xd\n"	/* offset r7 */
	"\t.byte 0x88\n\t.uleb128 0xc\n"	/* offset r8 */
	"\t.byte 0x89\n\t.uleb128 0xb\n"	/* offset r9 */
	"\t.byte 0x8a\n\t.uleb128 0xa\n"	/* offset r10 */
	"\t.byte 0x8b\n\t.uleb128 0x9\n"	/* offset r11 */
	"\t.byte 0x8c\n\t.uleb128 0x8\n"	/* offset r12 */
	"\t.byte 0x8d\n\t.uleb128 0x7\n"	/* offset r13 */
	"\t.byte 0x8e\n\t.uleb128 0x6\n"	/* offset r14 */
	"\t.byte 0x8f\n\t.uleb128 0x5\n"	/* offset r15 */
	"\t.align 8\n"
	".LEFDE2:\n\n", fcofs, CFRAME_SIZE+160);
#if LJ_HASFFI
    fprintf(ctx->fp,
	".Lframe2:\n"
	"\t.long .LECIE2-.LSCIE2\n"
	".LSCIE2:\n"
	"\t.long 0\n"
	"\t.byte 0x1\n"
	"\t.string \"zR\"\n"
	"\t.uleb128 0x1\n"
	"\t.sleb128 -8\n"
	"\t.byte 0xe\n"
	"\t.uleb128 1\n"			/* augmentation length */
	"\t.byte 0x1b\n"			/* pcrel|sdata4 */
	"\t.byte 0xc\n\t.uleb128 0xf\n\t.uleb128 160\n"
	"\t.align 8\n"
	".LECIE2:\n\n");
    fprintf(ctx->fp,
	".LSFDE3:\n"
	"\t.long .LEFDE3-.LASFDE3\n"
	".LASFDE3:\n"
	"\t.long .LASFDE3-.Lframe2\n"
	"\t.long lj_vm_ffi_call-.\n"
	"\t.long %d\n"
	"\t.uleb128 0\n"			/* augmentation length */
	"\t.byte 0xe\n\t.uleb128 160\n"		/* def_cfa_offset */
	"\t.byte 0xd\n\t.uleb128 0xd\n"		/* def_cfa_register r13 (FP) */
	"\t.byte 0x86\n\t.uleb128 0xe\n"	/* offset r6 */
	"\t.byte 0x87\n\t.uleb128 0xd\n"	/* offset r7 */
	"\t.byte 0x88\n\t.uleb128 0xc\n"	/* offset r8 */
	"\t.byte 0x89\n\t.uleb128 0xb\n"	/* offset r9 */
	"\t.byte 0x8a\n\t.uleb128 0xa\n"	/* offset r10 */
	"\t.byte 0x8b\n\t.uleb128 0x9\n"	/* offset r11 */
	"\t.byte 0x8c\n\t.uleb128 0x8\n"	/* offset r12 */
	"\t.byte 0x8d\n\t.uleb128 0x7\n"	/* offset r13 */
	"\t.byte 0x8e\n\t.uleb128 0x6\n"	/* offset r14 */
	"\t.byte 0x8f\n\t.uleb128 0x5\n"	/* offset r15 */
	"\t.align 8\n"
	".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
#endif
#endif
    break;
  default:  /* No other modes. */
    break;
  }
}