1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
|
|// Low-level VM code for PowerPC 32 bit or 32on64 bit mode.
|// Bytecode interpreter, fast functions and helper functions.
|// Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h
|
|.arch ppc
|.section code_op, code_sub
|
|.actionlist build_actionlist
|.globals GLOB_
|.globalnames globnames
|.externnames extnames
|
|// Note: The ragged indentation of the instructions is intentional.
|// The starting columns indicate data dependencies.
|
|//-----------------------------------------------------------------------
|
|// DynASM defines used by the PPC port:
|//
|// P64 64 bit pointers (only for GPR64 testing).
|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3).
|// Affects reg saves, stack layout, carry/overflow/dot flags etc.
|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360).
|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3).
|// Function pointers are really a struct: code, TOC, env (optional).
|// TOCENV Function pointers have an environment pointer, too (not on PS3).
|// PPE Power Processor Element of Cell (PS3) or Xenon (Xbox 360).
|// Must avoid (slow) micro-coded instructions.
|
|.if P64
|.define TOC, 1
|.define TOCENV, 1
|.macro lpx, a, b, c; ldx a, b, c; .endmacro
|.macro lp, a, b; ld a, b; .endmacro
|.macro stp, a, b; std a, b; .endmacro
|.define decode_OPP, decode_OP8
|.if FFI
|// Missing: Calling conventions, 64 bit regs, TOC.
|.error lib_ffi not yet implemented for PPC64
|.endif
|.else
|.macro lpx, a, b, c; lwzx a, b, c; .endmacro
|.macro lp, a, b; lwz a, b; .endmacro
|.macro stp, a, b; stw a, b; .endmacro
|.define decode_OPP, decode_OP4
|.endif
|
|// Convenience macros for TOC handling.
|.if TOC
|// Linker needs a TOC patch area for every external call relocation.
|.macro blex, target; bl extern target@plt; nop; .endmacro
|.macro .toc, a, b; a, b; .endmacro
|.if P64
|.define TOC_OFS, 8
|.define ENV_OFS, 16
|.else
|.define TOC_OFS, 4
|.define ENV_OFS, 8
|.endif
|.else // No TOC.
|.macro blex, target; bl extern target@plt; .endmacro
|.macro .toc, a, b; .endmacro
|.endif
|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro
|
|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro
|
|.macro andix., y, a, i
|.if PPE
| rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i)
| cmpwi y, 0
|.else
| andi. y, a, i
|.endif
|.endmacro
|
|.macro clrso, reg
|.if PPE
| li reg, 0
| mtxer reg
|.else
| mcrxr cr0
|.endif
|.endmacro
|
|.macro checkov, reg, noov
|.if PPE
| mfxer reg
| add reg, reg, reg
| cmpwi reg, 0
| li reg, 0
| mtxer reg
| bgey noov
|.else
| mcrxr cr0
| bley noov
|.endif
|.endmacro
|
|//-----------------------------------------------------------------------
|
|// Fixed register assignments for the interpreter.
|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA)
|
|.macro .FPU, a, b
|.if FPU
| a, b
|.endif
|.endmacro
|
|.macro .FPU, a, b, c
|.if FPU
| a, b, c
|.endif
|.endmacro
|
|// The following must be C callee-save (but BASE is often refetched).
|.define BASE, r14 // Base of current Lua stack frame.
|.define KBASE, r15 // Constants of current Lua function.
|.define PC, r16 // Next PC.
|.define DISPATCH, r17 // Opcode dispatch table.
|.define LREG, r18 // Register holding lua_State (also in SAVE_L).
|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8.
|.define JGL, r31 // On-trace: global_State + 32768.
|
|// Constants for type-comparisons, stores and conversions. C callee-save.
|.define TISNUM, r22
|.define TISNIL, r23
|.define ZERO, r24
|.if FPU
|.define TOBIT, f30 // 2^52 + 2^51.
|.define TONUM, f31 // 2^52 + 2^51 + 2^31.
|.endif
|
|// The following temporaries are not saved across C calls, except for RA.
|.define RA, r20 // Callee-save.
|.define RB, r10
|.define RC, r11
|.define RD, r12
|.define INS, r7 // Overlaps CARG5.
|
|.define TMP0, r0
|.define TMP1, r8
|.define TMP2, r9
|.define TMP3, r6 // Overlaps CARG4.
|
|// Saved temporaries.
|.define SAVE0, r21
|.define SAVE1, r25
|
|// Calling conventions.
|.define CARG1, r3
|.define CARG2, r4
|.define CARG3, r5
|.define CARG4, r6 // Overlaps TMP3.
|.define CARG5, r7 // Overlaps INS.
|
|.if FPU
|.define FARG1, f1
|.define FARG2, f2
|.endif
|
|.define CRET1, r3
|.define CRET2, r4
|
|.define TOCREG, r2 // TOC register (only used by C code).
|.define ENVREG, r11 // Environment pointer (nested C functions).
|
|// Stack layout while in interpreter. Must match with lj_frame.h.
|.if GPR64
|.if FRAME32
|
|// 456(sp) // \ 32/64 bit C frame info
|.define TONUM_LO, 452(sp) // |
|.define TONUM_HI, 448(sp) // |
|.define TMPD_LO, 444(sp) // |
|.define TMPD_HI, 440(sp) // |
|.define SAVE_CR, 432(sp) // | 64 bit CR save.
|.define SAVE_ERRF, 424(sp) // > Parameter save area.
|.define SAVE_NRES, 420(sp) // |
|.define SAVE_L, 416(sp) // |
|.define SAVE_PC, 412(sp) // |
|.define SAVE_MULTRES, 408(sp) // |
|.define SAVE_CFRAME, 400(sp) // / 64 bit C frame chain.
|// 392(sp) // Reserved.
|.define CFRAME_SPACE, 384 // Delta for sp.
|// Back chain for sp: 384(sp) <-- sp entering interpreter
|.define SAVE_LR, 376(sp) // 32 bit LR stored in hi-part.
|.define SAVE_GPR_, 232 // .. 232+18*8: 64 bit GPR saves.
|.define SAVE_FPR_, 88 // .. 88+18*8: 64 bit FPR saves.
|// 80(sp) // Needed for 16 byte stack frame alignment.
|// 16(sp) // Callee parameter save area (ABI mandated).
|// 8(sp) // Reserved
|// Back chain for sp: 0(sp) <-- sp while in interpreter
|// 32 bit sp stored in hi-part of 0(sp).
|
|.define TMPD_BLO, 447(sp)
|.define TMPD, TMPD_HI
|.define TONUM_D, TONUM_HI
|
|.else
|
|// 508(sp) // \ 32 bit C frame info.
|.define SAVE_ERRF, 472(sp) // |
|.define SAVE_NRES, 468(sp) // |
|.define SAVE_L, 464(sp) // > Parameter save area.
|.define SAVE_PC, 460(sp) // |
|.define SAVE_MULTRES, 456(sp) // |
|.define SAVE_CFRAME, 448(sp) // / 64 bit C frame chain.
|.define SAVE_LR, 416(sp)
|.define CFRAME_SPACE, 400 // Delta for sp.
|// Back chain for sp: 400(sp) <-- sp entering interpreter
|.define SAVE_FPR_, 256 // .. 256+18*8: 64 bit FPR saves.
|.define SAVE_GPR_, 112 // .. 112+18*8: 64 bit GPR saves.
|// 48(sp) // Callee parameter save area (ABI mandated).
|.define SAVE_TOC, 40(sp) // TOC save area.
|.define TMPD_LO, 36(sp) // \ Link editor temp (ABI mandated).
|.define TMPD_HI, 32(sp) // /
|.define TONUM_LO, 28(sp) // \ Compiler temp (ABI mandated).
|.define TONUM_HI, 24(sp) // /
|// Next frame lr: 16(sp)
|.define SAVE_CR, 8(sp) // 64 bit CR save.
|// Back chain for sp: 0(sp) <-- sp while in interpreter
|
|.define TMPD_BLO, 39(sp)
|.define TMPD, TMPD_HI
|.define TONUM_D, TONUM_HI
|
|.endif
|.else
|
|.if FPU
|.define SAVE_LR, 276(sp)
|.define CFRAME_SPACE, 272 // Delta for sp.
|// Back chain for sp: 272(sp) <-- sp entering interpreter
|.define SAVE_FPR_, 128 // .. 128+18*8: 64 bit FPR saves.
|.else
|.define SAVE_LR, 132(sp)
|.define CFRAME_SPACE, 128 // Delta for sp.
|// Back chain for sp: 128(sp) <-- sp entering interpreter
|.endif
|.define SAVE_GPR_, 56 // .. 56+18*4: 32 bit GPR saves.
|.define SAVE_CR, 52(sp) // 32 bit CR save.
|.define SAVE_ERRF, 48(sp) // 32 bit C frame info.
|.define SAVE_NRES, 44(sp)
|.define SAVE_CFRAME, 40(sp)
|.define SAVE_L, 36(sp)
|.define SAVE_PC, 32(sp)
|.define SAVE_MULTRES, 28(sp)
|.define UNUSED1, 24(sp)
|.if FPU
|.define TMPD_LO, 20(sp)
|.define TMPD_HI, 16(sp)
|.define TONUM_LO, 12(sp)
|.define TONUM_HI, 8(sp)
|.else
|.define SFSAVE_4, 20(sp)
|.define SFSAVE_3, 16(sp)
|.define SFSAVE_2, 12(sp)
|.define SFSAVE_1, 8(sp)
|.endif
|// Next frame lr: 4(sp)
|// Back chain for sp: 0(sp) <-- sp while in interpreter
|
|.if FPU
|.define TMPD_BLO, 23(sp)
|.define TMPD, TMPD_HI
|.define TONUM_D, TONUM_HI
|.endif
|
|.endif
|
|.macro save_, reg
|.if GPR64
| std r..reg, SAVE_GPR_+(reg-14)*8(sp)
|.else
| stw r..reg, SAVE_GPR_+(reg-14)*4(sp)
|.endif
| .FPU stfd f..reg, SAVE_FPR_+(reg-14)*8(sp)
|.endmacro
|.macro rest_, reg
|.if GPR64
| ld r..reg, SAVE_GPR_+(reg-14)*8(sp)
|.else
| lwz r..reg, SAVE_GPR_+(reg-14)*4(sp)
|.endif
| .FPU lfd f..reg, SAVE_FPR_+(reg-14)*8(sp)
|.endmacro
|
|.macro saveregs
|.if GPR64 and not FRAME32
| stdu sp, -CFRAME_SPACE(sp)
|.else
| stwu sp, -CFRAME_SPACE(sp)
|.endif
| save_ 14; save_ 15; save_ 16
| mflr r0
| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22
|.if GPR64 and not FRAME32
| std r0, SAVE_LR
|.else
| stw r0, SAVE_LR
|.endif
| save_ 23; save_ 24; save_ 25
| mfcr r0
| save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31
|.if GPR64
| std r0, SAVE_CR
|.else
| stw r0, SAVE_CR
|.endif
| .toc std TOCREG, SAVE_TOC
|.endmacro
|
|.macro restoreregs
|.if GPR64 and not FRAME32
| ld r0, SAVE_LR
|.else
| lwz r0, SAVE_LR
|.endif
|.if GPR64
| ld r12, SAVE_CR
|.else
| lwz r12, SAVE_CR
|.endif
| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19
| mtlr r0;
|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif
| rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25
|.if PPE; mtocrf 0x10, r12; .endif
| rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31
|.if PPE; mtocrf 0x08, r12; .endif
| addi sp, sp, CFRAME_SPACE
|.endmacro
|
|// Type definitions. Some of these are only used for documentation.
|.type L, lua_State, LREG
|.type GL, global_State
|.type TVALUE, TValue
|.type GCOBJ, GCobj
|.type STR, GCstr
|.type TAB, GCtab
|.type LFUNC, GCfuncL
|.type CFUNC, GCfuncC
|.type PROTO, GCproto
|.type UPVAL, GCupval
|.type NODE, Node
|.type NARGS8, int
|.type TRACE, GCtrace
|.type SBUF, SBuf
|
|//-----------------------------------------------------------------------
|
|// Trap for not-yet-implemented parts.
|.macro NYI; tw 4, sp, sp; .endmacro
|
|.if FPU
|// int/FP conversions.
|.macro tonum_i, freg, reg
| xoris reg, reg, 0x8000
| stw reg, TONUM_LO
| lfd freg, TONUM_D
| fsub freg, freg, TONUM
|.endmacro
|
|.macro tonum_u, freg, reg
| stw reg, TONUM_LO
| lfd freg, TONUM_D
| fsub freg, freg, TOBIT
|.endmacro
|
|.macro toint, reg, freg, tmpfreg
| fctiwz tmpfreg, freg
| stfd tmpfreg, TMPD
| lwz reg, TMPD_LO
|.endmacro
|
|.macro toint, reg, freg
| toint reg, freg, freg
|.endmacro
|.endif
|
|//-----------------------------------------------------------------------
|
|// Access to frame relative to BASE.
|.define FRAME_PC, -8
|.define FRAME_FUNC, -4
|
|// Instruction decode.
|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro
|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro
|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro
|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro
|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro
|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro
|
|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro
|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro
|
|// Instruction fetch.
|.macro ins_NEXT1
| lwz INS, 0(PC)
| addi PC, PC, 4
|.endmacro
|// Instruction decode+dispatch. Note: optimized for e300!
|.macro ins_NEXT2
| decode_OPP TMP1, INS
| lpx TMP0, DISPATCH, TMP1
| mtctr TMP0
| decode_RB8 RB, INS
| decode_RD8 RD, INS
| decode_RA8 RA, INS
| decode_RC8 RC, INS
| bctr
|.endmacro
|.macro ins_NEXT
| ins_NEXT1
| ins_NEXT2
|.endmacro
|
|// Instruction footer.
|.if 1
| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
| .define ins_next, ins_NEXT
| .define ins_next_, ins_NEXT
| .define ins_next1, ins_NEXT1
| .define ins_next2, ins_NEXT2
|.else
| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
| // Affects only certain kinds of benchmarks (and only with -j off).
| .macro ins_next
| b ->ins_next
| .endmacro
| .macro ins_next1
| .endmacro
| .macro ins_next2
| b ->ins_next
| .endmacro
| .macro ins_next_
| ->ins_next:
| ins_NEXT
| .endmacro
|.endif
|
|// Call decode and dispatch.
|.macro ins_callt
| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
| lwz PC, LFUNC:RB->pc
| lwz INS, 0(PC)
| addi PC, PC, 4
| decode_OPP TMP1, INS
| decode_RA8 RA, INS
| lpx TMP0, DISPATCH, TMP1
| add RA, RA, BASE
| mtctr TMP0
| bctr
|.endmacro
|
|.macro ins_call
| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
| stw PC, FRAME_PC(BASE)
| ins_callt
|.endmacro
|
|//-----------------------------------------------------------------------
|
|// Macros to test operand types.
|.macro checknum, reg; cmplw reg, TISNUM; .endmacro
|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro
|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro
|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro
|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro
|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro
|
|.macro branch_RD
| srwi TMP0, RD, 1
| addis PC, PC, -(BCBIAS_J*4 >> 16)
| add PC, PC, TMP0
|.endmacro
|
|// Assumes DISPATCH is relative to GL.
#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
|
#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
|
|.macro hotcheck, delta, target
| rlwinm TMP1, PC, 31, 25, 30
| addi TMP1, TMP1, GG_DISP2HOT
| lhzx TMP2, DISPATCH, TMP1
| addic. TMP2, TMP2, -delta
| sthx TMP2, DISPATCH, TMP1
| blt target
|.endmacro
|
|.macro hotloop
| hotcheck HOTCOUNT_LOOP, ->vm_hotloop
|.endmacro
|
|.macro hotcall
| hotcheck HOTCOUNT_CALL, ->vm_hotcall
|.endmacro
|
|// Set current VM state. Uses TMP0.
|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
|
|// Move table write barrier back. Overwrites mark and tmp.
|.macro barrierback, tab, mark, tmp
| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
| // Assumes LJ_GC_BLACK is 0x04.
| rlwinm mark, mark, 0, 30, 28 // black2gray(tab)
| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
| stb mark, tab->marked
| stw tmp, tab->gclist
|.endmacro
|
|//-----------------------------------------------------------------------
/* Generate subroutines used by opcodes and other parts of the VM. */
/* The .code_sub section should be last to help static branch prediction. */
static void build_subroutines(BuildCtx *ctx)
{
|.code_sub
|
|//-----------------------------------------------------------------------
|//-- Return handling ----------------------------------------------------
|//-----------------------------------------------------------------------
|
|->vm_returnp:
| // See vm_return. Also: TMP2 = previous base.
| andix. TMP0, PC, FRAME_P
| li TMP1, LJ_TTRUE
| beq ->cont_dispatch
|
| // Return from pcall or xpcall fast func.
| lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame.
| mr BASE, TMP2 // Restore caller base.
| // Prepending may overwrite the pcall frame, so do it at the end.
| stwu TMP1, FRAME_PC(RA) // Prepend true to results.
|
|->vm_returnc:
| addi RD, RD, 8 // RD = (nresults+1)*8.
| andix. TMP0, PC, FRAME_TYPE
| cmpwi cr1, RD, 0
| li CRET1, LUA_YIELD
| beq cr1, ->vm_unwind_c_eh
| mr MULTRES, RD
| beq ->BC_RET_Z // Handle regular return to Lua.
|
|->vm_return:
| // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
| // TMP0 = PC & FRAME_TYPE
| cmpwi TMP0, FRAME_C
| rlwinm TMP2, PC, 0, 0, 28
| li_vmstate C
| sub TMP2, BASE, TMP2 // TMP2 = previous base.
| bney ->vm_returnp
|
| addic. TMP1, RD, -8
| stp TMP2, L->base
| lwz TMP2, SAVE_NRES
| subi BASE, BASE, 8
| st_vmstate
| slwi TMP2, TMP2, 3
| beq >2
|1:
| addic. TMP1, TMP1, -8
|.if FPU
| lfd f0, 0(RA)
|.else
| lwz CARG1, 0(RA)
| lwz CARG2, 4(RA)
|.endif
| addi RA, RA, 8
|.if FPU
| stfd f0, 0(BASE)
|.else
| stw CARG1, 0(BASE)
| stw CARG2, 4(BASE)
|.endif
| addi BASE, BASE, 8
| bney <1
|
|2:
| cmpw TMP2, RD // More/less results wanted?
| bne >6
|3:
| stp BASE, L->top // Store new top.
|
|->vm_leave_cp:
| lp TMP0, SAVE_CFRAME // Restore previous C frame.
| li CRET1, 0 // Ok return status for vm_pcall.
| stp TMP0, L->cframe
|
|->vm_leave_unw:
| restoreregs
| blr
|
|6:
| ble >7 // Less results wanted?
| // More results wanted. Check stack size and fill up results with nil.
| lwz TMP1, L->maxstack
| cmplw BASE, TMP1
| bge >8
| stw TISNIL, 0(BASE)
| addi RD, RD, 8
| addi BASE, BASE, 8
| b <2
|
|7: // Less results wanted.
| subfic TMP3, TMP2, 0 // LUA_MULTRET+1 case?
| sub TMP0, RD, TMP2
| subfe TMP1, TMP1, TMP1 // TMP1 = TMP2 == 0 ? 0 : -1
| and TMP0, TMP0, TMP1
| sub BASE, BASE, TMP0 // Either keep top or shrink it.
| b <3
|
|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.
| stp BASE, L->top // Save current top held in BASE (yes).
| mr SAVE0, RD
| srwi CARG2, TMP2, 3
| mr CARG1, L
| bl extern lj_state_growstack // (lua_State *L, int n)
| lwz TMP2, SAVE_NRES
| mr RD, SAVE0
| slwi TMP2, TMP2, 3
| lp BASE, L->top // Need the (realloced) L->top in BASE.
| b <2
|
|->vm_unwind_c: // Unwind C stack, return from vm_pcall.
| // (void *cframe, int errcode)
| mr sp, CARG1
| mr CRET1, CARG2
|->vm_unwind_c_eh: // Landing pad for external unwinder.
| lwz L, SAVE_L
| .toc ld TOCREG, SAVE_TOC
| li TMP0, ~LJ_VMST_C
| lwz GL:TMP1, L->glref
| stw TMP0, GL:TMP1->vmstate
| b ->vm_leave_unw
|
|->vm_unwind_ff: // Unwind C stack, return from ff pcall.
| // (void *cframe)
|.if GPR64
| rldicr sp, CARG1, 0, 61
|.else
| rlwinm sp, CARG1, 0, 0, 29
|.endif
|->vm_unwind_ff_eh: // Landing pad for external unwinder.
| lwz L, SAVE_L
| .toc ld TOCREG, SAVE_TOC
| li TISNUM, LJ_TISNUM // Setup type comparison constants.
| lp BASE, L->base
| .FPU lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
| lwz DISPATCH, L->glref // Setup pointer to dispatch table.
| li ZERO, 0
| .FPU stw TMP3, TMPD
| li TMP1, LJ_TFALSE
| .FPU ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
| li TISNIL, LJ_TNIL
| li_vmstate INTERP
| .FPU lfs TOBIT, TMPD
| lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame.
| la RA, -8(BASE) // Results start at BASE-8.
| .FPU stw TMP3, TMPD
| addi DISPATCH, DISPATCH, GG_G2DISP
| stw TMP1, 0(RA) // Prepend false to error message.
| li RD, 16 // 2 results: false + error message.
| st_vmstate
| .FPU lfs TONUM, TMPD
| b ->vm_returnc
|
|//-----------------------------------------------------------------------
|//-- Grow stack for calls -----------------------------------------------
|//-----------------------------------------------------------------------
|
|->vm_growstack_c: // Grow stack for C function.
| li CARG2, LUA_MINSTACK
| b >2
|
|->vm_growstack_l: // Grow stack for Lua function.
| // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
| add RC, BASE, RC
| sub RA, RA, BASE
| stp BASE, L->base
| addi PC, PC, 4 // Must point after first instruction.
| stp RC, L->top
| srwi CARG2, RA, 3
|2:
| // L->base = new base, L->top = top
| stw PC, SAVE_PC
| mr CARG1, L
| bl extern lj_state_growstack // (lua_State *L, int n)
| lp BASE, L->base
| lp RC, L->top
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| sub RC, RC, BASE
| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
| ins_callt // Just retry the call.
|
|//-----------------------------------------------------------------------
|//-- Entry points into the assembler VM ---------------------------------
|//-----------------------------------------------------------------------
|
|->vm_resume: // Setup C frame and resume thread.
| // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
| saveregs
| mr L, CARG1
| lwz DISPATCH, L->glref // Setup pointer to dispatch table.
| mr BASE, CARG2
| lbz TMP1, L->status
| stw L, SAVE_L
| li PC, FRAME_CP
| addi TMP0, sp, CFRAME_RESUME
| addi DISPATCH, DISPATCH, GG_G2DISP
| stw CARG3, SAVE_NRES
| cmplwi TMP1, 0
| stw CARG3, SAVE_ERRF
| stp CARG3, SAVE_CFRAME
| stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
| stp TMP0, L->cframe
| beq >3
|
| // Resume after yield (like a return).
| stw L, DISPATCH_GL(cur_L)(DISPATCH)
| mr RA, BASE
| lp BASE, L->base
| li TISNUM, LJ_TISNUM // Setup type comparison constants.
| lp TMP1, L->top
| lwz PC, FRAME_PC(BASE)
| .FPU lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
| stb CARG3, L->status
| .FPU stw TMP3, TMPD
| .FPU ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
| .FPU lfs TOBIT, TMPD
| sub RD, TMP1, BASE
| .FPU stw TMP3, TMPD
| .FPU lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
| addi RD, RD, 8
| .FPU stw TMP0, TONUM_HI
| li_vmstate INTERP
| li ZERO, 0
| st_vmstate
| andix. TMP0, PC, FRAME_TYPE
| mr MULTRES, RD
| .FPU lfs TONUM, TMPD
| li TISNIL, LJ_TNIL
| beq ->BC_RET_Z
| b ->vm_return
|
|->vm_pcall: // Setup protected C frame and enter VM.
| // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
| saveregs
| li PC, FRAME_CP
| stw CARG4, SAVE_ERRF
| b >1
|
|->vm_call: // Setup C frame and enter VM.
| // (lua_State *L, TValue *base, int nres1)
| saveregs
| li PC, FRAME_C
|
|1: // Entry point for vm_pcall above (PC = ftype).
| lp TMP1, L:CARG1->cframe
| mr L, CARG1
| stw CARG3, SAVE_NRES
| lwz DISPATCH, L->glref // Setup pointer to dispatch table.
| stw CARG1, SAVE_L
| mr BASE, CARG2
| addi DISPATCH, DISPATCH, GG_G2DISP
| stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
| stp TMP1, SAVE_CFRAME
| stp sp, L->cframe // Add our C frame to cframe chain.
|
|3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
| stw L, DISPATCH_GL(cur_L)(DISPATCH)
| lp TMP2, L->base // TMP2 = old base (used in vmeta_call).
| li TISNUM, LJ_TISNUM // Setup type comparison constants.
| lp TMP1, L->top
| .FPU lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
| add PC, PC, BASE
| .FPU stw TMP3, TMPD
| li ZERO, 0
| .FPU ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
| .FPU lfs TOBIT, TMPD
| sub PC, PC, TMP2 // PC = frame delta + frame type
| .FPU stw TMP3, TMPD
| .FPU lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
| sub NARGS8:RC, TMP1, BASE
| .FPU stw TMP0, TONUM_HI
| li_vmstate INTERP
| .FPU lfs TONUM, TMPD
| li TISNIL, LJ_TNIL
| st_vmstate
|
|->vm_call_dispatch:
| // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
| lwz TMP0, FRAME_PC(BASE)
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| checkfunc TMP0; bne ->vmeta_call
|
|->vm_call_dispatch_f:
| ins_call
| // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
|
|->vm_cpcall: // Setup protected C frame, call C.
| // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
| saveregs
| mr L, CARG1
| lwz TMP0, L:CARG1->stack
| stw CARG1, SAVE_L
| lp TMP1, L->top
| lwz DISPATCH, L->glref // Setup pointer to dispatch table.
| stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
| sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
| lp TMP1, L->cframe
| addi DISPATCH, DISPATCH, GG_G2DISP
| .toc lp CARG4, 0(CARG4)
| li TMP2, 0
| stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
| stw TMP2, SAVE_ERRF // No error function.
| stp TMP1, SAVE_CFRAME
| stp sp, L->cframe // Add our C frame to cframe chain.
| stw L, DISPATCH_GL(cur_L)(DISPATCH)
| mtctr CARG4
| bctrl // (lua_State *L, lua_CFunction func, void *ud)
|.if PPE
| mr BASE, CRET1
| cmpwi CRET1, 0
|.else
| mr. BASE, CRET1
|.endif
| li PC, FRAME_CP
| bne <3 // Else continue with the call.
| b ->vm_leave_cp // No base? Just remove C frame.
|
|//-----------------------------------------------------------------------
|//-- Metamethod handling ------------------------------------------------
|//-----------------------------------------------------------------------
|
|// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
|// stack, so BASE doesn't need to be reloaded across these calls.
|
|//-- Continuation dispatch ----------------------------------------------
|
|->cont_dispatch:
| // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
| lwz TMP0, -12(BASE) // Continuation.
| mr RB, BASE
| mr BASE, TMP2 // Restore caller BASE.
| lwz LFUNC:TMP1, FRAME_FUNC(TMP2)
|.if FFI
| cmplwi TMP0, 1
|.endif
| lwz PC, -16(RB) // Restore PC from [cont|PC].
| subi TMP2, RD, 8
| stwx TISNIL, RA, TMP2 // Ensure one valid arg.
|.if FFI
| ble >1
|.endif
| lwz TMP1, LFUNC:TMP1->pc
| lwz KBASE, PC2PROTO(k)(TMP1)
| // BASE = base, RA = resultptr, RB = meta base
| mtctr TMP0
| bctr // Jump to continuation.
|
|.if FFI
|1:
| beq ->cont_ffi_callback // cont = 1: return from FFI callback.
| // cont = 0: tailcall from C function.
| subi TMP1, RB, 16
| sub RC, TMP1, BASE
| b ->vm_call_tail
|.endif
|
|->cont_cat: // RA = resultptr, RB = meta base
| lwz INS, -4(PC)
| subi CARG2, RB, 16
| decode_RB8 SAVE0, INS
|.if FPU
| lfd f0, 0(RA)
|.else
| lwz TMP2, 0(RA)
| lwz TMP3, 4(RA)
|.endif
| add TMP1, BASE, SAVE0
| stp BASE, L->base
| cmplw TMP1, CARG2
| sub CARG3, CARG2, TMP1
| decode_RA8 RA, INS
|.if FPU
| stfd f0, 0(CARG2)
|.else
| stw TMP2, 0(CARG2)
| stw TMP3, 4(CARG2)
|.endif
| bney ->BC_CAT_Z
|.if FPU
| stfdx f0, BASE, RA
|.else
| stwux TMP2, RA, BASE
| stw TMP3, 4(RA)
|.endif
| b ->cont_nop
|
|//-- Table indexing metamethods -----------------------------------------
|
|->vmeta_tgets1:
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
| li TMP0, LJ_TSTR
| decode_RB8 RB, INS
| stw STR:RC, 4(CARG3)
| add CARG2, BASE, RB
| stw TMP0, 0(CARG3)
| b >1
|
|->vmeta_tgets:
| la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
| li TMP0, LJ_TTAB
| stw TAB:RB, 4(CARG2)
| la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
| stw TMP0, 0(CARG2)
| li TMP1, LJ_TSTR
| stw STR:RC, 4(CARG3)
| stw TMP1, 0(CARG3)
| b >1
|
|->vmeta_tgetb: // TMP0 = index
|.if not DUALNUM
| tonum_u f0, TMP0
|.endif
| decode_RB8 RB, INS
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
| add CARG2, BASE, RB
|.if DUALNUM
| stw TISNUM, 0(CARG3)
| stw TMP0, 4(CARG3)
|.else
| stfd f0, 0(CARG3)
|.endif
| b >1
|
|->vmeta_tgetv:
| decode_RB8 RB, INS
| decode_RC8 RC, INS
| add CARG2, BASE, RB
| add CARG3, BASE, RC
|1:
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
| // Returns TValue * (finished) or NULL (metamethod).
| cmplwi CRET1, 0
| beq >3
|.if FPU
| lfd f0, 0(CRET1)
|.else
| lwz TMP0, 0(CRET1)
| lwz TMP1, 4(CRET1)
|.endif
| ins_next1
|.if FPU
| stfdx f0, BASE, RA
|.else
| stwux TMP0, RA, BASE
| stw TMP1, 4(RA)
|.endif
| ins_next2
|
|3: // Call __index metamethod.
| // BASE = base, L->top = new base, stack = cont/func/t/k
| subfic TMP1, BASE, FRAME_CONT
| lp BASE, L->top
| stw PC, -16(BASE) // [cont|PC]
| add PC, TMP1, BASE
| lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
| li NARGS8:RC, 16 // 2 args for func(t, k).
| b ->vm_call_dispatch_f
|
|->vmeta_tgetr:
| bl extern lj_tab_getinth // (GCtab *t, int32_t key)
| // Returns cTValue * or NULL.
| cmplwi CRET1, 0
| beq >1
|.if FPU
| lfd f14, 0(CRET1)
|.else
| lwz SAVE0, 0(CRET1)
| lwz SAVE1, 4(CRET1)
|.endif
| b ->BC_TGETR_Z
|1:
| stwx TISNIL, BASE, RA
| b ->cont_nop
|
|//-----------------------------------------------------------------------
|
|->vmeta_tsets1:
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
| li TMP0, LJ_TSTR
| decode_RB8 RB, INS
| stw STR:RC, 4(CARG3)
| add CARG2, BASE, RB
| stw TMP0, 0(CARG3)
| b >1
|
|->vmeta_tsets:
| la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
| li TMP0, LJ_TTAB
| stw TAB:RB, 4(CARG2)
| la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
| stw TMP0, 0(CARG2)
| li TMP1, LJ_TSTR
| stw STR:RC, 4(CARG3)
| stw TMP1, 0(CARG3)
| b >1
|
|->vmeta_tsetb: // TMP0 = index
|.if not DUALNUM
| tonum_u f0, TMP0
|.endif
| decode_RB8 RB, INS
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
| add CARG2, BASE, RB
|.if DUALNUM
| stw TISNUM, 0(CARG3)
| stw TMP0, 4(CARG3)
|.else
| stfd f0, 0(CARG3)
|.endif
| b >1
|
|->vmeta_tsetv:
| decode_RB8 RB, INS
| decode_RC8 RC, INS
| add CARG2, BASE, RB
| add CARG3, BASE, RC
|1:
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
| // Returns TValue * (finished) or NULL (metamethod).
| cmplwi CRET1, 0
|.if FPU
| lfdx f0, BASE, RA
|.else
| lwzux TMP2, RA, BASE
| lwz TMP3, 4(RA)
|.endif
| beq >3
| // NOBARRIER: lj_meta_tset ensures the table is not black.
| ins_next1
|.if FPU
| stfd f0, 0(CRET1)
|.else
| stw TMP2, 0(CRET1)
| stw TMP3, 4(CRET1)
|.endif
| ins_next2
|
|3: // Call __newindex metamethod.
| // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
| subfic TMP1, BASE, FRAME_CONT
| lp BASE, L->top
| stw PC, -16(BASE) // [cont|PC]
| add PC, TMP1, BASE
| lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
| li NARGS8:RC, 24 // 3 args for func(t, k, v)
|.if FPU
| stfd f0, 16(BASE) // Copy value to third argument.
|.else
| stw TMP2, 16(BASE)
| stw TMP3, 20(BASE)
|.endif
| b ->vm_call_dispatch_f
|
|->vmeta_tsetr:
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_tab_setinth // (lua_State *L, GCtab *t, int32_t key)
| // Returns TValue *.
|.if FPU
| stfd f14, 0(CRET1)
|.else
| stw SAVE0, 0(CRET1)
| stw SAVE1, 4(CRET1)
|.endif
| b ->cont_nop
|
|//-- Comparison metamethods ---------------------------------------------
|
|->vmeta_comp:
| mr CARG1, L
| subi PC, PC, 4
|.if DUALNUM
| mr CARG2, RA
|.else
| add CARG2, BASE, RA
|.endif
| stw PC, SAVE_PC
|.if DUALNUM
| mr CARG3, RD
|.else
| add CARG3, BASE, RD
|.endif
| stp BASE, L->base
| decode_OP1 CARG4, INS
| bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
| // Returns 0/1 or TValue * (metamethod).
|3:
| cmplwi CRET1, 1
| bgt ->vmeta_binop
| subfic CRET1, CRET1, 0
|4:
| lwz INS, 0(PC)
| addi PC, PC, 4
| decode_RD4 TMP2, INS
| addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
| and TMP2, TMP2, CRET1
| add PC, PC, TMP2
|->cont_nop:
| ins_next
|
|->cont_ra: // RA = resultptr
| lwz INS, -4(PC)
|.if FPU
| lfd f0, 0(RA)
|.else
| lwz CARG1, 0(RA)
| lwz CARG2, 4(RA)
|.endif
| decode_RA8 TMP1, INS
|.if FPU
| stfdx f0, BASE, TMP1
|.else
| stwux CARG1, TMP1, BASE
| stw CARG2, 4(TMP1)
|.endif
| b ->cont_nop
|
|->cont_condt: // RA = resultptr
| lwz TMP0, 0(RA)
| .gpr64 extsw TMP0, TMP0
| subfic TMP0, TMP0, LJ_TTRUE // Branch if result is true.
| subfe CRET1, CRET1, CRET1
| not CRET1, CRET1
| b <4
|
|->cont_condf: // RA = resultptr
| lwz TMP0, 0(RA)
| .gpr64 extsw TMP0, TMP0
| subfic TMP0, TMP0, LJ_TTRUE // Branch if result is false.
| subfe CRET1, CRET1, CRET1
| b <4
|
|->vmeta_equal:
| // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
| subi PC, PC, 4
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
| // Returns 0/1 or TValue * (metamethod).
| b <3
|
|->vmeta_equal_cd:
|.if FFI
| mr CARG2, INS
| subi PC, PC, 4
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_meta_equal_cd // (lua_State *L, BCIns op)
| // Returns 0/1 or TValue * (metamethod).
| b <3
|.endif
|
|->vmeta_istype:
| subi PC, PC, 4
| stp BASE, L->base
| srwi CARG2, RA, 3
| mr CARG1, L
| srwi CARG3, RD, 3
| stw PC, SAVE_PC
| bl extern lj_meta_istype // (lua_State *L, BCReg ra, BCReg tp)
| b ->cont_nop
|
|//-- Arithmetic metamethods ---------------------------------------------
|
|->vmeta_arith_nv:
| add CARG3, KBASE, RC
| add CARG4, BASE, RB
| b >1
|->vmeta_arith_nv2:
|.if DUALNUM
| mr CARG3, RC
| mr CARG4, RB
| b >1
|.endif
|
|->vmeta_unm:
| mr CARG3, RD
| mr CARG4, RD
| b >1
|
|->vmeta_arith_vn:
| add CARG3, BASE, RB
| add CARG4, KBASE, RC
| b >1
|
|->vmeta_arith_vv:
| add CARG3, BASE, RB
| add CARG4, BASE, RC
|.if DUALNUM
| b >1
|.endif
|->vmeta_arith_vn2:
|->vmeta_arith_vv2:
|.if DUALNUM
| mr CARG3, RB
| mr CARG4, RC
|.endif
|1:
| add CARG2, BASE, RA
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS.
| bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
| // Returns NULL (finished) or TValue * (metamethod).
| cmplwi CRET1, 0
| beq ->cont_nop
|
| // Call metamethod for binary op.
|->vmeta_binop:
| // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
| sub TMP1, CRET1, BASE
| stw PC, -16(CRET1) // [cont|PC]
| mr TMP2, BASE
| addi PC, TMP1, FRAME_CONT
| mr BASE, CRET1
| li NARGS8:RC, 16 // 2 args for func(o1, o2).
| b ->vm_call_dispatch
|
|->vmeta_len:
#if LJ_52
| mr SAVE0, CARG1
#endif
| mr CARG2, RD
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| bl extern lj_meta_len // (lua_State *L, TValue *o)
| // Returns NULL (retry) or TValue * (metamethod base).
#if LJ_52
| cmplwi CRET1, 0
| bne ->vmeta_binop // Binop call for compatibility.
| mr CARG1, SAVE0
| b ->BC_LEN_Z
#else
| b ->vmeta_binop // Binop call for compatibility.
#endif
|
|//-- Call metamethod ----------------------------------------------------
|
|->vmeta_call: // Resolve and call __call metamethod.
| // TMP2 = old base, BASE = new base, RC = nargs*8
| mr CARG1, L
| stp TMP2, L->base // This is the callers base!
| subi CARG2, BASE, 8
| stw PC, SAVE_PC
| add CARG3, BASE, RC
| mr SAVE0, NARGS8:RC
| bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
| lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
| addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
| ins_call
|
|->vmeta_callt: // Resolve __call for BC_CALLT.
| // BASE = old base, RA = new base, RC = nargs*8
| mr CARG1, L
| stp BASE, L->base
| subi CARG2, RA, 8
| stw PC, SAVE_PC
| add CARG3, RA, RC
| mr SAVE0, NARGS8:RC
| bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
| lwz TMP1, FRAME_PC(BASE)
| addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
| lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here.
| b ->BC_CALLT_Z
|
|//-- Argument coercion for 'for' statement ------------------------------
|
|->vmeta_for:
| mr CARG1, L
| stp BASE, L->base
| mr CARG2, RA
| stw PC, SAVE_PC
| mr SAVE0, INS
| bl extern lj_meta_for // (lua_State *L, TValue *base)
|.if JIT
| decode_OP1 TMP0, SAVE0
|.endif
| decode_RA8 RA, SAVE0
|.if JIT
| cmpwi TMP0, BC_JFORI
|.endif
| decode_RD8 RD, SAVE0
|.if JIT
| beqy =>BC_JFORI
|.endif
| b =>BC_FORI
|
|//-----------------------------------------------------------------------
|//-- Fast functions -----------------------------------------------------
|//-----------------------------------------------------------------------
|
|.macro .ffunc, name
|->ff_ .. name:
|.endmacro
|
|.macro .ffunc_1, name
|->ff_ .. name:
| cmplwi NARGS8:RC, 8
| lwz CARG3, 0(BASE)
| lwz CARG1, 4(BASE)
| blt ->fff_fallback
|.endmacro
|
|.macro .ffunc_2, name
|->ff_ .. name:
| cmplwi NARGS8:RC, 16
| lwz CARG3, 0(BASE)
| lwz CARG4, 8(BASE)
| lwz CARG1, 4(BASE)
| lwz CARG2, 12(BASE)
| blt ->fff_fallback
|.endmacro
|
|.macro .ffunc_n, name
|->ff_ .. name:
| cmplwi NARGS8:RC, 8
| lwz CARG1, 0(BASE)
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG2, 4(BASE)
|.endif
| blt ->fff_fallback
| checknum CARG1; bge ->fff_fallback
|.endmacro
|
|.macro .ffunc_nn, name
|->ff_ .. name:
| cmplwi NARGS8:RC, 16
| lwz CARG1, 0(BASE)
|.if FPU
| lfd FARG1, 0(BASE)
| lwz CARG3, 8(BASE)
| lfd FARG2, 8(BASE)
|.else
| lwz CARG2, 4(BASE)
| lwz CARG3, 8(BASE)
| lwz CARG4, 12(BASE)
|.endif
| blt ->fff_fallback
| checknum CARG1; bge ->fff_fallback
| checknum CARG3; bge ->fff_fallback
|.endmacro
|
|// Inlined GC threshold check. Caveat: uses TMP0 and TMP1.
|.macro ffgccheck
| lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
| lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
| cmplw TMP0, TMP1
| bgel ->fff_gcstep
|.endmacro
|
|//-- Base library: checks -----------------------------------------------
|
|.ffunc_1 assert
| li TMP1, LJ_TFALSE
| la RA, -8(BASE)
| cmplw cr1, CARG3, TMP1
| lwz PC, FRAME_PC(BASE)
| bge cr1, ->fff_fallback
| stw CARG3, 0(RA)
| addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8.
| addi TMP1, BASE, 8
| add TMP2, RA, NARGS8:RC
| stw CARG1, 4(RA)
| beq ->fff_res // Done if exactly 1 argument.
|1:
| cmplw TMP1, TMP2
|.if FPU
| lfd f0, 0(TMP1)
| stfd f0, 0(TMP1)
|.else
| lwz CARG1, 0(TMP1)
| lwz CARG2, 4(TMP1)
| stw CARG1, -8(TMP1)
| stw CARG2, -4(TMP1)
|.endif
| addi TMP1, TMP1, 8
| bney <1
| b ->fff_res
|
|.ffunc type
| cmplwi NARGS8:RC, 8
| lwz CARG1, 0(BASE)
| blt ->fff_fallback
| .gpr64 extsw CARG1, CARG1
| subfc TMP0, TISNUM, CARG1
| subfe TMP2, CARG1, CARG1
| orc TMP1, TMP2, TMP0
| addi TMP1, TMP1, ~LJ_TISNUM+1
| slwi TMP1, TMP1, 3
|.if FPU
| la TMP2, CFUNC:RB->upvalue
| lfdx FARG1, TMP2, TMP1
|.else
| add TMP1, CFUNC:RB, TMP1
| lwz CARG1, CFUNC:TMP1->upvalue[0].u32.hi
| lwz CARG2, CFUNC:TMP1->upvalue[0].u32.lo
|.endif
| b ->fff_resn
|
|//-- Base library: getters and setters ---------------------------------
|
|.ffunc_1 getmetatable
| checktab CARG3; bne >6
|1: // Field metatable must be at same offset for GCtab and GCudata!
| lwz TAB:CARG1, TAB:CARG1->metatable
|2:
| li CARG3, LJ_TNIL
| cmplwi TAB:CARG1, 0
| lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
| beq ->fff_restv
| lwz TMP0, TAB:CARG1->hmask
| li CARG3, LJ_TTAB // Use metatable as default result.
| lwz TMP1, STR:RC->sid
| lwz NODE:TMP2, TAB:CARG1->node
| and TMP1, TMP1, TMP0 // idx = str->sid & tab->hmask
| slwi TMP0, TMP1, 5
| slwi TMP1, TMP1, 3
| sub TMP1, TMP0, TMP1
| add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
|3: // Rearranged logic, because we expect _not_ to find the key.
| lwz CARG4, NODE:TMP2->key
| lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
| lwz CARG2, NODE:TMP2->val
| lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)
| checkstr CARG4; bne >4
| cmpw TMP0, STR:RC; beq >5
|4:
| lwz NODE:TMP2, NODE:TMP2->next
| cmplwi NODE:TMP2, 0
| beq ->fff_restv // Not found, keep default result.
| b <3
|5:
| checknil CARG2
| beq ->fff_restv // Ditto for nil value.
| mr CARG3, CARG2 // Return value of mt.__metatable.
| mr CARG1, TMP1
| b ->fff_restv
|
|6:
| cmpwi CARG3, LJ_TUDATA; beq <1
| .gpr64 extsw CARG3, CARG3
| subfc TMP0, TISNUM, CARG3
| subfe TMP2, CARG3, CARG3
| orc TMP1, TMP2, TMP0
| addi TMP1, TMP1, ~LJ_TISNUM+1
| slwi TMP1, TMP1, 2
| la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH)
| lwzx TAB:CARG1, TMP2, TMP1
| b <2
|
|.ffunc_2 setmetatable
| // Fast path: no mt for table yet and not clearing the mt.
| checktab CARG3; bne ->fff_fallback
| lwz TAB:TMP1, TAB:CARG1->metatable
| checktab CARG4; bne ->fff_fallback
| cmplwi TAB:TMP1, 0
| lbz TMP3, TAB:CARG1->marked
| bne ->fff_fallback
| andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
| stw TAB:CARG2, TAB:CARG1->metatable
| beq ->fff_restv
| barrierback TAB:CARG1, TMP3, TMP0
| b ->fff_restv
|
|.ffunc rawget
| cmplwi NARGS8:RC, 16
| lwz CARG4, 0(BASE)
| lwz TAB:CARG2, 4(BASE)
| blt ->fff_fallback
| checktab CARG4; bne ->fff_fallback
| la CARG3, 8(BASE)
| mr CARG1, L
| bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
| // Returns cTValue *.
|.if FPU
| lfd FARG1, 0(CRET1)
|.else
| lwz CARG2, 4(CRET1)
| lwz CARG1, 0(CRET1) // Caveat: CARG1 == CRET1.
|.endif
| b ->fff_resn
|
|//-- Base library: conversions ------------------------------------------
|
|.ffunc tonumber
| // Only handles the number case inline (without a base argument).
| cmplwi NARGS8:RC, 8
| lwz CARG1, 0(BASE)
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG2, 4(BASE)
|.endif
| bne ->fff_fallback // Exactly one argument.
| checknum CARG1; bgt ->fff_fallback
| b ->fff_resn
|
|.ffunc_1 tostring
| // Only handles the string or number case inline.
| checkstr CARG3
| // A __tostring method in the string base metatable is ignored.
| beq ->fff_restv // String key?
| // Handle numbers inline, unless a number base metatable is present.
| lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
| checknum CARG3
| cmplwi cr1, TMP0, 0
| stp BASE, L->base // Add frame since C call can throw.
| crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq
| stw PC, SAVE_PC // Redundant (but a defined value).
| beq ->fff_fallback
| ffgccheck
| mr CARG1, L
| mr CARG2, BASE
|.if DUALNUM
| bl extern lj_strfmt_number // (lua_State *L, cTValue *o)
|.else
| bl extern lj_strfmt_num // (lua_State *L, lua_Number *np)
|.endif
| // Returns GCstr *.
| li CARG3, LJ_TSTR
| b ->fff_restv
|
|//-- Base library: iterators -------------------------------------------
|
|.ffunc_1 next
| stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil.
| checktab CARG3
| lwz PC, FRAME_PC(BASE)
| bne ->fff_fallback
| la CARG2, 8(BASE)
| la CARG3, -8(BASE)
| bl extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o)
| // Returns 1=found, 0=end, -1=error.
| cmpwi CRET1, 0
| la RA, -8(BASE)
| li RD, (2+1)*8
| bgt ->fff_res // Found key/value.
| li CARG3, LJ_TNIL
| beq ->fff_restv // End of traversal: return nil.
| lwz CFUNC:RB, FRAME_FUNC(BASE)
| li NARGS8:RC, 2*8
| b ->fff_fallback // Invalid key.
|
|.ffunc_1 pairs
| checktab CARG3
| lwz PC, FRAME_PC(BASE)
| bne ->fff_fallback
#if LJ_52
| lwz TAB:TMP2, TAB:CARG1->metatable
|.if FPU
| lfd f0, CFUNC:RB->upvalue[0]
|.else
| lwz TMP0, CFUNC:RB->upvalue[0].u32.hi
| lwz TMP1, CFUNC:RB->upvalue[0].u32.lo
|.endif
| cmplwi TAB:TMP2, 0
| la RA, -8(BASE)
| bne ->fff_fallback
#else
|.if FPU
| lfd f0, CFUNC:RB->upvalue[0]
|.else
| lwz TMP0, CFUNC:RB->upvalue[0].u32.hi
| lwz TMP1, CFUNC:RB->upvalue[0].u32.lo
|.endif
| la RA, -8(BASE)
#endif
| stw TISNIL, 8(BASE)
| li RD, (3+1)*8
|.if FPU
| stfd f0, 0(RA)
|.else
| stw TMP0, 0(RA)
| stw TMP1, 4(RA)
|.endif
| b ->fff_res
|
|.ffunc ipairs_aux
| cmplwi NARGS8:RC, 16
| lwz CARG3, 0(BASE)
| lwz TAB:CARG1, 4(BASE)
| lwz CARG4, 8(BASE)
|.if DUALNUM
| lwz TMP2, 12(BASE)
|.else
| lfd FARG2, 8(BASE)
|.endif
| blt ->fff_fallback
| checktab CARG3
| checknum cr1, CARG4
| lwz PC, FRAME_PC(BASE)
|.if DUALNUM
| bne ->fff_fallback
| bne cr1, ->fff_fallback
|.else
| lus TMP0, 0x3ff0
| stw ZERO, TMPD_LO
| bne ->fff_fallback
| stw TMP0, TMPD_HI
| bge cr1, ->fff_fallback
| lfd FARG1, TMPD
| toint TMP2, FARG2, f0
|.endif
| lwz TMP0, TAB:CARG1->asize
| lwz TMP1, TAB:CARG1->array
|.if not DUALNUM
| fadd FARG2, FARG2, FARG1
|.endif
| addi TMP2, TMP2, 1
| la RA, -8(BASE)
| cmplw TMP0, TMP2
|.if DUALNUM
| stw TISNUM, 0(RA)
| slwi TMP3, TMP2, 3
| stw TMP2, 4(RA)
|.else
| slwi TMP3, TMP2, 3
| stfd FARG2, 0(RA)
|.endif
| ble >2 // Not in array part?
|.if FPU
| lwzx TMP2, TMP1, TMP3
| lfdx f0, TMP1, TMP3
|.else
| lwzux TMP2, TMP1, TMP3
| lwz TMP3, 4(TMP1)
|.endif
|1:
| checknil TMP2
| li RD, (0+1)*8
| beq ->fff_res // End of iteration, return 0 results.
| li RD, (2+1)*8
|.if FPU
| stfd f0, 8(RA)
|.else
| stw TMP2, 8(RA)
| stw TMP3, 12(RA)
|.endif
| b ->fff_res
|2: // Check for empty hash part first. Otherwise call C function.
| lwz TMP0, TAB:CARG1->hmask
| cmplwi TMP0, 0
| li RD, (0+1)*8
| beq ->fff_res
| mr CARG2, TMP2
| bl extern lj_tab_getinth // (GCtab *t, int32_t key)
| // Returns cTValue * or NULL.
| cmplwi CRET1, 0
| li RD, (0+1)*8
| beq ->fff_res
| lwz TMP2, 0(CRET1)
|.if FPU
| lfd f0, 0(CRET1)
|.else
| lwz TMP3, 4(CRET1)
|.endif
| b <1
|
|.ffunc_1 ipairs
| checktab CARG3
| lwz PC, FRAME_PC(BASE)
| bne ->fff_fallback
#if LJ_52
| lwz TAB:TMP2, TAB:CARG1->metatable
|.if FPU
| lfd f0, CFUNC:RB->upvalue[0]
|.else
| lwz TMP0, CFUNC:RB->upvalue[0].u32.hi
| lwz TMP1, CFUNC:RB->upvalue[0].u32.lo
|.endif
| cmplwi TAB:TMP2, 0
| la RA, -8(BASE)
| bne ->fff_fallback
#else
|.if FPU
| lfd f0, CFUNC:RB->upvalue[0]
|.else
| lwz TMP0, CFUNC:RB->upvalue[0].u32.hi
| lwz TMP1, CFUNC:RB->upvalue[0].u32.lo
|.endif
| la RA, -8(BASE)
#endif
|.if DUALNUM
| stw TISNUM, 8(BASE)
|.else
| stw ZERO, 8(BASE)
|.endif
| stw ZERO, 12(BASE)
| li RD, (3+1)*8
|.if FPU
| stfd f0, 0(RA)
|.else
| stw TMP0, 0(RA)
| stw TMP1, 4(RA)
|.endif
| b ->fff_res
|
|//-- Base library: catch errors ----------------------------------------
|
|.ffunc pcall
| cmplwi NARGS8:RC, 8
| lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
| blt ->fff_fallback
| mr TMP2, BASE
| la BASE, 8(BASE)
| // Remember active hook before pcall.
| rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31
| subi NARGS8:RC, NARGS8:RC, 8
| addi PC, TMP3, 8+FRAME_PCALL
| b ->vm_call_dispatch
|
|.ffunc xpcall
| cmplwi NARGS8:RC, 16
| lwz CARG3, 8(BASE)
|.if FPU
| lfd FARG2, 8(BASE)
| lfd FARG1, 0(BASE)
|.else
| lwz CARG1, 0(BASE)
| lwz CARG2, 4(BASE)
| lwz CARG4, 12(BASE)
|.endif
| blt ->fff_fallback
| lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH)
| mr TMP2, BASE
| checkfunc CARG3; bne ->fff_fallback // Traceback must be a function.
| la BASE, 16(BASE)
| // Remember active hook before pcall.
| rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31
|.if FPU
| stfd FARG2, 0(TMP2) // Swap function and traceback.
| stfd FARG1, 8(TMP2)
|.else
| stw CARG3, 0(TMP2)
| stw CARG4, 4(TMP2)
| stw CARG1, 8(TMP2)
| stw CARG2, 12(TMP2)
|.endif
| subi NARGS8:RC, NARGS8:RC, 16
| addi PC, TMP1, 16+FRAME_PCALL
| b ->vm_call_dispatch
|
|//-- Coroutine library --------------------------------------------------
|
|.macro coroutine_resume_wrap, resume
|.if resume
|.ffunc_1 coroutine_resume
| cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback
|.else
|.ffunc coroutine_wrap_aux
| lwz L:CARG1, CFUNC:RB->upvalue[0].gcr
|.endif
| lbz TMP0, L:CARG1->status
| lp TMP1, L:CARG1->cframe
| lp CARG2, L:CARG1->top
| cmplwi cr0, TMP0, LUA_YIELD
| lp TMP2, L:CARG1->base
| cmplwi cr1, TMP1, 0
| lwz TMP0, L:CARG1->maxstack
| cmplw cr7, CARG2, TMP2
| lwz PC, FRAME_PC(BASE)
| crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0
| add TMP2, CARG2, NARGS8:RC
| crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD
| cmplw cr1, TMP2, TMP0
| cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt
| stw PC, SAVE_PC
| cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov
| stp BASE, L->base
| blt cr6, ->fff_fallback
|1:
|.if resume
| addi BASE, BASE, 8 // Keep resumed thread in stack for GC.
| subi NARGS8:RC, NARGS8:RC, 8
| subi TMP2, TMP2, 8
|.endif
| stp TMP2, L:CARG1->top
| li TMP1, 0
| stp BASE, L->top
|2: // Move args to coroutine.
| cmpw TMP1, NARGS8:RC
|.if FPU
| lfdx f0, BASE, TMP1
|.else
| add CARG3, BASE, TMP1
| lwz TMP2, 0(CARG3)
| lwz TMP3, 4(CARG3)
|.endif
| beq >3
|.if FPU
| stfdx f0, CARG2, TMP1
|.else
| add CARG3, CARG2, TMP1
| stw TMP2, 0(CARG3)
| stw TMP3, 4(CARG3)
|.endif
| addi TMP1, TMP1, 8
| b <2
|3:
| li CARG3, 0
| mr L:SAVE0, L:CARG1
| li CARG4, 0
| bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
| // Returns thread status.
|4:
| lp TMP2, L:SAVE0->base
| cmplwi CRET1, LUA_YIELD
| lp TMP3, L:SAVE0->top
| li_vmstate INTERP
| lp BASE, L->base
| stw L, DISPATCH_GL(cur_L)(DISPATCH)
| st_vmstate
| bgt >8
| sub RD, TMP3, TMP2
| lwz TMP0, L->maxstack
| cmplwi RD, 0
| add TMP1, BASE, RD
| beq >6 // No results?
| cmplw TMP1, TMP0
| li TMP1, 0
| bgt >9 // Need to grow stack?
|
| subi TMP3, RD, 8
| stp TMP2, L:SAVE0->top // Clear coroutine stack.
|5: // Move results from coroutine.
| cmplw TMP1, TMP3
|.if FPU
| lfdx f0, TMP2, TMP1
| stfdx f0, BASE, TMP1
|.else
| add CARG3, TMP2, TMP1
| lwz CARG1, 0(CARG3)
| lwz CARG2, 4(CARG3)
| add CARG3, BASE, TMP1
| stw CARG1, 0(CARG3)
| stw CARG2, 4(CARG3)
|.endif
| addi TMP1, TMP1, 8
| bne <5
|6:
| andix. TMP0, PC, FRAME_TYPE
|.if resume
| li TMP1, LJ_TTRUE
| la RA, -8(BASE)
| stw TMP1, -8(BASE) // Prepend true to results.
| addi RD, RD, 16
|.else
| mr RA, BASE
| addi RD, RD, 8
|.endif
|7:
| stw PC, SAVE_PC
| mr MULTRES, RD
| beq ->BC_RET_Z
| b ->vm_return
|
|8: // Coroutine returned with error (at co->top-1).
|.if resume
| andix. TMP0, PC, FRAME_TYPE
| la TMP3, -8(TMP3)
| li TMP1, LJ_TFALSE
|.if FPU
| lfd f0, 0(TMP3)
|.else
| lwz CARG1, 0(TMP3)
| lwz CARG2, 4(TMP3)
|.endif
| stp TMP3, L:SAVE0->top // Remove error from coroutine stack.
| li RD, (2+1)*8
| stw TMP1, -8(BASE) // Prepend false to results.
| la RA, -8(BASE)
|.if FPU
| stfd f0, 0(BASE) // Copy error message.
|.else
| stw CARG1, 0(BASE) // Copy error message.
| stw CARG2, 4(BASE)
|.endif
| b <7
|.else
| mr CARG1, L
| mr CARG2, L:SAVE0
| bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
|.endif
|
|9: // Handle stack expansion on return from yield.
| mr CARG1, L
| srwi CARG2, RD, 3
| bl extern lj_state_growstack // (lua_State *L, int n)
| li CRET1, 0
| b <4
|.endmacro
|
| coroutine_resume_wrap 1 // coroutine.resume
| coroutine_resume_wrap 0 // coroutine.wrap
|
|.ffunc coroutine_yield
| lp TMP0, L->cframe
| add TMP1, BASE, NARGS8:RC
| stp BASE, L->base
| andix. TMP0, TMP0, CFRAME_RESUME
| stp TMP1, L->top
| li CRET1, LUA_YIELD
| beq ->fff_fallback
| stp ZERO, L->cframe
| stb CRET1, L->status
| b ->vm_leave_unw
|
|//-- Math library -------------------------------------------------------
|
|.ffunc_1 math_abs
| checknum CARG3
|.if DUALNUM
| bne >2
| srawi TMP1, CARG1, 31
| xor TMP2, TMP1, CARG1
|.if GPR64
| lus TMP0, 0x8000
| sub CARG1, TMP2, TMP1
| cmplw CARG1, TMP0
| beq >1
|.else
| sub. CARG1, TMP2, TMP1
| blt >1
|.endif
|->fff_resi:
| lwz PC, FRAME_PC(BASE)
| la RA, -8(BASE)
| stw TISNUM, -8(BASE)
| stw CRET1, -4(BASE)
| b ->fff_res1
|1:
| lus CARG3, 0x41e0 // 2^31.
| li CARG1, 0
| b ->fff_restv
|2:
|.endif
| bge ->fff_fallback
| rlwinm CARG3, CARG3, 0, 1, 31
| // Fallthrough.
|
|->fff_restv:
| // CARG3/CARG1 = TValue result.
| lwz PC, FRAME_PC(BASE)
| stw CARG3, -8(BASE)
| la RA, -8(BASE)
| stw CARG1, -4(BASE)
|->fff_res1:
| // RA = results, PC = return.
| li RD, (1+1)*8
|->fff_res:
| // RA = results, RD = (nresults+1)*8, PC = return.
| andix. TMP0, PC, FRAME_TYPE
| mr MULTRES, RD
| bney ->vm_return
| lwz INS, -4(PC)
| decode_RB8 RB, INS
|5:
| cmplw RB, RD // More results expected?
| decode_RA8 TMP0, INS
| bgt >6
| ins_next1
| // Adjust BASE. KBASE is assumed to be set for the calling frame.
| sub BASE, RA, TMP0
| ins_next2
|
|6: // Fill up results with nil.
| subi TMP1, RD, 8
| addi RD, RD, 8
| stwx TISNIL, RA, TMP1
| b <5
|
|.macro math_extern, func
| .ffunc_n math_ .. func
| blex func
| b ->fff_resn
|.endmacro
|
|.macro math_extern2, func
| .ffunc_nn math_ .. func
| blex func
| b ->fff_resn
|.endmacro
|
|.macro math_round, func
| .ffunc_1 math_ .. func
| checknum CARG3; beqy ->fff_restv
| rlwinm TMP2, CARG3, 12, 21, 31
| bge ->fff_fallback
| addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023
| cmplwi cr1, TMP2, 31 // 0 <= exp < 31?
| subfic TMP0, TMP2, 31
| blt >3
| slwi TMP1, CARG3, 11
| srwi TMP3, CARG1, 21
| oris TMP1, TMP1, 0x8000
| addi TMP2, TMP2, 1
| or TMP1, TMP1, TMP3
| slwi CARG2, CARG1, 11
| bge cr1, >4
| slw TMP3, TMP1, TMP2
| srw RD, TMP1, TMP0
| or TMP3, TMP3, CARG2
| srawi TMP2, CARG3, 31
|.if "func" == "floor"
| and TMP1, TMP3, TMP2
| addic TMP0, TMP1, -1
| subfe TMP1, TMP0, TMP1
| add CARG1, RD, TMP1
| xor CARG1, CARG1, TMP2
| sub CARG1, CARG1, TMP2
| b ->fff_resi
|.else
| andc TMP1, TMP3, TMP2
| addic TMP0, TMP1, -1
| subfe TMP1, TMP0, TMP1
| add CARG1, RD, TMP1
| cmpw CARG1, RD
| xor CARG1, CARG1, TMP2
| sub CARG1, CARG1, TMP2
| bge ->fff_resi
| // Overflow to 2^31.
| lus CARG3, 0x41e0 // 2^31.
| li CARG1, 0
| b ->fff_restv
|.endif
|3: // |x| < 1
| slwi TMP2, CARG3, 1
| srawi TMP1, CARG3, 31
| or TMP2, CARG1, TMP2 // ztest = (hi+hi) | lo
|.if "func" == "floor"
| and TMP1, TMP2, TMP1 // (ztest & sign) == 0 ? 0 : -1
| subfic TMP2, TMP1, 0
| subfe CARG1, CARG1, CARG1
|.else
| andc TMP1, TMP2, TMP1 // (ztest & ~sign) == 0 ? 0 : 1
| addic TMP2, TMP1, -1
| subfe CARG1, TMP2, TMP1
|.endif
| b ->fff_resi
|4: // exp >= 31. Check for -(2^31).
| xoris TMP1, TMP1, 0x8000
| srawi TMP2, CARG3, 31
|.if "func" == "floor"
| or TMP1, TMP1, CARG2
|.endif
|.if PPE
| orc TMP1, TMP1, TMP2
| cmpwi TMP1, 0
|.else
| orc. TMP1, TMP1, TMP2
|.endif
| crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
| lus CARG1, 0x8000 // -(2^31).
| beqy ->fff_resi
|5:
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG1, 0(BASE)
| lwz CARG2, 4(BASE)
|.endif
| blex func
| b ->fff_resn
|.endmacro
|
|.if DUALNUM
| math_round floor
| math_round ceil
|.else
| // NYI: use internal implementation.
| math_extern floor
| math_extern ceil
|.endif
|
|.if SQRT
|.ffunc_n math_sqrt
| fsqrt FARG1, FARG1
| b ->fff_resn
|.else
| math_extern sqrt
|.endif
|
|.ffunc math_log
| cmplwi NARGS8:RC, 8
| lwz CARG1, 0(BASE)
| bne ->fff_fallback // Need exactly 1 argument.
| checknum CARG1; bge ->fff_fallback
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG2, 4(BASE)
|.endif
| blex log
| b ->fff_resn
|
| math_extern log10
| math_extern exp
| math_extern sin
| math_extern cos
| math_extern tan
| math_extern asin
| math_extern acos
| math_extern atan
| math_extern sinh
| math_extern cosh
| math_extern tanh
| math_extern2 pow
| math_extern2 atan2
| math_extern2 fmod
|
|.if DUALNUM
|.ffunc math_ldexp
| cmplwi NARGS8:RC, 16
| lwz TMP0, 0(BASE)
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG1, 0(BASE)
| lwz CARG2, 4(BASE)
|.endif
| lwz TMP1, 8(BASE)
|.if GPR64
| lwz CARG2, 12(BASE)
|.elif FPU
| lwz CARG1, 12(BASE)
|.else
| lwz CARG3, 12(BASE)
|.endif
| blt ->fff_fallback
| checknum TMP0; bge ->fff_fallback
| checknum TMP1; bne ->fff_fallback
|.else
|.ffunc_nn math_ldexp
|.if GPR64
| toint CARG2, FARG2
|.else
| toint CARG1, FARG2
|.endif
|.endif
| blex ldexp
| b ->fff_resn
|
|.ffunc_n math_frexp
|.if GPR64
| la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
|.elif FPU
| la CARG1, DISPATCH_GL(tmptv)(DISPATCH)
|.else
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
|.endif
| lwz PC, FRAME_PC(BASE)
| blex frexp
| lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH)
| la RA, -8(BASE)
|.if not DUALNUM
| tonum_i FARG2, TMP1
|.endif
|.if FPU
| stfd FARG1, 0(RA)
|.else
| stw CRET1, 0(RA)
| stw CRET2, 4(RA)
|.endif
| li RD, (2+1)*8
|.if DUALNUM
| stw TISNUM, 8(RA)
| stw TMP1, 12(RA)
|.else
| stfd FARG2, 8(RA)
|.endif
| b ->fff_res
|
|.ffunc_n math_modf
|.if GPR64
| la CARG2, -8(BASE)
|.elif FPU
| la CARG1, -8(BASE)
|.else
| la CARG3, -8(BASE)
|.endif
| lwz PC, FRAME_PC(BASE)
| blex modf
| la RA, -8(BASE)
|.if FPU
| stfd FARG1, 0(BASE)
|.else
| stw CRET1, 0(BASE)
| stw CRET2, 4(BASE)
|.endif
| li RD, (2+1)*8
| b ->fff_res
|
|.macro math_minmax, name, ismax
|.if DUALNUM
| .ffunc_1 name
| checknum CARG3
| addi SAVE0, BASE, 8
| add SAVE1, BASE, NARGS8:RC
| bne >4
|1: // Handle integers.
| lwz CARG4, 0(SAVE0)
| cmplw cr1, SAVE0, SAVE1
| lwz CARG2, 4(SAVE0)
| bge cr1, ->fff_resi
| checknum CARG4
| xoris TMP0, CARG1, 0x8000
| xoris TMP3, CARG2, 0x8000
| bne >3
| subfc TMP3, TMP3, TMP0
| subfe TMP0, TMP0, TMP0
|.if ismax
| andc TMP3, TMP3, TMP0
|.else
| and TMP3, TMP3, TMP0
|.endif
| add CARG1, TMP3, CARG2
|.if GPR64
| rldicl CARG1, CARG1, 0, 32
|.endif
| addi SAVE0, SAVE0, 8
| b <1
|3:
| bge ->fff_fallback
| // Convert intermediate result to number and continue below.
|.if FPU
| tonum_i FARG1, CARG1
| lfd FARG2, 0(SAVE0)
|.else
| mr CARG2, CARG1
| bl ->vm_sfi2d_1
| lwz CARG3, 0(SAVE0)
| lwz CARG4, 4(SAVE0)
|.endif
| b >6
|4:
|.if FPU
| lfd FARG1, 0(BASE)
|.else
| lwz CARG1, 0(BASE)
| lwz CARG2, 4(BASE)
|.endif
| bge ->fff_fallback
|5: // Handle numbers.
| lwz CARG3, 0(SAVE0)
| cmplw cr1, SAVE0, SAVE1
|.if FPU
| lfd FARG2, 0(SAVE0)
|.else
| lwz CARG4, 4(SAVE0)
|.endif
| bge cr1, ->fff_resn
| checknum CARG3; bge >7
|6:
| addi SAVE0, SAVE0, 8
|.if FPU
|.if ismax
| fsub f0, FARG1, FARG2
|.else
| fsub f0, FARG2, FARG1
|.endif
| fsel FARG1, f0, FARG1, FARG2
|.else
| stw CARG1, SFSAVE_1
| stw CARG2, SFSAVE_2
| stw CARG3, SFSAVE_3
| stw CARG4, SFSAVE_4
| blex __ledf2
| cmpwi CRET1, 0
|.if ismax
| blt >8
|.else
| bge >8
|.endif
| lwz CARG1, SFSAVE_1
| lwz CARG2, SFSAVE_2
| b <5
|8:
| lwz CARG1, SFSAVE_3
| lwz CARG2, SFSAVE_4
|.endif
| b <5
|7: // Convert integer to number and continue above.
| lwz CARG3, 4(SAVE0)
| bne ->fff_fallback
|.if FPU
| tonum_i FARG2, CARG3
|.else
| bl ->vm_sfi2d_2
|.endif
| b <6
|.else
| .ffunc_n name
| li TMP1, 8
|1:
| lwzx CARG2, BASE, TMP1
| lfdx FARG2, BASE, TMP1
| cmplw cr1, TMP1, NARGS8:RC
| checknum CARG2
| bge cr1, ->fff_resn
| bge ->fff_fallback
|.if ismax
| fsub f0, FARG1, FARG2
|.else
| fsub f0, FARG2, FARG1
|.endif
| addi TMP1, TMP1, 8
| fsel FARG1, f0, FARG1, FARG2
| b <1
|.endif
|.endmacro
|
| math_minmax math_min, 0
| math_minmax math_max, 1
|
|//-- String library -----------------------------------------------------
|
|.ffunc string_byte // Only handle the 1-arg case here.
| cmplwi NARGS8:RC, 8
| lwz CARG3, 0(BASE)
| lwz STR:CARG1, 4(BASE)
| bne ->fff_fallback // Need exactly 1 argument.
| checkstr CARG3
| bne ->fff_fallback
| lwz TMP0, STR:CARG1->len
|.if DUALNUM
| lbz CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
| li RD, (0+1)*8
| lwz PC, FRAME_PC(BASE)
| cmplwi TMP0, 0
| la RA, -8(BASE)
| beqy ->fff_res
| b ->fff_resi
|.else
| lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end).
| addic TMP3, TMP0, -1 // RD = ((str->len != 0)+1)*8
| subfe RD, TMP3, TMP0
| stw TMP1, TONUM_LO // Inlined tonum_u f0, TMP1.
| addi RD, RD, 1
| lfd f0, TONUM_D
| la RA, -8(BASE)
| lwz PC, FRAME_PC(BASE)
| fsub f0, f0, TOBIT
| slwi RD, RD, 3
| stfd f0, 0(RA)
| b ->fff_res
|.endif
|
|.ffunc string_char // Only handle the 1-arg case here.
| ffgccheck
| cmplwi NARGS8:RC, 8
| lwz CARG3, 0(BASE)
|.if DUALNUM
| lwz TMP0, 4(BASE)
| bne ->fff_fallback // Exactly 1 argument.
| checknum CARG3; bne ->fff_fallback
| la CARG2, 7(BASE)
|.else
| lfd FARG1, 0(BASE)
| bne ->fff_fallback // Exactly 1 argument.
| checknum CARG3; bge ->fff_fallback
| toint TMP0, FARG1
| la CARG2, TMPD_BLO
|.endif
| li CARG3, 1
| cmplwi TMP0, 255; bgt ->fff_fallback
|->fff_newstr:
| mr CARG1, L
| stp BASE, L->base
| stw PC, SAVE_PC
| bl extern lj_str_new // (lua_State *L, char *str, size_t l)
|->fff_resstr:
| // Returns GCstr *.
| lp BASE, L->base
| li CARG3, LJ_TSTR
| b ->fff_restv
|
|.ffunc string_sub
| ffgccheck
| cmplwi NARGS8:RC, 16
| lwz CARG3, 16(BASE)
|.if not DUALNUM
| lfd f0, 16(BASE)
|.endif
| lwz TMP0, 0(BASE)
| lwz STR:CARG1, 4(BASE)
| blt ->fff_fallback
| lwz CARG2, 8(BASE)
|.if DUALNUM
| lwz TMP1, 12(BASE)
|.else
| lfd f1, 8(BASE)
|.endif
| li TMP2, -1
| beq >1
|.if DUALNUM
| checknum CARG3
| lwz TMP2, 20(BASE)
| bne ->fff_fallback
|1:
| checknum CARG2; bne ->fff_fallback
|.else
| checknum CARG3; bge ->fff_fallback
| toint TMP2, f0
|1:
| checknum CARG2; bge ->fff_fallback
|.endif
| checkstr TMP0; bne ->fff_fallback
|.if not DUALNUM
| toint TMP1, f1
|.endif
| lwz TMP0, STR:CARG1->len
| cmplw TMP0, TMP2 // len < end? (unsigned compare)
| addi TMP3, TMP2, 1
| blt >5
|2:
| cmpwi TMP1, 0 // start <= 0?
| add TMP3, TMP1, TMP0
| ble >7
|3:
| sub CARG3, TMP2, TMP1
| addi CARG2, STR:CARG1, #STR-1
| srawi TMP0, CARG3, 31
| addi CARG3, CARG3, 1
| add CARG2, CARG2, TMP1
| andc CARG3, CARG3, TMP0
|.if GPR64
| rldicl CARG2, CARG2, 0, 32
| rldicl CARG3, CARG3, 0, 32
|.endif
| b ->fff_newstr
|
|5: // Negative end or overflow.
| cmpw TMP0, TMP2 // len >= end? (signed compare)
| add TMP2, TMP0, TMP3 // Negative end: end = end+len+1.
| bge <2
| mr TMP2, TMP0 // Overflow: end = len.
| b <2
|
|7: // Negative start or underflow.
| .gpr64 extsw TMP1, TMP1
| addic CARG3, TMP1, -1
| subfe CARG3, CARG3, CARG3
| srawi CARG2, TMP3, 31 // Note: modifies carry.
| andc TMP3, TMP3, CARG3
| andc TMP1, TMP3, CARG2
| addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0)
| b <3
|
|.macro ffstring_op, name
| .ffunc string_ .. name
| ffgccheck
| cmplwi NARGS8:RC, 8
| lwz CARG3, 0(BASE)
| lwz STR:CARG2, 4(BASE)
| blt ->fff_fallback
| checkstr CARG3
| la SBUF:CARG1, DISPATCH_GL(tmpbuf)(DISPATCH)
| bne ->fff_fallback
| lwz TMP0, SBUF:CARG1->b
| stw L, SBUF:CARG1->L
| stp BASE, L->base
| stw PC, SAVE_PC
| stw TMP0, SBUF:CARG1->w
| bl extern lj_buf_putstr_ .. name
| bl extern lj_buf_tostr
| b ->fff_resstr
|.endmacro
|
|ffstring_op reverse
|ffstring_op lower
|ffstring_op upper
|
|//-- Bit library --------------------------------------------------------
|
|.macro .ffunc_bit, name
|.if DUALNUM
| .ffunc_1 bit_..name
| checknum CARG3; bnel ->fff_tobit_fb
|.else
| .ffunc_n bit_..name
| fadd FARG1, FARG1, TOBIT
| stfd FARG1, TMPD
| lwz CARG1, TMPD_LO
|.endif
|.endmacro
|
|.macro .ffunc_bit_op, name, ins
| .ffunc_bit name
| addi SAVE0, BASE, 8
| add SAVE1, BASE, NARGS8:RC
|1:
| lwz CARG4, 0(SAVE0)
| cmplw cr1, SAVE0, SAVE1
|.if DUALNUM
| lwz CARG2, 4(SAVE0)
|.else
| lfd FARG1, 0(SAVE0)
|.endif
| bgey cr1, ->fff_resi
| checknum CARG4
|.if DUALNUM
|.if FPU
| bnel ->fff_bitop_fb
|.else
| beq >3
| stw CARG1, SFSAVE_1
| bl ->fff_bitop_fb
| mr CARG2, CARG1
| lwz CARG1, SFSAVE_1
|3:
|.endif
|.else
| fadd FARG1, FARG1, TOBIT
| bge ->fff_fallback
| stfd FARG1, TMPD
| lwz CARG2, TMPD_LO
|.endif
| ins CARG1, CARG1, CARG2
| addi SAVE0, SAVE0, 8
| b <1
|.endmacro
|
|.ffunc_bit_op band, and
|.ffunc_bit_op bor, or
|.ffunc_bit_op bxor, xor
|
|.ffunc_bit bswap
| rotlwi TMP0, CARG1, 8
| rlwimi TMP0, CARG1, 24, 0, 7
| rlwimi TMP0, CARG1, 24, 16, 23
| mr CRET1, TMP0
| b ->fff_resi
|
|.ffunc_bit bnot
| not CRET1, CARG1
| b ->fff_resi
|
|.macro .ffunc_bit_sh, name, ins, shmod
|.if DUALNUM
| .ffunc_2 bit_..name
|.if FPU
| checknum CARG3; bnel ->fff_tobit_fb
|.else
| checknum CARG3; beq >1
| bl ->fff_tobit_fb
| lwz CARG2, 12(BASE) // Conversion polluted CARG2.
|1:
|.endif
| // Note: no inline conversion from number for 2nd argument!
| checknum CARG4; bne ->fff_fallback
|.else
| .ffunc_nn bit_..name
| fadd FARG1, FARG1, TOBIT
| fadd FARG2, FARG2, TOBIT
| stfd FARG1, TMPD
| lwz CARG1, TMPD_LO
| stfd FARG2, TMPD
| lwz CARG2, TMPD_LO
|.endif
|.if shmod == 1
| rlwinm CARG2, CARG2, 0, 27, 31
|.elif shmod == 2
| neg CARG2, CARG2
|.endif
| ins CRET1, CARG1, CARG2
| b ->fff_resi
|.endmacro
|
|.ffunc_bit_sh lshift, slw, 1
|.ffunc_bit_sh rshift, srw, 1
|.ffunc_bit_sh arshift, sraw, 1
|.ffunc_bit_sh rol, rotlw, 0
|.ffunc_bit_sh ror, rotlw, 2
|
|.ffunc_bit tobit
|.if DUALNUM
| b ->fff_resi
|.else
|->fff_resi:
| tonum_i FARG1, CRET1
|.endif
|->fff_resn:
| lwz PC, FRAME_PC(BASE)
| la RA, -8(BASE)
|.if FPU
| stfd FARG1, -8(BASE)
|.else
| stw CARG1, -8(BASE)
| stw CARG2, -4(BASE)
|.endif
| b ->fff_res1
|
|// Fallback FP number to bit conversion.
|->fff_tobit_fb:
|.if DUALNUM
|.if FPU
| lfd FARG1, 0(BASE)
| bgt ->fff_fallback
| fadd FARG1, FARG1, TOBIT
| stfd FARG1, TMPD
| lwz CARG1, TMPD_LO
| blr
|.else
| bgt ->fff_fallback
| mr CARG2, CARG1
| mr CARG1, CARG3
|// Modifies: CARG1, CARG2, TMP0, TMP1, TMP2.
|->vm_tobit:
| slwi TMP2, CARG1, 1
| addis TMP2, TMP2, 0x0020
| cmpwi TMP2, 0
| bge >2
| li TMP1, 0x3e0
| srawi TMP2, TMP2, 21
| not TMP1, TMP1
| sub. TMP2, TMP1, TMP2
| cmpwi cr7, CARG1, 0
| blt >1
| slwi TMP1, CARG1, 11
| srwi TMP0, CARG2, 21
| oris TMP1, TMP1, 0x8000
| or TMP1, TMP1, TMP0
| srw CARG1, TMP1, TMP2
| bclr 4, 28 // Return if cr7[lt] == 0, no hint.
| neg CARG1, CARG1
| blr
|1:
| addi TMP2, TMP2, 21
| srw TMP1, CARG2, TMP2
| slwi CARG2, CARG1, 12
| subfic TMP2, TMP2, 20
| slw TMP0, CARG2, TMP2
| or CARG1, TMP1, TMP0
| bclr 4, 28 // Return if cr7[lt] == 0, no hint.
| neg CARG1, CARG1
| blr
|2:
| li CARG1, 0
| blr
|.endif
|.endif
|->fff_bitop_fb:
|.if DUALNUM
|.if FPU
| lfd FARG1, 0(SAVE0)
| bgt ->fff_fallback
| fadd FARG1, FARG1, TOBIT
| stfd FARG1, TMPD
| lwz CARG2, TMPD_LO
| blr
|.else
| bgt ->fff_fallback
| mr CARG1, CARG4
| b ->vm_tobit
|.endif
|.endif
|
|//-----------------------------------------------------------------------
|
|->fff_fallback: // Call fast function fallback handler.
| // BASE = new base, RB = CFUNC, RC = nargs*8
| lp TMP3, CFUNC:RB->f
| add TMP1, BASE, NARGS8:RC
| lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC.
| addi TMP0, TMP1, 8*LUA_MINSTACK
| lwz TMP2, L->maxstack
| stw PC, SAVE_PC // Redundant (but a defined value).
| .toc lp TMP3, 0(TMP3)
| cmplw TMP0, TMP2
| stp BASE, L->base
| stp TMP1, L->top
| mr CARG1, L
| bgt >5 // Need to grow stack.
| mtctr TMP3
| bctrl // (lua_State *L)
| // Either throws an error, or recovers and returns -1, 0 or nresults+1.
| lp BASE, L->base
| cmpwi CRET1, 0
| slwi RD, CRET1, 3
| la RA, -8(BASE)
| bgt ->fff_res // Returned nresults+1?
|1: // Returned 0 or -1: retry fast path.
| lp TMP0, L->top
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| sub NARGS8:RC, TMP0, BASE
| bne ->vm_call_tail // Returned -1?
| ins_callt // Returned 0: retry fast path.
|
|// Reconstruct previous base for vmeta_call during tailcall.
|->vm_call_tail:
| andix. TMP0, PC, FRAME_TYPE
| rlwinm TMP1, PC, 0, 0, 28
| bne >3
| lwz INS, -4(PC)
| decode_RA8 TMP1, INS
| addi TMP1, TMP1, 8
|3:
| sub TMP2, BASE, TMP1
| b ->vm_call_dispatch // Resolve again for tailcall.
|
|5: // Grow stack for fallback handler.
| li CARG2, LUA_MINSTACK
| bl extern lj_state_growstack // (lua_State *L, int n)
| lp BASE, L->base
| cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry.
| b <1
|
|->fff_gcstep: // Call GC step function.
| // BASE = new base, RC = nargs*8
| mflr SAVE0
| stp BASE, L->base
| add TMP0, BASE, NARGS8:RC
| stw PC, SAVE_PC // Redundant (but a defined value).
| stp TMP0, L->top
| mr CARG1, L
| bl extern lj_gc_step // (lua_State *L)
| lp BASE, L->base
| mtlr SAVE0
| lp TMP0, L->top
| sub NARGS8:RC, TMP0, BASE
| lwz CFUNC:RB, FRAME_FUNC(BASE)
| blr
|
|//-----------------------------------------------------------------------
|//-- Special dispatch targets -------------------------------------------
|//-----------------------------------------------------------------------
|
|->vm_record: // Dispatch target for recording phase.
|.if JIT
| lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
| andix. TMP0, TMP3, HOOK_VMEVENT // No recording while in vmevent.
| bne >5
| // Decrement the hookcount for consistency, but always do the call.
| lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)
| andix. TMP0, TMP3, HOOK_ACTIVE
| bne >1
| subi TMP2, TMP2, 1
| andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
| beqy >1
| stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
| b >1
|.endif
|
|->vm_rethook: // Dispatch target for return hooks.
| lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
| andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
| beq >1
|5: // Re-dispatch to static ins.
| addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OPP TMP1, INS.
| lpx TMP0, DISPATCH, TMP1
| mtctr TMP0
| bctr
|
|->vm_inshook: // Dispatch target for instr/line hooks.
| lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
| lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)
| andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
| rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0
| bne <5
|
| cmpwi cr1, TMP0, 0
| addic. TMP2, TMP2, -1
| beq cr1, <5
| stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
| beq >1
| bge cr1, <5
|1:
| mr CARG1, L
| stw MULTRES, SAVE_MULTRES
| mr CARG2, PC
| stp BASE, L->base
| // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
| bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
|3:
| lp BASE, L->base
|4: // Re-dispatch to static ins.
| lwz INS, -4(PC)
| decode_OPP TMP1, INS
| decode_RB8 RB, INS
| addi TMP1, TMP1, GG_DISP2STATIC
| decode_RD8 RD, INS
| lpx TMP0, DISPATCH, TMP1
| decode_RA8 RA, INS
| decode_RC8 RC, INS
| mtctr TMP0
| bctr
|
|->cont_hook: // Continue from hook yield.
| addi PC, PC, 4
| lwz MULTRES, -20(RB) // Restore MULTRES for *M ins.
| b <4
|
|->vm_hotloop: // Hot loop counter underflow.
|.if JIT
| lwz LFUNC:TMP1, FRAME_FUNC(BASE)
| addi CARG1, DISPATCH, GG_DISP2J
| stw PC, SAVE_PC
| lwz TMP1, LFUNC:TMP1->pc
| mr CARG2, PC
| stw L, DISPATCH_J(L)(DISPATCH)
| lbz TMP1, PC2PROTO(framesize)(TMP1)
| stp BASE, L->base
| slwi TMP1, TMP1, 3
| add TMP1, BASE, TMP1
| stp TMP1, L->top
| bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
| b <3
|.endif
|
|->vm_callhook: // Dispatch target for call hooks.
| mr CARG2, PC
|.if JIT
| b >1
|.endif
|
|->vm_hotcall: // Hot call counter underflow.
|.if JIT
| ori CARG2, PC, 1
|1:
|.endif
| add TMP0, BASE, RC
| stw PC, SAVE_PC
| mr CARG1, L
| stp BASE, L->base
| sub RA, RA, BASE
| stp TMP0, L->top
| bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
| // Returns ASMFunction.
| lp BASE, L->base
| lp TMP0, L->top
| stw ZERO, SAVE_PC // Invalidate for subsequent line hook.
| sub NARGS8:RC, TMP0, BASE
| add RA, BASE, RA
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| lwz INS, -4(PC)
| mtctr CRET1
| bctr
|
|->cont_stitch: // Trace stitching.
|.if JIT
| // RA = resultptr, RB = meta base
| lwz INS, -4(PC)
| lwz TRACE:TMP2, -20(RB) // Save previous trace.
| addic. TMP1, MULTRES, -8
| decode_RA8 RC, INS // Call base.
| beq >2
|1: // Move results down.
|.if FPU
| lfd f0, 0(RA)
|.else
| lwz CARG1, 0(RA)
| lwz CARG2, 4(RA)
|.endif
| addic. TMP1, TMP1, -8
| addi RA, RA, 8
|.if FPU
| stfdx f0, BASE, RC
|.else
| add CARG3, BASE, RC
| stw CARG1, 0(CARG3)
| stw CARG2, 4(CARG3)
|.endif
| addi RC, RC, 8
| bne <1
|2:
| decode_RA8 RA, INS
| decode_RB8 RB, INS
| add RA, RA, RB
|3:
| cmplw RA, RC
| bgt >9 // More results wanted?
|
| lhz TMP3, TRACE:TMP2->traceno
| lhz RD, TRACE:TMP2->link
| cmpw RD, TMP3
| cmpwi cr1, RD, 0
| beq ->cont_nop // Blacklisted.
| slwi RD, RD, 3
| bne cr1, =>BC_JLOOP // Jump to stitched trace.
|
| // Stitch a new trace to the previous trace.
| stw TMP3, DISPATCH_J(exitno)(DISPATCH)
| stp L, DISPATCH_J(L)(DISPATCH)
| stp BASE, L->base
| addi CARG1, DISPATCH, GG_DISP2J
| mr CARG2, PC
| bl extern lj_dispatch_stitch // (jit_State *J, const BCIns *pc)
| lp BASE, L->base
| b ->cont_nop
|
|9:
| stwx TISNIL, BASE, RC
| addi RC, RC, 8
| b <3
|.endif
|
|->vm_profhook: // Dispatch target for profiler hook.
#if LJ_HASPROFILE
| mr CARG1, L
| stw MULTRES, SAVE_MULTRES
| mr CARG2, PC
| stp BASE, L->base
| bl extern lj_dispatch_profile // (lua_State *L, const BCIns *pc)
| // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.
| lp BASE, L->base
| subi PC, PC, 4
| b ->cont_nop
#endif
|
|//-----------------------------------------------------------------------
|//-- Trace exit handler -------------------------------------------------
|//-----------------------------------------------------------------------
|
|.macro savex_, a, b, c, d
|.if FPU
| stfd f..a, 16+a*8(sp)
| stfd f..b, 16+b*8(sp)
| stfd f..c, 16+c*8(sp)
| stfd f..d, 16+d*8(sp)
|.endif
|.endmacro
|
|->vm_exit_handler:
|.if JIT
| addi sp, sp, -(16+32*8+32*4)
| stmw r2, 16+32*8+2*4(sp)
| addi DISPATCH, JGL, -GG_DISP2G-32768
| li CARG2, ~LJ_VMST_EXIT
| lwz CARG1, 16+32*8+32*4(sp) // Get stack chain.
| stw CARG2, DISPATCH_GL(vmstate)(DISPATCH)
| savex_ 0,1,2,3
| stw CARG1, 0(sp) // Store extended stack chain.
| clrso TMP1
| savex_ 4,5,6,7
| addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp.
| savex_ 8,9,10,11
| stw CARG2, 16+32*8+1*4(sp) // Store sp in RID_SP.
| savex_ 12,13,14,15
| mflr CARG3
| li TMP1, 0
| savex_ 16,17,18,19
| stw TMP1, 16+32*8+0*4(sp) // Clear RID_TMP.
| savex_ 20,21,22,23
| lhz CARG4, 2(CARG3) // Load trace number.
| savex_ 24,25,26,27
| lwz L, DISPATCH_GL(cur_L)(DISPATCH)
| savex_ 28,29,30,31
| sub CARG3, TMP0, CARG3 // Compute exit number.
| lp BASE, DISPATCH_GL(jit_base)(DISPATCH)
| srwi CARG3, CARG3, 2
| stp L, DISPATCH_J(L)(DISPATCH)
| subi CARG3, CARG3, 2
| stp BASE, L->base
| stw CARG4, DISPATCH_J(parent)(DISPATCH)
| stw TMP1, DISPATCH_GL(jit_base)(DISPATCH)
| addi CARG1, DISPATCH, GG_DISP2J
| stw CARG3, DISPATCH_J(exitno)(DISPATCH)
| addi CARG2, sp, 16
| bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
| // Returns MULTRES (unscaled) or negated error code.
| lp TMP1, L->cframe
| lwz TMP2, 0(sp)
| lp BASE, L->base
|.if GPR64
| rldicr sp, TMP1, 0, 61
|.else
| rlwinm sp, TMP1, 0, 0, 29
|.endif
| lwz PC, SAVE_PC // Get SAVE_PC.
| stw TMP2, 0(sp)
| stw L, SAVE_L // Set SAVE_L (on-trace resume/yield).
| b >1
|.endif
|->vm_exit_interp:
|.if JIT
| // CARG1 = MULTRES or negated error code, BASE, PC and JGL set.
| lwz L, SAVE_L
| addi DISPATCH, JGL, -GG_DISP2G-32768
| stp BASE, L->base
|1:
| cmpwi CARG1, 0
| blt >9 // Check for error from exit.
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| slwi MULTRES, CARG1, 3
| li TMP2, 0
| stw MULTRES, SAVE_MULTRES
| lwz TMP1, LFUNC:RB->pc
| stw TMP2, DISPATCH_GL(jit_base)(DISPATCH)
| lwz KBASE, PC2PROTO(k)(TMP1)
| // Setup type comparison constants.
| li TISNUM, LJ_TISNUM
| .FPU lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
| .FPU stw TMP3, TMPD
| li ZERO, 0
| .FPU ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
| .FPU lfs TOBIT, TMPD
| .FPU stw TMP3, TMPD
| .FPU lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
| li TISNIL, LJ_TNIL
| .FPU stw TMP0, TONUM_HI
| .FPU lfs TONUM, TMPD
| // Modified copy of ins_next which handles function header dispatch, too.
| lwz INS, 0(PC)
| addi PC, PC, 4
| // Assumes TISNIL == ~LJ_VMST_INTERP == -1.
| stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
| decode_OPP TMP1, INS
| decode_RA8 RA, INS
| lpx TMP0, DISPATCH, TMP1
| mtctr TMP0
| cmplwi TMP1, BC_FUNCF*4 // Function header?
| bge >2
| decode_RB8 RB, INS
| decode_RD8 RD, INS
| decode_RC8 RC, INS
| bctr
|2:
| cmplwi TMP1, (BC_FUNCC+2)*4 // Fast function?
| blt >3
| // Check frame below fast function.
| lwz TMP1, FRAME_PC(BASE)
| andix. TMP0, TMP1, FRAME_TYPE
| bney >3 // Trace stitching continuation?
| // Otherwise set KBASE for Lua function below fast function.
| lwz TMP2, -4(TMP1)
| decode_RA8 TMP0, TMP2
| sub TMP1, BASE, TMP0
| lwz LFUNC:TMP2, -12(TMP1)
| lwz TMP1, LFUNC:TMP2->pc
| lwz KBASE, PC2PROTO(k)(TMP1)
|3:
| subi RC, MULTRES, 8
| add RA, RA, BASE
| bctr
|
|9: // Rethrow error from the right C frame.
| neg CARG2, CARG1
| mr CARG1, L
| bl extern lj_err_trace // (lua_State *L, int errcode)
|.endif
|
|//-----------------------------------------------------------------------
|//-- Math helper functions ----------------------------------------------
|//-----------------------------------------------------------------------
|
|// NYI: Use internal implementations of floor, ceil, trunc, sfcmp.
|
|.macro sfi2d, AHI, ALO
|.if not FPU
| mr. AHI, ALO
| bclr 12, 2 // Handle zero first.
| srawi TMP0, ALO, 31
| xor TMP1, ALO, TMP0
| sub TMP1, TMP1, TMP0 // Absolute value in TMP1.
| cntlzw AHI, TMP1
| andix. TMP0, TMP0, 0x800 // Mask sign bit.
| slw TMP1, TMP1, AHI // Align mantissa left with leading 1.
| subfic AHI, AHI, 0x3ff+31-1 // Exponent -1 in AHI.
| slwi ALO, TMP1, 21
| or AHI, AHI, TMP0 // Sign | Exponent.
| srwi TMP1, TMP1, 11
| slwi AHI, AHI, 20 // Align left.
| add AHI, AHI, TMP1 // Add mantissa, increment exponent.
| blr
|.endif
|.endmacro
|
|// Input: CARG2. Output: CARG1, CARG2. Temporaries: TMP0, TMP1.
|->vm_sfi2d_1:
| sfi2d CARG1, CARG2
|
|// Input: CARG4. Output: CARG3, CARG4. Temporaries: TMP0, TMP1.
|->vm_sfi2d_2:
| sfi2d CARG3, CARG4
|
|->vm_modi:
| divwo. TMP0, CARG1, CARG2
| bso >1
|.if GPR64
| xor CARG3, CARG1, CARG2
| cmpwi CARG3, 0
|.else
| xor. CARG3, CARG1, CARG2
|.endif
| mullw TMP0, TMP0, CARG2
| sub CARG1, CARG1, TMP0
| bgelr
| cmpwi CARG1, 0; beqlr
| add CARG1, CARG1, CARG2
| blr
|1:
| cmpwi CARG2, 0
| li CARG1, 0
| beqlr
| clrso TMP0 // Clear SO for -2147483648 % -1 and return 0.
| blr
|
|//-----------------------------------------------------------------------
|//-- Miscellaneous functions --------------------------------------------
|//-----------------------------------------------------------------------
|
|// void lj_vm_cachesync(void *start, void *end)
|// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size.
|// This is a good lower bound, except for very ancient PPC models.
|->vm_cachesync:
|.if JIT or FFI
| // Compute start of first cache line and number of cache lines.
| rlwinm CARG1, CARG1, 0, 0, 26
| sub CARG2, CARG2, CARG1
| addi CARG2, CARG2, 31
| rlwinm. CARG2, CARG2, 27, 5, 31
| beqlr
| mtctr CARG2
| mr CARG3, CARG1
|1: // Flush D-Cache.
| dcbst r0, CARG1
| addi CARG1, CARG1, 32
| bdnz <1
| sync
| mtctr CARG2
|1: // Invalidate I-Cache.
| icbi r0, CARG3
| addi CARG3, CARG3, 32
| bdnz <1
| isync
| blr
|.endif
|
|->vm_next:
|.if JIT
| NYI // On big-endian.
|.endif
|
|//-----------------------------------------------------------------------
|//-- FFI helper functions -----------------------------------------------
|//-----------------------------------------------------------------------
|
|// Handler for callback functions. Callback slot number in r11, g in r12.
|->vm_ffi_callback:
|.if FFI
|.type CTSTATE, CTState, PC
| saveregs
| lwz CTSTATE, GL:r12->ctype_state
| addi DISPATCH, r12, GG_G2DISP
| stw r11, CTSTATE->cb.slot
| stw r3, CTSTATE->cb.gpr[0]
| .FPU stfd f1, CTSTATE->cb.fpr[0]
| stw r4, CTSTATE->cb.gpr[1]
| .FPU stfd f2, CTSTATE->cb.fpr[1]
| stw r5, CTSTATE->cb.gpr[2]
| .FPU stfd f3, CTSTATE->cb.fpr[2]
| stw r6, CTSTATE->cb.gpr[3]
| .FPU stfd f4, CTSTATE->cb.fpr[3]
| stw r7, CTSTATE->cb.gpr[4]
| .FPU stfd f5, CTSTATE->cb.fpr[4]
| stw r8, CTSTATE->cb.gpr[5]
| .FPU stfd f6, CTSTATE->cb.fpr[5]
| stw r9, CTSTATE->cb.gpr[6]
| .FPU stfd f7, CTSTATE->cb.fpr[6]
| stw r10, CTSTATE->cb.gpr[7]
| .FPU stfd f8, CTSTATE->cb.fpr[7]
| addi TMP0, sp, CFRAME_SPACE+8
| stw TMP0, CTSTATE->cb.stack
| mr CARG1, CTSTATE
| stw CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
| mr CARG2, sp
| bl extern lj_ccallback_enter // (CTState *cts, void *cf)
| // Returns lua_State *.
| lp BASE, L:CRET1->base
| li TISNUM, LJ_TISNUM // Setup type comparison constants.
| lp RC, L:CRET1->top
| .FPU lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
| li ZERO, 0
| mr L, CRET1
| .FPU stw TMP3, TMPD
| .FPU lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| .FPU ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
| .FPU stw TMP0, TONUM_HI
| li TISNIL, LJ_TNIL
| li_vmstate INTERP
| .FPU lfs TOBIT, TMPD
| .FPU stw TMP3, TMPD
| sub RC, RC, BASE
| st_vmstate
| .FPU lfs TONUM, TMPD
| ins_callt
|.endif
|
|->cont_ffi_callback: // Return from FFI callback.
|.if FFI
| lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)
| stp BASE, L->base
| stp RB, L->top
| stp L, CTSTATE->L
| mr CARG1, CTSTATE
| mr CARG2, RA
| bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
| lwz CRET1, CTSTATE->cb.gpr[0]
| .FPU lfd FARG1, CTSTATE->cb.fpr[0]
| lwz CRET2, CTSTATE->cb.gpr[1]
| b ->vm_leave_unw
|.endif
|
|->vm_ffi_call: // Call C function via FFI.
| // Caveat: needs special frame unwinding, see below.
|.if FFI
| .type CCSTATE, CCallState, CARG1
| lwz TMP1, CCSTATE->spadj
| mflr TMP0
| lbz CARG2, CCSTATE->nsp
| lbz CARG3, CCSTATE->nfpr
| neg TMP1, TMP1
| stw TMP0, 4(sp)
| cmpwi cr1, CARG3, 0
| mr TMP2, sp
| addic. CARG2, CARG2, -1
| stwux sp, sp, TMP1
| crnot 4*cr1+eq, 4*cr1+eq // For vararg calls.
| stw r14, -4(TMP2)
| stw CCSTATE, -8(TMP2)
| mr r14, TMP2
| la TMP1, CCSTATE->stack
| slwi CARG2, CARG2, 2
| blty >2
| la TMP2, 8(sp)
|1:
| lwzx TMP0, TMP1, CARG2
| stwx TMP0, TMP2, CARG2
| addic. CARG2, CARG2, -4
| bge <1
|2:
| bney cr1, >3
| .FPU lfd f1, CCSTATE->fpr[0]
| .FPU lfd f2, CCSTATE->fpr[1]
| .FPU lfd f3, CCSTATE->fpr[2]
| .FPU lfd f4, CCSTATE->fpr[3]
| .FPU lfd f5, CCSTATE->fpr[4]
| .FPU lfd f6, CCSTATE->fpr[5]
| .FPU lfd f7, CCSTATE->fpr[6]
| .FPU lfd f8, CCSTATE->fpr[7]
|3:
| lp TMP0, CCSTATE->func
| lwz CARG2, CCSTATE->gpr[1]
| lwz CARG3, CCSTATE->gpr[2]
| lwz CARG4, CCSTATE->gpr[3]
| lwz CARG5, CCSTATE->gpr[4]
| mtctr TMP0
| lwz r8, CCSTATE->gpr[5]
| lwz r9, CCSTATE->gpr[6]
| lwz r10, CCSTATE->gpr[7]
| lwz CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1.
| bctrl
| lwz CCSTATE:TMP1, -8(r14)
| lwz TMP2, -4(r14)
| lwz TMP0, 4(r14)
| stw CARG1, CCSTATE:TMP1->gpr[0]
| .FPU stfd FARG1, CCSTATE:TMP1->fpr[0]
| stw CARG2, CCSTATE:TMP1->gpr[1]
| mtlr TMP0
| stw CARG3, CCSTATE:TMP1->gpr[2]
| mr sp, r14
| stw CARG4, CCSTATE:TMP1->gpr[3]
| mr r14, TMP2
| blr
|.endif
|// Note: vm_ffi_call must be the last function in this object file!
|
|//-----------------------------------------------------------------------
}
/* Generate the code for a single instruction. */
static void build_ins(BuildCtx *ctx, BCOp op, int defop)
{
int vk = 0;
|=>defop:
switch (op) {
/* -- Comparison ops ---------------------------------------------------- */
/* Remember: all ops branch for a true comparison, fall through otherwise. */
case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
| // RA = src1*8, RD = src2*8, JMP with RD = target
|.if DUALNUM
| lwzux CARG1, RA, BASE
| addi PC, PC, 4
| lwz CARG2, 4(RA)
| lwzux CARG3, RD, BASE
| lwz TMP2, -4(PC)
| checknum cr0, CARG1
| lwz CARG4, 4(RD)
| decode_RD4 TMP2, TMP2
| checknum cr1, CARG3
| addis SAVE0, TMP2, -(BCBIAS_J*4 >> 16)
| bne cr0, >7
| bne cr1, >8
| cmpw CARG2, CARG4
if (op == BC_ISLT) {
| bge >2
} else if (op == BC_ISGE) {
| blt >2
} else if (op == BC_ISLE) {
| bgt >2
} else {
| ble >2
}
|1:
| add PC, PC, SAVE0
|2:
| ins_next
|
|7: // RA is not an integer.
| bgt cr0, ->vmeta_comp
| // RA is a number.
| .FPU lfd f0, 0(RA)
| bgt cr1, ->vmeta_comp
| blt cr1, >4
| // RA is a number, RD is an integer.
|.if FPU
| tonum_i f1, CARG4
|.else
| bl ->vm_sfi2d_2
|.endif
| b >5
|
|8: // RA is an integer, RD is not an integer.
| bgt cr1, ->vmeta_comp
| // RA is an integer, RD is a number.
|.if FPU
| tonum_i f0, CARG2
|.else
| bl ->vm_sfi2d_1
|.endif
|4:
| .FPU lfd f1, 0(RD)
|5:
|.if FPU
| fcmpu cr0, f0, f1
|.else
| blex __ledf2
| cmpwi CRET1, 0
|.endif
if (op == BC_ISLT) {
| bge <2
} else if (op == BC_ISGE) {
| blt <2
} else if (op == BC_ISLE) {
| cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
| bge <2
} else {
| cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
| blt <2
}
| b <1
|.else
| lwzx TMP0, BASE, RA
| addi PC, PC, 4
| lfdx f0, BASE, RA
| lwzx TMP1, BASE, RD
| checknum cr0, TMP0
| lwz TMP2, -4(PC)
| lfdx f1, BASE, RD
| checknum cr1, TMP1
| decode_RD4 TMP2, TMP2
| bge cr0, ->vmeta_comp
| addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
| bge cr1, ->vmeta_comp
| fcmpu cr0, f0, f1
if (op == BC_ISLT) {
| bge >1
} else if (op == BC_ISGE) {
| blt >1
} else if (op == BC_ISLE) {
| cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
| bge >1
} else {
| cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
| blt >1
}
| add PC, PC, TMP2
|1:
| ins_next
|.endif
break;
case BC_ISEQV: case BC_ISNEV:
vk = op == BC_ISEQV;
| // RA = src1*8, RD = src2*8, JMP with RD = target
|.if DUALNUM
| lwzux CARG1, RA, BASE
| addi PC, PC, 4
| lwz CARG2, 4(RA)
| lwzux CARG3, RD, BASE
| checknum cr0, CARG1
| lwz SAVE0, -4(PC)
| checknum cr1, CARG3
| decode_RD4 SAVE0, SAVE0
| lwz CARG4, 4(RD)
| cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt
| addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)
if (vk) {
| ble cr7, ->BC_ISEQN_Z
} else {
| ble cr7, ->BC_ISNEN_Z
}
|.else
| lwzux CARG1, RA, BASE
| lwz SAVE0, 0(PC)
| lfd f0, 0(RA)
| addi PC, PC, 4
| lwzux CARG3, RD, BASE
| checknum cr0, CARG1
| decode_RD4 SAVE0, SAVE0
| lfd f1, 0(RD)
| checknum cr1, CARG3
| addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)
| bge cr0, >5
| bge cr1, >5
| fcmpu cr0, f0, f1
if (vk) {
| bne >1
| add PC, PC, SAVE0
} else {
| beq >1
| add PC, PC, SAVE0
}
|1:
| ins_next
|.endif
|5: // Either or both types are not numbers.
|.if not DUALNUM
| lwz CARG2, 4(RA)
| lwz CARG4, 4(RD)
|.endif
|.if FFI
| cmpwi cr7, CARG1, LJ_TCDATA
| cmpwi cr5, CARG3, LJ_TCDATA
|.endif
| not TMP2, CARG1
| cmplw CARG1, CARG3
| cmplwi cr1, TMP2, ~LJ_TISPRI // Primitive?
|.if FFI
| cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq
|.endif
| cmplwi cr6, TMP2, ~LJ_TISTABUD // Table or userdata?
|.if FFI
| beq cr7, ->vmeta_equal_cd
|.endif
| cmplw cr5, CARG2, CARG4
| crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt // 2: Same type and primitive.
| crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq // 1: Same tv or different type.
| crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq // 0: Same type and same tv.
| mr SAVE1, PC
| cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt // 0 or 2.
| cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt // 1 or 2.
if (vk) {
| bne cr0, >6
| add PC, PC, SAVE0
|6:
} else {
| beq cr0, >6
| add PC, PC, SAVE0
|6:
}
|.if DUALNUM
| bge cr0, >2 // Done if 1 or 2.
|1:
| ins_next
|2:
|.else
| blt cr0, <1 // Done if 1 or 2.
|.endif
| blt cr6, <1 // Done if not tab/ud.
|
| // Different tables or userdatas. Need to check __eq metamethod.
| // Field metatable must be at same offset for GCtab and GCudata!
| mr CARG3, CARG4
| lwz TAB:TMP2, TAB:CARG2->metatable
| li CARG4, 1-vk // ne = 0 or 1.
| cmplwi TAB:TMP2, 0
| beq <1 // No metatable?
| lbz TMP2, TAB:TMP2->nomm
| andix. TMP2, TMP2, 1<<MM_eq
| bne <1 // Or 'no __eq' flag set?
| mr PC, SAVE1 // Restore old PC.
| b ->vmeta_equal // Handle __eq metamethod.
break;
case BC_ISEQS: case BC_ISNES:
vk = op == BC_ISEQS;
| // RA = src*8, RD = str_const*8 (~), JMP with RD = target
| lwzux TMP0, RA, BASE
| srwi RD, RD, 1
| lwz STR:TMP3, 4(RA)
| lwz TMP2, 0(PC)
| subfic RD, RD, -4
| addi PC, PC, 4
|.if FFI
| cmpwi TMP0, LJ_TCDATA
|.endif
| lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4
| .gpr64 extsw TMP0, TMP0
| subfic TMP0, TMP0, LJ_TSTR
|.if FFI
| beq ->vmeta_equal_cd
|.endif
| sub TMP1, STR:TMP1, STR:TMP3
| or TMP0, TMP0, TMP1
| decode_RD4 TMP2, TMP2
| subfic TMP0, TMP0, 0
| addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
| subfe TMP1, TMP1, TMP1
if (vk) {
| andc TMP2, TMP2, TMP1
} else {
| and TMP2, TMP2, TMP1
}
| add PC, PC, TMP2
| ins_next
break;
case BC_ISEQN: case BC_ISNEN:
vk = op == BC_ISEQN;
| // RA = src*8, RD = num_const*8, JMP with RD = target
|.if DUALNUM
| lwzux CARG1, RA, BASE
| addi PC, PC, 4
| lwz CARG2, 4(RA)
| lwzux CARG3, RD, KBASE
| checknum cr0, CARG1
| lwz SAVE0, -4(PC)
| checknum cr1, CARG3
| decode_RD4 SAVE0, SAVE0
| lwz CARG4, 4(RD)
| addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)
if (vk) {
|->BC_ISEQN_Z:
} else {
|->BC_ISNEN_Z:
}
| bne cr0, >7
| bne cr1, >8
| cmpw CARG2, CARG4
|4:
|.else
if (vk) {
|->BC_ISEQN_Z: // Dummy label.
} else {
|->BC_ISNEN_Z: // Dummy label.
}
| lwzx CARG1, BASE, RA
| addi PC, PC, 4
| lfdx f0, BASE, RA
| lwz SAVE0, -4(PC)
| lfdx f1, KBASE, RD
| decode_RD4 SAVE0, SAVE0
| checknum CARG1
| addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)
| bge >3
| fcmpu cr0, f0, f1
|.endif
if (vk) {
| bne >1
| add PC, PC, SAVE0
|1:
|.if not FFI
|3:
|.endif
} else {
| beq >2
|1:
|.if not FFI
|3:
|.endif
| add PC, PC, SAVE0
|2:
}
| ins_next
|.if FFI
|3:
| cmpwi CARG1, LJ_TCDATA
| beq ->vmeta_equal_cd
| b <1
|.endif
|.if DUALNUM
|7: // RA is not an integer.
| bge cr0, <3
| // RA is a number.
| .FPU lfd f0, 0(RA)
| blt cr1, >1
| // RA is a number, RD is an integer.
|.if FPU
| tonum_i f1, CARG4
|.else
| bl ->vm_sfi2d_2
|.endif
| b >2
|
|8: // RA is an integer, RD is a number.
|.if FPU
| tonum_i f0, CARG2
|.else
| bl ->vm_sfi2d_1
|.endif
|1:
| .FPU lfd f1, 0(RD)
|2:
|.if FPU
| fcmpu cr0, f0, f1
|.else
| blex __ledf2
| cmpwi CRET1, 0
|.endif
| b <4
|.endif
break;
case BC_ISEQP: case BC_ISNEP:
vk = op == BC_ISEQP;
| // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
| lwzx TMP0, BASE, RA
| srwi TMP1, RD, 3
| lwz TMP2, 0(PC)
| not TMP1, TMP1
| addi PC, PC, 4
|.if FFI
| cmpwi TMP0, LJ_TCDATA
|.endif
| sub TMP0, TMP0, TMP1
|.if FFI
| beq ->vmeta_equal_cd
|.endif
| decode_RD4 TMP2, TMP2
| .gpr64 extsw TMP0, TMP0
| addic TMP0, TMP0, -1
| addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
| subfe TMP1, TMP1, TMP1
if (vk) {
| and TMP2, TMP2, TMP1
} else {
| andc TMP2, TMP2, TMP1
}
| add PC, PC, TMP2
| ins_next
break;
/* -- Unary test and copy ops ------------------------------------------- */
case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
| // RA = dst*8 or unused, RD = src*8, JMP with RD = target
| lwzx TMP0, BASE, RD
| lwz INS, 0(PC)
| addi PC, PC, 4
if (op == BC_IST || op == BC_ISF) {
| .gpr64 extsw TMP0, TMP0
| subfic TMP0, TMP0, LJ_TTRUE
| decode_RD4 TMP2, INS
| subfe TMP1, TMP1, TMP1
| addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
if (op == BC_IST) {
| andc TMP2, TMP2, TMP1
} else {
| and TMP2, TMP2, TMP1
}
| add PC, PC, TMP2
} else {
| li TMP1, LJ_TFALSE
|.if FPU
| lfdx f0, BASE, RD
|.else
| lwzux CARG1, RD, BASE
| lwz CARG2, 4(RD)
|.endif
| cmplw TMP0, TMP1
if (op == BC_ISTC) {
| bge >1
} else {
| blt >1
}
| addis PC, PC, -(BCBIAS_J*4 >> 16)
| decode_RD4 TMP2, INS
|.if FPU
| stfdx f0, BASE, RA
|.else
| stwux CARG1, RA, BASE
| stw CARG2, 4(RA)
|.endif
| add PC, PC, TMP2
|1:
}
| ins_next
break;
case BC_ISTYPE:
| // RA = src*8, RD = -type*8
| lwzx TMP0, BASE, RA
| srwi TMP1, RD, 3
| ins_next1
|.if not PPE and not GPR64
| add. TMP0, TMP0, TMP1
|.else
| neg TMP1, TMP1
| cmpw TMP0, TMP1
|.endif
| bne ->vmeta_istype
| ins_next2
break;
case BC_ISNUM:
| // RA = src*8, RD = -(TISNUM-1)*8
| lwzx TMP0, BASE, RA
| ins_next1
| checknum TMP0
| bge ->vmeta_istype
| ins_next2
break;
/* -- Unary ops --------------------------------------------------------- */
case BC_MOV:
| // RA = dst*8, RD = src*8
| ins_next1
|.if FPU
| lfdx f0, BASE, RD
| stfdx f0, BASE, RA
|.else
| lwzux TMP0, RD, BASE
| lwz TMP1, 4(RD)
| stwux TMP0, RA, BASE
| stw TMP1, 4(RA)
|.endif
| ins_next2
break;
case BC_NOT:
| // RA = dst*8, RD = src*8
| ins_next1
| lwzx TMP0, BASE, RD
| .gpr64 extsw TMP0, TMP0
| subfic TMP1, TMP0, LJ_TTRUE
| adde TMP0, TMP0, TMP1
| stwx TMP0, BASE, RA
| ins_next2
break;
case BC_UNM:
| // RA = dst*8, RD = src*8
| lwzux TMP1, RD, BASE
| lwz TMP0, 4(RD)
| checknum TMP1
|.if DUALNUM
| bne >5
|.if GPR64
| lus TMP2, 0x8000
| neg TMP0, TMP0
| cmplw TMP0, TMP2
| beq >4
|.else
| nego. TMP0, TMP0
| bso >4
|1:
|.endif
| ins_next1
| stwux TISNUM, RA, BASE
| stw TMP0, 4(RA)
|3:
| ins_next2
|4:
|.if not GPR64
| // Potential overflow.
| checkov TMP1, <1 // Ignore unrelated overflow.
|.endif
| lus TMP1, 0x41e0 // 2^31.
| li TMP0, 0
| b >7
|.endif
|5:
| bge ->vmeta_unm
| xoris TMP1, TMP1, 0x8000
|7:
| ins_next1
| stwux TMP1, RA, BASE
| stw TMP0, 4(RA)
|.if DUALNUM
| b <3
|.else
| ins_next2
|.endif
break;
case BC_LEN:
| // RA = dst*8, RD = src*8
| lwzux TMP0, RD, BASE
| lwz CARG1, 4(RD)
| checkstr TMP0; bne >2
| lwz CRET1, STR:CARG1->len
|1:
|.if DUALNUM
| ins_next1
| stwux TISNUM, RA, BASE
| stw CRET1, 4(RA)
|.else
| tonum_u f0, CRET1 // Result is a non-negative integer.
| ins_next1
| stfdx f0, BASE, RA
|.endif
| ins_next2
|2:
| checktab TMP0; bne ->vmeta_len
#if LJ_52
| lwz TAB:TMP2, TAB:CARG1->metatable
| cmplwi TAB:TMP2, 0
| bne >9
|3:
#endif
|->BC_LEN_Z:
| bl extern lj_tab_len // (GCtab *t)
| // Returns uint32_t (but less than 2^31).
| b <1
#if LJ_52
|9:
| lbz TMP0, TAB:TMP2->nomm
| andix. TMP0, TMP0, 1<<MM_len
| bne <3 // 'no __len' flag set: done.
| b ->vmeta_len
#endif
break;
/* -- Binary ops -------------------------------------------------------- */
|.macro ins_arithpre
| // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
||switch (vk) {
||case 0:
| lwzx CARG1, BASE, RB
| .if DUALNUM
| lwzx CARG3, KBASE, RC
| .endif
| .if FPU
| lfdx f14, BASE, RB
| lfdx f15, KBASE, RC
| .else
| add TMP1, BASE, RB
| add TMP2, KBASE, RC
| lwz CARG2, 4(TMP1)
| lwz CARG4, 4(TMP2)
| .endif
| .if DUALNUM
| checknum cr0, CARG1
| checknum cr1, CARG3
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
| bge ->vmeta_arith_vn
| .else
| checknum CARG1; bge ->vmeta_arith_vn
| .endif
|| break;
||case 1:
| lwzx CARG1, BASE, RB
| .if DUALNUM
| lwzx CARG3, KBASE, RC
| .endif
| .if FPU
| lfdx f15, BASE, RB
| lfdx f14, KBASE, RC
| .else
| add TMP1, BASE, RB
| add TMP2, KBASE, RC
| lwz CARG2, 4(TMP1)
| lwz CARG4, 4(TMP2)
| .endif
| .if DUALNUM
| checknum cr0, CARG1
| checknum cr1, CARG3
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
| bge ->vmeta_arith_nv
| .else
| checknum CARG1; bge ->vmeta_arith_nv
| .endif
|| break;
||default:
| lwzx CARG1, BASE, RB
| lwzx CARG3, BASE, RC
| .if FPU
| lfdx f14, BASE, RB
| lfdx f15, BASE, RC
| .else
| add TMP1, BASE, RB
| add TMP2, BASE, RC
| lwz CARG2, 4(TMP1)
| lwz CARG4, 4(TMP2)
| .endif
| checknum cr0, CARG1
| checknum cr1, CARG3
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
| bge ->vmeta_arith_vv
|| break;
||}
|.endmacro
|
|.macro ins_arithfallback, ins
||switch (vk) {
||case 0:
| ins ->vmeta_arith_vn2
|| break;
||case 1:
| ins ->vmeta_arith_nv2
|| break;
||default:
| ins ->vmeta_arith_vv2
|| break;
||}
|.endmacro
|
|.macro intmod, a, b, c
| bl ->vm_modi
|.endmacro
|
|.macro fpmod, a, b, c
|->BC_MODVN_Z:
| fdiv FARG1, b, c
| // NYI: Use internal implementation of floor.
| blex floor // floor(b/c)
| fmul a, FARG1, c
| fsub a, b, a // b - floor(b/c)*c
|.endmacro
|
|.macro sfpmod
|->BC_MODVN_Z:
| stw CARG1, SFSAVE_1
| stw CARG2, SFSAVE_2
| mr SAVE0, CARG3
| mr SAVE1, CARG4
| blex __divdf3
| blex floor
| mr CARG3, SAVE0
| mr CARG4, SAVE1
| blex __muldf3
| mr CARG3, CRET1
| mr CARG4, CRET2
| lwz CARG1, SFSAVE_1
| lwz CARG2, SFSAVE_2
| blex __subdf3
|.endmacro
|
|.macro ins_arithfp, fpins
| ins_arithpre
|.if "fpins" == "fpmod_"
| b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
|.elif FPU
| fpins f0, f14, f15
| ins_next1
| stfdx f0, BASE, RA
| ins_next2
|.else
| blex __divdf3 // Only soft-float div uses this macro.
| ins_next1
| stwux CRET1, RA, BASE
| stw CRET2, 4(RA)
| ins_next2
|.endif
|.endmacro
|
|.macro ins_arithdn, intins, fpins, fpcall
| // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
||switch (vk) {
||case 0:
| lwzux CARG1, RB, BASE
| lwzux CARG3, RC, KBASE
| lwz CARG2, 4(RB)
| checknum cr0, CARG1
| lwz CARG4, 4(RC)
| checknum cr1, CARG3
|| break;
||case 1:
| lwzux CARG3, RB, BASE
| lwzux CARG1, RC, KBASE
| lwz CARG4, 4(RB)
| checknum cr0, CARG3
| lwz CARG2, 4(RC)
| checknum cr1, CARG1
|| break;
||default:
| lwzux CARG1, RB, BASE
| lwzux CARG3, RC, BASE
| lwz CARG2, 4(RB)
| checknum cr0, CARG1
| lwz CARG4, 4(RC)
| checknum cr1, CARG3
|| break;
||}
| bne >5
| bne cr1, >5
|.if "intins" == "intmod"
| mr CARG1, CARG2
| mr CARG2, CARG4
|.endif
| intins CARG1, CARG2, CARG4
| bso >4
|1:
| ins_next1
| stwux TISNUM, RA, BASE
| stw CARG1, 4(RA)
|2:
| ins_next2
|4: // Overflow.
| checkov TMP0, <1 // Ignore unrelated overflow.
| ins_arithfallback b
|5: // FP variant.
|.if FPU
||if (vk == 1) {
| lfd f15, 0(RB)
| lfd f14, 0(RC)
||} else {
| lfd f14, 0(RB)
| lfd f15, 0(RC)
||}
|.endif
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
| ins_arithfallback bge
|.if "fpins" == "fpmod_"
| b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
|.else
|.if FPU
| fpins f0, f14, f15
| stfdx f0, BASE, RA
|.else
|.if "fpcall" == "sfpmod"
| sfpmod
|.else
| blex fpcall
|.endif
| stwux CRET1, RA, BASE
| stw CRET2, 4(RA)
|.endif
| ins_next1
| b <2
|.endif
|.endmacro
|
|.macro ins_arith, intins, fpins, fpcall
|.if DUALNUM
| ins_arithdn intins, fpins, fpcall
|.else
| ins_arithfp fpins
|.endif
|.endmacro
case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
|.if GPR64
|.macro addo32., y, a, b
| // Need to check overflow for (a<<32) + (b<<32).
| rldicr TMP0, a, 32, 31
| rldicr TMP1, b, 32, 31
| addo. TMP0, TMP0, TMP1
| add y, a, b
|.endmacro
| ins_arith addo32., fadd, __adddf3
|.else
| ins_arith addo., fadd, __adddf3
|.endif
break;
case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
|.if GPR64
|.macro subo32., y, a, b
| // Need to check overflow for (a<<32) - (b<<32).
| rldicr TMP0, a, 32, 31
| rldicr TMP1, b, 32, 31
| subo. TMP0, TMP0, TMP1
| sub y, a, b
|.endmacro
| ins_arith subo32., fsub, __subdf3
|.else
| ins_arith subo., fsub, __subdf3
|.endif
break;
case BC_MULVN: case BC_MULNV: case BC_MULVV:
| ins_arith mullwo., fmul, __muldf3
break;
case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
| ins_arithfp fdiv
break;
case BC_MODVN:
| ins_arith intmod, fpmod, sfpmod
break;
case BC_MODNV: case BC_MODVV:
| ins_arith intmod, fpmod_, sfpmod
break;
case BC_POW:
| // NYI: (partial) integer arithmetic.
| lwzx CARG1, BASE, RB
| lwzx CARG3, BASE, RC
|.if FPU
| lfdx FARG1, BASE, RB
| lfdx FARG2, BASE, RC
|.else
| add TMP1, BASE, RB
| add TMP2, BASE, RC
| lwz CARG2, 4(TMP1)
| lwz CARG4, 4(TMP2)
|.endif
| checknum cr0, CARG1
| checknum cr1, CARG3
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
| bge ->vmeta_arith_vv
| blex pow
| ins_next1
|.if FPU
| stfdx FARG1, BASE, RA
|.else
| stwux CARG1, RA, BASE
| stw CARG2, 4(RA)
|.endif
| ins_next2
break;
case BC_CAT:
| // RA = dst*8, RB = src_start*8, RC = src_end*8
| sub CARG3, RC, RB
| stp BASE, L->base
| add CARG2, BASE, RC
| mr SAVE0, RB
|->BC_CAT_Z:
| stw PC, SAVE_PC
| mr CARG1, L
| srwi CARG3, CARG3, 3
| bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
| // Returns NULL (finished) or TValue * (metamethod).
| cmplwi CRET1, 0
| lp BASE, L->base
| bne ->vmeta_binop
| ins_next1
|.if FPU
| lfdx f0, BASE, SAVE0 // Copy result from RB to RA.
| stfdx f0, BASE, RA
|.else
| lwzux TMP0, SAVE0, BASE
| lwz TMP1, 4(SAVE0)
| stwux TMP0, RA, BASE
| stw TMP1, 4(RA)
|.endif
| ins_next2
break;
/* -- Constant ops ------------------------------------------------------ */
case BC_KSTR:
| // RA = dst*8, RD = str_const*8 (~)
| srwi TMP1, RD, 1
| subfic TMP1, TMP1, -4
| ins_next1
| lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4
| li TMP2, LJ_TSTR
| stwux TMP2, RA, BASE
| stw TMP0, 4(RA)
| ins_next2
break;
case BC_KCDATA:
|.if FFI
| // RA = dst*8, RD = cdata_const*8 (~)
| srwi TMP1, RD, 1
| subfic TMP1, TMP1, -4
| ins_next1
| lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4
| li TMP2, LJ_TCDATA
| stwux TMP2, RA, BASE
| stw TMP0, 4(RA)
| ins_next2
|.endif
break;
case BC_KSHORT:
| // RA = dst*8, RD = int16_literal*8
|.if DUALNUM
| slwi RD, RD, 13
| srawi RD, RD, 16
| ins_next1
| stwux TISNUM, RA, BASE
| stw RD, 4(RA)
| ins_next2
|.else
| // The soft-float approach is faster.
| slwi RD, RD, 13
| srawi TMP1, RD, 31
| xor TMP2, TMP1, RD
| sub TMP2, TMP2, TMP1 // TMP2 = abs(x)
| cntlzw TMP3, TMP2
| subfic TMP1, TMP3, 0x40d // TMP1 = exponent-1
| slw TMP2, TMP2, TMP3 // TMP2 = left aligned mantissa
| subfic TMP3, RD, 0
| slwi TMP1, TMP1, 20
| rlwimi RD, TMP2, 21, 1, 31 // hi = sign(x) | (mantissa>>11)
| subfe TMP0, TMP0, TMP0
| add RD, RD, TMP1 // hi = hi + exponent-1
| and RD, RD, TMP0 // hi = x == 0 ? 0 : hi
| ins_next1
| stwux RD, RA, BASE
| stw ZERO, 4(RA)
| ins_next2
|.endif
break;
case BC_KNUM:
| // RA = dst*8, RD = num_const*8
| ins_next1
|.if FPU
| lfdx f0, KBASE, RD
| stfdx f0, BASE, RA
|.else
| lwzux TMP0, RD, KBASE
| lwz TMP1, 4(RD)
| stwux TMP0, RA, BASE
| stw TMP1, 4(RA)
|.endif
| ins_next2
break;
case BC_KPRI:
| // RA = dst*8, RD = primitive_type*8 (~)
| srwi TMP1, RD, 3
| not TMP0, TMP1
| ins_next1
| stwx TMP0, BASE, RA
| ins_next2
break;
case BC_KNIL:
| // RA = base*8, RD = end*8
| stwx TISNIL, BASE, RA
| addi RA, RA, 8
|1:
| stwx TISNIL, BASE, RA
| cmpw RA, RD
| addi RA, RA, 8
| blt <1
| ins_next_
break;
/* -- Upvalue and function ops ------------------------------------------ */
case BC_UGET:
| // RA = dst*8, RD = uvnum*8
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| srwi RD, RD, 1
| addi RD, RD, offsetof(GCfuncL, uvptr)
| lwzx UPVAL:RB, LFUNC:RB, RD
| ins_next1
| lwz TMP1, UPVAL:RB->v
|.if FPU
| lfd f0, 0(TMP1)
| stfdx f0, BASE, RA
|.else
| lwz TMP2, 0(TMP1)
| lwz TMP3, 4(TMP1)
| stwux TMP2, RA, BASE
| stw TMP3, 4(RA)
|.endif
| ins_next2
break;
case BC_USETV:
| // RA = uvnum*8, RD = src*8
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| srwi RA, RA, 1
| addi RA, RA, offsetof(GCfuncL, uvptr)
|.if FPU
| lfdux f0, RD, BASE
|.else
| lwzux CARG1, RD, BASE
| lwz CARG3, 4(RD)
|.endif
| lwzx UPVAL:RB, LFUNC:RB, RA
| lbz TMP3, UPVAL:RB->marked
| lwz CARG2, UPVAL:RB->v
| andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
| lbz TMP0, UPVAL:RB->closed
| lwz TMP2, 0(RD)
|.if FPU
| stfd f0, 0(CARG2)
|.else
| stw CARG1, 0(CARG2)
| stw CARG3, 4(CARG2)
|.endif
| cmplwi cr1, TMP0, 0
| lwz TMP1, 4(RD)
| cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
| subi TMP2, TMP2, (LJ_TNUMX+1)
| bne >2 // Upvalue is closed and black?
|1:
| ins_next
|
|2: // Check if new value is collectable.
| cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1)
| bge <1 // tvisgcv(v)
| lbz TMP3, GCOBJ:TMP1->gch.marked
| andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(v)
| la CARG1, GG_DISP2G(DISPATCH)
| // Crossed a write barrier. Move the barrier forward.
| beq <1
| bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
| b <1
break;
case BC_USETS:
| // RA = uvnum*8, RD = str_const*8 (~)
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| srwi TMP1, RD, 1
| srwi RA, RA, 1
| subfic TMP1, TMP1, -4
| addi RA, RA, offsetof(GCfuncL, uvptr)
| lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4
| lwzx UPVAL:RB, LFUNC:RB, RA
| lbz TMP3, UPVAL:RB->marked
| lwz CARG2, UPVAL:RB->v
| andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
| lbz TMP3, STR:TMP1->marked
| lbz TMP2, UPVAL:RB->closed
| li TMP0, LJ_TSTR
| stw STR:TMP1, 4(CARG2)
| stw TMP0, 0(CARG2)
| bne >2
|1:
| ins_next
|
|2: // Check if string is white and ensure upvalue is closed.
| andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(str)
| cmplwi cr1, TMP2, 0
| cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
| la CARG1, GG_DISP2G(DISPATCH)
| // Crossed a write barrier. Move the barrier forward.
| beq <1
| bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
| b <1
break;
case BC_USETN:
| // RA = uvnum*8, RD = num_const*8
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| srwi RA, RA, 1
| addi RA, RA, offsetof(GCfuncL, uvptr)
|.if FPU
| lfdx f0, KBASE, RD
|.else
| lwzux TMP2, RD, KBASE
| lwz TMP3, 4(RD)
|.endif
| lwzx UPVAL:RB, LFUNC:RB, RA
| ins_next1
| lwz TMP1, UPVAL:RB->v
|.if FPU
| stfd f0, 0(TMP1)
|.else
| stw TMP2, 0(TMP1)
| stw TMP3, 4(TMP1)
|.endif
| ins_next2
break;
case BC_USETP:
| // RA = uvnum*8, RD = primitive_type*8 (~)
| lwz LFUNC:RB, FRAME_FUNC(BASE)
| srwi RA, RA, 1
| srwi TMP0, RD, 3
| addi RA, RA, offsetof(GCfuncL, uvptr)
| not TMP0, TMP0
| lwzx UPVAL:RB, LFUNC:RB, RA
| ins_next1
| lwz TMP1, UPVAL:RB->v
| stw TMP0, 0(TMP1)
| ins_next2
break;
case BC_UCLO:
| // RA = level*8, RD = target
| lwz TMP1, L->openupval
| branch_RD // Do this first since RD is not saved.
| stp BASE, L->base
| cmplwi TMP1, 0
| mr CARG1, L
| beq >1
| add CARG2, BASE, RA
| bl extern lj_func_closeuv // (lua_State *L, TValue *level)
| lp BASE, L->base
|1:
| ins_next
break;
case BC_FNEW:
| // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
| srwi TMP1, RD, 1
| stp BASE, L->base
| subfic TMP1, TMP1, -4
| stw PC, SAVE_PC
| lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
| mr CARG1, L
| lwz CARG3, FRAME_FUNC(BASE)
| // (lua_State *L, GCproto *pt, GCfuncL *parent)
| bl extern lj_func_newL_gc
| // Returns GCfuncL *.
| lp BASE, L->base
| li TMP0, LJ_TFUNC
| stwux TMP0, RA, BASE
| stw LFUNC:CRET1, 4(RA)
| ins_next
break;
/* -- Table ops --------------------------------------------------------- */
case BC_TNEW:
case BC_TDUP:
| // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
| lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
| mr CARG1, L
| lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
| stp BASE, L->base
| cmplw TMP0, TMP1
| stw PC, SAVE_PC
| bge >5
|1:
if (op == BC_TNEW) {
| rlwinm CARG2, RD, 29, 21, 31
| rlwinm CARG3, RD, 18, 27, 31
| cmpwi CARG2, 0x7ff; beq >3
|2:
| bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
| // Returns Table *.
} else {
| srwi TMP1, RD, 1
| subfic TMP1, TMP1, -4
| lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
| bl extern lj_tab_dup // (lua_State *L, Table *kt)
| // Returns Table *.
}
| lp BASE, L->base
| li TMP0, LJ_TTAB
| stwux TMP0, RA, BASE
| stw TAB:CRET1, 4(RA)
| ins_next
if (op == BC_TNEW) {
|3:
| li CARG2, 0x801
| b <2
}
|5:
| mr SAVE0, RD
| bl extern lj_gc_step_fixtop // (lua_State *L)
| mr RD, SAVE0
| mr CARG1, L
| b <1
break;
case BC_GGET:
| // RA = dst*8, RD = str_const*8 (~)
case BC_GSET:
| // RA = src*8, RD = str_const*8 (~)
| lwz LFUNC:TMP2, FRAME_FUNC(BASE)
| srwi TMP1, RD, 1
| lwz TAB:RB, LFUNC:TMP2->env
| subfic TMP1, TMP1, -4
| lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
if (op == BC_GGET) {
| b ->BC_TGETS_Z
} else {
| b ->BC_TSETS_Z
}
break;
case BC_TGETV:
| // RA = dst*8, RB = table*8, RC = key*8
| lwzux CARG1, RB, BASE
| lwzux CARG2, RC, BASE
| lwz TAB:RB, 4(RB)
|.if DUALNUM
| lwz RC, 4(RC)
|.else
| lfd f0, 0(RC)
|.endif
| checktab CARG1
| checknum cr1, CARG2
| bne ->vmeta_tgetv
|.if DUALNUM
| lwz TMP0, TAB:RB->asize
| bne cr1, >5
| lwz TMP1, TAB:RB->array
| cmplw TMP0, RC
| slwi TMP2, RC, 3
|.else
| bge cr1, >5
| // Convert number key to integer, check for integerness and range.
| fctiwz f1, f0
| fadd f2, f0, TOBIT
| stfd f1, TMPD
| lwz TMP0, TAB:RB->asize
| fsub f2, f2, TOBIT
| lwz TMP2, TMPD_LO
| lwz TMP1, TAB:RB->array
| fcmpu cr1, f0, f2
| cmplw cr0, TMP0, TMP2
| crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq
| slwi TMP2, TMP2, 3
|.endif
| ble ->vmeta_tgetv // Integer key and in array part?
| lwzx TMP0, TMP1, TMP2
|.if FPU
| lfdx f14, TMP1, TMP2
|.else
| lwzux SAVE0, TMP1, TMP2
| lwz SAVE1, 4(TMP1)
|.endif
| checknil TMP0; beq >2
|1:
| ins_next1
|.if FPU
| stfdx f14, BASE, RA
|.else
| stwux SAVE0, RA, BASE
| stw SAVE1, 4(RA)
|.endif
| ins_next2
|
|2: // Check for __index if table value is nil.
| lwz TAB:TMP2, TAB:RB->metatable
| cmplwi TAB:TMP2, 0
| beq <1 // No metatable: done.
| lbz TMP0, TAB:TMP2->nomm
| andix. TMP0, TMP0, 1<<MM_index
| bne <1 // 'no __index' flag set: done.
| b ->vmeta_tgetv
|
|5:
| checkstr CARG2; bne ->vmeta_tgetv
|.if not DUALNUM
| lwz STR:RC, 4(RC)
|.endif
| b ->BC_TGETS_Z // String key?
break;
case BC_TGETS:
| // RA = dst*8, RB = table*8, RC = str_const*8 (~)
| lwzux CARG1, RB, BASE
| srwi TMP1, RC, 1
| lwz TAB:RB, 4(RB)
| subfic TMP1, TMP1, -4
| checktab CARG1
| lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
| bne ->vmeta_tgets1
|->BC_TGETS_Z:
| // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
| lwz TMP0, TAB:RB->hmask
| lwz TMP1, STR:RC->sid
| lwz NODE:TMP2, TAB:RB->node
| and TMP1, TMP1, TMP0 // idx = str->sid & tab->hmask
| slwi TMP0, TMP1, 5
| slwi TMP1, TMP1, 3
| sub TMP1, TMP0, TMP1
| add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
|1:
| lwz CARG1, NODE:TMP2->key
| lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
| lwz CARG2, NODE:TMP2->val
| lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)
| checkstr CARG1; bne >4
| cmpw TMP0, STR:RC; bne >4
| checknil CARG2; beq >5 // Key found, but nil value?
|3:
| stwux CARG2, RA, BASE
| stw TMP1, 4(RA)
| ins_next
|
|4: // Follow hash chain.
| lwz NODE:TMP2, NODE:TMP2->next
| cmplwi NODE:TMP2, 0
| bne <1
| // End of hash chain: key not found, nil result.
| li CARG2, LJ_TNIL
|
|5: // Check for __index if table value is nil.
| lwz TAB:TMP2, TAB:RB->metatable
| cmplwi TAB:TMP2, 0
| beq <3 // No metatable: done.
| lbz TMP0, TAB:TMP2->nomm
| andix. TMP0, TMP0, 1<<MM_index
| bne <3 // 'no __index' flag set: done.
| b ->vmeta_tgets
break;
case BC_TGETB:
| // RA = dst*8, RB = table*8, RC = index*8
| lwzux CARG1, RB, BASE
| srwi TMP0, RC, 3
| lwz TAB:RB, 4(RB)
| checktab CARG1; bne ->vmeta_tgetb
| lwz TMP1, TAB:RB->asize
| lwz TMP2, TAB:RB->array
| cmplw TMP0, TMP1; bge ->vmeta_tgetb
|.if FPU
| lwzx TMP1, TMP2, RC
| lfdx f0, TMP2, RC
|.else
| lwzux TMP1, TMP2, RC
| lwz TMP3, 4(TMP2)
|.endif
| checknil TMP1; beq >5
|1:
| ins_next1
|.if FPU
| stfdx f0, BASE, RA
|.else
| stwux TMP1, RA, BASE
| stw TMP3, 4(RA)
|.endif
| ins_next2
|
|5: // Check for __index if table value is nil.
| lwz TAB:TMP2, TAB:RB->metatable
| cmplwi TAB:TMP2, 0
| beq <1 // No metatable: done.
| lbz TMP2, TAB:TMP2->nomm
| andix. TMP2, TMP2, 1<<MM_index
| bne <1 // 'no __index' flag set: done.
| b ->vmeta_tgetb // Caveat: preserve TMP0!
break;
case BC_TGETR:
| // RA = dst*8, RB = table*8, RC = key*8
| add RB, BASE, RB
| lwz TAB:CARG1, 4(RB)
|.if DUALNUM
| add RC, BASE, RC
| lwz TMP0, TAB:CARG1->asize
| lwz CARG2, 4(RC)
| lwz TMP1, TAB:CARG1->array
|.else
| lfdx f0, BASE, RC
| lwz TMP0, TAB:CARG1->asize
| toint CARG2, f0
| lwz TMP1, TAB:CARG1->array
|.endif
| cmplw TMP0, CARG2
| slwi TMP2, CARG2, 3
| ble ->vmeta_tgetr // In array part?
|.if FPU
| lfdx f14, TMP1, TMP2
|.else
| lwzux SAVE0, TMP2, TMP1
| lwz SAVE1, 4(TMP2)
|.endif
|->BC_TGETR_Z:
| ins_next1
|.if FPU
| stfdx f14, BASE, RA
|.else
| stwux SAVE0, RA, BASE
| stw SAVE1, 4(RA)
|.endif
| ins_next2
break;
case BC_TSETV:
| // RA = src*8, RB = table*8, RC = key*8
| lwzux CARG1, RB, BASE
| lwzux CARG2, RC, BASE
| lwz TAB:RB, 4(RB)
|.if DUALNUM
| lwz RC, 4(RC)
|.else
| lfd f0, 0(RC)
|.endif
| checktab CARG1
| checknum cr1, CARG2
| bne ->vmeta_tsetv
|.if DUALNUM
| lwz TMP0, TAB:RB->asize
| bne cr1, >5
| lwz TMP1, TAB:RB->array
| cmplw TMP0, RC
| slwi TMP0, RC, 3
|.else
| bge cr1, >5
| // Convert number key to integer, check for integerness and range.
| fctiwz f1, f0
| fadd f2, f0, TOBIT
| stfd f1, TMPD
| lwz TMP0, TAB:RB->asize
| fsub f2, f2, TOBIT
| lwz TMP2, TMPD_LO
| lwz TMP1, TAB:RB->array
| fcmpu cr1, f0, f2
| cmplw cr0, TMP0, TMP2
| crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq
| slwi TMP0, TMP2, 3
|.endif
| ble ->vmeta_tsetv // Integer key and in array part?
| lwzx TMP2, TMP1, TMP0
| lbz TMP3, TAB:RB->marked
|.if FPU
| lfdx f14, BASE, RA
|.else
| add SAVE1, BASE, RA
| lwz SAVE0, 0(SAVE1)
| lwz SAVE1, 4(SAVE1)
|.endif
| checknil TMP2; beq >3
|1:
| andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table)
|.if FPU
| stfdx f14, TMP1, TMP0
|.else
| stwux SAVE0, TMP1, TMP0
| stw SAVE1, 4(TMP1)
|.endif
| bne >7
|2:
| ins_next
|
|3: // Check for __newindex if previous value is nil.
| lwz TAB:TMP2, TAB:RB->metatable
| cmplwi TAB:TMP2, 0
| beq <1 // No metatable: done.
| lbz TMP2, TAB:TMP2->nomm
| andix. TMP2, TMP2, 1<<MM_newindex
| bne <1 // 'no __newindex' flag set: done.
| b ->vmeta_tsetv
|
|5:
| checkstr CARG2; bne ->vmeta_tsetv
|.if not DUALNUM
| lwz STR:RC, 4(RC)
|.endif
| b ->BC_TSETS_Z // String key?
|
|7: // Possible table write barrier for the value. Skip valiswhite check.
| barrierback TAB:RB, TMP3, TMP0
| b <2
break;
case BC_TSETS:
| // RA = src*8, RB = table*8, RC = str_const*8 (~)
| lwzux CARG1, RB, BASE
| srwi TMP1, RC, 1
| lwz TAB:RB, 4(RB)
| subfic TMP1, TMP1, -4
| checktab CARG1
| lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
| bne ->vmeta_tsets1
|->BC_TSETS_Z:
| // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8
| lwz TMP0, TAB:RB->hmask
| lwz TMP1, STR:RC->sid
| lwz NODE:TMP2, TAB:RB->node
| stb ZERO, TAB:RB->nomm // Clear metamethod cache.
| and TMP1, TMP1, TMP0 // idx = str->sid & tab->hmask
|.if FPU
| lfdx f14, BASE, RA
|.else
| add CARG2, BASE, RA
| lwz SAVE0, 0(CARG2)
| lwz SAVE1, 4(CARG2)
|.endif
| slwi TMP0, TMP1, 5
| slwi TMP1, TMP1, 3
| sub TMP1, TMP0, TMP1
| lbz TMP3, TAB:RB->marked
| add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
|1:
| lwz CARG1, NODE:TMP2->key
| lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
| lwz CARG2, NODE:TMP2->val
| lwz NODE:TMP1, NODE:TMP2->next
| checkstr CARG1; bne >5
| cmpw TMP0, STR:RC; bne >5
| checknil CARG2; beq >4 // Key found, but nil value?
|2:
| andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
|.if FPU
| stfd f14, NODE:TMP2->val
|.else
| stw SAVE0, NODE:TMP2->val.u32.hi
| stw SAVE1, NODE:TMP2->val.u32.lo
|.endif
| bne >7
|3:
| ins_next
|
|4: // Check for __newindex if previous value is nil.
| lwz TAB:TMP1, TAB:RB->metatable
| cmplwi TAB:TMP1, 0
| beq <2 // No metatable: done.
| lbz TMP0, TAB:TMP1->nomm
| andix. TMP0, TMP0, 1<<MM_newindex
| bne <2 // 'no __newindex' flag set: done.
| b ->vmeta_tsets
|
|5: // Follow hash chain.
| cmplwi NODE:TMP1, 0
| mr NODE:TMP2, NODE:TMP1
| bne <1
| // End of hash chain: key not found, add a new one.
|
| // But check for __newindex first.
| lwz TAB:TMP1, TAB:RB->metatable
| la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
| stw PC, SAVE_PC
| mr CARG1, L
| cmplwi TAB:TMP1, 0
| stp BASE, L->base
| beq >6 // No metatable: continue.
| lbz TMP0, TAB:TMP1->nomm
| andix. TMP0, TMP0, 1<<MM_newindex
| beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
|6:
| li TMP0, LJ_TSTR
| stw STR:RC, 4(CARG3)
| mr CARG2, TAB:RB
| stw TMP0, 0(CARG3)
| bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
| // Returns TValue *.
| lp BASE, L->base
|.if FPU
| stfd f14, 0(CRET1)
|.else
| stw SAVE0, 0(CRET1)
| stw SAVE1, 4(CRET1)
|.endif
| b <3 // No 2nd write barrier needed.
|
|7: // Possible table write barrier for the value. Skip valiswhite check.
| barrierback TAB:RB, TMP3, TMP0
| b <3
break;
case BC_TSETB:
| // RA = src*8, RB = table*8, RC = index*8
| lwzux CARG1, RB, BASE
| srwi TMP0, RC, 3
| lwz TAB:RB, 4(RB)
| checktab CARG1; bne ->vmeta_tsetb
| lwz TMP1, TAB:RB->asize
| lwz TMP2, TAB:RB->array
| lbz TMP3, TAB:RB->marked
| cmplw TMP0, TMP1
|.if FPU
| lfdx f14, BASE, RA
|.else
| add CARG2, BASE, RA
| lwz SAVE0, 0(CARG2)
| lwz SAVE1, 4(CARG2)
|.endif
| bge ->vmeta_tsetb
| lwzx TMP1, TMP2, RC
| checknil TMP1; beq >5
|1:
| andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
|.if FPU
| stfdx f14, TMP2, RC
|.else
| stwux SAVE0, RC, TMP2
| stw SAVE1, 4(RC)
|.endif
| bne >7
|2:
| ins_next
|
|5: // Check for __newindex if previous value is nil.
| lwz TAB:TMP1, TAB:RB->metatable
| cmplwi TAB:TMP1, 0
| beq <1 // No metatable: done.
| lbz TMP1, TAB:TMP1->nomm
| andix. TMP1, TMP1, 1<<MM_newindex
| bne <1 // 'no __newindex' flag set: done.
| b ->vmeta_tsetb // Caveat: preserve TMP0!
|
|7: // Possible table write barrier for the value. Skip valiswhite check.
| barrierback TAB:RB, TMP3, TMP0
| b <2
break;
case BC_TSETR:
| // RA = dst*8, RB = table*8, RC = key*8
| add RB, BASE, RB
| lwz TAB:CARG2, 4(RB)
|.if DUALNUM
| add RC, BASE, RC
| lbz TMP3, TAB:CARG2->marked
| lwz TMP0, TAB:CARG2->asize
| lwz CARG3, 4(RC)
| lwz TMP1, TAB:CARG2->array
|.else
| lfdx f0, BASE, RC
| lbz TMP3, TAB:CARG2->marked
| lwz TMP0, TAB:CARG2->asize
| toint CARG3, f0
| lwz TMP1, TAB:CARG2->array
|.endif
| andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table)
| bne >7
|2:
| cmplw TMP0, CARG3
| slwi TMP2, CARG3, 3
|.if FPU
| lfdx f14, BASE, RA
|.else
| lwzux SAVE0, RA, BASE
| lwz SAVE1, 4(RA)
|.endif
| ble ->vmeta_tsetr // In array part?
| ins_next1
|.if FPU
| stfdx f14, TMP1, TMP2
|.else
| stwux SAVE0, TMP1, TMP2
| stw SAVE1, 4(TMP1)
|.endif
| ins_next2
|
|7: // Possible table write barrier for the value. Skip valiswhite check.
| barrierback TAB:CARG2, TMP3, TMP2
| b <2
break;
case BC_TSETM:
| // RA = base*8 (table at base-1), RD = num_const*8 (start index)
| add RA, BASE, RA
|1:
| add TMP3, KBASE, RD
| lwz TAB:CARG2, -4(RA) // Guaranteed to be a table.
| addic. TMP0, MULTRES, -8
| lwz TMP3, 4(TMP3) // Integer constant is in lo-word.
| srwi CARG3, TMP0, 3
| beq >4 // Nothing to copy?
| add CARG3, CARG3, TMP3
| lwz TMP2, TAB:CARG2->asize
| slwi TMP1, TMP3, 3
| lbz TMP3, TAB:CARG2->marked
| cmplw CARG3, TMP2
| add TMP2, RA, TMP0
| lwz TMP0, TAB:CARG2->array
| bgt >5
| add TMP1, TMP1, TMP0
| andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
|3: // Copy result slots to table.
|.if FPU
| lfd f0, 0(RA)
|.else
| lwz SAVE0, 0(RA)
| lwz SAVE1, 4(RA)
|.endif
| addi RA, RA, 8
| cmpw cr1, RA, TMP2
|.if FPU
| stfd f0, 0(TMP1)
|.else
| stw SAVE0, 0(TMP1)
| stw SAVE1, 4(TMP1)
|.endif
| addi TMP1, TMP1, 8
| blt cr1, <3
| bne >7
|4:
| ins_next
|
|5: // Need to resize array part.
| stp BASE, L->base
| mr CARG1, L
| stw PC, SAVE_PC
| mr SAVE0, RD
| bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
| // Must not reallocate the stack.
| mr RD, SAVE0
| b <1
|
|7: // Possible table write barrier for any value. Skip valiswhite check.
| barrierback TAB:CARG2, TMP3, TMP0
| b <4
break;
/* -- Calls and vararg handling ----------------------------------------- */
case BC_CALLM:
| // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
| add NARGS8:RC, NARGS8:RC, MULTRES
| // Fall through. Assumes BC_CALL follows.
break;
case BC_CALL:
| // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
| mr TMP2, BASE
| lwzux TMP0, BASE, RA
| lwz LFUNC:RB, 4(BASE)
| subi NARGS8:RC, NARGS8:RC, 8
| addi BASE, BASE, 8
| checkfunc TMP0; bne ->vmeta_call
| ins_call
break;
case BC_CALLMT:
| // RA = base*8, (RB = 0,) RC = extra_nargs*8
| add NARGS8:RC, NARGS8:RC, MULTRES
| // Fall through. Assumes BC_CALLT follows.
break;
case BC_CALLT:
| // RA = base*8, (RB = 0,) RC = (nargs+1)*8
| lwzux TMP0, RA, BASE
| lwz LFUNC:RB, 4(RA)
| subi NARGS8:RC, NARGS8:RC, 8
| lwz TMP1, FRAME_PC(BASE)
| checkfunc TMP0
| addi RA, RA, 8
| bne ->vmeta_callt
|->BC_CALLT_Z:
| andix. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand.
| lbz TMP3, LFUNC:RB->ffid
| xori TMP2, TMP1, FRAME_VARG
| cmplwi cr1, NARGS8:RC, 0
| bne >7
|1:
| stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC.
| li TMP2, 0
| cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function?
| beq cr1, >3
|2:
| addi TMP3, TMP2, 8
|.if FPU
| lfdx f0, RA, TMP2
|.else
| add CARG3, RA, TMP2
| lwz CARG1, 0(CARG3)
| lwz CARG2, 4(CARG3)
|.endif
| cmplw cr1, TMP3, NARGS8:RC
|.if FPU
| stfdx f0, BASE, TMP2
|.else
| stwux CARG1, TMP2, BASE
| stw CARG2, 4(TMP2)
|.endif
| mr TMP2, TMP3
| bne cr1, <2
|3:
| crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt
| beq >5
|4:
| ins_callt
|
|5: // Tailcall to a fast function with a Lua frame below.
| lwz INS, -4(TMP1)
| decode_RA8 RA, INS
| sub TMP1, BASE, RA
| lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1)
| lwz TMP1, LFUNC:TMP1->pc
| lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE.
| b <4
|
|7: // Tailcall from a vararg function.
| andix. TMP0, TMP2, FRAME_TYPEP
| bne <1 // Vararg frame below?
| sub BASE, BASE, TMP2 // Relocate BASE down.
| lwz TMP1, FRAME_PC(BASE)
| andix. TMP0, TMP1, FRAME_TYPE
| b <1
break;
case BC_ITERC:
| // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
| mr TMP2, BASE
| add BASE, BASE, RA
| lwz TMP1, -24(BASE)
| lwz LFUNC:RB, -20(BASE)
|.if FPU
| lfd f1, -8(BASE)
| lfd f0, -16(BASE)
|.else
| lwz CARG1, -8(BASE)
| lwz CARG2, -4(BASE)
| lwz CARG3, -16(BASE)
| lwz CARG4, -12(BASE)
|.endif
| stw TMP1, 0(BASE) // Copy callable.
| stw LFUNC:RB, 4(BASE)
| checkfunc TMP1
| li NARGS8:RC, 16 // Iterators get 2 arguments.
|.if FPU
| stfd f1, 16(BASE) // Copy control var.
| stfdu f0, 8(BASE) // Copy state.
|.else
| stw CARG1, 16(BASE) // Copy control var.
| stw CARG2, 20(BASE)
| stwu CARG3, 8(BASE) // Copy state.
| stw CARG4, 4(BASE)
|.endif
| bne ->vmeta_call
| ins_call
break;
case BC_ITERN:
| // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
|.if JIT
| // NYI on big-endian
|.endif
|->vm_IITERN:
| add RA, BASE, RA
| lwz TAB:RB, -12(RA)
| lwz RC, -4(RA) // Get index from control var.
| lwz TMP0, TAB:RB->asize
| lwz TMP1, TAB:RB->array
| addi PC, PC, 4
|1: // Traverse array part.
| cmplw RC, TMP0
| slwi TMP3, RC, 3
| bge >5 // Index points after array part?
| lwzx TMP2, TMP1, TMP3
|.if FPU
| lfdx f0, TMP1, TMP3
|.else
| lwzux CARG1, TMP3, TMP1
| lwz CARG2, 4(TMP3)
|.endif
| checknil TMP2
| lwz INS, -4(PC)
| beq >4
|.if DUALNUM
| stw RC, 4(RA)
| stw TISNUM, 0(RA)
|.else
| tonum_u f1, RC
|.endif
| addi RC, RC, 1
| addis TMP3, PC, -(BCBIAS_J*4 >> 16)
|.if FPU
| stfd f0, 8(RA)
|.else
| stw CARG1, 8(RA)
| stw CARG2, 12(RA)
|.endif
| decode_RD4 TMP1, INS
| stw RC, -4(RA) // Update control var.
| add PC, TMP1, TMP3
|.if not DUALNUM
| stfd f1, 0(RA)
|.endif
|3:
| ins_next
|
|4: // Skip holes in array part.
| addi RC, RC, 1
| b <1
|
|5: // Traverse hash part.
| lwz TMP1, TAB:RB->hmask
| sub RC, RC, TMP0
| lwz TMP2, TAB:RB->node
|6:
| cmplw RC, TMP1 // End of iteration? Branch to ITERL+1.
| slwi TMP3, RC, 5
| bgty <3
| slwi RB, RC, 3
| sub TMP3, TMP3, RB
| lwzx RB, TMP2, TMP3
|.if FPU
| lfdx f0, TMP2, TMP3
|.else
| add CARG3, TMP2, TMP3
| lwz CARG1, 0(CARG3)
| lwz CARG2, 4(CARG3)
|.endif
| add NODE:TMP3, TMP2, TMP3
| checknil RB
| lwz INS, -4(PC)
| beq >7
|.if FPU
| lfd f1, NODE:TMP3->key
|.else
| lwz CARG3, NODE:TMP3->key.u32.hi
| lwz CARG4, NODE:TMP3->key.u32.lo
|.endif
| addis TMP2, PC, -(BCBIAS_J*4 >> 16)
|.if FPU
| stfd f0, 8(RA)
|.else
| stw CARG1, 8(RA)
| stw CARG2, 12(RA)
|.endif
| add RC, RC, TMP0
| decode_RD4 TMP1, INS
|.if FPU
| stfd f1, 0(RA)
|.else
| stw CARG3, 0(RA)
| stw CARG4, 4(RA)
|.endif
| addi RC, RC, 1
| add PC, TMP1, TMP2
| stw RC, -4(RA) // Update control var.
| b <3
|
|7: // Skip holes in hash part.
| addi RC, RC, 1
| b <6
break;
case BC_ISNEXT:
| // RA = base*8, RD = target (points to ITERN)
| add RA, BASE, RA
| lwz TMP0, -24(RA)
| lwz CFUNC:TMP1, -20(RA)
| lwz TMP2, -16(RA)
| lwz TMP3, -8(RA)
| cmpwi cr0, TMP2, LJ_TTAB
| cmpwi cr1, TMP0, LJ_TFUNC
| cmpwi cr6, TMP3, LJ_TNIL
| bne cr1, >5
| lbz TMP1, CFUNC:TMP1->ffid
| crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq
| cmpwi cr7, TMP1, FF_next_N
| srwi TMP0, RD, 1
| crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
| add TMP3, PC, TMP0
| bne cr0, >5
| lus TMP1, (LJ_KEYINDEX >> 16)
| ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)
| stw ZERO, -4(RA) // Initialize control var.
| stw TMP1, -8(RA)
| addis PC, TMP3, -(BCBIAS_J*4 >> 16)
|1:
| ins_next
|5: // Despecialize bytecode if any of the checks fail.
| li TMP0, BC_JMP
| li TMP1, BC_ITERC
| stb TMP0, -1(PC)
| addis PC, TMP3, -(BCBIAS_J*4 >> 16)
| // NYI on big-endian: unpatch JLOOP.
| stb TMP1, 3(PC)
| b <1
break;
case BC_VARG:
| // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
| lwz TMP0, FRAME_PC(BASE)
| add RC, BASE, RC
| add RA, BASE, RA
| addi RC, RC, FRAME_VARG
| add TMP2, RA, RB
| subi TMP3, BASE, 8 // TMP3 = vtop
| sub RC, RC, TMP0 // RC = vbase
| // Note: RC may now be even _above_ BASE if nargs was < numparams.
| cmplwi cr1, RB, 0
|.if PPE
| sub TMP1, TMP3, RC
| cmpwi TMP1, 0
|.else
| sub. TMP1, TMP3, RC
|.endif
| beq cr1, >5 // Copy all varargs?
| subi TMP2, TMP2, 16
| ble >2 // No vararg slots?
|1: // Copy vararg slots to destination slots.
|.if FPU
| lfd f0, 0(RC)
|.else
| lwz CARG1, 0(RC)
| lwz CARG2, 4(RC)
|.endif
| addi RC, RC, 8
|.if FPU
| stfd f0, 0(RA)
|.else
| stw CARG1, 0(RA)
| stw CARG2, 4(RA)
|.endif
| cmplw RA, TMP2
| cmplw cr1, RC, TMP3
| bge >3 // All destination slots filled?
| addi RA, RA, 8
| blt cr1, <1 // More vararg slots?
|2: // Fill up remainder with nil.
| stw TISNIL, 0(RA)
| cmplw RA, TMP2
| addi RA, RA, 8
| blt <2
|3:
| ins_next
|
|5: // Copy all varargs.
| lwz TMP0, L->maxstack
| li MULTRES, 8 // MULTRES = (0+1)*8
| bley <3 // No vararg slots?
| add TMP2, RA, TMP1
| cmplw TMP2, TMP0
| addi MULTRES, TMP1, 8
| bgt >7
|6:
|.if FPU
| lfd f0, 0(RC)
|.else
| lwz CARG1, 0(RC)
| lwz CARG2, 4(RC)
|.endif
| addi RC, RC, 8
|.if FPU
| stfd f0, 0(RA)
|.else
| stw CARG1, 0(RA)
| stw CARG2, 4(RA)
|.endif
| cmplw RC, TMP3
| addi RA, RA, 8
| blt <6 // More vararg slots?
| b <3
|
|7: // Grow stack for varargs.
| mr CARG1, L
| stp RA, L->top
| sub SAVE0, RC, BASE // Need delta, because BASE may change.
| stp BASE, L->base
| sub RA, RA, BASE
| stw PC, SAVE_PC
| srwi CARG2, TMP1, 3
| bl extern lj_state_growstack // (lua_State *L, int n)
| lp BASE, L->base
| add RA, BASE, RA
| add RC, BASE, SAVE0
| subi TMP3, BASE, 8
| b <6
break;
/* -- Returns ----------------------------------------------------------- */
case BC_RETM:
| // RA = results*8, RD = extra_nresults*8
| add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8.
| // Fall through. Assumes BC_RET follows.
break;
case BC_RET:
| // RA = results*8, RD = (nresults+1)*8
| lwz PC, FRAME_PC(BASE)
| add RA, BASE, RA
| mr MULTRES, RD
|1:
| andix. TMP0, PC, FRAME_TYPE
| xori TMP1, PC, FRAME_VARG
| bne ->BC_RETV_Z
|
|->BC_RET_Z:
| // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
| lwz INS, -4(PC)
| cmpwi RD, 8
| subi TMP2, BASE, 8
| subi RC, RD, 8
| decode_RB8 RB, INS
| beq >3
| li TMP1, 0
|2:
| addi TMP3, TMP1, 8
|.if FPU
| lfdx f0, RA, TMP1
|.else
| add CARG3, RA, TMP1
| lwz CARG1, 0(CARG3)
| lwz CARG2, 4(CARG3)
|.endif
| cmpw TMP3, RC
|.if FPU
| stfdx f0, TMP2, TMP1
|.else
| add CARG3, TMP2, TMP1
| stw CARG1, 0(CARG3)
| stw CARG2, 4(CARG3)
|.endif
| beq >3
| addi TMP1, TMP3, 8
|.if FPU
| lfdx f1, RA, TMP3
|.else
| add CARG3, RA, TMP3
| lwz CARG1, 0(CARG3)
| lwz CARG2, 4(CARG3)
|.endif
| cmpw TMP1, RC
|.if FPU
| stfdx f1, TMP2, TMP3
|.else
| add CARG3, TMP2, TMP3
| stw CARG1, 0(CARG3)
| stw CARG2, 4(CARG3)
|.endif
| bne <2
|3:
|5:
| cmplw RB, RD
| decode_RA8 RA, INS
| bgt >6
| sub BASE, TMP2, RA
| lwz LFUNC:TMP1, FRAME_FUNC(BASE)
| ins_next1
| lwz TMP1, LFUNC:TMP1->pc
| lwz KBASE, PC2PROTO(k)(TMP1)
| ins_next2
|
|6: // Fill up results with nil.
| subi TMP1, RD, 8
| addi RD, RD, 8
| stwx TISNIL, TMP2, TMP1
| b <5
|
|->BC_RETV_Z: // Non-standard return case.
| andix. TMP2, TMP1, FRAME_TYPEP
| bne ->vm_return
| // Return from vararg function: relocate BASE down.
| sub BASE, BASE, TMP1
| lwz PC, FRAME_PC(BASE)
| b <1
break;
case BC_RET0: case BC_RET1:
| // RA = results*8, RD = (nresults+1)*8
| lwz PC, FRAME_PC(BASE)
| add RA, BASE, RA
| mr MULTRES, RD
| andix. TMP0, PC, FRAME_TYPE
| xori TMP1, PC, FRAME_VARG
| bney ->BC_RETV_Z
|
| lwz INS, -4(PC)
| subi TMP2, BASE, 8
| decode_RB8 RB, INS
if (op == BC_RET1) {
|.if FPU
| lfd f0, 0(RA)
| stfd f0, 0(TMP2)
|.else
| lwz CARG1, 0(RA)
| lwz CARG2, 4(RA)
| stw CARG1, 0(TMP2)
| stw CARG2, 4(TMP2)
|.endif
}
|5:
| cmplw RB, RD
| decode_RA8 RA, INS
| bgt >6
| sub BASE, TMP2, RA
| lwz LFUNC:TMP1, FRAME_FUNC(BASE)
| ins_next1
| lwz TMP1, LFUNC:TMP1->pc
| lwz KBASE, PC2PROTO(k)(TMP1)
| ins_next2
|
|6: // Fill up results with nil.
| subi TMP1, RD, 8
| addi RD, RD, 8
| stwx TISNIL, TMP2, TMP1
| b <5
break;
/* -- Loops and branches ------------------------------------------------ */
case BC_FORL:
|.if JIT
| hotloop
|.endif
| // Fall through. Assumes BC_IFORL follows.
break;
case BC_JFORI:
case BC_JFORL:
#if !LJ_HASJIT
break;
#endif
case BC_FORI:
case BC_IFORL:
| // RA = base*8, RD = target (after end of loop or start of loop)
vk = (op == BC_IFORL || op == BC_JFORL);
|.if DUALNUM
| // Integer loop.
| lwzux TMP1, RA, BASE
| lwz CARG1, FORL_IDX*8+4(RA)
| cmplw cr0, TMP1, TISNUM
if (vk) {
| lwz CARG3, FORL_STEP*8+4(RA)
| bne >9
|.if GPR64
| // Need to check overflow for (a<<32) + (b<<32).
| rldicr TMP0, CARG1, 32, 31
| rldicr TMP2, CARG3, 32, 31
| add CARG1, CARG1, CARG3
| addo. TMP0, TMP0, TMP2
|.else
| addo. CARG1, CARG1, CARG3
|.endif
| cmpwi cr6, CARG3, 0
| lwz CARG2, FORL_STOP*8+4(RA)
| bso >6
|4:
| stw CARG1, FORL_IDX*8+4(RA)
} else {
| lwz SAVE0, FORL_STEP*8(RA)
| lwz CARG3, FORL_STEP*8+4(RA)
| lwz TMP2, FORL_STOP*8(RA)
| lwz CARG2, FORL_STOP*8+4(RA)
| cmplw cr7, SAVE0, TISNUM
| cmplw cr1, TMP2, TISNUM
| crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
| crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
| cmpwi cr6, CARG3, 0
| bne >9
}
| blt cr6, >5
| cmpw CARG1, CARG2
|1:
| stw TISNUM, FORL_EXT*8(RA)
if (op != BC_JFORL) {
| srwi RD, RD, 1
}
| stw CARG1, FORL_EXT*8+4(RA)
if (op != BC_JFORL) {
| add RD, PC, RD
}
if (op == BC_FORI) {
| bgt >3 // See FP loop below.
} else if (op == BC_JFORI) {
| addis PC, RD, -(BCBIAS_J*4 >> 16)
| bley >7
} else if (op == BC_IFORL) {
| bgt >2
| addis PC, RD, -(BCBIAS_J*4 >> 16)
} else {
| bley =>BC_JLOOP
}
|2:
| ins_next
|5: // Invert check for negative step.
| cmpw CARG2, CARG1
| b <1
if (vk) {
|6: // Potential overflow.
| checkov TMP0, <4 // Ignore unrelated overflow.
| b <2
}
|.endif
if (vk) {
|.if DUALNUM
|9: // FP loop.
|.if FPU
| lfd f1, FORL_IDX*8(RA)
|.else
| lwz CARG1, FORL_IDX*8(RA)
| lwz CARG2, FORL_IDX*8+4(RA)
|.endif
|.else
| lfdux f1, RA, BASE
|.endif
|.if FPU
| lfd f3, FORL_STEP*8(RA)
| lfd f2, FORL_STOP*8(RA)
| fadd f1, f1, f3
| stfd f1, FORL_IDX*8(RA)
|.else
| lwz CARG3, FORL_STEP*8(RA)
| lwz CARG4, FORL_STEP*8+4(RA)
| mr SAVE1, RD
| blex __adddf3
| mr RD, SAVE1
| stw CRET1, FORL_IDX*8(RA)
| stw CRET2, FORL_IDX*8+4(RA)
| lwz CARG3, FORL_STOP*8(RA)
| lwz CARG4, FORL_STOP*8+4(RA)
|.endif
| lwz SAVE0, FORL_STEP*8(RA)
} else {
|.if DUALNUM
|9: // FP loop.
|.else
| lwzux TMP1, RA, BASE
| lwz SAVE0, FORL_STEP*8(RA)
| lwz TMP2, FORL_STOP*8(RA)
| cmplw cr0, TMP1, TISNUM
| cmplw cr7, SAVE0, TISNUM
| cmplw cr1, TMP2, TISNUM
|.endif
|.if FPU
| lfd f1, FORL_IDX*8(RA)
|.else
| lwz CARG1, FORL_IDX*8(RA)
| lwz CARG2, FORL_IDX*8+4(RA)
|.endif
| crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt
| crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
|.if FPU
| lfd f2, FORL_STOP*8(RA)
|.else
| lwz CARG3, FORL_STOP*8(RA)
| lwz CARG4, FORL_STOP*8+4(RA)
|.endif
| bge ->vmeta_for
}
| cmpwi cr6, SAVE0, 0
if (op != BC_JFORL) {
| srwi RD, RD, 1
}
|.if FPU
| stfd f1, FORL_EXT*8(RA)
|.else
| stw CARG1, FORL_EXT*8(RA)
| stw CARG2, FORL_EXT*8+4(RA)
|.endif
if (op != BC_JFORL) {
| add RD, PC, RD
}
|.if FPU
| fcmpu cr0, f1, f2
|.else
| mr SAVE1, RD
| blex __ledf2
| cmpwi CRET1, 0
| mr RD, SAVE1
|.endif
if (op == BC_JFORI) {
| addis PC, RD, -(BCBIAS_J*4 >> 16)
}
| blt cr6, >5
if (op == BC_FORI) {
| bgt >3
} else if (op == BC_IFORL) {
|.if DUALNUM
| bgty <2
|.else
| bgt >2
|.endif
|1:
| addis PC, RD, -(BCBIAS_J*4 >> 16)
} else if (op == BC_JFORI) {
| bley >7
} else {
| bley =>BC_JLOOP
}
|.if DUALNUM
| b <2
|.else
|2:
| ins_next
|.endif
|5: // Negative step.
if (op == BC_FORI) {
| bge <2
|3: // Used by integer loop, too.
| addis PC, RD, -(BCBIAS_J*4 >> 16)
} else if (op == BC_IFORL) {
| bgey <1
} else if (op == BC_JFORI) {
| bgey >7
} else {
| bgey =>BC_JLOOP
}
| b <2
if (op == BC_JFORI) {
|7:
| lwz INS, -4(PC)
| decode_RD8 RD, INS
| b =>BC_JLOOP
}
break;
case BC_ITERL:
|.if JIT
| hotloop
|.endif
| // Fall through. Assumes BC_IITERL follows.
break;
case BC_JITERL:
#if !LJ_HASJIT
break;
#endif
case BC_IITERL:
| // RA = base*8, RD = target
| lwzux TMP1, RA, BASE
| lwz TMP2, 4(RA)
| checknil TMP1; beq >1 // Stop if iterator returned nil.
if (op == BC_JITERL) {
| stw TMP1, -8(RA)
| stw TMP2, -4(RA)
| b =>BC_JLOOP
} else {
| branch_RD // Otherwise save control var + branch.
| stw TMP1, -8(RA)
| stw TMP2, -4(RA)
}
|1:
| ins_next
break;
case BC_LOOP:
| // RA = base*8, RD = target (loop extent)
| // Note: RA/RD is only used by trace recorder to determine scope/extent
| // This opcode does NOT jump, it's only purpose is to detect a hot loop.
|.if JIT
| hotloop
|.endif
| // Fall through. Assumes BC_ILOOP follows.
break;
case BC_ILOOP:
| // RA = base*8, RD = target (loop extent)
| ins_next
break;
case BC_JLOOP:
|.if JIT
| // RA = base*8 (ignored), RD = traceno*8
| lwz TMP1, DISPATCH_J(trace)(DISPATCH)
| srwi RD, RD, 1
| // Traces on PPC don't store the trace number, so use 0.
| stw ZERO, DISPATCH_GL(vmstate)(DISPATCH)
| lwzx TRACE:TMP2, TMP1, RD
| clrso TMP1
| lp TMP2, TRACE:TMP2->mcode
| stw BASE, DISPATCH_GL(jit_base)(DISPATCH)
| mtctr TMP2
| addi JGL, DISPATCH, GG_DISP2G+32768
| stw L, DISPATCH_GL(tmpbuf.L)(DISPATCH)
| bctr
|.endif
break;
case BC_JMP:
| // RA = base*8 (only used by trace recorder), RD = target
| branch_RD
| ins_next
break;
/* -- Function headers -------------------------------------------------- */
case BC_FUNCF:
|.if JIT
| hotcall
|.endif
case BC_FUNCV: /* NYI: compiled vararg functions. */
| // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
break;
case BC_JFUNCF:
#if !LJ_HASJIT
break;
#endif
case BC_IFUNCF:
| // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
| lwz TMP2, L->maxstack
| lbz TMP1, -4+PC2PROTO(numparams)(PC)
| lwz KBASE, -4+PC2PROTO(k)(PC)
| cmplw RA, TMP2
| slwi TMP1, TMP1, 3
| bgt ->vm_growstack_l
if (op != BC_JFUNCF) {
| ins_next1
}
|2:
| cmplw NARGS8:RC, TMP1 // Check for missing parameters.
| blt >3
if (op == BC_JFUNCF) {
| decode_RD8 RD, INS
| b =>BC_JLOOP
} else {
| ins_next2
}
|
|3: // Clear missing parameters.
| stwx TISNIL, BASE, NARGS8:RC
| addi NARGS8:RC, NARGS8:RC, 8
| b <2
break;
case BC_JFUNCV:
#if !LJ_HASJIT
break;
#endif
| NYI // NYI: compiled vararg functions
break; /* NYI: compiled vararg functions. */
case BC_IFUNCV:
| // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
| lwz TMP2, L->maxstack
| add TMP1, BASE, RC
| add TMP0, RA, RC
| stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC.
| addi TMP3, RC, 8+FRAME_VARG
| lwz KBASE, -4+PC2PROTO(k)(PC)
| cmplw TMP0, TMP2
| stw TMP3, 0(TMP1) // Store delta + FRAME_VARG.
| bge ->vm_growstack_l
| lbz TMP2, -4+PC2PROTO(numparams)(PC)
| mr RA, BASE
| mr RC, TMP1
| ins_next1
| cmpwi TMP2, 0
| addi BASE, TMP1, 8
| beq >3
|1:
| cmplw RA, RC // Less args than parameters?
| lwz TMP0, 0(RA)
| lwz TMP3, 4(RA)
| bge >4
| stw TISNIL, 0(RA) // Clear old fixarg slot (help the GC).
| addi RA, RA, 8
|2:
| addic. TMP2, TMP2, -1
| stw TMP0, 8(TMP1)
| stw TMP3, 12(TMP1)
| addi TMP1, TMP1, 8
| bne <1
|3:
| ins_next2
|
|4: // Clear missing parameters.
| li TMP0, LJ_TNIL
| b <2
break;
case BC_FUNCC:
case BC_FUNCCW:
| // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
if (op == BC_FUNCC) {
| lp RD, CFUNC:RB->f
} else {
| lp RD, DISPATCH_GL(wrapf)(DISPATCH)
}
| add TMP1, RA, NARGS8:RC
| lwz TMP2, L->maxstack
| .toc lp TMP3, 0(RD)
| add RC, BASE, NARGS8:RC
| stp BASE, L->base
| cmplw TMP1, TMP2
| stp RC, L->top
| li_vmstate C
|.if TOC
| mtctr TMP3
|.else
| mtctr RD
|.endif
if (op == BC_FUNCCW) {
| lp CARG2, CFUNC:RB->f
}
| mr CARG1, L
| bgt ->vm_growstack_c // Need to grow stack.
| .toc lp TOCREG, TOC_OFS(RD)
| .tocenv lp ENVREG, ENV_OFS(RD)
| st_vmstate
| bctrl // (lua_State *L [, lua_CFunction f])
| // Returns nresults.
| lp BASE, L->base
| .toc ld TOCREG, SAVE_TOC
| slwi RD, CRET1, 3
| lp TMP1, L->top
| li_vmstate INTERP
| lwz PC, FRAME_PC(BASE) // Fetch PC of caller.
| stw L, DISPATCH_GL(cur_L)(DISPATCH)
| sub RA, TMP1, RD // RA = L->top - nresults*8
| st_vmstate
| b ->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);
int i;
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 0x1\n"
"\t.sleb128 -4\n"
"\t.byte 65\n"
"\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
"\t.align 2\n"
".LECIE0:\n\n");
fprintf(ctx->fp,
".LSFDE0:\n"
"\t.long .LEFDE0-.LASFDE0\n"
".LASFDE0:\n"
"\t.long .Lframe0\n"
"\t.long .Lbegin\n"
"\t.long %d\n"
"\t.byte 0xe\n\t.uleb128 %d\n"
"\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
"\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n",
fcofs, CFRAME_SIZE);
for (i = 14; i <= 31; i++)
fprintf(ctx->fp,
"\t.byte %d\n\t.uleb128 %d\n"
"\t.byte %d\n\t.uleb128 %d\n",
0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));
fprintf(ctx->fp,
"\t.align 2\n"
".LEFDE0:\n\n");
#if LJ_HASFFI
fprintf(ctx->fp,
".LSFDE1:\n"
"\t.long .LEFDE1-.LASFDE1\n"
".LASFDE1:\n"
"\t.long .Lframe0\n"
#if LJ_TARGET_PS3
"\t.long .lj_vm_ffi_call\n"
#else
"\t.long lj_vm_ffi_call\n"
#endif
"\t.long %d\n"
"\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
"\t.byte 0x8e\n\t.uleb128 2\n"
"\t.byte 0xd\n\t.uleb128 0xe\n"
"\t.align 2\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 -4\n"
"\t.byte 65\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 1\n\t.uleb128 0\n"
"\t.align 2\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"
"\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
"\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n",
fcofs, CFRAME_SIZE);
for (i = 14; i <= 31; i++)
fprintf(ctx->fp,
"\t.byte %d\n\t.uleb128 %d\n"
"\t.byte %d\n\t.uleb128 %d\n",
0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));
fprintf(ctx->fp,
"\t.align 2\n"
".LEFDE2:\n\n");
#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 -4\n"
"\t.byte 65\n"
"\t.uleb128 1\n" /* augmentation length */
"\t.byte 0x1b\n" /* pcrel|sdata4 */
"\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
"\t.align 2\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 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
"\t.byte 0x8e\n\t.uleb128 2\n"
"\t.byte 0xd\n\t.uleb128 0xe\n"
"\t.align 2\n"
".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
#endif
#endif
break;
default:
break;
}
}
|