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
|
// Copyright 2015, ARM Limited
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of ARM Limited nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VIXL_A64_ASSEMBLER_A64_H_
#define VIXL_A64_ASSEMBLER_A64_H_
#include "vixl/globals.h"
#include "vixl/invalset.h"
#include "vixl/utils.h"
#include "vixl/code-buffer.h"
#include "vixl/a64/instructions-a64.h"
namespace vixl {
typedef uint64_t RegList;
static const int kRegListSizeInBits = sizeof(RegList) * 8;
// Registers.
// Some CPURegister methods can return Register or VRegister types, so we need
// to declare them in advance.
class Register;
class VRegister;
class CPURegister {
public:
enum RegisterType {
// The kInvalid value is used to detect uninitialized static instances,
// which are always zero-initialized before any constructors are called.
kInvalid = 0,
kRegister,
kVRegister,
kFPRegister = kVRegister,
kNoRegister
};
CPURegister() : code_(0), size_(0), type_(kNoRegister) {
VIXL_ASSERT(!IsValid());
VIXL_ASSERT(IsNone());
}
CPURegister(unsigned code, unsigned size, RegisterType type)
: code_(code), size_(size), type_(type) {
VIXL_ASSERT(IsValidOrNone());
}
unsigned code() const {
VIXL_ASSERT(IsValid());
return code_;
}
RegisterType type() const {
VIXL_ASSERT(IsValidOrNone());
return type_;
}
RegList Bit() const {
VIXL_ASSERT(code_ < (sizeof(RegList) * 8));
return IsValid() ? (static_cast<RegList>(1) << code_) : 0;
}
unsigned size() const {
VIXL_ASSERT(IsValid());
return size_;
}
int SizeInBytes() const {
VIXL_ASSERT(IsValid());
VIXL_ASSERT(size() % 8 == 0);
return size_ / 8;
}
int SizeInBits() const {
VIXL_ASSERT(IsValid());
return size_;
}
bool Is8Bits() const {
VIXL_ASSERT(IsValid());
return size_ == 8;
}
bool Is16Bits() const {
VIXL_ASSERT(IsValid());
return size_ == 16;
}
bool Is32Bits() const {
VIXL_ASSERT(IsValid());
return size_ == 32;
}
bool Is64Bits() const {
VIXL_ASSERT(IsValid());
return size_ == 64;
}
bool Is128Bits() const {
VIXL_ASSERT(IsValid());
return size_ == 128;
}
bool IsValid() const {
if (IsValidRegister() || IsValidVRegister()) {
VIXL_ASSERT(!IsNone());
return true;
} else {
// This assert is hit when the register has not been properly initialized.
// One cause for this can be an initialisation order fiasco. See
// https://isocpp.org/wiki/faq/ctors#static-init-order for some details.
VIXL_ASSERT(IsNone());
return false;
}
}
bool IsValidRegister() const {
return IsRegister() &&
((size_ == kWRegSize) || (size_ == kXRegSize)) &&
((code_ < kNumberOfRegisters) || (code_ == kSPRegInternalCode));
}
bool IsValidVRegister() const {
return IsVRegister() &&
((size_ == kBRegSize) || (size_ == kHRegSize) ||
(size_ == kSRegSize) || (size_ == kDRegSize) ||
(size_ == kQRegSize)) &&
(code_ < kNumberOfVRegisters);
}
bool IsValidFPRegister() const {
return IsFPRegister() && (code_ < kNumberOfVRegisters);
}
bool IsNone() const {
// kNoRegister types should always have size 0 and code 0.
VIXL_ASSERT((type_ != kNoRegister) || (code_ == 0));
VIXL_ASSERT((type_ != kNoRegister) || (size_ == 0));
return type_ == kNoRegister;
}
bool Aliases(const CPURegister& other) const {
VIXL_ASSERT(IsValidOrNone() && other.IsValidOrNone());
return (code_ == other.code_) && (type_ == other.type_);
}
bool Is(const CPURegister& other) const {
VIXL_ASSERT(IsValidOrNone() && other.IsValidOrNone());
return Aliases(other) && (size_ == other.size_);
}
bool IsZero() const {
VIXL_ASSERT(IsValid());
return IsRegister() && (code_ == kZeroRegCode);
}
bool IsSP() const {
VIXL_ASSERT(IsValid());
return IsRegister() && (code_ == kSPRegInternalCode);
}
bool IsRegister() const {
return type_ == kRegister;
}
bool IsVRegister() const {
return type_ == kVRegister;
}
bool IsFPRegister() const {
return IsS() || IsD();
}
bool IsW() const { return IsValidRegister() && Is32Bits(); }
bool IsX() const { return IsValidRegister() && Is64Bits(); }
// These assertions ensure that the size and type of the register are as
// described. They do not consider the number of lanes that make up a vector.
// So, for example, Is8B() implies IsD(), and Is1D() implies IsD, but IsD()
// does not imply Is1D() or Is8B().
// Check the number of lanes, ie. the format of the vector, using methods such
// as Is8B(), Is1D(), etc. in the VRegister class.
bool IsV() const { return IsVRegister(); }
bool IsB() const { return IsV() && Is8Bits(); }
bool IsH() const { return IsV() && Is16Bits(); }
bool IsS() const { return IsV() && Is32Bits(); }
bool IsD() const { return IsV() && Is64Bits(); }
bool IsQ() const { return IsV() && Is128Bits(); }
const Register& W() const;
const Register& X() const;
const VRegister& V() const;
const VRegister& B() const;
const VRegister& H() const;
const VRegister& S() const;
const VRegister& D() const;
const VRegister& Q() const;
bool IsSameSizeAndType(const CPURegister& other) const {
return (size_ == other.size_) && (type_ == other.type_);
}
protected:
unsigned code_;
unsigned size_;
RegisterType type_;
private:
bool IsValidOrNone() const {
return IsValid() || IsNone();
}
};
class Register : public CPURegister {
public:
Register() : CPURegister() {}
explicit Register(const CPURegister& other)
: CPURegister(other.code(), other.size(), other.type()) {
VIXL_ASSERT(IsValidRegister());
}
Register(unsigned code, unsigned size)
: CPURegister(code, size, kRegister) {}
bool IsValid() const {
VIXL_ASSERT(IsRegister() || IsNone());
return IsValidRegister();
}
static const Register& WRegFromCode(unsigned code);
static const Register& XRegFromCode(unsigned code);
private:
static const Register wregisters[];
static const Register xregisters[];
};
class VRegister : public CPURegister {
public:
VRegister() : CPURegister(), lanes_(1) {}
explicit VRegister(const CPURegister& other)
: CPURegister(other.code(), other.size(), other.type()), lanes_(1) {
VIXL_ASSERT(IsValidVRegister());
VIXL_ASSERT(IsPowerOf2(lanes_) && (lanes_ <= 16));
}
VRegister(unsigned code, unsigned size, unsigned lanes = 1)
: CPURegister(code, size, kVRegister), lanes_(lanes) {
VIXL_ASSERT(IsPowerOf2(lanes_) && (lanes_ <= 16));
}
VRegister(unsigned code, VectorFormat format)
: CPURegister(code, RegisterSizeInBitsFromFormat(format), kVRegister),
lanes_(IsVectorFormat(format) ? LaneCountFromFormat(format) : 1) {
VIXL_ASSERT(IsPowerOf2(lanes_) && (lanes_ <= 16));
}
bool IsValid() const {
VIXL_ASSERT(IsVRegister() || IsNone());
return IsValidVRegister();
}
static const VRegister& BRegFromCode(unsigned code);
static const VRegister& HRegFromCode(unsigned code);
static const VRegister& SRegFromCode(unsigned code);
static const VRegister& DRegFromCode(unsigned code);
static const VRegister& QRegFromCode(unsigned code);
static const VRegister& VRegFromCode(unsigned code);
VRegister V8B() const { return VRegister(code_, kDRegSize, 8); }
VRegister V16B() const { return VRegister(code_, kQRegSize, 16); }
VRegister V4H() const { return VRegister(code_, kDRegSize, 4); }
VRegister V8H() const { return VRegister(code_, kQRegSize, 8); }
VRegister V2S() const { return VRegister(code_, kDRegSize, 2); }
VRegister V4S() const { return VRegister(code_, kQRegSize, 4); }
VRegister V2D() const { return VRegister(code_, kQRegSize, 2); }
VRegister V1D() const { return VRegister(code_, kDRegSize, 1); }
bool Is8B() const { return (Is64Bits() && (lanes_ == 8)); }
bool Is16B() const { return (Is128Bits() && (lanes_ == 16)); }
bool Is4H() const { return (Is64Bits() && (lanes_ == 4)); }
bool Is8H() const { return (Is128Bits() && (lanes_ == 8)); }
bool Is2S() const { return (Is64Bits() && (lanes_ == 2)); }
bool Is4S() const { return (Is128Bits() && (lanes_ == 4)); }
bool Is1D() const { return (Is64Bits() && (lanes_ == 1)); }
bool Is2D() const { return (Is128Bits() && (lanes_ == 2)); }
// For consistency, we assert the number of lanes of these scalar registers,
// even though there are no vectors of equivalent total size with which they
// could alias.
bool Is1B() const {
VIXL_ASSERT(!(Is8Bits() && IsVector()));
return Is8Bits();
}
bool Is1H() const {
VIXL_ASSERT(!(Is16Bits() && IsVector()));
return Is16Bits();
}
bool Is1S() const {
VIXL_ASSERT(!(Is32Bits() && IsVector()));
return Is32Bits();
}
bool IsLaneSizeB() const { return LaneSizeInBits() == kBRegSize; }
bool IsLaneSizeH() const { return LaneSizeInBits() == kHRegSize; }
bool IsLaneSizeS() const { return LaneSizeInBits() == kSRegSize; }
bool IsLaneSizeD() const { return LaneSizeInBits() == kDRegSize; }
int lanes() const {
return lanes_;
}
bool IsScalar() const {
return lanes_ == 1;
}
bool IsVector() const {
return lanes_ > 1;
}
bool IsSameFormat(const VRegister& other) const {
return (size_ == other.size_) && (lanes_ == other.lanes_);
}
unsigned LaneSizeInBytes() const {
return SizeInBytes() / lanes_;
}
unsigned LaneSizeInBits() const {
return LaneSizeInBytes() * 8;
}
private:
static const VRegister bregisters[];
static const VRegister hregisters[];
static const VRegister sregisters[];
static const VRegister dregisters[];
static const VRegister qregisters[];
static const VRegister vregisters[];
int lanes_;
};
// Backward compatibility for FPRegisters.
typedef VRegister FPRegister;
// No*Reg is used to indicate an unused argument, or an error case. Note that
// these all compare equal (using the Is() method). The Register and VRegister
// variants are provided for convenience.
const Register NoReg;
const VRegister NoVReg;
const FPRegister NoFPReg; // For backward compatibility.
const CPURegister NoCPUReg;
#define DEFINE_REGISTERS(N) \
const Register w##N(N, kWRegSize); \
const Register x##N(N, kXRegSize);
REGISTER_CODE_LIST(DEFINE_REGISTERS)
#undef DEFINE_REGISTERS
const Register wsp(kSPRegInternalCode, kWRegSize);
const Register sp(kSPRegInternalCode, kXRegSize);
#define DEFINE_VREGISTERS(N) \
const VRegister b##N(N, kBRegSize); \
const VRegister h##N(N, kHRegSize); \
const VRegister s##N(N, kSRegSize); \
const VRegister d##N(N, kDRegSize); \
const VRegister q##N(N, kQRegSize); \
const VRegister v##N(N, kQRegSize);
REGISTER_CODE_LIST(DEFINE_VREGISTERS)
#undef DEFINE_VREGISTERS
// Registers aliases.
const Register ip0 = x16;
const Register ip1 = x17;
const Register lr = x30;
const Register xzr = x31;
const Register wzr = w31;
// AreAliased returns true if any of the named registers overlap. Arguments
// set to NoReg are ignored. The system stack pointer may be specified.
bool AreAliased(const CPURegister& reg1,
const CPURegister& reg2,
const CPURegister& reg3 = NoReg,
const CPURegister& reg4 = NoReg,
const CPURegister& reg5 = NoReg,
const CPURegister& reg6 = NoReg,
const CPURegister& reg7 = NoReg,
const CPURegister& reg8 = NoReg);
// AreSameSizeAndType returns true if all of the specified registers have the
// same size, and are of the same type. The system stack pointer may be
// specified. Arguments set to NoReg are ignored, as are any subsequent
// arguments. At least one argument (reg1) must be valid (not NoCPUReg).
bool AreSameSizeAndType(const CPURegister& reg1,
const CPURegister& reg2,
const CPURegister& reg3 = NoCPUReg,
const CPURegister& reg4 = NoCPUReg,
const CPURegister& reg5 = NoCPUReg,
const CPURegister& reg6 = NoCPUReg,
const CPURegister& reg7 = NoCPUReg,
const CPURegister& reg8 = NoCPUReg);
// AreSameFormat returns true if all of the specified VRegisters have the same
// vector format. Arguments set to NoReg are ignored, as are any subsequent
// arguments. At least one argument (reg1) must be valid (not NoVReg).
bool AreSameFormat(const VRegister& reg1,
const VRegister& reg2,
const VRegister& reg3 = NoVReg,
const VRegister& reg4 = NoVReg);
// AreConsecutive returns true if all of the specified VRegisters are
// consecutive in the register file. Arguments set to NoReg are ignored, as are
// any subsequent arguments. At least one argument (reg1) must be valid
// (not NoVReg).
bool AreConsecutive(const VRegister& reg1,
const VRegister& reg2,
const VRegister& reg3 = NoVReg,
const VRegister& reg4 = NoVReg);
// Lists of registers.
class CPURegList {
public:
explicit CPURegList(CPURegister reg1,
CPURegister reg2 = NoCPUReg,
CPURegister reg3 = NoCPUReg,
CPURegister reg4 = NoCPUReg)
: list_(reg1.Bit() | reg2.Bit() | reg3.Bit() | reg4.Bit()),
size_(reg1.size()), type_(reg1.type()) {
VIXL_ASSERT(AreSameSizeAndType(reg1, reg2, reg3, reg4));
VIXL_ASSERT(IsValid());
}
CPURegList(CPURegister::RegisterType type, unsigned size, RegList list)
: list_(list), size_(size), type_(type) {
VIXL_ASSERT(IsValid());
}
CPURegList(CPURegister::RegisterType type, unsigned size,
unsigned first_reg, unsigned last_reg)
: size_(size), type_(type) {
VIXL_ASSERT(((type == CPURegister::kRegister) &&
(last_reg < kNumberOfRegisters)) ||
((type == CPURegister::kVRegister) &&
(last_reg < kNumberOfVRegisters)));
VIXL_ASSERT(last_reg >= first_reg);
list_ = (UINT64_C(1) << (last_reg + 1)) - 1;
list_ &= ~((UINT64_C(1) << first_reg) - 1);
VIXL_ASSERT(IsValid());
}
CPURegister::RegisterType type() const {
VIXL_ASSERT(IsValid());
return type_;
}
// Combine another CPURegList into this one. Registers that already exist in
// this list are left unchanged. The type and size of the registers in the
// 'other' list must match those in this list.
void Combine(const CPURegList& other) {
VIXL_ASSERT(IsValid());
VIXL_ASSERT(other.type() == type_);
VIXL_ASSERT(other.RegisterSizeInBits() == size_);
list_ |= other.list();
}
// Remove every register in the other CPURegList from this one. Registers that
// do not exist in this list are ignored. The type and size of the registers
// in the 'other' list must match those in this list.
void Remove(const CPURegList& other) {
VIXL_ASSERT(IsValid());
VIXL_ASSERT(other.type() == type_);
VIXL_ASSERT(other.RegisterSizeInBits() == size_);
list_ &= ~other.list();
}
// Variants of Combine and Remove which take a single register.
void Combine(const CPURegister& other) {
VIXL_ASSERT(other.type() == type_);
VIXL_ASSERT(other.size() == size_);
Combine(other.code());
}
void Remove(const CPURegister& other) {
VIXL_ASSERT(other.type() == type_);
VIXL_ASSERT(other.size() == size_);
Remove(other.code());
}
// Variants of Combine and Remove which take a single register by its code;
// the type and size of the register is inferred from this list.
void Combine(int code) {
VIXL_ASSERT(IsValid());
VIXL_ASSERT(CPURegister(code, size_, type_).IsValid());
list_ |= (UINT64_C(1) << code);
}
void Remove(int code) {
VIXL_ASSERT(IsValid());
VIXL_ASSERT(CPURegister(code, size_, type_).IsValid());
list_ &= ~(UINT64_C(1) << code);
}
static CPURegList Union(const CPURegList& list_1, const CPURegList& list_2) {
VIXL_ASSERT(list_1.type_ == list_2.type_);
VIXL_ASSERT(list_1.size_ == list_2.size_);
return CPURegList(list_1.type_, list_1.size_, list_1.list_ | list_2.list_);
}
static CPURegList Union(const CPURegList& list_1,
const CPURegList& list_2,
const CPURegList& list_3);
static CPURegList Union(const CPURegList& list_1,
const CPURegList& list_2,
const CPURegList& list_3,
const CPURegList& list_4);
static CPURegList Intersection(const CPURegList& list_1,
const CPURegList& list_2) {
VIXL_ASSERT(list_1.type_ == list_2.type_);
VIXL_ASSERT(list_1.size_ == list_2.size_);
return CPURegList(list_1.type_, list_1.size_, list_1.list_ & list_2.list_);
}
static CPURegList Intersection(const CPURegList& list_1,
const CPURegList& list_2,
const CPURegList& list_3);
static CPURegList Intersection(const CPURegList& list_1,
const CPURegList& list_2,
const CPURegList& list_3,
const CPURegList& list_4);
bool Overlaps(const CPURegList& other) const {
return (type_ == other.type_) && ((list_ & other.list_) != 0);
}
RegList list() const {
VIXL_ASSERT(IsValid());
return list_;
}
void set_list(RegList new_list) {
VIXL_ASSERT(IsValid());
list_ = new_list;
}
// Remove all callee-saved registers from the list. This can be useful when
// preparing registers for an AAPCS64 function call, for example.
void RemoveCalleeSaved();
CPURegister PopLowestIndex();
CPURegister PopHighestIndex();
// AAPCS64 callee-saved registers.
static CPURegList GetCalleeSaved(unsigned size = kXRegSize);
static CPURegList GetCalleeSavedV(unsigned size = kDRegSize);
// AAPCS64 caller-saved registers. Note that this includes lr.
// TODO(all): Determine how we handle d8-d15 being callee-saved, but the top
// 64-bits being caller-saved.
static CPURegList GetCallerSaved(unsigned size = kXRegSize);
static CPURegList GetCallerSavedV(unsigned size = kDRegSize);
bool IsEmpty() const {
VIXL_ASSERT(IsValid());
return list_ == 0;
}
bool IncludesAliasOf(const CPURegister& other) const {
VIXL_ASSERT(IsValid());
return (type_ == other.type()) && ((other.Bit() & list_) != 0);
}
bool IncludesAliasOf(int code) const {
VIXL_ASSERT(IsValid());
return ((code & list_) != 0);
}
int Count() const {
VIXL_ASSERT(IsValid());
return CountSetBits(list_);
}
unsigned RegisterSizeInBits() const {
VIXL_ASSERT(IsValid());
return size_;
}
unsigned RegisterSizeInBytes() const {
int size_in_bits = RegisterSizeInBits();
VIXL_ASSERT((size_in_bits % 8) == 0);
return size_in_bits / 8;
}
unsigned TotalSizeInBytes() const {
VIXL_ASSERT(IsValid());
return RegisterSizeInBytes() * Count();
}
private:
RegList list_;
unsigned size_;
CPURegister::RegisterType type_;
bool IsValid() const;
};
// AAPCS64 callee-saved registers.
extern const CPURegList kCalleeSaved;
extern const CPURegList kCalleeSavedV;
// AAPCS64 caller-saved registers. Note that this includes lr.
extern const CPURegList kCallerSaved;
extern const CPURegList kCallerSavedV;
// Operand.
class Operand {
public:
// #<immediate>
// where <immediate> is int64_t.
// This is allowed to be an implicit constructor because Operand is
// a wrapper class that doesn't normally perform any type conversion.
Operand(int64_t immediate = 0); // NOLINT(runtime/explicit)
// rm, {<shift> #<shift_amount>}
// where <shift> is one of {LSL, LSR, ASR, ROR}.
// <shift_amount> is uint6_t.
// This is allowed to be an implicit constructor because Operand is
// a wrapper class that doesn't normally perform any type conversion.
Operand(Register reg,
Shift shift = LSL,
unsigned shift_amount = 0); // NOLINT(runtime/explicit)
// rm, {<extend> {#<shift_amount>}}
// where <extend> is one of {UXTB, UXTH, UXTW, UXTX, SXTB, SXTH, SXTW, SXTX}.
// <shift_amount> is uint2_t.
explicit Operand(Register reg, Extend extend, unsigned shift_amount = 0);
bool IsImmediate() const;
bool IsShiftedRegister() const;
bool IsExtendedRegister() const;
bool IsZero() const;
// This returns an LSL shift (<= 4) operand as an equivalent extend operand,
// which helps in the encoding of instructions that use the stack pointer.
Operand ToExtendedRegister() const;
int64_t immediate() const {
VIXL_ASSERT(IsImmediate());
return immediate_;
}
Register reg() const {
VIXL_ASSERT(IsShiftedRegister() || IsExtendedRegister());
return reg_;
}
Shift shift() const {
VIXL_ASSERT(IsShiftedRegister());
return shift_;
}
Extend extend() const {
VIXL_ASSERT(IsExtendedRegister());
return extend_;
}
unsigned shift_amount() const {
VIXL_ASSERT(IsShiftedRegister() || IsExtendedRegister());
return shift_amount_;
}
private:
int64_t immediate_;
Register reg_;
Shift shift_;
Extend extend_;
unsigned shift_amount_;
};
// MemOperand represents the addressing mode of a load or store instruction.
class MemOperand {
public:
explicit MemOperand(Register base,
int64_t offset = 0,
AddrMode addrmode = Offset);
MemOperand(Register base,
Register regoffset,
Shift shift = LSL,
unsigned shift_amount = 0);
MemOperand(Register base,
Register regoffset,
Extend extend,
unsigned shift_amount = 0);
MemOperand(Register base,
const Operand& offset,
AddrMode addrmode = Offset);
const Register& base() const { return base_; }
const Register& regoffset() const { return regoffset_; }
int64_t offset() const { return offset_; }
AddrMode addrmode() const { return addrmode_; }
Shift shift() const { return shift_; }
Extend extend() const { return extend_; }
unsigned shift_amount() const { return shift_amount_; }
bool IsImmediateOffset() const;
bool IsRegisterOffset() const;
bool IsPreIndex() const;
bool IsPostIndex() const;
void AddOffset(int64_t offset);
private:
Register base_;
Register regoffset_;
int64_t offset_;
AddrMode addrmode_;
Shift shift_;
Extend extend_;
unsigned shift_amount_;
};
class LabelTestHelper; // Forward declaration.
class Label {
public:
Label() : location_(kLocationUnbound) {}
~Label() {
// If the label has been linked to, it needs to be bound to a target.
VIXL_ASSERT(!IsLinked() || IsBound());
}
bool IsBound() const { return location_ >= 0; }
bool IsLinked() const { return !links_.empty(); }
ptrdiff_t location() const { return location_; }
static const int kNPreallocatedLinks = 4;
static const ptrdiff_t kInvalidLinkKey = PTRDIFF_MAX;
static const size_t kReclaimFrom = 512;
static const size_t kReclaimFactor = 2;
typedef InvalSet<ptrdiff_t,
kNPreallocatedLinks,
ptrdiff_t,
kInvalidLinkKey,
kReclaimFrom,
kReclaimFactor> LinksSetBase;
typedef InvalSetIterator<LinksSetBase> LabelLinksIteratorBase;
private:
class LinksSet : public LinksSetBase {
public:
LinksSet() : LinksSetBase() {}
};
// Allows iterating over the links of a label. The behaviour is undefined if
// the list of links is modified in any way while iterating.
class LabelLinksIterator : public LabelLinksIteratorBase {
public:
explicit LabelLinksIterator(Label* label)
: LabelLinksIteratorBase(&label->links_) {}
};
void Bind(ptrdiff_t location) {
// Labels can only be bound once.
VIXL_ASSERT(!IsBound());
location_ = location;
}
void AddLink(ptrdiff_t instruction) {
// If a label is bound, the assembler already has the information it needs
// to write the instruction, so there is no need to add it to links_.
VIXL_ASSERT(!IsBound());
links_.insert(instruction);
}
void DeleteLink(ptrdiff_t instruction) {
links_.erase(instruction);
}
void ClearAllLinks() {
links_.clear();
}
// TODO: The comment below considers average case complexity for our
// usual use-cases. The elements of interest are:
// - Branches to a label are emitted in order: branch instructions to a label
// are generated at an offset in the code generation buffer greater than any
// other branch to that same label already generated. As an example, this can
// be broken when an instruction is patched to become a branch. Note that the
// code will still work, but the complexity considerations below may locally
// not apply any more.
// - Veneers are generated in order: for multiple branches of the same type
// branching to the same unbound label going out of range, veneers are
// generated in growing order of the branch instruction offset from the start
// of the buffer.
//
// When creating a veneer for a branch going out of range, the link for this
// branch needs to be removed from this `links_`. Since all branches are
// tracked in one underlying InvalSet, the complexity for this deletion is the
// same as for finding the element, ie. O(n), where n is the number of links
// in the set.
// This could be reduced to O(1) by using the same trick as used when tracking
// branch information for veneers: split the container to use one set per type
// of branch. With that setup, when a veneer is created and the link needs to
// be deleted, if the two points above hold, it must be the minimum element of
// the set for its type of branch, and that minimum element will be accessible
// in O(1).
// The offsets of the instructions that have linked to this label.
LinksSet links_;
// The label location.
ptrdiff_t location_;
static const ptrdiff_t kLocationUnbound = -1;
// It is not safe to copy labels, so disable the copy constructor and operator
// by declaring them private (without an implementation).
Label(const Label&);
void operator=(const Label&);
// The Assembler class is responsible for binding and linking labels, since
// the stored offsets need to be consistent with the Assembler's buffer.
friend class Assembler;
// The MacroAssembler and VeneerPool handle resolution of branches to distant
// targets.
friend class MacroAssembler;
friend class VeneerPool;
};
// Required InvalSet template specialisations.
#define INVAL_SET_TEMPLATE_PARAMETERS \
ptrdiff_t, \
Label::kNPreallocatedLinks, \
ptrdiff_t, \
Label::kInvalidLinkKey, \
Label::kReclaimFrom, \
Label::kReclaimFactor
template<>
inline ptrdiff_t InvalSet<INVAL_SET_TEMPLATE_PARAMETERS>::Key(
const ptrdiff_t& element) {
return element;
}
template<>
inline void InvalSet<INVAL_SET_TEMPLATE_PARAMETERS>::SetKey(
ptrdiff_t* element, ptrdiff_t key) {
*element = key;
}
#undef INVAL_SET_TEMPLATE_PARAMETERS
class Assembler;
class LiteralPool;
// A literal is a 32-bit or 64-bit piece of data stored in the instruction
// stream and loaded through a pc relative load. The same literal can be
// referred to by multiple instructions but a literal can only reside at one
// place in memory. A literal can be used by a load before or after being
// placed in memory.
//
// Internally an offset of 0 is associated with a literal which has been
// neither used nor placed. Then two possibilities arise:
// 1) the label is placed, the offset (stored as offset + 1) is used to
// resolve any subsequent load using the label.
// 2) the label is not placed and offset is the offset of the last load using
// the literal (stored as -offset -1). If multiple loads refer to this
// literal then the last load holds the offset of the preceding load and
// all loads form a chain. Once the offset is placed all the loads in the
// chain are resolved and future loads fall back to possibility 1.
class RawLiteral {
public:
enum DeletionPolicy {
kDeletedOnPlacementByPool,
kDeletedOnPoolDestruction,
kManuallyDeleted
};
RawLiteral(size_t size,
LiteralPool* literal_pool,
DeletionPolicy deletion_policy = kManuallyDeleted);
// The literal pool only sees and deletes `RawLiteral*` pointers, but they are
// actually pointing to `Literal<T>` objects.
virtual ~RawLiteral() {}
size_t size() {
VIXL_STATIC_ASSERT(kDRegSizeInBytes == kXRegSizeInBytes);
VIXL_STATIC_ASSERT(kSRegSizeInBytes == kWRegSizeInBytes);
VIXL_ASSERT((size_ == kXRegSizeInBytes) ||
(size_ == kWRegSizeInBytes) ||
(size_ == kQRegSizeInBytes));
return size_;
}
uint64_t raw_value128_low64() {
VIXL_ASSERT(size_ == kQRegSizeInBytes);
return low64_;
}
uint64_t raw_value128_high64() {
VIXL_ASSERT(size_ == kQRegSizeInBytes);
return high64_;
}
uint64_t raw_value64() {
VIXL_ASSERT(size_ == kXRegSizeInBytes);
VIXL_ASSERT(high64_ == 0);
return low64_;
}
uint32_t raw_value32() {
VIXL_ASSERT(size_ == kWRegSizeInBytes);
VIXL_ASSERT(high64_ == 0);
VIXL_ASSERT(is_uint32(low64_) || is_int32(low64_));
return static_cast<uint32_t>(low64_);
}
bool IsUsed() { return offset_ < 0; }
bool IsPlaced() { return offset_ > 0; }
LiteralPool* GetLiteralPool() const {
return literal_pool_;
}
ptrdiff_t offset() {
VIXL_ASSERT(IsPlaced());
return offset_ - 1;
}
protected:
void set_offset(ptrdiff_t offset) {
VIXL_ASSERT(offset >= 0);
VIXL_ASSERT(IsWordAligned(offset));
VIXL_ASSERT(!IsPlaced());
offset_ = offset + 1;
}
ptrdiff_t last_use() {
VIXL_ASSERT(IsUsed());
return -offset_ - 1;
}
void set_last_use(ptrdiff_t offset) {
VIXL_ASSERT(offset >= 0);
VIXL_ASSERT(IsWordAligned(offset));
VIXL_ASSERT(!IsPlaced());
offset_ = -offset - 1;
}
size_t size_;
ptrdiff_t offset_;
uint64_t low64_;
uint64_t high64_;
private:
LiteralPool* literal_pool_;
DeletionPolicy deletion_policy_;
friend class Assembler;
friend class LiteralPool;
};
template <typename T>
class Literal : public RawLiteral {
public:
explicit Literal(T value,
LiteralPool* literal_pool = NULL,
RawLiteral::DeletionPolicy ownership = kManuallyDeleted)
: RawLiteral(sizeof(value), literal_pool, ownership) {
VIXL_STATIC_ASSERT(sizeof(value) <= kXRegSizeInBytes);
UpdateValue(value);
}
Literal(T high64, T low64,
LiteralPool* literal_pool = NULL,
RawLiteral::DeletionPolicy ownership = kManuallyDeleted)
: RawLiteral(kQRegSizeInBytes, literal_pool, ownership) {
VIXL_STATIC_ASSERT(sizeof(low64) == (kQRegSizeInBytes / 2));
UpdateValue(high64, low64);
}
virtual ~Literal() {}
// Update the value of this literal, if necessary by rewriting the value in
// the pool.
// If the literal has already been placed in a literal pool, the address of
// the start of the code buffer must be provided, as the literal only knows it
// offset from there. This also allows patching the value after the code has
// been moved in memory.
void UpdateValue(T new_value, uint8_t* code_buffer = NULL) {
VIXL_ASSERT(sizeof(new_value) == size_);
memcpy(&low64_, &new_value, sizeof(new_value));
if (IsPlaced()) {
VIXL_ASSERT(code_buffer != NULL);
RewriteValueInCode(code_buffer);
}
}
void UpdateValue(T high64, T low64, uint8_t* code_buffer = NULL) {
VIXL_ASSERT(sizeof(low64) == size_ / 2);
memcpy(&low64_, &low64, sizeof(low64));
memcpy(&high64_, &high64, sizeof(high64));
if (IsPlaced()) {
VIXL_ASSERT(code_buffer != NULL);
RewriteValueInCode(code_buffer);
}
}
void UpdateValue(T new_value, const Assembler* assembler);
void UpdateValue(T high64, T low64, const Assembler* assembler);
private:
void RewriteValueInCode(uint8_t* code_buffer) {
VIXL_ASSERT(IsPlaced());
VIXL_STATIC_ASSERT(sizeof(T) <= kXRegSizeInBytes);
switch (size()) {
case kSRegSizeInBytes:
*reinterpret_cast<uint32_t*>(code_buffer + offset()) = raw_value32();
break;
case kDRegSizeInBytes:
*reinterpret_cast<uint64_t*>(code_buffer + offset()) = raw_value64();
break;
default:
VIXL_ASSERT(size() == kQRegSizeInBytes);
uint64_t* base_address =
reinterpret_cast<uint64_t*>(code_buffer + offset());
*base_address = raw_value128_low64();
*(base_address + 1) = raw_value128_high64();
}
}
};
// Control whether or not position-independent code should be emitted.
enum PositionIndependentCodeOption {
// All code generated will be position-independent; all branches and
// references to labels generated with the Label class will use PC-relative
// addressing.
PositionIndependentCode,
// Allow VIXL to generate code that refers to absolute addresses. With this
// option, it will not be possible to copy the code buffer and run it from a
// different address; code must be generated in its final location.
PositionDependentCode,
// Allow VIXL to assume that the bottom 12 bits of the address will be
// constant, but that the top 48 bits may change. This allows `adrp` to
// function in systems which copy code between pages, but otherwise maintain
// 4KB page alignment.
PageOffsetDependentCode
};
// Control how scaled- and unscaled-offset loads and stores are generated.
enum LoadStoreScalingOption {
// Prefer scaled-immediate-offset instructions, but emit unscaled-offset,
// register-offset, pre-index or post-index instructions if necessary.
PreferScaledOffset,
// Prefer unscaled-immediate-offset instructions, but emit scaled-offset,
// register-offset, pre-index or post-index instructions if necessary.
PreferUnscaledOffset,
// Require scaled-immediate-offset instructions.
RequireScaledOffset,
// Require unscaled-immediate-offset instructions.
RequireUnscaledOffset
};
// Assembler.
class Assembler {
public:
Assembler(size_t capacity,
PositionIndependentCodeOption pic = PositionIndependentCode);
Assembler(byte* buffer, size_t capacity,
PositionIndependentCodeOption pic = PositionIndependentCode);
// The destructor asserts that one of the following is true:
// * The Assembler object has not been used.
// * Nothing has been emitted since the last Reset() call.
// * Nothing has been emitted since the last FinalizeCode() call.
~Assembler();
// System functions.
// Start generating code from the beginning of the buffer, discarding any code
// and data that has already been emitted into the buffer.
void Reset();
// Finalize a code buffer of generated instructions. This function must be
// called before executing or copying code from the buffer.
void FinalizeCode();
// Label.
// Bind a label to the current PC.
void bind(Label* label);
// Bind a label to a specified offset from the start of the buffer.
void BindToOffset(Label* label, ptrdiff_t offset);
// Place a literal at the current PC.
void place(RawLiteral* literal);
ptrdiff_t CursorOffset() const {
return buffer_->CursorOffset();
}
ptrdiff_t BufferEndOffset() const {
return static_cast<ptrdiff_t>(buffer_->capacity());
}
// Return the address of an offset in the buffer.
template <typename T>
T GetOffsetAddress(ptrdiff_t offset) const {
VIXL_STATIC_ASSERT(sizeof(T) >= sizeof(uintptr_t));
return buffer_->GetOffsetAddress<T>(offset);
}
// Return the address of a bound label.
template <typename T>
T GetLabelAddress(const Label * label) const {
VIXL_ASSERT(label->IsBound());
VIXL_STATIC_ASSERT(sizeof(T) >= sizeof(uintptr_t));
return GetOffsetAddress<T>(label->location());
}
// Return the address of the cursor.
template <typename T>
T GetCursorAddress() const {
VIXL_STATIC_ASSERT(sizeof(T) >= sizeof(uintptr_t));
return GetOffsetAddress<T>(CursorOffset());
}
// Return the address of the start of the buffer.
template <typename T>
T GetStartAddress() const {
VIXL_STATIC_ASSERT(sizeof(T) >= sizeof(uintptr_t));
return GetOffsetAddress<T>(0);
}
Instruction* InstructionAt(ptrdiff_t instruction_offset) {
return GetOffsetAddress<Instruction*>(instruction_offset);
}
ptrdiff_t InstructionOffset(Instruction* instruction) {
VIXL_STATIC_ASSERT(sizeof(*instruction) == 1);
ptrdiff_t offset = instruction - GetStartAddress<Instruction*>();
VIXL_ASSERT((0 <= offset) &&
(offset < static_cast<ptrdiff_t>(BufferCapacity())));
return offset;
}
// Instruction set functions.
// Branch / Jump instructions.
// Branch to register.
void br(const Register& xn);
// Branch with link to register.
void blr(const Register& xn);
// Branch to register with return hint.
void ret(const Register& xn = lr);
// Unconditional branch to label.
void b(Label* label);
// Conditional branch to label.
void b(Label* label, Condition cond);
// Unconditional branch to PC offset.
void b(int imm26);
// Conditional branch to PC offset.
void b(int imm19, Condition cond);
// Branch with link to label.
void bl(Label* label);
// Branch with link to PC offset.
void bl(int imm26);
// Compare and branch to label if zero.
void cbz(const Register& rt, Label* label);
// Compare and branch to PC offset if zero.
void cbz(const Register& rt, int imm19);
// Compare and branch to label if not zero.
void cbnz(const Register& rt, Label* label);
// Compare and branch to PC offset if not zero.
void cbnz(const Register& rt, int imm19);
// Table lookup from one register.
void tbl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Table lookup from two registers.
void tbl(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vm);
// Table lookup from three registers.
void tbl(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vn3,
const VRegister& vm);
// Table lookup from four registers.
void tbl(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vn3,
const VRegister& vn4,
const VRegister& vm);
// Table lookup extension from one register.
void tbx(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Table lookup extension from two registers.
void tbx(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vm);
// Table lookup extension from three registers.
void tbx(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vn3,
const VRegister& vm);
// Table lookup extension from four registers.
void tbx(const VRegister& vd,
const VRegister& vn,
const VRegister& vn2,
const VRegister& vn3,
const VRegister& vn4,
const VRegister& vm);
// Test bit and branch to label if zero.
void tbz(const Register& rt, unsigned bit_pos, Label* label);
// Test bit and branch to PC offset if zero.
void tbz(const Register& rt, unsigned bit_pos, int imm14);
// Test bit and branch to label if not zero.
void tbnz(const Register& rt, unsigned bit_pos, Label* label);
// Test bit and branch to PC offset if not zero.
void tbnz(const Register& rt, unsigned bit_pos, int imm14);
// Address calculation instructions.
// Calculate a PC-relative address. Unlike for branches the offset in adr is
// unscaled (i.e. the result can be unaligned).
// Calculate the address of a label.
void adr(const Register& rd, Label* label);
// Calculate the address of a PC offset.
void adr(const Register& rd, int imm21);
// Calculate the page address of a label.
void adrp(const Register& rd, Label* label);
// Calculate the page address of a PC offset.
void adrp(const Register& rd, int imm21);
// Data Processing instructions.
// Add.
void add(const Register& rd,
const Register& rn,
const Operand& operand);
// Add and update status flags.
void adds(const Register& rd,
const Register& rn,
const Operand& operand);
// Compare negative.
void cmn(const Register& rn, const Operand& operand);
// Subtract.
void sub(const Register& rd,
const Register& rn,
const Operand& operand);
// Subtract and update status flags.
void subs(const Register& rd,
const Register& rn,
const Operand& operand);
// Compare.
void cmp(const Register& rn, const Operand& operand);
// Negate.
void neg(const Register& rd,
const Operand& operand);
// Negate and update status flags.
void negs(const Register& rd,
const Operand& operand);
// Add with carry bit.
void adc(const Register& rd,
const Register& rn,
const Operand& operand);
// Add with carry bit and update status flags.
void adcs(const Register& rd,
const Register& rn,
const Operand& operand);
// Subtract with carry bit.
void sbc(const Register& rd,
const Register& rn,
const Operand& operand);
// Subtract with carry bit and update status flags.
void sbcs(const Register& rd,
const Register& rn,
const Operand& operand);
// Negate with carry bit.
void ngc(const Register& rd,
const Operand& operand);
// Negate with carry bit and update status flags.
void ngcs(const Register& rd,
const Operand& operand);
// Logical instructions.
// Bitwise and (A & B).
void and_(const Register& rd,
const Register& rn,
const Operand& operand);
// Bitwise and (A & B) and update status flags.
void ands(const Register& rd,
const Register& rn,
const Operand& operand);
// Bit test and set flags.
void tst(const Register& rn, const Operand& operand);
// Bit clear (A & ~B).
void bic(const Register& rd,
const Register& rn,
const Operand& operand);
// Bit clear (A & ~B) and update status flags.
void bics(const Register& rd,
const Register& rn,
const Operand& operand);
// Bitwise or (A | B).
void orr(const Register& rd, const Register& rn, const Operand& operand);
// Bitwise nor (A | ~B).
void orn(const Register& rd, const Register& rn, const Operand& operand);
// Bitwise eor/xor (A ^ B).
void eor(const Register& rd, const Register& rn, const Operand& operand);
// Bitwise enor/xnor (A ^ ~B).
void eon(const Register& rd, const Register& rn, const Operand& operand);
// Logical shift left by variable.
void lslv(const Register& rd, const Register& rn, const Register& rm);
// Logical shift right by variable.
void lsrv(const Register& rd, const Register& rn, const Register& rm);
// Arithmetic shift right by variable.
void asrv(const Register& rd, const Register& rn, const Register& rm);
// Rotate right by variable.
void rorv(const Register& rd, const Register& rn, const Register& rm);
// Bitfield instructions.
// Bitfield move.
void bfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
// Signed bitfield move.
void sbfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
// Unsigned bitfield move.
void ubfm(const Register& rd,
const Register& rn,
unsigned immr,
unsigned imms);
// Bfm aliases.
// Bitfield insert.
void bfi(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
bfm(rd, rn, (rd.size() - lsb) & (rd.size() - 1), width - 1);
}
// Bitfield extract and insert low.
void bfxil(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
bfm(rd, rn, lsb, lsb + width - 1);
}
// Sbfm aliases.
// Arithmetic shift right.
void asr(const Register& rd, const Register& rn, unsigned shift) {
VIXL_ASSERT(shift < rd.size());
sbfm(rd, rn, shift, rd.size() - 1);
}
// Signed bitfield insert with zero at right.
void sbfiz(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
sbfm(rd, rn, (rd.size() - lsb) & (rd.size() - 1), width - 1);
}
// Signed bitfield extract.
void sbfx(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
sbfm(rd, rn, lsb, lsb + width - 1);
}
// Signed extend byte.
void sxtb(const Register& rd, const Register& rn) {
sbfm(rd, rn, 0, 7);
}
// Signed extend halfword.
void sxth(const Register& rd, const Register& rn) {
sbfm(rd, rn, 0, 15);
}
// Signed extend word.
void sxtw(const Register& rd, const Register& rn) {
sbfm(rd, rn, 0, 31);
}
// Ubfm aliases.
// Logical shift left.
void lsl(const Register& rd, const Register& rn, unsigned shift) {
unsigned reg_size = rd.size();
VIXL_ASSERT(shift < reg_size);
ubfm(rd, rn, (reg_size - shift) % reg_size, reg_size - shift - 1);
}
// Logical shift right.
void lsr(const Register& rd, const Register& rn, unsigned shift) {
VIXL_ASSERT(shift < rd.size());
ubfm(rd, rn, shift, rd.size() - 1);
}
// Unsigned bitfield insert with zero at right.
void ubfiz(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
ubfm(rd, rn, (rd.size() - lsb) & (rd.size() - 1), width - 1);
}
// Unsigned bitfield extract.
void ubfx(const Register& rd,
const Register& rn,
unsigned lsb,
unsigned width) {
VIXL_ASSERT(width >= 1);
VIXL_ASSERT(lsb + width <= rn.size());
ubfm(rd, rn, lsb, lsb + width - 1);
}
// Unsigned extend byte.
void uxtb(const Register& rd, const Register& rn) {
ubfm(rd, rn, 0, 7);
}
// Unsigned extend halfword.
void uxth(const Register& rd, const Register& rn) {
ubfm(rd, rn, 0, 15);
}
// Unsigned extend word.
void uxtw(const Register& rd, const Register& rn) {
ubfm(rd, rn, 0, 31);
}
// Extract.
void extr(const Register& rd,
const Register& rn,
const Register& rm,
unsigned lsb);
// Conditional select: rd = cond ? rn : rm.
void csel(const Register& rd,
const Register& rn,
const Register& rm,
Condition cond);
// Conditional select increment: rd = cond ? rn : rm + 1.
void csinc(const Register& rd,
const Register& rn,
const Register& rm,
Condition cond);
// Conditional select inversion: rd = cond ? rn : ~rm.
void csinv(const Register& rd,
const Register& rn,
const Register& rm,
Condition cond);
// Conditional select negation: rd = cond ? rn : -rm.
void csneg(const Register& rd,
const Register& rn,
const Register& rm,
Condition cond);
// Conditional set: rd = cond ? 1 : 0.
void cset(const Register& rd, Condition cond);
// Conditional set mask: rd = cond ? -1 : 0.
void csetm(const Register& rd, Condition cond);
// Conditional increment: rd = cond ? rn + 1 : rn.
void cinc(const Register& rd, const Register& rn, Condition cond);
// Conditional invert: rd = cond ? ~rn : rn.
void cinv(const Register& rd, const Register& rn, Condition cond);
// Conditional negate: rd = cond ? -rn : rn.
void cneg(const Register& rd, const Register& rn, Condition cond);
// Rotate right.
void ror(const Register& rd, const Register& rs, unsigned shift) {
extr(rd, rs, rs, shift);
}
// Conditional comparison.
// Conditional compare negative.
void ccmn(const Register& rn,
const Operand& operand,
StatusFlags nzcv,
Condition cond);
// Conditional compare.
void ccmp(const Register& rn,
const Operand& operand,
StatusFlags nzcv,
Condition cond);
// CRC-32 checksum from byte.
void crc32b(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 checksum from half-word.
void crc32h(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 checksum from word.
void crc32w(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 checksum from double word.
void crc32x(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 C checksum from byte.
void crc32cb(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 C checksum from half-word.
void crc32ch(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32 C checksum from word.
void crc32cw(const Register& rd,
const Register& rn,
const Register& rm);
// CRC-32C checksum from double word.
void crc32cx(const Register& rd,
const Register& rn,
const Register& rm);
// Multiply.
void mul(const Register& rd, const Register& rn, const Register& rm);
// Negated multiply.
void mneg(const Register& rd, const Register& rn, const Register& rm);
// Signed long multiply: 32 x 32 -> 64-bit.
void smull(const Register& rd, const Register& rn, const Register& rm);
// Signed multiply high: 64 x 64 -> 64-bit <127:64>.
void smulh(const Register& xd, const Register& xn, const Register& xm);
// Multiply and accumulate.
void madd(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Multiply and subtract.
void msub(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Signed long multiply and accumulate: 32 x 32 + 64 -> 64-bit.
void smaddl(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Unsigned long multiply and accumulate: 32 x 32 + 64 -> 64-bit.
void umaddl(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Unsigned long multiply: 32 x 32 -> 64-bit.
void umull(const Register& rd,
const Register& rn,
const Register& rm) {
umaddl(rd, rn, rm, xzr);
}
// Unsigned multiply high: 64 x 64 -> 64-bit <127:64>.
void umulh(const Register& xd,
const Register& xn,
const Register& xm);
// Signed long multiply and subtract: 64 - (32 x 32) -> 64-bit.
void smsubl(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Unsigned long multiply and subtract: 64 - (32 x 32) -> 64-bit.
void umsubl(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra);
// Signed integer divide.
void sdiv(const Register& rd, const Register& rn, const Register& rm);
// Unsigned integer divide.
void udiv(const Register& rd, const Register& rn, const Register& rm);
// Bit reverse.
void rbit(const Register& rd, const Register& rn);
// Reverse bytes in 16-bit half words.
void rev16(const Register& rd, const Register& rn);
// Reverse bytes in 32-bit words.
void rev32(const Register& rd, const Register& rn);
// Reverse bytes.
void rev(const Register& rd, const Register& rn);
// Count leading zeroes.
void clz(const Register& rd, const Register& rn);
// Count leading sign bits.
void cls(const Register& rd, const Register& rn);
// Memory instructions.
// Load integer or FP register.
void ldr(const CPURegister& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Store integer or FP register.
void str(const CPURegister& rt, const MemOperand& dst,
LoadStoreScalingOption option = PreferScaledOffset);
// Load word with sign extension.
void ldrsw(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Load byte.
void ldrb(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Store byte.
void strb(const Register& rt, const MemOperand& dst,
LoadStoreScalingOption option = PreferScaledOffset);
// Load byte with sign extension.
void ldrsb(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Load half-word.
void ldrh(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Store half-word.
void strh(const Register& rt, const MemOperand& dst,
LoadStoreScalingOption option = PreferScaledOffset);
// Load half-word with sign extension.
void ldrsh(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferScaledOffset);
// Load integer or FP register (with unscaled offset).
void ldur(const CPURegister& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Store integer or FP register (with unscaled offset).
void stur(const CPURegister& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load word with sign extension.
void ldursw(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load byte (with unscaled offset).
void ldurb(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Store byte (with unscaled offset).
void sturb(const Register& rt, const MemOperand& dst,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load byte with sign extension (and unscaled offset).
void ldursb(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load half-word (with unscaled offset).
void ldurh(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Store half-word (with unscaled offset).
void sturh(const Register& rt, const MemOperand& dst,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load half-word with sign extension (and unscaled offset).
void ldursh(const Register& rt, const MemOperand& src,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Load integer or FP register pair.
void ldp(const CPURegister& rt, const CPURegister& rt2,
const MemOperand& src);
// Store integer or FP register pair.
void stp(const CPURegister& rt, const CPURegister& rt2,
const MemOperand& dst);
// Load word pair with sign extension.
void ldpsw(const Register& rt, const Register& rt2, const MemOperand& src);
// Load integer or FP register pair, non-temporal.
void ldnp(const CPURegister& rt, const CPURegister& rt2,
const MemOperand& src);
// Store integer or FP register pair, non-temporal.
void stnp(const CPURegister& rt, const CPURegister& rt2,
const MemOperand& dst);
// Load integer or FP register from literal pool.
void ldr(const CPURegister& rt, RawLiteral* literal);
// Load word with sign extension from literal pool.
void ldrsw(const Register& rt, RawLiteral* literal);
// Load integer or FP register from pc + imm19 << 2.
void ldr(const CPURegister& rt, int imm19);
// Load word with sign extension from pc + imm19 << 2.
void ldrsw(const Register& rt, int imm19);
// Store exclusive byte.
void stxrb(const Register& rs, const Register& rt, const MemOperand& dst);
// Store exclusive half-word.
void stxrh(const Register& rs, const Register& rt, const MemOperand& dst);
// Store exclusive register.
void stxr(const Register& rs, const Register& rt, const MemOperand& dst);
// Load exclusive byte.
void ldxrb(const Register& rt, const MemOperand& src);
// Load exclusive half-word.
void ldxrh(const Register& rt, const MemOperand& src);
// Load exclusive register.
void ldxr(const Register& rt, const MemOperand& src);
// Store exclusive register pair.
void stxp(const Register& rs,
const Register& rt,
const Register& rt2,
const MemOperand& dst);
// Load exclusive register pair.
void ldxp(const Register& rt, const Register& rt2, const MemOperand& src);
// Store-release exclusive byte.
void stlxrb(const Register& rs, const Register& rt, const MemOperand& dst);
// Store-release exclusive half-word.
void stlxrh(const Register& rs, const Register& rt, const MemOperand& dst);
// Store-release exclusive register.
void stlxr(const Register& rs, const Register& rt, const MemOperand& dst);
// Load-acquire exclusive byte.
void ldaxrb(const Register& rt, const MemOperand& src);
// Load-acquire exclusive half-word.
void ldaxrh(const Register& rt, const MemOperand& src);
// Load-acquire exclusive register.
void ldaxr(const Register& rt, const MemOperand& src);
// Store-release exclusive register pair.
void stlxp(const Register& rs,
const Register& rt,
const Register& rt2,
const MemOperand& dst);
// Load-acquire exclusive register pair.
void ldaxp(const Register& rt, const Register& rt2, const MemOperand& src);
// Store-release byte.
void stlrb(const Register& rt, const MemOperand& dst);
// Store-release half-word.
void stlrh(const Register& rt, const MemOperand& dst);
// Store-release register.
void stlr(const Register& rt, const MemOperand& dst);
// Load-acquire byte.
void ldarb(const Register& rt, const MemOperand& src);
// Load-acquire half-word.
void ldarh(const Register& rt, const MemOperand& src);
// Load-acquire register.
void ldar(const Register& rt, const MemOperand& src);
// Prefetch memory.
void prfm(PrefetchOperation op, const MemOperand& addr,
LoadStoreScalingOption option = PreferScaledOffset);
// Prefetch memory (with unscaled offset).
void prfum(PrefetchOperation op, const MemOperand& addr,
LoadStoreScalingOption option = PreferUnscaledOffset);
// Prefetch memory in the literal pool.
void prfm(PrefetchOperation op, RawLiteral* literal);
// Prefetch from pc + imm19 << 2.
void prfm(PrefetchOperation op, int imm19);
// Move instructions. The default shift of -1 indicates that the move
// instruction will calculate an appropriate 16-bit immediate and left shift
// that is equal to the 64-bit immediate argument. If an explicit left shift
// is specified (0, 16, 32 or 48), the immediate must be a 16-bit value.
//
// For movk, an explicit shift can be used to indicate which half word should
// be overwritten, eg. movk(x0, 0, 0) will overwrite the least-significant
// half word with zero, whereas movk(x0, 0, 48) will overwrite the
// most-significant.
// Move immediate and keep.
void movk(const Register& rd, uint64_t imm, int shift = -1) {
MoveWide(rd, imm, shift, MOVK);
}
// Move inverted immediate.
void movn(const Register& rd, uint64_t imm, int shift = -1) {
MoveWide(rd, imm, shift, MOVN);
}
// Move immediate.
void movz(const Register& rd, uint64_t imm, int shift = -1) {
MoveWide(rd, imm, shift, MOVZ);
}
// Misc instructions.
// Monitor debug-mode breakpoint.
void brk(int code);
// Halting debug-mode breakpoint.
void hlt(int code);
// Generate exception targeting EL1.
void svc(int code);
// Move register to register.
void mov(const Register& rd, const Register& rn);
// Move inverted operand to register.
void mvn(const Register& rd, const Operand& operand);
// System instructions.
// Move to register from system register.
void mrs(const Register& rt, SystemRegister sysreg);
// Move from register to system register.
void msr(SystemRegister sysreg, const Register& rt);
// System instruction.
void sys(int op1, int crn, int crm, int op2, const Register& rt = xzr);
// System instruction with pre-encoded op (op1:crn:crm:op2).
void sys(int op, const Register& rt = xzr);
// System data cache operation.
void dc(DataCacheOp op, const Register& rt);
// System instruction cache operation.
void ic(InstructionCacheOp op, const Register& rt);
// System hint.
void hint(SystemHint code);
// Clear exclusive monitor.
void clrex(int imm4 = 0xf);
// Data memory barrier.
void dmb(BarrierDomain domain, BarrierType type);
// Data synchronization barrier.
void dsb(BarrierDomain domain, BarrierType type);
// Instruction synchronization barrier.
void isb();
// Alias for system instructions.
// No-op.
void nop() {
hint(NOP);
}
// FP and NEON instructions.
// Move double precision immediate to FP register.
void fmov(const VRegister& vd, double imm);
// Move single precision immediate to FP register.
void fmov(const VRegister& vd, float imm);
// Move FP register to register.
void fmov(const Register& rd, const VRegister& fn);
// Move register to FP register.
void fmov(const VRegister& vd, const Register& rn);
// Move FP register to FP register.
void fmov(const VRegister& vd, const VRegister& fn);
// Move 64-bit register to top half of 128-bit FP register.
void fmov(const VRegister& vd, int index, const Register& rn);
// Move top half of 128-bit FP register to 64-bit register.
void fmov(const Register& rd, const VRegister& vn, int index);
// FP add.
void fadd(const VRegister& vd, const VRegister& vn, const VRegister& vm);
// FP subtract.
void fsub(const VRegister& vd, const VRegister& vn, const VRegister& vm);
// FP multiply.
void fmul(const VRegister& vd, const VRegister& vn, const VRegister& vm);
// FP fused multiply-add.
void fmadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
const VRegister& va);
// FP fused multiply-subtract.
void fmsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
const VRegister& va);
// FP fused multiply-add and negate.
void fnmadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
const VRegister& va);
// FP fused multiply-subtract and negate.
void fnmsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
const VRegister& va);
// FP multiply-negate scalar.
void fnmul(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP reciprocal exponent scalar.
void frecpx(const VRegister& vd,
const VRegister& vn);
// FP divide.
void fdiv(const VRegister& vd, const VRegister& fn, const VRegister& vm);
// FP maximum.
void fmax(const VRegister& vd, const VRegister& fn, const VRegister& vm);
// FP minimum.
void fmin(const VRegister& vd, const VRegister& fn, const VRegister& vm);
// FP maximum number.
void fmaxnm(const VRegister& vd, const VRegister& fn, const VRegister& vm);
// FP minimum number.
void fminnm(const VRegister& vd, const VRegister& fn, const VRegister& vm);
// FP absolute.
void fabs(const VRegister& vd, const VRegister& vn);
// FP negate.
void fneg(const VRegister& vd, const VRegister& vn);
// FP square root.
void fsqrt(const VRegister& vd, const VRegister& vn);
// FP round to integer, nearest with ties to away.
void frinta(const VRegister& vd, const VRegister& vn);
// FP round to integer, implicit rounding.
void frinti(const VRegister& vd, const VRegister& vn);
// FP round to integer, toward minus infinity.
void frintm(const VRegister& vd, const VRegister& vn);
// FP round to integer, nearest with ties to even.
void frintn(const VRegister& vd, const VRegister& vn);
// FP round to integer, toward plus infinity.
void frintp(const VRegister& vd, const VRegister& vn);
// FP round to integer, exact, implicit rounding.
void frintx(const VRegister& vd, const VRegister& vn);
// FP round to integer, towards zero.
void frintz(const VRegister& vd, const VRegister& vn);
void FPCompareMacro(const VRegister& vn,
double value,
FPTrapFlags trap);
void FPCompareMacro(const VRegister& vn,
const VRegister& vm,
FPTrapFlags trap);
// FP compare registers.
void fcmp(const VRegister& vn, const VRegister& vm);
// FP compare immediate.
void fcmp(const VRegister& vn, double value);
void FPCCompareMacro(const VRegister& vn,
const VRegister& vm,
StatusFlags nzcv,
Condition cond,
FPTrapFlags trap);
// FP conditional compare.
void fccmp(const VRegister& vn,
const VRegister& vm,
StatusFlags nzcv,
Condition cond);
// FP signaling compare registers.
void fcmpe(const VRegister& vn, const VRegister& vm);
// FP signaling compare immediate.
void fcmpe(const VRegister& vn, double value);
// FP conditional signaling compare.
void fccmpe(const VRegister& vn,
const VRegister& vm,
StatusFlags nzcv,
Condition cond);
// FP conditional select.
void fcsel(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
Condition cond);
// Common FP Convert functions.
void NEONFPConvertToInt(const Register& rd,
const VRegister& vn,
Instr op);
void NEONFPConvertToInt(const VRegister& vd,
const VRegister& vn,
Instr op);
// FP convert between precisions.
void fcvt(const VRegister& vd, const VRegister& vn);
// FP convert to higher precision.
void fcvtl(const VRegister& vd, const VRegister& vn);
// FP convert to higher precision (second part).
void fcvtl2(const VRegister& vd, const VRegister& vn);
// FP convert to lower precision.
void fcvtn(const VRegister& vd, const VRegister& vn);
// FP convert to lower prevision (second part).
void fcvtn2(const VRegister& vd, const VRegister& vn);
// FP convert to lower precision, rounding to odd.
void fcvtxn(const VRegister& vd, const VRegister& vn);
// FP convert to lower precision, rounding to odd (second part).
void fcvtxn2(const VRegister& vd, const VRegister& vn);
// FP convert to signed integer, nearest with ties to away.
void fcvtas(const Register& rd, const VRegister& vn);
// FP convert to unsigned integer, nearest with ties to away.
void fcvtau(const Register& rd, const VRegister& vn);
// FP convert to signed integer, nearest with ties to away.
void fcvtas(const VRegister& vd, const VRegister& vn);
// FP convert to unsigned integer, nearest with ties to away.
void fcvtau(const VRegister& vd, const VRegister& vn);
// FP convert to signed integer, round towards -infinity.
void fcvtms(const Register& rd, const VRegister& vn);
// FP convert to unsigned integer, round towards -infinity.
void fcvtmu(const Register& rd, const VRegister& vn);
// FP convert to signed integer, round towards -infinity.
void fcvtms(const VRegister& vd, const VRegister& vn);
// FP convert to unsigned integer, round towards -infinity.
void fcvtmu(const VRegister& vd, const VRegister& vn);
// FP convert to signed integer, nearest with ties to even.
void fcvtns(const Register& rd, const VRegister& vn);
// FP convert to unsigned integer, nearest with ties to even.
void fcvtnu(const Register& rd, const VRegister& vn);
// FP convert to signed integer, nearest with ties to even.
void fcvtns(const VRegister& rd, const VRegister& vn);
// FP convert to unsigned integer, nearest with ties to even.
void fcvtnu(const VRegister& rd, const VRegister& vn);
// FP convert to signed integer or fixed-point, round towards zero.
void fcvtzs(const Register& rd, const VRegister& vn, int fbits = 0);
// FP convert to unsigned integer or fixed-point, round towards zero.
void fcvtzu(const Register& rd, const VRegister& vn, int fbits = 0);
// FP convert to signed integer or fixed-point, round towards zero.
void fcvtzs(const VRegister& vd, const VRegister& vn, int fbits = 0);
// FP convert to unsigned integer or fixed-point, round towards zero.
void fcvtzu(const VRegister& vd, const VRegister& vn, int fbits = 0);
// FP convert to signed integer, round towards +infinity.
void fcvtps(const Register& rd, const VRegister& vn);
// FP convert to unsigned integer, round towards +infinity.
void fcvtpu(const Register& rd, const VRegister& vn);
// FP convert to signed integer, round towards +infinity.
void fcvtps(const VRegister& vd, const VRegister& vn);
// FP convert to unsigned integer, round towards +infinity.
void fcvtpu(const VRegister& vd, const VRegister& vn);
// Convert signed integer or fixed point to FP.
void scvtf(const VRegister& fd, const Register& rn, int fbits = 0);
// Convert unsigned integer or fixed point to FP.
void ucvtf(const VRegister& fd, const Register& rn, int fbits = 0);
// Convert signed integer or fixed-point to FP.
void scvtf(const VRegister& fd, const VRegister& vn, int fbits = 0);
// Convert unsigned integer or fixed-point to FP.
void ucvtf(const VRegister& fd, const VRegister& vn, int fbits = 0);
// Unsigned absolute difference.
void uabd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference.
void sabd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned absolute difference and accumulate.
void uaba(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference and accumulate.
void saba(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add.
void add(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Subtract.
void sub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned halving add.
void uhadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed halving add.
void shadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned rounding halving add.
void urhadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed rounding halving add.
void srhadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned halving sub.
void uhsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed halving sub.
void shsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned saturating add.
void uqadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating add.
void sqadd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned saturating subtract.
void uqsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating subtract.
void sqsub(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add pairwise.
void addp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add pair of elements scalar.
void addp(const VRegister& vd,
const VRegister& vn);
// Multiply-add to accumulator.
void mla(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Multiply-subtract to accumulator.
void mls(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Multiply.
void mul(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Multiply by scalar element.
void mul(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Multiply-add by scalar element.
void mla(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Multiply-subtract by scalar element.
void mls(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply-add by scalar element.
void smlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply-add by scalar element (second part).
void smlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply-add by scalar element.
void umlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply-add by scalar element (second part).
void umlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply-sub by scalar element.
void smlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply-sub by scalar element (second part).
void smlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply-sub by scalar element.
void umlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply-sub by scalar element (second part).
void umlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply by scalar element.
void smull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed long multiply by scalar element (second part).
void smull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply by scalar element.
void umull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply by scalar element (second part).
void umull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating double long multiply by element.
void sqdmull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating double long multiply by element (second part).
void sqdmull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating doubling long multiply-add by element.
void sqdmlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating doubling long multiply-add by element (second part).
void sqdmlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating doubling long multiply-sub by element.
void sqdmlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating doubling long multiply-sub by element (second part).
void sqdmlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Compare equal.
void cmeq(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare signed greater than or equal.
void cmge(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare signed greater than.
void cmgt(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare unsigned higher.
void cmhi(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare unsigned higher or same.
void cmhs(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare bitwise test bits nonzero.
void cmtst(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Compare bitwise to zero.
void cmeq(const VRegister& vd,
const VRegister& vn,
int value);
// Compare signed greater than or equal to zero.
void cmge(const VRegister& vd,
const VRegister& vn,
int value);
// Compare signed greater than zero.
void cmgt(const VRegister& vd,
const VRegister& vn,
int value);
// Compare signed less than or equal to zero.
void cmle(const VRegister& vd,
const VRegister& vn,
int value);
// Compare signed less than zero.
void cmlt(const VRegister& vd,
const VRegister& vn,
int value);
// Signed shift left by register.
void sshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned shift left by register.
void ushl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating shift left by register.
void sqshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned saturating shift left by register.
void uqshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed rounding shift left by register.
void srshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned rounding shift left by register.
void urshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating rounding shift left by register.
void sqrshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned saturating rounding shift left by register.
void uqrshl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise and.
void and_(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise or.
void orr(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise or immediate.
void orr(const VRegister& vd,
const int imm8,
const int left_shift = 0);
// Move register to register.
void mov(const VRegister& vd,
const VRegister& vn);
// Bitwise orn.
void orn(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise eor.
void eor(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bit clear immediate.
void bic(const VRegister& vd,
const int imm8,
const int left_shift = 0);
// Bit clear.
void bic(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise insert if false.
void bif(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise insert if true.
void bit(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Bitwise select.
void bsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Polynomial multiply.
void pmul(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Vector move immediate.
void movi(const VRegister& vd,
const uint64_t imm,
Shift shift = LSL,
const int shift_amount = 0);
// Bitwise not.
void mvn(const VRegister& vd,
const VRegister& vn);
// Vector move inverted immediate.
void mvni(const VRegister& vd,
const int imm8,
Shift shift = LSL,
const int shift_amount = 0);
// Signed saturating accumulate of unsigned value.
void suqadd(const VRegister& vd,
const VRegister& vn);
// Unsigned saturating accumulate of signed value.
void usqadd(const VRegister& vd,
const VRegister& vn);
// Absolute value.
void abs(const VRegister& vd,
const VRegister& vn);
// Signed saturating absolute value.
void sqabs(const VRegister& vd,
const VRegister& vn);
// Negate.
void neg(const VRegister& vd,
const VRegister& vn);
// Signed saturating negate.
void sqneg(const VRegister& vd,
const VRegister& vn);
// Bitwise not.
void not_(const VRegister& vd,
const VRegister& vn);
// Extract narrow.
void xtn(const VRegister& vd,
const VRegister& vn);
// Extract narrow (second part).
void xtn2(const VRegister& vd,
const VRegister& vn);
// Signed saturating extract narrow.
void sqxtn(const VRegister& vd,
const VRegister& vn);
// Signed saturating extract narrow (second part).
void sqxtn2(const VRegister& vd,
const VRegister& vn);
// Unsigned saturating extract narrow.
void uqxtn(const VRegister& vd,
const VRegister& vn);
// Unsigned saturating extract narrow (second part).
void uqxtn2(const VRegister& vd,
const VRegister& vn);
// Signed saturating extract unsigned narrow.
void sqxtun(const VRegister& vd,
const VRegister& vn);
// Signed saturating extract unsigned narrow (second part).
void sqxtun2(const VRegister& vd,
const VRegister& vn);
// Extract vector from pair of vectors.
void ext(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int index);
// Duplicate vector element to vector or scalar.
void dup(const VRegister& vd,
const VRegister& vn,
int vn_index);
// Move vector element to scalar.
void mov(const VRegister& vd,
const VRegister& vn,
int vn_index);
// Duplicate general-purpose register to vector.
void dup(const VRegister& vd,
const Register& rn);
// Insert vector element from another vector element.
void ins(const VRegister& vd,
int vd_index,
const VRegister& vn,
int vn_index);
// Move vector element to another vector element.
void mov(const VRegister& vd,
int vd_index,
const VRegister& vn,
int vn_index);
// Insert vector element from general-purpose register.
void ins(const VRegister& vd,
int vd_index,
const Register& rn);
// Move general-purpose register to a vector element.
void mov(const VRegister& vd,
int vd_index,
const Register& rn);
// Unsigned move vector element to general-purpose register.
void umov(const Register& rd,
const VRegister& vn,
int vn_index);
// Move vector element to general-purpose register.
void mov(const Register& rd,
const VRegister& vn,
int vn_index);
// Signed move vector element to general-purpose register.
void smov(const Register& rd,
const VRegister& vn,
int vn_index);
// One-element structure load to one register.
void ld1(const VRegister& vt,
const MemOperand& src);
// One-element structure load to two registers.
void ld1(const VRegister& vt,
const VRegister& vt2,
const MemOperand& src);
// One-element structure load to three registers.
void ld1(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const MemOperand& src);
// One-element structure load to four registers.
void ld1(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
const MemOperand& src);
// One-element single structure load to one lane.
void ld1(const VRegister& vt,
int lane,
const MemOperand& src);
// One-element single structure load to all lanes.
void ld1r(const VRegister& vt,
const MemOperand& src);
// Two-element structure load.
void ld2(const VRegister& vt,
const VRegister& vt2,
const MemOperand& src);
// Two-element single structure load to one lane.
void ld2(const VRegister& vt,
const VRegister& vt2,
int lane,
const MemOperand& src);
// Two-element single structure load to all lanes.
void ld2r(const VRegister& vt,
const VRegister& vt2,
const MemOperand& src);
// Three-element structure load.
void ld3(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const MemOperand& src);
// Three-element single structure load to one lane.
void ld3(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
int lane,
const MemOperand& src);
// Three-element single structure load to all lanes.
void ld3r(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const MemOperand& src);
// Four-element structure load.
void ld4(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
const MemOperand& src);
// Four-element single structure load to one lane.
void ld4(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
int lane,
const MemOperand& src);
// Four-element single structure load to all lanes.
void ld4r(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
const MemOperand& src);
// Count leading sign bits.
void cls(const VRegister& vd,
const VRegister& vn);
// Count leading zero bits (vector).
void clz(const VRegister& vd,
const VRegister& vn);
// Population count per byte.
void cnt(const VRegister& vd,
const VRegister& vn);
// Reverse bit order.
void rbit(const VRegister& vd,
const VRegister& vn);
// Reverse elements in 16-bit halfwords.
void rev16(const VRegister& vd,
const VRegister& vn);
// Reverse elements in 32-bit words.
void rev32(const VRegister& vd,
const VRegister& vn);
// Reverse elements in 64-bit doublewords.
void rev64(const VRegister& vd,
const VRegister& vn);
// Unsigned reciprocal square root estimate.
void ursqrte(const VRegister& vd,
const VRegister& vn);
// Unsigned reciprocal estimate.
void urecpe(const VRegister& vd,
const VRegister& vn);
// Signed pairwise long add.
void saddlp(const VRegister& vd,
const VRegister& vn);
// Unsigned pairwise long add.
void uaddlp(const VRegister& vd,
const VRegister& vn);
// Signed pairwise long add and accumulate.
void sadalp(const VRegister& vd,
const VRegister& vn);
// Unsigned pairwise long add and accumulate.
void uadalp(const VRegister& vd,
const VRegister& vn);
// Shift left by immediate.
void shl(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift left by immediate.
void sqshl(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift left unsigned by immediate.
void sqshlu(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned saturating shift left by immediate.
void uqshl(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed shift left long by immediate.
void sshll(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed shift left long by immediate (second part).
void sshll2(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed extend long.
void sxtl(const VRegister& vd,
const VRegister& vn);
// Signed extend long (second part).
void sxtl2(const VRegister& vd,
const VRegister& vn);
// Unsigned shift left long by immediate.
void ushll(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned shift left long by immediate (second part).
void ushll2(const VRegister& vd,
const VRegister& vn,
int shift);
// Shift left long by element size.
void shll(const VRegister& vd,
const VRegister& vn,
int shift);
// Shift left long by element size (second part).
void shll2(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned extend long.
void uxtl(const VRegister& vd,
const VRegister& vn);
// Unsigned extend long (second part).
void uxtl2(const VRegister& vd,
const VRegister& vn);
// Shift left by immediate and insert.
void sli(const VRegister& vd,
const VRegister& vn,
int shift);
// Shift right by immediate and insert.
void sri(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed maximum.
void smax(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed pairwise maximum.
void smaxp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add across vector.
void addv(const VRegister& vd,
const VRegister& vn);
// Signed add long across vector.
void saddlv(const VRegister& vd,
const VRegister& vn);
// Unsigned add long across vector.
void uaddlv(const VRegister& vd,
const VRegister& vn);
// FP maximum number across vector.
void fmaxnmv(const VRegister& vd,
const VRegister& vn);
// FP maximum across vector.
void fmaxv(const VRegister& vd,
const VRegister& vn);
// FP minimum number across vector.
void fminnmv(const VRegister& vd,
const VRegister& vn);
// FP minimum across vector.
void fminv(const VRegister& vd,
const VRegister& vn);
// Signed maximum across vector.
void smaxv(const VRegister& vd,
const VRegister& vn);
// Signed minimum.
void smin(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed minimum pairwise.
void sminp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed minimum across vector.
void sminv(const VRegister& vd,
const VRegister& vn);
// One-element structure store from one register.
void st1(const VRegister& vt,
const MemOperand& src);
// One-element structure store from two registers.
void st1(const VRegister& vt,
const VRegister& vt2,
const MemOperand& src);
// One-element structure store from three registers.
void st1(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const MemOperand& src);
// One-element structure store from four registers.
void st1(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
const MemOperand& src);
// One-element single structure store from one lane.
void st1(const VRegister& vt,
int lane,
const MemOperand& src);
// Two-element structure store from two registers.
void st2(const VRegister& vt,
const VRegister& vt2,
const MemOperand& src);
// Two-element single structure store from two lanes.
void st2(const VRegister& vt,
const VRegister& vt2,
int lane,
const MemOperand& src);
// Three-element structure store from three registers.
void st3(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const MemOperand& src);
// Three-element single structure store from three lanes.
void st3(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
int lane,
const MemOperand& src);
// Four-element structure store from four registers.
void st4(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
const MemOperand& src);
// Four-element single structure store from four lanes.
void st4(const VRegister& vt,
const VRegister& vt2,
const VRegister& vt3,
const VRegister& vt4,
int lane,
const MemOperand& src);
// Unsigned add long.
void uaddl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned add long (second part).
void uaddl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned add wide.
void uaddw(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned add wide (second part).
void uaddw2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed add long.
void saddl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed add long (second part).
void saddl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed add wide.
void saddw(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed add wide (second part).
void saddw2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned subtract long.
void usubl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned subtract long (second part).
void usubl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned subtract wide.
void usubw(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned subtract wide (second part).
void usubw2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed subtract long.
void ssubl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed subtract long (second part).
void ssubl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed integer subtract wide.
void ssubw(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed integer subtract wide (second part).
void ssubw2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned maximum.
void umax(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned pairwise maximum.
void umaxp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned maximum across vector.
void umaxv(const VRegister& vd,
const VRegister& vn);
// Unsigned minimum.
void umin(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned pairwise minimum.
void uminp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned minimum across vector.
void uminv(const VRegister& vd,
const VRegister& vn);
// Transpose vectors (primary).
void trn1(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Transpose vectors (secondary).
void trn2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unzip vectors (primary).
void uzp1(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unzip vectors (secondary).
void uzp2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Zip vectors (primary).
void zip1(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Zip vectors (secondary).
void zip2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed shift right by immediate.
void sshr(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned shift right by immediate.
void ushr(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed rounding shift right by immediate.
void srshr(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned rounding shift right by immediate.
void urshr(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed shift right by immediate and accumulate.
void ssra(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned shift right by immediate and accumulate.
void usra(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed rounding shift right by immediate and accumulate.
void srsra(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned rounding shift right by immediate and accumulate.
void ursra(const VRegister& vd,
const VRegister& vn,
int shift);
// Shift right narrow by immediate.
void shrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Shift right narrow by immediate (second part).
void shrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Rounding shift right narrow by immediate.
void rshrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Rounding shift right narrow by immediate (second part).
void rshrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned saturating shift right narrow by immediate.
void uqshrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned saturating shift right narrow by immediate (second part).
void uqshrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned saturating rounding shift right narrow by immediate.
void uqrshrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Unsigned saturating rounding shift right narrow by immediate (second part).
void uqrshrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift right narrow by immediate.
void sqshrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift right narrow by immediate (second part).
void sqshrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating rounded shift right narrow by immediate.
void sqrshrn(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating rounded shift right narrow by immediate (second part).
void sqrshrn2(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift right unsigned narrow by immediate.
void sqshrun(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed saturating shift right unsigned narrow by immediate (second part).
void sqshrun2(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed sat rounded shift right unsigned narrow by immediate.
void sqrshrun(const VRegister& vd,
const VRegister& vn,
int shift);
// Signed sat rounded shift right unsigned narrow by immediate (second part).
void sqrshrun2(const VRegister& vd,
const VRegister& vn,
int shift);
// FP reciprocal step.
void frecps(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP reciprocal estimate.
void frecpe(const VRegister& vd,
const VRegister& vn);
// FP reciprocal square root estimate.
void frsqrte(const VRegister& vd,
const VRegister& vn);
// FP reciprocal square root step.
void frsqrts(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference and accumulate long.
void sabal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference and accumulate long (second part).
void sabal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned absolute difference and accumulate long.
void uabal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned absolute difference and accumulate long (second part).
void uabal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference long.
void sabdl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed absolute difference long (second part).
void sabdl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned absolute difference long.
void uabdl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned absolute difference long (second part).
void uabdl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Polynomial multiply long.
void pmull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Polynomial multiply long (second part).
void pmull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply-add.
void smlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply-add (second part).
void smlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned long multiply-add.
void umlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned long multiply-add (second part).
void umlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply-sub.
void smlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply-sub (second part).
void smlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned long multiply-sub.
void umlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned long multiply-sub (second part).
void umlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply.
void smull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed long multiply (second part).
void smull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply-add.
void sqdmlal(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply-add (second part).
void sqdmlal2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply-subtract.
void sqdmlsl(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply-subtract (second part).
void sqdmlsl2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply.
void sqdmull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling long multiply (second part).
void sqdmull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling multiply returning high half.
void sqdmulh(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating rounding doubling multiply returning high half.
void sqrdmulh(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Signed saturating doubling multiply element returning high half.
void sqdmulh(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Signed saturating rounding doubling multiply element returning high half.
void sqrdmulh(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// Unsigned long multiply long.
void umull(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Unsigned long multiply (second part).
void umull2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add narrow returning high half.
void addhn(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Add narrow returning high half (second part).
void addhn2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Rounding add narrow returning high half.
void raddhn(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Rounding add narrow returning high half (second part).
void raddhn2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Subtract narrow returning high half.
void subhn(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Subtract narrow returning high half (second part).
void subhn2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Rounding subtract narrow returning high half.
void rsubhn(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// Rounding subtract narrow returning high half (second part).
void rsubhn2(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP vector multiply accumulate.
void fmla(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP vector multiply subtract.
void fmls(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP vector multiply extended.
void fmulx(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP absolute greater than or equal.
void facge(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP absolute greater than.
void facgt(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP multiply by element.
void fmul(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// FP fused multiply-add to accumulator by element.
void fmla(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// FP fused multiply-sub from accumulator by element.
void fmls(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// FP multiply extended by element.
void fmulx(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index);
// FP compare equal.
void fcmeq(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP greater than.
void fcmgt(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP greater than or equal.
void fcmge(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP compare equal to zero.
void fcmeq(const VRegister& vd,
const VRegister& vn,
double imm);
// FP greater than zero.
void fcmgt(const VRegister& vd,
const VRegister& vn,
double imm);
// FP greater than or equal to zero.
void fcmge(const VRegister& vd,
const VRegister& vn,
double imm);
// FP less than or equal to zero.
void fcmle(const VRegister& vd,
const VRegister& vn,
double imm);
// FP less than to zero.
void fcmlt(const VRegister& vd,
const VRegister& vn,
double imm);
// FP absolute difference.
void fabd(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise add vector.
void faddp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise add scalar.
void faddp(const VRegister& vd,
const VRegister& vn);
// FP pairwise maximum vector.
void fmaxp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise maximum scalar.
void fmaxp(const VRegister& vd,
const VRegister& vn);
// FP pairwise minimum vector.
void fminp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise minimum scalar.
void fminp(const VRegister& vd,
const VRegister& vn);
// FP pairwise maximum number vector.
void fmaxnmp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise maximum number scalar.
void fmaxnmp(const VRegister& vd,
const VRegister& vn);
// FP pairwise minimum number vector.
void fminnmp(const VRegister& vd,
const VRegister& vn,
const VRegister& vm);
// FP pairwise minimum number scalar.
void fminnmp(const VRegister& vd,
const VRegister& vn);
// Emit generic instructions.
// Emit raw instructions into the instruction stream.
void dci(Instr raw_inst) { Emit(raw_inst); }
// Emit 32 bits of data into the instruction stream.
void dc32(uint32_t data) {
VIXL_ASSERT(buffer_monitor_ > 0);
buffer_->Emit32(data);
}
// Emit 64 bits of data into the instruction stream.
void dc64(uint64_t data) {
VIXL_ASSERT(buffer_monitor_ > 0);
buffer_->Emit64(data);
}
// Copy a string into the instruction stream, including the terminating NULL
// character. The instruction pointer is then aligned correctly for
// subsequent instructions.
void EmitString(const char * string) {
VIXL_ASSERT(string != NULL);
VIXL_ASSERT(buffer_monitor_ > 0);
buffer_->EmitString(string);
buffer_->Align();
}
// Code generation helpers.
// Register encoding.
static Instr Rd(CPURegister rd) {
VIXL_ASSERT(rd.code() != kSPRegInternalCode);
return rd.code() << Rd_offset;
}
static Instr Rn(CPURegister rn) {
VIXL_ASSERT(rn.code() != kSPRegInternalCode);
return rn.code() << Rn_offset;
}
static Instr Rm(CPURegister rm) {
VIXL_ASSERT(rm.code() != kSPRegInternalCode);
return rm.code() << Rm_offset;
}
static Instr RmNot31(CPURegister rm) {
VIXL_ASSERT(rm.code() != kSPRegInternalCode);
VIXL_ASSERT(!rm.IsZero());
return Rm(rm);
}
static Instr Ra(CPURegister ra) {
VIXL_ASSERT(ra.code() != kSPRegInternalCode);
return ra.code() << Ra_offset;
}
static Instr Rt(CPURegister rt) {
VIXL_ASSERT(rt.code() != kSPRegInternalCode);
return rt.code() << Rt_offset;
}
static Instr Rt2(CPURegister rt2) {
VIXL_ASSERT(rt2.code() != kSPRegInternalCode);
return rt2.code() << Rt2_offset;
}
static Instr Rs(CPURegister rs) {
VIXL_ASSERT(rs.code() != kSPRegInternalCode);
return rs.code() << Rs_offset;
}
// These encoding functions allow the stack pointer to be encoded, and
// disallow the zero register.
static Instr RdSP(Register rd) {
VIXL_ASSERT(!rd.IsZero());
return (rd.code() & kRegCodeMask) << Rd_offset;
}
static Instr RnSP(Register rn) {
VIXL_ASSERT(!rn.IsZero());
return (rn.code() & kRegCodeMask) << Rn_offset;
}
// Flags encoding.
static Instr Flags(FlagsUpdate S) {
if (S == SetFlags) {
return 1 << FlagsUpdate_offset;
} else if (S == LeaveFlags) {
return 0 << FlagsUpdate_offset;
}
VIXL_UNREACHABLE();
return 0;
}
static Instr Cond(Condition cond) {
return cond << Condition_offset;
}
// PC-relative address encoding.
static Instr ImmPCRelAddress(int imm21) {
VIXL_ASSERT(is_int21(imm21));
Instr imm = static_cast<Instr>(truncate_to_int21(imm21));
Instr immhi = (imm >> ImmPCRelLo_width) << ImmPCRelHi_offset;
Instr immlo = imm << ImmPCRelLo_offset;
return (immhi & ImmPCRelHi_mask) | (immlo & ImmPCRelLo_mask);
}
// Branch encoding.
static Instr ImmUncondBranch(int imm26) {
VIXL_ASSERT(is_int26(imm26));
return truncate_to_int26(imm26) << ImmUncondBranch_offset;
}
static Instr ImmCondBranch(int imm19) {
VIXL_ASSERT(is_int19(imm19));
return truncate_to_int19(imm19) << ImmCondBranch_offset;
}
static Instr ImmCmpBranch(int imm19) {
VIXL_ASSERT(is_int19(imm19));
return truncate_to_int19(imm19) << ImmCmpBranch_offset;
}
static Instr ImmTestBranch(int imm14) {
VIXL_ASSERT(is_int14(imm14));
return truncate_to_int14(imm14) << ImmTestBranch_offset;
}
static Instr ImmTestBranchBit(unsigned bit_pos) {
VIXL_ASSERT(is_uint6(bit_pos));
// Subtract five from the shift offset, as we need bit 5 from bit_pos.
unsigned b5 = bit_pos << (ImmTestBranchBit5_offset - 5);
unsigned b40 = bit_pos << ImmTestBranchBit40_offset;
b5 &= ImmTestBranchBit5_mask;
b40 &= ImmTestBranchBit40_mask;
return b5 | b40;
}
// Data Processing encoding.
static Instr SF(Register rd) {
return rd.Is64Bits() ? SixtyFourBits : ThirtyTwoBits;
}
static Instr ImmAddSub(int imm) {
VIXL_ASSERT(IsImmAddSub(imm));
if (is_uint12(imm)) { // No shift required.
imm <<= ImmAddSub_offset;
} else {
imm = ((imm >> 12) << ImmAddSub_offset) | (1 << ShiftAddSub_offset);
}
return imm;
}
static Instr ImmS(unsigned imms, unsigned reg_size) {
VIXL_ASSERT(((reg_size == kXRegSize) && is_uint6(imms)) ||
((reg_size == kWRegSize) && is_uint5(imms)));
USE(reg_size);
return imms << ImmS_offset;
}
static Instr ImmR(unsigned immr, unsigned reg_size) {
VIXL_ASSERT(((reg_size == kXRegSize) && is_uint6(immr)) ||
((reg_size == kWRegSize) && is_uint5(immr)));
USE(reg_size);
VIXL_ASSERT(is_uint6(immr));
return immr << ImmR_offset;
}
static Instr ImmSetBits(unsigned imms, unsigned reg_size) {
VIXL_ASSERT((reg_size == kWRegSize) || (reg_size == kXRegSize));
VIXL_ASSERT(is_uint6(imms));
VIXL_ASSERT((reg_size == kXRegSize) || is_uint6(imms + 3));
USE(reg_size);
return imms << ImmSetBits_offset;
}
static Instr ImmRotate(unsigned immr, unsigned reg_size) {
VIXL_ASSERT((reg_size == kWRegSize) || (reg_size == kXRegSize));
VIXL_ASSERT(((reg_size == kXRegSize) && is_uint6(immr)) ||
((reg_size == kWRegSize) && is_uint5(immr)));
USE(reg_size);
return immr << ImmRotate_offset;
}
static Instr ImmLLiteral(int imm19) {
VIXL_ASSERT(is_int19(imm19));
return truncate_to_int19(imm19) << ImmLLiteral_offset;
}
static Instr BitN(unsigned bitn, unsigned reg_size) {
VIXL_ASSERT((reg_size == kWRegSize) || (reg_size == kXRegSize));
VIXL_ASSERT((reg_size == kXRegSize) || (bitn == 0));
USE(reg_size);
return bitn << BitN_offset;
}
static Instr ShiftDP(Shift shift) {
VIXL_ASSERT(shift == LSL || shift == LSR || shift == ASR || shift == ROR);
return shift << ShiftDP_offset;
}
static Instr ImmDPShift(unsigned amount) {
VIXL_ASSERT(is_uint6(amount));
return amount << ImmDPShift_offset;
}
static Instr ExtendMode(Extend extend) {
return extend << ExtendMode_offset;
}
static Instr ImmExtendShift(unsigned left_shift) {
VIXL_ASSERT(left_shift <= 4);
return left_shift << ImmExtendShift_offset;
}
static Instr ImmCondCmp(unsigned imm) {
VIXL_ASSERT(is_uint5(imm));
return imm << ImmCondCmp_offset;
}
static Instr Nzcv(StatusFlags nzcv) {
return ((nzcv >> Flags_offset) & 0xf) << Nzcv_offset;
}
// MemOperand offset encoding.
static Instr ImmLSUnsigned(int imm12) {
VIXL_ASSERT(is_uint12(imm12));
return imm12 << ImmLSUnsigned_offset;
}
static Instr ImmLS(int imm9) {
VIXL_ASSERT(is_int9(imm9));
return truncate_to_int9(imm9) << ImmLS_offset;
}
static Instr ImmLSPair(int imm7, unsigned access_size) {
VIXL_ASSERT(((imm7 >> access_size) << access_size) == imm7);
int scaled_imm7 = imm7 >> access_size;
VIXL_ASSERT(is_int7(scaled_imm7));
return truncate_to_int7(scaled_imm7) << ImmLSPair_offset;
}
static Instr ImmShiftLS(unsigned shift_amount) {
VIXL_ASSERT(is_uint1(shift_amount));
return shift_amount << ImmShiftLS_offset;
}
static Instr ImmPrefetchOperation(int imm5) {
VIXL_ASSERT(is_uint5(imm5));
return imm5 << ImmPrefetchOperation_offset;
}
static Instr ImmException(int imm16) {
VIXL_ASSERT(is_uint16(imm16));
return imm16 << ImmException_offset;
}
static Instr ImmSystemRegister(int imm15) {
VIXL_ASSERT(is_uint15(imm15));
return imm15 << ImmSystemRegister_offset;
}
static Instr ImmHint(int imm7) {
VIXL_ASSERT(is_uint7(imm7));
return imm7 << ImmHint_offset;
}
static Instr CRm(int imm4) {
VIXL_ASSERT(is_uint4(imm4));
return imm4 << CRm_offset;
}
static Instr CRn(int imm4) {
VIXL_ASSERT(is_uint4(imm4));
return imm4 << CRn_offset;
}
static Instr SysOp(int imm14) {
VIXL_ASSERT(is_uint14(imm14));
return imm14 << SysOp_offset;
}
static Instr ImmSysOp1(int imm3) {
VIXL_ASSERT(is_uint3(imm3));
return imm3 << SysOp1_offset;
}
static Instr ImmSysOp2(int imm3) {
VIXL_ASSERT(is_uint3(imm3));
return imm3 << SysOp2_offset;
}
static Instr ImmBarrierDomain(int imm2) {
VIXL_ASSERT(is_uint2(imm2));
return imm2 << ImmBarrierDomain_offset;
}
static Instr ImmBarrierType(int imm2) {
VIXL_ASSERT(is_uint2(imm2));
return imm2 << ImmBarrierType_offset;
}
// Move immediates encoding.
static Instr ImmMoveWide(uint64_t imm) {
VIXL_ASSERT(is_uint16(imm));
return static_cast<Instr>(imm << ImmMoveWide_offset);
}
static Instr ShiftMoveWide(int64_t shift) {
VIXL_ASSERT(is_uint2(shift));
return static_cast<Instr>(shift << ShiftMoveWide_offset);
}
// FP Immediates.
static Instr ImmFP32(float imm);
static Instr ImmFP64(double imm);
// FP register type.
static Instr FPType(FPRegister fd) {
return fd.Is64Bits() ? FP64 : FP32;
}
static Instr FPScale(unsigned scale) {
VIXL_ASSERT(is_uint6(scale));
return scale << FPScale_offset;
}
// Immediate field checking helpers.
static bool IsImmAddSub(int64_t immediate);
static bool IsImmConditionalCompare(int64_t immediate);
static bool IsImmFP32(float imm);
static bool IsImmFP64(double imm);
static bool IsImmLogical(uint64_t value,
unsigned width,
unsigned* n = NULL,
unsigned* imm_s = NULL,
unsigned* imm_r = NULL);
static bool IsImmLSPair(int64_t offset, unsigned access_size);
static bool IsImmLSScaled(int64_t offset, unsigned access_size);
static bool IsImmLSUnscaled(int64_t offset);
static bool IsImmMovn(uint64_t imm, unsigned reg_size);
static bool IsImmMovz(uint64_t imm, unsigned reg_size);
// Instruction bits for vector format in data processing operations.
static Instr VFormat(VRegister vd) {
if (vd.Is64Bits()) {
switch (vd.lanes()) {
case 2: return NEON_2S;
case 4: return NEON_4H;
case 8: return NEON_8B;
default: return 0xffffffff;
}
} else {
VIXL_ASSERT(vd.Is128Bits());
switch (vd.lanes()) {
case 2: return NEON_2D;
case 4: return NEON_4S;
case 8: return NEON_8H;
case 16: return NEON_16B;
default: return 0xffffffff;
}
}
}
// Instruction bits for vector format in floating point data processing
// operations.
static Instr FPFormat(VRegister vd) {
if (vd.lanes() == 1) {
// Floating point scalar formats.
VIXL_ASSERT(vd.Is32Bits() || vd.Is64Bits());
return vd.Is64Bits() ? FP64 : FP32;
}
// Two lane floating point vector formats.
if (vd.lanes() == 2) {
VIXL_ASSERT(vd.Is64Bits() || vd.Is128Bits());
return vd.Is128Bits() ? NEON_FP_2D : NEON_FP_2S;
}
// Four lane floating point vector format.
VIXL_ASSERT((vd.lanes() == 4) && vd.Is128Bits());
return NEON_FP_4S;
}
// Instruction bits for vector format in load and store operations.
static Instr LSVFormat(VRegister vd) {
if (vd.Is64Bits()) {
switch (vd.lanes()) {
case 1: return LS_NEON_1D;
case 2: return LS_NEON_2S;
case 4: return LS_NEON_4H;
case 8: return LS_NEON_8B;
default: return 0xffffffff;
}
} else {
VIXL_ASSERT(vd.Is128Bits());
switch (vd.lanes()) {
case 2: return LS_NEON_2D;
case 4: return LS_NEON_4S;
case 8: return LS_NEON_8H;
case 16: return LS_NEON_16B;
default: return 0xffffffff;
}
}
}
// Instruction bits for scalar format in data processing operations.
static Instr SFormat(VRegister vd) {
VIXL_ASSERT(vd.lanes() == 1);
switch (vd.SizeInBytes()) {
case 1: return NEON_B;
case 2: return NEON_H;
case 4: return NEON_S;
case 8: return NEON_D;
default: return 0xffffffff;
}
}
static Instr ImmNEONHLM(int index, int num_bits) {
int h, l, m;
if (num_bits == 3) {
VIXL_ASSERT(is_uint3(index));
h = (index >> 2) & 1;
l = (index >> 1) & 1;
m = (index >> 0) & 1;
} else if (num_bits == 2) {
VIXL_ASSERT(is_uint2(index));
h = (index >> 1) & 1;
l = (index >> 0) & 1;
m = 0;
} else {
VIXL_ASSERT(is_uint1(index) && (num_bits == 1));
h = (index >> 0) & 1;
l = 0;
m = 0;
}
return (h << NEONH_offset) | (l << NEONL_offset) | (m << NEONM_offset);
}
static Instr ImmNEONExt(int imm4) {
VIXL_ASSERT(is_uint4(imm4));
return imm4 << ImmNEONExt_offset;
}
static Instr ImmNEON5(Instr format, int index) {
VIXL_ASSERT(is_uint4(index));
int s = LaneSizeInBytesLog2FromFormat(static_cast<VectorFormat>(format));
int imm5 = (index << (s + 1)) | (1 << s);
return imm5 << ImmNEON5_offset;
}
static Instr ImmNEON4(Instr format, int index) {
VIXL_ASSERT(is_uint4(index));
int s = LaneSizeInBytesLog2FromFormat(static_cast<VectorFormat>(format));
int imm4 = index << s;
return imm4 << ImmNEON4_offset;
}
static Instr ImmNEONabcdefgh(int imm8) {
VIXL_ASSERT(is_uint8(imm8));
Instr instr;
instr = ((imm8 >> 5) & 7) << ImmNEONabc_offset;
instr |= (imm8 & 0x1f) << ImmNEONdefgh_offset;
return instr;
}
static Instr NEONCmode(int cmode) {
VIXL_ASSERT(is_uint4(cmode));
return cmode << NEONCmode_offset;
}
static Instr NEONModImmOp(int op) {
VIXL_ASSERT(is_uint1(op));
return op << NEONModImmOp_offset;
}
// Size of the code generated since label to the current position.
size_t SizeOfCodeGeneratedSince(Label* label) const {
VIXL_ASSERT(label->IsBound());
return buffer_->OffsetFrom(label->location());
}
size_t SizeOfCodeGenerated() const {
return buffer_->CursorOffset();
}
size_t BufferCapacity() const { return buffer_->capacity(); }
size_t RemainingBufferSpace() const { return buffer_->RemainingBytes(); }
void EnsureSpaceFor(size_t amount) {
if (buffer_->RemainingBytes() < amount) {
size_t capacity = buffer_->capacity();
size_t size = buffer_->CursorOffset();
do {
// TODO(all): refine.
capacity *= 2;
} while ((capacity - size) < amount);
buffer_->Grow(capacity);
}
}
#ifdef VIXL_DEBUG
void AcquireBuffer() {
VIXL_ASSERT(buffer_monitor_ >= 0);
buffer_monitor_++;
}
void ReleaseBuffer() {
buffer_monitor_--;
VIXL_ASSERT(buffer_monitor_ >= 0);
}
#endif
PositionIndependentCodeOption pic() const {
return pic_;
}
bool AllowPageOffsetDependentCode() const {
return (pic() == PageOffsetDependentCode) ||
(pic() == PositionDependentCode);
}
static const Register& AppropriateZeroRegFor(const CPURegister& reg) {
return reg.Is64Bits() ? xzr : wzr;
}
protected:
void LoadStore(const CPURegister& rt,
const MemOperand& addr,
LoadStoreOp op,
LoadStoreScalingOption option = PreferScaledOffset);
void LoadStorePair(const CPURegister& rt,
const CPURegister& rt2,
const MemOperand& addr,
LoadStorePairOp op);
void LoadStoreStruct(const VRegister& vt,
const MemOperand& addr,
NEONLoadStoreMultiStructOp op);
void LoadStoreStruct1(const VRegister& vt,
int reg_count,
const MemOperand& addr);
void LoadStoreStructSingle(const VRegister& vt,
uint32_t lane,
const MemOperand& addr,
NEONLoadStoreSingleStructOp op);
void LoadStoreStructSingleAllLanes(const VRegister& vt,
const MemOperand& addr,
NEONLoadStoreSingleStructOp op);
void LoadStoreStructVerify(const VRegister& vt,
const MemOperand& addr,
Instr op);
void Prefetch(PrefetchOperation op,
const MemOperand& addr,
LoadStoreScalingOption option = PreferScaledOffset);
// TODO(all): The third parameter should be passed by reference but gcc 4.8.2
// reports a bogus uninitialised warning then.
void Logical(const Register& rd,
const Register& rn,
const Operand operand,
LogicalOp op);
void LogicalImmediate(const Register& rd,
const Register& rn,
unsigned n,
unsigned imm_s,
unsigned imm_r,
LogicalOp op);
void ConditionalCompare(const Register& rn,
const Operand& operand,
StatusFlags nzcv,
Condition cond,
ConditionalCompareOp op);
void AddSubWithCarry(const Register& rd,
const Register& rn,
const Operand& operand,
FlagsUpdate S,
AddSubWithCarryOp op);
// Functions for emulating operands not directly supported by the instruction
// set.
void EmitShift(const Register& rd,
const Register& rn,
Shift shift,
unsigned amount);
void EmitExtendShift(const Register& rd,
const Register& rn,
Extend extend,
unsigned left_shift);
void AddSub(const Register& rd,
const Register& rn,
const Operand& operand,
FlagsUpdate S,
AddSubOp op);
void NEONTable(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEONTableOp op);
// Find an appropriate LoadStoreOp or LoadStorePairOp for the specified
// registers. Only simple loads are supported; sign- and zero-extension (such
// as in LDPSW_x or LDRB_w) are not supported.
static LoadStoreOp LoadOpFor(const CPURegister& rt);
static LoadStorePairOp LoadPairOpFor(const CPURegister& rt,
const CPURegister& rt2);
static LoadStoreOp StoreOpFor(const CPURegister& rt);
static LoadStorePairOp StorePairOpFor(const CPURegister& rt,
const CPURegister& rt2);
static LoadStorePairNonTemporalOp LoadPairNonTemporalOpFor(
const CPURegister& rt, const CPURegister& rt2);
static LoadStorePairNonTemporalOp StorePairNonTemporalOpFor(
const CPURegister& rt, const CPURegister& rt2);
static LoadLiteralOp LoadLiteralOpFor(const CPURegister& rt);
private:
static uint32_t FP32ToImm8(float imm);
static uint32_t FP64ToImm8(double imm);
// Instruction helpers.
void MoveWide(const Register& rd,
uint64_t imm,
int shift,
MoveWideImmediateOp mov_op);
void DataProcShiftedRegister(const Register& rd,
const Register& rn,
const Operand& operand,
FlagsUpdate S,
Instr op);
void DataProcExtendedRegister(const Register& rd,
const Register& rn,
const Operand& operand,
FlagsUpdate S,
Instr op);
void LoadStorePairNonTemporal(const CPURegister& rt,
const CPURegister& rt2,
const MemOperand& addr,
LoadStorePairNonTemporalOp op);
void LoadLiteral(const CPURegister& rt, uint64_t imm, LoadLiteralOp op);
void ConditionalSelect(const Register& rd,
const Register& rn,
const Register& rm,
Condition cond,
ConditionalSelectOp op);
void DataProcessing1Source(const Register& rd,
const Register& rn,
DataProcessing1SourceOp op);
void DataProcessing3Source(const Register& rd,
const Register& rn,
const Register& rm,
const Register& ra,
DataProcessing3SourceOp op);
void FPDataProcessing1Source(const VRegister& fd,
const VRegister& fn,
FPDataProcessing1SourceOp op);
void FPDataProcessing3Source(const VRegister& fd,
const VRegister& fn,
const VRegister& fm,
const VRegister& fa,
FPDataProcessing3SourceOp op);
void NEONAcrossLanesL(const VRegister& vd,
const VRegister& vn,
NEONAcrossLanesOp op);
void NEONAcrossLanes(const VRegister& vd,
const VRegister& vn,
NEONAcrossLanesOp op);
void NEONModifiedImmShiftLsl(const VRegister& vd,
const int imm8,
const int left_shift,
NEONModifiedImmediateOp op);
void NEONModifiedImmShiftMsl(const VRegister& vd,
const int imm8,
const int shift_amount,
NEONModifiedImmediateOp op);
void NEONFP2Same(const VRegister& vd,
const VRegister& vn,
Instr vop);
void NEON3Same(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEON3SameOp vop);
void NEONFP3Same(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
Instr op);
void NEON3DifferentL(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEON3DifferentOp vop);
void NEON3DifferentW(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEON3DifferentOp vop);
void NEON3DifferentHN(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEON3DifferentOp vop);
void NEONFP2RegMisc(const VRegister& vd,
const VRegister& vn,
NEON2RegMiscOp vop,
double value = 0.0);
void NEON2RegMisc(const VRegister& vd,
const VRegister& vn,
NEON2RegMiscOp vop,
int value = 0);
void NEONFP2RegMisc(const VRegister& vd,
const VRegister& vn,
Instr op);
void NEONAddlp(const VRegister& vd,
const VRegister& vn,
NEON2RegMiscOp op);
void NEONPerm(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
NEONPermOp op);
void NEONFPByElement(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index,
NEONByIndexedElementOp op);
void NEONByElement(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index,
NEONByIndexedElementOp op);
void NEONByElementL(const VRegister& vd,
const VRegister& vn,
const VRegister& vm,
int vm_index,
NEONByIndexedElementOp op);
void NEONShiftImmediate(const VRegister& vd,
const VRegister& vn,
NEONShiftImmediateOp op,
int immh_immb);
void NEONShiftLeftImmediate(const VRegister& vd,
const VRegister& vn,
int shift,
NEONShiftImmediateOp op);
void NEONShiftRightImmediate(const VRegister& vd,
const VRegister& vn,
int shift,
NEONShiftImmediateOp op);
void NEONShiftImmediateL(const VRegister& vd,
const VRegister& vn,
int shift,
NEONShiftImmediateOp op);
void NEONShiftImmediateN(const VRegister& vd,
const VRegister& vn,
int shift,
NEONShiftImmediateOp op);
void NEONXtn(const VRegister& vd,
const VRegister& vn,
NEON2RegMiscOp vop);
Instr LoadStoreStructAddrModeField(const MemOperand& addr);
// Encode the specified MemOperand for the specified access size and scaling
// preference.
Instr LoadStoreMemOperand(const MemOperand& addr,
unsigned access_size,
LoadStoreScalingOption option);
// Link the current (not-yet-emitted) instruction to the specified label, then
// return an offset to be encoded in the instruction. If the label is not yet
// bound, an offset of 0 is returned.
ptrdiff_t LinkAndGetByteOffsetTo(Label * label);
ptrdiff_t LinkAndGetInstructionOffsetTo(Label * label);
ptrdiff_t LinkAndGetPageOffsetTo(Label * label);
// A common implementation for the LinkAndGet<Type>OffsetTo helpers.
template <int element_shift>
ptrdiff_t LinkAndGetOffsetTo(Label* label);
// Literal load offset are in words (32-bit).
ptrdiff_t LinkAndGetWordOffsetTo(RawLiteral* literal);
// Emit the instruction in buffer_.
void Emit(Instr instruction) {
VIXL_STATIC_ASSERT(sizeof(instruction) == kInstructionSize);
VIXL_ASSERT(buffer_monitor_ > 0);
buffer_->Emit32(instruction);
}
// Buffer where the code is emitted.
CodeBuffer* buffer_;
PositionIndependentCodeOption pic_;
#ifdef VIXL_DEBUG
int64_t buffer_monitor_;
#endif
};
// All Assembler emits MUST acquire/release the underlying code buffer. The
// helper scope below will do so and optionally ensure the buffer is big enough
// to receive the emit. It is possible to request the scope not to perform any
// checks (kNoCheck) if for example it is known in advance the buffer size is
// adequate or there is some other size checking mechanism in place.
class CodeBufferCheckScope {
public:
// Tell whether or not the scope needs to ensure the associated CodeBuffer
// has enough space for the requested size.
enum CheckPolicy {
kNoCheck,
kCheck
};
// Tell whether or not the scope should assert the amount of code emitted
// within the scope is consistent with the requested amount.
enum AssertPolicy {
kNoAssert, // No assert required.
kExactSize, // The code emitted must be exactly size bytes.
kMaximumSize // The code emitted must be at most size bytes.
};
CodeBufferCheckScope(Assembler* assm,
size_t size,
CheckPolicy check_policy = kCheck,
AssertPolicy assert_policy = kMaximumSize)
: assm_(assm) {
if (check_policy == kCheck) assm->EnsureSpaceFor(size);
#ifdef VIXL_DEBUG
assm->bind(&start_);
size_ = size;
assert_policy_ = assert_policy;
assm->AcquireBuffer();
#else
USE(assert_policy);
#endif
}
// This is a shortcut for CodeBufferCheckScope(assm, 0, kNoCheck, kNoAssert).
explicit CodeBufferCheckScope(Assembler* assm) : assm_(assm) {
#ifdef VIXL_DEBUG
size_ = 0;
assert_policy_ = kNoAssert;
assm->AcquireBuffer();
#endif
}
~CodeBufferCheckScope() {
#ifdef VIXL_DEBUG
assm_->ReleaseBuffer();
switch (assert_policy_) {
case kNoAssert: break;
case kExactSize:
VIXL_ASSERT(assm_->SizeOfCodeGeneratedSince(&start_) == size_);
break;
case kMaximumSize:
VIXL_ASSERT(assm_->SizeOfCodeGeneratedSince(&start_) <= size_);
break;
default:
VIXL_UNREACHABLE();
}
#endif
}
protected:
Assembler* assm_;
#ifdef VIXL_DEBUG
Label start_;
size_t size_;
AssertPolicy assert_policy_;
#endif
};
template <typename T>
void Literal<T>::UpdateValue(T new_value, const Assembler* assembler) {
return UpdateValue(new_value, assembler->GetStartAddress<uint8_t*>());
}
template <typename T>
void Literal<T>::UpdateValue(T high64, T low64, const Assembler* assembler) {
return UpdateValue(high64, low64, assembler->GetStartAddress<uint8_t*>());
}
} // namespace vixl
#endif // VIXL_A64_ASSEMBLER_A64_H_
|