offlineasm 0.4.6

Portable assembler for Rust
Documentation
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
<!-- Packaging copy of docs/reference.md. Edit the root file and re-copy. -->

# Instruction reference

Instruction reference for offlineasm and onlineasm.
## Conventions

### Operands

`O1` is the first operand written in the assembly, `O2`, `O3`, `O4` the following ones, in the order they are written in. `O1` is
the destination wherever the mnemonic has one. `t0`, `t1`, `t2` are the ISA-implicit registers used
by the multiply/divide family.

- `op O1, O2` is `O1 = O1 <op> O2`. `op O1, O2, O3` is `O1 = O2 <op> O3`.
- Registers fall in three portable classes: general-purpose (`t0`-`t12`, `csr0`-`csr10`, and the
  special registers `cfr`, `sp`, `lr`, `zr`, `zero`, `fp`, `tp`), floating-point (`ft0`-`ft7`,
  `csfr0`-`csfr7`), and 128-bit vector (`v0`-`v7`). Every name is a fixed alias for a physical
  register of the selected target. See [Registers]#registers for full mapping of them.
- Operand kinds are: 
  - `m` memory (`off[base]`, `off[base, index, scale]`, `off[]`)
  - `imm` immediate
  - `lbl` code label
  - `ext` external symbol (see [External symbols]#external-symbols)
  - `addr` any addressable source.
- Letter at the end of instruction specifies its width: `b` 8 bit, `h` 16, `i` 32, `q` 64, `p` 64 (pointer), `f` `f32`, `d`
  `f64`, `v` 128-bit vector.
- Branch names start with `b`, except `bswap*` and `bfiq`. 
  - `c*` compares and writes `0`/`1` to a register. 
  - `t*` tests a bit, and writes `0`/`1` to a register. 
  - `bt*` is a test + branch, which does not write to register.  
- `UInt()` and `SInt()` denote an unsigned or signed integers respectively.
- `IsUnordered()` is true when FP operand is NaN.



### Types and accessors

- `bits(N)`, `integer`, `boolean` are primitive types, where `bits(N)` denote integer of width N.
- `X[n]` - is a view of operand `n` as 64-bit integer. 
- `X[n]<hi:lo>` selects a bit slice (e.g. `X[n]<31:0>` is the 32-bit view).
- `V[n]` - 128-bit view of operand `n`'s vector/FP register. `V[n]<31:0>` and `V[n]<63:0>` are its
  `f32`/`f64` views.
- `Mem[address, size]` - a `size`-byte memory access at `address`. `size` is `1`/`2`/`4`/`8`/`16`
  (or `32` for a 256-bit pair store).
- `PC`, `LR`, `SP` - the implicit program counter, link register, and stack pointer.
- `FLAG` - `bits(4)` of `N:Z:C:V` (negative, zero, carry, overflow), the synthesized condition
  state written by the `*s`/compare/test family. `FLAG.N`, `FLAG.Z`, `FLAG.C`, `FLAG.V`
  name the individual bits.

### Shared subroutines

- `(bits(N), bits(4)) AddWithCarry(bits(N) x, bits(N) y, bit carry_in)` - computes `x + y +
  carry_in` and returns the result together with the `N:Z:C:V` flags it produces. Subtraction is
  `AddWithCarry(x, NOT(y), '1')`.
- `(bits(N), bit) MulWithOverflow(bits(N) x, bits(N) y)` - a full-width multiply together with
  whether the truncated `N`-bit result differs from the true product (signed overflow).
- `ZeroExtend(bits(M) x, integer N)` / `SignExtend(bits(M) x, integer N)` - widen `x` to `N` bits.
- `IsZeroBit(bits(N) x)` - `x == 0`, as a single bit usable in `X[n] = if ... then 1 else 0`.
- `Min(x, y)`, `Max(x, y)`, `Abs(x)` - minimum/maximum out of `x` and `y`, or absolute value of `x`.
- `RotateLeft(bits(N) x, integer amount)`, `RotateRight(bits(N) x, integer amount)`,
  `ByteReverse(bits(N) x)`.
- `CountLeadingZeroBits(bits(N) x)`, `CountTrailingZeroBits(bits(N) x)`, `BitCount(bits(N) x)` - clz, ctz, popcount.
- `Sqrt()`, `RoundToNearest()`, `FloorToIntegral()`, `CeilToIntegral()`, `TruncateToIntegral()` - the IEEE-754 rounding operations.
- `FPToFixed(bits(N) x, integer M, rounding)` / `FixedToFP(integer x, integer N)` - float-to-
  integer and integer-to-float conversion; `FPConvert(bits(N) x, integer M)` converts between
  float widths. `InexactConversion()` reports whether the most recent `FPToFixed` lost precision.
- `EffectiveAddress(m)` - the address denoted by a memory operand `m` (`off[base]`,
  `off[base, index, scale]`), computed without accessing memory. `GlobalAddress(sym)` resolves a
  global symbol's address at link/lowering time. `TLSBase()` is the platform's thread-local
  storage base.
- `Acquire(location)` / `Release(location) = value` - a load/store with acquire/release memory
  ordering.
- `AcquireExclusive(location)` / `(boolean) ReleaseExclusive(location) = value` - an exclusive
  (linked) load and its paired conditional store, returning whether the store succeeded.
- `Barrier(kind)` - a memory barrier, `kind` is `Full` (`memfence`) or `Sync` (`fence`).
  `SpinLoopHint()` is `pause`'s CPU hint. `Trap()` raises a trap. `CallNative()`/`CallSlowPath()`/
  `SuspendLoop()` are the `rloop` backend's host-call primitives. `EmitRawText()` is `emit`'s raw
  text splice.
- `BranchTo(target)` - transfers control to `target`.

## Registers

offlineasm and onlineasm have the same set of registers available. The availability of register is dependent on target platform. 

If you require access to a register by its raw platform name instead of its portable name, use
the `%` prefix: `move %rax, 42`.

The `X[n]`/`V[n]` accessors used throughout this reference address these same portable registers
by operand position; the tables below give the physical register each portable name maps to.

### General-purpose registers

|  | x86-64 | AArch64 | RISC-V 64 |
| ---| ---| ---| --- |
| `t0` | `rax` | `x0` | `x10` |
| `t1` | `rsi` | `x1` | `x11` |
| `t2` | `rdx` | `x2` | `x12` |
| `t3` | `rcx` | `x3` | `x13` |
| `t4` | `r8` | `x4` | `x14` |
| `t5` | `r10` | `x5` | `x15` |
| `t6` | `rdi` | `x6` | `x16` |
| `t7` | `r9` | `x7` | `x17` |
| `t8` | - | `x8` | `x5` |
| `t9` | - | `x9` | `x6` |
| `t10` | - | `x10` | `x7` |
| `t11` | - | `x11` | - |
| `t12` | - | `x12` | - |
| `csr0` | `rbx` | `x19` | `x18` |
| `csr1` | `r12` | `x20` | `x19` |
| `csr2` | `r13` | `x21` | `x20` |
| `csr3` | `r14` | `x22` | `x21` |
| `csr4` | `r15` | `x23` | `x22` |
| `csr5` | `rsi` | `x24` | `x23` |
| `csr6` | `rdi` | `x25` | `x24` |
| `csr7` | - | `x26` | `x25` |
| `csr8` | - | `x27` | `x26` |
| `csr9` | - | `x28` | `x27` |
| `csr10` | - | - | `x9` |
| `cfr` | `rbp` | `x29` | `x8` |
| `sp` | `rsp` | `sp` | `x2` |
| `lr` | - | `x30` | `x1` |
| `zr` | - | `xzr` | - |
| `zero` | - | - | `x0` |
| `tp` | - | - | `x4` |
| `fp` | - | - | `x8` |

`t0`-`t12` are caller-saved temporaries, `csr0`-`csr10` callee-saved. The rest are
- `cfr` is the frame pointer (`rbp`, `x29`, `x8`), 
- `sp` the stack pointer (`rsp`, `sp`, `x2`).
- `lr` the link register (AArch64 and RISC-V only),
- `fp` a RISC-V alias of `cfr`.
- `tp` the RISC-V thread pointer.
- `zr`/`zero` read as zero and discard writes.

### Floating-point and vector registers

| portable | x86-64 | AArch64 | RISC-V 64 |
| ---| ---| ---| --- |
| `ft0` | `xmm0` | `v0` | `f8` |
| `ft1` | `xmm1` | `v1` | `f10` |
| `ft2` | `xmm2` | `v2` | `f12` |
| `ft3` | `xmm3` | `v3` | `f14` |
| `ft4` | `xmm4` | `v4` | `f16` |
| `ft5` | `xmm5` | `v5` | `f18` |
| `ft6` | `xmm6` | `v6` | `f20` |
| `ft7` | `xmm7` | `v7` | `f22` |
| `csfr0` | - | `v8` | `f1` |
| `csfr1` | - | `v9` | `f3` |
| `csfr2` | - | `v10` | `f5` |
| `csfr3` | - | `v11` | `f7` |
| `csfr4` | - | `v12` | `f9` |
| `csfr5` | - | `v13` | `f11` |
| `csfr6` | - | `v14` | `f13` |
| `csfr7` | - | `v15` | `f15` |
| `v0` | `xmm0` | `v16` | `f0` |
| `v1` | `xmm1` | `v17` | `f2` |
| `v2` | `xmm2` | `v18` | `f4` |
| `v3` | `xmm3` | `v19` | `f6` |
| `v4` | `xmm4` | `v20` | `f24` |
| `v5` | `xmm5` | `v21` | `f26` |
| `v6` | `xmm6` | `v22` | `f28` |
| `v7` | `xmm7` | `v23` | `f30` |

### Callee-saved registers

These registers must be preserved by the callee using `pushCalleeSaves` or `popCalleeSaves` (or use push/pop manually).

| target | general-purpose | floating-point |
| --- | --- | --- |
| x86-64 (System V) | `csr0`-`csr4` | - |
| x86-64 (Windows x64) | `csr0`-`csr6` | - |
| AArch64 (AAPCS64) | `csr0`-`csr9` | `csfr0`-`csfr7` |
| RISC-V 64 | `csr0`-`csr10` | `csfr0`-`csfr7` |

`cfr` and `sp` are also preserved by the ABI, but they are not always required (e.g leaf functions), thus are not in pushCalleeSaves/popCalleeSaves requirements.

x86-64 also has no `csfr` registers which are floating point calle saved registers, as only Windows calling convention treats them as calle saved, and we do not expose `xmm6` to `xmm15` in the portable syntax, instead save them manually if you use them via `%` prefix. 

### Scratch and reserved registers

onlineasm/offlineasm sometimes need a register for materialization, or staging an operand e.g for division on x64. For this we reserve one or two machine registers. 

These registers are generally not recommended to be used in raw way (via `%r11` for example), as at any point of program they can be clobbered. Each numbered section below opens with a "Scratch registers" table listing which scratch registers its instructions clobber and when; consult it to know where it is safe, and where you have to save the register. 

| target | scratch GPR | scratch FPR |
| --- | --- | --- |
| x86-64 | `r11` | `xmm7` |
| AArch64 | `x16`, `x17` | `v31` |
| RISC-V 64 | `x29`, `x31` | `f31` |

- x86-64: 
  - `%r11` GPR expansion scratch.
  - `%xmm7`: FPR expansion scratch
- AArch64: 
  - `%x16`: GPR expansion scratch
  - `%x17` second GPR expansion scratch
  - `%x18` the platform register
  - `%q31`, `%d31`, `%s31`, `%v31`: FPR  expansion scratch
- RISC-V 64: 
  - `%x3`/`%gp`: psABI's reserved `gp` 
  - `%x29`: expansion scratch 
  - `%x30`: flags register
  - `%x31`/`%t6`: expansion scratch 
  - `%f31`/`%ft11`: FPR expansion scratch

*NOTE on rloop: it has no native registers, so `%` prefix has no effect and will produce an error during lowering.

## External symbols

An external symbol is a function or data object outside the code being assembled. It is a
`jmp`/`call` target, or the source of `move`, `leap`, `globaladdr`, and `la`, which take its address.

offlineasm declares one per file with `extern _name` (far) or `extern near _name`, and then uses it
like a label: `call _name`. A declared name cannot also be defined or declared `global` in the same file. rloop does not support external symbols. 

onlineasm uses asmkit's `ExternalName` as external names. `Assembler::extern_far`, `Assembler::extern_near`, and
`Assembler::extern_name` declare one and return an `Extern` operand. In `onlineasm!`,
`extern name = {expr};` (or `extern near name = {expr};`) binds it to `name`, and
`call extern {expr}` (or `extern near {expr}`) declares one in place. 

Once you are done emitting code `Finished::load` will allow you to manually resolve all declared extern names. `LoadedCode::rebind` allows to point **far** entries to a new address.

A **far** extern is reached through a pointer-sized slot in an address table, so it can be anywhere. onlineasm places the table right after the code. offlineasm uses the linker's GOT on ELF
and Mach-O, and on COFF emits a slot in `.rdata` with the
same instructions. A **near** extern is a direct PC-relative reference and must be in range of the
code: ±2 GiB on x86-64 and RISC-V 64, and on AArch64 ±128 MiB for `bl`/`b` and ±4 GiB for `adrp`.
onlineasm fails to load an image whose near extern is out of range.

Position-independent code (the `PIC` setting in offlineasm, `AssemblerOptions::with_pic` in
onlineasm) reaches every extern through the table, as if it were declared far.

| target | address (`leap`, `move`, ...) | `call` / `jmp` |
| --- | --- | --- |
| x86-64 near | `lea d, [rip + sym]` | `call sym` / `jmp sym` |
| x86-64 far | `mov d, qword ptr [rip + sym@GOTPCREL]` | `call`/`jmp qword ptr [rip + sym@GOTPCREL]` |
| AArch64 near | `adrp d, sym` + `add d, d, :lo12:sym` | `bl sym` / `b sym` |
| AArch64 far | `adrp d, :got:sym` + `ldr d, [d, :got_lo12:sym]` | the far address into `x16`, then `blr`/`br x16` |
| RISC-V 64 near | `lla d, sym` | `call sym` / `jump sym, x31` |
| RISC-V 64 far | `lga d, sym` | the far address into `x31`, then `jalr` |

## Patching emitted code

onlineasm only. `#[patch = name]` on an instruction emits it through a
patchable site and binds the site's `PatchHandle` to `name` (the
`Assembler::emit_patched` equivalent outside the macro). After `finish`,
`Finished::location` turns the handle into a `PatchLocation`: a jump site is
retargeted with `asmkit::repatch_jump_span`, an immediate site rewritten with
`onlineasm::repatch_u64`. Both stay writable, and no thread may execute the
patched instruction while it is rewritten.

| Mnemonic | Site | Restrictions |
| --- | --- | --- |
| `jmp`, `call` | jump | `O1` must be a label. Register, memory, absolute, and external targets are not patchable. |
| `move` | 64-bit immediate | `O1` must be a register and `O2` an immediate. |
| integer branches (`bieq`, `bqeq`, ...), test branches (`btqz`, ...), flag branches (`bo`, `bs`, `bz`, `bnz`), arithmetic branches (`baddqo`, ...), float branches (`bdeq`, ...) | jump | The expansion must be a single branch: float conditions that need several branches are not patchable (which ones depends on the target), and neither is the overflow-of-`or` branch (`borio`/`borqo`), which emits no branch at all. |

An external symbol is never a patch site. Anything else fails with
`NotPatchable` (a panic naming the mnemonic from the macro).

`#[patch_abs = name]` (macro only) on `jmp`/`call` with an integer or `{expr}`
target reserves a 64-bit absolute-address slot for callees outside jump range:
it emits a patchable `move` of the target into the expansion scratch GPR
followed by an indirect jump/call through it, and binds the `move`'s immediate
site. The scratch GPR is clobbered.

Handles from a backward assembler are virtual until `finish` replays the tape,
and resolve through `Finished::location` like any other handle.
`Finished::link` drops every handle: `location` on a linked image returns
`None`. To patch before allocating, apply `asmkit::repatch_jump` /
`asmkit::repatch_value` to a copy of `Finished::data` instead.

See `Assembler::emit_patched` and the `patch` example (`cargo run -p onlineasm
--example patch`).

## 1. Memory operations

### Scratch registers

An address *needs folding* when one memory operand cannot encode it, so
the backend computes it into a scratch register first. On AArch64 that is
an index whose scale is neither 1 nor the access size, an index together
with an offset, an offset outside both the scaled unsigned 12-bit and the
unscaled ±256 forms, or an absolute address. On RISC-V 64
it is any index, an offset outside ±2 KiB, or an absolute address. x86-64
never folds.

Loads and stores: `move`, `loadi`, `loadp`, `loadq`, `zxi2q`, `storei`,
`storep`, `storeq`, `storeh`, `storeb`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | value stored to memory is an immediate that does not fit the store (64-bit: signed 32 bits), a label, or memory |
| AArch64 | `x16` | address needs folding |
| AArch64 | `x17` | value stored to memory is an immediate (any value) or memory |
| RISC-V 64 | `x31` | address needs folding; value stored to memory is an immediate (any value) |
| RISC-V 64 | `x29` | immediate stored through an address that needs folding |

Atomic loads: `atomicloadb`, `atomicloadh`, `atomicloadi`, `atomicloadq`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address has any offset or index (`ldar` takes only `[Xn]`) |
| RISC-V 64 | `x31` | address needs folding |

Extending loads and extensions: `loadis`, `loadb`, `loadbsi`, `loadbsq`,
`loadh`, `loadhsi`, `loadhsq`, `sxb2i`, `sxh2i`, `sxb2q`, `sxb2p`,
`sxh2q`, `sxi2q`, `zxb2i`, `zxh2i`, `zxb2q`, `zxh2q`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | source is memory (loaded into `x16`, then extended) or an immediate |
| RISC-V 64 | `x31` | source is memory (loaded into `x31`, then extended) or an immediate |

Transfers: `transferi`, `transferp`, `transferq`. The shared expansion
stages every non-register source through the first scratch register.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | source is memory, an immediate, or a label |
| AArch64 | `x16` | source is memory, an immediate, or a label; memory destination needs folding |
| RISC-V 64 | `x31` | source is memory, an immediate, or a label; either address needs folding |
| RISC-V 64 | `x29` | staged source stored through a destination address that needs folding |

Float and vector moves: `loadf`, `loadd`, `moved`, `storef`, `stored`,
`loadv`, `storev`, `movev`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address needs folding |
| RISC-V 64 | `x31` | address needs folding (`loadv`/`storev`: either 8-byte half) |
| RISC-V 64 | `f31` | `storev` through an address that needs folding |

Address computation: `leai`, `leap`, `pcrtoaddr`, `globaladdr`, `la`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address is anything but a bare base register (a label or extern goes straight into the destination) |
| RISC-V 64 | `x31` | unindexed address whose offset is outside ±2 KiB and whose base is the destination |

Pair loads and stores: `loadpairq`, `loadpairp`, `loadpairi`,
`loadpaird`, `loadpairv`, `storepairq`, `storepairp`, `storepairi`,
`storepaird`, `storepairv`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | integer pair load whose first destination is the base or index and whose second destination is the same register or the other address register |
| AArch64 | `x16` | address has an index, is absolute, or its offset is not a multiple of the element size within ±64 elements; integer pair load into the same register twice |
| AArch64 | `v31` | `loadpaird`/`loadpairv` into the same register twice |
| RISC-V 64 | `x31` | address has an index, is absolute, or either half's offset is outside ±2 KiB |

Stack operations: `push`, `pop`, `pushv`, `popv`, `pushCalleeSaves`,
`popCalleeSaves`, `peek`, `poke`. `pushv`, `popv`, `pushCalleeSaves`, and
`popCalleeSaves` never clobber scratch registers. RISC-V 64 `push`/`pop`
accept only registers.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | `push` of an immediate that does not fit signed 32 bits, or of a label |
| AArch64 | `x16` | `push` of an immediate or memory operand in the lower slot of a pair; memory operand address needs folding; `peek`/`poke` offset is not a multiple of 8 in 0..32760 |
| AArch64 | `x17` | `push` of an immediate or memory operand in the upper slot of a pair; `pop` into memory |
| RISC-V 64 | `x31` | `peek`/`poke` offset is outside ±2 KiB |

Thread-local slots: `tls_loadb`, `tls_loadh`, `tls_loadi`, `tls_loadp`
(`tls_loadq`), `tls_storeb`, `tls_storeh`, `tls_storei`, `tls_storep`
(`tls_storeq`), `tls_leap`. The offset being "out of range" means
not a multiple of the access size in `0..4096 * size` for AArch64
loads/stores, outside ±4095 for AArch64 `tls_leap`, and outside ±2 KiB on
RISC-V 64. On x86-64 the offset has to fit a signed 32-bit displacement.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | always (holds the thread pointer) |
| AArch64 | `x17` | offset out of range |
| RISC-V 64 | `x31` | offset out of range |
| RISC-V 64 | `x29`, `f31` | `tls_store*` with the offset out of range |

### `move O1, O2`

```text
X[O1] = X[O2];
```

Accepts `#[patch]` in `onlineasm` when `O1` is a register and `O2` is an
immediate; see [Patching emitted code](#patching-emitted-code).

### `loadi O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Mem[address, 4], 64);
```

### `loadp O1, O2`

```text
bits(64) address = X[O2];
X[O1] = Mem[address, 8];
```

### `loadq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = Mem[address, 8];
```

### `atomicloadb O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Acquire(Mem[address, 1]), 64);
```

### `atomicloadh O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Acquire(Mem[address, 2]), 64);
```

### `atomicloadi O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Acquire(Mem[address, 4]), 64);
```

### `atomicloadq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = Acquire(Mem[address, 8]);
```

### `loadis O1, O2`

```text
bits(64) address = X[O2];
X[O1] = SignExtend(Mem[address, 4], 64);
```

### `loadb O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Mem[address, 1], 64);
```

### `loadbsi O1, O2`

```text
bits(64) address = X[O2];
X[O1] = SignExtend(Mem[address, 1], 64);
```

### `loadbsq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = SignExtend(Mem[address, 1], 64);
```

### `loadh O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(Mem[address, 2], 64);
```

### `loadhsi O1, O2`

```text
bits(64) address = X[O2];
X[O1] = SignExtend(Mem[address, 2], 64);
```

### `loadhsq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = SignExtend(Mem[address, 2], 64);
```

### `storei O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 4] = X[O2]<31:0>;
```

### `storep O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 8] = X[O2];
```

### `storeq O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 8] = X[O2];
```

### `storeh O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 2] = X[O2]<15:0>;
```

### `storeb O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 1] = X[O2]<7:0>;
```

### `transferi O1, O2`

```text
bits(64) address = X[O2];
X[O1]<31:0> = Mem[address, 4];
```

The upper 32 bits of `X[O1]` are unspecified, unlike `loadi`.

### `transferp O1, O2`

```text
bits(64) address = X[O2];
X[O1] = Mem[address, 8];
```

### `transferq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = Mem[address, 8];
```

### `sxb2i O1, O2`

```text
bits(32) result = SignExtend(X[O2]<7:0>, 32);
X[O1] = ZeroExtend(result, 64);
```

### `sxh2i O1, O2`

```text
bits(32) result = SignExtend(X[O2]<15:0>, 32);
X[O1] = ZeroExtend(result, 64);
```

### `sxb2q O1, O2`

```text
X[O1] = SignExtend(X[O2]<7:0>, 64);
```

### `sxb2p O1, O2`

```text
X[O1] = SignExtend(X[O2]<7:0>, 64);
```

### `sxh2q O1, O2`

```text
X[O1] = SignExtend(X[O2]<15:0>, 64);
```

### `sxi2q O1, O2`

```text
X[O1] = SignExtend(X[O2]<31:0>, 64);
```

### `zxb2i O1, O2`

```text
bits(32) result = ZeroExtend(X[O2]<7:0>, 32);
X[O1] = ZeroExtend(result, 64);
```

### `zxh2i O1, O2`

```text
bits(32) result = ZeroExtend(X[O2]<15:0>, 32);
X[O1] = ZeroExtend(result, 64);
```

### `zxb2q O1, O2`

```text
X[O1] = ZeroExtend(X[O2]<7:0>, 64);
```

### `zxh2q O1, O2`

```text
X[O1] = ZeroExtend(X[O2]<15:0>, 64);
```

### `zxi2q O1, O2`

```text
X[O1] = ZeroExtend(X[O2]<31:0>, 64);
```

### `loadf O1, O2`

```text
bits(64) address = X[O2];
V[O1]<31:0> = Mem[address, 4];
```

### `loadd O1, O2`

```text
bits(64) address = X[O2];
V[O1]<63:0> = Mem[address, 8];
```

### `moved O1, O2`

```text
V[O1]<63:0> = V[O2]<63:0>;
```

### `storef O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 4] = V[O2]<31:0>;
```

### `stored O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 8] = V[O2]<63:0>;
```

### `loadv O1, O2`

```text
bits(64) address = X[O2];
V[O1] = Mem[address, 16];
```

### `storev O1, O2`

```text
bits(64) address = X[O1];
Mem[address, 16] = V[O2];
```

### `movev O1, O2`

```text
V[O1] = V[O2];
```

### `leai O1, O2`

```text
X[O1] = ZeroExtend(EffectiveAddress(O2)<31:0>, 64);
```

### `leap O1, O2`

```text
X[O1] = EffectiveAddress(O2);
```

### `pcrtoaddr O1, O2`

```text
X[O1] = PC + SInt(O2);
```

`O2` is a PC-relative immediate offset.

### `globaladdr O1, O2`

```text
X[O1] = GlobalAddress(O2);
```

`O2` names a label or an [external symbol](#external-symbols), resolved at link or load time.

### `la O1, O2`

```text
X[O1] = EffectiveAddress(O2);
```

### `loadqinc O1, O2, O3`

```text
bits(64) address = X[O2];
X[O1] = Mem[address, 8];
X[O2] = address + X[O3];
```

Scratch:

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | increment does not fit signed 32 bits |
| AArch64 | `x17` | increment is outside ±4095 |
| RISC-V 64 | `x31` | increment is outside ±2 KiB |

### `loadpairq O1, O2, O3`

```text
bits(64) address = X[O3];
(X[O1], X[O2]) = Mem[address, 16] as (bits(64), bits(64));
```

### `loadpairp O1, O2, O3`

```text
bits(64) address = X[O3];
(X[O1], X[O2]) = Mem[address, 16] as (bits(64), bits(64));
```

### `loadpairi O1, O2, O3`

```text
bits(64) address = X[O3];
(bits(32) lo, bits(32) hi) = Mem[address, 8] as (bits(32), bits(32));
X[O1] = ZeroExtend(lo, 64);
X[O2] = ZeroExtend(hi, 64);
```

### `loadpaird O1, O2, O3`

```text
bits(64) address = X[O3];
(V[O1]<63:0>, V[O2]<63:0>) = Mem[address, 16] as (bits(64), bits(64));
```

### `loadpairv O1, O2, O3`

```text
bits(64) address = X[O3];
(V[O1], V[O2]) = Mem[address, 32] as (bits(128), bits(128));
```

### `storepairq O1, O2, O3`

```text
bits(64) address = X[O1];
Mem[address, 16] = (X[O2], X[O3]) as bits(128);
```

### `storepairp O1, O2, O3`

```text
bits(64) address = X[O1];
Mem[address, 16] = (X[O2], X[O3]) as bits(128);
```

### `storepairi O1, O2, O3`

```text
bits(64) address = X[O1];
Mem[address, 8] = (X[O2]<31:0>, X[O3]<31:0>) as bits(64);
```

### `storepaird O1, O2, O3`

```text
bits(64) address = X[O1];
Mem[address, 16] = (V[O2]<63:0>, V[O3]<63:0>) as bits(128);
```

### `storepairv O1, O2, O3`

```text
bits(64) address = X[O1];
Mem[address, 32] = (V[O2], V[O3]) as bits(256);
```

### `push O1, ..., On`

```text
for each operand Oi in O1..On do
    SP = SP - 8;
    Mem[SP, 8] = X[Oi];
endfor
```

### `pop O1, ..., On`

```text
for each operand Oi in On..O1 do
    X[Oi] = Mem[SP, 8];
    SP = SP + 8;
endfor
```

Each operand takes an 8-byte slot and the last operand ends up at `[sp]`, so `peek 0` reads it
on every target. AArch64 keeps `sp` 16-byte aligned (Linux enables the hardware check), so there a
single `push` or `pop` moves `sp` by `8 * n` rounded up to 16, where `n` is its operand count. The
operands keep the layout above and an odd count leaves a padding slot on top. Pop with the same
operand count you pushed with. Operands pair up into `stp`/`ldp`, and immediates and memory operands
stage through `x16`/`x17`. Memory operands based on `sp` are rejected on AArch64.

On rloop, `push` and `pop` read and write memory at `sp`, which the host points at a stack it owns.

### `pushv O1`

```text
SP = SP - 16;
Mem[SP, 16] = V[O1];
```

### `popv O1`

```text
V[O1] = Mem[SP, 16];
SP = SP + 16;
```

### `pushCalleeSaves O1, ..., On`

```text
for each callee-saved operand Oi in O1..On do
    SP = SP - 8;
    Mem[SP, 8] = X[Oi];
endfor
```

### `popCalleeSaves O1, ..., On`

```text
for each callee-saved operand Oi in On..O1 do
    X[Oi] = Mem[SP, 8];
    SP = SP + 8;
endfor
```

Lays operands out like `push` and `pop`, including the AArch64 rounding.

### `peek O1, O2`

```text
X[O1] = Mem[SP + 8 * UInt(O2), 8];
```

### `poke O1, O2`

```text
Mem[SP + 8 * UInt(O1), 8] = X[O2];
```

### `tls_loadb O1, O2` / `tls_loadh` / `tls_loadi` / `tls_loadp` (`tls_loadq` alias)

```text
X[O1] = ZeroExtend(Mem[TLSBase() + 8 * O2, size], 64);
```

`size` is 1/2/4/8 by suffix. `O2` is an immediate slot index, so the
address is `TLSBase() + 8 * O2`.

### `tls_storeb O1, O2` / `tls_storeh` / `tls_storei` / `tls_storep` (`tls_storeq` alias)

```text
Mem[TLSBase() + 8 * O1, size] = X[O2]<8*size-1:0>;
```


### `tls_leap O1, O2`

```text
X[O1] = TLSBase() + 8 * O2;
```

Materializes the slot address. 

### Thread-local slots across operating systems

Every slot is 8 bytes at `TLSBase() + 8 * idx`. The base itself is
platform-defined, and each backend reads it the fast way:

- Linux/BSD x86-64: `mov reg, fs:[off]` (`fs` set by `arch_prctl`).
- Windows x64: `mov reg, gs:[off]` (the TEB slot). Select it with the
  `WINDOWS` setting (`if WINDOWS` in `offlineasm!` source); Linux/BSD is
  the default.
- AArch64 (Linux/BSD/macOS): `mrs tmp, tpidr_el0` then `ldr/str`.
- RISC-V 64: `ld/sd` directly off `tp` (`x4`).

The JIT (`onlineasm`) picks `fs` vs `gs` from its `Abi`
(`Abi::Windows` means `gs`). The portable `rloop` backend does not
support thread-local slots.

Named OS thread-locals (ELF `initial-exec`, Mach-O TLV, Windows
`_tls_index` slots) have no link-time address a JIT can resolve, so
there is no named-symbol form, and you have to resolve the variable
address manually once per thread, and store it in a reserved TLS slot via
`tls_storep`.

## 2. Integer arithmetic and bitwise logic

### Scratch registers

Integer ALU: `addi`, `addp`, `addq`, `subi`, `subp`, `subq`, `muli`, `mulp`, `mulq`, `andi`, `andp`, `andq`, `ori`, `orp`, `orq`, `orh`, `xori`, `xorp`, `xorq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | memory destination in the two-operand form, with a memory source, or for `mul*`; immediate that does not fit the 32-bit immediate field; memory operand addressed through the destination register |
| AArch64 | `x16` | memory address that must be folded (index scale other than the access size, index plus offset, offset out of range); memory destination with a memory, unencodable-immediate or `sp` right operand; memory operand addressed through the destination register |
| AArch64 | `x17` | memory destination; memory source; immediate the instruction cannot encode (every `mul*` immediate); `sub*` whose right operand is the destination or `sp` |
| RISC-V 64 | `x31` | memory destination; memory source; memory address that must be folded; immediate outside signed 12 bits (every `mul*` immediate); `sub*` whose right operand is the destination; `orh` always |
| RISC-V 64 | `x29` | memory destination whose address must be folded; second memory operand addressed through the destination register |

Flag-setting ALU: `addis`, `subis`, `oris`, `addqs`, `subqs`, `addps`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | as for the integer ALU; `sub*` whose right operand is the destination register |
| AArch64 | `x16`, `x17` | as for the integer ALU |
| RISC-V 64 | `x29`, `x31` | always (`oris`: `x29` only with a memory destination) |
| RISC-V 64 | `x30` | always to receives the emulated flags |

On RISC-V 64, `addis` and `subis` also push and pop a 16-byte stack slot.

Negate and complement: `negi`, `negp`, `negq`, `noti`, `notq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | never |
| AArch64 | `x16` | memory address that must be folded |
| AArch64 | `x17` | memory operand |
| RISC-V 64 | - | never (memory operands are rejected) |

Shifts and rotates: `lshifti`, `lshiftp`, `lshiftq`, `rshifti`, `rshiftp`, `rshiftq`, `urshifti`, `urshiftp`, `urshiftq`, `lrotatei`, `lrotateq`, `rrotatei`, `rrotateq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | memory destination |
| AArch64 | `x16` | memory destination |
| AArch64 | `x17` | `lrotate*` by a register count |
| RISC-V 64 | `x31` | memory destination; every rotate |
| RISC-V 64 | `x29` | memory destination whose address must be folded |

On x86-64 a register count is swapped into `cl` and back, so `rcx` is preserved; shifting `rcx` itself by another register is rejected.

Byte swap: `bswapi`, `bswapq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | never (register operands only) |
| AArch64 | `x16` | memory or immediate source |
| AArch64 | `x17` | memory destination |
| RISC-V 64 | `x29`, `x31` | always (register operands only) |

Add and subtract with carry: `adcq`, `sbcq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | immediate outside signed 32 bits; memory destination with a memory source |
| AArch64 | `x16` | memory or immediate source; memory address that must be folded |
| AArch64 | `x17` | memory destination |
| RISC-V 64 | `x29`, `x30` | always, also receive emulated flags in `x30`  |
| RISC-V 64 | `x31` | memory destination |

On RISC-V 64 both also push and pop a 48-byte stack slot.

Multiply high: `umulhq`, `smulhq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | never (immediate factors are rejected) |
| AArch64 | `x16` | memory or immediate factor |
| RISC-V 64 | `x31` | memory or immediate factor |

Widening multiply: `smulli`, `umulli`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | always |
| AArch64 | - | never |
| RISC-V 64 | `x29`, `x31` | always |

Three-operand divide and remainder: `divi`, `divis`, `divq`, `divqs`, `remi`, `remis`, `remq`, `remqs`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | immediate divisor; divisor in or addressed through `rax`/`rdx`; destination `rax`/`rdx` |
| AArch64 | `x16` | memory or immediate divisor; memory address that must be folded |
| AArch64 | `x17` | `rem*` always |
| RISC-V 64 | `x31` | memory or immediate dividend or divisor |

On x86-64 `rax` and `rdx` are pushed before the divide and popped after it. On RISC-V 64, a dividend and divisor that both need staging also push and pop an 8-byte stack slot.

Accumulator divide: `idivi`, `udivi`, `idivq`, `udivq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | immediate divisor |
| AArch64 | `x16`, `x17` | always |
| RISC-V 64 | `x31` | always (memory and immediate divisors are rejected) |

Sign extension into the pair: `cdqi`, `cqoq` clobber no scratch register on any target.

Set on less than: `slt`, `sltu`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | immediate left operand; memory left operand with an immediate or memory right operand; immediate outside signed 32 bits |
| AArch64 | `x16` | memory left operand (an immediate left operand is swapped to the right) |
| AArch64 | `x17` | memory right operand; right immediate outside -4095..4095; memory destination |
| RISC-V 64 | `x31` | memory or immediate operand |
| RISC-V 64 | `x29` | memory destination |

On RISC-V 64, a memory left operand with an immediate right operand also pushes and pops an 8-byte stack slot.

Conditional move: `movz`, `movn`, `cmov`, `cmovz`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | memory or immediate source |
| AArch64 | `x16` | memory or immediate source |
| RISC-V 64 | `x31` | memory source whose address must be folded |

Bit counts: `popcnti`, `popcntq`, `tzcnti`, `tzcntq`, `lzcnti`, `lzcntq`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | never |
| AArch64 | `x16` | `popcnt*` always; `tzcnt*`/`lzcnt*` with a memory or immediate source |
| AArch64 | `x17` | `tzcnt*` always |
| AArch64 | `v31` | `popcnt*` always |
| RISC-V 64 | `x29`, `x31` | always |

Floating-point bitwise: `andf`, `andd`, `orf`, `ord`

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | never (immediate sources are rejected) |
| AArch64 | `v31` | memory or immediate source |
| AArch64 | `x16` | immediate source; memory address that must be folded |
| RISC-V 64 | `x29`, `x31` | always |
| RISC-V 64 | `f31` | memory source |

### `addi O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> + X[O3]<31:0>;
```

### `addp O1, O2, O3`

```text
X[O1] = X[O2] + X[O3];
```

### `addq O1, O2, O3`

```text
X[O1] = X[O2] + X[O3];
```

### `subi O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> - X[O3]<31:0>;
```

### `subp O1, O2, O3`

```text
X[O1] = X[O2] - X[O3];
```

### `subq O1, O2, O3`

```text
X[O1] = X[O2] - X[O3];
```

### `muli O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> * X[O3]<31:0>;
```

### `mulp O1, O2, O3`

```text
X[O1] = X[O2] * X[O3];
```

### `mulq O1, O2, O3`

```text
X[O1] = X[O2] * X[O3];
```

### `andi O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> AND X[O3]<31:0>;
```

### `andp O1, O2, O3`

```text
X[O1] = X[O2] AND X[O3];
```

### `andq O1, O2, O3`

```text
X[O1] = X[O2] AND X[O3];
```

### `ori O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> OR X[O3]<31:0>;
```

### `orp O1, O2, O3`

```text
X[O1] = X[O2] OR X[O3];
```

### `orq O1, O2, O3`

```text
X[O1] = X[O2] OR X[O3];
```

### `orh O1, O2, O3`

```text
X[O1]<15:0> = X[O2]<15:0> OR X[O3]<15:0>;
```

### `xori O1, O2, O3`

```text
X[O1]<31:0> = X[O2]<31:0> EOR X[O3]<31:0>;
```

### `xorp O1, O2, O3`

```text
X[O1] = X[O2] EOR X[O3];
```

### `xorq O1, O2, O3`

```text
X[O1] = X[O2] EOR X[O3];
```

### `andf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> AND V[O3]<31:0>;
```

### `andd O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> AND V[O3]<63:0>;
```

### `orf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> OR V[O3]<31:0>;
```

### `ord O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> OR V[O3]<63:0>;
```

### `negi O1`

```text
X[O1]<31:0> = -X[O1]<31:0>;
```

### `negp O1`

```text
X[O1] = -X[O1];
```

### `negq O1`

```text
X[O1] = -X[O1];
```

### `noti O1`

```text
X[O1]<31:0> = NOT(X[O1]<31:0>);
```

### `notq O1`

```text
X[O1] = NOT(X[O1]);
```

### `lshifti O1, O2`

```text
X[O1]<31:0> = LSL(X[O1]<31:0>, UInt(X[O2]<5:0>));
```

### `lshiftp O1, O2`

```text
X[O1] = LSL(X[O1], UInt(X[O2]<5:0>));
```

### `lshiftq O1, O2`

```text
X[O1] = LSL(X[O1], UInt(X[O2]<5:0>));
```

### `rshifti O1, O2`

```text
X[O1]<31:0> = ASR(X[O1]<31:0>, UInt(X[O2]<5:0>));
```

### `rshiftp O1, O2`

```text
X[O1] = ASR(X[O1], UInt(X[O2]<5:0>));
```

### `rshiftq O1, O2`

```text
X[O1] = ASR(X[O1], UInt(X[O2]<5:0>));
```

### `urshifti O1, O2`

```text
X[O1]<31:0> = LSR(X[O1]<31:0>, UInt(X[O2]<5:0>));
```

### `urshiftp O1, O2`

```text
X[O1] = LSR(X[O1], UInt(X[O2]<5:0>));
```

### `urshiftq O1, O2`

```text
X[O1] = LSR(X[O1], UInt(X[O2]<5:0>));
```

### `lrotatei O1, O2`

```text
X[O1]<31:0> = RotateLeft(X[O1]<31:0>, UInt(X[O2]<4:0>));
```

### `lrotateq O1, O2`

```text
X[O1] = RotateLeft(X[O1], UInt(X[O2]<5:0>));
```

### `rrotatei O1, O2`

```text
X[O1]<31:0> = RotateRight(X[O1]<31:0>, UInt(X[O2]<4:0>));
```

### `rrotateq O1, O2`

```text
X[O1] = RotateRight(X[O1], UInt(X[O2]<5:0>));
```

### `bswapi O1, O2`

```text
X[O1]<31:0> = ByteReverse(X[O2]<31:0>);
```

### `bswapq O1, O2`

```text
X[O1] = ByteReverse(X[O2]);
```

### `adcq O1, O2`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], FLAG.C);
X[O1] = result;
FLAG = nzcv;
```

### `sbcq O1, O2`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), FLAG.C);
X[O1] = result;
FLAG = nzcv;
```

### `umulhq O1`

```text
bits(128) product = ZeroExtend(X[t0], 128) * ZeroExtend(X[O1], 128);
X[t0] = product<63:0>;
X[t2] = product<127:64>;
```

### `smulhq O1`

```text
bits(128) product = SignExtend(X[t0], 128) * SignExtend(X[O1], 128);
X[t0] = product<63:0>;
X[t2] = product<127:64>;
```

### `smulli O1, O2, O3`

```text
bits(64) product = SignExtend(X[O2]<31:0>, 64) * SignExtend(X[O3]<31:0>, 64);
X[O1] = product;
```

### `umulli O1, O2, O3`

```text
bits(64) product = ZeroExtend(X[O2]<31:0>, 64) * ZeroExtend(X[O3]<31:0>, 64);
X[O1] = product;
```

### `addqs O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O2], X[O3], '0');
X[O1] = result;
FLAG = nzcv;
```

### `subqs O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O2], NOT(X[O3]), '1');
X[O1] = result;
FLAG = nzcv;
```

### `addis O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O2]<31:0>, X[O3]<31:0>, '0');
X[O1]<31:0> = result;
FLAG = nzcv;
```

### `subis O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O2]<31:0>, NOT(X[O3]<31:0>), '1');
X[O1]<31:0> = result;
FLAG = nzcv;
```

### `oris O1, O2, O3`

```text
bits(32) result = X[O2]<31:0> OR X[O3]<31:0>;
X[O1]<31:0> = result;
FLAG.N = result<31>;
FLAG.Z = IsZeroBit(result);
```

### `addps O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O2], X[O3], '0');
X[O1] = result;
FLAG = nzcv;
```

### `addlshiftp O1, O2, O3, O4`

```text
X[O1] = X[O2] + LSL(X[O3], UInt(X[O4]<5:0>));
```

Scratch: x86-64 `r11` when the shift amount is greater than 3; never on AArch64 or RISC-V 64.

### `divi O1, O2, O3`

```text
X[O1]<31:0> = SInt(X[O2]<31:0>) DIV SInt(X[O3]<31:0>);
```

### `divis O1, O2, O3`

```text
X[O1]<31:0> = SInt(X[O2]<31:0>) DIV SInt(X[O3]<31:0>);
FLAG.Z = IsZeroBit(X[O1]<31:0>);
```

### `divq O1, O2, O3`

```text
X[O1] = SInt(X[O2]) DIV SInt(X[O3]);
```

### `divqs O1, O2, O3`

```text
X[O1] = SInt(X[O2]) DIV SInt(X[O3]);
FLAG.Z = IsZeroBit(X[O1]);
```

### `remi O1, O2, O3`

```text
X[O1]<31:0> = SInt(X[O2]<31:0>) MOD SInt(X[O3]<31:0>);
```

### `remis O1, O2, O3`

```text
X[O1]<31:0> = SInt(X[O2]<31:0>) MOD SInt(X[O3]<31:0>);
FLAG.Z = IsZeroBit(X[O1]<31:0>);
```

### `remq O1, O2, O3`

```text
X[O1] = SInt(X[O2]) MOD SInt(X[O3]);
```

### `remqs O1, O2, O3`

```text
X[O1] = SInt(X[O2]) MOD SInt(X[O3]);
FLAG.Z = IsZeroBit(X[O1]);
```

### `cdqi`

```text
bits(64) widened = SignExtend(X[t0]<31:0>, 64);
X[t0] = widened<31:0>;
X[t2] = widened<63:32>;
```

Splits the 64-bit sign extension of the low word of `X[t0]` across the `X[t2]:X[t0]` pair.

### `cqoq`

```text
bits(128) widened = SignExtend(X[t0], 128);
X[t0] = widened<63:0>;
X[t2] = widened<127:64>;
```

Splits the 128-bit sign extension of `X[t0]` across the `X[t2]:X[t0]` pair.

### `idivi O1`

```text
(X[t0], X[t2]) = (SInt(X[t0]) DIV SInt(X[O1]), SInt(X[t0]) MOD SInt(X[O1]));
```

### `udivi O1`

```text
(X[t0], X[t2]) = (UInt(X[t0]) DIV UInt(X[O1]), UInt(X[t0]) MOD UInt(X[O1]));
```

### `idivq O1`

```text
(X[t0], X[t2]) = (SInt(X[t0]) DIV SInt(X[O1]), SInt(X[t0]) MOD SInt(X[O1]));
```

### `udivq O1`

```text
(X[t0], X[t2]) = (UInt(X[t0]) DIV UInt(X[O1]), UInt(X[t0]) MOD UInt(X[O1]));
```

### `slt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) < SInt(X[O3]) then 1 else 0;
```

### `sltu O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) < UInt(X[O3]) then 1 else 0;
```

### `movz O1, O2, O3`

```text
if IsZeroBit(X[O3]) then
    X[O1] = X[O2];
endif
```

### `movn O1, O2, O3`

```text
if !IsZeroBit(X[O3]) then
    X[O1] = X[O2];
endif
```

### `cmov O1, O2, O3`

```text
if !IsZeroBit(X[O3]) then
    X[O1] = X[O2];
endif
```

### `cmovz O1, O2, O3`

```text
if IsZeroBit(X[O3]) then
    X[O1] = X[O2];
endif
```

### `bfiq O1, O2, O3, O4`

```text
X[O1] = BFXPreserve(X[O1], X[O2], UInt(O3), UInt(O4));
```

Scratch:

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | always |
| AArch64 | `x16` | always |
| AArch64 | `x17` | field width 64 (the masks are not logical immediates) |
| RISC-V 64 | `x31` | always |

`O3`/`O4` are the immediate low-bit position and width of the field taken from `X[O2]` and inserted into `X[O1]`.

### `popcnti O1, O2`

```text
X[O1] = ZeroExtend(BitCount(X[O2]<31:0>), 64);
```

### `popcntq O1, O2`

```text
X[O1] = ZeroExtend(BitCount(X[O2]), 64);
```

### `tzcnti O1, O2`

```text
X[O1] = ZeroExtend(CountTrailingZeroBits(X[O2]<31:0>), 64);
```

### `tzcntq O1, O2`

```text
X[O1] = ZeroExtend(CountTrailingZeroBits(X[O2]), 64);
```

### `lzcnti O1, O2`

```text
X[O1] = ZeroExtend(CountLeadingZeroBits(X[O2]<31:0>), 64);
```

### `lzcntq O1, O2`

```text
X[O1] = ZeroExtend(CountLeadingZeroBits(X[O2]), 64);
```

## 3. Floating-point arithmetic

### Scratch registers

"Address needs folding" means the memory operand cannot be encoded directly: on AArch64 an absolute address, an index plus a nonzero offset, an index scale other than 1 or the access size, or an out-of-range offset; on RISC-V 64 an absolute address, any index, or an offset outside 12 bits.

Binary arithmetic: `addf`, `addd`, `subf`, `subd`, `mulf`, `muld`, `divf`, `divd`, `fmin`, `fmax`, `dmin`, `dmax`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `xmm7` | `subf`/`subd`/`divf`/`divd` only: destination is the right source but not the left, and the left source is memory or AVX is off |
| AArch64 | `v31` | right source is memory, an immediate, or the destination; two-operand source is memory or an immediate |
| AArch64 | `x16` | immediate source; address needs folding |
| RISC-V 64 | `f31` | right source is memory, an immediate, or the destination; two-operand source is memory or an immediate |
| RISC-V 64 | `x31` | immediate source; address needs folding |

Fused multiply-add: `fmaddf`, `fmaddd`, `fmsubf`, `fmsubd`, `fnmaddf`, `fnmaddd`, `fnmsubf`, `fnmsubd`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `xmm7` | always (stages the first factor) |
| AArch64 | `v31` | a factor or the addend is memory or an immediate |
| AArch64 | `x16` | immediate operand; address needs folding |
| RISC-V 64 | `f31` | a factor or the addend is memory or an immediate |
| RISC-V 64 | `x31` | immediate operand; address needs folding |

Square root and rounding: `sqrtf`, `sqrtd`, `roundf`, `roundd`, `floorf`, `floord`, `ceilf`, `ceild`, `truncatef`, `truncated`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `v31` | source is memory or an immediate |
| AArch64 | `x16` | immediate source; address needs folding |
| RISC-V 64 | `f31` | rounding ops: always; `sqrtf`/`sqrtd`: source is memory or an immediate |
| RISC-V 64 | `x31` | rounding ops: always; `sqrtf`/`sqrtd`: immediate source; address needs folding |
| RISC-V 64 | `x29` | rounding ops: always |

Absolute value and negation: `absf`, `absd`, `negf`, `negd`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | always (materializes the sign mask) |
| x86-64 | `xmm7` | memory source, or the source is the destination (the sign mask is built in the destination) |
| AArch64 | `v31` | source is memory or an immediate |
| AArch64 | `x16` | immediate source; address needs folding |
| RISC-V 64 | `f31` | source is memory or an immediate |
| RISC-V 64 | `x31` | immediate source; address needs folding |

Zeroing and vector lane extraction: `movdz`, `umovb`, `umovh`, `umovi`, `umovq`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | - | |
| RISC-V 64 | - | |

On RISC-V 64, `umovb`, `umovh`, and `umovi` spill the holding half of the source through 8 bytes pushed below `sp`, `sp` is restored afterwards.

### `addf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> + V[O3]<31:0>;
```

### `addd O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> + V[O3]<63:0>;
```

### `subf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> - V[O3]<31:0>;
```

### `subd O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> - V[O3]<63:0>;
```

### `mulf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> * V[O3]<31:0>;
```

### `muld O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> * V[O3]<63:0>;
```

### `divf O1, O2, O3`

```text
V[O1]<31:0> = V[O2]<31:0> / V[O3]<31:0>;
```

### `divd O1, O2, O3`

```text
V[O1]<63:0> = V[O2]<63:0> / V[O3]<63:0>;
```

### `fmin O1, O2, O3`

```text
V[O1]<31:0> = Min(V[O2]<31:0>, V[O3]<31:0>);
```

### `fmax O1, O2, O3`

```text
V[O1]<31:0> = Max(V[O2]<31:0>, V[O3]<31:0>);
```

### `dmin O1, O2, O3`

```text
V[O1]<63:0> = Min(V[O2]<63:0>, V[O3]<63:0>);
```

### `dmax O1, O2, O3`

```text
V[O1]<63:0> = Max(V[O2]<63:0>, V[O3]<63:0>);
```

### `fmaddf O1, O2, O3, O4`

```text
V[O1]<31:0> = V[O2]<31:0> * V[O3]<31:0> + V[O4]<31:0>;
```

Requires FMA on x86-64.

### `fmaddd O1, O2, O3, O4`

```text
V[O1]<63:0> = V[O2]<63:0> * V[O3]<63:0> + V[O4]<63:0>;
```

Requires FMA on x86-64.

### `fmsubf O1, O2, O3, O4`

```text
V[O1]<31:0> = V[O2]<31:0> * V[O3]<31:0> - V[O4]<31:0>;
```

Requires FMA on x86-64.

### `fmsubd O1, O2, O3, O4`

```text
V[O1]<63:0> = V[O2]<63:0> * V[O3]<63:0> - V[O4]<63:0>;
```

Requires FMA on x86-64.

### `fnmaddf O1, O2, O3, O4`

```text
V[O1]<31:0> = -(V[O2]<31:0> * V[O3]<31:0>) + V[O4]<31:0>;
```

Requires FMA on x86-64.

### `fnmaddd O1, O2, O3, O4`

```text
V[O1]<63:0> = -(V[O2]<63:0> * V[O3]<63:0>) + V[O4]<63:0>;
```

Requires FMA on x86-64.

### `fnmsubf O1, O2, O3, O4`

```text
V[O1]<31:0> = -(V[O2]<31:0> * V[O3]<31:0>) - V[O4]<31:0>;
```

Requires FMA on x86-64.

### `fnmsubd O1, O2, O3, O4`

```text
V[O1]<63:0> = -(V[O2]<63:0> * V[O3]<63:0>) - V[O4]<63:0>;
```

Requires FMA on x86-64.

### `sqrtf O1, O2`

```text
V[O1]<31:0> = Sqrt(V[O2]<31:0>);
```

### `sqrtd O1, O2`

```text
V[O1]<63:0> = Sqrt(V[O2]<63:0>);
```

### `roundf O1, O2`

```text
V[O1]<31:0> = RoundToNearest(V[O2]<31:0>);
```

### `roundd O1, O2`

```text
V[O1]<63:0> = RoundToNearest(V[O2]<63:0>);
```

### `floorf O1, O2`

```text
V[O1]<31:0> = FloorToIntegral(V[O2]<31:0>);
```

### `floord O1, O2`

```text
V[O1]<63:0> = FloorToIntegral(V[O2]<63:0>);
```

### `ceilf O1, O2`

```text
V[O1]<31:0> = CeilToIntegral(V[O2]<31:0>);
```

### `ceild O1, O2`

```text
V[O1]<63:0> = CeilToIntegral(V[O2]<63:0>);
```

### `truncatef O1, O2`

```text
V[O1]<31:0> = TruncateToIntegral(V[O2]<31:0>);
```

### `truncated O1, O2`

```text
V[O1]<63:0> = TruncateToIntegral(V[O2]<63:0>);
```

### `absf O1, O2`

```text
V[O1]<31:0> = Abs(V[O2]<31:0>);
```

### `absd O1, O2`

```text
V[O1]<63:0> = Abs(V[O2]<63:0>);
```

### `negf O1, O2`

```text
V[O1]<31:0> = -V[O2]<31:0>;
```

### `negd O1, O2`

```text
V[O1]<63:0> = -V[O2]<63:0>;
```

### `movdz O1`

```text
V[O1]<63:0> = 0.0;
```

### `umovb O1, O2, O3`

```text
X[O1] = ZeroExtend(V[O2]<UInt(O3) * 8 + 7 : UInt(O3) * 8>, 64);
```

### `umovh O1, O2, O3`

```text
X[O1] = ZeroExtend(V[O2]<UInt(O3) * 16 + 15 : UInt(O3) * 16>, 64);
```

### `umovi O1, O2, O3`

```text
X[O1] = ZeroExtend(V[O2]<UInt(O3) * 32 + 31 : UInt(O3) * 32>, 64);
```

### `umovq O1, O2, O3`

```text
X[O1] = V[O2]<UInt(O3) * 64 + 63 : UInt(O3) * 64>;
```

## 4. Conversions

### Scratch registers

Float-to-int truncations: `truncatef2is`, `truncated2is`, `truncatef2i`, `truncatef2qs`, `truncated2i`, `truncated2qs`, `td2i`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | - |
| AArch64 | `x16` | always (overflow/NaN result fixup); memory address needs folding |
| AArch64 | `v31` | source is memory or an immediate |
| RISC-V 64 | `x31` | always (overflow result fixup); memory address needs folding |
| RISC-V 64 | `f31` | source is memory or an immediate |

Unsigned-range truncations: `truncatef2q`, `truncated2q`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11`, `xmm7` | always |
| AArch64 | `x16`, `v31` | always |
| RISC-V 64 | `x31`, `f31` | always |

Int-to-float conversions: `ci2d`, `ci2ds`, `ci2f`, `ci2fs`, `cq2fs`, `cq2ds`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | - |
| AArch64 | `x16` | source is memory or an immediate |
| RISC-V 64 | `x31` | source is memory or an immediate |

Unsigned quad-to-float conversions: `cq2f`, `cq2d`. The caller-supplied `O3` is also clobbered.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | source is negative (halving path) |
| AArch64 | `x16` | source is negative (halving path); source is memory |
| RISC-V 64 | `x31` | source is negative (halving path); source is memory |

Float-to-float conversions: `cd2f`, `cf2d`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | - |
| AArch64 | `v31` | source is memory or an immediate |
| AArch64 | `x16` | memory address needs folding; immediate source |
| RISC-V 64 | `f31` | source is memory or an immediate |
| RISC-V 64 | `x31` | memory address needs folding; immediate source |

Bit-casts: `fq2d`, `fd2q`, `fi2f`, `ff2i`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | - |
| AArch64 | - | - |
| RISC-V 64 | - | - |

### `truncatef2is O1, O2`

```text
X[O1] = SignExtend(FPToFixed(V[O2]<31:0>, 32, RoundTowardsZero), 64);
```

### `truncated2is O1, O2`

```text
X[O1] = SignExtend(FPToFixed(V[O2]<63:0>, 32, RoundTowardsZero), 64);
```

### `truncatef2i O1, O2`

```text
X[O1] = ZeroExtend(FPToFixed(V[O2]<31:0>, 32, RoundTowardsZero), 64);
```

### `truncatef2qs O1, O2`

```text
X[O1] = FPToFixed(V[O2]<31:0>, 64, RoundTowardsZero);
```

### `truncated2i O1, O2`

```text
X[O1] = ZeroExtend(FPToFixed(V[O2]<63:0>, 32, RoundTowardsZero), 64);
```

### `truncated2qs O1, O2`

```text
X[O1] = FPToFixed(V[O2]<63:0>, 64, RoundTowardsZero);
```

### `truncatef2q O1, O2`

```text
X[O1] = FPToFixed(V[O2]<31:0>, 64, RoundTowardsZero);
```

### `truncated2q O1, O2`

```text
X[O1] = FPToFixed(V[O2]<63:0>, 64, RoundTowardsZero);
```

### `ci2d O1, O2`

```text
V[O2]<63:0> = FixedToFP(SInt(X[O1]<31:0>), 64);
```

### `ci2ds O1, O2`

```text
V[O2]<63:0> = FixedToFP(SInt(X[O1]<31:0>), 64);
```

### `ci2f O1, O2`

```text
V[O2]<31:0> = FixedToFP(SInt(X[O1]<31:0>), 32);
```

### `ci2fs O1, O2`

```text
V[O2]<31:0> = FixedToFP(SInt(X[O1]<31:0>), 32);
```

### `cq2fs O1, O2`

```text
V[O2]<31:0> = FixedToFP(SInt(X[O1]), 32);
```

### `cq2f O1, O2`

```text
V[O1]<31:0> = FixedToFP(SInt(X[O2]), 32);
```

`O3` names the scratch register the lowering may use.

### `cq2d O1, O2`

```text
V[O1]<63:0> = FixedToFP(SInt(X[O2]), 64);
```

`O3` names the scratch register the lowering may use.

### `cq2ds O1, O2`

```text
V[O2]<63:0> = FixedToFP(SInt(X[O1]), 64);
```

### `cd2f O1, O2`

```text
V[O1]<31:0> = FPConvert(V[O2]<63:0>, 32);
```

### `cf2d O1, O2`

```text
V[O1]<63:0> = FPConvert(V[O2]<31:0>, 64);
```

### `fq2d O1, O2`

```text
V[O1]<63:0> = V[O2];
```

Reinterprets the 64 bits of `X[O2]` as an `f64` bit pattern.

### `fd2q O1, O2`

```text
X[O1] = V[O2]<63:0>;
```

Reinterprets the 64 bits of the `f64` register `V[O2]` as an integer bit pattern.

### `fi2f O1, O2`

```text
V[O1]<31:0> = X[O2]<31:0>;
```

Reinterprets the low 32 bits of `X[O2]` as an `f32` bit pattern.

### `ff2i O1, O2`

```text
X[O1] = ZeroExtend(V[O2]<31:0>, 64);
```

Reinterprets the `f32` bit pattern of `V[O2]` as an integer.

### `btd2i O1, O2, O3`

```text
X[O1] = FPToFixed(V[O2]<63:0>, 32, RoundTowardsZero);
if X[O1] == 0x80000000 then
    BranchTo(O3);
endif
```

Scratch: same as the float-to-int truncations, plus AArch64 `x17` always (the `0x80000000` compare immediate).

### `td2i O1, O2`

```text
X[O1] = ZeroExtend(FPToFixed(V[O2]<63:0>, 32, RoundTowardsZero), 64);
```

### `bcd2i O1, O2, O3`

```text
X[O1] = ZeroExtend(FPToFixed(V[O2]<63:0>, 32, RoundTowardsZero), 64);
if InexactConversion() then
    BranchTo(O3);
endif
```

Scratch: same as the float-to-int truncations, plus x86-64 `xmm7`, AArch64 `v31`, and RISC-V 64 `f31` always (round-trip compare).

## 5. Comparing and testing values

### Scratch registers

No opcode in this section touches the RISC-V 64 flags register `x30`.

Integer compare and set: `cieq`, `cineq`, `cia`, `ciaeq`, `cib`, `cibeq`, `cigt`, `cigteq`, `cilt`, `cilteq`, and the same conditions for `cb*`, `cp*`, `cq*`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | O2 is an immediate (except `0` against a register in `eq`/`neq` forms); O3 is an immediate too wide for the operand size (outside signed 32 bits for `cp*`/`cq*`); O2 is memory and O3 is an immediate or memory |
| AArch64 | `x16` | O2 is memory; O2 is an immediate and O3 is memory; both are immediates; `cbgt`, `cbgteq`, `cblt`, `cblteq` (always); an address needs synthesis |
| AArch64 | `x17` | O3 is memory and O2 is not an immediate; an immediate outside `-4095..4095`; `cbgt`, `cbgteq`, `cblt`, `cblteq` (always); memory destination |
| RISC-V 64 | `x31` | O2 or O3 is an immediate (any value) or memory; an address needs synthesis |
| RISC-V 64 | `x29` | memory destination |

On RISC-V 64, when both O2 and O3 need staging, O2 is saved on the stack below `sp` instead of in a second scratch register, and the 8- and 32-bit forms (`ci*`, `cb*`) sign- or zero-extend register operands O2 and O3 to 64 bits in place.

Float compare and set: `cfeq`, `cfneq`, `cfnequn`, `cfgt`, `cfgteq`, `cflt`, `cflteq`, and the same conditions for `cd*`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `xmm7` | the operand `ucomis*` takes first is memory: O2 for `cfneq`, `cfgt`, `cfgteq`; O3 for `cfeq`, `cfnequn`, `cflt`, `cflteq` |
| AArch64 | `v31` | a source is memory or an immediate |
| AArch64 | `x16` | a source is an immediate; an address needs synthesis |
| AArch64 | `x17` | memory destination |
| RISC-V 64 | `x29` | always |
| RISC-V 64 | `x31` | `cfneq`, `cdneq` (always); a source is an immediate; an address needs synthesis |
| RISC-V 64 | `f31` | a source is memory or an immediate |

Test and set: `tis`, `tiz`, `tinz`, `tps`, `tpz`, `tpnz`, `tqs`, `tqz`, `tqnz`, `tbs`, `tbz`, `tbnz`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | a mask must be a register or an encodable immediate |
| AArch64 | `x16` | O2 is memory or an immediate; an address needs synthesis |
| AArch64 | `x17` | the mask is not a register; `tbs`, `tbz`, `tbnz` (always); memory destination |
| RISC-V 64 | `x29` | always |
| RISC-V 64 | `x31` | O2 is memory or an immediate; the mask is not a register; an address needs synthesis |

On AArch64 a mask applies to a register O2 in place (`and O2, O2, mask`), so O2 itself is clobbered.

### `cieq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) == SInt(X[O3]<31:0>) then 1 else 0;
```

### `cineq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) != SInt(X[O3]<31:0>) then 1 else 0;
```

### `cia O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<31:0>) > UInt(X[O3]<31:0>) then 1 else 0;
```

### `ciaeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<31:0>) >= UInt(X[O3]<31:0>) then 1 else 0;
```

### `cib O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<31:0>) < UInt(X[O3]<31:0>) then 1 else 0;
```

### `cibeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<31:0>) <= UInt(X[O3]<31:0>) then 1 else 0;
```

### `cigt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) > SInt(X[O3]<31:0>) then 1 else 0;
```

### `cigteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) >= SInt(X[O3]<31:0>) then 1 else 0;
```

### `cilt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) < SInt(X[O3]<31:0>) then 1 else 0;
```

### `cilteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<31:0>) <= SInt(X[O3]<31:0>) then 1 else 0;
```

### `cbeq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) == SInt(X[O3]<7:0>) then 1 else 0;
```

### `cbneq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) != SInt(X[O3]<7:0>) then 1 else 0;
```

### `cba O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<7:0>) > UInt(X[O3]<7:0>) then 1 else 0;
```

### `cbaeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<7:0>) >= UInt(X[O3]<7:0>) then 1 else 0;
```

### `cbb O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<7:0>) < UInt(X[O3]<7:0>) then 1 else 0;
```

### `cbbeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]<7:0>) <= UInt(X[O3]<7:0>) then 1 else 0;
```

### `cbgt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) > SInt(X[O3]<7:0>) then 1 else 0;
```

### `cbgteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) >= SInt(X[O3]<7:0>) then 1 else 0;
```

### `cblt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) < SInt(X[O3]<7:0>) then 1 else 0;
```

### `cblteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]<7:0>) <= SInt(X[O3]<7:0>) then 1 else 0;
```

### `cpeq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) == SInt(X[O3]) then 1 else 0;
```

### `cpneq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) != SInt(X[O3]) then 1 else 0;
```

### `cpa O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) > UInt(X[O3]) then 1 else 0;
```

### `cpaeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) >= UInt(X[O3]) then 1 else 0;
```

### `cpb O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) < UInt(X[O3]) then 1 else 0;
```

### `cpbeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) <= UInt(X[O3]) then 1 else 0;
```

### `cpgt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) > SInt(X[O3]) then 1 else 0;
```

### `cpgteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) >= SInt(X[O3]) then 1 else 0;
```

### `cplt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) < SInt(X[O3]) then 1 else 0;
```

### `cplteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) <= SInt(X[O3]) then 1 else 0;
```

### `cqeq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) == SInt(X[O3]) then 1 else 0;
```

### `cqneq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) != SInt(X[O3]) then 1 else 0;
```

### `cqa O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) > UInt(X[O3]) then 1 else 0;
```

### `cqaeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) >= UInt(X[O3]) then 1 else 0;
```

### `cqb O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) < UInt(X[O3]) then 1 else 0;
```

### `cqbeq O1, O2, O3`

```text
X[O1] = if UInt(X[O2]) <= UInt(X[O3]) then 1 else 0;
```

### `cqgt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) > SInt(X[O3]) then 1 else 0;
```

### `cqgteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) >= SInt(X[O3]) then 1 else 0;
```

### `cqlt O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) < SInt(X[O3]) then 1 else 0;
```

### `cqlteq O1, O2, O3`

```text
X[O1] = if SInt(X[O2]) <= SInt(X[O3]) then 1 else 0;
```

### `cfeq O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> == V[O3]<31:0> then 1 else 0;
```

### `cfneq O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> != V[O3]<31:0> then 1 else 0;
```

### `cfnequn O1, O2, O3`

```text
X[O1] = if IsUnordered(V[O2]<31:0>, V[O3]<31:0>) || V[O2]<31:0> != V[O3]<31:0> then 1 else 0;
```

### `cfgt O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> > V[O3]<31:0> then 1 else 0;
```

### `cfgteq O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> >= V[O3]<31:0> then 1 else 0;
```

### `cflt O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> < V[O3]<31:0> then 1 else 0;
```

### `cflteq O1, O2, O3`

```text
X[O1] = if V[O2]<31:0> <= V[O3]<31:0> then 1 else 0;
```

### `cdeq O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> == V[O3]<63:0> then 1 else 0;
```

### `cdneq O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> != V[O3]<63:0> then 1 else 0;
```

### `cdnequn O1, O2, O3`

```text
X[O1] = if IsUnordered(V[O2]<63:0>, V[O3]<63:0>) || V[O2]<63:0> != V[O3]<63:0> then 1 else 0;
```

### `cdgt O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> > V[O3]<63:0> then 1 else 0;
```

### `cdgteq O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> >= V[O3]<63:0> then 1 else 0;
```

### `cdlt O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> < V[O3]<63:0> then 1 else 0;
```

### `cdlteq O1, O2, O3`

```text
X[O1] = if V[O2]<63:0> <= V[O3]<63:0> then 1 else 0;
```

### `tis O1, O2`

```text
X[O1] = if SInt(X[O2]<31:0>) < 0 then 1 else 0;
```

### `tiz O1, O2`

```text
X[O1] = if IsZeroBit(X[O2]<31:0>) then 1 else 0;
```

### `tinz O1, O2`

```text
X[O1] = if !IsZeroBit(X[O2]<31:0>) then 1 else 0;
```

### `tps O1, O2`

```text
X[O1] = if SInt(X[O2]<63:0>) < 0 then 1 else 0;
```

### `tpz O1, O2`

```text
X[O1] = if IsZeroBit(X[O2]<63:0>) then 1 else 0;
```

### `tpnz O1, O2`

```text
X[O1] = if !IsZeroBit(X[O2]<63:0>) then 1 else 0;
```

### `tqs O1, O2`

```text
X[O1] = if SInt(X[O2]<63:0>) < 0 then 1 else 0;
```

### `tqz O1, O2`

```text
X[O1] = if IsZeroBit(X[O2]<63:0>) then 1 else 0;
```

### `tqnz O1, O2`

```text
X[O1] = if !IsZeroBit(X[O2]<63:0>) then 1 else 0;
```

### `tbs O1, O2`

```text
X[O1] = if SInt(X[O2]<7:0>) < 0 then 1 else 0;
```

### `tbz O1, O2`

```text
X[O1] = if IsZeroBit(X[O2]<7:0>) then 1 else 0;
```

### `tbnz O1, O2`

```text
X[O1] = if !IsZeroBit(X[O2]<7:0>) then 1 else 0;
```

## 6. Branches and control flow

Every branch in this section accepts `#[patch]` in `onlineasm` (a jump site),
except float conditions that expand to several branches and the
overflow-of-`or` arithmetic branch; see
[Patching emitted code](#patching-emitted-code).

### Scratch registers

Integer compare branches: `bieq`, `bineq`, `bia`, `biaeq`, `bib`, `bibeq`, `bigt`, `bigteq`, `bilt`, `bilteq`, and the same conditions for `bb*`, `bp*`, `bq*`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | O1 is an immediate (except `0` against a register in `eq`/`neq` forms); O2 is an immediate too wide for the operand size (outside signed 32 bits for `bp*`/`bq*`); O1 is memory and O2 is an immediate or memory |
| AArch64 | `x16` | O1 is memory; O1 is an immediate and O2 is memory; both are immediates; `bbgt`, `bbgteq`, `bblt`, `bblteq` (always); an address needs synthesis |
| AArch64 | `x17` | O2 is memory and O1 is not an immediate; an immediate outside `-4095..4095`; `bbgt`, `bbgteq`, `bblt`, `bblteq` (always) |
| RISC-V 64 | `x31` | O1 or O2 is an immediate (any value) or memory; `bigt`, `bigteq`, `bilt`, `bilteq`, `bbgt`, `bbgteq`, `bblt`, `bblteq` (always); an address needs synthesis |
| RISC-V 64 | `x29` | both O1 and O2 are immediates or memory; `bigt`, `bigteq`, `bilt`, `bilteq`, `bbgt`, `bbgteq`, `bblt`, `bblteq` (always) |

On RISC-V 64 the signed 8- and 32-bit forms sign-extend both sides into `x31` and `x29` even when they are registers.

Test branches: `btis`, `btiz`, `btinz`, `btps`, `btpz`, `btpnz`, `btqs`, `btqz`, `btqnz`, `btbs`, `btbz`, `btbnz`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | a mask must be a register or an encodable immediate |
| AArch64 | `x16` | O1 is memory or an immediate; an address needs synthesis |
| AArch64 | `x17` | the mask is not a register; `btbs`, `btbz`, `btbnz` with a mask or a memory O1 |
| RISC-V 64 | `x31` | O1 is memory or an immediate; the mask is not a register; an address needs synthesis |
| RISC-V 64 | `x29` | a mask is given (except a register mask over a memory or immediate O1); `btis`, `btps`, `btqs`, `btbs` (always) |

Without a mask, a register O1 needs no scratch on AArch64 (`cbz`, `cbnz`, `tbnz`), and neither does a zero or non-zero test of a register on RISC-V 64. On AArch64 a mask applies to a register O1 in place (`and O1, O1, mask`), so O1 itself is clobbered.

Arithmetic branches: `baddio`, `baddis`, `baddiz`, `baddinz`, and the same flags for `baddp*`, `baddq*`, `bsubi*`, `bsubp*`, `bsubq*`, `bmuli*`, `bmulp*`, `bmulq*`, `bori*`, `borp*`, `borq*`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | an immediate outside signed 32 bits; a memory source with a memory destination; `bmul*` with a memory destination; `dst = lhs - dst`; a memory operand addressed through the destination register |
| AArch64 | `x16` | `bmulio`, `bmulpo`, `bmulqo` (always); `bmul*`/`bor*` `s`/`z`/`nz` forms with a memory destination; a memory source or unencodable immediate with a memory destination; a memory operand addressed through the destination register; an address needs synthesis |
| AArch64 | `x17` | `bmulio`, `bmulpo`, `bmulqo` (always); a memory source; an immediate the instruction cannot encode (any `bmul*` immediate); memory destination; `dst = lhs - dst`; a second memory operand addressed through the destination register |
| RISC-V 64 | `x30` | `badd*o`, `bsub*o`, `bmul*o` (always) |
| RISC-V 64 | `x31` | `baddio`, `bsubio`, `bmulio`, `bmulpo`, `bmulqo` (always); `baddis`, `bsubis`, `bmulis`, `boris` with a register destination; a memory source or destination; an immediate outside 12 bits (any `bmul*` immediate); `dst = lhs - dst`; a memory operand addressed through the destination register; an address needs synthesis |
| RISC-V 64 | `x29` | `badd*o`, `bsub*o` unless the source is a 12-bit immediate; `bmulio` (always); `bmulpo`, `bmulqo` when the source is not a register; a memory destination whose address needs synthesis; a second memory operand addressed through the destination register |

`bmulpo` and `bmulqo` on AArch64 also use 16 bytes below `sp` when both factors are staged.

Float branches: `bdeq`, `bdneq`, `bdgt`, `bdgteq`, `bdlt`, `bdlteq`, `bdequn`, `bdnequn`, `bdgtun`, `bdgtequn`, `bdltun`, `bdltequn`, `bfeq`, `bfgt`, `bfgteq`, `bflt`, `bfgtun`, `bfgtequn`, `bfltun`, `bfltequn`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `xmm7` | the operand `ucomis*` takes first is memory: O1, or O2 for `bdlt`, `bdlteq`, `bdltun`, `bdltequn`, `bflt`, `bfltun`, `bfltequn` |
| AArch64 | `v31` | a source is memory or an immediate |
| AArch64 | `x16` | a source is an immediate; an address needs synthesis |
| RISC-V 64 | `x31` | always |
| RISC-V 64 | `x29` | `bdequn`, `bdgtun`, `bdgtequn`, `bdltun`, `bdltequn`, `bfgtun`, `bfgtequn`, `bfltun`, `bfltequn` (always) |
| RISC-V 64 | `f31` | a source is memory or an immediate |

AArch64 and RISC-V 64 reject two non-register sources.

Flag branches: `bo`, `bs`, `bz`, `bnz`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | - | |
| RISC-V 64 | `x31` | always (the flag bit is masked out of `x30`) |

Jumps and calls: `jmp`, `call`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | absolute-address target |
| AArch64 | `x16` | memory-indirect, absolute-address, or far extern target |
| RISC-V 64 | `x31` | memory-indirect, absolute-address, or far extern target; `jmp` to a near extern |

`ret`, `break`, and `nop` clobber no scratch register on any target.

### `bieq O1, O2, O3`

```text
if SInt(X[O1]<31:0>) == SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bineq O1, O2, O3`

```text
if SInt(X[O1]<31:0>) != SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bia O1, O2, O3`

```text
if UInt(X[O1]<31:0>) > UInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `biaeq O1, O2, O3`

```text
if UInt(X[O1]<31:0>) >= UInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bib O1, O2, O3`

```text
if UInt(X[O1]<31:0>) < UInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bibeq O1, O2, O3`

```text
if UInt(X[O1]<31:0>) <= UInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bigt O1, O2, O3`

```text
if SInt(X[O1]<31:0>) > SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bigteq O1, O2, O3`

```text
if SInt(X[O1]<31:0>) >= SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bilt O1, O2, O3`

```text
if SInt(X[O1]<31:0>) < SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bilteq O1, O2, O3`

```text
if SInt(X[O1]<31:0>) <= SInt(X[O2]<31:0>) then
    BranchTo(O3);
endif
```

### `bbeq O1, O2, O3`

```text
if SInt(X[O1]<7:0>) == SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbneq O1, O2, O3`

```text
if SInt(X[O1]<7:0>) != SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bba O1, O2, O3`

```text
if UInt(X[O1]<7:0>) > UInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbaeq O1, O2, O3`

```text
if UInt(X[O1]<7:0>) >= UInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbb O1, O2, O3`

```text
if UInt(X[O1]<7:0>) < UInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbbeq O1, O2, O3`

```text
if UInt(X[O1]<7:0>) <= UInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbgt O1, O2, O3`

```text
if SInt(X[O1]<7:0>) > SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bbgteq O1, O2, O3`

```text
if SInt(X[O1]<7:0>) >= SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bblt O1, O2, O3`

```text
if SInt(X[O1]<7:0>) < SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bblteq O1, O2, O3`

```text
if SInt(X[O1]<7:0>) <= SInt(X[O2]<7:0>) then
    BranchTo(O3);
endif
```

### `bpeq O1, O2, O3`

```text
if SInt(X[O1]) == SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpneq O1, O2, O3`

```text
if SInt(X[O1]) != SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpa O1, O2, O3`

```text
if UInt(X[O1]) > UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpaeq O1, O2, O3`

```text
if UInt(X[O1]) >= UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpb O1, O2, O3`

```text
if UInt(X[O1]) < UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpbeq O1, O2, O3`

```text
if UInt(X[O1]) <= UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpgt O1, O2, O3`

```text
if SInt(X[O1]) > SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bpgteq O1, O2, O3`

```text
if SInt(X[O1]) >= SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bplt O1, O2, O3`

```text
if SInt(X[O1]) < SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bplteq O1, O2, O3`

```text
if SInt(X[O1]) <= SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqeq O1, O2, O3`

```text
if SInt(X[O1]) == SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqneq O1, O2, O3`

```text
if SInt(X[O1]) != SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqa O1, O2, O3`

```text
if UInt(X[O1]) > UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqaeq O1, O2, O3`

```text
if UInt(X[O1]) >= UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqb O1, O2, O3`

```text
if UInt(X[O1]) < UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqbeq O1, O2, O3`

```text
if UInt(X[O1]) <= UInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqgt O1, O2, O3`

```text
if SInt(X[O1]) > SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqgteq O1, O2, O3`

```text
if SInt(X[O1]) >= SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqlt O1, O2, O3`

```text
if SInt(X[O1]) < SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `bqlteq O1, O2, O3`

```text
if SInt(X[O1]) <= SInt(X[O2]) then
    BranchTo(O3);
endif
```

### `btis O1, O2`

```text
if SInt(X[O1]<31:0>) < 0 then
    BranchTo(O2);
endif
```

### `btiz O1, O2`

```text
if IsZeroBit(X[O1]<31:0>) then
    BranchTo(O2);
endif
```

### `btinz O1, O2`

```text
if !IsZeroBit(X[O1]<31:0>) then
    BranchTo(O2);
endif
```

### `btps O1, O2`

```text
if SInt(X[O1]<63:0>) < 0 then
    BranchTo(O2);
endif
```

### `btpz O1, O2`

```text
if IsZeroBit(X[O1]<63:0>) then
    BranchTo(O2);
endif
```

### `btpnz O1, O2`

```text
if !IsZeroBit(X[O1]<63:0>) then
    BranchTo(O2);
endif
```

### `btqs O1, O2`

```text
if SInt(X[O1]<63:0>) < 0 then
    BranchTo(O2);
endif
```

### `btqz O1, O2`

```text
if IsZeroBit(X[O1]<63:0>) then
    BranchTo(O2);
endif
```

### `btqnz O1, O2`

```text
if !IsZeroBit(X[O1]<63:0>) then
    BranchTo(O2);
endif
```

### `btbs O1, O2`

```text
if SInt(X[O1]<7:0>) < 0 then
    BranchTo(O2);
endif
```

### `btbz O1, O2`

```text
if IsZeroBit(X[O1]<7:0>) then
    BranchTo(O2);
endif
```

### `btbnz O1, O2`

```text
if !IsZeroBit(X[O1]<7:0>) then
    BranchTo(O2);
endif
```

### `baddio O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, X[O2]<31:0>, '0');
X[O1]<31:0> = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `baddis O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, X[O2]<31:0>, '0');
X[O1]<31:0> = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `baddiz O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, X[O2]<31:0>, '0');
X[O1]<31:0> = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `baddinz O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, X[O2]<31:0>, '0');
X[O1]<31:0> = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `baddpo O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `baddps O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `baddpz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `baddpnz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `baddqo O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `baddqs O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `baddqz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `baddqnz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], X[O2], '0');
X[O1] = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `bsubio O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, NOT(X[O2]<31:0>), '1');
X[O1]<31:0> = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `bsubis O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, NOT(X[O2]<31:0>), '1');
X[O1]<31:0> = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `bsubiz O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, NOT(X[O2]<31:0>), '1');
X[O1]<31:0> = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `bsubinz O1, O2, O3`

```text
(bits(32) result, bits(4) nzcv) = AddWithCarry(X[O1]<31:0>, NOT(X[O2]<31:0>), '1');
X[O1]<31:0> = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `bmulio O1, O2, O3`

```text
(bits(32) result, bit overflow) = MulWithOverflow(X[O1]<31:0>, X[O2]<31:0>);
X[O1]<31:0> = result;
if overflow == '1' then
    BranchTo(O3);
endif
```

### `bmulis O1, O2, O3`

```text
(bits(32) result, bit overflow) = MulWithOverflow(X[O1]<31:0>, X[O2]<31:0>);
X[O1]<31:0> = result;
if result<31> == '1' then
    BranchTo(O3);
endif
```

### `bmuliz O1, O2, O3`

```text
(bits(32) result, bit overflow) = MulWithOverflow(X[O1]<31:0>, X[O2]<31:0>);
X[O1]<31:0> = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bmulinz O1, O2, O3`

```text
(bits(32) result, bit overflow) = MulWithOverflow(X[O1]<31:0>, X[O2]<31:0>);
X[O1]<31:0> = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bsubqo O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `bsubqs O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `bsubqz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `bsubqnz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `bsubpo O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.V == '1' then
    BranchTo(O3);
endif
```

### `bsubps O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.N == '1' then
    BranchTo(O3);
endif
```

### `bsubpz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.Z == '1' then
    BranchTo(O3);
endif
```

### `bsubpnz O1, O2, O3`

```text
(bits(64) result, bits(4) nzcv) = AddWithCarry(X[O1], NOT(X[O2]), '1');
X[O1] = result;
if nzcv.Z != '1' then
    BranchTo(O3);
endif
```

### `bmulqo O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if overflow == '1' then
    BranchTo(O3);
endif
```

### `bmulqs O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if result<63> == '1' then
    BranchTo(O3);
endif
```

### `bmulqz O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bmulqnz O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bmulpo O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if overflow == '1' then
    BranchTo(O3);
endif
```

### `bmulps O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if result<63> == '1' then
    BranchTo(O3);
endif
```

### `bmulpz O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bmulpnz O1, O2, O3`

```text
(bits(64) result, bit overflow) = MulWithOverflow(X[O1], X[O2]);
X[O1] = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borqo O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
// bitwise OR cannot overflow: this branch is never taken
if FALSE then
    BranchTo(O3);
endif
```

### `borqs O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if result<63> == '1' then
    BranchTo(O3);
endif
```

### `borqz O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borqnz O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borpo O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
// bitwise OR cannot overflow: this branch is never taken
if FALSE then
    BranchTo(O3);
endif
```

### `borps O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if result<63> == '1' then
    BranchTo(O3);
endif
```

### `borpz O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borpnz O1, O2, O3`

```text
bits(64) result = X[O1] OR X[O2];
X[O1] = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borio O1, O2, O3`

```text
bits(32) result = X[O1]<31:0> OR X[O2]<31:0>;
X[O1]<31:0> = result;
// bitwise OR cannot overflow: this branch is never taken
if FALSE then
    BranchTo(O3);
endif
```

### `boris O1, O2, O3`

```text
bits(32) result = X[O1]<31:0> OR X[O2]<31:0>;
X[O1]<31:0> = result;
if result<31> == '1' then
    BranchTo(O3);
endif
```

### `boriz O1, O2, O3`

```text
bits(32) result = X[O1]<31:0> OR X[O2]<31:0>;
X[O1]<31:0> = result;
if IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `borinz O1, O2, O3`

```text
bits(32) result = X[O1]<31:0> OR X[O2]<31:0>;
X[O1]<31:0> = result;
if !IsZeroBit(result) then
    BranchTo(O3);
endif
```

### `bdeq O1, O2, O3`

```text
if V[O1]<63:0> == V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdneq O1, O2, O3`

```text
if V[O1]<63:0> != V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdgt O1, O2, O3`

```text
if V[O1]<63:0> > V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdgteq O1, O2, O3`

```text
if V[O1]<63:0> >= V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdlt O1, O2, O3`

```text
if V[O1]<63:0> < V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdlteq O1, O2, O3`

```text
if V[O1]<63:0> <= V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdequn O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> == V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdnequn O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> != V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdgtun O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> > V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdgtequn O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> >= V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdltun O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> < V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bdltequn O1, O2, O3`

```text
if IsUnordered(V[O1]<63:0>, V[O2]<63:0>) || V[O1]<63:0> <= V[O2]<63:0> then
    BranchTo(O3);
endif
```

### `bfeq O1, O2, O3`

```text
if V[O1]<31:0> == V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfgt O1, O2, O3`

```text
if V[O1]<31:0> > V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfgteq O1, O2, O3`

```text
if V[O1]<31:0> >= V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bflt O1, O2, O3`

```text
if V[O1]<31:0> < V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfgtun O1, O2, O3`

```text
if IsUnordered(V[O1]<31:0>, V[O2]<31:0>) || V[O1]<31:0> > V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfgtequn O1, O2, O3`

```text
if IsUnordered(V[O1]<31:0>, V[O2]<31:0>) || V[O1]<31:0> >= V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfltun O1, O2, O3`

```text
if IsUnordered(V[O1]<31:0>, V[O2]<31:0>) || V[O1]<31:0> < V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bfltequn O1, O2, O3`

```text
if IsUnordered(V[O1]<31:0>, V[O2]<31:0>) || V[O1]<31:0> <= V[O2]<31:0> then
    BranchTo(O3);
endif
```

### `bo O1`

```text
if FLAG.V == '1' then
    BranchTo(O1);
endif
```

### `bs O1`

```text
if FLAG.N == '1' then
    BranchTo(O1);
endif
```

### `bz O1`

```text
if FLAG.Z == '1' then
    BranchTo(O1);
endif
```

### `bnz O1`

```text
if FLAG.Z == '0' then
    BranchTo(O1);
endif
```

### `jmp O1`

```text
BranchTo(O1);
```

Accepts `#[patch]` in `onlineasm` with a label `O1` (see
[Patching emitted code](#patching-emitted-code)); `#[patch_abs]` takes an
absolute target instead. `O1` may be an [external symbol](#external-symbols).

### `call O1`

```text
LR = PC;
BranchTo(O1);
```

Accepts `#[patch]` in `onlineasm` with a label `O1` (see
[Patching emitted code](#patching-emitted-code)); `#[patch_abs]` takes an
absolute target instead. `O1` may be an [external symbol](#external-symbols).

On RISC-V 64, `call` keeps `ra`: it spills `ra` to a 16-byte slot below `sp` around the transfer,
so the callee starts with `sp` 16 bytes lower and `ra` is unchanged when the call returns. On x86-64
the callee starts 8 bytes lower (the pushed return address). On AArch64 `sp` is unchanged and `LR` is
overwritten.

On rloop, a label target (or a register holding a label address from `leap`) is an interpreted
call: `LR` gets the return point and `ret` goes back to it, as on AArch64 and RISC-V. Any other target
is a native function address, called through the host's `call_native` hook with `t0`/`t1` as
arguments and its result in `t0`/`t1`. Portable code therefore saves `lr` around calls on every
target except x86-64, rloop included.

### `ret`

```text
BranchTo(LR);
```

### `break`

```text
Trap();
```

### `nop`

```text
// no operation
```

## 7. Atomics, fences, and system operations

### Scratch registers

Fetch-and-add, fetch-and-subtract, and exchange: `atomicxchgadd{b,h,i,q}`, `atomicxchgsub{b,h,i,q}`, `atomicxchg{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address has an offset or an index (LSE atomics take only `[Xn]`) |
| RISC-V 64 | `x31` | always (holds the address) |
| RISC-V 64 | `x29`, `x30`, 32-byte stack frame | `b`/`h` widths (`lr.w`/`sc.w` merge loop) |

Fetch-and-or and fetch-and-xor: `atomicxchgor{b,h,i,q}`, `atomicxchgxor{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | always (`lock cmpxchg` retry loop; `rax` is saved and restored on the stack) |
| AArch64 | `x16` | address has an offset or an index |
| RISC-V 64 | `x31` | always (holds the address) |
| RISC-V 64 | `x29`, `x30`, 32-byte stack frame | `b`/`h` widths (`lr.w`/`sc.w` merge loop) |

Fetch-and-clear: `atomicxchgclear{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | `r11` | always (complemented source; `lock cmpxchg` retry loop; `rax` is saved and restored on the stack) |
| AArch64 | `x16` | always (complemented source); an address with an offset or index also folds into `x16` and overwrites it, so use a bare base register |
| RISC-V 64 | `x31`, `x29` | always (complemented source staged in `x29`, address in `x31`) |
| RISC-V 64 | `x30`, 32-byte stack frame | `b`/`h` widths (`lr.w`/`sc.w` merge loop) |

Compare-and-swap: `atomicweakcas{b,h,i,q}`, `batomicweakcas{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | (`t0` is `rax`, the operand-visible expected/old value of `lock cmpxchg`) |
| AArch64 | `x17` | always (saves the expected value across `casal`) |
| AArch64 | `x16` | address has an offset or an index |
| RISC-V 64 | `x31`, `x29`, `x30` | always (`lr`/`sc` loop: address, compare/status, loaded word) |
| RISC-V 64 | 32-byte stack frame | `b`/`h` widths |

Load-linked: `loadlinkacq{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address has an offset or an index |
| RISC-V 64 | `x31` | always (holds the address) |
| RISC-V 64 | `x29` | `b`/`h` widths (shift) |

Store-conditional: `storecondrel{b,h,i,q}`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | `x16` | address has an offset or an index |
| AArch64 | `x16`, `x17` | the status register is also the source or an address register |
| RISC-V 64 | `x31` | always (holds the address) |
| RISC-V 64 | `x29`, `x30`, 32-byte stack frame | `b`/`h` widths (`lr.w`/`sc.w` merge loop) |

On x86-64 the conditional store is one `lock cmpxchg` against `t0` (`rax`), which holds the current memory value when the store fails. On RISC-V 64 the `b`/`h` forms also overwrite the source register `O3` with the shift amount.

Fences and spin hint: `memfence`, `fence`, `pause`.

| target | clobbers | when |
| --- | --- | --- |
| x86-64 | - | |
| AArch64 | - | |
| RISC-V 64 | - | |

### `atomicxchgaddb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = old + X[O2]<7:0>;
X[O2]<7:0> = old;
```

### `atomicxchgaddh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = old + X[O2]<15:0>;
X[O2]<15:0> = old;
```

### `atomicxchgaddi O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = old + X[O2]<31:0>;
X[O2]<31:0> = old;
```

### `atomicxchgaddq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = old + X[O2];
X[O2] = old;
```

### `atomicxchgsubb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = old - X[O2]<7:0>;
X[O2]<7:0> = old;
```

### `atomicxchgsubh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = old - X[O2]<15:0>;
X[O2]<15:0> = old;
```

### `atomicxchgsubi O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = old - X[O2]<31:0>;
X[O2]<31:0> = old;
```

### `atomicxchgsubq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = old - X[O2];
X[O2] = old;
```

### `atomicxchgb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = X[O2]<7:0>;
X[O2]<7:0> = old;
```

### `atomicxchgh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = X[O2]<15:0>;
X[O2]<15:0> = old;
```

### `atomicxchgi O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = X[O2]<31:0>;
X[O2]<31:0> = old;
```

### `atomicxchgq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = X[O2];
X[O2] = old;
```

### `atomicxchgclearb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = old AND NOT(X[O2]<7:0>);
X[O2]<7:0> = old;
```

### `atomicxchgclearh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = old AND NOT(X[O2]<15:0>);
X[O2]<15:0> = old;
```

### `atomicxchgcleari O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = old AND NOT(X[O2]<31:0>);
X[O2]<31:0> = old;
```

### `atomicxchgclearq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = old AND NOT(X[O2]);
X[O2] = old;
```

### `atomicxchgorb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = old OR X[O2]<7:0>;
X[O2]<7:0> = old;
```

### `atomicxchgorh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = old OR X[O2]<15:0>;
X[O2]<15:0> = old;
```

### `atomicxchgori O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = old OR X[O2]<31:0>;
X[O2]<31:0> = old;
```

### `atomicxchgorq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = old OR X[O2];
X[O2] = old;
```

### `atomicxchgxorb O1, O2`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
Release(Mem[address, 1]) = old EOR X[O2]<7:0>;
X[O2]<7:0> = old;
```

### `atomicxchgxorh O1, O2`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
Release(Mem[address, 2]) = old EOR X[O2]<15:0>;
X[O2]<15:0> = old;
```

### `atomicxchgxori O1, O2`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
Release(Mem[address, 4]) = old EOR X[O2]<31:0>;
X[O2]<31:0> = old;
```

### `atomicxchgxorq O1, O2`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
Release(Mem[address, 8]) = old EOR X[O2];
X[O2] = old;
```

### `atomicweakcasb O1, O2, O3`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
if old == X[O2]<7:0> then
    Release(Mem[address, 1]) = X[O3]<7:0>;
endif
X[t0] = ZeroExtend(old, 64);
```

### `atomicweakcash O1, O2, O3`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
if old == X[O2]<15:0> then
    Release(Mem[address, 2]) = X[O3]<15:0>;
endif
X[t0] = ZeroExtend(old, 64);
```

### `atomicweakcasi O1, O2, O3`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
if old == X[O2]<31:0> then
    Release(Mem[address, 4]) = X[O3]<31:0>;
endif
X[t0] = ZeroExtend(old, 64);
```

### `atomicweakcasq O1, O2, O3`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
if old == X[O2] then
    Release(Mem[address, 8]) = X[O3];
endif
X[t0] = ZeroExtend(old, 64);
```

### `batomicweakcasb O1, O2, O3, O4`

```text
bits(64) address = X[O1];
bits(8) old = Acquire(Mem[address, 1]);
if old == X[O2]<7:0> then
    Release(Mem[address, 1]) = X[O3]<7:0>;
else
    BranchTo(O4);
endif
X[t0] = ZeroExtend(old, 64);
```

### `batomicweakcash O1, O2, O3, O4`

```text
bits(64) address = X[O1];
bits(16) old = Acquire(Mem[address, 2]);
if old == X[O2]<15:0> then
    Release(Mem[address, 2]) = X[O3]<15:0>;
else
    BranchTo(O4);
endif
X[t0] = ZeroExtend(old, 64);
```

### `batomicweakcasi O1, O2, O3, O4`

```text
bits(64) address = X[O1];
bits(32) old = Acquire(Mem[address, 4]);
if old == X[O2]<31:0> then
    Release(Mem[address, 4]) = X[O3]<31:0>;
else
    BranchTo(O4);
endif
X[t0] = ZeroExtend(old, 64);
```

### `batomicweakcasq O1, O2, O3, O4`

```text
bits(64) address = X[O1];
bits(64) old = Acquire(Mem[address, 8]);
if old == X[O2] then
    Release(Mem[address, 8]) = X[O3];
else
    BranchTo(O4);
endif
X[t0] = ZeroExtend(old, 64);
```

### `loadlinkacqb O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(AcquireExclusive(Mem[address, 1]), 64);
```

### `loadlinkacqh O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(AcquireExclusive(Mem[address, 2]), 64);
```

### `loadlinkacqi O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(AcquireExclusive(Mem[address, 4]), 64);
```

### `loadlinkacqq O1, O2`

```text
bits(64) address = X[O2];
X[O1] = ZeroExtend(AcquireExclusive(Mem[address, 8]), 64);
```

### `storecondrelb O1, O2, O3`

```text
bits(64) address = X[O1];
boolean succeeded = ReleaseExclusive(Mem[address, 1]) = X[O3]<7:0>;
X[O2] = if succeeded then 0 else 1;
```

### `storecondrelh O1, O2, O3`

```text
bits(64) address = X[O1];
boolean succeeded = ReleaseExclusive(Mem[address, 2]) = X[O3]<15:0>;
X[O2] = if succeeded then 0 else 1;
```

### `storecondreli O1, O2, O3`

```text
bits(64) address = X[O1];
boolean succeeded = ReleaseExclusive(Mem[address, 4]) = X[O3]<31:0>;
X[O2] = if succeeded then 0 else 1;
```

### `storecondrelq O1, O2, O3`

```text
bits(64) address = X[O1];
boolean succeeded = ReleaseExclusive(Mem[address, 8]) = X[O3];
X[O2] = if succeeded then 0 else 1;
```

### `memfence`

```text
Barrier(Full);
```

### `fence`

```text
Barrier(Sync);
```

### `pause`

```text
SpinLoopHint();
```

## 8. Directives, annotations, and the interpreter loop

### Scratch registers

No entry in this section clobbers a scratch register on any target. The `rloop*` entries lower only on the `rloop` backend, which has no native registers.

### `emit O1, ..., On`

```text
EmitRawText(O1, O2, ..., On);
```

`offlineasm` only.

### `tagCodePtr`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `tagReturnAddress`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `untagReturnAddress`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `removeCodePtrTag`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `untagArrayPtr`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `removeArrayPtrTag`

```text
// no-op annotation; consumed by lowering, has no runtime effect
```

### `rloopCrash`

```text
Trap();
```

`rloop` backend only.

### `rloopCallNativeFunction O1`

```text
CallNative(O1);
SuspendLoop();
```

`rloop` backend only.

### `rloopCallNative O1`

```text
CallNative(O1);
```

`rloop` backend only.

### `rloopCallSlowPath O1`

```text
CallSlowPath(O1);
```

`rloop` backend only.

### `rloopCallSlowPath3 O1`

```text
CallSlowPath(O1);
```

`rloop` backend only.

### `rloopCallSlowPath4 O1`

```text
CallSlowPath(O1);
```

`rloop` backend only.

### `rloopCallSlowPathVoid O1`

```text
CallSlowPath(O1);
```

`rloop` backend only.

### `rloopDo`

```text
// annotation passthrough
```

`rloop` backend only.

## Availability

Every entry above is accepted by both assemblers, except these families.

- Offlineasm only: `emit`.
- Offlineasm's `rloop` backend only: `rloopCrash`, `rloopCallNativeFunction`, `rloopCallNative`, `rloopCallSlowPath`, `rloopCallSlowPath3`, `rloopCallSlowPath4`, `rloopCallSlowPathVoid`, `rloopDo`.