aboutsummaryrefslogtreecommitdiff
path: root/cpu/frv.cpu
blob: 86eb06716fcdceb82bca6b4262117aa9c162331b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
; Fujitsu FRV opcode support, for GNU Binutils.  -*- Scheme -*-
;
; Copyright 2000, 2001 Free Software Foundation, Inc.
;
; Contributed by Red Hat Inc; developed under contract from Fujitsu.
;
; 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

(include "simplify.inc")

; define-arch must appear first

(define-arch
  (name frv) ; name of cpu architecture
  (comment "Fujitsu FRV")
  (insn-lsb0? #t)
  (machs frv fr500 fr400 tomcat simple)
  (isas frv)
)

(define-isa
  (name frv)
  (base-insn-bitsize 32)
  ; Initial bitnumbers to decode insns by.
  (decode-assist (24 23 22 21 20 19 18))
  (liw-insns 1)       ; The frv fetches  up to 1 insns at a time.
  (parallel-insns 4)  ; The frv executes up to 4 insns at a time.
)

; 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 frvbf)
  (comment "Fujitsu FRV base family")
  (endian big)
  (word-bitsize 32)
)

; Generic FR-V machine. Supports the entire architecture
(define-mach
  (name frv)
  (comment "Generic FRV cpu")
  (cpu frvbf)
)
(define-model
  (name frv) (comment "Generic FRV model") (attrs)
  (mach frv)

  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))

  ; `state' is a list of variables for recording model state
  ; (state)

  (unit u-exec "Execution Unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
)

; FR500 machine.
(define-mach
  (name fr500)
  (comment "FR500 cpu")
  (cpu frvbf)
)
(define-model
  (name fr500) (comment "FR500 model") (attrs)
  (mach fr500)

  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))

  ; `state' is a list of variables for recording model state
  (state
   ; State items
   ; These are all masks with each bit representing one register.
   (prev-fpop       DI) ; Previous use of FR register was floating point insn
   (prev-media      DI) ; Previous use of FR register was a media insn
   (prev-cc-complex DI) ; Previous use of ICC register was not simple
   (cur-fpop        DI) ; Current use of FR register was floating point insn
   (cur-media       DI) ; Current use of FR register was a media insn
   (cur-cc-complex  DI) ; Current use of ICC register was not simple
  )
  ; Basic unit for instructions with no latency penalties
  (unit u-exec "Execution Unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Basic integer insn unit
  (unit u-integer "Integer Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Integer multiplication unit
  (unit u-imul "Integer Multiplication Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRdoublek INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Integer division unit
  (unit u-idiv "Integer Division Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Branch unit
  (unit u-branch "Branch Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)
	 (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
	((pc)) ; outputs
	() ; profile action (default)
	)
  ; Trap unit
  (unit u-trap "Trap Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)
	 (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Condition code check unit
  (unit u-check "Check Unit" ()
	1 1 ; issue done
	() ; state
	((ICCi_3 INT -1) (FCCi_3 INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; GR set half unit
  (unit u-set-hilo "GR Set Half" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	((GRkhi INT -1) (GRklo INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR load unit -- TODO doesn't handle quad
  (unit u-gr-load "GR Load Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (GRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR store unit -- TODO doesn't handle quad
  (unit u-gr-store "GR Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; GR recovering store unit -- TODO doesn't handle quad
  (unit u-gr-r-store "GR Recovering Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; FR load unit -- TODO doesn't handle quad
  (unit u-fr-load "FR Load Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((FRintk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; FR store unit -- TODO doesn't handle quad
  (unit u-fr-store "FR Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; FR recovering store unit -- TODO doesn't handle quad
  (unit u-fr-r-store "FR Recovering Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Swap unit
  (unit u-swap "Swap Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; FR Move to FR unit
  (unit u-fr2fr "FR Move to FR Unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1)) ; inputs
	((FRk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; FR Move to GR unit
  (unit u-fr2gr "FR Move to GR Unit" ()
	1 1 ; issue done
	() ; state
	((FRintk INT -1)) ; inputs
	((GRj INT -1)) ; outputs
	() ; profile action (default)
	)
  ; SPR Move to GR unit
  (unit u-spr2gr "SPR Move to GR Unit" ()
	1 1 ; issue done
	() ; state
	((spr INT -1)) ; inputs
	((GRj INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR Move to FR unit
  (unit u-gr2fr "GR Move to FR Unit" ()
	1 1 ; issue done
	() ; state
	((GRj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR Move to SPR unit
  (unit u-gr2spr "GR Move to SPR Unit" ()
	1 1 ; issue done
	() ; state
	((GRj INT -1)) ; inputs
	((spr INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Arithmetic unit
  (unit u-float-arith "Float Arithmetic unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1) (FRj INT -1) ; inputs
	 (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
	((FRk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Dual Arithmetic unit
  (unit u-float-dual-arith "Float Arithmetic unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1) (FRj INT -1) ; inputs
	 (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
	((FRk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Div unit
  (unit u-float-div "Float Div unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1) (FRj INT -1)) ; inputs
	((FRk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Square Root unit
  (unit u-float-sqrt "Float Square Root unit" ()
	1 1 ; issue done
	() ; state
	((FRj INT -1) (FRdoublej INT -1)) ; inputs
	((FRk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Dual Square Root unit
  (unit u-float-dual-sqrt "Float Dual Square Root unit" ()
	1 1 ; issue done
	() ; state
	((FRj INT -1)) ; inputs
	((FRk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Compare unit
  (unit u-float-compare "Float Compare unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1) (FRj INT -1)
	 (FRdoublei INT -1) (FRdoublej INT -1)) ; inputs
	((FCCi_2 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Dual Float Compare unit
  (unit u-float-dual-compare "Float Dual Compare unit" ()
	1 1 ; issue done
	() ; state
	((FRi INT -1) (FRj INT -1)) ; inputs
	((FCCi_2 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Float Conversion unit
  (unit u-float-convert "Float Conversion unit" ()
	1 1 ; issue done
	() ; state
	((FRj INT -1) (FRintj INT -1) (FRdoublej INT -1)) ; inputs
	((FRk INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Dual Float Conversion unit
  (unit u-float-dual-convert "Float Dual Conversion unit" ()
	1 1 ; issue done
	() ; state
	((FRj INT -1) (FRintj INT -1)) ; inputs
	((FRk INT -1) (FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit
  (unit u-media "Media unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1) (ACC40Si INT -1) (ACCGi INT -1)) ; inputs
	((FRintk INT -1) (ACC40Sk INT -1) (ACC40Uk INT -1) (ACCGk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Quad Arithmetic unit
  (unit u-media-quad-arith "Media Quad Arithmetic unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual Multiplication unit
  (unit u-media-dual-mul "Media Dual Multiplication unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Quad Multiplication unit
  (unit u-media-quad-mul "Media Quad Multiplication unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Quad Complex unit
  (unit u-media-quad-complex "Media Quad Complex unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual Expand unit
  (unit u-media-dual-expand "Media Dual Expand unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual Unpack unit
  (unit u-media-dual-unpack "Media Dual Unpack unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual byte to half unit
  (unit u-media-dual-btoh "Media Byte to byte" ()
	1 1 ; issue done
	() ; state
	((FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual half to byte unit
  (unit u-media-dual-htob "Media Half to byte" ()
	1 1 ; issue done
	() ; state
	((FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual byte to half unit extended
  (unit u-media-dual-btohe "Media Byte to byte extended" ()
	1 1 ; issue done
	() ; state
	((FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Barrier unit
  (unit u-barrier "Barrier unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Memory Barrier unit
  (unit u-membar "Memory Barrier unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache invalidate unit
  (unit u-ici "Insn cache invalidate unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache invalidate unit
  (unit u-dci "Data cache invalidate unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache flush unit
  (unit u-dcf "Data cache flush unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache preload unit
  (unit u-icpl "Insn cache preload unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache preload unit
  (unit u-dcpl "Data cache preload unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache unlock unit
  (unit u-icul "Insn cache unlock unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache unlock unit
  (unit u-dcul "Data cache unlock unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
)

; Tomcat machine. Early version of fr500 machine
(define-mach
  (name tomcat)
  (comment "Tomcat -- early version of fr500")
  (cpu frvbf)
)
(define-model
  (name tomcat) (comment "Tomcat model") (attrs)
  (mach tomcat)

  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))

  ; `state' is a list of variables for recording model state
  ; (state)

  (unit u-exec "Execution Unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
)

; FR400 machine
(define-mach
  (name fr400)
  (comment "FR400 cpu")
  (cpu frvbf)
)
(define-model
  (name fr400) (comment "FR400 model") (attrs)
  (mach fr400)
  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
  ; `state' is a list of variables for recording model state
  (state
   ; State items
   ; These are all masks with each bit representing one register.
   (prev-fp-load    DI) ; Previous use of FR  register was floating point load
   (prev-fr-p4      DI) ; Previous use of FR  register was media unit 4
   (prev-fr-p6      DI) ; Previous use of FR  register was media unit 6
   (prev-acc-p2     DI) ; Previous use of ACC register was media unit 2
   (prev-acc-p4     DI) ; Previous use of ACC register was media unit 4
   (cur-fp-load     DI) ; Current  use of FR  register is  floating point load
   (cur-fr-p4       DI) ; Current  use of FR  register is  media unit 4
   (cur-fr-p6       DI) ; Current  use of FR  register is  media unit 6
   (cur-acc-p2      DI) ; Current  use of ACC register is  media unit 2
   (cur-acc-p4      DI) ; Current  use of ACC register is  media unit 4
  )
  (unit u-exec "Execution Unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Basic integer insn unit
  (unit u-integer "Integer Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Integer multiplication unit
  (unit u-imul "Integer Multiplication Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRdoublek INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Integer division unit
  (unit u-idiv "Integer Division Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (ICCi_1 INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Branch unit
  (unit u-branch "Branch Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)
	 (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
	((pc)) ; outputs
	() ; profile action (default)
	)
  ; Trap unit
  (unit u-trap "Trap Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)
	 (ICCi_2 INT -1) (FCCi_2 INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Condition code check unit
  (unit u-check "Check Unit" ()
	1 1 ; issue done
	() ; state
	((ICCi_3 INT -1) (FCCi_3 INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; GR set half unit
  (unit u-set-hilo "GR Set Half" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	((GRkhi INT -1) (GRklo INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR load unit -- TODO doesn't handle quad
  (unit u-gr-load "GR Load Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1) (GRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR store unit -- TODO doesn't handle quad
  (unit u-gr-store "GR Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (GRk INT -1) (GRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; FR load unit -- TODO doesn't handle quad
  (unit u-fr-load "FR Load Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((FRintk INT -1) (FRdoublek INT -1)) ; outputs
	() ; profile action (default)
	)
  ; FR store unit -- TODO doesn't handle quad
  (unit u-fr-store "FR Store Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1) (FRintk INT -1) (FRdoublek INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Swap unit
  (unit u-swap "Swap Unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	((GRk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; FR Move to GR unit
  (unit u-fr2gr "FR Move to GR Unit" ()
	1 1 ; issue done
	() ; state
	((FRintk INT -1)) ; inputs
	((GRj INT -1)) ; outputs
	() ; profile action (default)
	)
  ; SPR Move to GR unit
  (unit u-spr2gr "SPR Move to GR Unit" ()
	1 1 ; issue done
	() ; state
	((spr INT -1)) ; inputs
	((GRj INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR Move to FR unit
  (unit u-gr2fr "GR Move to FR Unit" ()
	1 1 ; issue done
	() ; state
	((GRj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; GR Move to SPR unit
  (unit u-gr2spr "GR Move to SPR Unit" ()
	1 1 ; issue done
	() ; state
	((GRj INT -1)) ; inputs
	((spr INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M1 -- see table 13-8 in the fr400 LSI
  (unit u-media-1 "Media-1 unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-1-quad "Media-1-quad unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-hilo "Media-hilo unit -- a variation of the Media-1 unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	((FRkhi INT -1) (FRklo INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M2 -- see table 13-8 in the fr400 LSI
  (unit u-media-2 "Media-2 unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-2-quad "Media-2-quad unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1) (ACC40Uk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-2-acc "Media-2-acc unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1)) ; inputs
	((ACC40Sk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-2-acc-dual "Media-2-acc-dual unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1)) ; inputs
	((ACC40Sk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-2-add-sub "Media-2-add-sub unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1)) ; inputs
	((ACC40Sk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-2-add-sub-dual "Media-2-add-sub-dual unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1)) ; inputs
	((ACC40Sk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M3 -- see table 13-8 in the fr400 LSI
  (unit u-media-3 "Media-3 unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-3-dual "Media-3-dual unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-3-quad "Media-3-quad unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M4 -- see table 13-8 in the fr400 LSI
  (unit u-media-4 "Media-4 unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1) (FRintj INT -1)) ; inputs
	((ACC40Sk INT -1) (FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-4-accg "Media-4-accg unit" ()
	1 1 ; issue done
	() ; state
	((ACCGi INT -1) (FRinti INT -1)) ; inputs
	((ACCGk INT -1) (FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  (unit u-media-4-acc-dual "Media-4-acc-dual unit" ()
	1 1 ; issue done
	() ; state
	((ACC40Si INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M6 -- see table 13-8 in the fr400 LSI
  (unit u-media-6 "Media-6 unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media unit M7 -- see table 13-8 in the fr400 LSI
  (unit u-media-7 "Media-1 unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1) (FRintj INT -1)) ; inputs
	((FCCk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual Expand unit
  (unit u-media-dual-expand "Media Dual Expand unit" ()
	1 1 ; issue done
	() ; state
	((FRinti INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Media Dual half to byte unit
  (unit u-media-dual-htob "Media Half to byte" ()
	1 1 ; issue done
	() ; state
	((FRintj INT -1)) ; inputs
	((FRintk INT -1)) ; outputs
	() ; profile action (default)
	)
  ; Barrier unit
  (unit u-barrier "Barrier unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Memory Barrier unit
  (unit u-membar "Memory Barrier unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache invalidate unit
  (unit u-ici "Insn cache invalidate unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache invalidate unit
  (unit u-dci "Data cache invalidate unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache flush unit
  (unit u-dcf "Data cache flush unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache preload unit
  (unit u-icpl "Insn cache preload unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache preload unit
  (unit u-dcpl "Data cache preload unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Insn cache unlock unit
  (unit u-icul "Insn cache unlock unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
  ; Data cache unlock unit
  (unit u-dcul "Data cache unlock unit" ()
	1 1 ; issue done
	() ; state
	((GRi INT -1) (GRj INT -1)) ; inputs
	() ; outputs
	() ; profile action (default)
	)
)

; Simple machine - single issue integer machine
(define-mach
  (name simple)
  (comment "Simple single issue integer cpu")
  (cpu frvbf)
)
(define-model
  (name simple) (comment "Simple model") (attrs)
  (mach simple)
  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
  ; `state' is a list of variables for recording model state
  (state)
  (unit u-exec "Execution Unit" ()
	1 1 ; issue done
	() ; state
	() ; inputs
	() ; outputs
	() ; profile action (default)
	)
)

; The instruction fetch/execute cycle.
;
; This is how to fetch and decode an instruction.
; Leave it out for now

; (define-extract (const SI 0))

; This is how to execute a decoded instruction.
; Leave it out for now

; (define-execute (const SI 0))

; An attribute to describe which unit an insn runs in.
(define-attr
  (for insn)
  (type enum)
  (name UNIT)
  (comment "parallel execution pipeline selection")
  ; The order of declaration is significant. Keep variations on the same unit
  ; together and keep the '01' variation last within each unit.
  (values NIL
	  I0 I1 I01
	  FM0 FM1 FM01
	  B0 B1 B01
	  C
	  MULT-DIV ; multiply/division slotted differently on different machines
	  LOAD     ; loads             slotted differently on different machines
	  NUM_UNITS
  )
)
; Attributes to describe major categories of insns
(define-attr
  (for insn)
  (type enum)
  (name FR400-MAJOR)
  (comment "fr400 major insn categories")
  ; The order of declaration is significant. Keep variations on the same major
  ; together.
  (values NONE
	  I-1 I-2 I-3 I-4 I-5
	  B-1 B-2 B-3 B-4 B-5 B-6
	  C-1 C-2
	  M-1 M-2
  )
)
(define-attr
  (for insn)
  (type enum)
  (name FR500-MAJOR)
  (comment "fr500 major insn categories")
  ; The order of declaration is significant. Keep variations on the same major
  ; together.
  (values NONE
	  I-1 I-2 I-3 I-4 I-5 I-6
	  B-1 B-2 B-3 B-4 B-5 B-6
	  C-1 C-2
	  F-1 F-2 F-3 F-4 F-5 F-6 F-7 F-8
	  M-1 M-2 M-3 M-4 M-5 M-6 M-7 M-8
  )
)
; Privileged insn
(define-attr
  (for insn)
  (type boolean)
  (name PRIVILEGED)
  (comment "insn only allowed in supervisor mode")
)
; Non-Excepting insn
(define-attr
  (for insn)
  (type boolean)
  (name NON-EXCEPTING)
  (comment "non-excepting insn")
)
; Conditional insn
(define-attr
  (for insn)
  (type boolean)
  (name CONDITIONAL)
  (comment "conditional insn")
)
; insn accesses FR registers
(define-attr
  (for insn)
  (type boolean)
  (name FR-ACCESS)
  (comment "insn accesses FR registers")
)
; insn preserves MSR.OVF
(define-attr
  (for insn)
  (type boolean)
  (name PRESERVE-OVF)
  (comment "Preserve value of MSR.OVF")
)
; null attribute -- used as a place holder for where an attribue it required.
(define-attr
  (for insn)
  (type boolean)
  (name NA)
  (comment "placeholder attribute")
  (attrs META) ; do not define in any generated file for now
)

; IDOC attribute for instruction documentation.

(define-attr
  (for insn)
  (type enum)
  (name IDOC)
  (comment "insn kind for documentation")
  (attrs META)
  (values
   (MEM - () "Memory")
   (ALU - () "ALU")
   (FPU - () "FPU")
   (BR - () "Branch")
   (PRIV - () "Priviledged")
   (MISC - () "Miscellaneous")
  )
)

; Instruction fields.
;
; Attributes:
; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
; RESERVED: bits are not used to decode insn, must be all 0
(dnf f-pack      "packing bit"                  () 31  1)
(dnf f-op        "primary opcode"               () 24  7)
(dnf f-ope1      "extended opcode"              () 11  6)
(dnf f-ope2      "extended opcode"              ()  9  4)
(dnf f-ope3      "extended opcode"              () 15  3)
(dnf f-ope4      "extended opcode"              ()  7  2)

(dnf f-GRi       "source register 1"            () 17  6)
(dnf f-GRj       "source register 2"            ()  5  6)
(dnf f-GRk       "destination register"         () 30  6)

(dnf f-FRi       "source register 1"            () 17  6)
(dnf f-FRj       "source register 2"            ()  5  6)
(dnf f-FRk       "destination register"         () 30  6)

(dnf f-CPRi      "source register 1"            () 17  6)
(dnf f-CPRj      "source register 2"            ()  5  6)
(dnf f-CPRk      "destination register"         () 30  6)

(dnf f-ACCGi     "source register"              () 17  6)
(dnf f-ACCGk     "destination register"         () 30  6)

(dnf f-ACC40Si   "40 bit signed accumulator"    () 17  6)
(dnf f-ACC40Ui   "40 bit unsigned accumulator"  () 17  6)
(dnf f-ACC40Sk   "40 bit accumulator"           () 30  6)
(dnf f-ACC40Uk   "40 bit accumulator"           () 30  6)

(dnf f-CRi       "source      register"         () 14  3)
(dnf f-CRj       "source      register"         ()  2  3)
(dnf f-CRk       "destination register"         () 27  3)
(dnf f-CCi       "condition   register"         () 11  3)

(df  f-CRj_int   "target cr for ck insns"       () 26  2 UINT
     ((value pc) (sub WI value 4))
     ((value pc) (add WI value 4))
)
(dnf f-CRj_float "target cr for fck insns"      () 26  2)

(dnf f-ICCi_1    "condition register"           () 11  2)
(dnf f-ICCi_2    "condition register"           () 26  2)
(dnf f-ICCi_3    "condition register"           ()  1  2)
(dnf f-FCCi_1    "condition register"           () 11  2)
(dnf f-FCCi_2    "condition register"           () 26  2)
(dnf f-FCCi_3    "condition register"           ()  1  2)
(dnf f-FCCk      "condition register"           () 26  2)
(dnf f-eir       "exception insn register"      () 17  6)

(df  f-s10       "10 bit sign extended"         ()  9 10  INT #f #f)
(df  f-s12       "12 bit sign extended"         () 11 12  INT #f #f)
(df  f-d12       "12 bit sign extended"         () 11 12  INT #f #f)
(df  f-u16       "16 bit unsigned"              () 15 16 UINT #f #f)
(df  f-s16       "16 bit sign extended"         () 15 16  INT #f #f)
(df  f-s6        "6  bit   signed"              ()  5  6  INT #f #f)
(df  f-s6_1      "6  bit   signed"              () 11  6  INT #f #f)
(df  f-u6        "6  bit unsigned"              ()  5  6 UINT #f #f)
(df  f-s5        "5  bit   signed"              ()  4  5  INT #f #f)

(df  f-u12-h "upper 6 bits of u12"  () 17 6  INT #f #f)
(df  f-u12-l "lower 6 bits of u12"  ()  5 6 UINT #f #f)
(dnmf f-u12   "12 bit signed immediate" () INT
      (f-u12-h f-u12-l)
      (sequence () ; insert
		(set (ifield f-u12-h) (sra SI (ifield f-u12) 6))
		(set (ifield f-u12-l) (and (ifield f-u12) #x3f))
		)
      (sequence () ; extract
		(set (ifield f-u12) (or (sll (ifield f-u12-h) 6)
					(ifield f-u12-l)))
		)
)

(dnf f-int-cc    "integer  branch conditions"   () 30  4)
(dnf f-flt-cc    "floating branch conditions"   () 30  4)
(df  f-cond      "conditional arithmetic"       ()  8  1 UINT #f #f)
(df  f-ccond     "lr branch condition"          () 12  1 UINT #f #f)
(df  f-hint      "2 bit branch prediction hint" () 17  2 UINT #f #f)
(df  f-LI        "link indicator"               () 25  1 UINT #f #f)
(df  f-lock      "cache lock indicator"         () 25  1 UINT #f #f)
(df  f-debug     "debug mode indicator"         () 25  1 UINT #f #f)
(df  f-A         "all accumulator bit"          () 17  1 UINT #f #f)
(df  f-ae        "cache all entries indicator"  () 25  1 UINT #f #f)

(dnf  f-spr-h "upper 6 bits of spr"  () 30  6)
(dnf  f-spr-l "lower 6 bits of spr"  () 17  6)
(dnmf f-spr   "special purpose register" () UINT
      (f-spr-h f-spr-l)
      (sequence () ; insert
		(set (ifield f-spr-h) (srl (ifield f-spr) (const 6)))
		(set (ifield f-spr-l) (and (ifield f-spr) (const #x3f)))
		)
      (sequence () ; extract
		(set (ifield f-spr) (or (sll (ifield f-spr-h) (const 6))
					(ifield f-spr-l)))
		)
)

(df  f-label16    "18 bit pc relative signed offset" (PCREL-ADDR) 15 16 INT
     ((value pc) (sra WI (sub WI value pc) (const 2)))
     ((value pc) (add WI (sll WI value (const 2)) pc))
)

(df   f-labelH6   "upper 6  bits of label24"  () 30  6 INT #f #f)
(dnf  f-labelL18  "lower 18 bits of label24"  () 17 18)
(dnmf f-label24   "26 bit signed offset"     (PCREL-ADDR) INT
      (f-labelH6 f-labelL18)
      ; insert
      (sequence ()
		(set (ifield f-labelH6)
		     (sra WI (sub (ifield f-label24) pc) (const 20)))
		(set (ifield f-labelL18)
		     (and (srl (sub (ifield f-label24) pc) (const 2))
			  (const #x3ffff)))
		)
      ; extract
      (sequence ()
		(set (ifield f-label24)
		     (add (sll (or (sll (ifield f-labelH6) (const 18))
				   (ifield f-labelL18))
			       (const 2))
			  pc)))
)

(dnf f-ICCi_1-null  "null field" (RESERVED) 11  2)
(dnf f-ICCi_2-null  "null field" (RESERVED) 26  2)
(dnf f-ICCi_3-null  "null field" (RESERVED)  1  2)
(dnf f-FCCi_1-null  "null field" (RESERVED) 11  2)
(dnf f-FCCi_2-null  "null field" (RESERVED) 26  2)
(dnf f-FCCi_3-null  "null field" (RESERVED)  1  2)
(dnf f-rs-null      "null field" (RESERVED) 17  6)
(dnf f-GRi-null     "null field" (RESERVED) 17  6)
(dnf f-GRj-null     "null field" (RESERVED)  5  6)
(dnf f-GRk-null     "null field" (RESERVED) 30  6)
(dnf f-FRi-null     "null field" (RESERVED) 17  6)
(dnf f-FRj-null     "null field" (RESERVED)  5  6)
(dnf f-ACCj-null    "null field" (RESERVED)  5  6)
(dnf f-rd-null      "null field" (RESERVED) 30  6)
(dnf f-cond-null    "null field" (RESERVED) 30  4)
(dnf f-ccond-null   "null field" (RESERVED) 12  1)
(dnf f-s12-null     "null field" (RESERVED) 11 12)
(dnf f-label16-null "null field" (RESERVED) 15 16)
(dnf f-misc-null-1  "null field" (RESERVED) 30  5)
(dnf f-misc-null-2  "null field" (RESERVED) 11  6)
(dnf f-misc-null-3  "null field" (RESERVED) 11  4)
(dnf f-misc-null-4  "null field" (RESERVED) 17  2)
(dnf f-misc-null-5  "null field" (RESERVED) 17 16)
(dnf f-misc-null-6  "null field" (RESERVED) 30  3)
(dnf f-misc-null-7  "null field" (RESERVED) 17  3)
(dnf f-misc-null-8  "null field" (RESERVED)  5  3)
(dnf f-misc-null-9  "null field" (RESERVED)  5  4)
(dnf f-misc-null-10 "null field" (RESERVED) 16  5)
(dnf f-misc-null-11 "null field" (RESERVED)  5  1)

(dnf f-LI-off      "null field" (RESERVED) 25  1)
(dnf f-LI-on       "null field" (RESERVED) 25  1)

; Enums.

; insn-op:
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op "insn op enums" () OP_ f-op
 (
 "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
 "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F"
 "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D" "2E" "2F"
 "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F"
 "40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "4A" "4B" "4C" "4D" "4E" "4F"
 "50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "5A" "5B" "5C" "5D" "5E" "5F"
 "60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "6A" "6B" "6C" "6D" "6E" "6F"
 "70" "71" "72" "73" "74" "75" "76" "77" "78" "79" "7A" "7B" "7C" "7D" "7E" "7F"
 )
)

(define-normal-insn-enum insn-ope1 "insn ope enums" () OPE1_ f-ope1
 (
 "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
 "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F"
 "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D" "2E" "2F"
 "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F"
 )
)

(define-normal-insn-enum insn-ope2 "insn ope enums" () OPE2_ f-ope2
 (
 "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
 )
)

(define-normal-insn-enum insn-ope3 "insn ope enums" () OPE3_ f-ope3
 (
 "00" "01" "02" "03" "04" "05" "06" "07"
 )
)

(define-normal-insn-enum insn-ope4 "insn ope enums" () OPE4_ f-ope4
 (
 "0" "1" "2" "3"
 )
)

; int-cc: integer branch conditions
; FIXME: should use die macro or some such
(define-normal-insn-enum int-cc "integer branch cond enums" () ICC_ f-int-cc
  (
   "nev" "c"  "v"  "lt" "eq" "ls" "n" "le"
   "ra"  "nc" "nv" "ge" "ne" "hi" "p" "gt"
  )
)

; flt-cc: floating-point/media branch conditions
; FIXME: should use die macro or some such
(define-normal-insn-enum flt-cc "float branch cond enums" () FCC_ f-flt-cc
  ("nev" "u" "gt" "ug" "lt" "ul" "lg" "ne"
   "eq" "ue" "ge" "uge" "le" "ule" "o" "ra")
)

; 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 PROFILE) (pc) () () ())

; The PSR. The individual fields are referenced more than the entire
; register, so reference them directly. We can assemble the
; entire register contents when necessary.
;
(dsh h-psr_imple "PSR.IMPLE"   () (register UQI))
(dsh h-psr_ver   "PSR.VER"     () (register UQI))
(dsh h-psr_ice   "PSR.ICE bit" () (register BI))
(dsh h-psr_nem   "PSR.NEM bit" () (register BI))
(dsh h-psr_cm    "PSR.CM  bit" () (register BI))
(dsh h-psr_be    "PSR.BE  bit" () (register BI))
(dsh h-psr_esr   "PSR.ESR bit" () (register BI))
(dsh h-psr_ef    "PSR.EF  bit" () (register BI))
(dsh h-psr_em    "PSR.EM  bit" () (register BI))
(dsh h-psr_pil   "PSR.PIL    " () (register UQI))
(dsh h-psr_ps    "PSR.PS  bit" () (register BI))
(dsh h-psr_et    "PSR.ET  bit" () (register BI))

; PSR.S requires special handling because the shadow registers (SR0-SR4) must
; be switched with GR4-GR7 when changing from user to supervisor mode or
; vice-versa.
(define-hardware
  (name h-psr_s)
  (comment "PSR.S bit")
  (attrs)
  (type register BI)
  (get)
  (set (newval) (c-call VOID "@cpu@_h_psr_s_set_handler" newval))
)

; The TBR. The individual bits are referenced more than the entire
; register, so reference them directly. We can assemble the
; entire register contents when necessary.
;
(dsh h-tbr_tba "TBR.TBA" () (register UWI))
(dsh h-tbr_tt  "TBR.TT"  () (register UQI))

; The BPSR. The individual bits are referenced more than the entire
; register, so reference them directly. We can assemble the
; entire register contents when necessary.
;
(dsh h-bpsr_bs   "PSR.S   bit" () (register BI))
(dsh h-bpsr_bet  "PSR.ET  bit" () (register BI))

; General registers
;
(define-keyword
  (name gr-names)
  (print-name h-gr)
  (prefix "")
  (values
   (sp 1) (fp 2)
   (gr0   0)(gr1   1)(gr2   2)(gr3   3)(gr4   4)(gr5   5)(gr6   6)(gr7   7)
   (gr8   8)(gr9   9)(gr10 10)(gr11 11)(gr12 12)(gr13 13)(gr14 14)(gr15 15)
   (gr16 16)(gr17 17)(gr18 18)(gr19 19)(gr20 20)(gr21 21)(gr22 22)(gr23 23)
   (gr24 24)(gr25 25)(gr26 26)(gr27 27)(gr28 28)(gr29 29)(gr30 30)(gr31 31)
   (gr32 32)(gr33 33)(gr34 34)(gr35 35)(gr36 36)(gr37 37)(gr38 38)(gr39 39)
   (gr40 40)(gr41 41)(gr42 42)(gr43 43)(gr44 44)(gr45 45)(gr46 46)(gr47 47)
   (gr48 48)(gr49 49)(gr50 50)(gr51 51)(gr52 52)(gr53 53)(gr54 54)(gr55 55)
   (gr56 56)(gr57 57)(gr58 58)(gr59 59)(gr60 60)(gr61 61)(gr62 62)(gr63 63)
  )
)

(define-hardware
  (name h-gr)
  (comment "general registers")
  (attrs PROFILE)
  (type register USI (64))
  (indices extern-keyword gr-names)
  (get (index) (c-call WI "@cpu@_h_gr_get_handler" index))
  (set (index newval) (c-call VOID "@cpu@_h_gr_set_handler" index newval))
)

; General Registers as double words
; These registers are shadowed onto h-gr
(define-hardware
  (name h-gr_double)
  (comment "general registers as double words")
  (attrs PROFILE VIRTUAL)
  (type register DI (32))
  ; FIXME: Need constraint to prohibit odd numbers.
  (indices extern-keyword gr-names)
  (get (index)
       (c-call DI "@cpu@_h_gr_double_get_handler" index))
  (set (index newval)
       (c-call VOID "@cpu@_h_gr_double_set_handler" index newval))
)

; General Registers as high and low half words
; These registers are shadowed onto h-gr
(define-hardware
  (name h-gr_hi)
  (comment "general registers as high half word")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword gr-names)
  (get (index) (c-call UHI "@cpu@_h_gr_hi_get_handler" index))
  (set (index newval) (c-call VOID "@cpu@_h_gr_hi_set_handler" index newval))
)
(define-hardware
  (name h-gr_lo)
  (comment "general registers as low half word")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword gr-names)
  (get (index) (c-call UHI "@cpu@_h_gr_lo_get_handler" index))
  (set (index newval) (c-call VOID "@cpu@_h_gr_lo_set_handler" index newval))
)

; Floating Point Registers
(define-keyword
  (name fr-names)
  (print-name h-fr)
  (prefix "")
  (values
   (fr0   0)(fr1   1)(fr2   2)(fr3   3)(fr4   4)(fr5   5)(fr6   6)(fr7   7)
   (fr8   8)(fr9   9)(fr10 10)(fr11 11)(fr12 12)(fr13 13)(fr14 14)(fr15 15)
   (fr16 16)(fr17 17)(fr18 18)(fr19 19)(fr20 20)(fr21 21)(fr22 22)(fr23 23)
   (fr24 24)(fr25 25)(fr26 26)(fr27 27)(fr28 28)(fr29 29)(fr30 30)(fr31 31)
   (fr32 32)(fr33 33)(fr34 34)(fr35 35)(fr36 36)(fr37 37)(fr38 38)(fr39 39)
   (fr40 40)(fr41 41)(fr42 42)(fr43 43)(fr44 44)(fr45 45)(fr46 46)(fr47 47)
   (fr48 48)(fr49 49)(fr50 50)(fr51 51)(fr52 52)(fr53 53)(fr54 54)(fr55 55)
   (fr56 56)(fr57 57)(fr58 58)(fr59 59)(fr60 60)(fr61 61)(fr62 62)(fr63 63)
  )
)

(define-hardware
  (name h-fr)
  (comment "floating point registers")
  (attrs PROFILE)
  (type register SF (64))
  (indices extern-keyword fr-names)
  (get (index) (c-call SF "@cpu@_h_fr_get_handler" index))
  (set (index newval) (c-call VOID "@cpu@_h_fr_set_handler" index newval))
)

; Floating Point Registers as double precision
; These registers are shadowed onto h-fr

(define-hardware
  (name h-fr_double)
  (comment "floating point registers as double precision")
  (attrs PROFILE VIRTUAL)
  (type register DF (32))
  ; FIXME: Need constraint to prohibit odd numbers.
  (indices extern-keyword fr-names)
  (get (index)
       (c-call DF "@cpu@_h_fr_double_get_handler" index))
  (set (index newval)
       (c-call VOID "@cpu@_h_fr_double_set_handler" index newval))
)

; Floating Point Registers as integer words.
; These registers are shadowed onto h-fr

(define-hardware
  (name h-fr_int)
  (comment "floating point registers as integers")
  (attrs PROFILE VIRTUAL)
  (type register USI (64))
  (indices extern-keyword fr-names)
  (get (index)
       (c-call USI "@cpu@_h_fr_int_get_handler" index))
  (set (index newval)
       (c-call VOID "@cpu@_h_fr_int_set_handler" index newval))
)

; Floating Point Registers as high and low half words
; These registers are shadowed onto h-fr
(define-hardware
  (name h-fr_hi)
  (comment "floating point registers as unsigned high half word")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (srl (reg h-fr_int regno) 16))
  (set (regno newval) (set (reg h-fr_int regno)
			   (or (and (reg h-fr_int regno) #xffff)
			       (sll newval 16))))
)
(define-hardware
  (name h-fr_lo)
  (comment "floating point registers as unsigned low half word")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (and (reg h-fr_int regno) #xffff))
  (set (regno newval) (set (reg h-fr_int regno)
			   (or (and (reg h-fr_int regno) #xffff0000)
			       (and newval #xffff))))
)

; Floating Point Registers as unsigned bytes
; These registers are shadowed onto h-fr
(define-hardware
  (name h-fr_0)
  (comment "floating point registers as unsigned byte 0")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (and (reg h-fr_int regno) #xff))
  (set (regno newval)
       (sequence ()
		 (if (gt USI newval #xff)
		     (set newval #xff))
		 (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xffffff00)
					   newval))))
)
(define-hardware
  (name h-fr_1)
  (comment "floating point registers as unsigned byte 1")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (and (srl (reg h-fr_int regno) 8) #xff))
  (set (regno newval)
       (sequence ()
		 (if (gt USI newval #xff)
		     (set newval #xff))
		 (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xffff00ff) 
					   (sll newval 8)))))
)
(define-hardware
  (name h-fr_2)
  (comment "floating point registers as unsigned byte 2")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (and (srl (reg h-fr_int regno) 16) #xff))
  (set (regno newval)
       (sequence ()
		 (if (gt USI newval #xff)
		     (set newval #xff))
		 (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #xff00ffff) 
					   (sll newval 16)))))
)
(define-hardware
  (name h-fr_3)
  (comment "floating point registers as unsigned byte 3")
  (attrs PROFILE VIRTUAL)
  (type register UHI (64))
  (indices extern-keyword fr-names)
  (get (regno) (and (srl (reg h-fr_int regno) 24) #xff))
  (set (regno newval)
       (sequence ()
		 (if (gt USI newval #xff)
		     (set newval #xff))
		 (set (reg h-fr_int regno) (or (and (reg h-fr_int regno) #x00ffffff) 
					   (sll newval 24)))))
)
; Coprocessor Registers
;
(define-keyword
  (name cpr-names)
  (print-name h-cpr)
  (prefix "")
  (values
(cpr0   0)(cpr1   1)(cpr2   2)(cpr3   3)(cpr4   4)(cpr5   5)(cpr6   6)(cpr7   7)
(cpr8   8)(cpr9   9)(cpr10 10)(cpr11 11)(cpr12 12)(cpr13 13)(cpr14 14)(cpr15 15)
(cpr16 16)(cpr17 17)(cpr18 18)(cpr19 19)(cpr20 20)(cpr21 21)(cpr22 22)(cpr23 23)
(cpr24 24)(cpr25 25)(cpr26 26)(cpr27 27)(cpr28 28)(cpr29 29)(cpr30 30)(cpr31 31)
(cpr32 32)(cpr33 33)(cpr34 34)(cpr35 35)(cpr36 36)(cpr37 37)(cpr38 38)(cpr39 39)
(cpr40 40)(cpr41 41)(cpr42 42)(cpr43 43)(cpr44 44)(cpr45 45)(cpr46 46)(cpr47 47)
(cpr48 48)(cpr49 49)(cpr50 50)(cpr51 51)(cpr52 52)(cpr53 53)(cpr54 54)(cpr55 55)
(cpr56 56)(cpr57 57)(cpr58 58)(cpr59 59)(cpr60 60)(cpr61 61)(cpr62 62)(cpr63 63)
  )
)

(define-hardware
  (name h-cpr)
  (comment "coprocessor registers")
  (attrs PROFILE (MACH frv))
  (type register WI (64))
  (indices extern-keyword cpr-names)
)

; Coprocessor Registers as double words
; These registers are shadowed onto h-cpr
(define-hardware
  (name h-cpr_double)
  (comment "coprocessor registers as double words")
  (attrs PROFILE VIRTUAL (MACH frv))
  (type register DI (32))
  ; FIXME: Need constraint to prohibit odd numbers.
  (indices extern-keyword cpr-names)
  (get (index)
       (c-call DI "@cpu@_h_cpr_double_get_handler" index))
  (set (index newval)
       (c-call VOID "@cpu@_h_cpr_double_set_handler" index newval))
)

; Special Purpose Registers
;
(define-keyword
  (name spr-names)
  (print-name h-spr)
  (prefix "")
  (values
   (psr        0) (pcsr       1) (bpcsr      2) (tbr        3) (bpsr       4)

   (hsr0      16) (hsr1      17) (hsr2      18) (hsr3      19)
   (hsr4      20) (hsr5      21) (hsr6      22) (hsr7      23)
   (hsr8      24) (hsr9      25) (hsr10     26) (hsr11     27)
   (hsr12     28) (hsr13     29) (hsr14     30) (hsr15     31)
   (hsr16     32) (hsr17     33) (hsr18     34) (hsr19     35)
   (hsr20     36) (hsr21     37) (hsr22     38) (hsr23     39)
   (hsr24     40) (hsr25     41) (hsr26     42) (hsr27     43)
   (hsr28     44) (hsr29     45) (hsr30     46) (hsr31     47)
   (hsr32     48) (hsr33     49) (hsr34     50) (hsr35     51)
   (hsr36     52) (hsr37     53) (hsr38     54) (hsr39     55)
   (hsr40     56) (hsr41     57) (hsr42     58) (hsr43     59)
   (hsr44     60) (hsr45     61) (hsr46     62) (hsr47     63)
   (hsr48     64) (hsr49     65) (hsr50     66) (hsr51     67)
   (hsr52     68) (hsr53     69) (hsr54     70) (hsr55     71)
   (hsr56     72) (hsr57     73) (hsr58     74) (hsr59     75)
   (hsr60     76) (hsr61     77) (hsr62     78) (hsr63     79)

   (ccr      256) (cccr     263) (lr       272) (lcr      273) (isr      288)

   (neear0   352) (neear1   353) (neear2   354) (neear3   355)
   (neear4   356) (neear5   357) (neear6   358) (neear7   359)
   (neear8   360) (neear9   361) (neear10  362) (neear11  363)
   (neear12  364) (neear13  365) (neear14  366) (neear15  367)
   (neear16  368) (neear17  369) (neear18  370) (neear19  371)
   (neear20  372) (neear21  373) (neear22  374) (neear23  375)
   (neear24  376) (neear25  377) (neear26  378) (neear27  379)
   (neear28  380) (neear29  381) (neear30  382) (neear31  383)

   (nesr0    384) (nesr1    385) (nesr2    386) (nesr3    387)
   (nesr4    388) (nesr5    389) (nesr6    390) (nesr7    391)
   (nesr8    392) (nesr9    393) (nesr10   394) (nesr11   395)
   (nesr12   396) (nesr13   397) (nesr14   398) (nesr15   399)
   (nesr16   400) (nesr17   401) (nesr18   402) (nesr19   403)
   (nesr20   404) (nesr21   405) (nesr22   406) (nesr23   407)
   (nesr24   408) (nesr25   409) (nesr26   410) (nesr27   411)
   (nesr28   412) (nesr29   413) (nesr30   414) (nesr31   415)

   (necr     416)

   (gner0    432) (gner1    433)

   (fner0    434) (fner1    435)

   (epcr0    512) (epcr1    513) (epcr2    514) (epcr3    515)
   (epcr4    516) (epcr5    517) (epcr6    518) (epcr7    519)
   (epcr8    520) (epcr9    521) (epcr10   522) (epcr11   523)
   (epcr12   524) (epcr13   525) (epcr14   526) (epcr15   527)
   (epcr16   528) (epcr17   529) (epcr18   530) (epcr19   531)
   (epcr20   532) (epcr21   533) (epcr22   534) (epcr23   535)
   (epcr24   536) (epcr25   537) (epcr26   538) (epcr27   539)
   (epcr28   540) (epcr29   541) (epcr30   542) (epcr31   543)
   (epcr32   544) (epcr33   545) (epcr34   546) (epcr35   547)
   (epcr36   548) (epcr37   549) (epcr38   550) (epcr39   551)
   (epcr40   552) (epcr41   553) (epcr42   554) (epcr43   555)
   (epcr44   556) (epcr45   557) (epcr46   558) (epcr47   559)
   (epcr48   560) (epcr49   561) (epcr50   562) (epcr51   563)
   (epcr52   564) (epcr53   565) (epcr54   566) (epcr55   567)
   (epcr56   568) (epcr57   569) (epcr58   570) (epcr59   571)
   (epcr60   572) (epcr61   573) (epcr62   574) (epcr63   575)

   (esr0     576) (esr1     577) (esr2     578) (esr3     579)
   (esr4     580) (esr5     581) (esr6     582) (esr7     583)
   (esr8     584) (esr9     585) (esr10    586) (esr11    587)
   (esr12    588) (esr13    589) (esr14    590) (esr15    591)
   (esr16    592) (esr17    593) (esr18    594) (esr19    595)
   (esr20    596) (esr21    597) (esr22    598) (esr23    599)
   (esr24    600) (esr25    601) (esr26    602) (esr27    603)
   (esr28    604) (esr29    605) (esr30    606) (esr31    607)
   (esr32    608) (esr33    609) (esr34    610) (esr35    611)
   (esr36    612) (esr37    613) (esr38    614) (esr39    615)
   (esr40    616) (esr41    617) (esr42    618) (esr43    619)
   (esr44    620) (esr45    621) (esr46    622) (esr47    623)
   (esr48    624) (esr49    625) (esr50    626) (esr51    627)
   (esr52    628) (esr53    629) (esr54    630) (esr55    631)
   (esr56    632) (esr57    633) (esr58    634) (esr59    635)
   (esr60    636) (esr61    637) (esr62    638) (esr63    639)

   (eir0     640) (eir1     641) (eir2     642) (eir3     643)
   (eir4     644) (eir5     645) (eir6     646) (eir7     647)
   (eir8     648) (eir9     649) (eir10    650) (eir11    651)
   (eir12    652) (eir13    653) (eir14    654) (eir15    655)
   (eir16    656) (eir17    657) (eir18    658) (eir19    659)
   (eir20    660) (eir21    661) (eir22    662) (eir23    663)
   (eir24    664) (eir25    665) (eir26    666) (eir27    667)
   (eir28    668) (eir29    669) (eir30    670) (eir31    671)

   (esfr0    672) (esfr1    673)

   (sr0      768) (sr1      769) (sr2      770) (sr3      771) 

   (fsr0    1024) (fsr1    1025) (fsr2    1026) (fsr3    1027)
   (fsr4    1028) (fsr5    1029) (fsr6    1030) (fsr7    1031)
   (fsr8    1032) (fsr9    1033) (fsr10   1034) (fsr11   1035)
   (fsr12   1036) (fsr13   1037) (fsr14   1038) (fsr15   1039)
   (fsr16   1040) (fsr17   1041) (fsr18   1042) (fsr19   1043)
   (fsr20   1044) (fsr21   1045) (fsr22   1046) (fsr23   1047)
   (fsr24   1048) (fsr25   1049) (fsr26   1050) (fsr27   1051)
   (fsr28   1052) (fsr29   1053) (fsr30   1054) (fsr31   1055)
   (fsr32   1056) (fsr33   1057) (fsr34   1058) (fsr35   1059)
   (fsr36   1060) (fsr37   1061) (fsr38   1062) (fsr39   1063)
   (fsr40   1064) (fsr41   1065) (fsr42   1066) (fsr43   1067)
   (fsr44   1068) (fsr45   1069) (fsr46   1070) (fsr47   1071)
   (fsr48   1072) (fsr49   1073) (fsr50   1074) (fsr51   1075)
   (fsr52   1076) (fsr53   1077) (fsr54   1078) (fsr55   1079)
   (fsr56   1080) (fsr57   1081) (fsr58   1082) (fsr59   1083)
   (fsr60   1084) (fsr61   1085) (fsr62   1086) (fsr63   1087)

   ; FQ0-FQ31 are 64 bit registers.
   ; These names allow access to the upper 32 bits of the FQ registers.
   (fqop0   1088) (fqop1   1090) (fqop2   1092) (fqop3   1094) 
   (fqop4   1096) (fqop5   1098) (fqop6   1100) (fqop7   1102) 
   (fqop8   1104) (fqop9   1106) (fqop10  1108) (fqop11  1110) 
   (fqop12  1112) (fqop13  1114) (fqop14  1116) (fqop15  1118) 
   (fqop16  1120) (fqop17  1122) (fqop18  1124) (fqop19  1126) 
   (fqop20  1128) (fqop21  1130) (fqop22  1132) (fqop23  1134) 
   (fqop24  1136) (fqop25  1138) (fqop26  1140) (fqop27  1142) 
   (fqop28  1144) (fqop29  1146) (fqop30  1148) (fqop31  1150) 
   ; These names allow access to the lower 32 bits of the FQ registers.
   (fqst0   1089) (fqst1   1091) (fqst2   1093) (fqst3   1095) 
   (fqst4   1097) (fqst5   1099) (fqst6   1101) (fqst7   1103) 
   (fqst8   1105) (fqst9   1107) (fqst10  1109) (fqst11  1111) 
   (fqst12  1113) (fqst13  1115) (fqst14  1117) (fqst15  1119) 
   (fqst16  1121) (fqst17  1123) (fqst18  1125) (fqst19  1127) 
   (fqst20  1129) (fqst21  1131) (fqst22  1133) (fqst23  1135) 
   (fqst24  1137) (fqst25  1139) (fqst26  1141) (fqst27  1143) 
   (fqst28  1145) (fqst29  1147) (fqst30  1149) (fqst31  1151) 
   ; These also access the lower 32 bits of the FQ registers.
   ; These are not accessible as spr registers (see LSI appendix - section 13.4)
;  (fq0     1089) (fq1     1091) (fq2     1093) (fq3     1095) 
;  (fq4     1097) (fq5     1099) (fq6     1101) (fq7     1103) 
;  (fq8     1105) (fq9     1107) (fq10    1109) (fq11    1111) 
;  (fq12    1113) (fq13    1115) (fq14    1117) (fq15    1119) 
;  (fq16    1121) (fq17    1123) (fq18    1125) (fq19    1127) 
;  (fq20    1129) (fq21    1131) (fq22    1133) (fq23    1135) 
;  (fq24    1137) (fq25    1139) (fq26    1141) (fq27    1143) 
;  (fq28    1145) (fq29    1147) (fq30    1149) (fq31    1151) 

   (mcilr0  1272) (mcilr1  1273)

   (msr0    1280) (msr1    1281) (msr2    1282) (msr3    1283)
   (msr4    1284) (msr5    1285) (msr6    1286) (msr7    1287)
   (msr8    1288) (msr9    1289) (msr10   1290) (msr11   1291)
   (msr12   1292) (msr13   1293) (msr14   1294) (msr15   1295)
   (msr16   1296) (msr17   1297) (msr18   1298) (msr19   1299)
   (msr20   1300) (msr21   1301) (msr22   1302) (msr23   1303)
   (msr24   1304) (msr25   1305) (msr26   1306) (msr27   1307)
   (msr28   1308) (msr29   1309) (msr30   1310) (msr31   1311)
   (msr32   1312) (msr33   1313) (msr34   1314) (msr35   1315)
   (msr36   1316) (msr37   1317) (msr38   1318) (msr39   1319)
   (msr40   1320) (msr41   1321) (msr42   1322) (msr43   1323)
   (msr44   1324) (msr45   1325) (msr46   1326) (msr47   1327)
   (msr48   1328) (msr49   1329) (msr50   1330) (msr51   1331)
   (msr52   1332) (msr53   1333) (msr54   1334) (msr55   1335)
   (msr56   1336) (msr57   1337) (msr58   1338) (msr59   1339)
   (msr60   1340) (msr61   1341) (msr62   1342) (msr63   1343)

   ; MQ0-MQ31 are 64 bit registers.
   ; These names allow access to the upper 32 bits of the MQ registers.
   (mqop0   1344) (mqop1   1346) (mqop2   1348) (mqop3   1350) 
   (mqop4   1352) (mqop5   1354) (mqop6   1356) (mqop7   1358) 
   (mqop8   1360) (mqop9   1362) (mqop10  1364) (mqop11  1366) 
   (mqop12  1368) (mqop13  1370) (mqop14  1372) (mqop15  1374) 
   (mqop16  1376) (mqop17  1378) (mqop18  1380) (mqop19  1382) 
   (mqop20  1384) (mqop21  1386) (mqop22  1388) (mqop23  1390) 
   (mqop24  1392) (mqop25  1394) (mqop26  1396) (mqop27  1398) 
   (mqop28  1400) (mqop29  1402) (mqop30  1404) (mqop31  1406) 
   ; These names allow access to the lower 32 bits of the MQ registers.
   (mqst0   1345) (mqst1   1347) (mqst2   1349) (mqst3   1351) 
   (mqst4   1353) (mqst5   1355) (mqst6   1357) (mqst7   1359) 
   (mqst8   1361) (mqst9   1363) (mqst10  1365) (mqst11  1367) 
   (mqst12  1369) (mqst13  1371) (mqst14  1373) (mqst15  1375) 
   (mqst16  1377) (mqst17  1379) (mqst18  1381) (mqst19  1383) 
   (mqst20  1385) (mqst21  1387) (mqst22  1389) (mqst23  1391) 
   (mqst24  1393) (mqst25  1395) (mqst26  1397) (mqst27  1399) 
   (mqst28  1401) (mqst29  1403) (mqst30  1405) (mqst31  1407) 
   ; These also access the lower 32 bits of the MQ registers.
   ; These are not accessible as spr registers (see LSI appendix - section 13.4)
;  (mq0     1345) (mq1     1347) (mq2     1349) (mq3     1351) 
;  (mq4     1353) (mq5     1355) (mq6     1357) (mq7     1359) 
;  (mq8     1361) (mq9     1363) (mq10    1365) (mq11    1367) 
;  (mq12    1369) (mq13    1371) (mq14    1373) (mq15    1375) 
;  (mq16    1377) (mq17    1379) (mq18    1381) (mq19    1383) 
;  (mq20    1385) (mq21    1387) (mq22    1389) (mq23    1391) 
;  (mq24    1393) (mq25    1395) (mq26    1397) (mq27    1399) 
;  (mq28    1401) (mq29    1403) (mq30    1405) (mq31    1407) 

   ; These are not accessible as spr registers (see LSI appendix - section 13.4)
;  (acc0    1408) (acc1    1409) (acc2    1410) (acc3    1411)
;  (acc4    1412) (acc5    1413) (acc6    1414) (acc7    1415)
;  (acc8    1416) (acc9    1417) (acc10   1418) (acc11   1419)
;  (acc12   1420) (acc13   1421) (acc14   1422) (acc15   1423)
;  (acc16   1424) (acc17   1425) (acc18   1426) (acc19   1427)
;  (acc20   1428) (acc21   1429) (acc22   1430) (acc23   1431)
;  (acc24   1432) (acc25   1433) (acc26   1434) (acc27   1435)
;  (acc28   1436) (acc29   1437) (acc30   1438) (acc31   1439)
;  (acc32   1440) (acc33   1441) (acc34   1442) (acc35   1443)
;  (acc36   1444) (acc37   1445) (acc38   1446) (acc39   1447)
;  (acc40   1448) (acc41   1449) (acc42   1450) (acc43   1451)
;  (acc44   1452) (acc45   1453) (acc46   1454) (acc47   1455)
;  (acc48   1456) (acc49   1457) (acc50   1458) (acc51   1459)
;  (acc52   1460) (acc53   1461) (acc54   1462) (acc55   1463)
;  (acc56   1464) (acc57   1465) (acc58   1466) (acc59   1467)
;  (acc60   1468) (acc61   1469) (acc62   1470) (acc63   1471)

;  (accg0   1472) (accg1   1473) (accg2   1474) (accg3   1475)
;  (accg4   1476) (accg5   1477) (accg6   1478) (accg7   1479)
;  (accg8   1480) (accg9   1481) (accg10  1482) (accg11  1483)
;  (accg12  1484) (accg13  1485) (accg14  1486) (accg15  1487)
;  (accg16  1488) (accg17  1489) (accg18  1490) (accg19  1491)
;  (accg20  1492) (accg21  1493) (accg22  1494) (accg23  1495)
;  (accg24  1496) (accg25  1497) (accg26  1498) (accg27  1499)
;  (accg28  1500) (accg29  1501) (accg30  1502) (accg31  1503)
;  (accg32  1504) (accg33  1505) (accg34  1506) (accg35  1507)
;  (accg36  1508) (accg37  1509) (accg38  1510) (accg39  1511)
;  (accg40  1512) (accg41  1513) (accg42  1514) (accg43  1515)
;  (accg44  1516) (accg45  1517) (accg46  1518) (accg47  1519)
;  (accg48  1520) (accg49  1521) (accg50  1522) (accg51  1523)
;  (accg52  1524) (accg53  1525) (accg54  1526) (accg55  1527)
;  (accg56  1528) (accg57  1529) (accg58  1530) (accg59  1531)
;  (accg60  1532) (accg61  1533) (accg62  1534) (accg63  1535)

   (ear0    1536) (ear1    1537) (ear2    1538) (ear3    1539)
   (ear4    1540) (ear5    1541) (ear6    1542) (ear7    1543)
   (ear8    1544) (ear9    1545) (ear10   1546) (ear11   1547)
   (ear12   1548) (ear13   1549) (ear14   1550) (ear15   1551)
   (ear16   1552) (ear17   1553) (ear18   1554) (ear19   1555)
   (ear20   1556) (ear21   1557) (ear22   1558) (ear23   1559)
   (ear24   1560) (ear25   1561) (ear26   1562) (ear27   1563)
   (ear28   1564) (ear29   1565) (ear30   1566) (ear31   1567)
   (ear32   1568) (ear33   1569) (ear34   1570) (ear35   1571)
   (ear36   1572) (ear37   1573) (ear38   1574) (ear39   1575)
   (ear40   1576) (ear41   1577) (ear42   1578) (ear43   1579)
   (ear44   1580) (ear45   1581) (ear46   1582) (ear47   1583)
   (ear48   1584) (ear49   1585) (ear50   1586) (ear51   1587)
   (ear52   1588) (ear53   1589) (ear54   1590) (ear55   1591)
   (ear56   1592) (ear57   1593) (ear58   1594) (ear59   1595)
   (ear60   1596) (ear61   1597) (ear62   1598) (ear63   1599)

   (edr0    1600) (edr1    1601) (edr2    1602) (edr3    1603)
   (edr4    1604) (edr5    1605) (edr6    1606) (edr7    1607)
   (edr8    1608) (edr9    1609) (edr10   1610) (edr11   1611)
   (edr12   1612) (edr13   1613) (edr14   1614) (edr15   1615)
   (edr16   1616) (edr17   1617) (edr18   1618) (edr19   1619)
   (edr20   1620) (edr21   1621) (edr22   1622) (edr23   1623)
   (edr24   1624) (edr25   1625) (edr26   1626) (edr27   1627)
   (edr28   1628) (edr29   1629) (edr30   1630) (edr31   1631)
   (edr32   1632) (edr33   1636) (edr34   1634) (edr35   1635)
   (edr36   1636) (edr37   1637) (edr38   1638) (edr39   1639)
   (edr40   1640) (edr41   1641) (edr42   1642) (edr43   1643)
   (edr44   1644) (edr45   1645) (edr46   1646) (edr47   1647)
   (edr48   1648) (edr49   1649) (edr50   1650) (edr51   1651)
   (edr52   1652) (edr53   1653) (edr54   1654) (edr55   1655)
   (edr56   1656) (edr57   1657) (edr58   1658) (edr59   1659)
   (edr60   1660) (edr61   1661) (edr62   1662) (edr63   1663)

   (iamlr0  1664) (iamlr1  1665) (iamlr2  1666) (iamlr3  1667)
   (iamlr4  1668) (iamlr5  1669) (iamlr6  1670) (iamlr7  1671)
   (iamlr8  1672) (iamlr9  1673) (iamlr10 1674) (iamlr11 1675)
   (iamlr12 1676) (iamlr13 1677) (iamlr14 1678) (iamlr15 1679)
   (iamlr16 1680) (iamlr17 1681) (iamlr18 1682) (iamlr19 1683)
   (iamlr20 1684) (iamlr21 1685) (iamlr22 1686) (iamlr23 1687)
   (iamlr24 1688) (iamlr25 1689) (iamlr26 1690) (iamlr27 1691)
   (iamlr28 1692) (iamlr29 1693) (iamlr30 1694) (iamlr31 1695)
   (iamlr32 1696) (iamlr33 1697) (iamlr34 1698) (iamlr35 1699)
   (iamlr36 1700) (iamlr37 1701) (iamlr38 1702) (iamlr39 1703)
   (iamlr40 1704) (iamlr41 1705) (iamlr42 1706) (iamlr43 1707)
   (iamlr44 1708) (iamlr45 1709) (iamlr46 1710) (iamlr47 1711)
   (iamlr48 1712) (iamlr49 1713) (iamlr50 1714) (iamlr51 1715)
   (iamlr52 1716) (iamlr53 1717) (iamlr54 1718) (iamlr55 1719)
   (iamlr56 1720) (iamlr57 1721) (iamlr58 1722) (iamlr59 1723)
   (iamlr60 1724) (iamlr61 1725) (iamlr62 1726) (iamlr63 1727)

   (iampr0  1728) (iampr1  1729) (iampr2  1730) (iampr3  1731)
   (iampr4  1732) (iampr5  1733) (iampr6  1734) (iampr7  1735)
   (iampr8  1736) (iampr9  1737) (iampr10 1738) (iampr11 1739)
   (iampr12 1740) (iampr13 1741) (iampr14 1742) (iampr15 1743)
   (iampr16 1744) (iampr17 1745) (iampr18 1746) (iampr19 1747)
   (iampr20 1748) (iampr21 1749) (iampr22 1750) (iampr23 1751)
   (iampr24 1752) (iampr25 1753) (iampr26 1754) (iampr27 1755)
   (iampr28 1756) (iampr29 1757) (iampr30 1758) (iampr31 1759)
   (iampr32 1760) (iampr33 1761) (iampr34 1762) (iampr35 1763)
   (iampr36 1764) (iampr37 1765) (iampr38 1766) (iampr39 1767)
   (iampr40 1768) (iampr41 1769) (iampr42 1770) (iampr43 1771)
   (iampr44 1772) (iampr45 1773) (iampr46 1774) (iampr47 1775)
   (iampr48 1776) (iampr49 1777) (iampr50 1778) (iampr51 1779)
   (iampr52 1780) (iampr53 1781) (iampr54 1782) (iampr55 1783)
   (iampr56 1784) (iampr57 1785) (iampr58 1786) (iampr59 1787)
   (iampr60 1788) (iampr61 1789) (iampr62 1790) (iampr63 1791)

   (damlr0  1792) (damlr1  1793) (damlr2  1794) (damlr3  1795)
   (damlr4  1796) (damlr5  1797) (damlr6  1798) (damlr7  1799)
   (damlr8  1800) (damlr9  1801) (damlr10 1802) (damlr11 1803)
   (damlr12 1804) (damlr13 1805) (damlr14 1806) (damlr15 1807)
   (damlr16 1808) (damlr17 1809) (damlr18 1810) (damlr19 1811)
   (damlr20 1812) (damlr21 1813) (damlr22 1814) (damlr23 1815)
   (damlr24 1816) (damlr25 1817) (damlr26 1818) (damlr27 1819)
   (damlr28 1820) (damlr29 1821) (damlr30 1822) (damlr31 1823)
   (damlr32 1824) (damlr33 1825) (damlr34 1826) (damlr35 1827)
   (damlr36 1828) (damlr37 1829) (damlr38 1830) (damlr39 1831)
   (damlr40 1832) (damlr41 1833) (damlr42 1834) (damlr43 1835)
   (damlr44 1836) (damlr45 1837) (damlr46 1838) (damlr47 1839)
   (damlr48 1840) (damlr49 1841) (damlr50 1842) (damlr51 1843)
   (damlr52 1844) (damlr53 1845) (damlr54 1846) (damlr55 1847)
   (damlr56 1848) (damlr57 1849) (damlr58 1850) (damlr59 1851)
   (damlr60 1852) (damlr61 1853) (damlr62 1854) (damlr63 1855)

   (dampr0  1856) (dampr1  1857) (dampr2  1858) (dampr3  1859)
   (dampr4  1860) (dampr5  1861) (dampr6  1862) (dampr7  1863)
   (dampr8  1864) (dampr9  1865) (dampr10 1866) (dampr11 1867)
   (dampr12 1868) (dampr13 1869) (dampr14 1870) (dampr15 1871)
   (dampr16 1872) (dampr17 1873) (dampr18 1874) (dampr19 1875)
   (dampr20 1876) (dampr21 1877) (dampr22 1878) (dampr23 1879)
   (dampr24 1880) (dampr25 1881) (dampr26 1882) (dampr27 1883)
   (dampr28 1884) (dampr29 1885) (dampr30 1886) (dampr31 1887)
   (dampr32 1888) (dampr33 1889) (dampr34 1890) (dampr35 1891)
   (dampr36 1892) (dampr37 1893) (dampr38 1894) (dampr39 1895)
   (dampr40 1896) (dampr41 1897) (dampr42 1898) (dampr43 1899)
   (dampr44 1900) (dampr45 1901) (dampr46 1902) (dampr47 1903)
   (dampr48 1904) (dampr49 1905) (dampr50 1906) (dampr51 1907)
   (dampr52 1908) (dampr53 1909) (dampr54 1910) (dampr55 1911)
   (dampr56 1912) (dampr57 1913) (dampr58 1914) (dampr59 1915)
   (dampr60 1916) (dampr61 1917) (dampr62 1918) (dampr63 1919)

   (amcr    1920) (stbar   1921) (mmcr    1922)
   (dcr     2048) (brr     2049) (nmar    2050)

   (ibar0   2052) (ibar1   2053) (ibar2   2054) (ibar3   2055)
   (dbar0   2056) (dbar1   2057) (dbar2   2058) (dbar3   2059)

   (dbdr00  2060) (dbdr01  2061) (dbdr02  2062) (dbdr03  2063)
   (dbdr10  2064) (dbdr11  2065) (dbdr12  2066) (dbdr13  2067)
   (dbdr20  2068) (dbdr21  2069) (dbdr22  2070) (dbdr23  2071)
   (dbdr30  2072) (dbdr31  2073) (dbdr32  2074) (dbdr33  2075)

   (dbmr00  2076) (dbmr01  2077) (dbmr02  2078) (dbmr03  2079)
   (dbmr10  2080) (dbmr11  2081) (dbmr12  2082) (dbmr13  2083)
   (dbmr20  2084) (dbmr21  2085) (dbmr22  2086) (dbmr23  2087)
   (dbmr30  2088) (dbmr31  2089) (dbmr32  2090) (dbmr33  2091)

   (cpcfr   2092) (cpcr    2093) (cpsr    2094)

   (cpesr0  2096) (cpesr1  2097)
   (cpemr0  2098) (cpemr1  2099)

   (ihsr8   3848)
  )
)

(define-hardware
  (name h-spr)
  (comment "special purpose registers")
  (attrs PROFILE)
  (type register UWI (4096))
  (indices extern-keyword spr-names)
  (get (index) (c-call UWI "@cpu@_h_spr_get_handler" index))
  (set (index newval) (c-call VOID "@cpu@_h_spr_set_handler" index newval))
)

(define-pmacro (spr-pcsr)  (reg h-spr   1))
(define-pmacro (spr-bpcsr) (reg h-spr   2))
(define-pmacro (spr-lr)    (reg h-spr 272))
(define-pmacro (spr-lcr)   (reg h-spr 273))
(define-pmacro (spr-sr0)   (reg h-spr 768))
(define-pmacro (spr-sr1)   (reg h-spr 769))
(define-pmacro (spr-sr2)   (reg h-spr 770))
(define-pmacro (spr-sr3)   (reg h-spr 771))

; Accumulator guard. Actually a subset of the SPR registers, but those SPRs
; are read-only in most insns. This hardware element is used by those insns
; which have direct access (mwtaccg, mrdaccg).
(define-keyword
  (name accg-names)
  (print-name h-accg)
  (prefix "")
  (values
   (accg0   0)(accg1   1)(accg2   2)(accg3   3)
   (accg4   4)(accg5   5)(accg6   6)(accg7   7)
   (accg8   8)(accg9   9)(accg10 10)(accg11 11)
   (accg12 12)(accg13 13)(accg14 14)(accg15 15)
   (accg16 16)(accg17 17)(accg18 18)(accg19 19)
   (accg20 20)(accg21 21)(accg22 22)(accg23 23)
   (accg24 24)(accg25 25)(accg26 26)(accg27 27)
   (accg28 28)(accg29 29)(accg30 30)(accg31 31)
   (accg32 32)(accg33 33)(accg34 34)(accg35 35)
   (accg36 36)(accg37 37)(accg38 38)(accg39 39)
   (accg40 40)(accg41 41)(accg42 42)(accg43 43)
   (accg44 44)(accg45 45)(accg46 46)(accg47 47)
   (accg48 48)(accg49 49)(accg50 50)(accg51 51)
   (accg52 52)(accg53 53)(accg54 54)(accg55 55)
   (accg56 56)(accg57 57)(accg58 58)(accg59 59)
   (accg60 60)(accg61 61)(accg62 62)(accg63 63)
  )
)

(define-hardware
  (name h-accg)
  (comment "accumulator guard")
  (attrs PROFILE VIRTUAL)
  (type register UWI (64))
  (indices extern-keyword accg-names)
  (get (index)
       (and (reg h-spr (add index 1472)) #xff))
  (set (index newval)
       (set (raw-reg UWI h-spr (add index 1472)) (and newval #xff)))
)

; 40 bit accumulator. Composed of ACCG and ACC registers concatenated, but
; referenced more often as the composed 40 bits.
(define-keyword
  (name acc-names)
  (print-name h-acc40)
  (prefix "")
  (values
(acc0   0)(acc1   1)(acc2   2)(acc3   3)(acc4   4)(acc5   5)(acc6   6)(acc7   7)
(acc8   8)(acc9   9)(acc10 10)(acc11 11)(acc12 12)(acc13 13)(acc14 14)(acc15 15)
(acc16 16)(acc17 17)(acc18 18)(acc19 19)(acc20 20)(acc21 21)(acc22 22)(acc23 23)
(acc24 24)(acc25 25)(acc26 26)(acc27 27)(acc28 28)(acc29 29)(acc30 30)(acc31 31)
(acc32 32)(acc33 33)(acc34 34)(acc35 35)(acc36 36)(acc37 37)(acc38 38)(acc39 39)
(acc40 40)(acc41 41)(acc42 42)(acc43 43)(acc44 44)(acc45 45)(acc46 46)(acc47 47)
(acc48 48)(acc49 49)(acc50 50)(acc51 51)(acc52 52)(acc53 53)(acc54 54)(acc55 55)
(acc56 56)(acc57 57)(acc58 58)(acc59 59)(acc60 60)(acc61 61)(acc62 62)(acc63 63)
  )
)

(define-hardware
  (name h-acc40S)
  (comment "40 bit signed accumulator")
  (attrs PROFILE VIRTUAL)
  (type register DI (64))
  (indices extern-keyword acc-names)
  ; The accumlator is made up of two 32 bit registers, accgi/acci.
  ; We want to extract this as a combined 40 signed bits
  (get (index)
       (or DI
	   (sll  DI (ext DI (trunc QI (reg h-spr (add index 1472))))
		 32)
	   (zext DI (reg h-spr (add index 1408)))))
  ; Bits 40-63 are not written. raw-reg is used to bypass read-only restrictions
  ; on ACC and ACCG registers
  (set (index newval)
       (sequence ()
		 (c-call VOID "frv_check_spr_write_access" (add index 1408))
		 (set (raw-reg UWI h-spr
			       (add index 1472)) (and (srl newval 32) #xff))
		 (set (raw-reg UWI h-spr
			       (add index 1408)) (trunc USI newval))))
)

(define-hardware
  (name h-acc40U)
  (comment "40 bit unsigned accumulator")
  (attrs PROFILE VIRTUAL)
  (type register UDI (64))
  (indices extern-keyword acc-names)
  ; The accumlator is made up of two 32 bit registers, accgi/acci.
  ; We want to extract this as a combined 40 unsigned bits
  (get (index)
       (or DI
	   (sll  DI (zext DI (reg h-spr (add index 1472))) 32)
	   (zext DI (reg h-spr (add index 1408)))))
  ; Bits 40-63 are not written. raw-reg is used to bypass read-only restrictions
  ; on ACC and ACCG registers
  (set (index newval)
       (sequence ()
		 (c-call VOID "frv_check_spr_write_access" (add index 1408))
		 (set (raw-reg UWI h-spr
			       (add index 1472)) (and (srl newval 32) #xff))
		 (set (raw-reg UWI h-spr
			       (add index 1408)) (trunc USI newval))))
)

; Integer condition code registers (CCR)
;
; The individual sub registers bits of the CCR are referenced more often than
; the entire register so set them directly. We can assemble the
; entire register when necessary.
;
(define-keyword
  (name iccr-names)
  (print-name h-iccr)
  (prefix "")
  (values (icc0 0) (icc1 1) (icc2 2) (icc3 3))
)

(define-hardware
  (name h-iccr)
  (comment "Integer condition code registers")
  (attrs PROFILE)
  (type register UQI (4))
  (indices extern-keyword iccr-names)
)

; Floating point condition code registers (CCR)
;
; The individual sub registers bits of the CCR are referenced more often than
; the entire register so set them directly. We can assemble the
; entire register when necessary.
;
(define-keyword
  (name fccr-names)
  (print-name h-fccr)
  (prefix "")
  (values (fcc0 0) (fcc1 1) (fcc2 2) (fcc3 3))
)

(define-hardware
  (name h-fccr)
  (comment "Integer condition code registers")
  (attrs PROFILE)
  (type register UQI (4))
  (indices extern-keyword fccr-names)
)

; C condition code registers (CCCR)
;
(define-keyword
  (name cccr-names)
  (print-name h-cccr)
  (prefix "")
  (values (cc0 0) (cc1 1) (cc2 2) (cc3 3) (cc4 4) (cc5 5) (cc6 6) (cc7 7))
)

(define-hardware
  (name h-cccr)
  (comment "Condition code registers")
  (attrs PROFILE)
  (type register UQI (8))
  (indices extern-keyword cccr-names)
)

; Dummy hardware used to define packing bit on insns
;
(define-hardware
  (name h-pack)
  (comment "Packing bit dummy hardware")
  (type immediate (UINT 1))
  (values keyword "" (("" 1) (".p" 0) (".P" 0)))
)
; Dummy hardware used to define hint field for branches always taken
;
(define-hardware
  (name h-hint-taken)
  (comment "Branch taken hint dummy hardware")
  (type immediate (UINT 1))
  ; The order of these is important. We want '2' to get written by default,
  ; but we also want the docoder/disassembler to allow the values '0', '1' and
  ; '3'.
  (values keyword "" (("" 2) ("" 0) ("" 1) ("" 3)))
)
; Dummy hardware used to define hint field for branches never taken
;
(define-hardware
  (name h-hint-not-taken)
  (comment "Branch not taken hint dummy hardware")
  (type immediate (UINT 1))
  ; The order of these is important. We want '0' to get written by default,
  ; but we also want the docoder/disassembler to allow the values '1', '2' and
  ; '3'.
  (values keyword "" (("" 0) ("" 1) ("" 2) ("" 3)))
)

; Instruction Operands.
; These entries provide a layer between the assembler and the raw hardware
; description, and are used to refer to hardware elements in the semantic
; code.  Usually there's a bit of over-specification, but in more complicated
; instruction sets there isn't.

; FRV specific operand attributes:

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

; ??? Convention says this should be o-sr, but then the insn definitions
; should refer to o-sr which is clumsy.  The "o-" could be implicit, but
; then it should be implicit for all the symbols here, but then there would
; be confusion between (f-)simm8 and (h-)simm8.
; So for now the rule is exactly as it appears here.

; dnmop: define-normal-mode-operand: temporary, pending potential removal
; of modes from h/w.
(define-pmacro (dnmop xname xcomment xattrs xtype xindex xmode)
  (define-operand
    (name xname)
    (comment xcomment)
    (.splice attrs (.unsplice xattrs))
    (type xtype)
    (index xindex)
    (mode xmode)
    )
)

(dnop  pack "packing bit" () h-pack f-pack)

(dnmop GRi        "source register 1"      () h-gr        f-GRi  SI)
(dnmop GRj        "source register 2"      () h-gr        f-GRj  SI)
(dnmop GRk        "destination register"   () h-gr        f-GRk  SI)
(dnmop GRkhi      "destination register"   () h-gr_hi     f-GRk  UHI)
(dnmop GRklo      "destination register"   () h-gr_lo     f-GRk  UHI)
(dnmop GRdoublek  "destination register"   () h-gr_double f-GRk  DI)
(dnmop ACC40Si    "signed accumulator"     () h-acc40S    f-ACC40Si DI)
(dnmop ACC40Ui    "unsigned accumulator"   () h-acc40U    f-ACC40Ui UDI)
(dnmop ACC40Sk    "target accumulator"     () h-acc40S    f-ACC40Sk DI)
(dnmop ACC40Uk    "target accumulator"     () h-acc40U    f-ACC40Uk UDI)
(dnmop ACCGi      "source register"        () h-accg      f-ACCGi   UWI)
(dnmop ACCGk      "target register"        () h-accg      f-ACCGk   UWI)

(dnmop CPRi       "source register"        ((MACH frv)) h-cpr        f-CPRi SI)
(dnmop CPRj       "source register"        ((MACH frv)) h-cpr        f-CPRj SI)
(dnmop CPRk       "destination register"   ((MACH frv)) h-cpr        f-CPRk SI)
(dnmop CPRdoublek "destination register"   ((MACH frv)) h-cpr_double f-CPRk DI)

; floating point operands
(dnmop FRinti    "source register 1"      () h-fr_int    f-FRi SI)
(dnmop FRintj    "source register 2"      () h-fr_int    f-FRj SI)
(dnmop FRintk    "target register"        () h-fr_int    f-FRk SI)
(dnmop FRi       "source register 1"      () h-fr        f-FRi SF)
(dnmop FRj       "source register 2"      () h-fr        f-FRj SF)
(dnmop FRk       "destination register"   () h-fr        f-FRk SF)
(dnmop FRkhi     "destination register"   () h-fr_hi     f-FRk UHI)
(dnmop FRklo     "destination register"   () h-fr_lo     f-FRk UHI)
(dnmop FRdoublei "source register 1"      () h-fr_double f-FRi DF)
(dnmop FRdoublej "source register 2"      () h-fr_double f-FRj DF)
(dnmop FRdoublek "target register"        () h-fr_double f-FRk DF)

(dnop CRi       "source register 1"       () h-cccr f-CRi)
(dnop CRj       "source register 2"       () h-cccr f-CRj)
(dnop CRj_int   "destination register"    () h-cccr f-CRj_int)
(dnop CRj_float "destination register"    () h-cccr f-CRj_float)
(dnop CRk       "destination register"    () h-cccr f-CRk)
(dnop CCi       "condition   register"    () h-cccr f-CCi)

(dnop ICCi_1  "condition   register"      () h-iccr f-ICCi_1)
(dnop ICCi_2  "condition   register"      () h-iccr f-ICCi_2)
(dnop ICCi_3  "condition   register"      () h-iccr f-ICCi_3)
(dnop FCCi_1  "condition   register"      () h-fccr f-FCCi_1)
(dnop FCCi_2  "condition   register"      () h-fccr f-FCCi_2)
(dnop FCCi_3  "condition   register"      () h-fccr f-FCCi_3)
(dnop FCCk    "condition   register"      () h-fccr f-FCCk)

(dnop eir     "exception insn reg"        () h-uint f-eir)
(dnop s10     "10 bit signed immediate"   (HASH-PREFIX) h-sint f-s10)
(dnop u16     "16 bit unsigned immediate" (HASH-PREFIX) h-uint f-u16)
(dnop s16     "16 bit signed   immediate" (HASH-PREFIX) h-sint f-s16)
(dnop s6      "6  bit signed   immediate" (HASH-PREFIX) h-sint f-s6)
(dnop s6_1    "6  bit signed   immediate" (HASH-PREFIX) h-sint f-s6_1)
(dnop u6      "6  bit unsigned immediate" (HASH-PREFIX) h-uint f-u6)
(dnop s5      "5  bit signed   immediate" (HASH-PREFIX) h-sint f-s5)
(dnop cond    "conditional arithmetic"    (HASH-PREFIX) h-uint f-cond)
(dnop ccond   "lr branch condition"       (HASH-PREFIX) h-uint f-ccond)
(dnop hint    "2 bit branch predictor"    (HASH-PREFIX) h-uint f-hint)
(dnop hint_taken "2 bit branch predictor"     () h-hint-taken     f-hint)
(dnop hint_not_taken "2 bit branch predictor" () h-hint-not-taken f-hint)

(dnop LI      "link indicator"            () h-uint f-LI)
(dnop lock    "cache lock indicator"      (HASH-PREFIX) h-uint f-lock)
(dnop debug   "debug mode indicator"      (HASH-PREFIX) h-uint f-debug)
(dnop A       "all accumulator indicator" (HASH-PREFIX) h-uint f-A)
(dnop ae      "all entries indicator"     (HASH-PREFIX) h-uint f-ae)

(dnop label16  "18 bit pc relative address" () h-iaddr f-label16)
(dnop label24  "26 bit pc relative address" () h-iaddr f-label24)

(define-operand
  (name FRintieven)
  (comment "(even) source register 1")
  (attrs)
  (type h-fr_int)
  (index f-FRi)
  (mode SI)
  (handlers (parse "even_register"))
)

(define-operand
  (name FRintjeven)
  (comment "(even) source register 2")
  (attrs)
  (type h-fr_int)
  (index f-FRj)
  (mode SI)
  (handlers (parse "even_register"))
)

(define-operand
  (name FRintkeven)
  (comment "(even) target register")
  (attrs)
  (type h-fr_int)
  (index f-FRk)
  (mode SI)
  (handlers (parse "even_register"))
)

(define-operand
  (name d12)
  (comment "12 bit signed immediate")
  (attrs)
  (type h-sint)
  (index f-d12)
  (handlers (parse "d12"))
)

(define-operand
  (name s12)
  (comment "12 bit signed immediate")
  (attrs HASH-PREFIX)
  (type h-sint)
  (index f-d12)
  (handlers (parse "s12"))
)

(define-operand
  (name u12)
  (comment "12 bit signed immediate")
  (attrs HASH-PREFIX)
  (type h-sint)
  (index f-u12)
  (handlers (parse "u12"))
)

(define-operand 
  (name spr)
  (comment "special purpose register")
  (attrs)
  (type  h-spr)
  (index f-spr)
  (handlers (parse "spr") (print "spr"))
)

(define-operand
  (name ulo16)
  (comment "16 bit unsigned immediate, for #lo()")
  (attrs)
  (type h-uint)
  (index f-u16)
  (handlers (parse "ulo16") (print "lo"))
)

(define-operand
  (name slo16)
  (comment "16 bit unsigned immediate, for #lo()")
  (attrs)
  (type h-sint)
  (index f-s16)
  (handlers (parse "uslo16") (print "lo"))
)

(define-operand
  (name uhi16)
  (comment "16 bit unsigned immediate, for #hi()")
  (attrs)
  (type h-uint)
  (index f-u16)
  (handlers (parse "uhi16") (print "hi"))
)

; operands representing hardware
;
(dnop psr_esr "PSR.ESR bit" (SEM-ONLY) h-psr_esr f-nil)
(dnop psr_s   "PSR.S   bit" (SEM-ONLY) h-psr_s   f-nil)
(dnop psr_ps  "PSR.PS  bit" (SEM-ONLY) h-psr_ps  f-nil)
(dnop psr_et  "PSR.ET  bit" (SEM-ONLY) h-psr_et  f-nil)

(dnop bpsr_bs  "BPSR.BS  bit" (SEM-ONLY) h-bpsr_bs  f-nil)
(dnop bpsr_bet "BPSR.BET bit" (SEM-ONLY) h-bpsr_bet f-nil)

(dnop tbr_tba "TBR.TBA" (SEM-ONLY) h-tbr_tba f-nil)
(dnop tbr_tt  "TBR.TT"  (SEM-ONLY) h-tbr_tt  f-nil)

; Null operands
;
(define-pmacro (ICCi_1-null)  (f-ICCi_1-null 0))
(define-pmacro (ICCi_2-null)  (f-ICCi_2-null 0))
(define-pmacro (ICCi_3-null)  (f-ICCi_3-null 0))
(define-pmacro (FCCi_1-null)  (f-FCCi_1-null 0))
(define-pmacro (FCCi_2-null)  (f-FCCi_2-null 0))
(define-pmacro (FCCi_3-null)  (f-FCCi_3-null 0))
(define-pmacro (rs-null)      (f-rs-null     0))
(define-pmacro (GRi-null)     (f-GRi-null    0))
(define-pmacro (GRj-null)     (f-GRj-null    0))
(define-pmacro (GRk-null)     (f-GRk-null    0))
(define-pmacro (FRi-null)     (f-FRi-null    0))
(define-pmacro (FRj-null)     (f-FRj-null    0))
(define-pmacro (ACCj-null)    (f-ACCj-null   0))
(define-pmacro (rd-null)      (f-rd-null     0))
(define-pmacro (cond-null)    (f-cond-null   0))
(define-pmacro (ccond-null)   (f-ccond-null  0))
(define-pmacro (s12-null)     (f-s12-null    0))
(define-pmacro (label16-null) (f-label16-null 0))
(define-pmacro (misc-null-1)  (f-misc-null-1 0))
(define-pmacro (misc-null-2)  (f-misc-null-2 0))
(define-pmacro (misc-null-3)  (f-misc-null-3 0))
(define-pmacro (misc-null-4)  (f-misc-null-4 0))
(define-pmacro (misc-null-5)  (f-misc-null-5 0))
(define-pmacro (misc-null-6)  (f-misc-null-6 0))
(define-pmacro (misc-null-7)  (f-misc-null-7 0))
(define-pmacro (misc-null-8)  (f-misc-null-8 0))
(define-pmacro (misc-null-9)  (f-misc-null-9 0))
(define-pmacro (misc-null-10) (f-misc-null-10 0))
(define-pmacro (misc-null-11) (f-misc-null-11 0))

(define-pmacro (LI-on)       (f-LI-on  1))
(define-pmacro (LI-off)      (f-LI-off 0))

; Instruction definitions.
;
; Notes:
; - dni is short for "define-normal-instruction"
; - Macros are used to represent each insn format. These should be used as much
;   as possible unless an insn has exceptional behaviour
;

; Commonly used Macros
;
; Specific registers
;

; Integer condition code manipulation
;
(define-pmacro (set-z-and-n icc x)
  (if (eq x 0)
      (set icc (or (and icc #x7) #x4))
      (if (lt x 0)
	  (set icc (or (and icc #xb) #x8))
	  (set icc (and icc #x3))))
)

(define-pmacro (set-n icc val)
  (if (eq val 0)
      (set icc (and icc #x7))
      (set icc (or  icc #x8)))
)

(define-pmacro (set-z icc val)
  (if (eq val 0)
      (set icc (and icc #xb))
      (set icc (or  icc #x4)))
)

(define-pmacro (set-v icc val)
  (if (eq val 0)
      (set icc (and icc #xd))
      (set icc (or  icc #x2)))
)

(define-pmacro (set-c icc val)
  (if (eq val 0)
      (set icc (and icc #xe))
      (set icc (or  icc #x1)))
)

(define-pmacro (nbit icc)
  (trunc BI (srl (and icc #x8) 3))
)

(define-pmacro (zbit icc)
  (trunc BI (srl (and icc #x4) 2))
)

(define-pmacro (vbit icc)
  (trunc BI (srl (and icc #x2) 1))
)

(define-pmacro (cbit icc)
  (trunc BI (and icc #x1))
)

(define-pmacro (ebit icc)
  (trunc BI (srl (and icc #x8) 3))
)

(define-pmacro (lbit icc)
  (trunc BI (srl (and icc #x4) 2))
)

(define-pmacro (gbit icc)
  (trunc BI (srl (and icc #x2) 1))
)

(define-pmacro (ubit icc)
  (trunc BI (and icc #x1))
)

; FRV specific insn attributes:
;

; Format: INT, Logic, Shift r-r
;
(define-pmacro (int-logic-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRk")
       (+ pack GRk op GRi (ICCi_1-null) ope GRj)
       (set GRk (operation GRi GRj))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-logic-r-r add  add   OP_00 OPE2_00 "add reg/reg")
(int-logic-r-r sub  sub   OP_00 OPE2_04 "sub reg/reg")
(int-logic-r-r and  and   OP_01 OPE2_00 "and reg/reg")
(int-logic-r-r or   or    OP_01 OPE2_02 "or  reg/reg")
(int-logic-r-r xor  xor   OP_01 OPE2_04 "xor reg/reg")

(dni not
     ("not")
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     ("not$pack $GRj,$GRk")
     (+ pack GRk OP_01 (rs-null) (ICCi_1-null) OPE2_06 GRj)
     (set GRk (inv GRj))
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

(dni sdiv
     "signed division"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "sdiv$pack $GRi,$GRj,$GRk"
     (+ pack GRk OP_00 GRi (ICCi_1-null) OPE2_0E GRj)
     (sequence ()
	       (c-call VOID "@cpu@_signed_integer_divide"
		       GRi GRj (index-of GRk) 0)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni nsdiv
     "non excepting signed division"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
      (MACH simple,tomcat,fr500,frv))
     "nsdiv$pack $GRi,$GRj,$GRk"
     (+ pack GRk OP_01 GRi (ICCi_1-null) OPE2_0E GRj)
     (sequence ()
	       (c-call VOID "@cpu@_signed_integer_divide"
		       GRi GRj (index-of GRk) 1)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni udiv
     "unsigned division reg/reg"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "udiv$pack $GRi,$GRj,$GRk"
     (+ pack GRk OP_00 GRi (ICCi_1-null) OPE2_0F GRj)
     (sequence ()
	       (c-call VOID "@cpu@_unsigned_integer_divide"
		       GRi GRj (index-of GRk) 0)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni nudiv
     "non excepting unsigned division"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
      (MACH simple,tomcat,fr500,frv))
     "nudiv$pack $GRi,$GRj,$GRk"
     (+ pack GRk OP_01 GRi (ICCi_1-null) OPE2_0F GRj)
     (sequence ()
	       (c-call VOID "@cpu@_unsigned_integer_divide"
		       GRi GRj (index-of GRk) 1)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

; Multiplication
;
(define-pmacro (multiply-r-r name signop op ope comment)
  (dni name
       (comment)
       ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRdoublek")
       (+ pack GRdoublek op GRi (ICCi_1-null) ope GRj) 
       (set GRdoublek (mul DI (signop DI GRi) (signop DI GRj)))
       ((fr400 (unit u-imul))
	(fr500 (unit u-imul)))
  )
)

(multiply-r-r smul ext  OP_00 OPE2_08 "signed   multiply reg/reg")
(multiply-r-r umul zext OP_00 OPE2_0A "unsigned multiply reg/reg")

(define-pmacro (int-shift-r-r name op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRk")
       (+ pack GRk op GRi (ICCi_1-null) ope GRj)
       (set GRk (name GRi (and GRj #x1f)))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-shift-r-r sll OP_01 OPE2_08 "shift left  logical reg/reg")
(int-shift-r-r srl OP_01 OPE2_0A "shift right logical reg/reg")
(int-shift-r-r sra OP_01 OPE2_0C "shift right arith   reg/reg")

(define-pmacro (scan-semantics arg1 arg2 targ)
  (sequence ((WI tmp1) (WI tmp2))
	    (set tmp1 arg1)
	    (set tmp2 (sra arg2 1))
	    (set targ (c-call WI "@cpu@_scan_result" (xor tmp1 tmp2))))
)

(dni scan
     "scan"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "scan$pack $GRi,$GRj,$GRk"
     (+ pack GRk OP_0B GRi (ICCi_1-null) OPE2_00 GRj)
     (scan-semantics GRi GRj GRk)
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

; Format: conditional INT, Logic, Shift r-r
;
(define-pmacro (conditional-int-logic name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
       (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (set GRk (operation GRi GRj)))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(conditional-int-logic cadd  add  OP_58 OPE4_0 "conditional add")
(conditional-int-logic csub  sub  OP_58 OPE4_1 "conditional sub")
(conditional-int-logic cand  and  OP_5A OPE4_0 "conditional and")
(conditional-int-logic cor   or   OP_5A OPE4_1 "conditional or")
(conditional-int-logic cxor  xor  OP_5A OPE4_2 "conditional xor")

(dni cnot
     "conditional not"
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "cnot$pack $GRj,$GRk,$CCi,$cond"
     (+ pack GRk OP_5A (rs-null) CCi cond OPE4_3 GRj)
     (if (eq CCi (or cond 2))
	 (set GRk (inv GRj)))
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

(dni csmul
     "conditional signed multiply"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "csmul$pack $GRi,$GRj,$GRdoublek,$CCi,$cond"
     (+ pack GRdoublek OP_58 GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (set GRdoublek (mul DI (ext DI GRi) (ext DI GRj))))
     ((fr400 (unit u-imul))
      (fr500 (unit u-imul)))
)

(dni csdiv
     "conditional signed division"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "csdiv$pack $GRi,$GRj,$GRk,$CCi,$cond"
     (+ pack GRk OP_58 GRi CCi cond OPE4_3 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ()
		   (c-call VOID "@cpu@_signed_integer_divide"
			   GRi GRj (index-of GRk) 0)
		   (clobber GRk)))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni cudiv
     "conditional unsigned division"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "cudiv$pack $GRi,$GRj,$GRk,$CCi,$cond"
     (+ pack GRk OP_59 GRi CCi cond OPE4_3 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ()
		   (c-call VOID "@cpu@_unsigned_integer_divide"
			   GRi GRj (index-of GRk) 0)
		   (clobber GRk)))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(define-pmacro (conditional-shift name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
       (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (set GRk (operation GRi (and GRj #x1f))))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(conditional-shift csll sll OP_5C OPE4_0 "conditional shift left  logical")
(conditional-shift csrl srl OP_5C OPE4_1 "conditional shift right logical")
(conditional-shift csra sra OP_5C OPE4_2 "conditional shift right arith")

(dni cscan
     "conditional scan"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "cscan$pack $GRi,$GRj,$GRk,$CCi,$cond"
     (+ pack GRk OP_65 GRi CCi cond OPE4_3 GRj)
     (if (eq CCi (or cond 2))
	 (scan-semantics GRi GRj GRk))
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

; Format: INT, Logic, Shift, cc r-r
;
(define-pmacro (int-arith-cc-semantics operation icc)
  (sequence ((BI tmp) (QI cc) (SI result))
	    (set cc icc)
	    (set tmp ((.sym operation -oflag) GRi GRj (const 0)))
	    (set-v cc tmp)
	    (set tmp ((.sym operation -cflag) GRi GRj (const 0)))
	    (set-c cc tmp)
	    (set result (operation GRi GRj))
	    (set-z-and-n cc result)
	    (set GRk result)
	    (set icc cc))
)

(define-pmacro (int-arith-cc-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 ope GRj)
       (int-arith-cc-semantics operation ICCi_1)
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-cc-r-r addcc add OP_00 OPE2_01 "add reg/reg, set icc")
(int-arith-cc-r-r subcc sub OP_00 OPE2_05 "sub reg/reg, set icc")

(define-pmacro (int-logic-cc-semantics op icc)
  (sequence ((SI tmp))
	    (set tmp (op GRi GRj))
	    (set GRk tmp)
	    (set-z-and-n icc tmp))
)

(define-pmacro (int-logic-cc-r-r name op ope comment)
  (dni (.sym name cc)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str (.sym name cc) "$pack $GRi,$GRj,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 ope GRj)
       (int-logic-cc-semantics name ICCi_1)
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-logic-cc-r-r and OP_01 OPE2_01 "and reg/reg, set icc")
(int-logic-cc-r-r or  OP_01 OPE2_03 "or  reg/reg, set icc")
(int-logic-cc-r-r xor OP_01 OPE2_05 "xor reg/reg, set icc")

(define-pmacro (int-shift-cc-semantics op l-r icc)
  (sequence ((WI shift) (SI tmp) (QI cc))
	    (set shift (and GRj #x1f))
	    (set cc (c-call QI (.str "@cpu@_set_icc_for_shift_" l-r)
			    GRi shift icc))
	    (set tmp (op GRi shift))
	    (set GRk tmp)
	    (set-z-and-n cc tmp)
	    (set icc cc))
)

(define-pmacro (int-shift-cc-r-r name l-r op ope comment)
  (dni (.sym name cc)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str (.sym name cc) "$pack $GRi,$GRj,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 ope GRj)
       (int-shift-cc-semantics name l-r ICCi_1)
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-shift-cc-r-r sll left  OP_01 OPE2_09 "shift left  logical reg/reg,set icc")
(int-shift-cc-r-r srl right OP_01 OPE2_0B "shift right logical reg/reg,set icc")
(int-shift-cc-r-r sra right OP_01 OPE2_0D "shift right arith   reg/reg,set icc")

(define-pmacro (multiply-cc-semantics signop arg1 arg2 targ icc)
  (sequence ((DI tmp) (QI cc))
	    (set cc icc)
	    (set tmp (mul DI (signop DI arg1) (signop DI arg2)))
	    (set-n cc (srl DI tmp 63))
	    (set-z cc (eq tmp 0))
	    (set targ tmp)
	    (set icc cc))
)

(define-pmacro (multiply-cc-r-r name signop op ope comment)
  (dni name
       (comment)
       ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRdoublek,$ICCi_1")
       (+ pack GRdoublek op GRi ICCi_1 ope GRj)
       (multiply-cc-semantics signop GRi GRj GRdoublek ICCi_1)
       ((fr400 (unit u-imul))
	(fr500 (unit u-imul)))
  )
)

(multiply-cc-r-r smulcc ext  OP_00 OPE2_09 "signed   multiply reg/reg")
(multiply-cc-r-r umulcc zext OP_00 OPE2_0B "unsigned multiply reg/reg")


; Format: conditional INT, Logic, Shift, cc r-r
;
(define-pmacro (conditional-int-arith-cc name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
       (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (int-arith-cc-semantics operation
				   (reg h-iccr (and (index-of CCi) 3))))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(conditional-int-arith-cc caddcc add OP_59 OPE4_0 "add, set icc")
(conditional-int-arith-cc csubcc sub OP_59 OPE4_1 "sub, set icc")

(dni csmulcc
     "conditional signed multiply and set condition code"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
     "csmulcc$pack $GRi,$GRj,$GRdoublek,$CCi,$cond"
     (+ pack GRdoublek OP_59 GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (multiply-cc-semantics ext GRi GRj GRdoublek
				(reg h-iccr (and (index-of CCi) 3))))
     ((fr400 (unit u-imul))
      (fr500 (unit u-imul)))
)

(define-pmacro (conditional-int-logic-cc name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
       (.str name "$pack $GRi,$GRj,$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (int-logic-cc-semantics operation
				   (reg h-iccr (and (index-of CCi) 3))))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(conditional-int-logic-cc candcc and OP_5B OPE4_0 "conditional and, set icc")
(conditional-int-logic-cc corcc  or  OP_5B OPE4_1 "conditional or , set icc")
(conditional-int-logic-cc cxorcc xor OP_5B OPE4_2 "conditional xor, set icc")

(define-pmacro (conditional-int-shift-cc name l-r op ope comment)
  (dni (.sym c name cc)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
       (.str (.sym c name cc) "$pack $GRi,$GRj,$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (int-shift-cc-semantics name l-r
				   (reg h-iccr (and (index-of CCi) 3))))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(conditional-int-shift-cc sll left  OP_5D OPE4_0 "shift left  logical, set icc")
(conditional-int-shift-cc srl right OP_5D OPE4_1 "shift right logical, set icc")
(conditional-int-shift-cc sra right OP_5D OPE4_2 "shift right arith  , set icc")

; Add and subtract with carry
;
(define-pmacro (int-arith-x-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 ope GRj)
       (set GRk ((.sym operation c) GRi GRj (cbit ICCi_1)))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-x-r-r addx add OP_00 OPE2_02 "Add reg/reg, with carry")
(int-arith-x-r-r subx sub OP_00 OPE2_06 "Sub reg/reg, with carry")

(define-pmacro (int-arith-x-cc-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$GRj,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 ope GRj)
       (sequence ((WI tmp) (QI cc))
		 (set cc ICCi_1)
		 (set tmp ((.sym operation c) GRi GRj (cbit cc)))
		 (set-v cc ((.sym operation -oflag) GRi GRj (cbit cc)))
		 (set-c cc ((.sym operation -cflag) GRi GRj (cbit cc)))
		 (set-z-and-n cc tmp)
		 (set GRk tmp)
		 (set ICCi_1 cc))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-x-cc-r-r addxcc add OP_00 OPE2_03 "Add reg/reg, use/set carry")
(int-arith-x-cc-r-r subxcc sub OP_00 OPE2_07 "Sub reg/reg, use/set carry")

; Format: INT, Logic, Shift r-simm
;
(define-pmacro (int-logic-r-simm name operation op comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s12,$GRk")
       (+ pack GRk op GRi s12)
       (set GRk (operation GRi s12))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-logic-r-simm addi  add   OP_10 "add reg/immed")
(int-logic-r-simm subi  sub   OP_14 "sub reg/immed")
(int-logic-r-simm andi  and   OP_20 "and reg/immed")
(int-logic-r-simm ori   or    OP_22 "or  reg/immed")
(int-logic-r-simm xori  xor   OP_24 "xor reg/immed")

(dni sdivi
     "signed division reg/immed"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "sdivi$pack $GRi,$s12,$GRk"
     (+ pack GRk OP_1E GRi s12)
     (sequence ()
	       (c-call VOID "@cpu@_signed_integer_divide"
		       GRi s12 (index-of GRk) 0)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni nsdivi
     "non excepting signed division reg/immed"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
      (MACH simple,tomcat,fr500,frv))
     "nsdivi$pack $GRi,$s12,$GRk"
     (+ pack GRk OP_2E GRi s12)
     (sequence ()
	       (c-call VOID "@cpu@_signed_integer_divide"
		       GRi s12 (index-of GRk) 1)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni udivi
     "unsigned division reg/immed"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "udivi$pack $GRi,$s12,$GRk"
     (+ pack GRk OP_1F GRi s12)
     (sequence ()
	       (c-call VOID "@cpu@_unsigned_integer_divide"
		       GRi s12 (index-of GRk) 0)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(dni nudivi
     "non excepting unsigned division reg/immed"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) NON-EXCEPTING
      (MACH simple,tomcat,fr500,frv))
     "nudivi$pack $GRi,$s12,$GRk"
     (+ pack GRk OP_2F GRi s12)
     (sequence ()
	       (c-call VOID "@cpu@_unsigned_integer_divide"
		       GRi s12 (index-of GRk) 1)
	       (clobber GRk))
     ((fr400 (unit u-idiv))
      (fr500 (unit u-idiv)))
)

(define-pmacro (multiply-r-simm name signop op comment)
  (dni name
       (comment)
       ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s12,$GRdoublek")
       (+ pack GRdoublek op GRi s12)
       (set GRdoublek (mul DI (signop DI GRi) (signop DI s12)))
       ((fr400 (unit u-imul))
	(fr500 (unit u-imul)))
  )
)

(multiply-r-simm smuli ext  OP_18 "signed   multiply reg/immed")
(multiply-r-simm umuli zext OP_1A "unsigned multiply reg/immed")

(define-pmacro (int-shift-r-simm name op comment)
  (dni (.sym name i)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str (.sym name i) "$pack $GRi,$s12,$GRk")
       (+ pack GRk op GRi s12)
       (set GRk (name GRi (and s12 #x1f)))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-shift-r-simm sll OP_28 "shift left  logical reg/immed")
(int-shift-r-simm srl OP_2A "shift right logical reg/immed")
(int-shift-r-simm sra OP_2C "shift right arith   reg/immed")

(dni scani
     "scan immediate"
     ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "scani$pack $GRi,$s12,$GRk"
     (+ pack GRk OP_47 GRi s12)
     (scan-semantics GRi s12 GRk)
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

; Format: INT, Logic, Shift cc r-simm
;
(define-pmacro (int-arith-cc-r-simm name operation op comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 s10)
       (sequence ((BI tmp) (QI cc) (SI result))
		 (set cc ICCi_1)
		 (set tmp ((.sym operation -oflag) GRi s10 (const 0)))
		 (set-v cc tmp)
		 (set tmp ((.sym operation -cflag) GRi s10 (const 0)))
		 (set-c cc tmp)
		 (set result (operation GRi s10))
		 (set-z-and-n cc result)
		 (set GRk result)
		 (set ICCi_1 cc))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-cc-r-simm addicc add OP_11 "add reg/immed, set icc")
(int-arith-cc-r-simm subicc sub OP_15 "sub reg/immed, set icc")

(define-pmacro (int-logic-cc-r-simm name op comment)
  (dni (.sym name icc)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str (.sym name icc) "$pack $GRi,$s10,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 s10)
       (sequence ((SI tmp))
		 (set tmp (name GRi s10))
		 (set GRk tmp)
		 (set-z-and-n ICCi_1 tmp))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-logic-cc-r-simm and  OP_21 "and reg/immed, set icc")
(int-logic-cc-r-simm or   OP_23 "or  reg/immed, set icc")
(int-logic-cc-r-simm xor  OP_25 "xor reg/immed, set icc")

(define-pmacro (multiply-cc-r-simm name signop op comment)
  (dni name
       (comment)
       ((UNIT MULT-DIV) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s10,$GRdoublek,$ICCi_1")
       (+ pack GRdoublek op GRi ICCi_1 s10)
       (multiply-cc-semantics signop GRi s10 GRdoublek ICCi_1)
       ((fr400 (unit u-imul))
	(fr500 (unit u-imul)))
  )
)

(multiply-cc-r-simm smulicc ext  OP_19 "signed   multiply reg/immed")
(multiply-cc-r-simm umulicc zext OP_1B "unsigned multiply reg/immed")

(define-pmacro (int-shift-cc-r-simm name l-r op comment)
  (dni (.sym name icc)
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str (.sym name icc) "$pack $GRi,$s10,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 s10)
       (sequence ((WI shift) (SI tmp) (QI cc))
		 (set shift (and s10 #x1f))
		 (set cc (c-call QI (.str "@cpu@_set_icc_for_shift_" l-r)
				 GRi shift ICCi_1))
		 (set tmp (name GRi shift))
		 (set GRk tmp)
		 (set-z-and-n cc tmp)
		 (set ICCi_1 cc))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-shift-cc-r-simm sll left  OP_29 "shift left  logical reg/immed, set icc")
(int-shift-cc-r-simm srl right OP_2B "shift right logical reg/immed, set icc")
(int-shift-cc-r-simm sra right OP_2D "shift right arith   reg/immed, set icc")

(define-pmacro (int-arith-x-r-simm name operation op comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 s10)
       (set GRk ((.sym operation c) GRi s10 (cbit ICCi_1)))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-x-r-simm addxi add OP_12 "Add reg/immed, with carry")
(int-arith-x-r-simm subxi sub OP_16 "Sub reg/immed, with carry")

(define-pmacro (int-arith-x-cc-r-simm name operation op comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
       (.str name "$pack $GRi,$s10,$GRk,$ICCi_1")
       (+ pack GRk op GRi ICCi_1 s10)
       (sequence ((WI tmp) (QI cc))
		 (set cc ICCi_1)
		 (set tmp ((.sym operation c) GRi s10 (cbit cc)))
		 (set-v cc ((.sym operation -oflag) GRi s10 (cbit cc)))
		 (set-c cc ((.sym operation -cflag) GRi s10 (cbit cc)))
		 (set-z-and-n cc tmp)
		 (set GRk tmp)
		 (set ICCi_1 cc))
       ((fr400 (unit u-integer))
	(fr500 (unit u-integer)))
  )
)

(int-arith-x-cc-r-simm addxicc add OP_13 "Add reg/immed, with carry")
(int-arith-x-cc-r-simm subxicc sub OP_17 "Sub reg/immed, with carry")

; Byte compare insns

(dni cmpb
     "Compare bytes"
     ((UNIT I01) (FR400-MAJOR I-1) (MACH fr400))
     "cmpb$pack $GRi,$GRj,$ICCi_1"
     (+ pack (GRk-null) OP_00 GRi ICCi_1 OPE2_0C GRj)
     (sequence ((QI cc))
	       (set-n cc (eq (and GRi #xff000000) (and GRj #xff000000)))
	       (set-z cc (eq (and GRi #x00ff0000) (and GRj #x00ff0000)))
	       (set-v cc (eq (and GRi #x0000ff00) (and GRj #x0000ff00)))
	       (set-c cc (eq (and GRi #x000000ff) (and GRj #x000000ff)))
	       (set ICCi_1 cc))
     ((fr400 (unit u-integer)))
)

(dni cmpba
     "OR of Compare bytes"
     ((UNIT I01) (FR400-MAJOR I-1) (MACH fr400))
     "cmpba$pack $GRi,$GRj,$ICCi_1"
     (+ pack (GRk-null) OP_00 GRi ICCi_1 OPE2_0D GRj)
     (sequence ((QI cc))
	       (set cc 0)
	       (set-c cc
		      (orif (eq (and GRi #xff000000) (and GRj #xff000000))
			    (orif (eq (and GRi #x00ff0000) (and GRj #x00ff0000))
				  (orif (eq (and GRi #x0000ff00)
					    (and GRj #x0000ff00))
					 (eq (and GRi #x000000ff)
					    (and GRj #x000000ff))))))
	       (set ICCi_1 cc))
     ((fr400 (unit u-integer)))
)

; Format: Load immediate
;
(dni setlo
     "set low order bits"
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "setlo$pack $ulo16,$GRklo"
     (+ pack GRk OP_3D (misc-null-4) u16)
     (set GRklo u16)
     ((fr400 (unit u-set-hilo))
      (fr500 (unit u-set-hilo)))
)

(dni sethi
     "set high order bits"
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "sethi$pack $uhi16,$GRkhi"
     (+ pack GRkhi OP_3E (misc-null-4) u16)
     (set GRkhi u16)
     ((fr400 (unit u-set-hilo))
      (fr500 (unit u-set-hilo)))
)

(dni setlos
     "set low order bits and extend sign"
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "setlos$pack $slo16,$GRk"
     (+ pack GRk OP_3F (misc-null-4) s16)
     (set GRk s16)
     ((fr400 (unit u-integer))
      (fr500 (unit u-integer)))
)

(define-pmacro (load-gr-r name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (set GRk (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
       ((fr400 (unit u-gr-load))
	(fr500 (unit u-gr-load)))
  )
)

(load-gr-r ldsb   QI OP_02 OPE1_00 "Load   signed byte")
(load-gr-r ldub  UQI OP_02 OPE1_01 "Load unsigned byte")
(load-gr-r ldsh   HI OP_02 OPE1_02 "Load   signed half")
(load-gr-r lduh  UHI OP_02 OPE1_03 "Load unsigned half")
(load-gr-r ld     SI OP_02 OPE1_04 "Load          word")

(define-pmacro (load-fr-r name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) FR-ACCESS)
       (.str name "$pack @($GRi,$GRj),$FRintk")
       (+ pack FRintk op GRi ope GRj)
       (set FRintk (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
       ((fr400 (unit u-fr-load))
	(fr500 (unit u-fr-load)))
  )
)

(load-fr-r ldbf UQI OP_02 OPE1_08 "Load byte   float")
(load-fr-r ldhf UHI OP_02 OPE1_09 "Load half   float")
(load-fr-r ldf   SI OP_02 OPE1_0A "Load word   float")

(define-pmacro (load-cpr-r name mode op ope reg attr comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) attr)
       (.str name "$pack @($GRi,$GRj),$" reg "k")
       (+ pack (.sym reg k) op GRi ope GRj)
       (set (.sym reg k)
	    (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj)))
       ()
  )
)

(load-cpr-r ldc SI OP_02 OPE1_0D CPR (MACH frv) "Load coprocessor word")

; These correspond to enumerators in frv-sim.h
(define-pmacro (ne-UQI-size) 0)
(define-pmacro (ne-QI-size)  1)
(define-pmacro (ne-UHI-size) 2)
(define-pmacro (ne-HI-size)  3)
(define-pmacro (ne-SI-size)  4)
(define-pmacro (ne-DI-size)  5)
(define-pmacro (ne-XI-size)  6)

(define-pmacro (ne-load-semantics base dispix targ idisp size is_float action)
  (sequence ((BI do_op))
	    (set do_op
		 (c-call BI "@cpu@_check_non_excepting_load"
			  (index-of base) dispix (index-of targ)
			  idisp size is_float))
	    (if do_op action))
)

(define-pmacro (ne-load-gr-r name mode op ope size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) GRk 0 size 0
			  (set GRk
			       (c-call mode (.str "@cpu@_read_mem_" mode)
				       pc (add GRi GRj))))
       ((fr500 (unit u-gr-load)))
  )
)

(ne-load-gr-r nldsb  QI OP_02 OPE1_20 (ne-QI-size)  "Load   signed byte")
(ne-load-gr-r nldub UQI OP_02 OPE1_21 (ne-UQI-size) "Load unsigned byte")
(ne-load-gr-r nldsh  HI OP_02 OPE1_22 (ne-HI-size)  "Load   signed half")
(ne-load-gr-r nlduh UHI OP_02 OPE1_23 (ne-UHI-size) "Load unsigned half")
(ne-load-gr-r nld    SI OP_02 OPE1_24 (ne-SI-size)  "Load          word")

(define-pmacro (ne-load-fr-r name mode op ope size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$FRintk")
       (+ pack FRintk op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) FRintk 0 size 1
			  (set FRintk
			       (c-call mode (.str "@cpu@_read_mem_" mode)
				       pc (add GRi GRj))))
       ((fr500 (unit u-fr-load)))
  )
)

(ne-load-fr-r nldbf UQI OP_02 OPE1_28 (ne-UQI-size) "Load byte float")
(ne-load-fr-r nldhf UHI OP_02 OPE1_29 (ne-UHI-size) "Load half float")
(ne-load-fr-r nldf   SI OP_02 OPE1_2A (ne-SI-size)  "Load word float")

; Semantics for a load-double insn
;
(define-pmacro (load-double-semantics not_gr mode regtype address arg)
  (if (orif not_gr (ne (index-of (.sym regtype doublek)) 0))
      (sequence ()
		(set address (add GRi arg))
		(set (.sym regtype doublek)
		     (c-call mode (.str "@cpu@_read_mem_" mode) pc address))))
)

(define-pmacro (load-double-r-r
		name not_gr mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi ope GRj)
       (sequence ((WI address))
		 (load-double-semantics not_gr mode regtype address GRj))
       profile
  )
)

(load-double-r-r ldd  0 DI OP_02 OPE1_05 GR  NA
		 ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		 "Load double word")
(load-double-r-r lddf 1 DF OP_02 OPE1_0B FR  FR-ACCESS
		 ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		 "Load double float")
(load-double-r-r lddc 1 DI OP_02 OPE1_0E CPR (MACH frv) ()
		 "Load coprocessor double")

(define-pmacro (ne-load-double-r-r
		name not_gr mode op ope regtype size is_float attr profile
		comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi ope GRj)
       (sequence ((WI address))
		 (ne-load-semantics GRi (index-of GRj) (.sym regtype doublek)
				    0 size is_float
				    (load-double-semantics not_gr mode
							   regtype
							   address GRj)))
       profile
  )
)

(ne-load-double-r-r nldd  0 DI OP_02 OPE1_25 GR (ne-DI-size) 0 NA
		    ((fr500 (unit u-gr-load))) "Load double   word")
(ne-load-double-r-r nlddf 1 DF OP_02 OPE1_2B FR (ne-DI-size) 1 FR-ACCESS
		    ((fr500 (unit u-fr-load))) "Load double float")

; Semantics for a load-quad insn
;
(define-pmacro (load-quad-semantics regtype address arg)
  (sequence ()
	    (set address (add GRi arg))
	    (c-call VOID (.str "@cpu@_load_quad_" regtype)
		    pc address (index-of (.sym regtype k))))
)

(define-pmacro (load-quad-r-r name op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "k")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (load-quad-semantics regtype address GRj))
       ; TODO regtype-k not referenced for profiling
       profile
  )
)

(load-quad-r-r ldq  OP_02 OPE1_06 GR    NA        ((fr500 (unit u-gr-load)))
	       "Load quad word")
(load-quad-r-r ldqf OP_02 OPE1_0C FRint FR-ACCESS ((fr500 (unit u-fr-load)))
	       "Load quad float")
(load-quad-r-r ldqc OP_02 OPE1_0F CPR   NA        () "Load coprocessor quad")

(define-pmacro (ne-load-quad-r-r
		name op ope regtype size is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "k")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (ne-load-semantics GRi (index-of GRj) (.sym regtype k)
				    0 size is_float
				    (load-quad-semantics regtype address GRj)))
       ; TODO regtype-k not referenced for profiling
       profile
  )
)

(ne-load-quad-r-r nldq  OP_02 OPE1_26 GR    (ne-XI-size) 0 NA
		  ((fr500 (unit u-gr-load))) "Load quad word")
(ne-load-quad-r-r nldqf OP_02 OPE1_2C FRint (ne-XI-size) 1 FR-ACCESS
		  ((fr500 (unit u-fr-load))) "Load quad float")

(define-pmacro (load-gr-u-semantics mode)
  (sequence ((UWI address))
	    (set address (add GRi GRj))
	    (set GRk (c-call mode (.str "@cpu@_read_mem_" mode) pc address))
	    (if (ne (index-of GRi) (index-of GRk))
		(sequence ()
			  (set GRi address)
			  (c-call VOID "@cpu@_force_update"))))
)

(define-pmacro (load-gr-u name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (load-gr-u-semantics mode)
       ((fr400 (unit u-gr-load))
	(fr500 (unit u-gr-load)))
  )
)

(load-gr-u ldsbu   QI OP_02 OPE1_10 "Load   signed byte, update index")
(load-gr-u ldubu  UQI OP_02 OPE1_11 "Load unsigned byte, update index")
(load-gr-u ldshu   HI OP_02 OPE1_12 "Load   signed half, update index")
(load-gr-u lduhu  UHI OP_02 OPE1_13 "Load unsigned half, update index")
(load-gr-u ldu     SI OP_02 OPE1_14 "Load          word, update index")

(define-pmacro (ne-load-gr-u name mode op ope size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) GRk 0 size 0 (load-gr-u-semantics mode))
       ((fr500 (unit u-gr-load)))
  )
)

(ne-load-gr-u nldsbu  QI OP_02 OPE1_30 (ne-QI-size)  "Load   signed byte, update index")
(ne-load-gr-u nldubu UQI OP_02 OPE1_31 (ne-UQI-size) "Load unsigned byte, update index")
(ne-load-gr-u nldshu  HI OP_02 OPE1_32 (ne-HI-size)  "Load   signed half, update index")
(ne-load-gr-u nlduhu UHI OP_02 OPE1_33 (ne-UHI-size) "Load unsigned half, update index")
(ne-load-gr-u nldu    SI OP_02 OPE1_34 (ne-SI-size)  "Load          word, update index")

(define-pmacro (load-non-gr-u-semantics mode regtype)
  (sequence ((UWI address))
	    (set address (add GRi GRj))
	    (set (.sym regtype k)
		 (c-call mode (.str "@cpu@_read_mem_" mode) pc address))
	    (set GRi address)
	    (c-call VOID "@cpu@_force_update"))
)

(define-pmacro (load-fr-u name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) FR-ACCESS)
       (.str name "$pack @($GRi,$GRj),$FRintk")
       (+ pack FRintk op GRi ope GRj)
       (load-non-gr-u-semantics mode FRint)
       ((fr400 (unit u-fr-load))
	(fr500 (unit u-fr-load)))
  )
)

(load-fr-u ldbfu  UQI OP_02 OPE1_18 "Load byte float, update index")
(load-fr-u ldhfu  UHI OP_02 OPE1_19 "Load half float, update index")
(load-fr-u ldfu    SI OP_02 OPE1_1A "Load word float, update index")

(define-pmacro (load-cpr-u name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv))
       (.str name "$pack @($GRi,$GRj),$CPRk")
       (+ pack CPRk op GRi ope GRj)
       (load-non-gr-u-semantics mode CPR)
       ()
  )
)

(load-cpr-u ldcu SI OP_02 OPE1_1D "Load coprocessor word float,update index")

(define-pmacro (ne-load-non-gr-u name mode op ope regtype size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$" regtype "k")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) (.sym regtype k) 0 size 1
			  (load-non-gr-u-semantics mode regtype))
       ((fr500 (unit u-fr-load)))
  )
)

(ne-load-non-gr-u nldbfu UQI OP_02 OPE1_38 FRint (ne-UQI-size) "Load byte float, update index")
(ne-load-non-gr-u nldhfu UHI OP_02 OPE1_39 FRint (ne-UHI-size) "Load half float, update index")
(ne-load-non-gr-u nldfu   SI OP_02 OPE1_3A FRint (ne-SI-size)  "Load word float, update index")

(define-pmacro (load-double-gr-u-semantics)
  (sequence ((WI address))
	    (load-double-semantics 0 DI GR address GRj)
	    (if (ne (index-of GRi) (index-of GRdoublek))
		(sequence ()
			  (set GRi address)
			  (c-call VOID "@cpu@_force_update"))))
)

(define-pmacro (load-double-gr-u name op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2))
       (.str name "$pack @($GRi,$GRj),$GRdoublek")
       (+ pack GRdoublek op GRi ope GRj)
       (load-double-gr-u-semantics)
       ((fr400 (unit u-gr-load))
	(fr500 (unit u-gr-load)))
  )
)

(load-double-gr-u lddu  OP_02 OPE1_15 "Load double word, update index")

(define-pmacro (ne-load-double-gr-u name op ope size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$GRdoublek")
       (+ pack GRdoublek op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) GRdoublek 0 size 0
			  (load-double-gr-u-semantics))
       ((fr500 (unit u-gr-load)))

  )
)

(ne-load-double-gr-u nlddu OP_02 OPE1_35 (ne-DI-size) "Load double word, update index")

(define-pmacro (load-double-non-gr-u-semantics mode regtype)
  (sequence ((WI address))
	    (load-double-semantics 1 mode regtype address GRj)
	    (set GRi address)
	    (c-call VOID "@cpu@_force_update"))
)

(define-pmacro (load-double-non-gr-u
		name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi ope GRj)
       (load-double-non-gr-u-semantics mode regtype)
       profile
  )
)

(load-double-non-gr-u lddfu DF OP_02 OPE1_1B FR  FR-ACCESS
		      ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		      "Load double float, update index")
(load-double-non-gr-u lddcu DI OP_02 OPE1_1E CPR (MACH frv)
		      () "Load coprocessor double float, update index")

(define-pmacro (ne-load-double-non-gr-u name mode op ope regtype size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING FR-ACCESS
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$GRj),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) (.sym regtype doublek) 0 size 1
			  (load-double-non-gr-u-semantics mode regtype))
       ((fr500 (unit u-fr-load)))
  )
)

(ne-load-double-non-gr-u nlddfu DF OP_02 OPE1_3B FR (ne-DI-size) "Load double float, update index")

(define-pmacro (load-quad-gr-u-semantics)
  (sequence ((WI address))
	    (load-quad-semantics GR address GRj)
	    (if (ne (index-of GRi) (index-of GRk))
		(sequence ()
			  (set GRi address)
			  (c-call VOID "@cpu@_force_update"))))
)

(define-pmacro (load-quad-gr-u name op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv))
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (load-quad-gr-u-semantics)
       ; TODO - GRk not referenced here for profiling
       ((fr500 (unit u-gr-load)))
  )
)

(load-quad-gr-u ldqu  OP_02 OPE1_16 "Load quad word, update index")

(define-pmacro (ne-load-quad-gr-u name op ope size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING)
       (.str name "$pack @($GRi,$GRj),$GRk")
       (+ pack GRk op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) GRk 0 size 0
			  (load-quad-gr-u-semantics))
       ; TODO - GRk not referenced here for profiling
       ((fr500 (unit u-gr-load)))
  )
)

(ne-load-quad-gr-u nldqu OP_02 OPE1_36 (ne-XI-size) "Load quad word, update index")

(define-pmacro (load-quad-non-gr-u-semantics regtype)
  (sequence ((WI address))
	    (load-quad-semantics regtype address GRj)
	    (set GRi address)
	    (c-call VOID "@cpu@_force_update"))
)

(define-pmacro (load-quad-non-gr-u name op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "k")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (load-quad-non-gr-u-semantics regtype)
       profile
  )
)

(load-quad-non-gr-u ldqfu OP_02 OPE1_1C FRint FR-ACCESS
		    ((fr500 (unit u-fr-load))) "Load quad float, update index")
(load-quad-non-gr-u ldqcu OP_02 OPE1_1F CPR   NA
		    () "Load coprocessor quad word, update index")

(define-pmacro (ne-load-quad-non-gr-u name op ope regtype size comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING FR-ACCESS)
       (.str name "$pack @($GRi,$GRj),$" regtype "k")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (ne-load-semantics GRi (index-of GRj) (.sym regtype k) 0 size 1
			  (load-quad-non-gr-u-semantics regtype))
       ((fr500 (unit u-fr-load)))
  )
)

(ne-load-quad-non-gr-u nldqfu OP_02 OPE1_3C FRint (ne-XI-size) "Load quad float,update index")

(define-pmacro (load-r-simm name mode op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
       (.str name "$pack @($GRi,$d12),$" regtype "k")
       (+ pack (.sym regtype k) op GRi d12)
       (set (.sym regtype k)
	    (c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi d12)))
       profile
  )
)

(load-r-simm ldsbi  QI OP_30 GR NA
	     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
	     "Load   signed byte")
(load-r-simm ldshi  HI OP_31 GR NA
	     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
	     "Load   signed half")
(load-r-simm ldi    SI OP_32 GR NA
	     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
	     "Load          word")
(load-r-simm ldubi UQI OP_35 GR NA
	     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
	     "Load unsigned byte")
(load-r-simm lduhi UHI OP_36 GR NA
	     ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
	     "Load unsigned half")

(load-r-simm ldbfi UQI OP_38 FRint FR-ACCESS
	     ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
	     "Load byte float")
(load-r-simm ldhfi UHI OP_39 FRint FR-ACCESS
	     ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
	     "Load half float")
(load-r-simm ldfi   SI OP_3A FRint FR-ACCESS
	     ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
	     "Load word float")

(define-pmacro (ne-load-r-simm
		name mode op regtype size is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$d12),$" regtype "k")
       (+ pack (.sym regtype k) op GRi d12)
       (ne-load-semantics GRi -1 (.sym regtype k) d12 size is_float
			  (set (.sym regtype k)
			       (c-call mode (.str "@cpu@_read_mem_" mode)
				       pc (add GRi d12))))
       profile
  )
)

(ne-load-r-simm nldsbi  QI OP_40 GR (ne-QI-size)  0 NA
		((fr500 (unit u-gr-load))) "Load   signed byte")
(ne-load-r-simm nldubi UQI OP_41 GR (ne-UQI-size) 0 NA
		((fr500 (unit u-gr-load))) "Load unsigned byte")
(ne-load-r-simm nldshi  HI OP_42 GR (ne-HI-size)  0 NA
		((fr500 (unit u-gr-load))) "Load   signed half")
(ne-load-r-simm nlduhi UHI OP_43 GR (ne-UHI-size) 0 NA
		((fr500 (unit u-gr-load))) "Load unsigned half")
(ne-load-r-simm nldi    SI OP_44 GR (ne-SI-size)  0 NA
		((fr500 (unit u-gr-load))) "Load          word")

(ne-load-r-simm nldbfi UQI OP_48 FRint (ne-UQI-size) 1 FR-ACCESS
		((fr500 (unit u-fr-load))) "Load byte float")
(ne-load-r-simm nldhfi UHI OP_49 FRint (ne-UHI-size) 1 FR-ACCESS
		((fr500 (unit u-fr-load))) "Load half float")
(ne-load-r-simm nldfi   SI OP_4A FRint (ne-SI-size)  1 FR-ACCESS
		((fr500 (unit u-fr-load))) "Load word float")

(define-pmacro (load-double-r-simm
		name not_gr mode op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) attr)
       (.str name "$pack @($GRi,$d12),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi d12)
       (sequence ((WI address))
		 (load-double-semantics not_gr mode regtype address d12))
       profile
  )
)

(load-double-r-simm lddi  0 DI OP_33 GR NA
		    ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		    "Load double word")
(load-double-r-simm lddfi 1 DF OP_3B FR FR-ACCESS
		    ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		    "Load double float")

(define-pmacro (ne-load-double-r-simm
		name not_gr mode op regtype size is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) NON-EXCEPTING attr
	(MACH simple,tomcat,fr500,frv))
       (.str name "$pack @($GRi,$d12),$" regtype "doublek")
       (+ pack (.sym regtype doublek) op GRi d12)
       (sequence ((WI address))
		 (ne-load-semantics GRi -1 (.sym regtype doublek)
				    d12 size is_float
				    (load-double-semantics not_gr mode
							   regtype
							   address d12)))
       profile
  )
)

(ne-load-double-r-simm nlddi  0 DI OP_45 GR (ne-DI-size) 0 NA
		       ((fr500 (unit u-gr-load))) "Load double word")
(ne-load-double-r-simm nlddfi 1 DF OP_4B FR (ne-DI-size) 1 FR-ACCESS
		       ((fr500 (unit u-fr-load))) "Load double float")

(define-pmacro (load-quad-r-simm name op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) attr)
       (.str name "$pack @($GRi,$d12),$" regtype "k")
       (+ pack (.sym regtype k) op GRi d12)
       (sequence ((WI address))
		 (load-quad-semantics regtype address d12))
       profile
  )
)

(load-quad-r-simm ldqi  OP_34 GR    NA
		  ((fr500 (unit u-gr-load))) "Load quad word")
(load-quad-r-simm ldqfi OP_3C FRint FR-ACCESS
		  ((fr500 (unit u-fr-load))) "Load quad float")

(define-pmacro (ne-load-quad-r-simm
		name op regtype size is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) NON-EXCEPTING attr)
       (.str name "$pack @($GRi,$d12),$" regtype "k")
       (+ pack (.sym regtype k) op GRi d12)
       (sequence ((WI address))
		 (ne-load-semantics GRi -1 (.sym regtype k) d12 size is_float
				    (load-quad-semantics regtype address d12)))
       profile
  )
)

(ne-load-quad-r-simm nldqi  OP_46 GR    (ne-XI-size) 0 NA
		     ((fr500 (unit u-gr-load))) "Load quad word")
(ne-load-quad-r-simm nldqfi OP_4C FRint (ne-XI-size) 1 FR-ACCESS
		     ((fr500 (unit u-fr-load))) "Load quad float")

(define-pmacro (store-r-r name mode op ope reg attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" reg "k,@($GRi,$GRj)")
       (+ pack (.sym reg k) op GRi ope GRj)
       (c-call VOID (.str "@cpu@_write_mem_" mode)
	       pc (add GRi GRj) (.sym reg k))
       profile
  )
)

(store-r-r stb   QI OP_03 OPE1_00 GR NA
	   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	   "Store unsigned byte")
(store-r-r sth   HI OP_03 OPE1_01 GR NA
	   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	   "Store unsigned half")
(store-r-r st    SI OP_03 OPE1_02 GR NA
	   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	   "Store          word")

(store-r-r stbf  QI OP_03 OPE1_08 FRint FR-ACCESS
	   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	   "Store byte float")
(store-r-r sthf  HI OP_03 OPE1_09 FRint FR-ACCESS
	   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	   "Store half float")
(store-r-r stf   SI OP_03 OPE1_0A FRint FR-ACCESS
	   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	   "Store word float")

(store-r-r stc   SI OP_03 OPE1_25 CPR (MACH frv) () "Store coprocessor word")

(define-pmacro (r-store name mode op ope reg size is_float profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv))
       (.str name "$pack $" reg "k,@($GRi,$GRj)")
       (+ pack (.sym reg k) op GRi ope GRj)
       (sequence ((WI address))
		 (set address (add GRi GRj))
		 (c-call VOID (.str "@cpu@_write_mem_" mode)
			 pc address (.sym reg k))
		 (c-call VOID "@cpu@_check_recovering_store"
			 address (index-of (.sym reg k)) size is_float))
       profile
  )
)

(r-store rstb  QI OP_03 OPE1_20 GR 1 0
	 ((fr500 (unit u-gr-r-store))) "Store unsigned byte")
(r-store rsth  HI OP_03 OPE1_21 GR 2 0
	 ((fr500 (unit u-gr-r-store))) "Store unsigned half")
(r-store rst   SI OP_03 OPE1_22 GR 4 0
	 ((fr500 (unit u-gr-r-store))) "Store          word")

(r-store rstbf QI OP_03 OPE1_28 FRint 1 1
	 ((fr500 (unit u-fr-r-store))) "Store byte float")
(r-store rsthf HI OP_03 OPE1_29 FRint 2 1
	 ((fr500 (unit u-fr-r-store))) "Store half float")
(r-store rstf  SI OP_03 OPE1_2A FRint 4 1
	 ((fr500 (unit u-fr-r-store))) "Store word float")

; Semantics for a store-double insn
;
(define-pmacro (store-double-semantics mode regtype address arg)
  (sequence ()
	    (set address (add GRi arg))
	    (c-call VOID (.str "@cpu@_write_mem_" mode)
		    pc address (.sym regtype doublek)))
)

(define-pmacro (store-double-r-r name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-double-semantics mode regtype address GRj))
       profile
  )
)

(store-double-r-r std  DI OP_03 OPE1_03 GR  NA
		  ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		  "Store double word")
(store-double-r-r stdf DF OP_03 OPE1_0B FR  FR-ACCESS
		  ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		  "Store double float")

(store-double-r-r stdc DI OP_03 OPE1_26 CPR (MACH frv)
		  () "Store coprocessor double word")

(define-pmacro (r-store-double
		name mode op ope regtype is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-double-semantics mode regtype address GRj)
		 (c-call VOID "@cpu@_check_recovering_store"
			 address (index-of (.sym regtype k)) 8 is_float))
       profile
  )
)

(r-store-double rstd  DI OP_03 OPE1_23 GR 0 NA
		((fr500 (unit u-gr-r-store))) "Store double word")
(r-store-double rstdf DF OP_03 OPE1_2B FR 1 FR-ACCESS
		((fr500 (unit u-fr-r-store))) "Store double float")

; Semantics for a store-quad insn
;
(define-pmacro (store-quad-semantics regtype address arg)
  (sequence ()
	    (set address (add GRi arg))
	    (c-call VOID (.str "@cpu@_store_quad_" regtype)
		     pc address (index-of (.sym regtype k))))
)

(define-pmacro (store-quad-r-r name op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-quad-semantics regtype address GRj))
       profile
  )
)

(store-quad-r-r stq   OP_03 OPE1_04 GR    NA
		((fr500 (unit u-gr-store))) "Store quad word")
(store-quad-r-r stqf  OP_03 OPE1_0C FRint FR-ACCESS
		((fr500 (unit u-fr-store)))
		"Store quad float")
(store-quad-r-r stqc  OP_03 OPE1_27 CPR   NA
		() "Store coprocessor quad word")

(define-pmacro (r-store-quad name op ope regtype is_float attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-quad-semantics regtype address GRj)
		 (c-call VOID "@cpu@_check_recovering_store"
			 address (index-of (.sym regtype k)) 16 is_float))
       profile
  )
)

(r-store-quad rstq  OP_03 OPE1_24 GR    0 NA
	      ((fr500 (unit u-gr-r-store))) "Store quad word")
(r-store-quad rstqf OP_03 OPE1_2C FRint 1 FR-ACCESS
	      ((fr500 (unit u-fr-r-store))) "Store quad float")

(define-pmacro (store-r-r-u name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((UWI address))
		 (set address (add GRi GRj))
		 (c-call VOID (.str "@cpu@_write_mem_" mode)
			 pc address (.sym regtype k))
		 (set GRi address))
       profile
  )
)

(store-r-r-u stbu  QI OP_03 OPE1_10 GR NA
	     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	     "Store unsigned byte, update index")
(store-r-r-u sthu  HI OP_03 OPE1_11 GR NA
	     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	     "Store unsigned half, update index")
(store-r-r-u stu   WI OP_03 OPE1_12 GR NA
	     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	     "Store          word, update index")

(store-r-r-u stbfu QI OP_03 OPE1_18 FRint FR-ACCESS
	     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	     "Store byte float, update index")
(store-r-r-u sthfu HI OP_03 OPE1_19 FRint FR-ACCESS
	     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	     "Store half float, update index")
(store-r-r-u stfu  SI OP_03 OPE1_1A FRint FR-ACCESS
	     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	     "Store word float, update index")

(store-r-r-u stcu  SI OP_03 OPE1_2D CPR (MACH frv) ()
	     "Store coprocessor word, update index")

(define-pmacro (store-double-r-r-u
		name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-double-semantics mode regtype address GRj)
		 (set GRi address))
       profile
  )
)

(store-double-r-r-u stdu  DI OP_03 OPE1_13 GR  NA
		    ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		    "Store double word, update index")
(store-double-r-r-u stdfu DF OP_03 OPE1_1B FR  FR-ACCESS
		    ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		    "Store double float,update index")
(store-double-r-r-u stdcu DI OP_03 OPE1_2E CPR (MACH frv) ()
		    "Store coprocessor double word, update index")

(define-pmacro (store-quad-r-r-u name op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj)")
       (+ pack (.sym regtype k) op GRi ope GRj)
       (sequence ((WI address))
		 (store-quad-semantics regtype address GRj)
		 (set GRi address))
       profile
  )
)

(store-quad-r-r-u stqu  OP_03 OPE1_14 GR    NA
		  ((fr500 (unit u-gr-store)))
		  "Store quad word, update index")
(store-quad-r-r-u stqfu OP_03 OPE1_1C FRint FR-ACCESS
		  ((fr500 (unit u-fr-store)))
		  "Store quad float, update index")
(store-quad-r-r-u stqcu OP_03 OPE1_2F CPR   NA ()
		  "Store coprocessor quad   word, update index")

(define-pmacro (conditional-load name mode op ope regtype profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
       (.str name "$pack @($GRi,$GRj),$" regtype "k,$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (set (.sym regtype k)
		(c-call mode (.str "@cpu@_read_mem_" mode) pc (add GRi GRj))))
       profile
  )
)

(conditional-load cldsb  QI OP_5E OPE4_0 GR
		  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		  "Load   signed byte")
(conditional-load cldub UQI OP_5E OPE4_1 GR
		  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		  "Load unsigned byte")
(conditional-load cldsh  HI OP_5E OPE4_2 GR
		  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		  "Load   signed half")
(conditional-load clduh UHI OP_5E OPE4_3 GR
		  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		  "Load unsigned half")
(conditional-load cld    SI OP_5F OPE4_0 GR
		  ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
		  "Load          word")

(conditional-load cldbf UQI OP_60 OPE4_0 FRint
		  ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		  "Load byte float")
(conditional-load cldhf UHI OP_60 OPE4_1 FRint
		  ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		  "Load half float")
(conditional-load cldf   SI OP_60 OPE4_2 FRint
		  ((fr400 (unit u-fr-load)) (fr500 (unit u-fr-load)))
		  "Load word float")

(define-pmacro (conditional-load-double
		name not_gr mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL attr)
       (.str name "$pack @($GRi,$GRj),$" regtype "doublek,$CCi,$cond")
       (+ pack (.sym regtype doublek) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (load-double-semantics not_gr mode regtype address GRj)))
       profile
  )
)

(conditional-load-double cldd  0 DI OP_5F OPE4_1 GR NA
			 ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
			 "Load double word")
(conditional-load-double clddf 1 DF OP_60 OPE4_3 FR FR-ACCESS
			 ((fr400 (unit u-gr-load)) (fr500 (unit u-gr-load)))
			 "Load double float")

(dni cldq
     "conditional load quad integer"
     ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) CONDITIONAL)
     "cldq$pack @($GRi,$GRj),$GRk,$CCi,$cond"
     (+ pack GRk OP_5F GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ((WI address))
		   (load-quad-semantics GR address GRj)))
     ((fr500 (unit u-gr-load)))
)

(define-pmacro (conditional-load-gr-u name mode op ope comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
       (.str name "$pack @($GRi,$GRj),$GRk,$CCi,$cond")
       (+ pack GRk op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (set address (add GRi GRj))
		     (set GRk
			  (c-call mode (.str "@cpu@_read_mem_" mode)
				  pc address))
		     (if (ne (index-of GRi) (index-of GRk))
			 (set GRi address))))
       ((fr400 (unit u-gr-load))
	(fr500 (unit u-gr-load)))
  )
)

(conditional-load-gr-u cldsbu  QI OP_61 OPE4_0 "Load   signed byte, update")
(conditional-load-gr-u cldubu UQI OP_61 OPE4_1 "Load unsigned byte, update")
(conditional-load-gr-u cldshu  HI OP_61 OPE4_2 "Load   signed half, update")
(conditional-load-gr-u clduhu UHI OP_61 OPE4_3 "Load unsigned half, update")
(conditional-load-gr-u cldu    SI OP_62 OPE4_0 "Load          word, update")

(define-pmacro (conditional-load-non-gr-u name mode op ope regtype comment)
  (dni name
       (comment)
       ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL FR-ACCESS)
       (.str name "$pack @($GRi,$GRj),$" regtype "k,$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (set address (add GRi GRj))
		     (set (.sym regtype k)
			  (c-call mode (.str "@cpu@_read_mem_" mode)
				  pc address))
		     (set GRi address)))
       ((fr400 (unit u-fr-load))
	(fr500 (unit u-fr-load)))
  )
)

(conditional-load-non-gr-u cldbfu UQI OP_63 OPE4_0 FRint "Load byte float, update")
(conditional-load-non-gr-u cldhfu UHI OP_63 OPE4_1 FRint "Load half float, update")
(conditional-load-non-gr-u cldfu   SI OP_63 OPE4_2 FRint "Load word float, update")


(dni clddu
     "Load double word,  update"
     ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL)
     "clddu$pack @($GRi,$GRj),$GRdoublek,$CCi,$cond"
     (+ pack GRdoublek OP_62 GRi CCi cond OPE4_1 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ((WI address))
		   (load-double-semantics 0 DI GR address GRj)
		   (if (ne (index-of GRi) (index-of GRdoublek))
		       (set GRi address))))
     ((fr400 (unit u-gr-load))
      (fr500 (unit u-gr-load)))
)

(dni clddfu
     "Load double float, update"
     ((UNIT LOAD) (FR500-MAJOR I-2) (FR400-MAJOR I-2) CONDITIONAL FR-ACCESS)
     "clddfu$pack @($GRi,$GRj),$FRdoublek,$CCi,$cond"
     (+ pack FRdoublek OP_63 GRi CCi cond OPE4_3 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ((WI address))
		   (load-double-semantics 1 DF FR address GRj)
		   (set GRi address)))
     ((fr400 (unit u-fr-load))
      (fr500 (unit u-fr-load)))
)

(dni cldqu
     "conditional load quad integer and update index"
     ((UNIT LOAD) (FR500-MAJOR I-2) (MACH frv) CONDITIONAL)
     "cldqu$pack @($GRi,$GRj),$GRk,$CCi,$cond"
     (+ pack GRk OP_62 GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ((WI address))
		   (load-quad-semantics GR address GRj)
		   (if (ne (index-of GRi) (index-of GRk))
		       (set GRi address))))
     ((fr500 (unit u-gr-load)))
)

(define-pmacro (conditional-store name mode op ope regtype profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL)
       (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi cond ope GRj)
       (if (eq CCi (or cond 2))
	   (c-call VOID (.str "@cpu@_write_mem_" mode)
		   pc (add GRi GRj) (.sym regtype k)))
       profile
  )
)

(conditional-store cstb  QI OP_64 OPE4_0 GR
		   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		   "Store unsigned byte")
(conditional-store csth  HI OP_64 OPE4_1 GR
		   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		   "Store unsigned half")
(conditional-store cst   SI OP_64 OPE4_2 GR
		   ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		   "Store          word")

(conditional-store cstbf QI OP_66 OPE4_0 FRint
		   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		   "Store byte float")
(conditional-store csthf HI OP_66 OPE4_1 FRint
		   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		   "Store half float")
(conditional-store cstf  SI OP_66 OPE4_2 FRint
		   ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		   "Store word float")

(define-pmacro (conditional-store-double
		name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (store-double-semantics mode regtype address GRj)))
       profile
  )
)

(conditional-store-double cstd  DI OP_64 OPE4_3 GR NA
			  ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
			  "Store double word")
(conditional-store-double cstdf DF OP_66 OPE4_3 FR FR-ACCESS
			  ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
			  "Store double float")

(dni cstq
     "conditionally store quad word"
     ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) CONDITIONAL)
     "cstq$pack $GRk,@($GRi,$GRj),$CCi,$cond"
     (+ pack GRk OP_65 GRi CCi cond OPE4_0 GRj)
     (if (eq CCi (or cond 2))
	 (sequence ((WI address))
		   (store-quad-semantics GR address GRj)))
     ((fr500 (unit u-gr-store)))
)

(define-pmacro (conditional-store-u
		name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (set address (add GRi GRj))
		     (c-call VOID (.str "@cpu@_write_mem_" mode)
			     pc address (.sym regtype k))
		     (set GRi address)))
       profile
  )
)

(conditional-store-u cstbu QI OP_67 OPE4_0 GR NA
		     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		     "Store unsigned byte, update index")
(conditional-store-u csthu HI OP_67 OPE4_1 GR NA
		     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		     "Store unsigned half, update index")
(conditional-store-u cstu  SI OP_67 OPE4_2 GR NA
		     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		     "Store          word, update index")

(conditional-store-u cstbfu QI OP_68 OPE4_0 FRint FR-ACCESS
		     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		     "Store byte float, update index")
(conditional-store-u csthfu HI OP_68 OPE4_1 FRint FR-ACCESS
		     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		     "Store half float, update index")
(conditional-store-u cstfu  SI OP_68 OPE4_2 FRint FR-ACCESS
		     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		     "Store word float, update index")

(define-pmacro (conditional-store-double-u
		name mode op ope regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) CONDITIONAL attr)
       (.str name "$pack $" regtype "k,@($GRi,$GRj),$CCi,$cond")
       (+ pack (.sym regtype k) op GRi CCi  cond ope GRj)
       (if (eq CCi (or cond 2))
	   (sequence ((WI address))
		     (store-double-semantics mode regtype address GRj)
		     (set GRi address)))
       profile
  )
)

(conditional-store-double-u cstdu  DI OP_67 OPE4_3 GR NA
			    ((fr400 (unit u-gr-store))
			     (fr500 (unit u-gr-store)))
			    "Store double word, update index")
(conditional-store-double-u cstdfu DF OP_68 OPE4_3 FR FR-ACCESS
			    ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
			    "Store double float, update index")

(define-pmacro (store-r-simm name mode op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" regtype "k,@($GRi,$d12)")
       (+ pack (.sym regtype k) op GRi d12)
       (c-call VOID (.str "@cpu@_write_mem_" mode)
	       pc (add GRi d12) (.sym regtype k))
       profile
  )
)

(store-r-simm stbi QI OP_50 GR NA
	      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	      "Store unsigned byte")
(store-r-simm sthi HI OP_51 GR NA
	      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	      "Store unsigned half")
(store-r-simm sti  SI OP_52 GR NA
	      ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
	      "Store          word")

(store-r-simm stbfi QI OP_4E FRint FR-ACCESS
	      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	      "Store byte float")
(store-r-simm sthfi HI OP_4F FRint FR-ACCESS
	      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	      "Store half float")
(store-r-simm stfi  SI OP_55 FRint FR-ACCESS
	      ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
	      "Store word float")

(define-pmacro (store-double-r-simm name mode op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (FR400-MAJOR I-3) attr)
       (.str name "$pack $" regtype "k,@($GRi,$d12)")
       (+ pack (.sym regtype k) op GRi d12)
       (sequence ((WI address))
		 (store-double-semantics mode regtype address d12))
       profile
  )
)

(store-double-r-simm stdi  DI OP_53 GR NA
		     ((fr400 (unit u-gr-store)) (fr500 (unit u-gr-store)))
		     "Store double word")
(store-double-r-simm stdfi DF OP_56 FR FR-ACCESS
		     ((fr400 (unit u-fr-store)) (fr500 (unit u-fr-store)))
		     "Store double float")

(define-pmacro (store-quad-r-simm name op regtype attr profile comment)
  (dni name
       (comment)
       ((UNIT I0) (FR500-MAJOR I-3) (MACH frv) attr)
       (.str name "$pack $" regtype "k,@($GRi,$d12)")
       (+ pack (.sym regtype k) op GRi d12)
       (sequence ((WI address))
		 (store-quad-semantics regtype address d12))
       profile
  )
)

(store-quad-r-simm stqi  OP_54 GR    NA ((fr500 (unit u-gr-store)))
		   "Store quad word")
(store-quad-r-simm stqfi OP_57 FRint FR-ACCESS ()
		   "Store quad float")

(define-pmacro (swap-semantics base offset arg)
  (sequence ((WI tmp) (WI address))
	    (set tmp arg)
	    (set address (add base offset))
	    (set arg (c-call WI "@cpu@_read_mem_WI" pc address))
	    (c-call VOID "@cpu@_write_mem_WI" pc address tmp))
)

(dni swap
     "Swap contents of memory with GR"
     ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
     "swap$pack @($GRi,$GRj),$GRk"
     (+ pack GRk OP_03 GRi OPE1_05 GRj)
     (swap-semantics GRi GRj GRk)
     ((fr400 (unit u-swap))
      (fr500 (unit u-swap)))
)

(dni "swapi"
     "Swap contents of memory with GR"
     ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
     ("swapi$pack @($GRi,$d12),$GRk")
     (+ pack GRk OP_4D GRi d12)
     (swap-semantics GRi d12 GRk)
     ((fr400 (unit u-swap))
      (fr500 (unit u-swap)))
)

(dni cswap
     "Conditionally swap contents of memory with GR"
     ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2) CONDITIONAL)
     "cswap$pack @($GRi,$GRj),$GRk,$CCi,$cond"
     (+ pack GRk OP_65 GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (swap-semantics GRi GRj GRk))
     ((fr400 (unit u-swap))
      (fr500 (unit u-swap)))
)

(define-pmacro (register-transfer
		name op ope reg_src reg_targ pipe major1 major2 attr1 attr2
		profile comment)
  (dni name
       (comment)
       ((UNIT pipe) major1 major2 attr1 attr2)
       (.str name "$pack $" reg_src ",$" reg_targ)
       (+ pack reg_targ op (rs-null) ope reg_src)
       (set reg_targ reg_src)
       profile
  )
)

(register-transfer movgf OP_03 OPE1_15
		   GRj FRintk I0 (FR500-MAJOR I-4) (FR400-MAJOR I-4)
		   FR-ACCESS NA
		   ((fr400 (unit u-gr2fr)) (fr500 (unit u-gr2fr)))
		   "transfer gr to fr")
(register-transfer movfg OP_03 OPE1_0D
		   FRintk GRj I0 (FR500-MAJOR I-4) (FR400-MAJOR I-4)
		   FR-ACCESS NA
		   ((fr400 (unit u-fr2gr)) (fr500 (unit u-fr2gr)))
		   "transfer fr to gr")

(define-pmacro (nextreg hw r offset) (reg hw (add (index-of r) offset)))

(define-pmacro (register-transfer-double-from-gr-semantics cond)
  (if cond
      (if (eq (index-of GRj) 0)
	  (sequence ()
		    (set FRintk 0)
		    (set (nextreg h-fr_int FRintk 1) 0))
	  (sequence ()
		    (set FRintk GRj)
		    (set (nextreg h-fr_int FRintk 1) (nextreg h-gr GRj 1)))))
)

(dni movgfd
     "move GR for FR double"
     ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) FR-ACCESS)
     "movgfd$pack $GRj,$FRintk"
     (+ pack FRintk OP_03 (rs-null) OPE1_16 GRj)
     (register-transfer-double-from-gr-semantics 1)
     ; TODO -- doesn't handle second register in the pair
     ((fr400 (unit u-gr2fr))
      (fr500 (unit u-gr2fr)))
)

(define-pmacro (register-transfer-double-to-gr-semantics cond)
  (if (andif (ne (index-of GRj) 0) cond)
      (sequence ()
		(set GRj FRintk)
		(set (nextreg h-gr GRj 1) (nextreg h-fr_int FRintk 1))))
)

(dni movfgd
     "move FR for GR double"
     ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) FR-ACCESS)
     "movfgd$pack $FRintk,$GRj"
     (+ pack FRintk OP_03 (rs-null) OPE1_0E GRj)
     (register-transfer-double-to-gr-semantics 1)
     ; TODO -- doesn't handle second register in the pair
     ((fr400 (unit u-fr2gr))
      (fr500 (unit u-fr2gr)))
)

(dni movgfq
     "move GR for FR quad"
     ((UNIT I0) (FR500-MAJOR I-4) (MACH frv) FR-ACCESS)
     "movgfq$pack $GRj,$FRintk"
     (+ pack FRintk OP_03 (rs-null) OPE1_17 GRj)
     (if (eq (index-of GRj) 0)
	 (sequence ()
		   (set FRintk 0)
		   (set (reg h-fr_int (add (index-of FRintk) 1)) 0)
		   (set (reg h-fr_int (add (index-of FRintk) 2)) 0)
		   (set (reg h-fr_int (add (index-of FRintk) 3)) 0))
	 (sequence ()
		   (set FRintk GRj)
		   (set (reg h-fr_int (add (index-of FRintk) 1))
			(reg h-gr (add (index-of GRj)    1)))
		   (set (reg h-fr_int (add (index-of FRintk) 2))
			(reg h-gr (add (index-of GRj)    2)))
		   (set (reg h-fr_int (add (index-of FRintk) 3))
			(reg h-gr (add (index-of GRj)    3)))))
     ()
)

(dni movfgq
     "move FR for GR quad"
     ((UNIT I0) (FR500-MAJOR I-4) (MACH frv) FR-ACCESS)
     "movfgq$pack $FRintk,$GRj"
     (+ pack FRintk OP_03 (rs-null) OPE1_0F GRj)
     (if (ne (index-of GRj) 0)
	 (sequence ()
		   (set GRj FRintk)
		   (set (reg h-gr (add (index-of GRj)    1))
			(reg h-fr_int (add (index-of FRintk) 1)))
		   (set (reg h-gr (add (index-of GRj)    2))
			(reg h-fr_int (add (index-of FRintk) 2)))
		   (set (reg h-gr (add (index-of GRj)    3))
			(reg h-fr_int (add (index-of FRintk) 3)))))
     ()
)

(define-pmacro (conditional-register-transfer
		name op ope reg_src reg_targ pipe major1 major2 mach
		profile comment)
  (dni name
       (comment)
       ((UNIT pipe) major1 major2 CONDITIONAL FR-ACCESS mach)
       (.str name "$pack $" reg_src ",$" reg_targ ",$CCi,$cond")
       (+ pack reg_targ op (rs-null) CCi cond ope reg_src)
       (if (eq CCi (or cond 2))
	   (set reg_targ reg_src))
       profile
  )
)

(conditional-register-transfer cmovgf OP_69 OPE4_0 GRj FRintk I0
			       (FR500-MAJOR I-4) (FR400-MAJOR I-4)
			       NA
			       ((fr400 (unit u-gr2fr)) (fr500 (unit u-gr2fr)))
			       "transfer gr to fr")
(conditional-register-transfer cmovfg OP_69 OPE4_2 FRintk GRj I0
			       (FR500-MAJOR I-4) (FR400-MAJOR I-4)
			       NA
			       ((fr400 (unit u-fr2gr)) (fr500 (unit u-fr2gr)))
			       "transfer fr to gr")


(dni cmovgfd
     "Conditional move GR to FR double"
     ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) CONDITIONAL FR-ACCESS)
     "cmovgfd$pack $GRj,$FRintk,$CCi,$cond"
     (+ pack FRintk OP_69 (rs-null) CCi cond OPE4_1 GRj)
     (register-transfer-double-from-gr-semantics (eq CCi (or cond 2)))
     ; TODO -- doesn't handle extra registers in double
     ((fr400 (unit u-gr2fr))
      (fr500 (unit u-gr2fr)))
)

(dni cmovfgd
     "Conditional move FR to GR double"
     ((UNIT I0) (FR500-MAJOR I-4) (FR400-MAJOR I-4) CONDITIONAL FR-ACCESS)
     "cmovfgd$pack $FRintk,$GRj,$CCi,$cond"
     (+ pack FRintk OP_69 (rs-null) CCi cond OPE4_3 GRj)
     (register-transfer-double-to-gr-semantics (eq CCi (or cond 2)))
     ; TODO -- doesn't handle second register in the pair
     ((fr400 (unit u-fr2gr))
      (fr500 (unit u-fr2gr)))
)

(define-pmacro (register-transfer-spr
		name op ope reg_src reg_targ unitname comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
       (.str name "$pack $" reg_src ",$" reg_targ)
       (+ pack reg_targ op ope reg_src)
       (set reg_targ reg_src)
       ((fr400 (unit unitname))
	(fr500 (unit unitname)))
  )
)

(register-transfer-spr movgs OP_03 OPE1_06 GRj spr u-gr2spr "transfer gr->spr")
(register-transfer-spr movsg OP_03 OPE1_07 spr GRj u-spr2gr "transfer spr->gr")

; Integer Branch Conditions
(define-pmacro (Inev cc) (const BI 0))
(define-pmacro (Ira  cc) (const BI 1))
(define-pmacro (Ieq  cc) (     zbit cc))
(define-pmacro (Ine  cc) (not (zbit cc)))
(define-pmacro (Ile  cc) (     orif (zbit cc) (xor (nbit cc) (vbit cc))))
(define-pmacro (Igt  cc) (not (orif (zbit cc) (xor (nbit cc) (vbit cc)))))
(define-pmacro (Ilt  cc) (     xor  (nbit cc) (vbit cc)))
(define-pmacro (Ige  cc) (not (xor  (nbit cc) (vbit cc))))
(define-pmacro (Ils  cc) (     orif (cbit cc) (zbit cc)))
(define-pmacro (Ihi  cc) (not (orif (cbit cc) (zbit cc))))
(define-pmacro (Ic   cc) (     cbit cc))
(define-pmacro (Inc  cc) (not (cbit cc)))
(define-pmacro (In   cc) (     nbit cc))
(define-pmacro (Ip   cc) (not (nbit cc)))
(define-pmacro (Iv   cc) (     vbit cc))
(define-pmacro (Inv  cc) (not (vbit cc)))

; Float Branch Conditions
(define-pmacro (Fnev cc) (const BI 0))
(define-pmacro (Fra  cc) (const BI 1))
(define-pmacro (Fne  cc) (orif (lbit cc) (orif (gbit cc) (ubit cc))))
(define-pmacro (Feq  cc) (ebit cc))
(define-pmacro (Flg  cc) (orif (lbit cc) (gbit cc)))
(define-pmacro (Fue  cc) (orif (ebit cc) (ubit cc)))
(define-pmacro (Ful  cc) (orif (lbit cc) (ubit cc)))
(define-pmacro (Fge  cc) (orif (ebit cc) (gbit cc)))
(define-pmacro (Flt  cc) (lbit cc))
(define-pmacro (Fuge cc) (orif (ebit cc) (orif (gbit cc) (ubit cc))))
(define-pmacro (Fug  cc) (orif (gbit cc) (ubit cc)))
(define-pmacro (Fle  cc) (orif (ebit cc) (lbit cc)))
(define-pmacro (Fgt  cc) (gbit cc))
(define-pmacro (Fule cc) (orif (ebit cc) (orif (lbit cc) (ubit cc))))
(define-pmacro (Fu   cc) (ubit cc))
(define-pmacro (Fo   cc) (orif (ebit cc) (orif (lbit cc) (gbit cc))))

(define-pmacro (conditional-branch-i prefix cc op cond comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
       (.str (.sym prefix cc) "$pack $ICCi_2,$hint,$label16")
       (+ pack (.sym ICC_ cc) ICCi_2 op hint label16)
       (sequence ()
		 (c-call VOID "@cpu@_model_branch" label16 hint)
		 (if (cond ICCi_2)
		     (set pc label16)))
       ((fr400 (unit u-branch))
	(fr500 (unit u-branch)))
  )
)

(dni bra
     "integer branch equal"
      ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
      "bra$pack $hint_taken$label16"
      (+ pack ICC_ra (ICCi_2-null) OP_06 hint_taken label16)
      (sequence ()
		(c-call VOID "@cpu@_model_branch" label16 hint_taken)
		(set pc label16))
      ((fr400 (unit u-branch))
       (fr500 (unit u-branch)))
)

(dni bno
     "integer branch never"
      ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1))
      "bno$pack$hint_not_taken"
      (+ pack ICC_nev (ICCi_2-null) OP_06 hint_not_taken (label16-null))
      (c-call VOID "@cpu@_model_branch" label16 hint_not_taken)
      ((fr400 (unit u-branch))
       (fr500 (unit u-branch)))
)

(conditional-branch-i b eq  OP_06 Ieq  "integer branch equal")
(conditional-branch-i b ne  OP_06 Ine  "integer branch not equal")
(conditional-branch-i b le  OP_06 Ile  "integer branch less or equal")
(conditional-branch-i b gt  OP_06 Igt  "integer branch greater")
(conditional-branch-i b lt  OP_06 Ilt  "integer branch less")
(conditional-branch-i b ge  OP_06 Ige  "integer branch greater or equal")
(conditional-branch-i b ls  OP_06 Ils  "integer branch less or equal unsigned")
(conditional-branch-i b hi  OP_06 Ihi  "integer branch greater unsigned")
(conditional-branch-i b c   OP_06 Ic   "integer branch carry set")
(conditional-branch-i b nc  OP_06 Inc  "integer branch carry clear")
(conditional-branch-i b n   OP_06 In   "integer branch negative")
(conditional-branch-i b p   OP_06 Ip   "integer branch positive")
(conditional-branch-i b v   OP_06 Iv   "integer branch overflow set")
(conditional-branch-i b nv  OP_06 Inv  "integer branch overflow clear")

(define-pmacro (conditional-branch-f prefix cc op cond comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
       (.str (.sym prefix cc) "$pack $FCCi_2,$hint,$label16")
       (+ pack (.sym FCC_ cc) FCCi_2 op hint label16)
       (sequence ()
		 (c-call VOID "@cpu@_model_branch" label16 hint)
		 (if (cond FCCi_2) (set pc label16)))
       ((fr400 (unit u-branch))
	(fr500 (unit u-branch)))
  )
)

(dni fbra
     "float branch equal"
      ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
      "fbra$pack $hint_taken$label16"
      (+ pack FCC_ra (FCCi_2-null) OP_07 hint_taken label16)
      (sequence ()
		(c-call VOID "@cpu@_model_branch" label16 hint_taken)
		(set pc label16))
      ((fr400 (unit u-branch))
       (fr500 (unit u-branch)))
)

(dni fbno
     "float branch never"
      ((UNIT B01) (FR500-MAJOR B-1) (FR400-MAJOR B-1) FR-ACCESS)
      "fbno$pack$hint_not_taken"
      (+ pack FCC_nev (FCCi_2-null) OP_07 hint_not_taken (label16-null))
      (c-call VOID "@cpu@_model_branch" label16 hint_not_taken)
      ((fr400 (unit u-branch))
       (fr500 (unit u-branch)))
)

(conditional-branch-f fb ne  OP_07 Fne  "float branch not equal")
(conditional-branch-f fb eq  OP_07 Feq  "float branch equal")
(conditional-branch-f fb lg  OP_07 Flg  "float branch less or greater")
(conditional-branch-f fb ue  OP_07 Fue  "float branch unordered or equal")
(conditional-branch-f fb ul  OP_07 Ful  "float branch unordered or less")
(conditional-branch-f fb ge  OP_07 Fge  "float branch greater or equal")
(conditional-branch-f fb lt  OP_07 Flt  "float branch less")
(conditional-branch-f fb uge OP_07 Fuge "float branch unordered, greater,equal")
(conditional-branch-f fb ug  OP_07 Fug  "float branch unordered or greater")
(conditional-branch-f fb le  OP_07 Fle  "float branch less or equal")
(conditional-branch-f fb gt  OP_07 Fgt  "float branch greater")
(conditional-branch-f fb ule OP_07 Fule "float branch unordered, less or equal")
(conditional-branch-f fb u   OP_07 Fu   "float branch unordered")
(conditional-branch-f fb o   OP_07 Fo   "float branch ordered")

(define-pmacro (ctrlr-branch-semantics cond ccond)
  (sequence ((SI tmp))
	    (set tmp (sub (spr-lcr) 1))
	    (set (spr-lcr) tmp)
	    (if cond
		(if (eq ccond 0)
		    (if (ne tmp 0)
			(set pc (spr-lr)))
		    (if (eq tmp 0)
			(set pc (spr-lr))))))
)

(dni bctrlr
     "LCR conditional branch to lr"
     ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
     ("bctrlr$pack $ccond,$hint")
     (+ pack (cond-null) (ICCi_2-null) OP_0E hint OPE3_01 ccond (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
	       (ctrlr-branch-semantics (const BI 1) ccond))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(define-pmacro (conditional-branch-cclr prefix cc i-f op ope cond attr comment)
  (dni (.sym prefix cc lr)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) attr)
       (.str (.sym prefix cc lr) "$pack $" i-f "CCi_2,$hint")
       (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op hint ope
	  (ccond-null) (s12-null))
       (sequence ()
		 (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
		 (if (cond (.sym i-f CCi_2)) (set pc (spr-lr))))
       ((fr400 (unit u-branch))
	(fr500 (unit u-branch)))
  )
)

(dni bralr
     "integer cclr branch always"
     ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
     "bralr$pack$hint_taken"
     (+ pack ICC_ra (ICCi_2-null) OP_0E hint_taken OPE3_02 (ccond-null) (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
	       (set pc (spr-lr)))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni bnolr
     "integer cclr branch never"
     ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
     "bnolr$pack$hint_not_taken"
     (+ pack ICC_nev (ICCi_2-null) OP_0E hint_not_taken OPE3_02 (ccond-null) (s12-null))
     (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(conditional-branch-cclr b eq  I OP_0E OPE3_02 Ieq  NA "integer cclr branch equal")
(conditional-branch-cclr b ne  I OP_0E OPE3_02 Ine  NA "integer cclr branch not equal")
(conditional-branch-cclr b le  I OP_0E OPE3_02 Ile  NA "integer cclr branch less or equal")
(conditional-branch-cclr b gt  I OP_0E OPE3_02 Igt  NA "integer cclr branch greater")
(conditional-branch-cclr b lt  I OP_0E OPE3_02 Ilt  NA "integer cclr branch less")
(conditional-branch-cclr b ge  I OP_0E OPE3_02 Ige  NA "integer cclr branch greater or equal")
(conditional-branch-cclr b ls  I OP_0E OPE3_02 Ils  NA "integer cclr branch less or equal unsigned")
(conditional-branch-cclr b hi  I OP_0E OPE3_02 Ihi  NA "integer cclr branch greater unsigned")
(conditional-branch-cclr b c   I OP_0E OPE3_02 Ic   NA "integer cclr branch carry set")
(conditional-branch-cclr b nc  I OP_0E OPE3_02 Inc  NA "integer cclr branch carry clear")
(conditional-branch-cclr b n   I OP_0E OPE3_02 In   NA "integer cclr branch negative")
(conditional-branch-cclr b p   I OP_0E OPE3_02 Ip   NA "integer cclr branch positive")
(conditional-branch-cclr b v   I OP_0E OPE3_02 Iv   NA "integer cclr branch overflow set")
(conditional-branch-cclr b nv  I OP_0E OPE3_02 Inv  NA "integer cclr branch overflow clear")

(dni fbralr
     "float cclr branch always"
     ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) FR-ACCESS)
     "fbralr$pack$hint_taken"
     (+ pack FCC_ra (FCCi_2-null) OP_0E hint_taken OPE3_06 (ccond-null) (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
	       (set pc (spr-lr)))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni fbnolr
     "float cclr branch never"
     ((UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3) FR-ACCESS)
     "fbnolr$pack$hint_not_taken"
     (+ pack FCC_nev (FCCi_2-null) OP_0E hint_not_taken OPE3_06 (ccond-null) (s12-null))
     (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(conditional-branch-cclr fb eq  F OP_0E OPE3_06 Feq  FR-ACCESS "float cclr branch equal")
(conditional-branch-cclr fb ne  F OP_0E OPE3_06 Fne  FR-ACCESS "float cclr branch not equal")
(conditional-branch-cclr fb lg  F OP_0E OPE3_06 Flg  FR-ACCESS "float branch less or greater")
(conditional-branch-cclr fb ue  F OP_0E OPE3_06 Fue  FR-ACCESS "float branch unordered or equal")
(conditional-branch-cclr fb ul  F OP_0E OPE3_06 Ful  FR-ACCESS "float branch unordered or less")
(conditional-branch-cclr fb ge  F OP_0E OPE3_06 Fge  FR-ACCESS "float branch greater or equal")
(conditional-branch-cclr fb lt  F OP_0E OPE3_06 Flt  FR-ACCESS "float branch less")
(conditional-branch-cclr fb uge F OP_0E OPE3_06 Fuge FR-ACCESS "float branch unordered, greater, equal")
(conditional-branch-cclr fb ug  F OP_0E OPE3_06 Fug  FR-ACCESS "float branch unordered or greater")
(conditional-branch-cclr fb le  F OP_0E OPE3_06 Fle  FR-ACCESS "float branch less or equal")
(conditional-branch-cclr fb gt  F OP_0E OPE3_06 Fgt  FR-ACCESS "float branch greater")
(conditional-branch-cclr fb ule F OP_0E OPE3_06 Fule FR-ACCESS "float branch unordered, less or equal")
(conditional-branch-cclr fb u   F OP_0E OPE3_06 Fu   FR-ACCESS "float branch unordered")
(conditional-branch-cclr fb o   F OP_0E OPE3_06 Fo   FR-ACCESS "float branch ordered")

(define-pmacro (conditional-branch-ctrlr prefix cc i-f op ope cond attr comment)
  (dni (.sym prefix cc lr)
       (comment)
       ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) attr)
       (.str (.sym prefix cc lr) "$pack $" i-f "CCi_2,$ccond,$hint")
       (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op hint ope ccond (s12-null))
       (sequence ()
		 (c-call VOID "@cpu@_model_branch" (spr-lr) hint)
		 (ctrlr-branch-semantics (cond (.sym i-f CCi_2)) ccond))
       ((fr400 (unit u-branch))
	(fr500 (unit u-branch)))
  )
)

(dni bcralr
     "integer ctrlr branch always"
     ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
     "bcralr$pack $ccond$hint_taken"
     (+ pack ICC_ra (ICCi_2-null) OP_0E hint_taken OPE3_03 ccond (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
	       (ctrlr-branch-semantics (const BI 1) ccond))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni bcnolr
     "integer ctrlr branch never"
     ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2))
     "bcnolr$pack$hint_not_taken"
     (+ pack ICC_nev (ICCi_2-null) OP_0E hint_not_taken OPE3_03 (ccond-null) (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
	       (ctrlr-branch-semantics (const BI 0) ccond))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(conditional-branch-ctrlr bc eq  I OP_0E OPE3_03 Ieq  NA "integer ctrlr branch equal")
(conditional-branch-ctrlr bc ne  I OP_0E OPE3_03 Ine  NA "integer ctrlr branch not equal")
(conditional-branch-ctrlr bc le  I OP_0E OPE3_03 Ile  NA "integer ctrlr branch less equal")
(conditional-branch-ctrlr bc gt  I OP_0E OPE3_03 Igt  NA "integer ctrlr branch greater")
(conditional-branch-ctrlr bc lt  I OP_0E OPE3_03 Ilt  NA "integer ctrlr branch less")
(conditional-branch-ctrlr bc ge  I OP_0E OPE3_03 Ige  NA "integer ctrlr branch greater equal")
(conditional-branch-ctrlr bc ls  I OP_0E OPE3_03 Ils  NA "integer ctrlr branch less equal unsigned")
(conditional-branch-ctrlr bc hi  I OP_0E OPE3_03 Ihi  NA "integer ctrlr branch greater unsigned")
(conditional-branch-ctrlr bc c   I OP_0E OPE3_03 Ic   NA "integer ctrlr branch carry set")
(conditional-branch-ctrlr bc nc  I OP_0E OPE3_03 Inc  NA "integer ctrlr branch carry clear")
(conditional-branch-ctrlr bc n   I OP_0E OPE3_03 In   NA "integer ctrlr branch negative")
(conditional-branch-ctrlr bc p   I OP_0E OPE3_03 Ip   NA "integer ctrlr branch positive")
(conditional-branch-ctrlr bc v   I OP_0E OPE3_03 Iv   NA "integer ctrlr branch overflow set")
(conditional-branch-ctrlr bc nv  I OP_0E OPE3_03 Inv  NA "integer ctrlr branch overflow clear")

(dni fcbralr
     "float ctrlr branch always"
     ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) FR-ACCESS)
     "fcbralr$pack $ccond$hint_taken"
     (+ pack FCC_ra (FCCi_2-null) OP_0E hint_taken OPE3_07 ccond (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_taken)
	       (ctrlr-branch-semantics (const BI 1) ccond))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni fcbnolr
     "float ctrlr branch never"
     ((UNIT B0) (FR500-MAJOR B-2) (FR400-MAJOR B-2) FR-ACCESS)
     "fcbnolr$pack$hint_not_taken"
     (+ pack FCC_nev (FCCi_2-null) OP_0E hint_not_taken OPE3_07 (ccond-null) (s12-null))
     (sequence ()
	       (c-call VOID "@cpu@_model_branch" (spr-lr) hint_not_taken)
	       (ctrlr-branch-semantics (const BI 0) ccond))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(conditional-branch-ctrlr fcb eq  F OP_0E OPE3_07 Feq  FR-ACCESS "float cclr branch equal")
(conditional-branch-ctrlr fcb ne  F OP_0E OPE3_07 Fne  FR-ACCESS "float cclr branch not equal")
(conditional-branch-ctrlr fcb lg  F OP_0E OPE3_07 Flg  FR-ACCESS "float branch less or greater")
(conditional-branch-ctrlr fcb ue  F OP_0E OPE3_07 Fue  FR-ACCESS "float branch unordered or equal")
(conditional-branch-ctrlr fcb ul  F OP_0E OPE3_07 Ful  FR-ACCESS "float branch unordered or less")
(conditional-branch-ctrlr fcb ge  F OP_0E OPE3_07 Fge  FR-ACCESS "float branch greater or equal")
(conditional-branch-ctrlr fcb lt  F OP_0E OPE3_07 Flt  FR-ACCESS "float branch less")
(conditional-branch-ctrlr fcb uge F OP_0E OPE3_07 Fuge FR-ACCESS "float branch unordered, greater, equal")
(conditional-branch-ctrlr fcb ug  F OP_0E OPE3_07 Fug  FR-ACCESS "float branch unordered or greater")
(conditional-branch-ctrlr fcb le  F OP_0E OPE3_07 Fle  FR-ACCESS "float branch less or equal")
(conditional-branch-ctrlr fcb gt  F OP_0E OPE3_07 Fgt  FR-ACCESS "float branch greater")
(conditional-branch-ctrlr fcb ule F OP_0E OPE3_07 Fule FR-ACCESS "float branch unordered, less or equal")
(conditional-branch-ctrlr fcb u   F OP_0E OPE3_07 Fu   FR-ACCESS "float branch unordered")
(conditional-branch-ctrlr fcb o   F OP_0E OPE3_07 Fo   FR-ACCESS "float branch ordered")

(define-pmacro (jump-and-link-semantics base offset LI)
  (sequence ()
	    (if (eq LI 1)
		(c-call VOID "@cpu@_set_write_next_vliw_addr_to_LR" 1))
	    ; Target address gets aligned here
	    (set pc (and (add base offset) #xfffffffc))
	    (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
)

(dni jmpl
     "jump and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
     "jmpl$pack @($GRi,$GRj)"
     (+ pack (misc-null-1) (LI-off) OP_0C GRi (misc-null-2) GRj)
     (jump-and-link-semantics GRi GRj LI)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni calll
     "call and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
     "calll$pack @($GRi,$GRj)"
     (+ pack (misc-null-1) (LI-on) OP_0C GRi (misc-null-2) GRj)
     (jump-and-link-semantics GRi GRj LI)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni jmpil
     "jump immediate and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
     "jmpil$pack @($GRi,$s12)"
     (+ pack (misc-null-1) (LI-off) OP_0D GRi s12)
     (jump-and-link-semantics GRi s12 LI)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni callil
     "call immediate and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5))
     "callil$pack @($GRi,$s12)"
     (+ pack (misc-null-1) (LI-on) OP_0D GRi s12)
     (jump-and-link-semantics GRi s12 LI)
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni call
     "call and link"
     ((UNIT B0) (FR500-MAJOR B-4) (FR400-MAJOR B-4))
     "call$pack $label24"
     (+ pack OP_0F label24)
     (sequence ()
	       (c-call VOID "@cpu@_set_write_next_vliw_addr_to_LR" 1)
	       (set pc label24)
	       (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni rett
    "return from trap"
    ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2) PRIVILEGED)
    "rett$pack $debug"
    (+ pack (misc-null-1) debug OP_05 (rs-null) (s12-null))
    ; frv_rett handles operating vs user mode
    (sequence ()
	      (set pc (c-call UWI "frv_rett" pc debug))
	      (c-call VOID "@cpu@_model_branch" pc #x2)) ; hint branch taken
    ()
)

(dni rei
     "run exception instruction"
     ((UNIT C) (FR500-MAJOR C-1) (MACH frv) PRIVILEGED)
     "rei$pack $eir"
     (+ pack (rd-null) OP_37 eir (s12-null))
     (nop) ; for now
     ()
)

(define-pmacro (trap-semantics cond base offset)
  (if cond
      (sequence ()
		; This is defered to frv_itrap because for the breakpoint
		; case we want to change as little of the machine state as
		; possible.
		;
		; PCSR=PC
		; PSR.PS=PSR.S
		; PSR.ET=0
		; if PSR.ESR==1
		;   SR0 through SR3=GR4 through GR7
		; TBR.TT=0x80 + ((GRi + s12) & 0x7f)
		; PC=TBR
		; We still should indicate what is modified by this insn.
		(clobber (spr-pcsr))
		(clobber psr_ps)
		(clobber psr_et)
		(clobber tbr_tt)
		(if (ne psr_esr (const 0))
		    (sequence ()
			      (clobber (spr-sr0))
			      (clobber (spr-sr1))
			      (clobber (spr-sr2))
			      (clobber (spr-sr3))))
		; frv_itrap handles operating vs user mode
		(c-call VOID "frv_itrap" pc base offset)))
)

(define-pmacro (trap-r prefix cc i-f op ope cond attr comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) attr)
       (.str (.sym prefix cc) "$pack $" i-f "CCi_2,$GRi,$GRj")
       (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op GRi (misc-null-3) ope GRj)
       (trap-semantics (cond (.sym i-f CCi_2)) GRi GRj)
       ((fr400 (unit u-trap))
	(fr500 (unit u-trap)))
  )
)

(dni tra
     "integer trap always"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
     "tra$pack $GRi,$GRj"
     (+ pack ICC_ra (ICCi_2-null) OP_04 GRi (misc-null-3) OPE4_0 GRj)
     (trap-semantics (const BI 1) GRi GRj)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(dni tno
     "integer trap never"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
     "tno$pack"
     (+ pack ICC_nev (ICCi_2-null) OP_04 (GRi-null) (misc-null-3) OPE4_0 (GRj-null))
     (trap-semantics (const BI 0) GRi GRj)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(trap-r t eq  I OP_04 OPE4_0 Ieq  NA "integer trap equal")
(trap-r t ne  I OP_04 OPE4_0 Ine  NA "integer trap not equal")
(trap-r t le  I OP_04 OPE4_0 Ile  NA "integer trap less or equal")
(trap-r t gt  I OP_04 OPE4_0 Igt  NA "integer trap greater")
(trap-r t lt  I OP_04 OPE4_0 Ilt  NA "integer trap less")
(trap-r t ge  I OP_04 OPE4_0 Ige  NA "integer trap greater or equal")
(trap-r t ls  I OP_04 OPE4_0 Ils  NA "integer trap less or equal unsigned")
(trap-r t hi  I OP_04 OPE4_0 Ihi  NA "integer trap greater unsigned")
(trap-r t c   I OP_04 OPE4_0 Ic   NA "integer trap carry set")
(trap-r t nc  I OP_04 OPE4_0 Inc  NA "integer trap carry clear")
(trap-r t n   I OP_04 OPE4_0 In   NA "integer trap negative")
(trap-r t p   I OP_04 OPE4_0 Ip   NA "integer trap positive")
(trap-r t v   I OP_04 OPE4_0 Iv   NA "integer trap overflow set")
(trap-r t nv  I OP_04 OPE4_0 Inv  NA "integer trap overflow clear")

(dni ftra
     "float trap always"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
     "ftra$pack $GRi,$GRj"
     (+ pack FCC_ra (FCCi_2-null) OP_04 GRi (misc-null-3) OPE4_1 GRj)
     (trap-semantics (const BI 1) GRi GRj)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(dni ftno
     "flost trap never"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
     "ftno$pack"
     (+ pack FCC_nev (FCCi_2-null) OP_04 (GRi-null) (misc-null-3) OPE4_1 (GRj-null))
     (trap-semantics (const BI 0) GRi GRj)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(trap-r ft ne  F OP_04 OPE4_1 Fne  FR-ACCESS "float trap not equal")
(trap-r ft eq  F OP_04 OPE4_1 Feq  FR-ACCESS "float trap equal")
(trap-r ft lg  F OP_04 OPE4_1 Flg  FR-ACCESS "float trap greater or less")
(trap-r ft ue  F OP_04 OPE4_1 Fue  FR-ACCESS "float trap unordered or equal")
(trap-r ft ul  F OP_04 OPE4_1 Ful  FR-ACCESS "float trap unordered or less")
(trap-r ft ge  F OP_04 OPE4_1 Fge  FR-ACCESS "float trap greater or equal")
(trap-r ft lt  F OP_04 OPE4_1 Flt  FR-ACCESS "float trap less")
(trap-r ft uge F OP_04 OPE4_1 Fuge FR-ACCESS "float trap unordered greater or equal")
(trap-r ft ug  F OP_04 OPE4_1 Fug  FR-ACCESS "float trap unordered or greater")
(trap-r ft le  F OP_04 OPE4_1 Fle  FR-ACCESS "float trap less or equal")
(trap-r ft gt  F OP_04 OPE4_1 Fgt  FR-ACCESS "float trap greater")
(trap-r ft ule F OP_04 OPE4_1 Fule FR-ACCESS "float trap unordered less or equal")
(trap-r ft u   F OP_04 OPE4_1 Fu   FR-ACCESS "float trap unordered")
(trap-r ft o   F OP_04 OPE4_1 Fo   FR-ACCESS "float trap ordered")

(define-pmacro (trap-immed prefix cc i-f op cond attr comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) attr)
       (.str (.sym prefix cc) "$pack $" i-f "CCi_2,$GRi,$s12")
       (+ pack (.sym i-f CC_ cc) (.sym i-f CCi_2) op GRi s12)
       (trap-semantics (cond (.sym i-f CCi_2)) GRi s12)
       ((fr400 (unit u-trap))
	(fr500 (unit u-trap)))
  )
)

(dni tira
     "integer trap always"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
     "tira$pack $GRi,$s12"
     (+ pack ICC_ra (ICCi_2-null) OP_1C GRi s12)
     (trap-semantics (const BI 1) GRi s12)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(dni tino
     "integer trap never"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
     "tino$pack"
     (+ pack ICC_nev (ICCi_2-null) OP_1C (GRi-null) (s12-null))
     (trap-semantics (const BI 0) GRi s12)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(trap-immed ti eq  I OP_1C Ieq  NA "integer trap equal")
(trap-immed ti ne  I OP_1C Ine  NA "integer trap not equal")
(trap-immed ti le  I OP_1C Ile  NA "integer trap less or equal")
(trap-immed ti gt  I OP_1C Igt  NA "integer trap greater")
(trap-immed ti lt  I OP_1C Ilt  NA "integer trap less")
(trap-immed ti ge  I OP_1C Ige  NA "integer trap greater or equal")
(trap-immed ti ls  I OP_1C Ils  NA "integer trap less or equal unsigned")
(trap-immed ti hi  I OP_1C Ihi  NA "integer trap greater unsigned")
(trap-immed ti c   I OP_1C Ic   NA "integer trap carry set")
(trap-immed ti nc  I OP_1C Inc  NA "integer trap carry clear")
(trap-immed ti n   I OP_1C In   NA "integer trap negative")
(trap-immed ti p   I OP_1C Ip   NA "integer trap positive")
(trap-immed ti v   I OP_1C Iv   NA "integer trap overflow set")
(trap-immed ti nv  I OP_1C Inv  NA "integer trap overflow clear")

(dni ftira
     "float trap always"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
     "ftira$pack $GRi,$s12"
     (+ pack FCC_ra (ICCi_2-null) OP_1D GRi s12)
     (trap-semantics (const BI 1) GRi s12)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(dni ftino
     "float trap never"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
     "ftino$pack"
     (+ pack FCC_nev (FCCi_2-null) OP_1D (GRi-null) (s12-null))
     (trap-semantics (const BI 0) GRi s12)
     ((fr400 (unit u-trap))
      (fr500 (unit u-trap)))
)

(trap-immed fti ne  F OP_1D Fne  FR-ACCESS "float trap not equal")
(trap-immed fti eq  F OP_1D Feq  FR-ACCESS "float trap equal")
(trap-immed fti lg  F OP_1D Flg  FR-ACCESS "float trap greater or less")
(trap-immed fti ue  F OP_1D Fue  FR-ACCESS "float trap unordered or equal")
(trap-immed fti ul  F OP_1D Ful  FR-ACCESS "float trap unordered or less")
(trap-immed fti ge  F OP_1D Fge  FR-ACCESS "float trap greater or equal")
(trap-immed fti lt  F OP_1D Flt  FR-ACCESS "float trap less")
(trap-immed fti uge F OP_1D Fuge FR-ACCESS "float trap unordered greater or equal")
(trap-immed fti ug  F OP_1D Fug  FR-ACCESS "float trap unordered or greater")
(trap-immed fti le  F OP_1D Fle  FR-ACCESS "float trap less or equal")
(trap-immed fti gt  F OP_1D Fgt  FR-ACCESS "float trap greater")
(trap-immed fti ule F OP_1D Fule FR-ACCESS "float trap unordered less or equal")
(trap-immed fti u   F OP_1D Fu   FR-ACCESS "float trap unordered")
(trap-immed fti o   F OP_1D Fo   FR-ACCESS "float trap ordered")

(dni break
     "break trap"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1))
     "break$pack"
     (+ pack (rd-null) OP_04 (rs-null) (misc-null-3) OPE4_3 (GRj-null))
     (sequence ()
	       ; This is defered to frv_break because for the breakpoint
	       ; case we want to change as little of the machine state as
	       ; possible.
	       ;
	       ; BPCSR=PC
	       ; BPSR.BS=PSR.S
	       ; BPSR.BET=PSR.ET
	       ; PSR.S=1
	       ; PSR.ET=0
	       ; TBR.TT=0xff
	       ; PC=TBR
	       ; We still should indicate what is modified by this insn.
	       (clobber (spr-bpcsr))
	       (clobber bpsr_bs)
	       (clobber bpsr_bet)
	       (clobber psr_s)
	       (clobber psr_et)
	       (clobber tbr_tt)
	       (c-call VOID "frv_break"))
     ()
)

(dni mtrap
     "media trap"
     ((UNIT C) (FR500-MAJOR C-1) (FR400-MAJOR C-1) FR-ACCESS)
     "mtrap$pack"
     (+ pack (rd-null) OP_04 (rs-null) (misc-null-3) OPE4_2 (GRj-null))
     (c-call VOID "frv_mtrap")
     ()
)

(define-pmacro (condition-code-logic name operation ope comment)
  (dni name
       (comment)
       ((UNIT B01) (FR500-MAJOR B-6) (FR400-MAJOR B-6))
       (.str name "$pack $CRi,$CRj,$CRk")
       (+ pack (misc-null-6) CRk OP_0A (misc-null-7) CRi ope (misc-null-8) CRj)
       (set CRk (c-call UQI "@cpu@_cr_logic" operation CRi CRj))
       ()
  )
)
(define-pmacro (op-andcr)   0)
(define-pmacro (op-orcr)    1)
(define-pmacro (op-xorcr)   2)
(define-pmacro (op-nandcr)  3)
(define-pmacro (op-norcr)   4)
(define-pmacro (op-andncr)  5)
(define-pmacro (op-orncr)   6)
(define-pmacro (op-nandncr) 7)
(define-pmacro (op-norncr)  8)

(define-pmacro (cr-true)  3)
(define-pmacro (cr-false) 2)
(define-pmacro (cr-undefined) 0)

(condition-code-logic andcr   (op-andcr)   OPE1_08 "and   condition code regs")
(condition-code-logic orcr    (op-orcr)    OPE1_09 "or    condition code regs")
(condition-code-logic xorcr   (op-xorcr)   OPE1_0A "xor   condition code regs")
(condition-code-logic nandcr  (op-nandcr)  OPE1_0C "nand  condition code regs")
(condition-code-logic norcr   (op-norcr)   OPE1_0D "nor   condition code regs")
(condition-code-logic andncr  (op-andncr)  OPE1_10 "andn  condition code regs")
(condition-code-logic orncr   (op-orncr)   OPE1_11 "orn   condition code regs")
(condition-code-logic nandncr (op-nandncr) OPE1_14 "nandn condition code regs")
(condition-code-logic norncr  (op-norncr)  OPE1_15 "norn  condition code regs")

(dni notcr
     ("not cccr register")
     ((UNIT B01) (FR500-MAJOR B-6) (FR400-MAJOR B-6))
     (.str notcr "$pack $CRj,$CRk")
     (+ pack (misc-null-6) CRk OP_0A (rs-null) OPE1_0B (misc-null-8) CRj)
     (set CRk (xor CRj 1))
     ()
)

(define-pmacro (check-semantics cond cr)
  (if cond (set cr (cr-true)) (set cr (cr-false)))
)

(define-pmacro (check-int-condition-code prefix cc op cond comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
       (.str (.sym prefix cc) "$pack $ICCi_3,$CRj_int")
       (+ pack (.sym ICC_ cc) CRj_int op (misc-null-5) ICCi_3)
       (check-semantics (cond ICCi_3) CRj_int)
       ((fr400 (unit u-check))
	(fr500 (unit u-check)))
  )
)

(dni ckra
     "check integer cc always"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
     "ckra$pack $CRj_int"
     (+ pack ICC_ra CRj_int OP_08 (misc-null-5) (ICCi_3-null))
     (check-semantics (const BI 1) CRj_int)
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(dni ckno
     "check integer cc never"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5))
     "ckno$pack $CRj_int"
     (+ pack ICC_nev CRj_int OP_08 (misc-null-5) (ICCi_3-null))
     (check-semantics (const BI 0) CRj_int)
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(check-int-condition-code ck eq  OP_08 Ieq  "check integer cc equal")
(check-int-condition-code ck ne  OP_08 Ine  "check integer cc not equal")
(check-int-condition-code ck le  OP_08 Ile  "check integer cc less or equal")
(check-int-condition-code ck gt  OP_08 Igt  "check integer cc greater")
(check-int-condition-code ck lt  OP_08 Ilt  "check integer cc less")
(check-int-condition-code ck ge  OP_08 Ige  "check integer cc greater or equal")
(check-int-condition-code ck ls  OP_08 Ils  "check integer cc less or equal unsigned")
(check-int-condition-code ck hi  OP_08 Ihi  "check integer cc greater unsigned")
(check-int-condition-code ck c   OP_08 Ic   "check integer cc carry set")
(check-int-condition-code ck nc  OP_08 Inc  "check integer cc carry clear")
(check-int-condition-code ck n   OP_08 In   "check integer cc negative")
(check-int-condition-code ck p   OP_08 Ip   "check integer cc positive")
(check-int-condition-code ck v   OP_08 Iv   "check integer cc overflow set")
(check-int-condition-code ck nv  OP_08 Inv  "check integer cc overflow clear")

(define-pmacro (check-float-condition-code prefix cc op cond comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
       (.str (.sym prefix cc) "$pack $FCCi_3,$CRj_float")
       (+ pack (.sym FCC_ cc) CRj_float op (misc-null-5) FCCi_3)
       (check-semantics (cond FCCi_3) CRj_float)
       ((fr400 (unit u-check))
	(fr500 (unit u-check)))
  )
)

(dni fckra
     "check float cc always"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
     "fckra$pack $CRj_float"
     (+ pack FCC_ra CRj_float OP_09 (misc-null-5) FCCi_3)
     (check-semantics (const BI 1) CRj_float)
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(dni fckno
     "check float cc never"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) FR-ACCESS)
     "fckno$pack $CRj_float"
     (+ pack FCC_nev CRj_float OP_09 (misc-null-5) FCCi_3)
     (check-semantics (const BI 0) CRj_float)
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(check-float-condition-code fck ne  OP_09 Fne  "check float cc not equal")
(check-float-condition-code fck eq  OP_09 Feq  "check float cc equal")
(check-float-condition-code fck lg  OP_09 Flg  "check float cc greater or less")
(check-float-condition-code fck ue  OP_09 Fue  "check float cc unordered or equal")
(check-float-condition-code fck ul  OP_09 Ful  "check float cc unordered or less")
(check-float-condition-code fck ge  OP_09 Fge  "check float cc greater or equal")
(check-float-condition-code fck lt  OP_09 Flt  "check float cc less")
(check-float-condition-code fck uge OP_09 Fuge "check float cc unordered greater or equal")
(check-float-condition-code fck ug  OP_09 Fug  "check float cc unordered or greater")
(check-float-condition-code fck le  OP_09 Fle  "check float cc less or equal")
(check-float-condition-code fck gt  OP_09 Fgt  "check float cc greater")
(check-float-condition-code fck ule OP_09 Fule "check float cc unordered less or equal")
(check-float-condition-code fck u   OP_09 Fu   "check float cc unordered")
(check-float-condition-code fck o   OP_09 Fo   "check float cc ordered")

(define-pmacro (conditional-check-int-condition-code prefix cc op ope test comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
       (.str (.sym prefix cc) "$pack $ICCi_3,$CRj_int,$CCi,$cond")
       (+ pack (.sym ICC_ cc) CRj_int op (rs-null) CCi cond ope
	  (misc-null-9) ICCi_3)
       (if (eq CCi (or cond 2))
	   (check-semantics (test ICCi_3) CRj_int)
	   (set CRj_int (cr-undefined)))
       ((fr400 (unit u-check))
	(fr500 (unit u-check)))
  )
)

(dni cckra
     "conditional check integer cc always"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
     "cckra$pack $CRj_int,$CCi,$cond"
     (+ pack ICC_ra CRj_int OP_6A (rs-null) CCi cond OPE4_0
	(misc-null-9) (ICCi_3-null))
     (if (eq CCi (or cond 2))
	 (check-semantics (const BI 1) CRj_int)
	 (set CRj_int (cr-undefined)))
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(dni cckno
     "conditional check integer cc never"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL)
     "cckno$pack $CRj_int,$CCi,$cond"
     (+ pack ICC_nev CRj_int OP_6A (rs-null) CCi cond OPE4_0
	(misc-null-9) (ICCi_3-null))
     (if (eq CCi (or cond 2))
	 (check-semantics (const BI 0) CRj_int)
	 (set CRj_int (cr-undefined)))
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(conditional-check-int-condition-code cck eq  OP_6A OPE4_0 Ieq  "check integer cc equal")
(conditional-check-int-condition-code cck ne  OP_6A OPE4_0 Ine  "check integer cc not equal")
(conditional-check-int-condition-code cck le  OP_6A OPE4_0 Ile  "check integer cc less or equal")
(conditional-check-int-condition-code cck gt  OP_6A OPE4_0 Igt  "check integer cc greater")
(conditional-check-int-condition-code cck lt  OP_6A OPE4_0 Ilt  "check integer cc less")
(conditional-check-int-condition-code cck ge  OP_6A OPE4_0 Ige  "check integer cc greater or equal")
(conditional-check-int-condition-code cck ls  OP_6A OPE4_0 Ils  "check integer cc less or equal unsigned")
(conditional-check-int-condition-code cck hi  OP_6A OPE4_0 Ihi  "check integer cc greater unsigned")
(conditional-check-int-condition-code cck c   OP_6A OPE4_0 Ic   "check integer cc carry set")
(conditional-check-int-condition-code cck nc  OP_6A OPE4_0 Inc  "check integer cc carry clear")
(conditional-check-int-condition-code cck n   OP_6A OPE4_0 In   "check integer cc negative")
(conditional-check-int-condition-code cck p   OP_6A OPE4_0 Ip   "check integer cc positive")
(conditional-check-int-condition-code cck v   OP_6A OPE4_0 Iv   "check integer cc overflow set")
(conditional-check-int-condition-code cck nv  OP_6A OPE4_0 Inv  "check integer cc overflow clear")

(define-pmacro (conditional-check-float-condition-code prefix cc op ope test comment)
  (dni (.sym prefix cc)
       (comment)
       ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
       (.str (.sym prefix cc) "$pack $FCCi_3,$CRj_float,$CCi,$cond")
       (+ pack (.sym FCC_ cc) CRj_float op (rs-null) CCi cond ope
	  (misc-null-9) FCCi_3)
       (if (eq CCi (or cond 2))
	   (check-semantics (test FCCi_3) CRj_float)
	   (set CRj_float (cr-undefined)))
       ((fr400 (unit u-check))
	(fr500 (unit u-check)))
  )
)

(dni cfckra
     "conditional check float cc always"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
     "cfckra$pack $CRj_float,$CCi,$cond"
     (+ pack FCC_ra CRj_float OP_6A (rs-null) CCi cond OPE4_1
	(misc-null-9) (FCCi_3-null))
     (if (eq CCi (or cond 2))
	 (check-semantics (const BI 1) CRj_float)
	 (set CRj_float (cr-undefined)))
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(dni cfckno
     "conditional check float cc never"
     ((UNIT B01) (FR500-MAJOR B-5) (FR400-MAJOR B-5) CONDITIONAL FR-ACCESS)
     "cfckno$pack $CRj_float,$CCi,$cond"
     (+ pack FCC_nev CRj_float OP_6A (rs-null) CCi cond OPE4_1
	(misc-null-9) (FCCi_3-null))
     (if (eq CCi (or cond 2))
	 (check-semantics (const BI 0) CRj_float)
	 (set CRj_float (cr-undefined)))
     ((fr400 (unit u-check))
      (fr500 (unit u-check)))
)

(conditional-check-float-condition-code cfck ne  OP_6A OPE4_1 Fne  "check float cc not equal")
(conditional-check-float-condition-code cfck eq  OP_6A OPE4_1 Feq  "check float cc equal")
(conditional-check-float-condition-code cfck lg  OP_6A OPE4_1 Flg  "check float cc greater or less")
(conditional-check-float-condition-code cfck ue  OP_6A OPE4_1 Fue  "check float cc unordered or equal")
(conditional-check-float-condition-code cfck ul  OP_6A OPE4_1 Ful  "check float cc unordered or less")
(conditional-check-float-condition-code cfck ge  OP_6A OPE4_1 Fge  "check float cc greater or equal")
(conditional-check-float-condition-code cfck lt  OP_6A OPE4_1 Flt  "check float cc less")
(conditional-check-float-condition-code cfck uge OP_6A OPE4_1 Fuge "check float cc unordered greater or equal")
(conditional-check-float-condition-code cfck ug  OP_6A OPE4_1 Fug  "check float cc unordered or greater")
(conditional-check-float-condition-code cfck le  OP_6A OPE4_1 Fle  "check float cc less or equal")
(conditional-check-float-condition-code cfck gt  OP_6A OPE4_1 Fgt  "check float cc greater")
(conditional-check-float-condition-code cfck ule OP_6A OPE4_1 Fule "check float cc unordered less or equal")
(conditional-check-float-condition-code cfck u   OP_6A OPE4_1 Fu   "check float cc unordered")
(conditional-check-float-condition-code cfck o   OP_6A OPE4_1 Fo   "check float cc ordered")

(dni cjmpl
     "conditional jump and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5) CONDITIONAL)
     "cjmpl$pack @($GRi,$GRj),$CCi,$cond"
     (+ pack (misc-null-1) (LI-off) OP_6A GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (jump-and-link-semantics GRi GRj LI))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(dni ccalll
     "conditional call and link"
     ((UNIT I0) (FR500-MAJOR I-5) (FR400-MAJOR I-5) CONDITIONAL)
     "ccalll$pack @($GRi,$GRj),$CCi,$cond"
     (+ pack (misc-null-1) (LI-on) OP_6A GRi CCi cond OPE4_2 GRj)
     (if (eq CCi (or cond 2))
	 (jump-and-link-semantics GRi GRj LI))
     ((fr400 (unit u-branch))
      (fr500 (unit u-branch)))
)

(define-pmacro (cache-invalidate name cache all op ope profile comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
       (.str name "$pack @($GRi,$GRj)")
       (+ pack (rd-null) op GRi ope GRj)
       (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) all)
       profile
  )
)

(cache-invalidate ici insn 0 OP_03 OPE1_38
		  ((fr400 (unit u-ici)) (fr500 (unit u-ici)))
		  "invalidate insn cache")
(cache-invalidate dci data 0 OP_03 OPE1_3C
		  ((fr400 (unit u-dci)) (fr500 (unit u-dci)))
		  "invalidate data cache")

(define-pmacro (cache-invalidate-entry name cache op ope profile comment)
  (dni name
       (comment)
       ((UNIT C) (FR400-MAJOR C-2) (MACH fr400))
       (.str name "$pack @($GRi,$GRj),$ae")
       (+ pack (misc-null-1) ae op GRi ope GRj)
       (if (eq ae 0)
	   (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) -1) ; Invalid ae setting for this insn
	   (c-call VOID (.str "@cpu@_" cache "_cache_invalidate") (add GRi GRj) ae))
       profile
  )
)

(cache-invalidate-entry icei insn OP_03 OPE1_39
			((fr400 (unit u-ici)))
			"invalidate insn cache entry")
(cache-invalidate-entry dcei data OP_03 OPE1_3A
			((fr400 (unit u-dci)))
			"invalidate data cache entry")

(dni dcf
     "Data cache flush"
     ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
     "dcf$pack @($GRi,$GRj)"
     (+ pack (rd-null) OP_03 GRi OPE1_3D GRj)
     (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) 0)
     ((fr400 (unit u-dcf))
      (fr500 (unit u-dcf)))
)

(dni dcef
     "Data cache entry flush"
     ((UNIT C) (FR400-MAJOR C-2) (MACH fr400))
     "dcef$pack @($GRi,$GRj),$ae"
     (+ pack (misc-null-1) ae OP_03 GRi OPE1_3B GRj)
     (if (eq ae 0)
	 (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) -1)
	 (c-call VOID "@cpu@_data_cache_flush" (add GRi GRj) ae))
     ((fr400 (unit u-dcf)))
)

(define-pmacro (write-TLB name insn op ope comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (MACH frv) PRIVILEGED)
       (.str insn "$pack $GRk,@($GRi,$GRj)")
       (+ pack GRk op GRi ope GRj)
       (nop) ; for now
       ()
  )
)

(write-TLB witlb witlb OP_03 OPE1_32 "write for insn TLB")
(write-TLB wdtlb wdtlb OP_03 OPE1_36 "write for data TLB")

(define-pmacro (invalidate-TLB name insn op ope comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (MACH frv) PRIVILEGED)
       (.str insn "$pack @($GRi,$GRj)")
       (+ pack (rd-null) op GRi ope GRj)
       (nop) ; for now
       ()
  )
)

(invalidate-TLB itlbi itlbi OP_03 OPE1_33 "invalidate insn TLB")
(invalidate-TLB dtlbi dtlbi OP_03 OPE1_37 "invalidate data TLB")

(define-pmacro (cache-preload name cache op ope profile comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
       (.str name "$pack $GRi,$GRj,$lock")
       (+ pack (misc-null-1) lock op GRi ope GRj)
       (c-call VOID (.str "@cpu@_" cache "_cache_preload") GRi GRj lock)
       profile
  )
)

(cache-preload icpl insn OP_03 OPE1_30
	       ((fr400 (unit u-icpl)) (fr500 (unit u-icpl)))
	       "preload insn cache")
(cache-preload dcpl data OP_03 OPE1_34
	       ((fr400 (unit u-dcpl)) (fr500 (unit u-dcpl)))
	       "preload data cache")

(define-pmacro (cache-unlock name cache op ope profile comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
       (.str name "$pack $GRi")
       (+ pack (rd-null) op GRi ope (GRj-null))
       (c-call VOID (.str "@cpu@_" cache "_cache_unlock") GRi)
       profile
  )
)

(cache-unlock icul insn OP_03 OPE1_31
	      ((fr400 (unit u-icul)) (fr500 (unit u-icul)))
	      "unlock insn cache")
(cache-unlock dcul data OP_03 OPE1_35
	      ((fr400 (unit u-dcul)) (fr500 (unit u-dcul)))
	      "unlock data cache")

(define-pmacro (barrier name insn op ope profile comment)
  (dni name
       (comment)
       ((UNIT C) (FR500-MAJOR C-2) (FR400-MAJOR C-2))
       (.str insn "$pack")
       (+ pack (rd-null) op (rs-null) ope (GRj-null))
       (nop) ; sufficient implementation
       profile
  )
)

(barrier bar    bar    OP_03 OPE1_3E
	 ((fr400 (unit u-barrier)) (fr500 (unit u-barrier)))
	 "barrier")
(barrier membar membar OP_03 OPE1_3F
	 ((fr400 (unit u-membar)) (fr500 (unit u-membar)))
	 "memory barrier")

; Coprocessor operations
(define-pmacro (cop-op num op)
  (dni (.sym cop num)
       "Coprocessor operation"
       ((UNIT C) (FR500-MAJOR C-2) (MACH frv))
       (.str "cop" num "$pack $s6_1,$CPRi,$CPRj,$CPRk")
       (+ pack CPRk op CPRi s6_1 CPRj)
       (nop) ; sufficient implementation
       ()
  )
)

(cop-op 1 OP_7E)
(cop-op 2 OP_7F)

(define-pmacro (clear-ne-flag-semantics target_index is_float)
  (c-call VOID "@cpu@_clear_ne_flags" target_index is_float)
)

(define-pmacro (clear-ne-flag-r name op ope reg is_float attr comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-6) (MACH simple,tomcat,fr500,frv) attr)
       (.str name "$pack $" reg "k")
       (+ pack (.sym reg k) op (rs-null) ope (GRj-null))
       (clear-ne-flag-semantics (index-of (.sym reg k)) is_float)
       ()
  )
)

(clear-ne-flag-r clrgr OP_0A OPE1_00 GR 0 NA        "Clear GR NE flag")
(clear-ne-flag-r clrfr OP_0A OPE1_02 FR 1 FR-ACCESS "Clear FR NE flag")

(define-pmacro (clear-ne-flag-all name op ope is_float attr comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-6) (MACH simple,tomcat,fr500,frv) attr)
       (.str name "$pack")
       (+ pack (rd-null) op (rs-null) ope (GRj-null))
       (clear-ne-flag-semantics -1 is_float)
       ()
  )
)

(clear-ne-flag-all clrga OP_0A OPE1_01 0 NA        "Clear GR NE flag ALL")
(clear-ne-flag-all clrfa OP_0A OPE1_03 1 FR-ACCESS "Clear FR NE flag ALL")

(define-pmacro (commit-semantics target_index is_float)
  (c-call VOID "@cpu@_commit" target_index is_float)
)

(define-pmacro (commit-r name op ope reg is_float attr comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-6) (MACH frv,fr500) attr)
       (.str name "$pack $" reg "k")
       (+ pack (.sym reg k) op (rs-null) ope (GRj-null))
       (commit-semantics (index-of (.sym reg k)) is_float)
       ()
  )
)

(commit-r commitgr OP_0A OPE1_04 GR 0 NA        "commit exceptions, specific GR")
(commit-r commitfr OP_0A OPE1_06 FR 1 FR-ACCESS "commit exceptions, specific FR")

(define-pmacro (commit name op ope is_float attr comment)
  (dni name
       (comment)
       ((UNIT I01) (FR500-MAJOR I-6) (MACH frv,fr500) attr)
       (.str name "$pack")
       (+ pack (rd-null) op (rs-null) ope (GRj-null))
       (commit-semantics -1 is_float)
       ()
  )
)

(commit commitga OP_0A OPE1_05 0 NA        "commit exceptions, any GR")
(commit commitfa OP_0A OPE1_07 1 FR-ACCESS "commit exceptions, any FR")

(define-pmacro (floating-point-conversion
		name op ope conv mode src targ attr comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv) attr)
       (.str name "$pack $" src ",$" targ)
       (+ pack targ op (rs-null) ope src)
       (set targ (conv mode src))
       ((fr500 (unit u-float-convert)))
  )
)

(floating-point-conversion fitos OP_79 OPE1_00 float SF FRintj FRk NA "Convert Integer to Single")
(floating-point-conversion fstoi OP_79 OPE1_01 fix   SI FRj FRintk NA "Convert Single  to Integer")
(floating-point-conversion fitod OP_7A OPE1_00 float DF FRintj FRdoublek (MACH frv) "Convert Integer to Double")
(floating-point-conversion fdtoi OP_7A OPE1_01 fix   SI FRdoublej FRintk (MACH frv) "Convert Double to Integer")

(define-pmacro (floating-point-dual-conversion
		name op ope conv mode src src_hw targ targ_hw attr comment)
  (dni name
       (comment)
       ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1) attr)
       (.str name "$pack $" src ",$" targ)
       (+ pack targ op (rs-null) ope src)
       (sequence ()
		 (set targ (conv mode src))
		 (set (nextreg targ_hw targ 1)
		      (conv mode (nextreg src_hw src 1))))
       ((fr500 (unit u-float-dual-convert)))
  )
)

(floating-point-dual-conversion fditos OP_79 OPE1_10 float SF FRintj h-fr_int FRk h-fr NA "Dual Convert Integer to Single")
(floating-point-dual-conversion fdstoi OP_79 OPE1_11 fix   SI FRj h-fr FRintk h-fr_int NA "Dual Convert Single  to Integer")

(define-pmacro (ne-floating-point-dual-conversion
		name op ope conv mode src src_hw targ targ_hw attr comment)
  (dni name
       (comment)
       ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1) NON-EXCEPTING attr)
       (.str name "$pack $" src ",$" targ)
       (+ pack targ op (rs-null) ope src)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of targ))
		 (set targ (conv mode src))
		 (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 1))
		 (set (nextreg targ_hw targ 1)
		      (conv mode (nextreg src_hw src 1))))
       ((fr500 (unit u-float-dual-convert)))
  )
)

(ne-floating-point-dual-conversion nfditos OP_79 OPE1_30 float SF FRintj h-fr_int FRk h-fr NA "Non excepting dual Convert Integer to Single")
(ne-floating-point-dual-conversion nfdstoi OP_79 OPE1_31 fix   SI FRj h-fr FRintk h-fr_int NA "Non excepting dual Convert Single  to Integer")

(define-pmacro (conditional-floating-point-conversion
		name op ope conv mode src targ comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $" src ",$" targ ",$CCi,$cond")
       (+ pack targ op (rs-null) CCi cond ope src)
       (if (eq CCi (or cond 2))
	   (set targ (conv mode src)))
       ((fr500 (unit u-float-convert)))
  )
)

(conditional-floating-point-conversion cfitos OP_6B OPE4_0 float SF FRintj FRk "Conditional convert Integer to Single")
(conditional-floating-point-conversion cfstoi OP_6B OPE4_1 fix   SI FRj FRintk "Conditional convert Single to Integer")

(define-pmacro (ne-floating-point-conversion 
		name op ope conv mode src targ comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $" src ",$" targ)
       (+ pack targ op (rs-null) ope src)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of targ))
		 (set targ (conv mode src)))
       ((fr500 (unit u-float-convert)))
  )
)

(ne-floating-point-conversion nfitos OP_79 OPE1_20 float SF FRintj FRk "NE convert Integer to Single")
(ne-floating-point-conversion nfstoi OP_79 OPE1_21 fix   SI FRj FRintk "NE convert Single to Integer")

(register-transfer fmovs OP_79 OPE1_02
		   FRj FRk FM01 (FR500-MAJOR F-1) NA
		   (MACH simple,tomcat,fr500,frv) NA
		   ((fr500 (unit u-fr2fr)))
		   "Move Single Float")
(register-transfer fmovd OP_7A OPE1_02
		   ; TODO -- unit doesn't handle extra register
		   FRdoublej FRdoublek FM01 (FR500-MAJOR F-1) NA
		   (MACH frv) NA
		   ((fr500 (unit u-fr2fr)))
		   "Move Double Float")

(dni fdmovs
     "Dual move single float"
     ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
     "fdmovs$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_12 FRj)
     (sequence ()
	       (set FRk FRj)
	       (set (nextreg h-fr FRk 1) (nextreg h-fr FRj 1)))
     ; TODO -- unit doesn't handle extra register
     ((fr500 (unit u-fr2fr)))
)

(conditional-register-transfer cfmovs OP_6C OPE4_0 FRj FRk FM01
			       (FR500-MAJOR F-1) NA
			       (MACH simple,tomcat,fr500,frv)
			       ((fr500 (unit u-fr2fr)))
			       "Conditional move Single Float")

(define-pmacro (floating-point-neg name src targ op ope attr comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-1) attr)
       (.str name "$pack $" src ",$" targ)
       (+ pack src op (rs-null) ope targ)
       (set targ (neg src))
       ((fr500 (unit u-float-arith)))
  )
)

(floating-point-neg fnegs FRj FRk OP_79 OPE1_03 (MACH simple,tomcat,fr500,frv) "Floating point negate, single")
(floating-point-neg fnegd FRdoublej FRdoublek OP_7A OPE1_03 (MACH frv) "Floating point negate, double")

(dni fdnegs
     "Floating point dual negate, single"
     ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
     "fdnegs$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_13 FRj)
     (sequence ()
	       (set FRk (neg FRj))
	       (set (nextreg h-fr FRk 1) (neg (nextreg h-fr FRj 1))))
     ((fr500 (unit u-float-dual-arith)))
)

(dni cfnegs
     "Conditional floating point negate, single"
     ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
     "cfnegs$pack $FRj,$FRk,$CCi,$cond"
     (+ pack FRj OP_6C (rs-null) CCi cond OPE4_1 FRk)
     (if (eq CCi (or cond 2))
	 (set FRk (neg FRj)))
     ((fr500 (unit u-float-arith)))
)

(define-pmacro (float-abs name src targ op ope attr comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-1) attr)
       (.str name "$pack $" src ",$" targ )
       (+ pack targ op (rs-null) ope src)
       (set targ (abs src))
       ((fr500 (unit u-float-arith)))
  )
)

(float-abs fabss FRj FRk OP_79 OPE1_04 (MACH simple,tomcat,fr500,frv) "Float absolute value, single")
(float-abs fabsd FRdoublej FRdoublek OP_7A OPE1_04 (MACH frv) "Float absolute value, double")

(dni fdabss
     "Floating point dual absolute value, single"
     ((MACH frv) (UNIT FM01) (FR500-MAJOR F-1))
     "fdabss$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_14 FRj)
     (sequence ()
	       (set FRk (abs FRj))
	       (set (nextreg h-fr FRk 1) (abs (nextreg h-fr FRj 1))))
     ((fr500 (unit u-float-dual-arith)))
)

(dni cfabss
     "Conditional floating point absolute value, single"
     ((UNIT FM01) (FR500-MAJOR F-1) (MACH simple,tomcat,fr500,frv))
     "cfabss$pack $FRj,$FRk,$CCi,$cond"
     (+ pack FRj OP_6C (rs-null) CCi cond OPE4_2 FRk)
     (if (eq CCi (or cond 2))
	 (set FRk (abs FRj)))
     ((fr500 (unit u-float-arith)))
)

(dni fsqrts
     "Square root single"
     ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
     "fsqrts$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_05 FRj)
     (set FRk (sqrt SF FRj))
     ((fr500 (unit u-float-sqrt)))
)

(dni fdsqrts
     "Dual square root single"
     ((MACH frv) (UNIT FM01) (FR500-MAJOR F-4))
     "fdsqrts$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_15 FRj)
     (sequence ()
	       (set FRk (sqrt SF FRj))
	       (set (nextreg h-fr FRk 1) (sqrt (nextreg h-fr FRj 1))))
     ((fr500 (unit u-float-dual-sqrt)))
)

(dni nfdsqrts
     "Non excepting Dual square root single"
     ((MACH frv) (UNIT FM01) (FR500-MAJOR F-4) NON-EXCEPTING)
     "nfdsqrts$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_35 FRj)
     (sequence ()
	       (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
	       (set FRk (sqrt SF FRj))
	       (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
	       (set (nextreg h-fr FRk 1) (sqrt (nextreg h-fr FRj 1))))
     ((fr500 (unit u-float-dual-sqrt)))
)

(dni fsqrtd
     "Square root double"
     ((UNIT FM01) (FR500-MAJOR F-4) (MACH frv))
     "fsqrtd$pack $FRdoublej,$FRdoublek"
     (+ pack FRdoublek OP_7A (rs-null) OPE1_05 FRdoublej)
     (set FRdoublek (sqrt DF FRdoublej))
     ((fr500 (unit u-float-sqrt)))
)

(dni cfsqrts
     "Conditional square root single"
     ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
     "cfsqrts$pack $FRj,$FRk,$CCi,$cond"
     (+ pack FRk OP_6E (rs-null) CCi cond OPE4_2 FRj)
     (if (eq CCi (or cond 2))
	 (set FRk (sqrt SF FRj)))
     ((fr500 (unit u-float-sqrt)))
)

(dni nfsqrts
     "Non exception square root, single"
     ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
     "nfsqrts$pack $FRj,$FRk"
     (+ pack FRk OP_79 (rs-null) OPE1_25 FRj)
     (sequence ()
	       (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
	       (set FRk (sqrt SF FRj)))
     ((fr500 (unit u-float-sqrt)))
)

(define-pmacro (float-binary-op-s name operation op ope major comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi ope FRj)
       (set FRk (operation FRi FRj))
       ((fr500 (unit u-float-arith)))
  )
)

(float-binary-op-s fadds add OP_79 OPE1_06 F-2 "add single float")
(float-binary-op-s fsubs sub OP_79 OPE1_07 F-2 "sub single float")
(float-binary-op-s fmuls mul OP_79 OPE1_08 F-3 "mul single float")

(dni fdivs
     "div single float"
     ((UNIT FM01) (FR500-MAJOR F-4) (MACH simple,tomcat,fr500,frv))
     "fdivs$pack $FRi,$FRj,$FRk"
     (+ pack FRk OP_79 FRi OPE1_09 FRj)
     (set FRk (div FRi FRj))
     ((fr500 (unit u-float-div)))
)

(define-pmacro (float-binary-op-d name operation op ope major comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) (MACH frv))
       (.str name "$pack $FRdoublei,$FRdoublej,$FRdoublek")
       (+ pack FRdoublek op FRdoublei ope FRdoublej)
       (set FRdoublek (operation FRdoublei FRdoublej))
       ((fr500 (unit u-float-arith)))
  )
)

(float-binary-op-d faddd add OP_7A OPE1_06 F-2 "add double float")
(float-binary-op-d fsubd sub OP_7A OPE1_07 F-2 "sub double float")
(float-binary-op-d fmuld mul OP_7A OPE1_08 F-3 "mul double float")
(float-binary-op-d fdivd div OP_7A OPE1_09 F-4 "div double float")

(define-pmacro (conditional-float-binary-op name operation op ope major comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
       (+ pack FRk op FRi CCi cond ope FRj)
       (if (eq CCi (or cond 2))
	   (set FRk (operation FRi FRj)))
       ((fr500 (unit u-float-arith)))
  )
)

(conditional-float-binary-op cfadds add OP_6D OPE4_0 F-2 "cond add single")
(conditional-float-binary-op cfsubs sub OP_6D OPE4_1 F-2 "cond sub single")
(conditional-float-binary-op cfmuls mul OP_6E OPE4_0 F-3 "cond mul single")
(conditional-float-binary-op cfdivs div OP_6E OPE4_1 F-4 "cond div single")

(define-pmacro (ne-float-binary-op name operation op ope major comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi ope FRj)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
		 (set FRk (operation FRi FRj)))
       ((fr500 (unit u-float-arith)))
  )
)

(ne-float-binary-op nfadds add OP_79 OPE1_26 F-2 "ne add single")
(ne-float-binary-op nfsubs sub OP_79 OPE1_27 F-2 "ne sub single")
(ne-float-binary-op nfmuls mul OP_79 OPE1_28 F-3 "ne mul single")
(ne-float-binary-op nfdivs div OP_79 OPE1_29 F-4 "ne div single")

(define-pmacro (fcc-eq) 8)
(define-pmacro (fcc-lt) 4)
(define-pmacro (fcc-gt) 2)
(define-pmacro (fcc-uo) 1)

(define-pmacro (compare-and-set-fcc arg1 arg2 fcc)
  (if (gt arg1 arg2)
      (set fcc (fcc-gt))
      (if (eq arg1 arg2)
	  (set fcc (fcc-eq))
	  (if (lt arg1 arg2)
	      (set fcc (fcc-lt))
	      (set fcc (fcc-uo)))))
)

(dni fcmps
     "compare single float"
     ((UNIT FM01) (FR500-MAJOR F-2) (MACH simple,tomcat,fr500,frv))
     "fcmps$pack $FRi,$FRj,$FCCi_2"
     (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_0A FRj)
     (compare-and-set-fcc FRi FRj FCCi_2)
     ((fr500 (unit u-float-compare)))
)

(dni fcmpd
     "compare double float"
     ((UNIT FM01) (FR500-MAJOR F-2) (MACH frv))
     "fcmpd$pack $FRdoublei,$FRdoublej,$FCCi_2"
     (+ pack (cond-null) FCCi_2 OP_7A FRdoublei OPE1_0A FRdoublej)
     (compare-and-set-fcc FRdoublei FRdoublej FCCi_2)
     ((fr500 (unit u-float-compare)))
)

(dni cfcmps
     "Conditional compare single, float"
     ((UNIT FM01) (FR500-MAJOR F-2) (MACH simple,tomcat,fr500,frv))
     "cfcmps$pack $FRi,$FRj,$FCCi_2,$CCi,$cond"
     (+ pack (cond-null) FCCi_2 OP_6D FRi CCi cond OPE4_2 FRj)
     (if (eq CCi (or cond 2))
	 (compare-and-set-fcc FRi FRj FCCi_2))
     ((fr500 (unit u-float-compare)))
)

(dni fdcmps
     "float dual compare single"
     ((UNIT FM01) (FR500-MAJOR F-6) (MACH simple,tomcat,fr500,frv))
     "fdcmps$pack $FRi,$FRj,$FCCi_2"
     (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_1A FRj)
     (sequence ()
	       (compare-and-set-fcc FRi FRj FCCi_2)
	       (compare-and-set-fcc (nextreg h-fr FRi 1) (nextreg h-fr FRj 1)
				    (nextreg h-fccr FCCi_2 1)))
     ((fr500 (unit u-float-dual-compare)))
)

(define-pmacro (float-mul-with-add name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (set targ (add_sub (mul arg1 arg2) targ))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(float-mul-with-add fmadds add FRi FRj FRk OP_79 OPE1_0B "mul with add, single")
(float-mul-with-add fmsubs sub FRi FRj FRk OP_79 OPE1_0C "mul with sub, single")

(float-mul-with-add fmaddd add FRdoublei FRdoublej FRdoublek OP_7A OPE1_0B "mul with add, double")
(float-mul-with-add fmsubd sub FRdoublei FRdoublej FRdoublek OP_7A OPE1_0C "mul with sub, double")

(dni fdmadds
     "Float dual multiply with add"
     ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
     "fdmadds$pack $FRi,$FRj,$FRk"
     (+ pack FRk OP_79 FRi OPE1_1B FRj)
     (sequence ()
	       (set FRk (add (mul FRi FRj) FRk))
	       (set (nextreg h-fr FRk 1)
		    (add (mul (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))
			 (nextreg h-fr FRk 1))))
     ; TODO dual registers not referenced for profiling
     ((fr500 (unit u-float-dual-arith)))
)

(dni nfdmadds
     "Non excepting float dual multiply with add"
     ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
     "nfdmadds$pack $FRi,$FRj,$FRk"
     (+ pack FRk OP_79 FRi OPE1_3B FRj)
     (sequence ()
	       (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
	       (set FRk (add (mul FRi FRj) FRk))
	       (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
	       (set (nextreg h-fr FRk 1)
		    (add (mul (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))
			 (nextreg h-fr FRk 1))))
     ; TODO dual registers not referenced for profiling
     ((fr500 (unit u-float-dual-arith)))
)

(define-pmacro (conditional-float-mul-with-add
		name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv) CONDITIONAL)
       (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
       (+ pack FRk op FRi CCi cond ope FRj)
       (if (eq CCi (or cond 2))
	   (set targ (add_sub (mul arg1 arg2) targ)))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(conditional-float-mul-with-add cfmadds add FRi FRj FRk OP_6F OPE4_0 "conditional mul with add, single")
(conditional-float-mul-with-add cfmsubs sub FRi FRj FRk OP_6F OPE4_1 "conditional mul with sub, single")

(define-pmacro (ne-float-mul-with-add name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv) NON-EXCEPTING)
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of targ))
		 (set targ (add_sub (mul arg1 arg2) targ)))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(ne-float-mul-with-add nfmadds add FRi FRj FRk OP_79 OPE1_2B "non excepting mul with add, single")
(ne-float-mul-with-add nfmsubs sub FRi FRj FRk OP_79 OPE1_2C "non excepting mul with sub, single")

(define-pmacro (float-parallel-mul-add-semantics cond add_sub arg1 arg2 targ)
  (if cond
      (sequence ()
		(set targ (mul arg1 arg2))
		(set (nextreg h-fr targ 1)
		     (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))))
)

(define-pmacro (float-parallel-mul-add
		name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (float-parallel-mul-add-semantics 1 add_sub arg1 arg2 targ)
       ((fr500 (unit u-float-dual-arith)))
  )
)

(float-parallel-mul-add fmas add FRi FRj FRk OP_79 OPE1_0E "parallel mul/add, single")
(float-parallel-mul-add fmss sub FRi FRj FRk OP_79 OPE1_0F "parallel mul/sub, single")

(define-pmacro (float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
  (sequence ()
	    (set targ (mul arg1 arg2))
	    (set (nextreg h-fr targ 1)
		 (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))
	    (set (nextreg h-fr targ 2)
		 (mul (nextreg h-fr arg1 2)	(nextreg h-fr arg2 2)))
	    (set (nextreg h-fr targ 3)
		 (add_sub (nextreg h-fr arg1 3) (nextreg h-fr arg2 3))))
)

(define-pmacro (float-dual-parallel-mul-add
		name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
       ()
  )
)

(float-dual-parallel-mul-add fdmas add FRi FRj FRk OP_79 OPE1_1C "dual parallel mul/add, single")
(float-dual-parallel-mul-add fdmss sub FRi FRj FRk OP_79 OPE1_1D "dual parallel mul/sub, single")

(define-pmacro (ne-float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
  (sequence ()
	    (c-call VOID "@cpu@_set_ne_index" (index-of targ))
	    (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 1))
	    (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 2))
	    (c-call VOID "@cpu@_set_ne_index" (add (index-of targ) 3))
	    (set targ (mul arg1 arg2))
	    (set (nextreg h-fr targ 1)
		 (add_sub (nextreg h-fr arg1 1) (nextreg h-fr arg2 1)))
	    (set (nextreg h-fr targ 2)
		 (mul (nextreg h-fr arg1 2)	(nextreg h-fr arg2 2)))
	    (set (nextreg h-fr targ 3)
		 (add_sub (nextreg h-fr arg1 3) (nextreg h-fr arg2 3))))
)

(define-pmacro (ne-float-dual-parallel-mul-add
		name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (ne-float-dual-parallel-mul-add-semantics add_sub arg1 arg2 targ)
       ()
  )
)

(ne-float-dual-parallel-mul-add nfdmas add FRi FRj FRk OP_79 OPE1_3C "non excepting dual parallel mul/add, single")
(ne-float-dual-parallel-mul-add nfdmss sub FRi FRj FRk OP_79 OPE1_3D "non excepting dual parallel mul/sub, single")

(define-pmacro (conditional-float-parallel-mul-add name add_sub op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) CONDITIONAL (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $FRi,$FRj,$FRk,$CCi,$cond")
       (+ pack FRk op FRi CCi cond ope FRj)
       (float-parallel-mul-add-semantics (eq CCi (or cond 2))
					 add_sub FRi FRj FRk)
       ((fr500 (unit u-float-dual-arith)))
  )
)

(conditional-float-parallel-mul-add cfmas add OP_6F OPE4_2 "conditional parallel mul/add, single")
(conditional-float-parallel-mul-add cfmss sub OP_6F OPE4_3 "conditional parallel mul/sub, single")

(define-pmacro (float-parallel-mul-add-double-semantics add_sub arg1 arg2 targ)
  (sequence ()
	    (set targ (ftrunc SF (mul DF (fext DF arg1) (fext DF arg2))))
	    (set (nextreg h-fr targ 1)
		 (ftrunc SF (add_sub DF
				     (fext DF (nextreg h-fr arg1 1))
				     (fext DF (nextreg h-fr arg2 1))))))
)

(define-pmacro (float-parallel-mul-add-double
		name add_sub arg1 arg2 targ op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH frv))
       (.str name "$pack $" arg1 ",$" arg2 ",$" targ)
       (+ pack targ op arg1 ope arg2)
       (float-parallel-mul-add-double-semantics add_sub arg1 arg2 targ)
       ()
  )
)

(float-parallel-mul-add-double fmad add FRi FRj FRk OP_7A OPE1_0E "parallel mul/add, double")
(float-parallel-mul-add-double fmsd sub FRi FRj FRk OP_7A OPE1_0F "parallel mul/sub, double")

(define-pmacro (ne-float-parallel-mul-add name add_sub op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR F-5) (MACH simple,tomcat,fr500,frv))
       (.str name "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi ope FRj)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
		 (set FRk (mul FRi FRj))
		 (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
		 (set (nextreg h-fr FRk 1)
		      (add_sub (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(ne-float-parallel-mul-add nfmas add OP_79 OPE1_2E "ne parallel mul/add,single")
(ne-float-parallel-mul-add nfmss sub OP_79 OPE1_2F "ne parallel mul/sub,single")

(define-pmacro (float-dual-arith name major oper1 oper2 op ope attr comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) attr)
       (.str name "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi ope FRj)
       (sequence ()
		 (set FRk (oper1 FRi FRj))
		 (set (nextreg h-fr FRk 1)
		      (oper2 (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(float-dual-arith fdadds F-6 add add OP_79 OPE1_16 (MACH simple,tomcat,fr500,frv) "dual add, single")
(float-dual-arith fdsubs F-6 sub sub OP_79 OPE1_17 (MACH simple,tomcat,fr500,frv) "dual sub, single")
(float-dual-arith fdmuls F-7 mul mul OP_79 OPE1_18 (MACH simple,tomcat,fr500,frv) "dual mul, single")
(float-dual-arith fddivs F-7 div div OP_79 OPE1_19 (MACH frv) "dual div,single")
(float-dual-arith fdsads F-6 add sub OP_79 OPE1_1E (MACH simple,tomcat,fr500,frv) "dual add/sub, single")

(dni fdmulcs
     "Float dual cross multiply single"
     ((UNIT FM01) (FR500-MAJOR F-7) (MACH simple,tomcat,fr500,frv))
     "fdmulcs$pack $FRi,$FRj,$FRk"
     (+ pack FRk OP_79 FRi OPE1_1F FRj)
     (sequence ()
	       (set FRk (mul FRi (nextreg h-fr FRj 1)))
	       (set (nextreg h-fr FRk 1) (mul (nextreg h-fr FRi 1) FRj)))
     ((fr500 (unit u-float-dual-arith)))
)

(dni nfdmulcs
     "NE float dual cross multiply single"
     ((UNIT FM01) (FR500-MAJOR F-7) (MACH simple,tomcat,fr500,frv))
     "nfdmulcs$pack $FRi,$FRj,$FRk"
     (+ pack FRk OP_79 FRi OPE1_3F FRj)
     (sequence ()
	       (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
	       (set FRk (mul FRi (nextreg h-fr FRj 1)))
	       (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
	       (set (nextreg h-fr FRk 1) (mul (nextreg h-fr FRi 1) FRj)))
     ((fr500 (unit u-float-dual-arith)))
)

(define-pmacro (ne-float-dual-arith name major oper1 oper2 op ope attr comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR major) attr)
       (.str name "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi ope FRj)
       (sequence ()
		 (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
		 (set FRk (oper1 FRi FRj))
		 (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
		 (set (nextreg h-fr FRk 1)
		      (oper2 (nextreg h-fr FRi 1) (nextreg h-fr FRj 1))))
       ((fr500 (unit u-float-dual-arith)))
  )
)

(ne-float-dual-arith nfdadds F-6 add add OP_79 OPE1_36 (MACH simple,tomcat,fr500,frv) "ne dual add, single")
(ne-float-dual-arith nfdsubs F-6 sub sub OP_79 OPE1_37 (MACH simple,tomcat,fr500,frv) "ne dual sub, single")
(ne-float-dual-arith nfdmuls F-7 mul mul OP_79 OPE1_38 (MACH simple,tomcat,fr500,frv) "ne dual mul, single")
(ne-float-dual-arith nfddivs F-7 div div OP_79 OPE1_39 (MACH frv) "ne dual div,single")
(ne-float-dual-arith nfdsads F-6 add sub OP_79 OPE1_3E (MACH simple,tomcat,fr500,frv) "ne dual add/sub, single")

(dni nfdcmps
     "non-excepting dual float compare"
     ((UNIT FM01) (FR500-MAJOR F-6) (MACH simple,tomcat,frv))
     "nfdcmps$pack $FRi,$FRj,$FCCi_2"
     (+ pack (cond-null) FCCi_2 OP_79 FRi OPE1_3A FRj)
     (sequence ()
	       (c-call VOID "@cpu@_set_ne_index" (index-of FRk))
	       (compare-and-set-fcc FRi FRj FCCi_2)
	       (c-call VOID "@cpu@_set_ne_index" (add (index-of FRk) 1))
	       (compare-and-set-fcc (nextreg h-fr FRi 1) (nextreg h-fr FRj 1)
				    (nextreg h-fccr FCCi_2 1)))
     ((fr500 (unit u-float-dual-compare)))
)

; Media Instructions
;
(define-pmacro (halfword hilo arg offset)
  (reg (.sym h-fr_ hilo) (add (index-of arg) offset)))

(dni mhsetlos
     "Media set lower signed 12 bits"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mhsetlos$pack $u12,$FRklo"
     (+ pack FRklo OP_78 OPE1_20 u12)
     (set FRklo u12)
     ((fr400 (unit u-media-hilo)))
)

(dni mhsethis
     "Media set upper signed 12 bits"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mhsethis$pack $u12,$FRkhi"
     (+ pack FRkhi OP_78 OPE1_22 u12)
     (set FRkhi u12)
     ((fr400 (unit u-media-hilo)))
)

(dni mhdsets
     "Media dual set halfword signed 12 bits"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mhdsets$pack $u12,$FRintk"
     (+ pack FRintk OP_78 OPE1_24 u12)
     (sequence ()
	       ; hack to get FRintk passed to modelling functions
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (set (halfword hi FRintk 0) u12)
	       (set (halfword lo FRintk 0) u12))
     ((fr400 (unit u-media-1)))
)

(define-pmacro (set-5-semantics target value)
  (sequence ((HI tmp))
	    (set tmp target)
	    (set tmp (and tmp #x07ff))
	    (set tmp (or tmp (sll (and s5 #x1f) 11)))
	    (set target tmp))
)

(define-pmacro (media-set-5 name hilo op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
       (.str name "$pack $s5,$FRk" hilo)
       (+ pack (.sym FRk hilo) op (FRi-null) ope (misc-null-11) s5)
       (set-5-semantics (.sym FRk hilo) s5)
       ((fr400 (unit u-media-hilo)))
  )
)

(media-set-5 mhsetloh lo OP_78 OPE1_21 "Media set upper 5 bits lo")
(media-set-5 mhsethih hi OP_78 OPE1_23 "Media set upper 5 bits hi")

(dni mhdseth
     "Media dual set halfword upper 5 bits"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mhdseth$pack $s5,$FRintk"
     (+ pack FRintk OP_78 (FRi-null) OPE1_25 (misc-null-11) s5)
     (sequence ()
	       ; hack to get FRintk passed to modelling functions
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (set-5-semantics (halfword hi FRintk 0) s5)
	       (set-5-semantics (halfword lo FRintk 0) s5))
     ((fr400 (unit u-media-1)))
)

(define-pmacro (media-logic-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$FRintk")
       (+ pack FRintk op FRinti ope FRintj)
       (set FRintk (operation FRinti FRintj))
       ((fr400 (unit u-media-1))
	(fr500 (unit u-media)))
  )
)

(media-logic-r-r mand and OP_7B OPE1_00 "and reg/reg")
(media-logic-r-r mor  or  OP_7B OPE1_01 "or  reg/reg")
(media-logic-r-r mxor xor OP_7B OPE1_02 "xor reg/reg")

(define-pmacro (conditional-media-logic name operation op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$FRintk,$CCi,$cond")
       (+ pack FRintk op FRinti CCi cond ope FRintj)
       (if (eq CCi (or cond 2))
	   (set FRintk (operation FRinti FRintj)))
       ((fr400 (unit u-media-1))
	(fr500 (unit u-media)))
  )
)

(conditional-media-logic cmand and OP_70 OPE4_0 "conditional and reg/reg")
(conditional-media-logic cmor  or  OP_70 OPE4_1 "conditional or  reg/reg")
(conditional-media-logic cmxor xor OP_70 OPE4_2 "conditional xor reg/reg")

(dni mnot
     ("mnot")
     ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
     ("mnot$pack $FRintj,$FRintk")
     (+ pack FRintk OP_7B (rs-null) OPE1_03 FRintj)
     (set FRintk (inv FRintj))
     ((fr400 (unit u-media-1))
      (fr500 (unit u-media)))
)

(dni cmnot
     ("cmnot")
     ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
     ("cmnot$pack $FRintj,$FRintk,$CCi,$cond")
     (+ pack FRintk OP_70 (rs-null) CCi cond OPE4_3 FRintj)
     (if (eq CCi (or cond 2))
	 (set FRintk (inv FRintj)))
     ((fr400 (unit u-media-1))
      (fr500 (unit u-media)))
)

(define-pmacro (media-rotate-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$u6,$FRintk")
       (+ pack FRintk op FRinti ope u6)
       (set FRintk (operation FRinti (and u6 #x1f)))
       ((fr400 (unit u-media-3))
	(fr500 (unit u-media)))
  )
)

(media-rotate-r-r mrotli rol OP_7B OPE1_04 "rotate left reg/reg")
(media-rotate-r-r mrotri ror OP_7B OPE1_05 "rotate right reg/reg")

(define-pmacro (media-cut-r-r name arg op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
       (.str name "$pack $FRinti,$" arg ",$FRintk")
       (+ pack FRintk op FRinti ope arg)
       (set FRintk (c-call SI "@cpu@_cut" FRinti (nextreg h-fr_int FRinti 1) arg))
       ((fr400 (unit u-media-3))
	(fr500 (unit u-media)))
  )
)

(media-cut-r-r mwcut  FRintj OP_7B OPE1_06 "media cut")
(media-cut-r-r mwcuti u6     OP_7B OPE1_07 "media cut")

(define-pmacro (media-cut-acc name arg op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
       (.str name "$pack $ACC40Si,$" arg ",$FRintk")
       (+ pack FRintk op ACC40Si ope arg)
       (set FRintk (c-call SI "@cpu@_media_cut" ACC40Si arg))
       ((fr400 (unit u-media-4))
	(fr500 (unit u-media)))
  )
)

(media-cut-acc mcut  FRintj OP_7B OPE1_2C "media accumulator cut reg")
(media-cut-acc mcuti s6     OP_7B OPE1_2E "media accumulator cut immed")

(define-pmacro (media-cut-acc-ss name arg op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
       (.str name "$pack $ACC40Si,$" arg ",$FRintk")
       (+ pack FRintk op ACC40Si ope arg)
       (set FRintk (c-call SI "@cpu@_media_cut_ss" ACC40Si arg))
       ((fr400 (unit u-media-4))
	(fr500 (unit u-media)))
  )
)

(media-cut-acc-ss mcutss  FRintj OP_7B OPE1_2D "media accumulator cut reg with saturation")
(media-cut-acc-ss mcutssi s6     OP_7B OPE1_2F "media accumulator cut immed with saturation")

; Dual Media Instructions
;
(define-pmacro (register-unaligned register alignment)
  (and (index-of register) (sub alignment 1))
)

(dni mdcutssi
     "Media dual cut with signed saturation"
     ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
     "mdcutssi$pack $ACC40Si,$s6,$FRintkeven"
     (+ pack FRintkeven OP_78 ACC40Si OPE1_0E s6)
     (if (register-unaligned ACC40Si 2)
	 (c-call VOID "@cpu@_media_acc_not_aligned")
	 (if (register-unaligned FRintkeven 2)
	     (c-call VOID "@cpu@_media_register_not_aligned")
	     (sequence ()
		       (set FRintkeven (c-call SI "@cpu@_media_cut_ss" ACC40Si s6))
		       (set (nextreg h-fr_int FRintkeven 1)
			    (c-call SI "@cpu@_media_cut_ss"
				    (nextreg h-acc40S ACC40Si 1) s6)))))
     ((fr400 (unit u-media-4-acc-dual
		   (out FRintk FRintkeven))))
)

; The (add (xxxx) (mul arg 0)) is a hack to get a reference to arg generated
; so it will be passed to the unit modelers.   YUCK!!!!!
(define-pmacro (extract-hilo reg1 off1 reg2 off2 arg1hi arg1lo arg2hi arg2lo)
  (sequence ()
	    (set arg1hi (add (halfword hi reg1 off1) (mul reg1 0)))
	    (set arg1lo (add (halfword lo reg1 off1) (mul reg1 0)))
	    (set arg2hi (add (halfword hi reg2 off2) (mul reg2 0)))
	    (set arg2lo (add (halfword lo reg2 off2) (mul reg2 0))))
)

(dni maveh
     "Media dual average"
     ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
     "maveh$pack $FRinti,$FRintj,$FRintk"
     (+ pack FRintk OP_7B FRinti OPE1_08 FRintj)
     (set FRintk (c-call SI "@cpu@_media_average" FRinti FRintj))
     ((fr400 (unit u-media-1))
      (fr500 (unit u-media)))
)

(define-pmacro (media-dual-shift name operation op ope profile comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$u6,$FRintk")
       (+ pack FRintk op FRinti ope u6)
       (sequence ()
		 ; hack to get these referenced for profiling
		 (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
		 (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
		 (set (halfword hi FRintk 0)
		      (operation (halfword hi FRinti 0) (and u6 #xf)))
		 (set (halfword lo FRintk 0)
		      (operation (halfword lo FRinti 0) (and u6 #xf))))
       profile
  )
)

(media-dual-shift msllhi sll OP_7B OPE1_09
		  ((fr400 (unit u-media-3)) (fr500 (unit u-media)))
		  "Media dual shift left  logical")
(media-dual-shift msrlhi srl OP_7B OPE1_0A
		  ((fr400 (unit u-media-3)) (fr500 (unit u-media)))
		  "Media dual shift right logical")
(media-dual-shift msrahi sra OP_7B OPE1_0B
		  ((fr400 (unit u-media-6)) (fr500 (unit u-media)))
		  "Media dual shift right arithmetic")

(define-pmacro (media-dual-word-rotate-r-r name operation op ope comment)
  (dni name
       (comment)
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$s6,$FRintkeven")
       (+ pack FRintkeven op FRintieven ope s6)
       (if (orif (register-unaligned FRintieven 2)
		 (register-unaligned FRintkeven 2))
	   (c-call VOID "@cpu@_media_register_not_aligned")
	   (sequence ()
		     (set FRintkeven (operation FRintieven (and s6 #x1f)))
		     (set (nextreg h-fr_int FRintkeven 1)
			  (operation (nextreg h-fr_int FRintieven 1)
				     (and s6 #x1f)))))
       ((fr400 (unit u-media-3-quad
		     (in  FRinti FRintieven)
		     (out FRintk FRintkeven))))
  )
)

(media-dual-word-rotate-r-r mdrotli rol OP_78 OPE1_0B "rotate left reg/reg")

(dni mcplhi
     "Media dual couple, halfword"
     ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
     "mcplhi$pack $FRinti,$u6,$FRintk"
     (+ pack FRintk OP_78 FRinti OPE1_0C u6)
     (sequence ((HI arg1) (HI arg2) (HI shift))
	       (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (set shift (and u6 #xf))
	       (set arg1 (sll (halfword hi FRinti 0) shift))
	       (if (ne shift 0)
		   (sequence ()
			     (set arg2 (halfword hi FRinti 1))
			     (set arg2 (srl HI (sll HI arg2 (sub 15 shift))
					    (sub 15 shift)))
			     (set arg1 (or HI arg1 arg2))))
	       (set (halfword hi FRintk 0) arg1))
     ((fr400 (unit u-media-3-dual)))
)

(dni mcpli
     "Media dual couple, word"
     ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
     "mcpli$pack $FRinti,$u6,$FRintk"
     (+ pack FRintk OP_78 FRinti OPE1_0D u6)
     (sequence ((SI tmp) (SI shift))
	       (set shift (and u6 #x1f))
	       (set tmp (sll FRinti shift))
	       (if (ne shift 0)
		   (sequence ((SI tmp1))
			     (set tmp1 (srl (sll (nextreg h-fr_int FRinti 1)
						 (sub 31 shift))
					    (sub 31 shift)))
			     (set tmp (or tmp tmp1))))
	       (set FRintk tmp))
     ((fr400 (unit u-media-3-dual)))
)

(define-pmacro (saturate arg max min result)
  (if (gt arg max)
      (set result max)
      (if (lt arg min)
	  (set result min)
	  (set result arg)))
)

(dni msaths
     "Media dual saturation signed"
     ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
     "msaths$pack $FRinti,$FRintj,$FRintk"
     (+ pack FRintk OP_7B FRinti OPE1_0C FRintj)
     (sequence ((HI argihi) (HI argilo) (HI argjhi) (HI argjlo))
	       (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
	       (saturate argihi argjhi (inv argjhi) (halfword hi FRintk 0))
	       (saturate argilo argjlo (inv argjlo) (halfword lo FRintk 0)))
     ((fr400 (unit u-media-1))
      (fr500 (unit u-media)))
)

(dni mqsaths
     "Media quad saturation signed"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mqsaths$pack $FRintieven,$FRintjeven,$FRintkeven"
     (+ pack FRintkeven OP_78 FRintieven OPE1_0F FRintjeven)
     (if (orif (register-unaligned FRintieven 2)
	       (orif (register-unaligned FRintjeven 2)
		     (register-unaligned FRintkeven 2)))
	 (c-call VOID "@cpu@_media_register_not_aligned")
	 (sequence ((HI argihi) (HI argilo) (HI argjhi) (HI argjlo))
		   ; hack to get FRintkeven referenced as a target for profiling
		   (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
		   (extract-hilo FRintieven 0 FRintjeven 0 argihi argilo argjhi argjlo)
		   (saturate argihi argjhi (inv argjhi) (halfword hi FRintkeven 0))
		   (saturate argilo argjlo (inv argjlo) (halfword lo FRintkeven 0))
		   (extract-hilo FRintieven 1 FRintjeven 1 argihi argilo argjhi argjlo)
		   (saturate argihi argjhi (inv argjhi) (halfword hi FRintkeven 1))
		   (saturate argilo argjlo (inv argjlo) (halfword lo FRintkeven 1))))
     ((fr400 (unit u-media-1-quad
		   (in  FRinti FRintieven)
		   (in  FRintj FRintjeven)
		   (out FRintk FRintkeven))))
)

(define-pmacro (saturate-unsigned arg max result)
  (if (gt arg max)
      (set result max)
      (set result arg))
)

(dni msathu
     "Media dual saturation unsigned"
     ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
     "msathu$pack $FRinti,$FRintj,$FRintk"
     (+ pack FRintk OP_7B FRinti OPE1_0D FRintj)
     (sequence ((UHI argihi) (UHI argilo) (UHI argjhi) (UHI argjlo))
	       (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
	       (saturate-unsigned argihi argjhi (halfword hi FRintk 0))
	       (saturate-unsigned argilo argjlo (halfword lo FRintk 0)))
     ((fr400 (unit u-media-1))
      (fr500 (unit u-media)))
)

(define-pmacro (media-dual-compare name mode op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$FCCk")
       (+ pack (cond-null) FCCk op FRinti ope FRintj)
       (if (register-unaligned FCCk 2)
	   (c-call VOID "@cpu@_media_cr_not_aligned")
	   (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
		     (extract-hilo FRinti 0 FRintj 0
				   argihi argilo argjhi argjlo)
		     (compare-and-set-fcc argihi argjhi FCCk)
		     (compare-and-set-fcc argilo argjlo (nextreg h-fccr FCCk 1))))
       ; TODO - doesn't handle second FCC
       ((fr400 (unit u-media-7))
	(fr500 (unit u-media)))
  )
)

(media-dual-compare mcmpsh HI  OP_7B OPE1_0E "Media dual compare signed")
(media-dual-compare mcmpuh UHI OP_7B OPE1_0F "Media dual compare unsigned")

; Bits for the MSR.SIE field
(define-pmacro (msr-sie-nil)      0)
(define-pmacro (msr-sie-fri-hi)   8)
(define-pmacro (msr-sie-fri-lo)   4)
(define-pmacro (msr-sie-fri-1-hi) 2)
(define-pmacro (msr-sie-fri-1-lo) 1)
(define-pmacro (msr-sie-acci)     8)
(define-pmacro (msr-sie-acci-1)   4)
(define-pmacro (msr-sie-acci-2)   2)
(define-pmacro (msr-sie-acci-3)   1)

(define-pmacro (saturate-v arg max min sie result)
  (if (gt DI arg max)
      (sequence ()
		(set result max)
		(c-call VOID "@cpu@_media_overflow" sie))
      (if (lt DI arg min)
	  (sequence ()
		    (set result min)
		    (c-call VOID "@cpu@_media_overflow" sie))
	  (set result arg)))
)

(dni mabshs
     "Media dual absolute value, halfword"
     ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
     "mabshs$pack $FRintj,$FRintk"
     (+ pack FRintk OP_78 (FRi-null) OPE1_0A FRintj)
     (sequence ((HI arghi) (HI arglo))
	       (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (set arghi (halfword hi FRintj 0))
	       (set arglo (halfword lo FRintj 0))
	       (saturate-v (abs arghi) 32767 -32768 (msr-sie-fri-hi)
			   (halfword hi FRintk 0))
	       (saturate-v (abs arglo) 32767 -32768 (msr-sie-fri-lo)
			   (halfword lo FRintk 0)))
     ((fr400 (unit u-media-1)))
)

(define-pmacro (media-arith-sat-semantics
		operation arg1 arg2 res mode max min sie)
  (sequence ((DI tmp))
	    (set tmp (operation arg1 arg2))
	    (saturate-v tmp max min sie res))
)

(define-pmacro (media-dual-arith-sat-semantics operation mode max min)
  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
	    (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
	    (media-arith-sat-semantics operation argihi argjhi
				       (halfword hi FRintk 0) mode max min
				       (msr-sie-fri-hi))
	    (media-arith-sat-semantics operation argilo argjlo
				       (halfword lo FRintk 0) mode max min
				       (msr-sie-fri-lo)))
)

(define-pmacro (media-dual-arith-sat name operation mode max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$FRintk")
       (+ pack FRintk op FRinti ope FRintj)
       (media-dual-arith-sat-semantics operation mode max min)
       ((fr400 (unit u-media-1))
	(fr500 (unit u-media)))
  )
)

(media-dual-arith-sat maddhss add  HI 32767 -32768 OP_7B OPE1_10 "Media dual add signed with saturation")
(media-dual-arith-sat maddhus add UHI 65535      0 OP_7B OPE1_11 "Media dual add unsigned with saturation")

(media-dual-arith-sat msubhss sub  HI 32767 -32768 OP_7B OPE1_12 "Media dual sub signed with saturation")
(media-dual-arith-sat msubhus sub UHI 65535      0 OP_7B OPE1_13 "Media dual sub unsigned with saturation")

(define-pmacro (conditional-media-dual-arith-sat
		name operation mode max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-1) CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$FRintk,$CCi,$cond")
       (+ pack FRintk op FRinti CCi cond ope FRintj)
       (if (eq CCi (or cond 2))
	   (media-dual-arith-sat-semantics operation mode max min))
       ((fr400 (unit u-media-1))
	(fr500 (unit u-media)))
  )
)

(conditional-media-dual-arith-sat cmaddhss add  HI 32767 -32768 OP_71 OPE4_0 "Conditional Media dual add signed with saturation")
(conditional-media-dual-arith-sat cmaddhus add UHI 65535      0 OP_71 OPE4_1 "Conditional Media dual add unsigned with saturation")

(conditional-media-dual-arith-sat cmsubhss sub  HI 32767 -32768 OP_71 OPE4_2 "Conditional Media dual sub signed with saturation")
(conditional-media-dual-arith-sat cmsubhus sub UHI 65535      0 OP_71 OPE4_3 "Conditional Media dual sub unsigned with saturation")

(define-pmacro (media-quad-arith-sat-semantics cond operation mode max min)
  (if (orif (register-unaligned FRintieven 2)
	    (orif (register-unaligned FRintjeven 2)
		  (register-unaligned FRintkeven 2)))
      (c-call VOID "@cpu@_media_register_not_aligned")
      (if cond
	  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
		    ; hack to get FRintkeven referenced as a target for profiling
		    (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
		    (extract-hilo FRintieven 0 FRintjeven 0
				  argihi argilo argjhi argjlo)
		    (media-arith-sat-semantics operation argihi argjhi
					       (halfword hi FRintkeven 0) mode
					       max min (msr-sie-fri-hi))
		    (media-arith-sat-semantics operation argilo argjlo
					       (halfword lo FRintkeven 0) mode
					       max min (msr-sie-fri-lo))
		    (extract-hilo FRintieven 1 FRintjeven 1
				  argihi argilo argjhi argjlo)
		    (media-arith-sat-semantics operation argihi argjhi
					       (halfword hi FRintkeven 1) mode
					       max min	(msr-sie-fri-1-hi))
		    (media-arith-sat-semantics operation argilo argjlo
					       (halfword lo FRintkeven 1) mode
					       max min (msr-sie-fri-1-lo)))))
)

(define-pmacro (media-quad-arith-sat name operation mode max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$FRintkeven")
       (+ pack FRintkeven op FRintieven ope FRintjeven)
       (media-quad-arith-sat-semantics 1 operation mode max min)
       ((fr400 (unit u-media-1-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)
		     (out FRintk FRintkeven)))
	(fr500 (unit u-media-quad-arith
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)
		     (out FRintk FRintkeven))))
  )
)

(media-quad-arith-sat mqaddhss add  HI 32767 -32768 OP_7B OPE1_18 "Media quad add signed with saturation")
(media-quad-arith-sat mqaddhus add UHI 65535      0 OP_7B OPE1_19 "Media quad add unsigned with saturation")

(media-quad-arith-sat mqsubhss sub  HI 32767 -32768 OP_7B OPE1_1A "Media quad sub signed with saturation")
(media-quad-arith-sat mqsubhus sub UHI 65535      0 OP_7B OPE1_1B "Media quad sub unsigned with saturation")

(define-pmacro (conditional-media-quad-arith-sat
		name operation mode max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-1) (FR400-MAJOR M-2) CONDITIONAL)
       (.str name "$pack $FRintieven,$FRintjeven,$FRintkeven,$CCi,$cond")
       (+ pack FRintkeven op FRintieven CCi cond ope FRintjeven)
       (media-quad-arith-sat-semantics (eq CCi (or cond 2))
				       operation mode max min)
       ((fr400 (unit u-media-1-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)
		     (out FRintk FRintkeven)))
	(fr500 (unit u-media-quad-arith
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)
		     (out FRintk FRintkeven))))
  )
)

(conditional-media-quad-arith-sat cmqaddhss add  HI 32767 -32768 OP_73 OPE4_0 "Conditional Media quad add signed with saturation")
(conditional-media-quad-arith-sat cmqaddhus add UHI 65535      0 OP_73 OPE4_1 "Conditional Media quad add unsigned with saturation")

(conditional-media-quad-arith-sat cmqsubhss sub  HI 32767 -32768 OP_73 OPE4_2 "Conditional Media quad sub signed with saturation")
(conditional-media-quad-arith-sat cmqsubhus sub UHI 65535      0 OP_73 OPE4_3 "Conditional Media quad sub unsigned with saturation")

(define-pmacro (media-acc-arith-sat name operation mode max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
       (.str name "$pack $ACC40Si,$ACC40Sk")
       (+ pack ACC40Sk op ACC40Si ope (ACCj-null))
       (if (register-unaligned ACC40Si 2)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (media-arith-sat-semantics operation ACC40Si
				      (nextreg h-acc40S ACC40Si 1)
				      ACC40Sk mode max min (msr-sie-acci)))
       ((fr400 (unit u-media-2-acc)))
  )
)

(media-acc-arith-sat maddaccs add DI #x7fffffffff (inv DI #x7fffffffff)
		     OP_78 OPE1_04 "Media accumulator addition")
(media-acc-arith-sat msubaccs sub DI #x7fffffffff (inv DI #x7fffffffff)
		     OP_78 OPE1_05 "Media accumulator subtraction")

(define-pmacro (media-dual-acc-arith-sat name operation mode max min op ope
					 comment)
  (dni name
       (comment)
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       (.str name "$pack $ACC40Si,$ACC40Sk")
       (+ pack ACC40Sk op ACC40Si ope (ACCj-null))
       (if (register-unaligned ACC40Si 4)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (if (register-unaligned ACC40Sk 2)
	       (c-call VOID "@cpu@_media_acc_not_aligned")
	       (sequence ()
			 (media-arith-sat-semantics operation ACC40Si
						    (nextreg h-acc40S ACC40Si 1)
						    ACC40Sk mode max min
						    (msr-sie-acci))
			 (media-arith-sat-semantics operation
						    (nextreg h-acc40S ACC40Si 2)
						    (nextreg h-acc40S ACC40Si 3)
						    (nextreg h-acc40S ACC40Sk 1)
						    mode max min
						    (msr-sie-acci-1)))))
       ((fr400 (unit u-media-2-acc-dual)))
  )
)

(media-dual-acc-arith-sat mdaddaccs add DI #x7fffffffff (inv DI #x7fffffffff)
			  OP_78 OPE1_06 "Media accumulator addition")
(media-dual-acc-arith-sat mdsubaccs sub DI #x7fffffffff (inv DI #x7fffffffff)
			  OP_78 OPE1_07 "Media accumulator subtraction")

(dni masaccs
     "Media add and subtract signed accumulator with saturation"
       ((UNIT FM01) (MACH fr400) (FR400-MAJOR M-1))
       "masaccs$pack $ACC40Si,$ACC40Sk"
       (+ pack ACC40Sk OP_78 ACC40Si OPE1_08 (ACCj-null))
       (if (register-unaligned ACC40Si 2)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (if (register-unaligned ACC40Sk 2)
	       (c-call VOID "@cpu@_media_acc_not_aligned")
	       (sequence ()
			 (media-arith-sat-semantics add ACC40Si
						    (nextreg h-acc40S ACC40Si 1)
						    ACC40Sk DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci))
			 (media-arith-sat-semantics sub ACC40Si
						    (nextreg h-acc40S ACC40Si 1)
						    (nextreg h-acc40S ACC40Sk 1)
						    DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci-1)))))
       ((fr400 (unit u-media-2-add-sub)))
  )

(dni mdasaccs
     "Media add and subtract signed accumulator with saturation"
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       "mdasaccs$pack $ACC40Si,$ACC40Sk"
       (+ pack ACC40Sk OP_78 ACC40Si OPE1_09 (ACCj-null))
       (if (register-unaligned ACC40Si 4)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (if (register-unaligned ACC40Sk 4)
	       (c-call VOID "@cpu@_media_acc_not_aligned")
	       (sequence ()
			 (media-arith-sat-semantics add ACC40Si
						    (nextreg h-acc40S ACC40Si 1)
						    ACC40Sk DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci))
			 (media-arith-sat-semantics sub ACC40Si
						    (nextreg h-acc40S ACC40Si 1)
						    (nextreg h-acc40S ACC40Sk 1)
						    DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci-1))
			 (media-arith-sat-semantics add
						    (nextreg h-acc40S ACC40Si 2)
						    (nextreg h-acc40S ACC40Si 3)
						    (nextreg h-acc40S ACC40Sk 2)
						    DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci-2))
			 (media-arith-sat-semantics sub
						    (nextreg h-acc40S ACC40Si 2)
						    (nextreg h-acc40S ACC40Si 3)
						    (nextreg h-acc40S ACC40Sk 3)
						    DI
						    #x7fffffffff
						    (inv DI #x7fffffffff)
						    (msr-sie-acci-3)))))
       ((fr400 (unit u-media-2-add-sub-dual)))
  )

(define-pmacro (media-multiply-semantics conv arg1 arg2 res)
  (set res (mul DI (conv DI arg1) (conv DI arg2)))
)

(define-pmacro (media-dual-multiply-semantics cond mode conv rhs1 rhs2)
  (if (register-unaligned ACC40Sk 2)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if cond
	  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
		    (extract-hilo FRinti 0 FRintj 0
				  argihi argilo argjhi argjlo)
		    (media-multiply-semantics conv argihi rhs1 ACC40Sk)
		    (media-multiply-semantics conv argilo rhs2
					      (nextreg h-acc40S ACC40Sk 1)))))
)

(define-pmacro (media-dual-multiply name mode conv rhs1 rhs2 op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) PRESERVE-OVF)
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
       (+ pack ACC40Sk op FRinti ope FRintj)
       (media-dual-multiply-semantics 1 mode conv rhs1 rhs2)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(media-dual-multiply mmulhs  HI ext  argjhi argjlo OP_7B OPE1_14 "Media dual multiply signed")
(media-dual-multiply mmulhu UHI zext argjhi argjlo OP_7B OPE1_15 "Media dual multiply unsigned")

(media-dual-multiply mmulxhs  HI ext  argjlo argjhi OP_7B OPE1_28 "Media dual cross multiply signed")
(media-dual-multiply mmulxhu UHI zext argjlo argjhi OP_7B OPE1_29 "Media dual cross multiply unsigned")

(define-pmacro (conditional-media-dual-multiply
		name mode conv rhs1 rhs2 op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1)
	PRESERVE-OVF CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
       (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
       (media-dual-multiply-semantics (eq CCi (or cond 2)) mode conv rhs1 rhs2)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(conditional-media-dual-multiply cmmulhs  HI ext  argjhi argjlo OP_72 OPE4_0 "Conditional Media dual multiply signed")
(conditional-media-dual-multiply cmmulhu UHI zext argjhi argjlo OP_72 OPE4_1 "Conditional Media dual multiply unsigned")

(define-pmacro (media-quad-multiply-semantics cond mode conv rhs1 rhs2)
  (if (register-unaligned ACC40Sk 4)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if (orif (register-unaligned FRintieven 2)
		(register-unaligned FRintjeven 2))
	  (c-call VOID "@cpu@_media_register_not_aligned")
	  (if cond
	      (sequence ((mode argihi) (mode argilo)
			 (mode argjhi) (mode argjlo))
			(extract-hilo FRintieven 0 FRintjeven 0
				      argihi argilo argjhi argjlo)
			(media-multiply-semantics conv argihi rhs1 ACC40Sk)
			(media-multiply-semantics conv argilo rhs2
						  (nextreg h-acc40S ACC40Sk 1))
			(extract-hilo FRintieven 1 FRintjeven 1
				      argihi argilo argjhi argjlo)
			(media-multiply-semantics conv argihi rhs1
						  (nextreg h-acc40S ACC40Sk 2))
			(media-multiply-semantics conv argilo rhs2
						  (nextreg h-acc40S ACC40Sk 3))))))
)

(define-pmacro (media-quad-multiply name mode conv rhs1 rhs2 op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2) PRESERVE-OVF)
       (.str name "$pack $FRintieven,$FRintjeven,$ACC40Sk")
       (+ pack ACC40Sk op FRintieven ope FRintjeven)
       (media-quad-multiply-semantics 1 mode conv rhs1 rhs2) 
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)))
	(fr500 (unit u-media-quad-mul
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))
  )
)

(media-quad-multiply mqmulhs  HI ext  argjhi argjlo OP_7B OPE1_1C "Media quad multiply signed")
(media-quad-multiply mqmulhu UHI zext argjhi argjlo OP_7B OPE1_1D "Media quad multiply unsigned")

(media-quad-multiply mqmulxhs  HI ext  argjlo argjhi OP_7B OPE1_2A "Media quad cross multiply signed")
(media-quad-multiply mqmulxhu UHI zext argjlo argjhi OP_7B OPE1_2B "Media quad cross multiply unsigned")

(define-pmacro (conditional-media-quad-multiply
		name mode conv rhs1 rhs2 op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2)
	PRESERVE-OVF CONDITIONAL)
       (.str name "$pack $FRintieven,$FRintjeven,$ACC40Sk,$CCi,$cond")
       (+ pack ACC40Sk op FRintieven CCi cond ope FRintjeven)
       (media-quad-multiply-semantics (eq CCi (or cond 2)) mode conv rhs1 rhs2)
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)))
	(fr500 (unit u-media-quad-mul
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))	     
  )
)

(conditional-media-quad-multiply cmqmulhs  HI ext  argjhi argjlo OP_74 OPE4_0 "Conditional Media quad multiply signed")
(conditional-media-quad-multiply cmqmulhu UHI zext argjhi argjlo OP_74 OPE4_1 "Conditional Media quad multiply unsigned")

(define-pmacro (media-multiply-acc-semantics 
		conv arg1 addop arg2 res max min sie)
  (sequence ((DI tmp))
	    (set tmp (addop res (mul DI (conv DI arg1) (conv DI arg2))))
	    (saturate-v tmp max min sie res))
)

(define-pmacro (media-dual-multiply-acc-semantics
		cond mode conv addop rhw res max min)
  (if (register-unaligned res 2)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if cond
	  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
		    (extract-hilo FRinti 0 FRintj 0
				  argihi argilo argjhi argjlo)
		    (media-multiply-acc-semantics conv argihi addop argjhi
						  res
						  max min (msr-sie-acci))
		    (media-multiply-acc-semantics conv argilo addop argjlo
						  (nextreg rhw res 1)
						  max min (msr-sie-acci-1)))))
)

(define-pmacro (media-dual-multiply-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$" res)
       (+ pack res op FRinti ope FRintj)
       (media-dual-multiply-acc-semantics 1 mode conv addop rhw res max min)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(media-dual-multiply-acc mmachs HI ext add h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_7B OPE1_16
			 "Media dual multiply and accumulate signed")

(media-dual-multiply-acc mmachu UHI zext add h-acc40U ACC40Uk
			 (const DI #xffffffffff) (const DI 0)
			 OP_7B OPE1_17
			 "Media dual multiply and accumulate unsigned")

(media-dual-multiply-acc mmrdhs HI ext sub h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_7B OPE1_30
			 "Media dual multiply and reduce signed")

(media-dual-multiply-acc mmrdhu UHI zext sub h-acc40U ACC40Uk
			 (const DI #xffffffffff) (const DI 0)
			 OP_7B OPE1_31
			 "Media dual multiply and reduce unsigned")

(define-pmacro (conditional-media-dual-multiply-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$" res ",$CCi,$cond")
       (+ pack res op FRinti CCi cond ope FRintj)
       (media-dual-multiply-acc-semantics (eq CCi (or cond 2))
					  mode conv addop rhw res max min)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(conditional-media-dual-multiply-acc cmmachs HI ext add h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_72 OPE4_2
			 "Conditional Media dual multiply and accumulate signed")

(conditional-media-dual-multiply-acc cmmachu UHI zext add  h-acc40U ACC40Uk
			 (const DI #xffffffffff) (const DI 0)
			 OP_72 OPE4_3
			 "Conditional Media dual multiply and accumulate unsigned")

(define-pmacro (media-quad-multiply-acc-semantics
		cond mode conv addop rhw res max min)
  (if (register-unaligned res 4)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if (orif (register-unaligned FRintieven 2)
		(register-unaligned FRintjeven 2))
	  (c-call VOID "@cpu@_media_register_not_aligned")
	  (if cond
	      (sequence ((mode argihi) (mode argilo)
			 (mode argjhi) (mode argjlo))
			(extract-hilo FRintieven 0 FRintjeven 0
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjhi
						      res
						      max min (msr-sie-acci))
			(media-multiply-acc-semantics conv argilo addop argjlo
						      (nextreg rhw res 1)
						      max min (msr-sie-acci-1))
			(extract-hilo FRintieven 1 FRintjeven 1
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjhi
						      (nextreg rhw res 2)
						      max min (msr-sie-acci-2))
			(media-multiply-acc-semantics conv argilo addop argjlo
						      (nextreg rhw res 3)
						      max min
						      (msr-sie-acci-3))))))
)

(define-pmacro (media-quad-multiply-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$" res)
       (+ pack res op FRintieven ope FRintjeven)
       (media-quad-multiply-acc-semantics 1 mode conv addop rhw res max min)
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)))
	(fr500 (unit u-media-quad-mul
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))
  )
)

(media-quad-multiply-acc mqmachs HI ext add h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_7B OPE1_1E
			 "Media quad multiply and accumulate signed")

(media-quad-multiply-acc mqmachu UHI zext add h-acc40U ACC40Uk
			 (const DI #xffffffffff) (const DI 0)
			 OP_7B OPE1_1F
			 "Media quad multiply and accumulate unsigned")

(define-pmacro (conditional-media-quad-multiply-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2) CONDITIONAL)
       (.str name "$pack $FRintieven,$FRintjeven,$" res ",$CCi,$cond")
       (+ pack res op FRintieven CCi cond ope FRintjeven)
       (media-quad-multiply-acc-semantics (eq CCi (or cond 2))
					  mode conv addop rhw res max min)
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven)))
	(fr500 (unit u-media-quad-mul
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))
  )
)

(conditional-media-quad-multiply-acc cmqmachs HI ext add h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_74 OPE4_2
			 "Conditional Media quad multiply and accumulate signed")

(conditional-media-quad-multiply-acc cmqmachu UHI zext add h-acc40U ACC40Uk
			 (const DI #xffffffffff) (const DI 0)
			 OP_74 OPE4_3
			 "Conditional media quad multiply and accumulate unsigned")

(define-pmacro (media-quad-multiply-cross-acc-semantics
		cond mode conv addop rhw res max min)
  (if (register-unaligned res 4)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if (orif (register-unaligned FRintieven 2)
		(register-unaligned FRintjeven 2))
	  (c-call VOID "@cpu@_media_register_not_aligned")
	  (if cond
	      (sequence ((mode argihi) (mode argilo)
			 (mode argjhi) (mode argjlo))
			(extract-hilo FRintieven 0 FRintjeven 0
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjhi
						      (nextreg rhw res 2)
						      max min (msr-sie-acci-2))
			(media-multiply-acc-semantics conv argilo addop argjlo
						      (nextreg rhw res 3)
						      max min (msr-sie-acci-3))
			(extract-hilo FRintieven 1 FRintjeven 1
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjhi
						      res
						      max min (msr-sie-acci))
			(media-multiply-acc-semantics conv argilo addop argjlo
						      (nextreg rhw res 1)
						      max min
						      (msr-sie-acci-1))))))
)

(define-pmacro (media-quad-multiply-cross-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$" res)
       (+ pack res op FRintieven ope FRintjeven)
       (media-quad-multiply-cross-acc-semantics 1 mode conv addop rhw res
						max min)
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))
  )
)

(media-quad-multiply-cross-acc mqxmachs HI ext add h-acc40S ACC40Sk
			 (const DI #x7fffffffff) (const DI #xffffff8000000000)
			 OP_78 OPE1_00
			 "Media quad multiply and cross accumulate signed")

(define-pmacro (media-quad-cross-multiply-cross-acc-semantics
		cond mode conv addop rhw res max min)
  (if (register-unaligned res 4)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if (orif (register-unaligned FRintieven 2)
		(register-unaligned FRintjeven 2))
	  (c-call VOID "@cpu@_media_register_not_aligned")
	  (if cond
	      (sequence ((mode argihi) (mode argilo)
			 (mode argjhi) (mode argjlo))
			(extract-hilo FRintieven 0 FRintjeven 0
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjlo
						      (nextreg rhw res 2)
						      max min (msr-sie-acci-2))
			(media-multiply-acc-semantics conv argilo addop argjhi
						      (nextreg rhw res 3)
						      max min (msr-sie-acci-3))
			(extract-hilo FRintieven 1 FRintjeven 1
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjlo
						      res
						      max min (msr-sie-acci))
			(media-multiply-acc-semantics conv argilo addop argjhi
						      (nextreg rhw res 1)
						      max min
						      (msr-sie-acci-1))))))
)

(define-pmacro (media-quad-cross-multiply-cross-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$" res)
       (+ pack res op FRintieven ope FRintjeven)
       (media-quad-cross-multiply-cross-acc-semantics 1 mode conv addop rhw res
						      max min)
       ((fr400 (unit u-media-2-quad
		     (in  FRinti FRintieven)
		     (in  FRintj FRintjeven))))
  )
)

(media-quad-cross-multiply-cross-acc mqxmacxhs HI ext add h-acc40S ACC40Sk
			(const DI #x7fffffffff) (const DI #xffffff8000000000)
			OP_78 OPE1_01
			"Media quad cross multiply and cross accumulate signed")

(define-pmacro (media-quad-cross-multiply-acc-semantics
		cond mode conv addop rhw res max min)
  (if (register-unaligned res 4)
      (c-call VOID "@cpu@_media_acc_not_aligned")
      (if (orif (register-unaligned FRintieven 2)
		(register-unaligned FRintjeven 2))
	  (c-call VOID "@cpu@_media_register_not_aligned")
	  (if cond
	      (sequence ((mode argihi) (mode argilo)
			 (mode argjhi) (mode argjlo))
			(extract-hilo FRintieven 0 FRintjeven 0
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjlo
						      res
						      max min (msr-sie-acci))
			(media-multiply-acc-semantics conv argilo addop argjhi
						      (nextreg rhw res 1)
						      max min (msr-sie-acci-1))
			(extract-hilo FRintieven 1 FRintjeven 1
				      argihi argilo argjhi argjlo)
			(media-multiply-acc-semantics conv argihi addop argjlo
						      (nextreg rhw res 2)
						      max min (msr-sie-acci-2))
			(media-multiply-acc-semantics conv argilo addop argjhi
						      (nextreg rhw res 3)
						      max min
						      (msr-sie-acci-3))))))
)

(define-pmacro (media-quad-cross-multiply-acc
		name mode conv addop rhw res max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM0) (MACH fr400) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$" res)
       (+ pack res op FRintieven ope FRintjeven)
       (media-quad-cross-multiply-acc-semantics 1 mode conv addop rhw res
						max min)
       ((fr400 (unit u-media-2-quad
		     (in FRinti FRintieven)
		     (in FRintj FRintjeven))))
  )
)

(media-quad-cross-multiply-acc mqmacxhs HI ext add h-acc40S ACC40Sk
			(const DI #x7fffffffff) (const DI #xffffff8000000000)
			OP_78 OPE1_02
			"Media quad cross multiply and accumulate signed")

(define-pmacro (media-complex-semantics
		conv lhs1 rhs1 lhs2 rhs2 res max min sie)
  (sequence ((DI tmp1) (DI tmp2))
	    (media-multiply-semantics conv lhs1 rhs1 tmp1)
	    (media-multiply-semantics conv lhs2 rhs2 tmp2)
	    (set tmp1 (sub tmp1 tmp2))
	    (saturate-v tmp1 max min sie res))
)

(define-pmacro (media-complex-semantics-i
		conv lhs1 rhs1 lhs2 rhs2 res max min sie)
  (sequence ((DI tmp1) (DI tmp2))
	    (media-multiply-semantics conv lhs1 rhs1 tmp1)
	    (media-multiply-semantics conv lhs2 rhs2 tmp2)
	    (set tmp1 (add tmp1 tmp2))
	    (saturate-v tmp1 max min sie res))
)

(define-pmacro (media-dual-complex-semantics mode conv rhs1 rhs2 max min)
  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
	    (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
	    (media-complex-semantics conv argihi rhs1 argilo rhs2 ACC40Sk
				     max min (msr-sie-acci)))
)

(define-pmacro (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min)
  (sequence ((mode argihi) (mode argilo) (mode argjhi) (mode argjlo))
	    (extract-hilo FRinti 0 FRintj 0 argihi argilo argjhi argjlo)
	    (media-complex-semantics-i conv argihi rhs1 argilo rhs2 ACC40Sk
				     max min (msr-sie-acci)))
)

(define-pmacro (media-dual-complex
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
       (+ pack ACC40Sk op FRinti ope FRintj)
       (media-dual-complex-semantics mode conv rhs1 rhs2 max min)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media)))
  )
)

(define-pmacro (media-dual-complex-i
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1))
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk")
       (+ pack ACC40Sk op FRinti ope FRintj)
       (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min)
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(media-dual-complex mcpxrs HI ext argjhi argjlo
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_7B OPE1_20
		    "Media dual complex real signed with saturation")

(media-dual-complex mcpxru UHI zext argjhi argjlo
		    (const DI #xffffffffff) (const DI 0)
		    OP_7B OPE1_21
		    "Media dual complex real unsigned with saturation")

(media-dual-complex-i mcpxis HI ext argjlo argjhi
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_7B OPE1_22
		    "Media dual complex imaginary signed with saturation")

(media-dual-complex-i mcpxiu UHI zext argjlo argjhi
		    (const DI #xffffffffff) (const DI 0)
		    OP_7B OPE1_23
		    "Media dual complex imaginary unsigned with saturation")

(define-pmacro (conditional-media-dual-complex
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
       (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
       (if (eq CCi (or cond 2))
	   (media-dual-complex-semantics mode conv rhs1 rhs2 max min))
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media)))
  )
)

(define-pmacro (conditional-media-dual-complex-i
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-1) CONDITIONAL)
       (.str name "$pack $FRinti,$FRintj,$ACC40Sk,$CCi,$cond")
       (+ pack ACC40Sk op FRinti CCi cond ope FRintj)
       (if (eq CCi (or cond 2))
	   (media-dual-complex-semantics-i mode conv rhs1 rhs2 max min))
       ((fr400 (unit u-media-2))
	(fr500 (unit u-media-dual-mul)))
  )
)

(conditional-media-dual-complex cmcpxrs HI ext argjhi argjlo
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_75 OPE4_0
		    "Conditional Media dual complex real signed with saturation")

(conditional-media-dual-complex cmcpxru UHI zext argjhi argjlo
		    (const DI #xffffffffff) (const DI 0)
		    OP_75 OPE4_1
		    "Conditional Media dual complex real unsigned with saturation")

(conditional-media-dual-complex-i cmcpxis HI ext argjlo argjhi
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_75 OPE4_2
		    "Conditional Media dual complex imaginary signed with saturation")

(conditional-media-dual-complex-i cmcpxiu UHI zext argjlo argjhi
		    (const DI #xffffffffff) (const DI 0)
		    OP_75 OPE4_3
		    "Conditional Media dual complex imaginary unsigned with saturation")

(define-pmacro (media-quad-complex
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$ACC40Sk")
       (+ pack ACC40Sk op FRintieven ope FRintjeven)
       (if (register-unaligned ACC40Sk 2)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (if (orif (register-unaligned FRintieven 2)
		     (register-unaligned FRintjeven 2))
	       (c-call VOID "@cpu@_media_register_not_aligned")
	       (sequence ((mode argihi) (mode argilo)
			  (mode argjhi) (mode argjlo))
			 (extract-hilo FRintieven 0 FRintjeven 0
				       argihi argilo argjhi argjlo)
			 (media-complex-semantics conv argihi rhs1 argilo rhs2
						  ACC40Sk
						  max min (msr-sie-acci))
			 (extract-hilo FRintieven 1 FRintjeven 1
				       argihi argilo argjhi argjlo)
			 (media-complex-semantics conv argihi rhs1 argilo rhs2
						  (nextreg h-acc40S ACC40Sk 1)
						  max min (msr-sie-acci-1)))))
       ((fr400 (unit u-media-2-quad
		     (in FRinti FRintieven)
		     (in FRintj FRintjeven)))
	(fr500 (unit u-media-quad-complex
		     (in FRinti FRintieven)
		     (in FRintj FRintjeven))))
  )
)

(define-pmacro (media-quad-complex-i
		name mode conv rhs1 rhs2 max min op ope comment)
  (dni name
       (comment)
       ((UNIT FM01) (FR500-MAJOR M-4) (FR400-MAJOR M-2))
       (.str name "$pack $FRintieven,$FRintjeven,$ACC40Sk")
       (+ pack ACC40Sk op FRintieven ope FRintjeven)
       (if (register-unaligned ACC40Sk 2)
	   (c-call VOID "@cpu@_media_acc_not_aligned")
	   (if (orif (register-unaligned FRintieven 2)
		     (register-unaligned FRintjeven 2))
	       (c-call VOID "@cpu@_media_register_not_aligned")
	       (sequence ((mode argihi) (mode argilo)
			  (mode argjhi) (mode argjlo))
			 (extract-hilo FRintieven 0 FRintjeven 0
				       argihi argilo argjhi argjlo)
			 (media-complex-semantics-i conv argihi rhs1 argilo rhs2
						  ACC40Sk
						  max min (msr-sie-acci))
			 (extract-hilo FRintieven 1 FRintjeven 1
				       argihi argilo argjhi argjlo)
			 (media-complex-semantics-i conv argihi rhs1 argilo rhs2
						  (nextreg h-acc40S ACC40Sk 1)
						  max min (msr-sie-acci-1)))))
       ((fr400 (unit u-media-2-quad
		     (in FRinti FRintieven)
		     (in FRintj FRintjeven)))
	(fr500 (unit u-media-quad-complex
		     (in FRinti FRintieven)
		     (in FRintj FRintjeven))))
  )
)

(media-quad-complex mqcpxrs HI ext argjhi argjlo
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_7B OPE1_24
		    "Media quad complex real signed with saturation")

(media-quad-complex mqcpxru UHI zext argjhi argjlo
		    (const DI #xffffffffff) (const DI 0)
		    OP_7B OPE1_25
		    "Media quad complex real unsigned with saturation")

(media-quad-complex-i mqcpxis HI ext argjlo argjhi
		    (const DI #x7fffffffff) (const DI #xffffff8000000000)
		    OP_7B OPE1_26
		    "Media quad complex imaginary signed with saturation")

(media-quad-complex-i mqcpxiu UHI zext argjlo argjhi
		    (const DI #xffffffffff) (const DI 0)
		    OP_7B OPE1_27
		    "Media quad complex imaginary unsigned with saturation")

(define-pmacro (media-pack src1 src2 targ offset)
  (sequence ()
	    (set (halfword hi targ offset) (halfword lo src1 offset))
	    (set (halfword lo targ offset) (halfword lo src2 offset)))
)

(define-pmacro (media-expand-halfword-to-word-semantics cond)
  (if cond
      (sequence ((UHI tmp))
		(if (and u6 1)
		    (set tmp (halfword lo FRinti 0))
		    (set tmp (halfword hi FRinti 0)))
		(set (halfword hi FRintk 0) tmp)
		(set (halfword lo FRintk 0) tmp)))
)

(dni mexpdhw
     "Media expand halfword to word"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
     "mexpdhw$pack $FRinti,$u6,$FRintk"
     (+ pack FRintk OP_7B FRinti OPE1_32 u6)
     (media-expand-halfword-to-word-semantics 1)
     ((fr400 (unit u-media-3))
      (fr500 (unit u-media)))
)

(dni cmexpdhw
     "Conditional media expand halfword to word"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1) CONDITIONAL)
     "cmexpdhw$pack $FRinti,$u6,$FRintk,$CCi,$cond"
     (+ pack FRintk OP_76 FRinti CCi cond OPE4_2 u6)
     (media-expand-halfword-to-word-semantics (eq CCi (or cond 2)))
     ((fr400 (unit u-media-3))
      (fr500 (unit u-media)))
)

(define-pmacro (media-expand-halfword-to-double-semantics cond)
  (if (register-unaligned FRintkeven 2)
      (c-call VOID "@cpu@_media_register_not_aligned")
      (if cond
	  (sequence ((UHI tmp))
		    ; a hack to get FRintkeven referenced for profiling
		    (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
		    (if (and u6 1)
			(set tmp (halfword lo FRinti 0))
			(set tmp (halfword hi FRinti 0)))
		    (set (halfword hi FRintkeven 0) tmp)
		    (set (halfword lo FRintkeven 0) tmp)
		    (set (halfword hi FRintkeven 1) tmp)
		    (set (halfword lo FRintkeven 1) tmp))))
)

(dni mexpdhd
     "Media expand halfword to double"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
     "mexpdhd$pack $FRinti,$u6,$FRintkeven"
     (+ pack FRintkeven OP_7B FRinti OPE1_33 u6)
     (media-expand-halfword-to-double-semantics 1)
     ((fr400 (unit u-media-dual-expand
		     (out FRintk FRintkeven)))
      (fr500 (unit u-media-dual-expand
		     (out FRintk FRintkeven))))
)

(dni cmexpdhd
     "Conditional media expand halfword to double"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
     "cmexpdhd$pack $FRinti,$u6,$FRintkeven,$CCi,$cond"
     (+ pack FRintkeven OP_76 FRinti CCi cond OPE4_3 u6)
     (media-expand-halfword-to-double-semantics (eq CCi (or cond 2)))
     ((fr400 (unit u-media-dual-expand
		   (out FRintk FRintkeven)))
      (fr500 (unit u-media-dual-expand
		   (out FRintk FRintkeven))))
)

(dni mpackh
     "Media halfword pack"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
     "mpackh$pack $FRinti,$FRintj,$FRintk"
     (+ pack FRintk OP_7B FRinti OPE1_34 FRintj)
     (media-pack FRinti FRintj FRintk 0)
     ((fr400 (unit u-media-3))
      (fr500 (unit u-media)))
)

(dni mdpackh
     "Media dual pack"
     ((UNIT FM01) (FR500-MAJOR M-5) (FR400-MAJOR M-2))
     "mdpackh$pack $FRintieven,$FRintjeven,$FRintkeven"
     (+ pack FRintkeven OP_7B FRintieven OPE1_36 FRintjeven)
     (if (orif (register-unaligned FRintieven 2)
	       (orif (register-unaligned FRintjeven 2)
		     (register-unaligned FRintkeven 2)))
	 (c-call VOID "@cpu@_media_register_not_aligned")
	 (sequence ()
		   ; hack to get these referenced for profiling
		   (set FRintieven (c-raw-call SI "frv_ref_SI" FRintieven))
		   (set FRintjeven (c-raw-call SI "frv_ref_SI" FRintjeven))
		   (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
		   (media-pack FRintieven FRintjeven FRintkeven 0)
		   (media-pack FRintieven FRintjeven FRintkeven 1)))
     ((fr400 (unit u-media-3-quad
		   (in  FRinti FRintieven)
		   (in  FRintj FRintjeven)
		   (out FRintk FRintkeven)))
      (fr500 (unit u-media-quad-arith
		   (in  FRinti FRintieven)
		   (in  FRintj FRintjeven)
		   (out FRintk FRintkeven))))
)

(define-pmacro (media-unpack src soff targ toff)
  (sequence ()
	    (set (halfword hi targ toff) (halfword hi src soff))
	    (set (halfword lo targ toff) (halfword hi src soff))
	    (set (halfword hi targ (add toff 1)) (halfword lo src soff))
	    (set (halfword lo targ (add toff 1)) (halfword lo src soff)))
)

(dni munpackh
     "Media halfword unpack"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
     "munpackh$pack $FRinti,$FRintkeven"
     (+ pack FRintkeven OP_7B FRinti OPE1_35 (FRj-null))
     (if (register-unaligned FRintkeven 2)
	 (c-call VOID "@cpu@_media_register_not_aligned")
	 (sequence ()
		   ; hack to get these referenced for profiling
		   (set FRinti (c-raw-call SI "frv_ref_SI" FRinti))
		   (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
		   (media-unpack FRinti 0 FRintkeven 0)))
     ((fr400 (unit u-media-dual-expand
		   (out FRintk FRintkeven)))
      (fr500 (unit u-media-dual-expand
		   (out FRintk FRintkeven))))
)

(dni mdunpackh
     "Media dual unpack"
     ((UNIT FM01) (FR500-MAJOR M-7) (MACH simple,tomcat,frv))
     "mdunpackh$pack $FRintieven,$FRintk"
     (+ pack FRintk OP_7B FRintieven OPE1_37 (FRj-null))
     (if (orif (register-unaligned FRintieven 2) (register-unaligned FRintk 4))
	 (c-call VOID "@cpu@_media_register_not_aligned")
	 (sequence ()
		   ; hack to get these referenced for profiling
		   (set FRintieven (c-raw-call SI "frv_ref_SI" FRintieven))
		   (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
		   (media-unpack FRintieven 0 FRintk 0)
		   (media-unpack FRintieven 1 FRintk 2)))
     ((fr500 (unit u-media-dual-unpack
		   (in FRinti FRintieven))))
)

(define-pmacro (ubyte num arg offset)
  (reg (.sym h-fr_ num) (add (index-of arg) offset)))

(define-pmacro (mbtoh-semantics cond)
  (if (register-unaligned FRintkeven 2)
      (c-call VOID "@cpu@_media_register_not_aligned")
      (if cond
	  (sequence ()
		    (set (halfword hi FRintkeven 0) (ubyte 3 FRintj 0))
		    (set (halfword lo FRintkeven 0) (ubyte 2 FRintj 0))
		    (set (halfword hi FRintkeven 1) (ubyte 1 FRintj 0))
		    (set (halfword lo FRintkeven 1) (ubyte 0 FRintj 0)))))
)

(dni mbtoh
     "Media convert byte to halfword"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
     "mbtoh$pack $FRintj,$FRintkeven"
     (+ pack FRintkeven OP_7B (FRi-null) OPE1_38 FRintj)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
	       (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
	       (mbtoh-semantics 1))
     ((fr400 (unit u-media-dual-expand
		   (out FRintk FRintkeven)))
      (fr500 (unit u-media-dual-btoh
		   (out FRintk FRintkeven))))
)

(dni cmbtoh
     "Conditional media convert byte to halfword"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
     "cmbtoh$pack $FRintj,$FRintkeven,$CCi,$cond"
     (+ pack FRintkeven OP_77 (FRi-null) CCi cond OPE4_0 FRintj)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
	       (set FRintkeven (c-raw-call SI "frv_ref_SI" FRintkeven))
	       (mbtoh-semantics (eq CCi (or cond 2))))
     ((fr400 (unit u-media-dual-expand
		   (out FRintk FRintkeven)))
      (fr500 (unit u-media-dual-btoh
		   (out FRintk FRintkeven))))
)

(define-pmacro (mhtob-semantics cond)
  (if (register-unaligned FRintjeven 2)
      (c-call VOID "@cpu@_media_register_not_aligned")
      (if cond
	  (sequence ()
		    (set (ubyte 3 FRintk 0) (halfword hi FRintjeven 0))
		    (set (ubyte 2 FRintk 0) (halfword lo FRintjeven 0))
		    (set (ubyte 1 FRintk 0) (halfword hi FRintjeven 1))
		    (set (ubyte 0 FRintk 0) (halfword lo FRintjeven 1)))))
)

(dni mhtob
     "Media convert halfword to byte"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2))
     "mhtob$pack $FRintjeven,$FRintk"
     (+ pack FRintk OP_7B (FRi-null) OPE1_39 FRintjeven)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintjeven (c-raw-call SI "frv_ref_SI" FRintjeven))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (mhtob-semantics 1))
     ((fr400 (unit u-media-dual-htob
		   (in FRintj FRintjeven)))
      (fr500 (unit u-media-dual-htob
		   (in FRintj FRintjeven))))
)

(dni cmhtob
     "Conditional media convert halfword to byte"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-2) CONDITIONAL)
     "cmhtob$pack $FRintjeven,$FRintk,$CCi,$cond"
     (+ pack FRintk OP_77 (FRi-null) CCi cond OPE4_1 FRintjeven)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintjeven (c-raw-call SI "frv_ref_SI" FRintjeven))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (mhtob-semantics (eq CCi (or cond 2))))
     ((fr400 (unit u-media-dual-htob
		   (in FRintj FRintjeven)))
      (fr500 (unit u-media-dual-htob
		   (in FRintj FRintjeven))))
)

(define-pmacro (mbtohe-semantics cond)
  (if (register-unaligned FRintk 4)
      (c-call VOID "@cpu@_media_register_not_aligned")
      (if cond
	  (sequence ()
		    (set (halfword hi FRintk 0) (ubyte 3 FRintj 0))
		    (set (halfword lo FRintk 0) (ubyte 3 FRintj 0))
		    (set (halfword hi FRintk 1) (ubyte 2 FRintj 0))
		    (set (halfword lo FRintk 1) (ubyte 2 FRintj 0))
		    (set (halfword hi FRintk 2) (ubyte 1 FRintj 0))
		    (set (halfword lo FRintk 2) (ubyte 1 FRintj 0))
		    (set (halfword hi FRintk 3) (ubyte 0 FRintj 0))
		    (set (halfword lo FRintk 3) (ubyte 0 FRintj 0)))))
)

(dni mbtohe
     "Media convert byte to halfword extended"
     ((UNIT FM01) (FR500-MAJOR M-7) (MACH simple,tomcat,frv))
     "mbtohe$pack $FRintj,$FRintk"
     (+ pack FRintk OP_7B (FRi-null) OPE1_3A FRintj)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (mbtohe-semantics 1))
     ((fr500 (unit u-media-dual-btohe)))
)

(dni cmbtohe
     "Conditional media convert byte to halfword extended"
     ((UNIT FM01) (FR500-MAJOR M-7) CONDITIONAL (MACH simple,tomcat,frv))
     "cmbtohe$pack $FRintj,$FRintk,$CCi,$cond"
     (+ pack FRintk OP_77 (FRi-null) CCi cond OPE4_2 FRintj)
     (sequence ()
	       ; hack to get these referenced for profiling
	       (set FRintj (c-raw-call SI "frv_ref_SI" FRintj))
	       (set FRintk (c-raw-call SI "frv_ref_SI" FRintk))
	       (mbtohe-semantics (eq CCi (or cond 2))))
     ((fr500 (unit u-media-dual-btohe)))
)

(dni mclracc
     "Media clear accumulator(s)"
     ((UNIT FM01) (FR500-MAJOR M-3))
     "mclracc$pack $ACC40Sk,$A"
     (+ pack ACC40Sk OP_7B A (misc-null-10) OPE1_3B (FRj-null))
     (c-call VOID "@cpu@_clear_accumulators" (index-of ACC40Sk) A)
     ((fr400 (unit u-media-4))
      (fr500 (unit u-media)))
)

(dni mrdacc
     "Media read accumulator"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
     "mrdacc$pack $ACC40Si,$FRintk"
     (+ pack FRintk OP_7B ACC40Si OPE1_3C (FRj-null))
     (set FRintk ACC40Si)
     ((fr400 (unit u-media-4))
      (fr500 (unit u-media)))
)

(dni mrdaccg
     "Media read accumulator guard"
     ((UNIT FM01) (FR500-MAJOR M-2) (FR400-MAJOR M-1))
     "mrdaccg$pack $ACCGi,$FRintk"
     (+ pack FRintk OP_7B ACCGi OPE1_3E (FRj-null))
     (set FRintk ACCGi)
     ((fr400 (unit u-media-4-accg))
      (fr500 (unit u-media)))
)

(dni mwtacc
     "Media write accumulator"
     ((UNIT FM01) (FR500-MAJOR M-3) (FR400-MAJOR M-1))
     "mwtacc$pack $FRinti,$ACC40Sk"
     (+ pack ACC40Sk OP_7B FRinti OPE1_3D (FRj-null))
     (set ACC40Sk (or (and ACC40Sk (const DI #xffffffff00000000))
		     FRinti))
     ((fr400 (unit u-media-4))
      (fr500 (unit u-media)))
)

(dni mwtaccg
     "Media write accumulator guard"
     ((UNIT FM01) (FR500-MAJOR M-3) (FR400-MAJOR M-1))
     "mwtaccg$pack $FRinti,$ACCGk"
     (+ pack ACCGk OP_7B FRinti OPE1_3F (FRj-null))
     (set ACCGk FRinti)
     ((fr400 (unit u-media-4-accg))
      (fr500 (unit u-media)))
)

(define-pmacro (media-cop num op)
  (dni (.sym mcop num)
       "Media custom instruction"
       ((UNIT FM01) (FR500-MAJOR M-1) (MACH frv))
       (.str "mcop" num "$pack $FRi,$FRj,$FRk")
       (+ pack FRk op FRi OPE1_00 FRj)
       (c-call VOID "@cpu@_media_cop" num)
       ()
  )
)

(media-cop 1 OP_7C)
(media-cop 2 OP_7D)

; nop
; A nop is defined to be a "ori gr0,0,gr0"
; This needn't be a macro-insn, but making it one greatly simplifies decode.c
; On the other hand spending a little time in the decoder is often worth it.
;
(dnmi nop "nop"
     ((UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
     "nop$pack"
     (emit ori pack (GRi 0) (s12 0) (GRk 0))
)

; Floating point NOP
(dni fnop
     "Floating point nop"
     ((UNIT FM01) (FR500-MAJOR F-8) (MACH simple,tomcat,fr500,frv))
     "fnop$pack"
     (+ pack (rd-null) OP_79 (FRi-null) OPE1_0D (FRj-null))
     (nop)
     ()
)

; Media NOP
; A special case of mclracc
(dnmi mnop "Media nop"
      (NO-DIS (UNIT FM01) (FR500-MAJOR M-3))
     "mnop$pack"
     (emit mclracc pack (ACC40Sk 63) (A 1))
)

; A return instruction
(dnmi ret "return"
      (NO-DIS (UNIT B01) (FR500-MAJOR B-3) (FR400-MAJOR B-3))
      "ret$pack"
      (emit bralr pack (hint_taken 2))
)

(dnmi cmp "compare"
      (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
      "cmp$pack $GRi,$GRj,$ICCi_1"
      (emit subcc pack GRi GRj (GRk 0) ICCi_1)
)

(dnmi cmpi "compare immediate"
      (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
      "cmpi$pack $GRi,$s10,$ICCi_1"
      (emit subicc pack GRi s10 (GRk 0) ICCi_1)
)

(dnmi ccmp "conditional compare"
      (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
      "ccmp$pack $GRi,$GRj,$CCi,$cond"
      (emit csubcc pack GRi GRj (GRk 0) CCi cond)
)

(dnmi mov "move"
      (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1))
      "mov$pack $GRi,$GRk"
      (emit ori pack GRi (s12 0) GRk)
)   

(dnmi cmov "conditional move"
      (NO-DIS (UNIT I01) (FR500-MAJOR I-1) (FR400-MAJOR I-1) CONDITIONAL)
      "cmov$pack $GRi,$GRk,$CCi,$cond"
      (emit cor pack GRi (GRj 0) GRk CCi cond)
)