aboutsummaryrefslogtreecommitdiff
path: root/cpu/xc16x.cpu
blob: 5537094fc42ff94245e104cf09fab9fb9c392121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
; Infineon XC16X CPU description.  -*- Scheme -*-
;
; Copyright 2006 Free Software Foundation, Inc.
;
; Contributed by KPIT Cummins Infosystems Ltd.; developed under contract 
; from Infineon Systems, GMBH , Germany.
;
; This file is part of the GNU Binutils.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
; 02110-1301, USA.

(include "simplify.inc")

; define-arch appears first

(define-arch
  (name xc16x) ; name of cpu family
  (comment "Infineon XC16X")
  (default-alignment aligned)
  (insn-lsb0? #t)		
  (machs xc16x)
  (isas xc16x)
)

; Attributes.   
; An attribute to describe which pipeline an insn runs in generally OS.
(define-attr
  (for insn)
  (type enum)
  (name PIPE)
  (comment "parallel execution pipeline selection")
  (values NONE OS)
)

; Instruction set parameters.

(define-isa
  (name xc16x)
  (default-insn-bitsize 32)
  (base-insn-bitsize 32)
  (default-insn-word-bitsize 16)
  (decode-assist (15 14 13 12))
  ; The XC16X fetches 1 insn at a time.
  (liw-insns 1)
  (parallel-insns 1)
)

; Cpu family definitions.

(define-cpu
  ; cpu names must be distinct from the architecture name and machine names.
  ; The "b" suffix stands for "base" and is the convention.
  ; The "f" suffix stands for "family" and is the convention.
  (name xc16xbf)
  (comment "Infineon XC16X base family")
  (endian little)
  (insn-chunk-bitsize 32)
  (word-bitsize 16)
  (parallel-insns 1)
)

(define-mach
  (name xc16x)
  (comment "Infineon XC16X cpu")
  (cpu xc16xbf)
)

; Model descriptions.

(define-model
  (name xc16x) (comment "XC16X") (attrs)
  (mach xc16x)
  
  (pipeline p-mem "" () ((prefetch) (fetch) (decode) (address) (memory) (execute) (writeback)))
  
    ; `state' is a list of variables for recording model state
    (state
     ; bit mask of h-gr registers, =1 means value being loaded from memory
     (h-gr UINT)
    )
  
  (unit u-exec "Execution Unit" ()
  	1 1 ; issue done
  	() ; state
  	((dr INT -1) (sr INT -1)) ; inputs
  	((dr INT -1)) ; outputs
  	() ; profile action (default)
	)
  (unit u-cmp "Compare Unit" ()
  	1 1 ; issue done
  	() ; state
  	((src1 INT -1) (src2 INT -1)) ; inputs
  	() ; outputs
  	() ; profile action (default)
	)
  (unit u-cti "Jump & Call Unit" ()
  	1 1 ; issue done
  	() ; state
  	((condbit) (sr INT -1)) ; inputs
  	((pc)) ; outputs
  	() ; profile action (default)
	)
  (unit u-mov "Data Movement Unit" ()
  	1 1 ; issue done
  	() ;state
  	((dr INT -1) (sr INT -1)) ; inputs
  	((dr INT -1)) ; output
  	() ; profile action (default)
  	)
 ) 
 
; Instruction fields.
;
; Attributes:
; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
; ABS-ADDR: absolute address (for reloc and disassembly purposes)
; RELOC: there is a relocation associated with this field (experiment)

(define-attr
  (for ifield operand)
  (type boolean)
  (name RELOC)
  (comment "there is a reloc associated with this field (experiment)")
)

(dnf f-op1       "op1"                 () 7  4)
(dnf f-op2       "op2"                 () 3  4)
(dnf f-condcode  "condcode"            () 7  4)  ;condition code required in other jmps and calls
(dnf f-icondcode "indrct condcode"     () 15 4)  ;condition code required in other jmpi and calli
(dnf f-rcond     "relative-cond"       () 7  4)  ;condition code required in JMPR 
(dnf f-qcond     "qbit"                () 7  4)  ;used in enum of bset/bclear macro
(dnf f-extccode  "extended condcode"   () 15 5)  ;condition code required in other jmpa and calla
(dnf f-r0	 "r0"		       () 9  2)  ;required where 2 bit register used(only R0-R3)
(dnf f-r1        "r1"                  () 15 4)
(dnf f-r2        "r2"                  () 11 4)
(dnf f-r3        "r3"                  () 12 4)
(dnf f-r4        "r4"                  () 11 4)
(dnf f-uimm2     "uimm2"               () 13 2)  ;used for immediate data,eg in ADD,MOV insns
(dnf f-uimm3     "uimm3"               () 10 3)  ;used for immediate data,eg in ADD,SUB insns
(dnf f-uimm4     "uimm4"               () 15 4)  ;used for immediate data,eg in MOV insns
(dnf f-uimm7     "uimm7"               (PCREL-ADDR RELOC) 15 7)	;used in TRAP
(dnf f-uimm8     "uimm8"               () 23 8)  ;used in immediate byte data,eg in ADDB,MOVB insns
(dnf f-uimm16    "uimm16"              () 31 16) ;used for immediate word data
(dnf f-memory    "memory"              () 31 16) ; used for memory operands 
(dnf f-memgr8    "memory" 	       () 31 16) ; memory location of gr
(dnf f-rel8      "rel8"                (PCREL-ADDR RELOC) 15 8)	;used in JMPR,CALLR
(dnf f-relhi8    "relhi8"              (PCREL-ADDR RELOC) 23 8)	;used in JB,JBC,JNB,JNBS
(dnf f-reg8      "reg8"                () 15 8)	;required where 8bit gp register used
(dnf f-regmem8   "regmem8"             () 15 8) ;required where 8bit register used
(dnf f-regoff8   "regoff8"             () 15 8)	;required for offset calc
(dnf f-reghi8    "reghi8"              () 23 8)	;required where 8bit register number used
(dnf f-regb8     "regb8"               () 15 8)	;required for byte registers RL0,RH0, till RL8,RH8
(dnf f-seg8      "seg8"                () 15 8) ;used as segment number in JMPS,CALLS
(dnf f-segnum8   "segnum8"             () 23 8) ;used in EXTS,EXTSR        
(dnf f-mask8     "mask8"               () 23 8) ;used as mask in BFLDH,BFLDL insns
(dnf f-pagenum   "page num"            () 25 10);used in EXTP,EXTPR
(dnf f-datahi8   "datahi8"             () 31 8) ;used for filling with const data
(dnf f-data8     "data8"               () 23 8) ;used for filling with const data
(dnf f-offset16  "address offset16"    (ABS-ADDR RELOC) 31 16) ;used in JMPS,JMPA,CALLA,CALLS
(dnf f-op-bit1   "gap of 1 bit"        () 11 1)	;used for filling with const data
(dnf f-op-bit2   "gap of 2 bits"       () 11 2)	;used for filling with const data
(dnf f-op-bit4   "gap of 4 bits"       () 11 4) ;used for filling with const data
(dnf f-op-bit3   "gap of 3 bits"       () 10 3) ;used in CALLA, JMPA
(dnf f-op-2bit   "gap of 2 bits"       () 10 2) ;used in CALLA
(dnf f-op-bitone "gap of 1 bit "       () 10 1) ;used in JMPA
(dnf f-op-onebit "gap of 1 bit "       () 9  1) ;used in JMPA
(dnf f-op-1bit   "gap of 1 bit "       () 8  1) ;used in JMPA, CALLA
(dnf f-op-lbit4  "gap of 4 bits"       () 15 4) ;used for filling with const data
(dnf f-op-lbit2  "gap of 2 bits"       () 15 2) ;used for filling with const data
(dnf f-op-bit8	 "gap of 8 bits"       () 31 8) ;used for filling with const data
(dnf f-op-bit16	 "gap of 16 bits"      () 31 16) ;used for filling with const data
(dnf f-qbit      "qbit"                () 7  4) ;used in bit field of bset/bclear
(dnf f-qlobit    "qlobit"              () 31 4) ;used for filling with const data
(dnf f-qhibit    "qhibit"              () 27 4) ;used for filling with const data
(dnf f-qlobit2   "qlobit2"             () 27 2) ;used for filling with const data
(dnf f-pof    "upof16"                 () 31 16) ; used for memory operands 

; Enums.
; insn-op1: bits 0-3
(define-normal-insn-enum insn-op1 "insn format enums" () OP1_ f-op1
  ("0" "1" "2" "3" "4" "5" "6" "7"
   "8" "9" "10" "11" "12" "13" "14" "15")
)

; insn-op2: bits 4-7
(define-normal-insn-enum insn-op2 "op2 enums" () OP2_ f-op2
  ("0" "1" "2" "3" "4" "5" "6" "7"
   "8" "9" "10" "11" "12" "13" "14" "15")
)

;/*for bclr/bset*/
; insn-rcond: bits 0-3
(define-normal-insn-enum insn-qcond "bit set/clear enums" () QBIT_ f-qcond
  (("0" 0) ("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5) ("6" 6) ("7" 7) ("8" 8) ("9" 9) ("10" 10) 
   ("11" 11) ("12" 12) ("13" 13) ("14" 14) ("15" 15))
)
;/************/
; insn-rcond: bits 0-3
(define-normal-insn-enum insn-rcond "relative jump condition code op2 enums" () COND_ f-rcond
  (("UC" 0) ("NET" 1) ("Z" 2) ("NE_NZ" 3) ("V" 4)  ("NV" 5) ("N" 6) ("NN" 7)
   ("C" 8) ("NC" 9) ("SGT" 10) ("SLE" 11) ("SLT" 12) ("SGE" 13) ("UGT" 14) ("ULE" 15)
   ("EQ" 2) ("NE" 3) ("ULT" 8) ("UGE" 9))
)



; Hardware pieces.
; These entries list the elements of the raw hardware.
; They're also used to provide tables and other elements of the assembly
; language.

(dnh h-pc "program counter" (PC) (pc) () () ())

(define-keyword
  (name gr-names)
  (print-name h-gr)
  (prefix "")
  (values (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
	  (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15))

)
(define-hardware
  (name h-gr)
  (comment "general registers")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (16))
  (indices extern-keyword gr-names)
)

(define-keyword
  (name ext-names)
  (print-name h-ext)
  (prefix "")
  (values (0x1 0) (0x2 1) (0x3 2) (0x4 3)
          ("1" 0) ("2" 1) ("3" 2) ("4" 3))

)

(define-hardware
  (name h-ext)
  (comment "ext values")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (8))
  (indices extern-keyword ext-names)
)

(define-keyword
  (name psw-names)
  (print-name h-psw)
  (prefix "")
  (values ("IEN" 136) ("r0.11" 240) ("r1.11" 241) ("r2.11" 242) ("r3.11" 243) ("r4.11" 244)
                      ("r5.11" 245) ("r6.11" 246) ("r7.11" 247) ("r8.11" 248)
                      ("r9.11" 249) ("r10.11" 250) ("r11.11" 251) ("r12.11" 252)
                      ("r13.11" 253) ("r14.11" 254) ("r15.11" 255))
)

(define-hardware
  (name h-psw)
  (comment "ext values")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (1))
  (indices extern-keyword psw-names)
)

(define-keyword
  (name grb-names)
  (print-name h-grb)
  (prefix "")
  (values (rl0 0) (rh0 1) (rl1 2) (rh1 3) (rl2 4) (rh2 5) (rl3 6) (rh3 7) 
          (rl4 8) (rh4 9) (rl5 10) (rh5 11) (rl6 12) (rh6 13) (rl7 14) (rh7 15))
)

(define-hardware
  (name h-grb)
  (comment "general registers")
  (attrs PROFILE CACHE-ADDR)
  (type register QI (16))
  (indices extern-keyword grb-names)
)

(define-keyword
  (name conditioncode-names)
  (print-name h-cc)
  (prefix "")
  (values (cc_UC 0) (cc_NET 1) (cc_Z 2) (cc_EQ 2) (cc_NZ 3) (cc_NE 3) (cc_V 4) (cc_NV 5) (cc_N 6)  (cc_NN 7) (cc_ULT 8)  (cc_UGE 9) 
	  (cc_C 8) (cc_NC 9) (cc_SGT 10) (cc_SLE 11) (cc_SLT 12) (cc_SGE 13) (cc_UGT 14) 
          (cc_ULE 15))
)
(define-hardware
  (name h-cc)
  (comment "condition codes")
  (attrs PROFILE CACHE-ADDR)
  (type register QI (16))
  (indices extern-keyword conditioncode-names)
)

(define-keyword
  (name extconditioncode-names)
  (print-name h-ecc)
  (prefix "")
  (values(cc_UC 0) (cc_NET 2) (cc_Z 4) (cc_EQ 4) (cc_NZ 6) (cc_NE 6) (cc_V 8) (cc_NV 10) (cc_N 12)  (cc_NN 14) (cc_ULT 16)  (cc_UGE 18) (cc_C 16) (cc_NC 18) (cc_SGT 20) 
         (cc_SLE 22) (cc_SLT 24) (cc_SGE 26) (cc_UGT 28) (cc_ULE 30) (cc_nusr0 1) 
         (cc_nusr1 3) (cc_usr0 5) (cc_usr1 7))
)
(define-hardware
  (name h-ecc)
  (comment "extended condition codes")
  (attrs PROFILE CACHE-ADDR)
  (type register QI (4))
  (indices extern-keyword extconditioncode-names)
)

(define-keyword
  (name grb8-names)
  (print-name h-grb8)
  (prefix "")
  (values (dpp0 0)  (dpp1 1)  (dpp2 2)  (dpp3 3)
	  (psw 136)   (cp 8)    (mdl 7)   (mdh  6)
	  (mdc 135)   (sp 9)    (csp 4)  (vecseg 137)
          (stkov 10)  (stkun 11) (cpucon1 12) (cpucon2 13)
	  (zeros 142)  (ones 143) (spseg 134) (tfr 214)
	  (rl0 240) (rh0 241) (rl1 242) (rh1 243) (rl2 244) (rh2 245) (rl3 246) (rh3 247)
	  (rl4 248) (rh4 249) (rl5 250) (rh5 251) (rl6 252) (rh6 253) (rl7 254) (rh7 255))
)

(define-hardware
  (name h-grb8)
  (comment "general byte registers")
  (attrs PROFILE CACHE-ADDR)
  (type register QI (36))
  (indices extern-keyword grb8-names)
)

(define-keyword
  (name r8-names)
  (print-name h-r8)
  (prefix "")
  (values (dpp0 0)  (dpp1 1)  (dpp2 2)  (dpp3 3)
	  (psw 136)   (cp 8)    (mdl 7)   (mdh  6)
	  (mdc 135)   (sp 9)    (csp 4)  (vecseg 137)
          (stkov 10)  (stkun 11) (cpucon1 12) (cpucon2 13)
	  (zeros 142)  (ones 143) (spseg 134) (tfr 214)
	  (r0 240) (r1 241) (r2 242) (r3 243) (r4 244) (r5 245) (r6 246) (r7 247)
	  (r8 248) (r9 249) (r10 250) (r11 251) (r12 252) (r13 253) (r14 254) (r15 255))
)

(define-hardware
  (name h-r8)
  (comment "registers")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (36))
  (indices extern-keyword r8-names)
)

(define-keyword
  (name regmem8-names)
  (print-name h-regmem8)
  (prefix "")
  (values (dpp0 0)  (dpp1 1)  (dpp2 2)  (dpp3 3)
	  (psw 136)   (cp 8)    (mdl 7)   (mdh  6)
	  (mdc 135)   (sp 9)    (csp 4)  (vecseg 137)
          (stkov 10)  (stkun 11) (cpucon1 12) (cpucon2 13)
	  (zeros 142)  (ones 143) (spseg 134) (tfr 214)
	  (r0 240) (r1 241) (r2 242) (r3 243) (r4 244) (r5 245) (r6 246) (r7 247)
	  (r8 248) (r9 249) (r10 250) (r11 251) (r12 252) (r13 253) (r14 254) (r15 255))
)

(define-hardware
  (name h-regmem8)
  (comment "registers")
  (attrs )
  (type register HI (16))
  (indices extern-keyword regmem8-names)
)

(define-keyword
  (name regdiv8-names)
  (print-name h-regdiv8)
  (prefix "")
  (values (r0 0) (r1 17) (r2 34) (r3 51) (r4 68) (r5 85) (r6 102) (r7 119)
	  (r8 136) (r9 153) (r10 170) (r11 187) (r12 204) (r13 221) (r14 238) (r15 255))
)

(define-hardware
  (name h-regdiv8)
  (comment "division insn registers")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (16))
  (indices extern-keyword regdiv8-names)
)

(define-keyword
  (name reg0-name)
  (print-name h-reg0)
  (prefix "")
  (values (0x1 1) (0x2 2) (0x3 3) (0x4 4) (0x5 5) (0x6 6) (0x7 7) (0x8 8) (0x9 9) (0xa 10) (0xb 11) 
          (0xc 12) (0xd 13) (0xe 14) (0xf 15)
          ("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5) ("6" 6) ("7" 7) ("8" 8) ("9" 9) ("10" 10) ("11" 11) 
          ("12" 12) ("13" 13) ("14" 14) ("15" 15))
)

(define-hardware
  (name h-r0)
  (comment "for 4-bit data excuding 0")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (30))
  (indices extern-keyword reg0-name)
)

(define-keyword
  (name reg0-name1)
  (print-name h-reg01)
  (prefix "")
  (values (0x1 1) (0x2 2) (0x3 3) (0x4 4) (0x5 5) (0x6 6) (0x7 7)
          ("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5) ("6" 6) ("7" 7))
)

(define-hardware
  (name h-r01)
  (comment "for 4-bit data excuding 0")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (14))
  (indices extern-keyword reg0-name1)
)

(define-keyword
  (name regbmem8-names)
  (print-name h-regbmem8)
  (prefix "")
  (values (dpp0 0)  (dpp1 1)  (dpp2 2)  (dpp3 3)
	  (psw 136)   (cp 8)    (mdl 7)   (mdh  6)
	  (mdc 135)   (sp 9)    (csp 4)  (vecseg 137)
          (stkov 10)  (stkun 11) (cpucon1 12) (cpucon2 13)
	  (zeros 142)  (ones 143) (spseg 134) (tfr 214)
	  (rl0 240) (rh0 241) (rl1 242) (rh1 243) (rl2 244) (rh2 245) (rl3 246) (rh3 247)
	  (rl4 248) (rh4 249) (rl5 250) (rh5 251) (rl6 252) (rh6 253) (rl7 254) (rh7 255))
)

(define-hardware
  (name h-regbmem8)
  (comment "registers")
  (attrs PROFILE CACHE-ADDR)
  (type register HI (36))
  (indices extern-keyword regbmem8-names)
)

(define-keyword
  (name memgr8-names)
  (print-name h-memgr8)
  (prefix "")
  (values (dpp0 65024)  (dpp1 65026)  (dpp2 65028)  (dpp3 65030)
	  (psw 65296)   (cp 65040)    (mdl 65038)   (mdh  65036)
	  (mdc 65294)   (sp 65042)    (csp 65032)  (vecseg 65298)
          (stkov 65044)  (stkun 65046) (cpucon1 65048) (cpucon2 65050)
	  (zeros 65308)  (ones 65310) (spseg 65292) (tfr 65452) )
)

(define-hardware
  (name h-memgr8)
  (comment "memory location of registers")
  (attrs )
  (type register HI (20))
  (indices extern-keyword memgr8-names)
)

(dsh h-cond "condition bit" () (register BI))   ;any bit from PSW while comparison
; This bit is part of the PSW register 
(dsh h-cbit  "carry bit"		() (register BI))

(dsh h-sgtdis "segmentation enable bit" () (register BI)) ;0 means segmentation enabled

;Instruction operands 
; -- layer between the assembler and the raw hardware description 
; -- the main means of manipulating instruction fields in the semantic code 

; XC16X specific operand attributes:

(define-attr
  (for operand)
  (type boolean)
  (name HASH-PREFIX)
  (comment "immediates have an optional '#' prefix")
)

(define-attr
  (for operand)
  (type boolean)
  (name DOT-PREFIX)
  (comment "bit addr have an optional '.' prefix")
)

(define-attr
  (for operand)
  (type boolean)
  (name POF-PREFIX)
  (comment "page offset ")
)

(define-attr
  (for operand)
  (type boolean)
  (name PAG-PREFIX)
  (comment "page ")
)

(define-attr
  (for operand)
  (type boolean)
  (name SOF-PREFIX)
  (comment "segment offset selection")
)

(define-attr
  (for operand)
  (type boolean)
  (name SEG-PREFIX)
  (comment "segment")
)

(dnop sr      "source register"              () h-gr    f-r2)
(dnop dr      "destination register"         () h-gr    f-r1)
(dnop dri     "destination register"         () h-gr    f-r4)
(dnop srb     "source register"              () h-grb   f-r2)
(dnop drb     "destination register"         () h-grb   f-r1)
(dnop sr2     "2 bit source register"	     () h-gr    f-r0)
(dnop src1    "source register 1"            () h-gr   f-r1)
(dnop src2    "source register 2"            () h-gr   f-r2)
(dnop srdiv   "source register 2"            () h-regdiv8   f-reg8)
(dnop RegNam  "PSW bits"                     () h-psw f-reg8) 
(dnop uimm2   "2 bit unsigned number"        (HASH-PREFIX) h-ext f-uimm2) 
(dnop uimm3   "3 bit unsigned number"        (HASH-PREFIX) h-r01 f-uimm3)
(dnop uimm4   "4 bit unsigned number"        (HASH-PREFIX) h-uint f-uimm4)
(dnop uimm7   "7 bit trap number"            (HASH-PREFIX) h-uint f-uimm7)
(dnop uimm8   "8 bit unsigned immediate"     (HASH-PREFIX) h-uint f-uimm8)
(dnop uimm16  "16 bit unsigned immediate"    (HASH-PREFIX) h-uint f-uimm16)
(dnop upof16  "16 bit unsigned immediate"    (POF-PREFIX) h-addr f-memory)
(dnop reg8    "8 bit word register number"   () h-r8 f-reg8)
(dnop regmem8 "8 bit word register number"   () h-regmem8 f-regmem8)
(dnop regbmem8 "8 bit byte register number"  () h-regbmem8 f-regmem8)
(dnop regoff8 "8 bit word register number"   () h-r8 f-regoff8)
(dnop reghi8  "8 bit word register number"   () h-r8 f-reghi8)
(dnop regb8   "8 bit byte register number"   () h-grb8 f-regb8)
(dnop genreg  "8 bit word register number"   () h-r8 f-regb8)
(dnop seg     "8 bit segment number"         () h-uint f-seg8)
(dnop seghi8  "8 bit hi segment number"      () h-uint f-segnum8)
(dnop caddr   "16 bit address offset"        () h-addr f-offset16)
(dnop rel     "8 bit signed relative offset" () h-sint f-rel8)
(dnop relhi   "hi 8 bit signed relative offset" () h-sint f-relhi8)	
(dnop condbit "condition bit"                (SEM-ONLY) h-cond f-nil)
(dnop bit1    "gap of 1 bit"    	     () h-uint f-op-bit1)
(dnop bit2    "gap of 2 bits"	             () h-uint f-op-bit2)
(dnop bit4    "gap of 4 bits"                () h-uint f-op-bit4)
(dnop lbit4   "gap of 4 bits"                () h-uint f-op-lbit4)
(dnop lbit2   "gap of 2 bits"                () h-uint f-op-lbit2)
(dnop bit8    "gap of 8 bits"	             () h-uint f-op-bit8)
(dnop u4      "gap of 4 bits"	             () h-r0   f-uimm4)
(dnop bitone  "field of 1 bit"	             () h-uint f-op-onebit)
(dnop bit01   "field of 1 bit"	             () h-uint f-op-1bit)
(dnop cond    "condition code" 	             () h-cc   f-condcode)
(dnop icond   "indirect condition code"      () h-cc   f-icondcode)
(dnop extcond "extended condition code"      () h-ecc  f-extccode)
(dnop memory  "16 bit memory" 		     () h-addr f-memory)
(dnop memgr8  "16 bit memory"		     () h-memgr8 f-memgr8)
(dnop cbit    "carry bit"                    (SEM-ONLY) h-cbit  f-nil)
(dnop qbit    "bit addr"               	     (DOT-PREFIX) h-uint  f-qbit)
(dnop qlobit  "bit addr"                     (DOT-PREFIX) h-uint  f-qlobit)
(dnop qhibit  "bit addr"                     (DOT-PREFIX) h-uint  f-qhibit)
(dnop mask8   "8 bit mask"     		     (HASH-PREFIX) h-uint f-mask8)
(dnop masklo8 "8 bit mask"     		     (HASH-PREFIX) h-uint f-datahi8)
(dnop pagenum "10 bit page number"     	     (HASH-PREFIX) h-uint f-pagenum)
(dnop data8   "8 bit data"     		     (HASH-PREFIX) h-uint f-data8)
(dnop datahi8 "8 bit data"     	             (HASH-PREFIX) h-uint f-datahi8)
(dnop sgtdisbit "segmentation enable bit"    (SEM-ONLY) h-sgtdis f-nil)
(dnop upag16  "16 bit unsigned immediate"    (PAG-PREFIX) h-uint f-uimm16)
(dnop useg8   "8 bit segment "    	     (SEG-PREFIX) h-uint f-seg8)
(dnop useg16  "16 bit address offset"        (SEG-PREFIX) h-uint f-offset16)
(dnop usof16  "16 bit address offset"        (SOF-PREFIX) h-uint f-offset16)

; define hash operator
(define-operand (name hash) (comment "# prefix") (attrs)
  (type h-sint)  
  (index f-nil)
  (handlers (parse "hash") (print "hash"))
)

; define dot operator
(define-operand (name dot) (comment ". prefix") (attrs)
  (type h-sint)  
  (index f-nil)
  (handlers (parse "dot") (print "dot"))
)

; define pof operator
(define-operand (name pof) (comment "pof: prefix") (attrs)
  (type h-sint)  
  (index f-nil)
  (handlers (parse "pof") (print "pof"))
)

; define pag operator
(define-operand (name pag) (comment "pag: prefix") (attrs)
  (type h-sint)
  (index f-nil)
  (handlers (parse "pag") (print "pag"))
)

; define sof operator
(define-operand (name sof) (comment "sof: prefix") (attrs)
  (type h-sint)  
  (index f-nil)
  (handlers (parse "sof") (print "sof"))
)

; define seg operator
(define-operand (name segm) (comment "seg: prefix") (attrs)
  (type h-sint)
  (index f-nil)
  (handlers (parse "seg") (print "seg"))
)

; IDOC attribute for instruction documentation.
(define-attr
  (for insn)
  (type enum)
  (name IDOC)
  (comment "insn kind for documentation")
  (attrs META)
  (values
   (MOVE - () "Data Movement")
   (ALU  - () "Arithmatic & logical")
   (CMP  - () "Compare")
   (JMP  - () "Jump & Call")
   (MISC - () "Miscellaneous")
   (SYSC - () "System control")
  )
)

; Include the instruction set descriptions from their respective
; source files.

;Arithmatic insns
;******************************************************************

;add/sub register and immediate
(define-pmacro (arithmetic16 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 (mem HI op2)))
       ()
  )
)
(arithmetic16 addrpof add add OP1_0 OP2_2 reg8 upof16 HI "pof")
(arithmetic16 subrpof sub sub OP1_2 OP2_2 reg8 upof16 HI "pof")
(arithmetic16 addbrpof addb add OP1_0 OP2_3 regb8 upof16 QI "pof")
(arithmetic16 subbrpof subb sub OP1_2 OP2_3 regb8 upof16 QI "pof")
(arithmetic16 addrpag add add OP1_0 OP2_2 reg8 upag16 HI "pag")
(arithmetic16 subrpag sub sub OP1_2 OP2_2 reg8 upag16 HI "pag")
(arithmetic16 addbrpag addb add OP1_0 OP2_3 regb8 upag16 QI "pag")
(arithmetic16 subbrpag subb sub OP1_2 OP2_3 regb8 upag16 QI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic17 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 (mem HI op2) cbit))
       ()
  )
)
(arithmetic17 addcrpof addc addc OP1_1 OP2_2 reg8 upof16 HI "pof")
(arithmetic17 subcrpof subc subc OP1_3 OP2_2 reg8 upof16 HI "pof")
(arithmetic17 addcbrpof addcb addc OP1_1 OP2_3 regb8 upof16 QI "pof")
(arithmetic17 subcbrpof subcb subc OP1_3 OP2_3 regb8 upof16 QI "pof")
(arithmetic17 addcrpag addc addc OP1_1 OP2_2 reg8 upag16 HI "pag")
(arithmetic17 subcrpag subc subc OP1_3 OP2_2 reg8 upag16 HI "pag")
(arithmetic17 addcbrpag addcb addc OP1_1 OP2_3 regb8 upag16 QI "pag")
(arithmetic17 subcbrpag subcb subc OP1_3 OP2_3 regb8 upag16 QI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic18 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"dir"$"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) (insn1 (mem HI op1) op2 ))
       ()
  )
)
(arithmetic18 addrpofr add add OP1_0 OP2_4 upof16 reg8 HI "pof")
(arithmetic18 subrpofr sub sub OP1_2 OP2_4 upof16 reg8 HI "pof")
(arithmetic18 addbrpofr addb add OP1_0 OP2_5 upof16 regb8 QI "pof")
(arithmetic18 subbrpofr subb sub OP1_2 OP2_5 upof16 regb8 QI "pof")

;add/sub register and immediate
(define-pmacro (arithmetic19 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"dir"$"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) (insn1 mode (mem HI op1) op2 cbit))
       ()
  )
)
(arithmetic19 addcrpofr addc addc OP1_1 OP2_4 upof16 reg8 HI "pof")
(arithmetic19 subcrpofr subc subc OP1_3 OP2_4 upof16 reg8 HI "pof")
(arithmetic19 addcbrpofr addcb addc OP1_1 OP2_5 upof16 regb8 QI "pof")
(arithmetic19 subcbrpofr subcb subc OP1_3 OP2_5 upof16 regb8 QI "pof")

;add/sub register and immediate
(define-pmacro (arithmetic20 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic20 addrhpof add add OP1_0 OP2_6 reg8 uimm16 HI "pof")
(arithmetic20 subrhpof sub sub OP1_2 OP2_6 reg8 uimm16 HI "pof")
(arithmetic20 addbrhpof add add OP1_0 OP2_6 reg8 uimm16 HI "pag")
(arithmetic20 subbrhpof sub sub OP1_2 OP2_6 reg8 uimm16 HI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic21 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic21 addrhpof3 add add OP1_0 OP2_8 dr uimm3 HI "pof")
(arithmetic21 subrhpof3 sub sub OP1_2 OP2_8 dr uimm3 HI "pof")
(arithmetic21 addbrhpag3 addb add OP1_0 OP2_9 drb uimm3 QI "pag")
(arithmetic21 subbrhpag3 subb sub OP1_2 OP2_9 drb uimm3 QI "pag")
(arithmetic21 addrhpag3 add add OP1_0 OP2_8 dr uimm3 HI "pag")
(arithmetic21 subrhpag3 sub sub OP1_2 OP2_8 dr uimm3 HI "pag")
(arithmetic21 addbrhpof3 addb add OP1_0 OP2_9 drb uimm3 QI "pof")
(arithmetic21 subbrhpof3 subb sub OP1_2 OP2_9 drb uimm3 QI "pof")

;add/sub register and immediate
(define-pmacro (arithmetic22 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic22 addrbhpof addb add OP1_0 OP2_7 regb8 uimm8 QI "pof")
(arithmetic22 subrbhpof subb sub OP1_2 OP2_7 regb8 uimm8 QI "pof")
(arithmetic22 addbrhpag addb add OP1_0 OP2_7 regb8 uimm8 QI "pag")
(arithmetic22 subbrhpag subb sub OP1_2 OP2_7 regb8 uimm8 QI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic23 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic23 addcrhpof addc addc OP1_1 OP2_6 reg8 uimm16 HI "pof")
(arithmetic23 subcrhpof subc subc OP1_3 OP2_6 reg8 uimm16 HI "pof")
(arithmetic23 addcbrhpof addc addc OP1_1 OP2_6 reg8 uimm16 HI "pag")
(arithmetic23 subcbrhpof subc subc OP1_3 OP2_6 reg8 uimm16 HI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic24 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic24 addcrhpof3 addc addc OP1_1 OP2_8 dr uimm3 HI "pof")
(arithmetic24 subcrhpof3 subc subc OP1_3 OP2_8 dr uimm3 HI "pof")
(arithmetic24 addcbrhpag3 addcb addc OP1_1 OP2_9 drb uimm3 QI "pag")
(arithmetic24 subcbrhpag3 subcb subc OP1_3 OP2_9 drb uimm3 QI "pag")
(arithmetic24 addcrhpag3 addc addc OP1_1 OP2_8 dr uimm3 HI "pag")
(arithmetic24 subcrhpag3 subc subc OP1_3 OP2_8 dr uimm3 HI "pag")
(arithmetic24 addcbrhpof3 addcb addc OP1_1 OP2_9 drb uimm3 QI "pof")
(arithmetic24 subcbrhpof3 subcb subc OP1_3 OP2_9 drb uimm3 QI "pof")

;add/sub register and immediate
(define-pmacro (arithmetic25 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic25 addcrbhpof addcb addc OP1_1 OP2_7 regb8 uimm8 QI "pof")
(arithmetic25 subcrbhpof subcb subc OP1_3 OP2_7 regb8 uimm8 QI "pof")
(arithmetic25 addcbrhpag addcb addc OP1_1 OP2_7 regb8 uimm8 QI "pag")
(arithmetic25 subcbrhpag subcb subc OP1_3 OP2_7 regb8 uimm8 QI "pag")

;add/sub register and immediate
(define-pmacro (arithmetic10 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic10 addri add add OP1_0 OP2_8 dr uimm3 HI)
(arithmetic10 subri sub sub OP1_2 OP2_8 dr uimm3 HI)
(arithmetic10 addbri addb add OP1_0 OP2_9 drb uimm3 QI)
(arithmetic10 subbri subb sub OP1_2 OP2_9 drb uimm3 QI)

;add/sub register and immediate
(define-pmacro (arithmetic11 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic11 addrim add add OP1_0 OP2_6 reg8 uimm16 HI)
(arithmetic11 subrim sub sub OP1_2 OP2_6 reg8 uimm16 HI)

;add/sub register and immediate
(define-pmacro (arithmetic12 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic12 addbrim addb add OP1_0 OP2_7 regb8 uimm8 QI)
(arithmetic12 subbrim subb sub OP1_2 OP2_7 regb8 uimm8 QI)

;add/sub register and immediate with carry
(define-pmacro (arithmetic13 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic13 addcri addc addc OP1_1 OP2_8 dr uimm3 HI)
(arithmetic13 subcri subc subc OP1_3 OP2_8 dr uimm3 HI)
(arithmetic13 addcbri addcb addc OP1_1 OP2_9 drb uimm3 QI)
(arithmetic13 subcbri subcb subc OP1_3 OP2_9 drb uimm3 QI)

;add/sub register and immediate with carry
(define-pmacro (arithmetic14 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic14 addcrim addc addc OP1_1 OP2_6 reg8 uimm16 HI)
(arithmetic14 subcrim subc subc OP1_3 OP2_6 reg8 uimm16 HI)

;add/sub register and immediate with carry
(define-pmacro (arithmetic15 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic15 addcbrim addcb addc OP1_1 OP2_7 regb8 uimm8 QI)
(arithmetic15 subcbrim subcb subc OP1_3 OP2_7 regb8 uimm8 QI)


;add/sub registers
(define-pmacro (arithmetic name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(arithmetic addr add add OP1_0 OP2_0 dr sr HI)
(arithmetic subr sub sub OP1_2 OP2_0 dr sr HI)
(arithmetic addbr addb add OP1_0 OP2_1 drb srb QI)
(arithmetic subbr subb sub OP1_2 OP2_1 drb srb QI)

;add/sub register and indirect memory
(define-pmacro (arithmetic1 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"]")
       (+ opc1 opc2 op1 (f-op-bit2 2) op2)
       (set mode op1 (insn1 mode op1 (mem HI op2)))
       ()
  )
)
(arithmetic1 add2 add add OP1_0 OP2_8 dr sr2 HI)
(arithmetic1 sub2 sub sub OP1_2 OP2_8 dr sr2 HI)
(arithmetic1 addb2 addb add OP1_0 OP2_9 drb sr2 QI)
(arithmetic1 subb2 subb sub OP1_2 OP2_9 drb sr2 QI)

;add/sub register and indirect memory post increment
(define-pmacro (arithmetic2 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"+]")
       (+ opc1 opc2 op1 (f-op-bit2 3) op2)
       (sequence ()
	   (set mode op1 (insn1 mode op1 (mem HI op2)))
	   (set HI op2 (add HI op2 (const 2)))
       )
       ()
  )
)
(arithmetic2 add2i add add OP1_0 OP2_8 dr sr2 HI)
(arithmetic2 sub2i sub sub OP1_2 OP2_8 dr sr2 HI)
(arithmetic2 addb2i addb add OP1_0 OP2_9 drb sr2 QI)
(arithmetic2 subb2i subb sub OP1_2 OP2_9 drb sr2 QI)

;add/sub registers with carry
(define-pmacro (arithmetic3 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)
(arithmetic3 addcr addc addc OP1_1 OP2_0 dr sr HI)
(arithmetic3 subcr subc subc OP1_3 OP2_0 dr sr HI)
(arithmetic3 addbcr addcb addc OP1_1 OP2_1 drb srb QI) 
(arithmetic3 subbcr subcb subc OP1_3 OP2_1 drb srb QI)


;add/sub register and indirect memory
(define-pmacro (arithmetic4 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"]")
       (+ opc1 opc2 op1 (f-op-bit2 2) op2)
       (set mode op1 (insn1 mode op1 (mem HI op2) cbit))
       ()
  )
)
(arithmetic4 addcr2 addc addc OP1_1 OP2_8 dr sr2 HI)
(arithmetic4 subcr2 subc subc OP1_3 OP2_8 dr sr2 HI)
(arithmetic4 addbcr2 addcb addc OP1_1 OP2_9 drb sr2 QI)
(arithmetic4 subbcr2 subcb subc OP1_3 OP2_9 drb sr2 QI)

;add/sub register and indirect memory post increment
(define-pmacro (arithmetic5 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"+]")
       (+ opc1 opc2 op1 (f-op-bit2 3) op2)
       (sequence ()
           (set mode op1 (insn1 mode op1 (mem HI op2) cbit))
           (set HI op2 (add HI op2 (const 2)))
       )
       ()
  )
)
(arithmetic5 addcr2i addc addc OP1_1 OP2_8 dr sr2 HI)
(arithmetic5 subcr2i subc subc OP1_3 OP2_8 dr sr2 HI)
(arithmetic5 addbcr2i addcb addc OP1_1 OP2_9 drb sr2 QI)
(arithmetic5 subbcr2i subcb subc OP1_3 OP2_9 drb sr2 QI)

;add/sub register and direct memory
(define-pmacro (arithmetic6 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)

;add/sub register and direct memory
(define-pmacro (arithmetic7 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) (insn1 (mem HI op1) op2))
       ()
  )
)
(arithmetic6 addrm2 add add OP1_0 OP2_2 regmem8 memgr8 HI)
(arithmetic7 addrm3 add add OP1_0 OP2_4 memgr8 regmem8 HI)
(arithmetic6 addrm add add OP1_0 OP2_2 reg8 memory HI)
(arithmetic7 addrm1 add add OP1_0 OP2_4 memory reg8 HI)
(arithmetic6 subrm3 sub sub OP1_2 OP2_2 regmem8 memgr8 HI)
(arithmetic7 subrm2 sub sub OP1_2 OP2_4 memgr8 regmem8 HI)
(arithmetic6 subrm1 sub sub OP1_2 OP2_2 reg8 memory HI)
(arithmetic7 subrm sub sub OP1_2 OP2_4 memory reg8 HI)
(arithmetic6 addbrm2 addb add OP1_0 OP2_3 regbmem8 memgr8 QI)
(arithmetic7 addbrm3 addb add OP1_0 OP2_5 memgr8 regbmem8 QI)
(arithmetic6 addbrm addb add OP1_0 OP2_3 regb8 memory QI)
(arithmetic7 addbrm1 addb add OP1_0 OP2_5 memory regb8 QI)
(arithmetic6 subbrm3 subb sub OP1_2 OP2_3 regbmem8 memgr8 QI)
(arithmetic7 subbrm2 subb sub OP1_2 OP2_5 memgr8 regbmem8 QI)
(arithmetic6 subbrm1 subb sub OP1_2 OP2_3 regb8 memory QI)
(arithmetic7 subbrm subb sub OP1_2 OP2_5 memory regb8 QI)

;add/sub registers with carry
(define-pmacro (arithmetic8 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2 cbit))
       ()
  )
)

;add/sub registers with carry
(define-pmacro (arithmetic9 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) (insn1 (mem HI op1) op2 cbit))
       ()
  )
)
(arithmetic8 addcrm2 addc addc OP1_1 OP2_2 regmem8 memgr8 HI)
(arithmetic9 addcrm3 addc addc OP1_1 OP2_4  memgr8 regmem8 HI)
(arithmetic8 addcrm addc addc OP1_1 OP2_2 reg8 memory HI)
(arithmetic9 addcrm1 addc addc OP1_1 OP2_4  memory reg8 HI)
(arithmetic8 subcrm3 subc subc OP1_3 OP2_2  regmem8 memgr8 HI)
(arithmetic9 subcrm2 subc subc OP1_3 OP2_4 memgr8 regmem8 HI)
(arithmetic8 subcrm1 subc subc OP1_3 OP2_2  reg8 memory HI)
(arithmetic9 subcrm subc subc OP1_3 OP2_4 memory reg8 HI)
(arithmetic8 addcbrm2 addcb addc OP1_1 OP2_3 regbmem8 memgr8 QI)
(arithmetic9 addcbrm3 addcb addc OP1_1 OP2_5  memgr8 regbmem8 QI)
(arithmetic8 addcbrm addcb addc OP1_1 OP2_3 regb8 memory QI)
(arithmetic9 addcbrm1 addcb addc OP1_1 OP2_5  memory regb8 QI)
(arithmetic8 subcbrm3 subcb subc OP1_3 OP2_3  regbmem8 memgr8 QI)
(arithmetic9 subcbrm2 subcb subc OP1_3 OP2_5 memgr8 regbmem8 QI)
(arithmetic8 subcbrm1 subcb subc OP1_3 OP2_3  regb8 memory QI)
(arithmetic9 subcbrm subcb subc OP1_3 OP2_5 memory regb8 QI)

; MUL Rwn,Rwm
(dni muls "signed multiplication"
     ((PIPE OS) (IDOC ALU))
     "mul $src1,$src2"
     (+ OP1_0 OP2_11 src1 src2)
     (reg SI h-md 0)
     ()
)
; MULU Rwn,Rwm
(dni mulu "unsigned multiplication"
     ((PIPE OS) (IDOC ALU))
     "mulu $src1,$src2"
     (+ OP1_1 OP2_11 src1 src2)
     (reg SI h-md 0)
     ()
)
; DIV Rwn
(dni div "16-by-16 signed division"
     ((PIPE OS) (IDOC ALU))
     "div $srdiv"
     (+ OP1_4 OP2_11 srdiv )
     (sequence ()
         (set HI (reg HI h-cr 6) (div HI (reg HI h-cr 6) srdiv))
         (set HI (reg HI h-cr 7) (mod HI (reg HI h-cr 6) srdiv))
     )
     ()
) 
; DIVL Rwn
(dni divl "32-by16 signed division"
     ((PIPE OS) (IDOC ALU))
     "divl $srdiv"
     (+ OP1_6 OP2_11 srdiv )
     (sequence ()
         (set HI (reg HI h-cr 6) (div SI (reg SI h-md 0) srdiv))
	 (set HI (reg HI h-cr 7) (mod SI (reg SI h-md 0) srdiv))
     )
     ()
)
; DIVLU Rwn 
(dni divlu "32-by16 unsigned division"
     ((PIPE OS) (IDOC ALU))
     "divlu $srdiv"
     (+ OP1_7 OP2_11 srdiv )
     (sequence ()
         (set HI (reg HI h-cr 6) (udiv SI (reg SI h-md 0) srdiv))
	 (set HI (reg HI h-cr 7) (umod SI (reg SI h-md 0) srdiv))
     )
     ()
)
; DIVU Rwn
(dni divu "16-by-16 unsigned division"
     ((PIPE OS) (IDOC ALU))
     "divu $srdiv"
     (+ OP1_5 OP2_11 srdiv )
     (sequence ()
         (set HI (reg HI h-cr 6) (udiv HI (reg HI h-cr 6) srdiv))
         (set HI (reg HI h-cr 7) (umod HI (reg HI h-cr 6) srdiv))
     )
     ()
)

;Integer one's complement
; CPL Rwn
(dni cpl "Integer Ones complement"
     ((PIPE OS) (IDOC MISC))
     "cpl $dr"
     (+ OP1_9 OP2_1 dr (f-op-bit4 0))
     (set dr (inv HI dr))
     ()
)

;Bytes one's complement
; CPLB Rbn
(dni cplb "Byte Ones complement"
     ((PIPE OS) (IDOC MISC))
     "cplb $drb"
     (+ OP1_11 OP2_1 drb (f-op-bit4 0))
     (set drb (inv QI drb))
     ()
)
;Integer two's complement
; NEG Rwn
(dni neg "Integer two's complement"
     ((PIPE OS) (IDOC MISC))
     "neg $dr"
     (+ OP1_8 OP2_1 dr (f-op-bit4 0))
     (set dr (neg HI dr))
     ()
)
;Bytes two's complement
; NEGB Rbn
(dni negb "byte twos complement"
     ((PIPE OS) (IDOC MISC))
     "negb $drb"
     (+ OP1_10 OP2_1 drb (f-op-bit4 0))
     (set drb (neg QI drb))
     ()
)

;****************************************************************
;logical insn
;****************************************************************
;and/or/xor registers
(define-pmacro (logical name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)

(logical andr and and OP1_6 OP2_0 dr sr HI)
(logical orr or or OP1_7 OP2_0 dr sr HI)
(logical xorr xor xor OP1_5 OP2_0 dr sr HI)
(logical andbr andb and OP1_6 OP2_1 drb srb QI)
(logical orbr orb or OP1_7 OP2_1 drb srb QI)
(logical xorbr xorb xor OP1_5 OP2_1 drb srb QI)

;and/or/xor register and immediate
(define-pmacro (logical1 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(logical1 andri and and OP1_6 OP2_8 dr uimm3 HI)
(logical1 orri or or OP1_7 OP2_8 dr uimm3 HI)
(logical1 xorri xor xor OP1_5 OP2_8 dr uimm3 HI)
(logical1 andbri andb and OP1_6 OP2_9 drb uimm3 QI)
(logical1 orbri orb or OP1_7 OP2_9 drb uimm3 QI)
(logical1 xorbri xorb xor OP1_5 OP2_9 drb uimm3 QI)

;and/or/xor register and immediate
(define-pmacro (logical2 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(logical2 andrim and and OP1_6 OP2_6 reg8 uimm16 HI)
(logical2 orrim or or OP1_7 OP2_6 reg8 uimm16 HI)
(logical2 xorrim xor xor OP1_5 OP2_6 reg8 uimm16 HI)

;and/or/xor register and immediate
(define-pmacro (logical3 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(logical3 andbrim andb and OP1_6 OP2_7 regb8 uimm8 QI)
(logical3 orbrim orb or OP1_7 OP2_7 regb8 uimm8 QI)
(logical3 xorbrim xorb xor OP1_5 OP2_7 regb8 uimm8 QI)

;and/or/xor register and indirect memory
(define-pmacro (logical4 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"]")
       (+ opc1 opc2 op1 (f-op-bit2 2) op2)
       (set mode op1 (insn1 mode op1 (mem HI op2)))
       ()
  )
)
(logical4 and2 and and OP1_6 OP2_8 dr sr2 HI)
(logical4 or2 or or OP1_7 OP2_8 dr sr2 HI)
(logical4 xor2 xor xor OP1_5 OP2_8 dr sr2 HI)
(logical4 andb2 andb and OP1_6 OP2_9 drb sr2 QI)
(logical4 orb2 orb or OP1_7 OP2_9 drb sr2 QI)
(logical4 xorb2 xorb xor OP1_5 OP2_9 drb sr2 QI)

;and/or/xor register and indirect memory post increment
(define-pmacro (logical5 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "logical" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",[$"op2"+]")
       (+ opc1 opc2 op1 (f-op-bit2 3) op2)
       (sequence ()
	   (set mode op1 (insn1 mode op1 (mem HI op2)))
	   (set HI op2 (add HI op2 (const 2)))
       )
       ()
  )
)
(logical5 and2i and and OP1_6 OP2_8 dr sr2 HI)
(logical5 or2i or or OP1_7 OP2_8 dr sr2 HI)
(logical5 xor2i xor xor OP1_5 OP2_8 dr sr2 HI)
(logical5 andb2i andb and OP1_6 OP2_9 drb sr2 QI)
(logical5 orb2i orb or OP1_7 OP2_9 drb sr2 QI)
(logical5 xorb2i xorb xor OP1_5 OP2_9 drb sr2 QI)

;add/sub register and immediate
(define-pmacro (logical7 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"dir"$"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set (mem HI op1) (insn1 (mem HI op1) op2 ))
       ()
  )
)
(logical7 andpofr and and OP1_6 OP2_2 reg8 upof16 HI "pof")
(logical7 orpofr or or OP1_7 OP2_2 reg8 upof16 HI "pof")
(logical7 xorpofr xor xor OP1_5 OP2_2 reg8 upof16 HI "pof")
(logical7 andbpofr andb and OP1_6 OP2_3 regb8 upof16 QI "pof")
(logical7 orbpofr orb or OP1_7 OP2_3 regb8 upof16 QI "pof")
(logical7 xorbpofr xorb xor OP1_5 OP2_3 regb8 upof16 QI "pof")

;add/sub register and immediate
(define-pmacro (logical8 name insn insn1 opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"dir"$"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set (mem HI op1) (insn1 (mem HI op1) op2 ))
       ()
  )
)
(logical8 andrpofr and and OP1_6 OP2_4 upof16 reg8 HI "pof")
(logical8 orrpofr or or OP1_7 OP2_4 upof16 reg8 HI "pof")
(logical8 xorrpofr xor xor OP1_5 OP2_4 upof16 reg8 HI "pof")
(logical8 andbrpofr andb and OP1_6 OP2_5 upof16 regb8 QI "pof")
(logical8 orbrpofr orb or OP1_7 OP2_5 upof16 regb8 QI "pof")
(logical8 xorbrpofr xorb xor OP1_5 OP2_5 upof16 regb8 QI "pof")

;and/or/xor register and direct memory
(define-pmacro (logical6 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)

;and/or/xor register and direct memory
(define-pmacro (logical7 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "arithmetic" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) (insn1 (mem HI op1) op2))
       ()
  )
)
(logical6 andrm2 and and OP1_6 OP2_2 regmem8 memgr8 HI)
(logical7 andrm3 and and OP1_6 OP2_4 memgr8 regmem8 HI)
(logical6 andrm and and OP1_6 OP2_2 reg8 memory HI)
(logical7 andrm1 and and OP1_6 OP2_4 memory reg8 HI)
(logical6 orrm3 or or OP1_7 OP2_2 regmem8 memgr8 HI)
(logical7 orrm2 or or OP1_7 OP2_4 memgr8 regmem8 HI)
(logical6 orrm1 or or OP1_7 OP2_2 reg8 memory HI)
(logical7 orrm or or OP1_7 OP2_4 memory reg8 HI)
(logical6 xorrm3 xor xor OP1_5 OP2_2 regmem8 memgr8 HI)
(logical7 xorrm2 xor xor OP1_5 OP2_4 memgr8 regmem8 HI)
(logical6 xorrm1 xor xor OP1_5 OP2_2 reg8 memory HI)
(logical7 xorrm xor xor OP1_5 OP2_4 memory reg8 HI)
(logical6 andbrm2 andb and OP1_6 OP2_3 regbmem8 memgr8 QI)
(logical7 andbrm3 andb and OP1_6 OP2_5 memgr8 regbmem8 QI)
(logical6 andbrm andb and OP1_6 OP2_3 regb8 memory QI)
(logical7 andbrm1 andb and OP1_6 OP2_5 memory regb8 QI)
(logical6 orbrm3 orb or OP1_7 OP2_3 regbmem8 memgr8 QI)
(logical7 orbrm2 orb or OP1_7 OP2_5 memgr8 regbmem8 QI)
(logical6 orbrm1 orb or OP1_7 OP2_3 regb8 memory QI)
(logical7 orbrm orb or OP1_7 OP2_5 memory regb8 QI)
(logical6 xorbrm3 xorb xor OP1_5 OP2_3 regbmem8 memgr8 QI)
(logical7 xorbrm2 xorb xor OP1_5 OP2_5 memgr8 regbmem8 QI)
(logical6 xorbrm1 xorb xor OP1_5 OP2_3 regb8 memory QI)
(logical7 xorbrm xorb xor OP1_5 OP2_5 memory regb8 QI)

;****************************************************************
;logical insn
;****************************************************************
;mov registers
(define-pmacro (move name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "mov registers" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 op2)
       ()
  )
)
(move movr mov OP1_15 OP2_0 dr sr HI)
(move movrb movb OP1_15 OP2_1 drb srb HI)

;mov register and immediate
(define-pmacro (move1 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op2 op1)
       (set mode op1 op2)
       ()
  )
)
(move1 movri mov  OP1_14 OP2_0 dri u4 HI)
(move1 movbri movb  OP1_14 OP2_1 srb u4 QI)

; MOV Rwn,#data16
(dni movi "move immediate to register"
     ((PIPE OS) (IDOC MOVE))
     "mov $reg8,$hash$uimm16"
     (+ OP1_14 OP2_6 reg8 uimm16)
     (set HI reg8 uimm16)
     ()
)

; MOVB reg,#data8
(dni movbi "move immediate to register"
     ((PIPE OS) (IDOC MOVE))
     "movb $regb8,$hash$uimm8"
     (+ OP1_14 OP2_7 regb8 uimm8 (f-op-bit8 0))
     (set QI regb8 uimm8)
     ()
)

;move and indirect memory
(define-pmacro (mov2 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",[$"op2"]")
       (+ opc1 opc2 op1 op2)
       (set mode op1 (mem HI op2))
       ()
  )
)
(mov2 movr2 mov OP1_10 OP2_8 dr sr HI)
(mov2 movbr2 movb OP1_10 OP2_9 drb sr QI)

;move and indirect memory
(define-pmacro (mov3 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op2 "],$"op1)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (mem HI op2))
       ()
  )
)
(mov3 movri2 mov OP1_11 OP2_8 dr sr HI)
(mov3 movbri2 movb OP1_11 OP2_9 drb sr QI)

;move and indirect memory
(define-pmacro (mov4 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [-$"op2 "],$"op1)
       (+ opc1 opc2 op1 op2)
       (sequence HI ()
	  (set op1 (sub op2 (const HI 2)))
	  (set HI (mem HI op2) op1)
       )
       ()
  )
)
(mov4 movri3 mov OP1_8 OP2_8 dr sr HI)
(mov4 movbri3 movb OP1_8 OP2_9 drb sr QI)

;mov register and indirect memory post increment
(define-pmacro (mov5 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",[$"op2"+]")
       (+ opc1 opc2 op1 op2)
       (sequence ()
	   (set mode op1 (mem HI op2))
	   (set HI op2 (add HI op2 (const 2)))
       )
       ()
  )
)
(mov5 mov2i mov OP1_9 OP2_8 dr sr HI)
(mov5 movb2i movb OP1_9 OP2_9 drb sr HI)

;mov indirect memory
(define-pmacro (mov6 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op1 "],[$"op2"]")
       (+ opc1 opc2 op1 op2)
       (set HI (mem HI op1) (mem HI op2))
       ()
  )
)
(mov6 mov6i mov OP1_12 OP2_8 dr sr HI)
(mov6 movb6i movb OP1_12 OP2_9 dr sr HI)

;mov indirect memory
(define-pmacro (mov7 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op1 "+],[$"op2"]")
       (+ opc1 opc2 op1 op2)
       (sequence ()
          (set mode (mem mode op1) (mem mode op2))
          (set mode op1 (add mode op1 (const mode 2)))
       )
       ()
  )
)
(mov7 mov7i mov OP1_13 OP2_8 dr sr HI)
(mov7 movb7i movb OP1_13 OP2_9 dr sr HI)

;mov indirect memory
(define-pmacro (mov8 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op1 "],[$"op2"+]")
       (+ opc1 opc2 op1 op2)
       (sequence ()
          (set mode (mem mode op1) (mem mode op2))
          (set mode op2 (add mode op2 (const mode 2)))
       )
       ()
  )
)
(mov8 mov8i mov OP1_14 OP2_8 dr sr HI)
(mov8 movb8i movb OP1_14 OP2_9 dr sr HI)

;mov indirect memory
(define-pmacro (mov9 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",[$"op2"+$hash$"uimm16"]")
       (+ opc1 opc2 op1 op2 uimm16)
       (sequence mode ((mode tmp1))
	   (set mode tmp1 (add HI op2 uimm16))
	   (set mode op1 (mem HI tmp1))
       )
       ()
  )
)
(mov9 mov9i mov OP1_13 OP2_4 dr sr HI)
(mov9 movb9i movb OP1_15 OP2_4 drb sr QI)

;mov indirect memory
(define-pmacro (mov10 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op2"+$hash$"uimm16 "],$"op1)
       (+ opc1 opc2 op1 op2 uimm16)
       (sequence mode ((mode tmp1))
	   (set mode tmp1 (add HI op1 uimm16))
	   (set mode (mem HI tmp1) op1)
       )
       ()
  )
)
(mov10 mov10i mov OP1_12 OP2_4 dr sr HI)
(mov10 movb10i movb OP1_14 OP2_4 drb sr QI)

;move and indirect memory
(define-pmacro (mov11 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " [$"op1 "],$"op2)
       (+ opc1 opc2 (f-op-lbit4 0) op1 op2)
       (set (mem mode op1) (mem HI op2))
       ()
  )
)
(mov11 movri11 mov OP1_8 OP2_4 src2 memory HI)
(mov11 movbri11 movb OP1_10 OP2_4 src2 memory HI)

;move and indirect memory
(define-pmacro (mov12 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op2 ",[$"op1"]")
       (+ opc1 opc2 (f-op-lbit4 0) op1 op2)
       (set (mem HI op2) (mem mode op1))
       ()
  )
)
(mov12 movri12 mov OP1_9 OP2_4 src2 memory HI)
(mov12 movbri12 movb OP1_11 OP2_4 src2 memory HI)

(define-pmacro (movemem3 name insn opc1 opc2 op1 op2  dir)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set HI op1 op2)
       ()
  )
)
(movemem3 movehm5 mov OP1_14 OP2_6 regoff8 upof16 "pof")
(movemem3 movehm6 mov OP1_14 OP2_6 regoff8 upag16 "pag")
(movemem3 movehm7 mov OP1_14 OP2_6 regoff8 useg16 "segm")
(movemem3 movehm8 mov OP1_14 OP2_6 regoff8 usof16 "sof")

(define-pmacro (movemem4 name insn opc1 opc2 op1 op2 dir)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op1 op2 (f-op-bit8 0))
       (set QI op1 op2)
       ()
  )
)
(movemem4 movehm9 movb OP1_14 OP2_7 regb8 uimm8 "pof")
(movemem4 movehm10 movb OP1_14 OP2_7 regoff8 uimm8 "pag")

(define-pmacro (movemem name insn opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"dir"$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (mem HI op2))
       ()
  )
)
(movemem movrmp mov OP1_15 OP2_2 regoff8 upof16 HI "pof")
(movemem movrmp1 movb OP1_15 OP2_3 regb8 upof16 QI "pof")
(movemem movrmp2 mov OP1_15 OP2_2 regoff8 upag16 HI "pag")
(movemem movrmp3 movb OP1_15 OP2_3 regb8 upag16 QI "pag")

(define-pmacro (movemem1 name insn opc1 opc2 op1 op2 dir)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"dir"$"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) op2 )
       ()
  )
)
(movemem1 movrmp4 mov OP1_15 OP2_6  upof16 regoff8 "pof")
(movemem1 movrmp5 movb OP1_15 OP2_7 upof16 regb8 "pof")

(define-pmacro (movemem2 name insn opc1 opc2 op1 op2 mode dir)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$hash$"dir"$"op2)
       (+ opc1 opc2 op2 op1)
       (set mode op1 op2)
       ()
  )
)
(movemem2 movehm1 mov OP1_14 OP2_0 dri u4 HI "pof")
(movemem2 movehm2 movb OP1_14 OP2_1 srb u4 QI "pof")
(movemem2 movehm3 mov OP1_14 OP2_0 dri u4 HI "pag")
(movemem2 movehm4 movb OP1_14 OP2_1 srb u4 QI "pag")

;move register and direct memory
(define-pmacro (move12 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (mem HI op2))
       ()
  )
)

;move register and direct memory
(define-pmacro (move13 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set (mem HI op1) op2)
       ()
  )
)
(move12 mve12 mov OP1_15 OP2_2 regmem8 memgr8 HI)
(move13 mve13 mov OP1_15 OP2_6 memgr8 regmem8 HI)
(move12 mover12 mov OP1_15 OP2_2 reg8 memory HI)
(move13 mvr13 mov OP1_15 OP2_6 memory reg8 HI)
(move12 mver12 movb OP1_15 OP2_3 regbmem8 memgr8 QI)
(move13 mver13 movb OP1_15 OP2_7 memgr8 regbmem8 QI)
(move12 movr12 movb OP1_15 OP2_3 regb8 memory QI)
(move13 movr13 movb OP1_15 OP2_7 memory regb8 QI)

; MOVBS Rw,Rb
(dni movbsrr "mov byte register with sign extension to word register"
     ((PIPE OS) (IDOC MOVE))
     "movbs $sr,$drb"
     (+ OP1_13 OP2_0 drb sr)
     (sequence ()
         (if QI (and QI drb (const 128))
                (set HI sr (or HI (const HI 65280) drb)))
         (set HI sr (and HI (const HI 255) drb)) 
     )
     ()
)

; MOVBZ Rw,Rb
(dni movbzrr "mov byte register with zero extension to word register"
     ((PIPE OS) (IDOC MOVE))
     "movbz $sr,$drb"
     (+ OP1_12 OP2_0 drb sr)
     (set HI sr (and HI (const HI 255) drb))
     ()
)

; MOVBS reg,POF mem
(dni movbsrpofm "mov memory to byte register"
     ((PIPE OS) (IDOC MOVE))
     "movbs $regmem8,$pof$upof16"
     (+ OP1_13 OP2_2 regmem8 upof16)
     (set QI regmem8 (mem HI upof16))
     ()
)

; MOVBS pof,reg
(dni movbspofmr "mov memory to byte register"
     ((PIPE OS) (IDOC MOVE))
     "movbs $pof$upof16,$regbmem8"
     (+ OP1_13 OP2_5 upof16 regbmem8 )
     (set QI  (mem HI upof16) regbmem8)
     ()
)

; MOVBZ reg,POF mem
(dni movbzrpofm "mov memory to byte register"
     ((PIPE OS) (IDOC MOVE))
     "movbz $reg8,$pof$upof16"
     (+ OP1_12 OP2_2 reg8 upof16)
     (set QI reg8 (mem HI upof16))
     ()
)

; MOVBZ pof,reg
(dni movbzpofmr "mov memory to byte register"
     ((PIPE OS) (IDOC MOVE))
     "movbz $pof$upof16,$regb8"
     (+ OP1_12 OP2_5 upof16 regb8 )
     (set QI  (mem HI upof16) regb8)
     ()
)

;move register and direct memory
(define-pmacro (move14 name insn opc1 opc2 op1 op2 )
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set HI op1 (and HI (const HI 255) (mem QI op2)))
       ()
  )
)

;move register and direct memory
(define-pmacro (move15 name insn opc1 opc2 op1 op2 )
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op2 op1)
       (set HI (mem HI op1) (and HI (const HI 255) op2))
       ()
  )
)
(move14 movebs14 movbs OP1_13 OP2_2 regmem8 memgr8 )
(move15 movebs15 movbs OP1_13 OP2_5 memgr8 regbmem8 )
(move14 moverbs14 movbs OP1_13 OP2_2 reg8 memory )
(move15 movrbs15 movbs OP1_13 OP2_5 memory regb8 )
(move14 movebz14 movbz OP1_12 OP2_2 regmem8 memgr8 )
(move15 movebz15 movbz OP1_12 OP2_5 memgr8 regbmem8 )
(move14 moverbz14 movbz OP1_12 OP2_2 reg8 memory )
(move15 movrbz15 movbz OP1_12 OP2_5 memory regb8 )


;mov registers
(define-pmacro (moveb1 name insn opc1 opc2 op1 op2)
  (dni name 
       (.str name "move" )
       ((PIPE OS) (IDOC MOVE))
       (.str insn " $"op2 ",$"op1)
       (+ opc1 opc2 op1 op2)
       (sequence ()
           (if QI (and QI op1 (const 128))
                  (set HI op2 (or HI (const HI 65280) op1)))
           (set HI op2 (and HI (const HI 255) op1)) 
       )
       ()
  )
)
(moveb1 movrbs movbs OP1_13 OP2_0 drb sr )
(moveb1 movrbz movbz OP1_12 OP2_0 drb sr )



;jump and call insns
;******************************************************************
;Absolute conditional jump
(define-pmacro (jmpabs name insn)
  (dni name
     (.str name "Absolute conditional jump" )
     ((PIPE OS) (IDOC JMP))
     (.str insn " $extcond,$caddr")
     (+ OP1_14 OP2_10 extcond (f-op-bitone 0) bitone bit01 caddr)
     (sequence ((HI tmp1) (HI tmp2))
        (set tmp1 (mem HI caddr))
        (set tmp2 (sub HI pc (mem HI caddr)))
        (if (gt tmp2 (const 0)) (lt tmp2 (const 32)) (eq tmp2 (const 32))
            (set bitone (const 1)))
	(if (lt tmp2 (const 0)) (eq tmp2 (const 0)) (gt tmp2 (const 32))
            (set bitone (const 0)))
        (if (eq extcond (const 1) (ne extcond cc_Z))
             (set bit01 (const 0))    
             (set HI pc (mem HI caddr)))
	(if (ne extcond (const 1) (eq extcond cc_Z))
             (set bit01 (const 1))
             (set HI pc (add HI pc (const 2))))
     )
     ()
  )
)

(jmpabs jmpa0 jmpa+)
(jmpabs jmpa1 jmpa)

; JMPA- cc,caddr
(dni jmpa- "Absolute conditional jump"
     (COND-CTI (PIPE OS) (IDOC JMP))
     "jmpa- $extcond,$caddr"
     (+ OP1_14 OP2_10 extcond (f-op-bitone 0) bitone (f-op-1bit 1) caddr)
     (sequence ((HI tmp1) (HI tmp2))
        (set tmp1 (mem HI caddr))
        (set tmp2 (sub HI pc (mem HI caddr)))
        (if (gt tmp2 (const 0)) (lt tmp2 (const 32)) (eq tmp2 (const 32))
            (set bitone (const 1)))
	(if (lt tmp2 (const 0)) (eq tmp2 (const 0)) (gt tmp2 (const 32))
            (set bitone (const 0)))
        (set HI pc (add HI pc (const 2)))
     )
     ()
)

; JMPI cc,[Rwn]
(dni jmpi "Indirect conditional jump"
     (COND-CTI (PIPE OS) (IDOC JMP))
     "jmpi $icond,[$sr]"
     (+ OP1_9 OP2_12 icond sr)
     (sequence ()
        (if (eq icond (const 1))
             (set HI pc (mem HI sr)))
             (set HI pc (add HI pc (const 2)))
     )
     ()
)

(define-pmacro (jmprel name insn opc1)
  (dni name
       (.str name "conditional" )
       (COND-CTI (PIPE OS) (IDOC JMP))
       (.str insn " $cond,$rel")
       (+ opc1 OP2_13 rel)
       (sequence ()
           (if (eq cond (const 1))
               (sequence ()
		    (if QI (lt QI rel (const 0))
                           (sequence ()
                                (neg QI rel)
                                (add QI rel (const 1))
                                (mul QI rel (const 2))
                                (set HI pc (sub HI pc rel))
                           ))
                    (set HI pc (add HI pc (mul QI rel (const 2))))
               )
            )
            (set HI pc pc)
       )
       ()
  )
)

(jmprel jmpr_nenz jmpr  COND_NE_NZ )
(jmprel jmpr_sgt jmpr  COND_SGT )
(jmprel jmpr_z jmpr  COND_Z )
(jmprel jmpr_v jmpr  COND_V )
(jmprel jmpr_nv jmpr  COND_NV )
(jmprel jmpr_n jmpr  COND_N )
(jmprel jmpr_nn jmpr  COND_NN )
(jmprel jmpr_c jmpr  COND_C )
(jmprel jmpr_nc jmpr  COND_NC )
(jmprel jmpr_eq jmpr  COND_EQ )
(jmprel jmpr_ne jmpr  COND_NE )
(jmprel jmpr_ult jmpr  COND_ULT )
(jmprel jmpr_ule jmpr  COND_ULE )
(jmprel jmpr_uge jmpr  COND_UGE )
(jmprel jmpr_ugt jmpr  COND_UGT )
(jmprel jmpr_sle jmpr  COND_SLE )
(jmprel jmpr_sge jmpr  COND_SGE )
(jmprel jmpr_net jmpr  COND_NET )
(jmprel jmpr_uc jmpr  COND_UC )
(jmprel jmpr_slt jmpr  COND_SLT )




; JMPS seg,caddr
(dni jmpseg "absolute inter-segment jump"
     (UNCOND-CTI(PIPE OS) (IDOC JMP))
     "jmps $hash$segm$useg8,$hash$sof$usof16"
     (+ OP1_15 OP2_10 seg usof16)
     (sequence ()
          (if QI (eq BI sgtdisbit (const BI 0))
                 (set QI (reg h-cr 10) useg8))
                 (nop)
          (set HI pc usof16)
     )
     ()
)

; JMPS seg,caddr
(dni jmps "absolute inter-segment jump"
     (UNCOND-CTI(PIPE OS) (IDOC JMP))
     "jmps $seg,$caddr"
     (+ OP1_15 OP2_10 seg caddr)
     (sequence ()
          (if QI (eq BI sgtdisbit (const BI 0))
                 (set QI (reg h-cr 10) seg))
                 (nop)
          (set HI pc caddr)
     )
     ()
)


;relative jump if bit set
;JB bitaddrQ.q,rel
(dni jb "relative jump if bit set"
     ((PIPE OS) (IDOC JMP))
     "jb $genreg$dot$qlobit,$relhi"
     (+ OP1_8 OP2_10 genreg relhi qlobit (f-qhibit 0))
     (sequence ((HI tmp1) (HI tmp2))
          (set HI tmp1 genreg)
          (set HI tmp2 (const 1))
          (sll HI tmp2 qlobit)
          (set HI tmp2 (and tmp1 tmp2))
          (if (eq tmp2 (const 1))
             (sequence ()
                (if QI (lt QI relhi (const 0))
                       (set HI pc (add HI pc (mul QI relhi (const 2)))))
             ))
         (set HI pc (add HI pc (const 4))) 
     )
     ()
)

;relative jump if bit set and clear bit
;JBC bitaddrQ.q,rel
(dni jbc "relative jump if bit set and clear bit"
     ((PIPE OS) (IDOC JMP))
     "jbc $genreg$dot$qlobit,$relhi"
     (+ OP1_10 OP2_10 genreg relhi qlobit (f-qhibit 0))
     (sequence ((HI tmp1) (HI tmp2))
          (set HI tmp1 genreg)
          (set HI tmp2 (const 1))
          (sll HI tmp2 qlobit)
          (set HI tmp2 (and tmp1 tmp2))
          (if (eq tmp2 (const 1))
             (sequence ()
                (if QI (lt QI relhi (const 0))
                       (set tmp2 (const 1))
                       (set tmp1 genreg)
                       (sll tmp2 qlobit)
                       (inv tmp2)
                       (set HI tmp1(and tmp1 tmp2))
                       (set HI genreg tmp1)
                       (set HI pc (add HI pc (mul QI relhi (const 2)))))
             ))
          (set HI pc (add HI pc (const 4)))
     )
     ()
)

;relative jump if bit set
;JNB bitaddrQ.q,rel
(dni jnb "relative jump if bit not set"
     ((PIPE OS) (IDOC JMP))
     "jnb $genreg$dot$qlobit,$relhi"
     (+ OP1_9 OP2_10 genreg relhi qlobit (f-qhibit 0))
     (sequence ((HI tmp1) (HI tmp2))
          (set HI tmp1 genreg)
          (set HI tmp2 (const 1))
          (sll HI tmp2 qlobit)
          (set HI tmp2 (and tmp1 tmp2))
          (if (eq tmp2 (const 0))
             (sequence ()
                (if QI (lt QI relhi (const 0))
                       (set HI pc (add HI pc (mul QI relhi (const 2)))))
             ))
          (set HI pc (add HI pc (const 4)))
     )
     ()
)

;relative jump if bit not set and set bit
;JNBS bitaddrQ.q,rel
(dni jnbs "relative jump if bit not set and set bit"
     ((PIPE OS) (IDOC JMP))
     "jnbs $genreg$dot$qlobit,$relhi"
     (+ OP1_11 OP2_10 genreg relhi qlobit (f-qhibit 0))
     (sequence ((HI tmp1) (HI tmp2))
          (set HI tmp1 genreg)
          (set HI tmp2 (const 1))
          (sll HI tmp2 qlobit)
          (set HI tmp2 (and tmp1 tmp2))
          (if (eq tmp2 (const 0))
             (sequence ()
                (if QI (lt QI relhi (const 0))
                       (set tmp2 (const 1))
                       (set tmp1 reg8)
                       (sll tmp2 qbit)
                       (set BI tmp1(or tmp1 tmp2))
                       (set HI reg8 tmp1)
                       (set HI pc (add HI pc (mul QI relhi (const 2)))))
             ))
          (set HI pc (add HI pc (const 4)))
     )
     ()
)


;Absolute conditional call
(define-pmacro (callabs name insn)
  (dni name
     (.str name "Absolute conditional call" )
     ((PIPE OS) (IDOC JMP))
     (.str insn " $extcond,$caddr")
     (+ OP1_12 OP2_10 extcond (f-op-2bit 0) bit01 caddr)
     (sequence ()
        (if (eq extcond (const 1))
          (set bit01 (const 0))
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
	  (set HI (mem HI (reg h-cr 9)) pc)
	  (set HI pc (mem HI caddr)))
        (if (ne extcond (const 1))
          (set bit01 (const 1))
          (set HI pc (add HI pc (const 2))))
     )
     ()
  )
)

(callabs calla0 calla+)
(callabs calla1 calla)

; CALLA- cc,caddr
(dni calla- "Absolute conditional call"
     (COND-CTI (PIPE OS) (IDOC JMP))
     "calla- $extcond,$caddr"
     (+ OP1_12 OP2_10 extcond (f-op-bit3 1) caddr)
     (sequence ()
        (if (eq extcond (const 1))
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
	  (set HI (mem HI (reg h-cr 9)) pc)
	  (set HI pc (mem HI caddr)))
        (set HI pc (add HI pc (const 2)))
     )
     ()
)

; CALLI cc,[Rwn]
(dni calli "indirect subroutine call"
     (COND-CTI (PIPE OS) (IDOC JMP))
     "calli $icond,[$sr]"
     (+ OP1_10 OP2_11 icond sr)
     (sequence ()
         (if (eq icond (const 1))
             (sequence ()
	             (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
        	     (set HI (mem HI (reg h-cr 9)) pc)
        	     (set HI pc (mem HI sr))
             )
         )
         (set HI pc (add HI pc (const 2)))
     )
     ()
)

; CALLR rel
(dni callr "Call subroutine with PC relative signed 8 bit offset"
     ( COND-CTI (PIPE OS) (IDOC JMP))
     "callr $rel"
     (+ OP1_11 OP2_11 rel)
     (sequence ()
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
	  (set HI (mem HI (reg h-cr 9)) pc)
          (sequence ()
                (if QI (lt QI rel (const 0))
                       (sequence ()
                           (neg QI rel)
                           (add QI rel (const 1))
                           (mul QI rel (const 2))
                           (set HI pc (sub HI pc rel))
                       ))
                (set HI pc (add HI pc (mul QI rel (const 2))))
          )
      )
      ()
)


; CALLS seg,caddr
(dni callseg "call inter-segment subroutine"
     (UNCOND-CTI (PIPE OS) (IDOC JMP))
     "calls $hash$segm$useg8,$hash$sof$usof16"
     (+ OP1_13 OP2_10 useg8 usof16)
     (sequence ()
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
          (set HI (mem HI (reg h-cr 9)) (reg h-cr 10))
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
          (set HI (mem HI (reg h-cr 9)) pc)
          (if QI (eq BI sgtdisbit (const BI 0))
                 (set QI (reg h-cr 10) useg8))
                 (nop)
          (set HI pc usof16)
     )
     ()
)

; CALLS seg,caddr
(dni calls "call inter-segment subroutine"
     (UNCOND-CTI (PIPE OS) (IDOC JMP))
     "calls $seg,$caddr"
     (+ OP1_13 OP2_10 seg caddr)
     (sequence ()
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
          (set HI (mem HI (reg h-cr 9)) (reg h-cr 10))
          (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
          (set HI (mem HI (reg h-cr 9)) pc)
          (if QI (eq BI sgtdisbit (const BI 0))
                 (set QI (reg h-cr 10) seg))
                 (nop)
          (set HI pc caddr)
     )
     ()
)

; PCALL reg,caddr
(dni pcall "push word and call absolute subroutine"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "pcall $reg8,$caddr"
       (+ OP1_14 OP2_2 reg8 caddr)
       (sequence ((HI tmp1))
            (set HI tmp1 reg8)
 	    (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
	    (set HI (mem HI (reg h-cr 9)) tmp1)
 	    (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
	    (set HI (mem HI (reg h-cr 9)) pc)
            (set HI pc caddr)
       )
       ()
)

; TRAP #uimm7
(dni trap "software trap"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "trap $hash$uimm7"
       (+ OP1_9 OP2_11 uimm7 (f-op-1bit 0))
       (sequence ()
	    (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
            (set HI (mem HI (reg h-cr 9)) (reg h-cr 4))
              (if QI (eq BI sgtdisbit (const BI 0))
                     (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
                     (set HI (mem HI (reg h-cr 9)) (reg h-cr 10) )
              )
              (nop)
            (set HI (reg h-cr 10) (reg h-cr 11))
            (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))
            (set HI (mem HI (reg h-cr 9)) pc)
            (set HI pc (mul QI uimm7 (const 4)))
       )
       ()
)

;Return insns
; RET
(dni ret "return from subroutine"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "ret"
       (+ OP1_12 OP2_11 (f-op-bit8 0))
       (sequence ()
           (set HI pc (mem HI (reg h-cr 9)))
           (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
       )
       ()
)

; RETS 
(dni rets "return from inter-segment sunroutine"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "rets"
       (+ OP1_13 OP2_11 (f-op-bit8 0))
       (sequence ()
           (set HI pc (mem HI (reg h-cr 9)))
           (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
              (if QI (eq BI sgtdisbit (const BI 0))
                     (set HI (reg h-cr 10) (mem HI (reg h-cr 9)))
              )
              (nop)
     	   (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
       )
       ()
)

; RETP reg
(dni retp "return from subroutine and pop word register"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "retp $reg8"
       (+ OP1_14 OP2_11 reg8)
       (sequence ((HI tmp1))
            (set HI pc (mem HI (reg h-cr 9)))
            (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
	    (set HI tmp1 (mem HI (reg h-cr 9)))
            (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
            (set HI reg8 tmp1)
       )
       ()
)

; RETI
(dni reti "return from ISR"
       (UNCOND-CTI (PIPE OS) (IDOC JMP))
       "reti"
       (+ OP1_15 OP2_11 (f-op-lbit4 8) (f-op-bit4 8))
       (sequence ()
           (set HI pc (mem HI (reg h-cr 9)))
           (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
              (if QI (eq BI sgtdisbit (const BI 0))
                  (sequence ()
                       (set HI (reg h-cr 10) (mem HI (reg h-cr 9)))
                       (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
                  )
              )
              (nop)
           (set HI (reg h-cr 4) (mem HI (reg h-cr 9)))
     	   (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))
       )
       ()
)

;stack operation insn
;******************************************************************
; POP reg
(dni pop "restore register from system stack"
     ((PIPE OS) (IDOC MISC))
     "pop $reg8"
     (+ OP1_15 OP2_12 reg8)
     (sequence ((HI tmp1))
	   (set HI tmp1 (mem HI (reg h-cr 9)))
	   (set (reg h-cr 9) (add HI (reg h-cr 9) (const 2)))         
           (set HI reg8 tmp1)
     )
     ()
)

; PUSH reg
(dni push "save register on system stack"
     ((PIPE OS) (IDOC MISC))
     "push $reg8"
     (+ OP1_14 OP2_12 reg8)
     (sequence ((HI tmp1))
	   (set HI tmp1 reg8)
	   (set (reg h-cr 9) (sub HI (reg h-cr 9) (const 2)))         
           (set HI (mem HI (reg h-cr 9)) tmp1)
     )
     ()
)

;context switching insns
; SCXT reg,#data16
(dni scxti "Push word register on stack and update same with immediate data"
     ((PIPE OS) (IDOC MISC))
     "scxt $reg8,$hash$uimm16"
     (+ OP1_12 OP2_6 reg8 uimm16)
     (sequence ((HI tmp1) (HI tmp2))
         (set HI tmp1 reg8)
         (set HI tmp2 uimm16)
         (sub HI (reg HI h-cr 9) (const 2))
         (set HI (reg HI h-cr 9) tmp1)
         (set HI reg8 tmp2)
     )
     ()
)

; SCXT reg,POF mem
(dni scxtrpofm "mov memory to byte register"
     ((PIPE OS) (IDOC MOVE))
     "scxt $reg8,$pof$upof16"
     (+ OP1_13 OP2_6 reg8 upof16)
     (set QI reg8 (mem HI upof16))
     ()
)

; SCXT regmem8,memgr8
(dni scxtmg "Push word register on stack and update same with direct memory"
     ((PIPE OS) (IDOC MISC))
     "scxt $regmem8,$memgr8"
     (+ OP1_13 OP2_6 regmem8 memgr8)
     (sequence ((HI tmp1) (HI tmp2))
         (set HI tmp1 regmem8)
         (set HI tmp2 memgr8)
         (sub HI (reg HI h-cr 9) (const 2))
         (set HI (reg HI h-cr 9) tmp1)
         (set HI regmem8 tmp2)
     )
     ()
)

; SCXT reg,mem
(dni scxtm "Push word register on stack and update same with direct memory"
     ((PIPE OS) (IDOC MISC))
     "scxt $reg8,$memory"
     (+ OP1_13 OP2_6 reg8 memory)
     (sequence ((HI tmp1) (HI tmp2))
         (set HI tmp1 reg8)
         (set HI tmp2 memory)
         (sub HI (reg HI h-cr 9) (const 2))
         (set HI (reg HI h-cr 9) tmp1)
         (set HI reg8 tmp2)
     )
     ()
)

;No operation
; NOP 
(dni nop "nop"
     ((PIPE OS) (IDOC MISC))
     "nop"
     (+ OP1_12 OP2_12 (f-op-bit8 0))
     ()
     ()
)

;*********system control instructions *********************/

(define-pmacro (sysctrl name insn opc1 opc2 op1 op2 op3)
  (dni name 
       (.str name "miscellaneous" )
       ((PIPE OS) (IDOC MISC))
       (.str insn )
       (+ opc1 opc2 (f-op-lbit4 op1) (f-op-bit4 op2) (f-data8 op3) (f-op-bit8 op3))
       ()
       ()
  )
)
(sysctrl srstm srst  OP1_11 OP2_7 4 8 183 )
(sysctrl idlem idle  OP1_8 OP2_7 7 8 135)
(sysctrl pwrdnm pwrdn  OP1_9 OP2_7 6 8 151)
(sysctrl diswdtm diswdt  OP1_10 OP2_5 5 10 165)
(sysctrl enwdtm enwdt  OP1_8 OP2_5 7 10 133)
(sysctrl einitm einit  OP1_11 OP2_5 4 10 181)
(sysctrl srvwdtm srvwdt  OP1_10 OP2_7 5 8 167 )

;s/w brk
; SBRK 
(dni sbrk "sbrk"
     ((PIPE OS) (IDOC MISC))
     "sbrk"
     (+ OP1_8 OP2_12 (f-op-bit8 0))
     ()
     ()
)

; atomic sequence
; ATOMIC #irang2
(dni atomic "begin atomic sequence"
     ((PIPE OS) (IDOC SYSC))
     "atomic $hash$uimm2"
     (+ OP1_13 OP2_1 (f-op-lbit2 0) uimm2 (f-op-bit4 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended register sequence
; EXTR #irang2
(dni extr "begin extended register sequence"
     ((PIPE OS) (IDOC SYSC))
     "extr $hash$uimm2"
     (+ OP1_13 OP2_1 (f-op-lbit2 2) uimm2 (f-op-bit4 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended page sequence
; EXTP Rw,#irang2
(dni extp "begin extended page sequence"
     ((PIPE OS) (IDOC SYSC))
     "extp $sr,$hash$uimm2"
     (+ OP1_13 OP2_12 (f-op-lbit2 1) uimm2 sr)
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended page sequence
; EXTP #pag10,#irang2
(dni extp1 "begin extended page sequence"
     ((PIPE OS) (IDOC SYSC))
     "extp $hash$pagenum,$hash$uimm2"
     (+ OP1_13 OP2_7 (f-op-lbit2 1) uimm2 (f-op-bit4 0) pagenum (f-qlobit 0) (f-qlobit2 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

; EXTP #pag10,#irang2
(dni extpg1 "begin extended page sequence"
     ((PIPE OS) (IDOC SYSC))
     "extp $hash$pag$upag16,$hash$uimm2"
     (+ OP1_13 OP2_7 (f-op-lbit2 1) uimm2 (f-op-bit4 0) upag16 )
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended page and register sequence
; EXTPR Rw,#irang2
(dni extpr "begin extended page and register sequence"
     ((PIPE OS) (IDOC SYSC))
     "extpr $sr,$hash$uimm2"
     (+ OP1_13 OP2_12 (f-op-lbit2 3) uimm2 sr)
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended page and register sequence
; EXTPR #pag10,#irang2
(dni extpr1 "begin extended page sequence"
     ((PIPE OS) (IDOC SYSC))
     "extpr $hash$pagenum,$hash$uimm2"
     (+ OP1_13 OP2_7 (f-op-lbit2 3) uimm2 (f-op-bit4 0) pagenum (f-qlobit 0) (f-qlobit2 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended segment sequence
; EXTS Rw,#irang2
(dni exts "begin extended segment sequence"
     ((PIPE OS) (IDOC SYSC))
     "exts $sr,$hash$uimm2"
     (+ OP1_13 OP2_12 (f-op-lbit2 0) uimm2 sr)
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended segment sequence
; EXTS #seg8,#irang2
(dni exts1 "begin extended segment sequence"
     ((PIPE OS) (IDOC SYSC))
     "exts $hash$seghi8,$hash$uimm2"
     (+ OP1_13 OP2_7 (f-op-lbit2 0) uimm2 (f-op-bit4 0) seghi8 (f-op-bit8 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended segment register sequence
; EXTSR Rwm,#irang2
(dni extsr "begin extended segment and register sequence"
     ((PIPE OS) (IDOC SYSC))
     "extsr $sr,$hash$uimm2"
     (+ OP1_13 OP2_12 (f-op-lbit2 2) uimm2 sr)
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;extended segment register sequence
; EXTSR #pag10,#irang2
(dni extsr1 "begin extended segment and register sequence"
     ((PIPE OS) (IDOC SYSC))
     "extsr $hash$seghi8,$hash$uimm2"
     (+ OP1_13 OP2_7 (f-op-lbit2 2) uimm2 (f-op-bit4 0) seghi8 (f-op-bit8 0))
     (sequence ((HI count))
	  (set HI count uimm2)
          (cond HI
  	    ((ne HI count (const 0))
	    (sequence ()
	       (set HI pc (add HI pc (const 2)))
               (set HI count (sub HI count (const 1)))
            ))
          )
          (set HI count (const 0))
      )
      ()
)

;prioritize register
;PRIOR Rwn,Rwm
(dni prior "add registers"
     ((PIPE OS) (IDOC ALU))
     "prior $dr,$sr"
     (+ OP1_2 OP2_11 dr sr)
     (sequence ((HI count) (HI tmp1) (HI tmp2))
	  (set HI count (const 0))
	  (set HI tmp1 sr)
	  (set HI tmp2 (and tmp1 (const 32768)))
          (cond HI
  	    ((ne HI tmp2 (const 1)) (ne HI sr (const 0))
	       (sll HI tmp1 (const 1))
               (set HI tmp2 (and tmp1 (const 32768)))
               (set HI count (add HI count (const 1)))
            )
           )        
           (set HI dr count)
      )
      ()
)


;bit instructions
;******************************************************************
;bit clear
(define-pmacro (bclear name insn opc1)
  (dni name
     (.str name "bit clear" )
     ((PIPE OS) (IDOC ALU))
     (.str insn " $reg8$dot$qbit")
     (+ opc1 OP2_14 reg8)
     (sequence ((HI tmp1) (HI tmp2))
     (set tmp2 (const 1))
     (set tmp1 reg8)
     (sll tmp2 qbit)
     (inv tmp2)
     (set BI tmp1(and tmp1 tmp2))
     (set HI reg8 tmp1))
     ()
  )
)

;clear direct bit
(dni bclr18 "bit logical MOVN"
     ((PIPE OS) (IDOC ALU))
     "bclr $RegNam"
     (+ OP1_11 OP2_14 RegNam)
     (sequence ((HI tmp1) (HI tmp2))
     (set tmp2 (const 1))
     (set tmp1 reg8)
     (sll tmp2 qbit)
     (inv tmp2)
     (set BI tmp1(and tmp1 tmp2))
     (set HI reg8 tmp1))
     ()
)


(bclear bclr0 bclr  QBIT_0 )
(bclear bclr1 bclr  QBIT_1 )
(bclear bclr2 bclr  QBIT_2 )
(bclear bclr3 bclr  QBIT_3 )
(bclear bclr4 bclr  QBIT_4 )
(bclear bclr5 bclr  QBIT_5 )
(bclear bclr6 bclr  QBIT_6 )
(bclear bclr7 bclr  QBIT_7 )
(bclear bclr8 bclr  QBIT_8 )
(bclear bclr9 bclr  QBIT_9 )
(bclear bclr10 bclr  QBIT_10 )
(bclear bclr11 bclr  QBIT_11 )
(bclear bclr12 bclr  QBIT_12 )
(bclear bclr13 bclr  QBIT_13 )
(bclear bclr14 bclr  QBIT_14 )
(bclear bclr15 bclr  QBIT_15 )

;set direct bit
(dni bset19 "bit logical MOVN"
     ((PIPE OS) (IDOC ALU))
     "bset $RegNam"
     (+ OP1_11 OP2_15 RegNam)
     (sequence ((HI tmp1) (HI tmp2))
     (set tmp2 (const 1))
     (set tmp1 reg8)
     (sll tmp2 qbit)
     (set BI tmp1(or tmp1 tmp2))
     (set HI reg8 tmp1))
     ()
)

;bit set
(define-pmacro (bitset name insn opc1)
  (dni name
     (.str name "bit set" )
     ((PIPE OS) (IDOC ALU))
     (.str insn " $reg8$dot$qbit")
     (+ opc1 OP2_15 reg8)
     (sequence ((HI tmp1) (HI tmp2))
     (set tmp2 (const 1))
     (set tmp1 reg8)
     (sll tmp2 qbit)
     (set BI tmp1(or tmp1 tmp2))
     (set HI reg8 tmp1))
     ()
  )
)


(bitset bset0 bset  QBIT_0 )
(bitset bset1 bset  QBIT_1 )
(bitset bset2 bset  QBIT_2 )
(bitset bset3 bset  QBIT_3 )
(bitset bset4 bset  QBIT_4 )
(bitset bset5 bset  QBIT_5 )
(bitset bset6 bset  QBIT_6 )
(bitset bset7 bset  QBIT_7 )
(bitset bset8 bset  QBIT_8 )
(bitset bset9 bset  QBIT_9 )
(bitset bset10 bset  QBIT_10 )
(bitset bset11 bset  QBIT_11 )
(bitset bset12 bset  QBIT_12 )
(bitset bset13 bset  QBIT_13 )
(bitset bset14 bset  QBIT_14 )
(bitset bset15 bset  QBIT_15 )

;mov direct bit
;BMOV bitaddrZ.z,bitaddrQ.q
(dni bmov "bit logical MOV"
     ((PIPE OS) (IDOC ALU))
     "bmov $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_4 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (set BI tmp1 tmp2)
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;movn direct bit
;BMOVN bitaddrZ.z,bitaddrQ.q
(dni bmovn "bit logical MOVN"
     ((PIPE OS) (IDOC ALU))
     "bmovn $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_3 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (inv HI tmp2)
     (set BI tmp1 tmp2)
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;and direct bit
;BAND bitaddrZ.z,bitaddrQ.q
(dni band "bit logical AND"
     ((PIPE OS) (IDOC ALU))
     "band $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_6 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (set BI tmp1(and tmp1 tmp2))
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;or direct bit
;BOR bitaddrZ.z,bitaddrQ.q
(dni bor "bit logical OR"
     ((PIPE OS) (IDOC ALU))
     "bor $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_5 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (set BI tmp1(or tmp1 tmp2))
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;xor direct bit
;BXOR bitaddrZ.z,bitaddrQ.q
(dni bxor "bit logical XOR"
     ((PIPE OS) (IDOC ALU))
     "bxor $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_7 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (set BI tmp1(xor tmp1 tmp2))
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;cmp direct bit to bit
;BCMP bitaddrZ.z,bitaddrQ.q
(dni bcmp "bit to bit compare"
     ((PIPE OS) (IDOC ALU))
     "bcmp $reghi8$dot$qhibit,$reg8$dot$qlobit"
     (+ OP1_2 OP2_10 reg8 reghi8 qhibit qlobit)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3) (HI tmp4))
     (set HI tmp1 reghi8)
     (set HI tmp2 reg8)
     (set tmp3 (const 1))
     (set tmp4 (const 1))
     (sll tmp3 qlobit)
     (sll tmp4 qhibit)
     (and tmp1 tmp3)
     (and tmp2 tmp4)
     (set BI tmp1(xor tmp1 tmp2))
     (set HI reghi8 tmp1)
     (set HI reg8 tmp2))
     ()
)

;bit field low byte
;BFLDL op1,op2,op3
(dni bfldl "bit field low byte"
     ((PIPE OS) (IDOC MOVE))
     "bfldl $reg8,$hash$mask8,$hash$datahi8"
     (+ OP1_0 OP2_10 reg8 mask8 datahi8)
     (sequence ((HI tmp1) (QI tmp2) (QI tmp3))
     (set HI tmp1 reg8)
     (set QI tmp2 mask8)
     (set QI tmp3 datahi8)
     (inv QI tmp2)
     (set HI tmp1 (and tmp1 tmp2))
     (set HI tmp1 (or tmp1 tmp3))
     (set HI reg8 tmp1)
     )
     ()
)

;bit field high byte
;BFLDH op1,op2,op3
(dni bfldh "bit field high byte"
     ((PIPE OS) (IDOC MOVE))
     "bfldh $reg8,$hash$masklo8,$hash$data8"
     (+ OP1_1 OP2_10 reg8 masklo8 data8)
     (sequence ((HI tmp1) (HI tmp2) (HI tmp3))
     	     (set HI tmp1 reg8)
	     (set QI tmp2 masklo8)
	     (set HI tmp3 data8)
	     (sll tmp2 (const 8))
	     (inv HI tmp2)
	     (sll tmp3 (const 8))
	     (set HI tmp1 (and tmp1 tmp2))
	     (set HI tmp1 (or tmp1 tmp3))
	     (set HI reg8 tmp1)
     )
     ()
)

;/**********compare instructions******************

;Compare register
;CMP Rwn,Rwm
(dni cmpr "compare two registers"
     ((PIPE OS) (IDOC CMP))
     "cmp $src1,$src2"
     (+ OP1_4 OP2_0 src1 src2)
     (set condbit (lt HI src1 src2))
     ()
)

;Compare byte register
;CMPB Rbn,Rbm
(dni cmpbr "compare two byte registers"
     ((PIPE OS) (IDOC CMP))
     "cmpb $drb,$srb"
     (+ OP1_4 OP2_1 drb srb)
     (set condbit (lt QI drb srb))
     ()
)

(define-pmacro (cmp1 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op1 (f-op-bit1 0) op2)
       (set condbit (lt mode op1 op2))
       ()
  )
)
(cmp1 cmpri cmp OP1_4 OP2_8 src1 uimm3 HI)
(cmp1 cmpbri cmpb OP1_4 OP2_9 drb uimm3 QI)

; CMP Rwn,#data16
(dni cmpi "compare"
     ((PIPE OS) (IDOC CMP))
     "cmp $reg8,$hash$uimm16"
     (+ OP1_4 OP2_6 reg8 uimm16)
     (set condbit (lt HI reg8 uimm16))
     ()
)

; CMPB reg,#data8
(dni cmpbi "compare"
     ((PIPE OS) (IDOC CMP))
     "cmpb $regb8,$hash$uimm8"
     (+ OP1_4 OP2_7 regb8 uimm8 (f-op-bit8 0))
     (set condbit (lt QI regb8 uimm8))
     ()
)

;compare reg and indirect memory
(define-pmacro (cmp2 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",[$"op2"]")
       (+ opc1 opc2 op1 (f-op-bit2 2) op2)
       (set condbit (lt mode op1 op2))
       ()
  )
)
(cmp2 cmpr2 cmp OP1_4 OP2_8 dr sr2 HI)
(cmp2 cmpbr2 cmpb OP1_4 OP2_9 drb sr2 QI)

;compare register and indirect memory post increment
(define-pmacro (cmp3 name insn opc1 opc2 op1 op2 mode)
  (dni name
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",[$"op2"+]")
       (+ opc1 opc2 op1 (f-op-bit2 3) op2)
       (sequence ()
          (set condbit (lt mode op1 op2))
   	  (set HI op2 (add HI op2 (const 2)))
       )
       ()
  )
)
(cmp3 cmp2i cmp OP1_4 OP2_8 dr sr2 HI)
(cmp3 cmpb2i cmpb OP1_4 OP2_9 drb sr2 QI)

;compare register and direct memory
(define-pmacro (cmp4 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$pof$"op2)
       (+ opc1 opc2 op1 op2)
       (set condbit (lt HI op1 (mem HI op2)))
       ()
  )
)
(cmp4 cmp04 cmp OP1_4 OP2_2 reg8 upof16 HI)
(cmp4 cmpb4 cmpb OP1_4 OP2_3 regb8 upof16 QI)

;compare register and direct memory
(define-pmacro (cmp4 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set condbit (lt HI op1 (mem HI op2)))
       ()
  )
)
(cmp4 cmp004 cmp OP1_4 OP2_2 regmem8 memgr8 HI)
(cmp4 cmp0004 cmp OP1_4 OP2_2 reg8 memory HI)
(cmp4 cmpb04 cmpb OP1_4 OP2_3 regbmem8 memgr8 QI)
(cmp4 cmpb004 cmpb OP1_4 OP2_3 regb8 memory QI)

;compare register and immediate
(define-pmacro (cmp5 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op2 op1)
       (sequence ()
            (set condbit (lt HI op1 op2))
	    (set mode op1 (sub HI op1 (const 1)))
       )     
       ()
  )
)
(cmp5 cmpd1ri cmpd1  OP1_10 OP2_0 sr uimm4 HI)
(cmp5 cmpd2ri cmpd2  OP1_11 OP2_0 sr uimm4 HI)
(cmp5 cmpi1ri cmpi1  OP1_8 OP2_0 sr uimm4 HI)
(cmp5 cmpi2ri cmpi2  OP1_9 OP2_0 sr uimm4 HI)
(cmp5 cmpd1rim cmpd1  OP1_10 OP2_6 reg8 uimm16 HI)
(cmp5 cmpd2rim cmpd2  OP1_11 OP2_6 reg8 uimm16 HI)
(cmp5 cmpi1rim cmpi1  OP1_8 OP2_6 reg8 uimm16 HI)
(cmp5 cmpi2rim cmpi2  OP1_9 OP2_6 reg8 uimm16 HI)

;compare register and direct memory
(define-pmacro (cmp6 name insn opc1 opc2 op1 op2 mode )
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$pof$"op2)
       (+ opc1 opc2 op1 op2)
       (sequence ()
            (set condbit (lt HI op1 (mem HI op2)))
	    (set mode op1 (sub HI op1 (const 1)))
       )    
       ()
  )
)
(cmp6 cmpd1rp cmpd1  OP1_10 OP2_2 reg8 upof16 HI )
(cmp6 cmpd2rp cmpd2  OP1_11 OP2_2 reg8 upof16 HI )
(cmp6 cmpi1rp cmpi1  OP1_8 OP2_2 reg8 upof16 HI )
(cmp6 cmpi2rp cmpi2  OP1_9 OP2_2 reg8 upof16 HI )

;compare register and direct memory
(define-pmacro (cmp7 name insn opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "compare" )
       ((PIPE OS) (IDOC CMP))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (sequence ()
            (set condbit (lt HI op1 (mem HI op2)))
	    (set mode op1 (sub HI op1 (const 1)))
       )    
       ()
  )
)
(cmp7 cmpd1rm cmpd1  OP1_10 OP2_2 regmem8 memgr8 HI)
(cmp7 cmpd2rm cmpd2  OP1_11 OP2_2 regmem8 memgr8 HI)
(cmp7 cmpi1rm cmpi1  OP1_8 OP2_2 regmem8 memgr8 HI)
(cmp7 cmpi2rm cmpi2  OP1_9 OP2_2 regmem8 memgr8 HI)
(cmp7 cmpd1rmi cmpd1  OP1_10 OP2_2 reg8 memory HI)
(cmp7 cmpd2rmi cmpd2  OP1_11 OP2_2 reg8 memory HI)
(cmp7 cmpi1rmi cmpi1  OP1_8 OP2_2 reg8 memory HI)
(cmp7 cmpi2rmi cmpi2  OP1_9 OP2_2 reg8 memory HI)


;Shift and rotate insns
;****************************************************************
(define-pmacro (shift name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "shift" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$"op2)
       (+ opc1 opc2 op1 op2)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(shift shlr shl sll OP1_4 OP2_12 dr sr HI)
(shift shrr shr srl OP1_6 OP2_12 dr sr HI)
(shift rolr rol rol OP1_0 OP2_12 dr sr HI)
(shift rorr ror ror OP1_2 OP2_12 dr sr HI)
(shift ashrr ashr sra OP1_10 OP2_12 dr sr HI)

(define-pmacro (shift1 name insn insn1 opc1 opc2 op1 op2 mode)
  (dni name 
       (.str name "shift" )
       ((PIPE OS) (IDOC ALU))
       (.str insn " $"op1 ",$hash$"op2)
       (+ opc1 opc2 op2 op1)
       (set mode op1 (insn1 mode op1 op2))
       ()
  )
)
(shift1 shlri shl sll OP1_5 OP2_12 sr uimm4 HI)
(shift1 shrri shr srl OP1_7 OP2_12 sr uimm4 HI)
(shift1 rolri rol rol OP1_1 OP2_12 sr uimm4 HI)
(shift1 rorri ror ror OP1_3 OP2_12 sr uimm4 HI)
(shift1 ashrri ashr sra OP1_11 OP2_12 sr uimm4 HI)