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
|
; $Id: IEMAllAImpl.asm $
;; @file
; IEM - Instruction Implementation in Assembly.
;
;
; Copyright (C) 2011-2023 Oracle and/or its affiliates.
;
; This file is part of VirtualBox base platform packages, as
; available from https://www.virtualbox.org.
;
; 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, in version 3 of the
; License.
;
; 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, see <https://www.gnu.org/licenses>.
;
; SPDX-License-Identifier: GPL-3.0-only
;
;*********************************************************************************************************************************
;* Header Files *
;*********************************************************************************************************************************
%include "VBox/asmdefs.mac"
%include "VBox/err.mac"
%include "iprt/x86.mac"
;*********************************************************************************************************************************
;* Defined Constants And Macros *
;*********************************************************************************************************************************
;;
; RET XX / RET wrapper for fastcall.
;
%macro RET_FASTCALL 1
%ifdef RT_ARCH_X86
%ifdef RT_OS_WINDOWS
ret %1
%else
ret
%endif
%else
ret
%endif
%endmacro
;;
; NAME for fastcall functions.
;
;; @todo 'global @fastcall@12' is still broken in yasm and requires dollar
; escaping (or whatever the dollar is good for here). Thus the ugly
; prefix argument.
;
%define NAME_FASTCALL(a_Name, a_cbArgs, a_Prefix) NAME(a_Name)
%ifdef RT_ARCH_X86
%ifdef RT_OS_WINDOWS
%undef NAME_FASTCALL
%define NAME_FASTCALL(a_Name, a_cbArgs, a_Prefix) a_Prefix %+ a_Name %+ @ %+ a_cbArgs
%endif
%endif
;;
; BEGINPROC for fastcall functions.
;
; @param 1 The function name (C).
; @param 2 The argument size on x86.
;
%macro BEGINPROC_FASTCALL 2
%ifdef ASM_FORMAT_PE
export %1=NAME_FASTCALL(%1,%2,$@)
%endif
%ifdef __NASM__
%ifdef ASM_FORMAT_OMF
export NAME(%1) NAME_FASTCALL(%1,%2,$@)
%endif
%endif
%ifndef ASM_FORMAT_BIN
global NAME_FASTCALL(%1,%2,$@)
%endif
NAME_FASTCALL(%1,%2,@):
IBT_ENDBRxx
%endmacro
;
; We employ some macro assembly here to hid the calling convention differences.
;
%ifdef RT_ARCH_AMD64
%macro PROLOGUE_1_ARGS 0
%endmacro
%macro EPILOGUE_1_ARGS 0
ret
%endmacro
%macro EPILOGUE_1_ARGS_EX 0
ret
%endmacro
%macro PROLOGUE_2_ARGS 0
%endmacro
%macro EPILOGUE_2_ARGS 0
ret
%endmacro
%macro EPILOGUE_2_ARGS_EX 1
ret
%endmacro
%macro PROLOGUE_3_ARGS 0
%endmacro
%macro EPILOGUE_3_ARGS 0
ret
%endmacro
%macro EPILOGUE_3_ARGS_EX 1
ret
%endmacro
%macro PROLOGUE_4_ARGS 0
%endmacro
%macro EPILOGUE_4_ARGS 0
ret
%endmacro
%macro EPILOGUE_4_ARGS_EX 1
ret
%endmacro
%ifdef ASM_CALL64_GCC
%define A0 rdi
%define A0_32 edi
%define A0_16 di
%define A0_8 dil
%define A1 rsi
%define A1_32 esi
%define A1_16 si
%define A1_8 sil
%define A2 rdx
%define A2_32 edx
%define A2_16 dx
%define A2_8 dl
%define A3 rcx
%define A3_32 ecx
%define A3_16 cx
%endif
%ifdef ASM_CALL64_MSC
%define A0 rcx
%define A0_32 ecx
%define A0_16 cx
%define A0_8 cl
%define A1 rdx
%define A1_32 edx
%define A1_16 dx
%define A1_8 dl
%define A2 r8
%define A2_32 r8d
%define A2_16 r8w
%define A2_8 r8b
%define A3 r9
%define A3_32 r9d
%define A3_16 r9w
%endif
%define T0 rax
%define T0_32 eax
%define T0_16 ax
%define T0_8 al
%define T1 r11
%define T1_32 r11d
%define T1_16 r11w
%define T1_8 r11b
%define T2 r10 ; only AMD64
%define T2_32 r10d
%define T2_16 r10w
%define T2_8 r10b
%else
; x86
%macro PROLOGUE_1_ARGS 0
push edi
%endmacro
%macro EPILOGUE_1_ARGS 0
pop edi
ret 0
%endmacro
%macro EPILOGUE_1_ARGS_EX 1
pop edi
ret %1
%endmacro
%macro PROLOGUE_2_ARGS 0
push edi
%endmacro
%macro EPILOGUE_2_ARGS 0
pop edi
ret 0
%endmacro
%macro EPILOGUE_2_ARGS_EX 1
pop edi
ret %1
%endmacro
%macro PROLOGUE_3_ARGS 0
push ebx
mov ebx, [esp + 4 + 4]
push edi
%endmacro
%macro EPILOGUE_3_ARGS_EX 1
%if (%1) < 4
%error "With three args, at least 4 bytes must be remove from the stack upon return (32-bit)."
%endif
pop edi
pop ebx
ret %1
%endmacro
%macro EPILOGUE_3_ARGS 0
EPILOGUE_3_ARGS_EX 4
%endmacro
%macro PROLOGUE_4_ARGS 0
push ebx
push edi
push esi
mov ebx, [esp + 12 + 4 + 0]
mov esi, [esp + 12 + 4 + 4]
%endmacro
%macro EPILOGUE_4_ARGS_EX 1
%if (%1) < 8
%error "With four args, at least 8 bytes must be remove from the stack upon return (32-bit)."
%endif
pop esi
pop edi
pop ebx
ret %1
%endmacro
%macro EPILOGUE_4_ARGS 0
EPILOGUE_4_ARGS_EX 8
%endmacro
%define A0 ecx
%define A0_32 ecx
%define A0_16 cx
%define A0_8 cl
%define A1 edx
%define A1_32 edx
%define A1_16 dx
%define A1_8 dl
%define A2 ebx
%define A2_32 ebx
%define A2_16 bx
%define A2_8 bl
%define A3 esi
%define A3_32 esi
%define A3_16 si
%define T0 eax
%define T0_32 eax
%define T0_16 ax
%define T0_8 al
%define T1 edi
%define T1_32 edi
%define T1_16 di
%endif
;;
; Load the relevant flags from [%1] if there are undefined flags (%3).
;
; @remarks Clobbers T0, stack. Changes EFLAGS.
; @param A2 The register pointing to the flags.
; @param 1 The parameter (A0..A3) pointing to the eflags.
; @param 2 The set of modified flags.
; @param 3 The set of undefined flags.
;
%macro IEM_MAYBE_LOAD_FLAGS 3
;%if (%3) != 0
pushf ; store current flags
mov T0_32, [%1] ; load the guest flags
and dword [xSP], ~(%2 | %3) ; mask out the modified and undefined flags
and T0_32, (%2 | %3) ; select the modified and undefined flags.
or [xSP], T0 ; merge guest flags with host flags.
popf ; load the mixed flags.
;%endif
%endmacro
;;
; Update the flag.
;
; @remarks Clobbers T0, T1, stack.
; @param 1 The register pointing to the EFLAGS.
; @param 2 The mask of modified flags to save.
; @param 3 The mask of undefined flags to (maybe) save.
;
%macro IEM_SAVE_FLAGS 3
%if (%2 | %3) != 0
pushf
pop T1
mov T0_32, [%1] ; flags
and T0_32, ~(%2 | %3) ; clear the modified & undefined flags.
and T1_32, (%2 | %3) ; select the modified and undefined flags.
or T0_32, T1_32 ; combine the flags.
mov [%1], T0_32 ; save the flags.
%endif
%endmacro
;;
; Calculates the new EFLAGS based on the CPU EFLAGS and fixed clear and set bit masks.
;
; @remarks Clobbers T0, T1, stack.
; @param 1 The register pointing to the EFLAGS.
; @param 2 The mask of modified flags to save.
; @param 3 Mask of additional flags to always clear
; @param 4 Mask of additional flags to always set.
;
%macro IEM_SAVE_AND_ADJUST_FLAGS 4
%if (%2 | %3 | %4) != 0
pushf
pop T1
mov T0_32, [%1] ; load flags.
and T0_32, ~(%2 | %3) ; clear the modified and always cleared flags.
and T1_32, (%2) ; select the modified flags.
or T0_32, T1_32 ; combine the flags.
%if (%4) != 0
or T0_32, %4 ; add the always set flags.
%endif
mov [%1], T0_32 ; save the result.
%endif
%endmacro
;;
; Calculates the new EFLAGS based on the CPU EFLAGS (%2), a clear mask (%3),
; signed input (%4[%5]) and parity index (%6).
;
; This is used by MUL and IMUL, where we got result (%4 & %6) in xAX which is
; also T0. So, we have to use T1 for the EFLAGS calculation and save T0/xAX
; while we extract the %2 flags from the CPU EFLAGS or use T2 (only AMD64).
;
; @remarks Clobbers T0, T1, stack, %6, EFLAGS.
; @param 1 The register pointing to the EFLAGS.
; @param 2 The mask of modified flags to save.
; @param 3 Mask of additional flags to always clear
; @param 4 The result register to set SF by.
; @param 5 The width of the %4 register in bits (8, 16, 32, or 64).
; @param 6 The (full) register containing the parity table index. Will be modified!
%macro IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF 6
%ifdef RT_ARCH_AMD64
pushf
pop T2
%else
push T0
pushf
pop T0
%endif
mov T1_32, [%1] ; load flags.
and T1_32, ~(%2 | %3 | X86_EFL_PF | X86_EFL_SF) ; clear the modified, always cleared flags and the two flags we calc.
%ifdef RT_ARCH_AMD64
and T2_32, (%2) ; select the modified flags.
or T1_32, T2_32 ; combine the flags.
%else
and T0_32, (%2) ; select the modified flags.
or T1_32, T0_32 ; combine the flags.
pop T0
%endif
; First calculate SF as it's likely to be refereing to the same register as %6 does.
bt %4, %5 - 1
jnc %%sf_clear
or T1_32, X86_EFL_SF
%%sf_clear:
; Parity last.
and %6, 0xff
%ifdef RT_ARCH_AMD64
lea T2, [NAME(g_afParity) xWrtRIP]
or T1_8, [T2 + %6]
%else
or T1_8, [NAME(g_afParity) + %6]
%endif
mov [%1], T1_32 ; save the result.
%endmacro
;;
; Calculates the new EFLAGS using fixed clear and set bit masks.
;
; @remarks Clobbers T0.
; @param 1 The register pointing to the EFLAGS.
; @param 2 Mask of additional flags to always clear
; @param 3 Mask of additional flags to always set.
;
%macro IEM_ADJUST_FLAGS 3
%if (%2 | %3) != 0
mov T0_32, [%1] ; Load flags.
%if (%2) != 0
and T0_32, ~(%2) ; Remove the always cleared flags.
%endif
%if (%3) != 0
or T0_32, %3 ; Add the always set flags.
%endif
mov [%1], T0_32 ; Save the result.
%endif
%endmacro
;;
; Calculates the new EFLAGS using fixed clear and set bit masks.
;
; @remarks Clobbers T0, %4, EFLAGS.
; @param 1 The register pointing to the EFLAGS.
; @param 2 Mask of additional flags to always clear
; @param 3 Mask of additional flags to always set.
; @param 4 The (full) register containing the parity table index. Will be modified!
;
%macro IEM_ADJUST_FLAGS_WITH_PARITY 4
mov T0_32, [%1] ; Load flags.
and T0_32, ~(%2 | X86_EFL_PF) ; Remove PF and the always cleared flags.
%if (%3) != 0
or T0_32, %3 ; Add the always set flags.
%endif
and %4, 0xff
%ifdef RT_ARCH_AMD64
lea T2, [NAME(g_afParity) xWrtRIP]
or T0_8, [T2 + %4]
%else
or T0_8, [NAME(g_afParity) + %4]
%endif
mov [%1], T0_32 ; Save the result.
%endmacro
;;
; Checks that the size expression %1 matches %2 adjusted according to
; RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK and for 256 entries.
; @param 1 The jump array size assembly expression.
; @param 2 The size without accounting for the IBT_ENDBRxx_WITHOUT_NOTRACK instruction.
;
%macro IEMCHECK_256_JUMP_ARRAY_SIZE 2
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
dw (0xffff - %2 - 256*4) + %1 ; will cause warning if entries are too big.
dw (0xffff + %2 + 256*4) - %1 ; will cause warning if entries are too small.
%else
dw (0xffff - %2) + %1 ; will cause warning if entries are too big.
dw (0xffff + %2) - %1 ; will cause warning if entries are too small.
%endif
%endmacro
;*********************************************************************************************************************************
;* External Symbols *
;*********************************************************************************************************************************
extern NAME(g_afParity)
;;
; Macro for implementing a binary operator.
;
; This will generate code for the 8, 16, 32 and 64 bit accesses with locked
; variants, except on 32-bit system where the 64-bit accesses requires hand
; coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; @param 1 The instruction mnemonic.
; @param 2 Non-zero if there should be a locked version.
; @param 3 The modified flags.
; @param 4 The undefined flags.
;
%macro IEMIMPL_BIN_OP 4
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 byte [A0], A1_8
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 word [A0], A1_16
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 dword [A0], A1_32
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 qword [A0], A1
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%if %2 != 0 ; locked versions requested?
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 byte [A0], A1_8
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8_locked
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 word [A0], A1_16
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16_locked
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 dword [A0], A1_32
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_locked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64_locked, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 qword [A0], A1
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64_locked
%endif ; RT_ARCH_AMD64
%endif ; locked
%endmacro
; instr,lock, modified-flags, undefined flags
IEMIMPL_BIN_OP add, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_BIN_OP adc, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_BIN_OP sub, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_BIN_OP sbb, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_BIN_OP or, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), X86_EFL_AF
IEMIMPL_BIN_OP xor, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), X86_EFL_AF
IEMIMPL_BIN_OP and, 1, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), X86_EFL_AF
IEMIMPL_BIN_OP cmp, 0, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_BIN_OP test, 0, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), X86_EFL_AF
;;
; Macro for implementing a binary operator, VEX variant with separate input/output.
;
; This will generate code for the 32 and 64 bit accesses, except on 32-bit system
; where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the first source register operand in A1, the second source register operand
; in A2 and a pointer to eflags in A3.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
%macro IEMIMPL_VEX_BIN_OP 3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%1 T0_32, A1_32, A2_32
mov [A0], T0_32
IEM_SAVE_FLAGS A3, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%1 T0, A1, A2
mov [A0], T0
IEM_SAVE_FLAGS A3, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%endmacro
; instr, modified-flags, undefined-flags
IEMIMPL_VEX_BIN_OP andn, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_AF | X86_EFL_PF)
IEMIMPL_VEX_BIN_OP bextr, (X86_EFL_OF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_SF | X86_EFL_AF | X86_EFL_PF)
IEMIMPL_VEX_BIN_OP bzhi, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_AF | X86_EFL_PF)
;;
; Macro for implementing BLSR, BLCMSK and BLSI (fallbacks implemented in C).
;
; This will generate code for the 32 and 64 bit accesses, except on 32-bit system
; where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
%macro IEMIMPL_VEX_BIN_OP_2 3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
mov T0_32, [A0]
%1 T0_32, A1_32
mov [A0], T0_32
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 12
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
mov T0, [A0]
%1 T0, A1
mov [A0], T0
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%endmacro
; instr, modified-flags, undefined-flags
IEMIMPL_VEX_BIN_OP_2 blsr, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_AF | X86_EFL_PF)
IEMIMPL_VEX_BIN_OP_2 blsmsk, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_AF | X86_EFL_PF)
IEMIMPL_VEX_BIN_OP_2 blsi, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_CF), (X86_EFL_AF | X86_EFL_PF)
;;
; Macro for implementing a binary operator w/o flags, VEX variant with separate input/output.
;
; This will generate code for the 32 and 64 bit accesses, except on 32-bit system
; where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the first source register operand in A1, the second source register operand
; in A2 and a pointer to eflags in A3.
;
; @param 1 The instruction mnemonic.
; @param 2 Fallback instruction if applicable.
; @param 3 Whether to emit fallback or not.
;
%macro IEMIMPL_VEX_BIN_OP_NOEFL 3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
%1 T0_32, A1_32, A2_32
mov [A0], T0_32
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%if %3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32_fallback, 12
PROLOGUE_3_ARGS
%ifdef ASM_CALL64_GCC
mov cl, A2_8
%2 A1_32, cl
mov [A0], A1_32
%else
xchg A2, A0
%2 A1_32, cl
mov [A2], A1_32
%endif
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_fallback
%endif
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 12
PROLOGUE_3_ARGS
%1 T0, A1, A2
mov [A0], T0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%if %3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64_fallback, 12
PROLOGUE_3_ARGS
%ifdef ASM_CALL64_GCC
mov cl, A2_8
%2 A1, cl
mov [A0], A1_32
%else
xchg A2, A0
%2 A1, cl
mov [A2], A1_32
%endif
mov [A0], A1
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64_fallback
%endif
%endif ; RT_ARCH_AMD64
%endmacro
; instr, fallback instr, emit fallback
IEMIMPL_VEX_BIN_OP_NOEFL sarx, sar, 1
IEMIMPL_VEX_BIN_OP_NOEFL shlx, shl, 1
IEMIMPL_VEX_BIN_OP_NOEFL shrx, shr, 1
IEMIMPL_VEX_BIN_OP_NOEFL pdep, nop, 0
IEMIMPL_VEX_BIN_OP_NOEFL pext, nop, 0
;
; RORX uses a immediate byte for the shift count, so we only do
; fallback implementation of that one.
;
BEGINPROC_FASTCALL iemAImpl_rorx_u32, 12
PROLOGUE_3_ARGS
%ifdef ASM_CALL64_GCC
mov cl, A2_8
ror A1_32, cl
mov [A0], A1_32
%else
xchg A2, A0
ror A1_32, cl
mov [A2], A1_32
%endif
EPILOGUE_3_ARGS
ENDPROC iemAImpl_rorx_u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_rorx_u64, 12
PROLOGUE_3_ARGS
%ifdef ASM_CALL64_GCC
mov cl, A2_8
ror A1, cl
mov [A0], A1_32
%else
xchg A2, A0
ror A1, cl
mov [A2], A1_32
%endif
mov [A0], A1
EPILOGUE_3_ARGS
ENDPROC iemAImpl_rorx_u64
%endif ; RT_ARCH_AMD64
;
; MULX
;
BEGINPROC_FASTCALL iemAImpl_mulx_u32, 16
PROLOGUE_4_ARGS
%ifdef ASM_CALL64_GCC
; A2_32 is EDX - prefect
mulx T0_32, T1_32, A3_32
mov [A1], T1_32 ; Low value first, as we should return the high part if same destination registers.
mov [A0], T0_32
%else
; A1 is xDX - must switch A1 and A2, so EDX=uSrc1
xchg A1, A2
mulx T0_32, T1_32, A3_32
mov [A2], T1_32 ; Low value first, as we should return the high part if same destination registers.
mov [A0], T0_32
%endif
EPILOGUE_4_ARGS
ENDPROC iemAImpl_mulx_u32
BEGINPROC_FASTCALL iemAImpl_mulx_u32_fallback, 16
PROLOGUE_4_ARGS
%ifdef ASM_CALL64_GCC
; A2_32 is EDX, T0_32 is EAX
mov eax, A3_32
mul A2_32
mov [A1], eax ; Low value first, as we should return the high part if same destination registers.
mov [A0], edx
%else
; A1 is xDX, T0_32 is EAX - must switch A1 and A2, so EDX=uSrc1
xchg A1, A2
mov eax, A3_32
mul A2_32
mov [A2], eax ; Low value first, as we should return the high part if same destination registers.
mov [A0], edx
%endif
EPILOGUE_4_ARGS
ENDPROC iemAImpl_mulx_u32_fallback
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_mulx_u64, 16
PROLOGUE_4_ARGS
%ifdef ASM_CALL64_GCC
; A2 is RDX - prefect
mulx T0, T1, A3
mov [A1], T1 ; Low value first, as we should return the high part if same destination registers.
mov [A0], T0
%else
; A1 is xDX - must switch A1 and A2, so RDX=uSrc1
xchg A1, A2
mulx T0, T1, A3
mov [A2], T1 ; Low value first, as we should return the high part if same destination registers.
mov [A0], T0
%endif
EPILOGUE_4_ARGS
ENDPROC iemAImpl_mulx_u64
BEGINPROC_FASTCALL iemAImpl_mulx_u64_fallback, 16
PROLOGUE_4_ARGS
%ifdef ASM_CALL64_GCC
; A2 is RDX, T0 is RAX
mov rax, A3
mul A2
mov [A1], rax ; Low value first, as we should return the high part if same destination registers.
mov [A0], rdx
%else
; A1 is xDX, T0 is RAX - must switch A1 and A2, so RDX=uSrc1
xchg A1, A2
mov rax, A3
mul A2
mov [A2], rax ; Low value first, as we should return the high part if same destination registers.
mov [A0], rdx
%endif
EPILOGUE_4_ARGS
ENDPROC iemAImpl_mulx_u64_fallback
%endif
;;
; Macro for implementing a bit operator.
;
; This will generate code for the 16, 32 and 64 bit accesses with locked
; variants, except on 32-bit system where the 64-bit accesses requires hand
; coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; @param 1 The instruction mnemonic.
; @param 2 Non-zero if there should be a locked version.
; @param 3 The modified flags.
; @param 4 The undefined flags.
;
%macro IEMIMPL_BIT_OP 4
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 word [A0], A1_16
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 dword [A0], A1_32
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
%1 qword [A0], A1
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%if %2 != 0 ; locked versions requested?
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 word [A0], A1_16
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16_locked
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 dword [A0], A1_32
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_locked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64_locked, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %3, %4
lock %1 qword [A0], A1
IEM_SAVE_FLAGS A2, %3, %4
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64_locked
%endif ; RT_ARCH_AMD64
%endif ; locked
%endmacro
IEMIMPL_BIT_OP bt, 0, (X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF)
IEMIMPL_BIT_OP btc, 1, (X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF)
IEMIMPL_BIT_OP bts, 1, (X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF)
IEMIMPL_BIT_OP btr, 1, (X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF)
;;
; Macro for implementing a bit search operator.
;
; This will generate code for the 16, 32 and 64 bit accesses, except on 32-bit
; system where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; In the ZF case the destination register is 'undefined', however it seems that
; both AMD and Intel just leaves it as is. The undefined EFLAGS differs between
; AMD and Intel and accoridng to https://www.sandpile.org/x86/flags.htm between
; Intel microarchitectures. We only implement 'intel' and 'amd' variation with
; the behaviour of more recent CPUs (Intel 10980X and AMD 3990X).
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
; @param 4 Non-zero if destination isn't written when ZF=1. Zero if always written.
;
%macro IEMIMPL_BIT_OP2 4
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0_16, A1_16
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0_16
.unchanged_dst:
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16 %+ _intel, 12
PROLOGUE_3_ARGS
%1 T1_16, A1_16
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T1_16
IEM_ADJUST_FLAGS_WITH_PARITY A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF | X86_EFL_ZF, 0, T1
EPILOGUE_3_ARGS
.unchanged_dst:
IEM_ADJUST_FLAGS A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF, X86_EFL_ZF | X86_EFL_PF
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16_intel
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16 %+ _amd, 12
PROLOGUE_3_ARGS
%1 T0_16, A1_16
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0_16
.unchanged_dst:
IEM_SAVE_AND_ADJUST_FLAGS A2, %2, 0, 0 ; Only the ZF flag is modified on AMD Zen 2.
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16_amd
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0_32, A1_32
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0_32
.unchanged_dst:
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32 %+ _intel, 12
PROLOGUE_3_ARGS
%1 T1_32, A1_32
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T1_32
IEM_ADJUST_FLAGS_WITH_PARITY A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF | X86_EFL_ZF, 0, T1
EPILOGUE_3_ARGS
.unchanged_dst:
IEM_ADJUST_FLAGS A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF, X86_EFL_ZF | X86_EFL_PF
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_intel
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32 %+ _amd, 12
PROLOGUE_3_ARGS
%1 T0_32, A1_32
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0_32
.unchanged_dst:
IEM_SAVE_AND_ADJUST_FLAGS A2, %2, 0, 0 ; Only the ZF flag is modified on AMD Zen 2.
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_amd
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0, A1
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0
.unchanged_dst:
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64 %+ _intel, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T1, A1
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T1
IEM_ADJUST_FLAGS_WITH_PARITY A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF | X86_EFL_ZF, 0, T1
EPILOGUE_3_ARGS
.unchanged_dst:
IEM_ADJUST_FLAGS A2, X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_CF, X86_EFL_ZF | X86_EFL_PF
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64_intel
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64 %+ _amd, 16
PROLOGUE_3_ARGS
%1 T0, A1
%if %4 != 0
jz .unchanged_dst
%endif
mov [A0], T0
.unchanged_dst:
IEM_SAVE_AND_ADJUST_FLAGS A2, %2, 0, 0 ; Only the ZF flag is modified on AMD Zen 2.
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64_amd
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_BIT_OP2 bsf, (X86_EFL_ZF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 1
IEMIMPL_BIT_OP2 bsr, (X86_EFL_ZF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 1
IEMIMPL_BIT_OP2 tzcnt, (X86_EFL_ZF | X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_PF), 0
IEMIMPL_BIT_OP2 lzcnt, (X86_EFL_ZF | X86_EFL_CF), (X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_PF), 0
;;
; Macro for implementing POPCNT.
;
; This will generate code for the 16, 32 and 64 bit accesses, except on 32-bit
; system where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; ASSUMES Intel and AMD set EFLAGS the same way.
;
; ASSUMES the instruction does not support memory destination.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
%macro IEMIMPL_BIT_OP3 3
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0_16, A1_16
mov [A0], T0_16
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0_32, A1_32
mov [A0], T0_32
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%1 T0, A1
mov [A0], T0
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_BIT_OP3 popcnt, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_OF | X86_EFL_SF | X86_EFL_AF | X86_EFL_PF), 0
;
; IMUL is also a similar but yet different case (no lock, no mem dst).
; The rDX:rAX variant of imul is handled together with mul further down.
;
BEGINCODE
; @param 1 EFLAGS that are modified.
; @param 2 Undefined EFLAGS.
; @param 3 Function suffix.
; @param 4 EFLAGS variation: 0 for native, 1 for intel (ignored),
; 2 for AMD (set AF, clear PF, ZF and SF).
%macro IEMIMPL_IMUL_TWO 4
BEGINPROC_FASTCALL iemAImpl_imul_two_u16 %+ %3, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %1, %2
imul A1_16, word [A0]
mov [A0], A1_16
%if %4 != 1
IEM_SAVE_FLAGS A2, %1, %2
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A2, %1, X86_EFL_AF | X86_EFL_ZF, A1_16, 16, A1
%endif
EPILOGUE_3_ARGS
ENDPROC iemAImpl_imul_two_u16 %+ %3
BEGINPROC_FASTCALL iemAImpl_imul_two_u32 %+ %3, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %1, %2
imul A1_32, dword [A0]
mov [A0], A1_32
%if %4 != 1
IEM_SAVE_FLAGS A2, %1, %2
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A2, %1, X86_EFL_AF | X86_EFL_ZF, A1_32, 32, A1
%endif
EPILOGUE_3_ARGS
ENDPROC iemAImpl_imul_two_u32 %+ %3
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_imul_two_u64 %+ %3, 16
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %1, %2
imul A1, qword [A0]
mov [A0], A1
%if %4 != 1
IEM_SAVE_FLAGS A2, %1, %2
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A2, %1, X86_EFL_AF | X86_EFL_ZF, A1, 64, A1
%endif
EPILOGUE_3_ARGS_EX 8
ENDPROC iemAImpl_imul_two_u64 %+ %3
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_IMUL_TWO X86_EFL_OF | X86_EFL_CF, X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF, , 0
IEMIMPL_IMUL_TWO X86_EFL_OF | X86_EFL_CF, 0, _intel, 1
IEMIMPL_IMUL_TWO X86_EFL_OF | X86_EFL_CF, 0, _amd, 2
;
; XCHG for memory operands. This implies locking. No flag changes.
;
; Each function takes two arguments, first the pointer to the memory,
; then the pointer to the register. They all return void.
;
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_xchg_u8_locked, 8
PROLOGUE_2_ARGS
mov T0_8, [A1]
xchg [A0], T0_8
mov [A1], T0_8
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u8_locked
BEGINPROC_FASTCALL iemAImpl_xchg_u16_locked, 8
PROLOGUE_2_ARGS
mov T0_16, [A1]
xchg [A0], T0_16
mov [A1], T0_16
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u16_locked
BEGINPROC_FASTCALL iemAImpl_xchg_u32_locked, 8
PROLOGUE_2_ARGS
mov T0_32, [A1]
xchg [A0], T0_32
mov [A1], T0_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u32_locked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_xchg_u64_locked, 8
PROLOGUE_2_ARGS
mov T0, [A1]
xchg [A0], T0
mov [A1], T0
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u64_locked
%endif
; Unlocked variants for fDisregardLock mode.
BEGINPROC_FASTCALL iemAImpl_xchg_u8_unlocked, 8
PROLOGUE_2_ARGS
mov T0_8, [A1]
mov T1_8, [A0]
mov [A0], T0_8
mov [A1], T1_8
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u8_unlocked
BEGINPROC_FASTCALL iemAImpl_xchg_u16_unlocked, 8
PROLOGUE_2_ARGS
mov T0_16, [A1]
mov T1_16, [A0]
mov [A0], T0_16
mov [A1], T1_16
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u16_unlocked
BEGINPROC_FASTCALL iemAImpl_xchg_u32_unlocked, 8
PROLOGUE_2_ARGS
mov T0_32, [A1]
mov T1_32, [A0]
mov [A0], T0_32
mov [A1], T1_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u32_unlocked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_xchg_u64_unlocked, 8
PROLOGUE_2_ARGS
mov T0, [A1]
mov T1, [A0]
mov [A0], T0
mov [A1], T1
EPILOGUE_2_ARGS
ENDPROC iemAImpl_xchg_u64_unlocked
%endif
;
; XADD for memory operands.
;
; Each function takes three arguments, first the pointer to the
; memory/register, then the pointer to the register, and finally a pointer to
; eflags. They all return void.
;
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_xadd_u8, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_8, [A1]
xadd [A0], T0_8
mov [A1], T0_8
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u8
BEGINPROC_FASTCALL iemAImpl_xadd_u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_16, [A1]
xadd [A0], T0_16
mov [A1], T0_16
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u16
BEGINPROC_FASTCALL iemAImpl_xadd_u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_32, [A1]
xadd [A0], T0_32
mov [A1], T0_32
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_xadd_u64, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0, [A1]
xadd [A0], T0
mov [A1], T0
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u64
%endif ; RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_xadd_u8_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_8, [A1]
lock xadd [A0], T0_8
mov [A1], T0_8
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u8_locked
BEGINPROC_FASTCALL iemAImpl_xadd_u16_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_16, [A1]
lock xadd [A0], T0_16
mov [A1], T0_16
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u16_locked
BEGINPROC_FASTCALL iemAImpl_xadd_u32_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0_32, [A1]
lock xadd [A0], T0_32
mov [A1], T0_32
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u32_locked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_xadd_u64_locked, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
mov T0, [A1]
lock xadd [A0], T0
mov [A1], T0
IEM_SAVE_FLAGS A2, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
EPILOGUE_3_ARGS
ENDPROC iemAImpl_xadd_u64_locked
%endif ; RT_ARCH_AMD64
;
; CMPXCHG8B.
;
; These are tricky register wise, so the code is duplicated for each calling
; convention.
;
; WARNING! This code make ASSUMPTIONS about which registers T1 and T0 are mapped to!
;
; C-proto:
; IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg8b,(uint64_t *pu64Dst, PRTUINT64U pu64EaxEdx, PRTUINT64U pu64EbxEcx,
; uint32_t *pEFlags));
;
; Note! Identical to iemAImpl_cmpxchg16b.
;
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_cmpxchg8b, 16
%ifdef RT_ARCH_AMD64
%ifdef ASM_CALL64_MSC
push rbx
mov r11, rdx ; pu64EaxEdx (is also T1)
mov r10, rcx ; pu64Dst
mov ebx, [r8]
mov ecx, [r8 + 4]
IEM_MAYBE_LOAD_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [r11]
mov edx, [r11 + 4]
cmpxchg8b [r10]
mov [r11], eax
mov [r11 + 4], edx
IEM_SAVE_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%else
push rbx
mov r10, rcx ; pEFlags
mov r11, rdx ; pu64EbxEcx (is also T1)
mov ebx, [r11]
mov ecx, [r11 + 4]
IEM_MAYBE_LOAD_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [rsi]
mov edx, [rsi + 4]
cmpxchg8b [rdi]
mov [rsi], eax
mov [rsi + 4], edx
IEM_SAVE_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%endif
%else
push esi
push edi
push ebx
push ebp
mov edi, ecx ; pu64Dst
mov esi, edx ; pu64EaxEdx
mov ecx, [esp + 16 + 4 + 0] ; pu64EbxEcx
mov ebp, [esp + 16 + 4 + 4] ; pEFlags
mov ebx, [ecx]
mov ecx, [ecx + 4]
IEM_MAYBE_LOAD_FLAGS ebp, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [esi]
mov edx, [esi + 4]
cmpxchg8b [edi]
mov [esi], eax
mov [esi + 4], edx
IEM_SAVE_FLAGS ebp, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, edi)
pop ebp
pop ebx
pop edi
pop esi
ret 8
%endif
ENDPROC iemAImpl_cmpxchg8b
BEGINPROC_FASTCALL iemAImpl_cmpxchg8b_locked, 16
%ifdef RT_ARCH_AMD64
%ifdef ASM_CALL64_MSC
push rbx
mov r11, rdx ; pu64EaxEdx (is also T1)
mov r10, rcx ; pu64Dst
mov ebx, [r8]
mov ecx, [r8 + 4]
IEM_MAYBE_LOAD_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [r11]
mov edx, [r11 + 4]
lock cmpxchg8b [r10]
mov [r11], eax
mov [r11 + 4], edx
IEM_SAVE_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%else
push rbx
mov r10, rcx ; pEFlags
mov r11, rdx ; pu64EbxEcx (is also T1)
mov ebx, [r11]
mov ecx, [r11 + 4]
IEM_MAYBE_LOAD_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [rsi]
mov edx, [rsi + 4]
lock cmpxchg8b [rdi]
mov [rsi], eax
mov [rsi + 4], edx
IEM_SAVE_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%endif
%else
push esi
push edi
push ebx
push ebp
mov edi, ecx ; pu64Dst
mov esi, edx ; pu64EaxEdx
mov ecx, [esp + 16 + 4 + 0] ; pu64EbxEcx
mov ebp, [esp + 16 + 4 + 4] ; pEFlags
mov ebx, [ecx]
mov ecx, [ecx + 4]
IEM_MAYBE_LOAD_FLAGS ebp, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov eax, [esi]
mov edx, [esi + 4]
lock cmpxchg8b [edi]
mov [esi], eax
mov [esi + 4], edx
IEM_SAVE_FLAGS ebp, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, edi)
pop ebp
pop ebx
pop edi
pop esi
ret 8
%endif
ENDPROC iemAImpl_cmpxchg8b_locked
%ifdef RT_ARCH_AMD64
;
; CMPXCHG16B.
;
; These are tricky register wise, so the code is duplicated for each calling
; convention.
;
; WARNING! This code make ASSUMPTIONS about which registers T1 and T0 are mapped to!
;
; C-proto:
; IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg16b,(PRTUINT128U pu128Dst, PRTUINT128U pu1284RaxRdx, PRTUINT128U pu128RbxRcx,
; uint32_t *pEFlags));
;
; Note! Identical to iemAImpl_cmpxchg8b.
;
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_cmpxchg16b, 16
%ifdef ASM_CALL64_MSC
push rbx
mov r11, rdx ; pu64RaxRdx (is also T1)
mov r10, rcx ; pu64Dst
mov rbx, [r8]
mov rcx, [r8 + 8]
IEM_MAYBE_LOAD_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov rax, [r11]
mov rdx, [r11 + 8]
cmpxchg16b [r10]
mov [r11], rax
mov [r11 + 8], rdx
IEM_SAVE_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%else
push rbx
mov r10, rcx ; pEFlags
mov r11, rdx ; pu64RbxRcx (is also T1)
mov rbx, [r11]
mov rcx, [r11 + 8]
IEM_MAYBE_LOAD_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov rax, [rsi]
mov rdx, [rsi + 8]
cmpxchg16b [rdi]
mov [rsi], rax
mov [rsi + 8], rdx
IEM_SAVE_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%endif
ENDPROC iemAImpl_cmpxchg16b
BEGINPROC_FASTCALL iemAImpl_cmpxchg16b_locked, 16
%ifdef ASM_CALL64_MSC
push rbx
mov r11, rdx ; pu64RaxRdx (is also T1)
mov r10, rcx ; pu64Dst
mov rbx, [r8]
mov rcx, [r8 + 8]
IEM_MAYBE_LOAD_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov rax, [r11]
mov rdx, [r11 + 8]
lock cmpxchg16b [r10]
mov [r11], rax
mov [r11 + 8], rdx
IEM_SAVE_FLAGS r9, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%else
push rbx
mov r10, rcx ; pEFlags
mov r11, rdx ; pu64RbxRcx (is also T1)
mov rbx, [r11]
mov rcx, [r11 + 8]
IEM_MAYBE_LOAD_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0 (eax)
mov rax, [rsi]
mov rdx, [rsi + 8]
lock cmpxchg16b [rdi]
mov [rsi], rax
mov [rsi + 8], rdx
IEM_SAVE_FLAGS r10, (X86_EFL_ZF), 0 ; clobbers T0+T1 (eax, r11)
pop rbx
ret
%endif
ENDPROC iemAImpl_cmpxchg16b_locked
%endif ; RT_ARCH_AMD64
;
; CMPXCHG.
;
; WARNING! This code make ASSUMPTIONS about which registers T1 and T0 are mapped to!
;
; C-proto:
; IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg,(uintX_t *puXDst, uintX_t puEax, uintX_t uReg, uint32_t *pEFlags));
;
BEGINCODE
%macro IEMIMPL_CMPXCHG 2
BEGINPROC_FASTCALL iemAImpl_cmpxchg_u8 %+ %2, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0 (eax)
mov al, [A1]
%1 cmpxchg [A0], A2_8
mov [A1], al
IEM_SAVE_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0+T1 (eax, r11/edi)
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cmpxchg_u8 %+ %2
BEGINPROC_FASTCALL iemAImpl_cmpxchg_u16 %+ %2, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0 (eax)
mov ax, [A1]
%1 cmpxchg [A0], A2_16
mov [A1], ax
IEM_SAVE_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0+T1 (eax, r11/edi)
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cmpxchg_u16 %+ %2
BEGINPROC_FASTCALL iemAImpl_cmpxchg_u32 %+ %2, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0 (eax)
mov eax, [A1]
%1 cmpxchg [A0], A2_32
mov [A1], eax
IEM_SAVE_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0+T1 (eax, r11/edi)
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cmpxchg_u32 %+ %2
BEGINPROC_FASTCALL iemAImpl_cmpxchg_u64 %+ %2, 16
%ifdef RT_ARCH_AMD64
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0 (eax)
mov rax, [A1]
%1 cmpxchg [A0], A2
mov [A1], rax
IEM_SAVE_FLAGS A3, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0+T1 (eax, r11/edi)
EPILOGUE_4_ARGS
%else
;
; Must use cmpxchg8b here. See also iemAImpl_cmpxchg8b.
;
push esi
push edi
push ebx
push ebp
mov edi, ecx ; pu64Dst
mov esi, edx ; pu64Rax
mov ecx, [esp + 16 + 4 + 0] ; pu64Reg - Note! Pointer on 32-bit hosts!
mov ebp, [esp + 16 + 4 + 4] ; pEFlags
mov ebx, [ecx]
mov ecx, [ecx + 4]
IEM_MAYBE_LOAD_FLAGS ebp, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0 (eax)
mov eax, [esi]
mov edx, [esi + 4]
lock cmpxchg8b [edi]
; cmpxchg8b doesn't set CF, PF, AF, SF and OF, so we have to do that.
jz .cmpxchg8b_not_equal
cmp eax, eax ; just set the other flags.
.store:
mov [esi], eax
mov [esi + 4], edx
IEM_SAVE_FLAGS ebp, (X86_EFL_ZF | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_SF | X86_EFL_OF), 0 ; clobbers T0+T1 (eax, edi)
pop ebp
pop ebx
pop edi
pop esi
ret 8
.cmpxchg8b_not_equal:
cmp [esi + 4], edx ;; @todo FIXME - verify 64-bit compare implementation
jne .store
cmp [esi], eax
jmp .store
%endif
ENDPROC iemAImpl_cmpxchg_u64 %+ %2
%endmacro ; IEMIMPL_CMPXCHG
IEMIMPL_CMPXCHG , ,
IEMIMPL_CMPXCHG lock, _locked
;;
; Macro for implementing a unary operator.
;
; This will generate code for the 8, 16, 32 and 64 bit accesses with locked
; variants, except on 32-bit system where the 64-bit accesses requires hand
; coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the source register operand in A1 and a pointer to eflags in A2.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
%macro IEMIMPL_UNARY_OP 3
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
%1 byte [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8_locked, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
lock %1 byte [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8_locked
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
%1 word [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16_locked, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
lock %1 word [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16_locked
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
%1 dword [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32_locked, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
lock %1 dword [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32_locked
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
%1 qword [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64_locked, 8
PROLOGUE_2_ARGS
IEM_MAYBE_LOAD_FLAGS A1, %2, %3
lock %1 qword [A0]
IEM_SAVE_FLAGS A1, %2, %3
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64_locked
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_UNARY_OP inc, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF), 0
IEMIMPL_UNARY_OP dec, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF), 0
IEMIMPL_UNARY_OP neg, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0
IEMIMPL_UNARY_OP not, 0, 0
;
; BSWAP. No flag changes.
;
; Each function takes one argument, pointer to the value to bswap
; (input/output). They all return void.
;
BEGINPROC_FASTCALL iemAImpl_bswap_u16, 4
PROLOGUE_1_ARGS
mov T0_32, [A0] ; just in case any of the upper bits are used.
db 66h
bswap T0_32
mov [A0], T0_32
EPILOGUE_1_ARGS
ENDPROC iemAImpl_bswap_u16
BEGINPROC_FASTCALL iemAImpl_bswap_u32, 4
PROLOGUE_1_ARGS
mov T0_32, [A0]
bswap T0_32
mov [A0], T0_32
EPILOGUE_1_ARGS
ENDPROC iemAImpl_bswap_u32
BEGINPROC_FASTCALL iemAImpl_bswap_u64, 4
%ifdef RT_ARCH_AMD64
PROLOGUE_1_ARGS
mov T0, [A0]
bswap T0
mov [A0], T0
EPILOGUE_1_ARGS
%else
PROLOGUE_1_ARGS
mov T0, [A0]
mov T1, [A0 + 4]
bswap T0
bswap T1
mov [A0 + 4], T0
mov [A0], T1
EPILOGUE_1_ARGS
%endif
ENDPROC iemAImpl_bswap_u64
;;
; Macro for implementing a shift operation.
;
; This will generate code for the 8, 16, 32 and 64 bit accesses, except on
; 32-bit system where the 64-bit accesses requires hand coding.
;
; All the functions takes a pointer to the destination memory operand in A0,
; the shift count in A1 and a pointer to eflags in A2.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
; Makes ASSUMPTIONS about A0, A1 and A2 assignments.
;
; @note the _intel and _amd variants are implemented in C.
;
%macro IEMIMPL_SHIFT_OP 3
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%ifdef ASM_CALL64_GCC
mov cl, A1_8
%1 byte [A0], cl
%else
xchg A1, A0
%1 byte [A1], cl
%endif
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%ifdef ASM_CALL64_GCC
mov cl, A1_8
%1 word [A0], cl
%else
xchg A1, A0
%1 word [A1], cl
%endif
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%ifdef ASM_CALL64_GCC
mov cl, A1_8
%1 dword [A0], cl
%else
xchg A1, A0
%1 dword [A1], cl
%endif
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
%ifdef ASM_CALL64_GCC
mov cl, A1_8
%1 qword [A0], cl
%else
xchg A1, A0
%1 qword [A1], cl
%endif
IEM_SAVE_FLAGS A2, %2, %3
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_SHIFT_OP rol, (X86_EFL_OF | X86_EFL_CF), 0
IEMIMPL_SHIFT_OP ror, (X86_EFL_OF | X86_EFL_CF), 0
IEMIMPL_SHIFT_OP rcl, (X86_EFL_OF | X86_EFL_CF), 0
IEMIMPL_SHIFT_OP rcr, (X86_EFL_OF | X86_EFL_CF), 0
IEMIMPL_SHIFT_OP shl, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), (X86_EFL_AF)
IEMIMPL_SHIFT_OP shr, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), (X86_EFL_AF)
IEMIMPL_SHIFT_OP sar, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), (X86_EFL_AF)
;;
; Macro for implementing a double precision shift operation.
;
; This will generate code for the 16, 32 and 64 bit accesses, except on
; 32-bit system where the 64-bit accesses requires hand coding.
;
; The functions takes the destination operand (r/m) in A0, the source (reg) in
; A1, the shift count in A2 and a pointer to the eflags variable/register in A3.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
;
; Makes ASSUMPTIONS about A0, A1, A2 and A3 assignments.
;
; @note the _intel and _amd variants are implemented in C.
;
%macro IEMIMPL_SHIFT_DBL_OP 3
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%ifdef ASM_CALL64_GCC
xchg A3, A2
%1 [A0], A1_16, cl
xchg A3, A2
%else
xchg A0, A2
%1 [A2], A1_16, cl
%endif
IEM_SAVE_FLAGS A3, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%ifdef ASM_CALL64_GCC
xchg A3, A2
%1 [A0], A1_32, cl
xchg A3, A2
%else
xchg A0, A2
%1 [A2], A1_32, cl
%endif
IEM_SAVE_FLAGS A3, %2, %3
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 20
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%ifdef ASM_CALL64_GCC
xchg A3, A2
%1 [A0], A1, cl
xchg A3, A2
%else
xchg A0, A2
%1 [A2], A1, cl
%endif
IEM_SAVE_FLAGS A3, %2, %3
EPILOGUE_4_ARGS_EX 12
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif ; RT_ARCH_AMD64
%endmacro
IEMIMPL_SHIFT_DBL_OP shld, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), (X86_EFL_AF)
IEMIMPL_SHIFT_DBL_OP shrd, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_PF | X86_EFL_CF), (X86_EFL_AF)
;;
; Macro for implementing a multiplication operations.
;
; This will generate code for the 8, 16, 32 and 64 bit accesses, except on
; 32-bit system where the 64-bit accesses requires hand coding.
;
; The 8-bit function only operates on AX, so it takes no DX pointer. The other
; functions takes a pointer to rAX in A0, rDX in A1, the operand in A2 and a
; pointer to eflags in A3.
;
; The functions all return 0 so the caller can be used for div/idiv as well as
; for the mul/imul implementation.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
; @param 4 Name suffix.
; @param 5 EFLAGS behaviour: 0 for native, 1 for intel and 2 for AMD.
;
; Makes ASSUMPTIONS about A0, A1, A2, A3, T0 and T1 assignments.
;
%macro IEMIMPL_MUL_OP 5
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8 %+ %4, 12
PROLOGUE_3_ARGS
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
mov al, [A0]
%1 A1_8
mov [A0], ax
%if %5 != 1
IEM_SAVE_FLAGS A2, %2, %3
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A2, %2, X86_EFL_AF | X86_EFL_ZF, ax, 8, xAX
%endif
xor eax, eax
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u8 %+ %4
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16 %+ %4, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
mov ax, [A0]
%ifdef ASM_CALL64_GCC
%1 A2_16
mov [A0], ax
mov [A1], dx
%else
mov T1, A1
%1 A2_16
mov [A0], ax
mov [T1], dx
%endif
%if %5 != 1
IEM_SAVE_FLAGS A3, %2, %3
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A3, %2, X86_EFL_AF | X86_EFL_ZF, ax, 16, xAX
%endif
xor eax, eax
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u16 %+ %4
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32 %+ %4, 16
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
mov eax, [A0]
%ifdef ASM_CALL64_GCC
%1 A2_32
mov [A0], eax
mov [A1], edx
%else
mov T1, A1
%1 A2_32
mov [A0], eax
mov [T1], edx
%endif
%if %5 != 1
IEM_SAVE_FLAGS A3, %2, %3
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A3, %2, X86_EFL_AF | X86_EFL_ZF, eax, 32, xAX
%endif
xor eax, eax
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u32 %+ %4
%ifdef RT_ARCH_AMD64 ; The 32-bit host version lives in IEMAllAImplC.cpp.
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64 %+ %4, 20
PROLOGUE_4_ARGS
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
mov rax, [A0]
%ifdef ASM_CALL64_GCC
%1 A2
mov [A0], rax
mov [A1], rdx
%else
mov T1, A1
%1 A2
mov [A0], rax
mov [T1], rdx
%endif
%if %5 != 1
IEM_SAVE_FLAGS A3, %2, %3
%else
IEM_SAVE_FLAGS_ADJUST_AND_CALC_SF_PF A3, %2, X86_EFL_AF | X86_EFL_ZF, rax, 64, xAX
%endif
xor eax, eax
EPILOGUE_4_ARGS_EX 12
ENDPROC iemAImpl_ %+ %1 %+ _u64 %+ %4
%endif ; !RT_ARCH_AMD64
%endmacro
IEMIMPL_MUL_OP mul, (X86_EFL_OF | X86_EFL_CF), (X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF), , 0
IEMIMPL_MUL_OP mul, (X86_EFL_OF | X86_EFL_CF), 0, _intel, 1
IEMIMPL_MUL_OP mul, (X86_EFL_OF | X86_EFL_CF), 0, _amd, 2
IEMIMPL_MUL_OP imul, (X86_EFL_OF | X86_EFL_CF), (X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF), , 0
IEMIMPL_MUL_OP imul, (X86_EFL_OF | X86_EFL_CF), 0, _intel, 1
IEMIMPL_MUL_OP imul, (X86_EFL_OF | X86_EFL_CF), 0, _amd, 2
BEGINCODE
;;
; Worker function for negating a 32-bit number in T1:T0
; @uses None (T0,T1)
BEGINPROC iemAImpl_negate_T0_T1_u32
push 0
push 0
xchg T0_32, [xSP]
xchg T1_32, [xSP + xCB]
sub T0_32, [xSP]
sbb T1_32, [xSP + xCB]
add xSP, xCB*2
ret
ENDPROC iemAImpl_negate_T0_T1_u32
%ifdef RT_ARCH_AMD64
;;
; Worker function for negating a 64-bit number in T1:T0
; @uses None (T0,T1)
BEGINPROC iemAImpl_negate_T0_T1_u64
push 0
push 0
xchg T0, [xSP]
xchg T1, [xSP + xCB]
sub T0, [xSP]
sbb T1, [xSP + xCB]
add xSP, xCB*2
ret
ENDPROC iemAImpl_negate_T0_T1_u64
%endif
;;
; Macro for implementing a division operations.
;
; This will generate code for the 8, 16, 32 and 64 bit accesses, except on
; 32-bit system where the 64-bit accesses requires hand coding.
;
; The 8-bit function only operates on AX, so it takes no DX pointer. The other
; functions takes a pointer to rAX in A0, rDX in A1, the operand in A2 and a
; pointer to eflags in A3.
;
; The functions all return 0 on success and -1 if a divide error should be
; raised by the caller.
;
; @param 1 The instruction mnemonic.
; @param 2 The modified flags.
; @param 3 The undefined flags.
; @param 4 1 if signed, 0 if unsigned.
; @param 5 Function suffix.
; @param 6 EFLAGS variation: 0 for native, 1 for intel (ignored),
; 2 for AMD (set AF, clear PF, ZF and SF).
;
; Makes ASSUMPTIONS about A0, A1, A2, A3, T0 and T1 assignments.
;
%macro IEMIMPL_DIV_OP 6
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u8 %+ %5, 12
PROLOGUE_3_ARGS
; div by chainsaw check.
test A1_8, A1_8
jz .div_zero
; Overflow check - unsigned division is simple to verify, haven't
; found a simple way to check signed division yet unfortunately.
%if %4 == 0
cmp [A0 + 1], A1_8
jae .div_overflow
%else
mov T0_16, [A0] ; T0 = dividend
mov T1, A1 ; T1 = saved divisor (because of missing T1_8 in 32-bit)
test A1_8, A1_8
js .divisor_negative
test T0_16, T0_16
jns .both_positive
neg T0_16
.one_of_each: ; OK range is 2^(result-with - 1) + (divisor - 1).
push T0 ; Start off like unsigned below.
shr T0_16, 7
cmp T0_8, A1_8
pop T0
jb .div_no_overflow
ja .div_overflow
and T0_8, 0x7f ; Special case for covering (divisor - 1).
cmp T0_8, A1_8
jae .div_overflow
jmp .div_no_overflow
.divisor_negative:
neg A1_8
test T0_16, T0_16
jns .one_of_each
neg T0_16
.both_positive: ; Same as unsigned shifted by sign indicator bit.
shr T0_16, 7
cmp T0_8, A1_8
jae .div_overflow
.div_no_overflow:
mov A1, T1 ; restore divisor
%endif
IEM_MAYBE_LOAD_FLAGS A2, %2, %3
mov ax, [A0]
%1 A1_8
mov [A0], ax
%if %6 == 2 ; AMD64 3990X: Set AF and clear PF, ZF and SF.
IEM_ADJUST_FLAGS A2, X86_EFL_PF | X86_EFL_ZF | X86_EFL_SF, X86_EFL_AF
%else
IEM_SAVE_FLAGS A2, %2, %3
%endif
xor eax, eax
.return:
EPILOGUE_3_ARGS
.div_zero:
.div_overflow:
mov eax, -1
jmp .return
ENDPROC iemAImpl_ %+ %1 %+ _u8 %+ %5
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u16 %+ %5, 16
PROLOGUE_4_ARGS
; div by chainsaw check.
test A2_16, A2_16
jz .div_zero
; Overflow check - unsigned division is simple to verify, haven't
; found a simple way to check signed division yet unfortunately.
%if %4 == 0
cmp [A1], A2_16
jae .div_overflow
%else
mov T0_16, [A1]
shl T0_32, 16
mov T0_16, [A0] ; T0 = dividend
mov T1, A2 ; T1 = divisor
test T1_16, T1_16
js .divisor_negative
test T0_32, T0_32
jns .both_positive
neg T0_32
.one_of_each: ; OK range is 2^(result-with - 1) + (divisor - 1).
push T0 ; Start off like unsigned below.
shr T0_32, 15
cmp T0_16, T1_16
pop T0
jb .div_no_overflow
ja .div_overflow
and T0_16, 0x7fff ; Special case for covering (divisor - 1).
cmp T0_16, T1_16
jae .div_overflow
jmp .div_no_overflow
.divisor_negative:
neg T1_16
test T0_32, T0_32
jns .one_of_each
neg T0_32
.both_positive: ; Same as unsigned shifted by sign indicator bit.
shr T0_32, 15
cmp T0_16, T1_16
jae .div_overflow
.div_no_overflow:
%endif
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
%ifdef ASM_CALL64_GCC
mov T1, A2
mov ax, [A0]
mov dx, [A1]
%1 T1_16
mov [A0], ax
mov [A1], dx
%else
mov T1, A1
mov ax, [A0]
mov dx, [T1]
%1 A2_16
mov [A0], ax
mov [T1], dx
%endif
%if %6 == 2 ; AMD64 3990X: Set AF and clear PF, ZF and SF.
IEM_ADJUST_FLAGS A3, X86_EFL_PF | X86_EFL_ZF | X86_EFL_SF, X86_EFL_AF
%else
IEM_SAVE_FLAGS A3, %2, %3
%endif
xor eax, eax
.return:
EPILOGUE_4_ARGS
.div_zero:
.div_overflow:
mov eax, -1
jmp .return
ENDPROC iemAImpl_ %+ %1 %+ _u16 %+ %5
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u32 %+ %5, 16
PROLOGUE_4_ARGS
; div by chainsaw check.
test A2_32, A2_32
jz .div_zero
; Overflow check - unsigned division is simple to verify, haven't
; found a simple way to check signed division yet unfortunately.
%if %4 == 0
cmp [A1], A2_32
jae .div_overflow
%else
push A2 ; save A2 so we modify it (we out of regs on x86).
mov T0_32, [A0] ; T0 = dividend low
mov T1_32, [A1] ; T1 = dividend high
test A2_32, A2_32
js .divisor_negative
test T1_32, T1_32
jns .both_positive
call NAME(iemAImpl_negate_T0_T1_u32)
.one_of_each: ; OK range is 2^(result-with - 1) + (divisor - 1).
push T0 ; Start off like unsigned below.
shl T1_32, 1
shr T0_32, 31
or T1_32, T0_32
cmp T1_32, A2_32
pop T0
jb .div_no_overflow
ja .div_overflow
and T0_32, 0x7fffffff ; Special case for covering (divisor - 1).
cmp T0_32, A2_32
jae .div_overflow
jmp .div_no_overflow
.divisor_negative:
neg A2_32
test T1_32, T1_32
jns .one_of_each
call NAME(iemAImpl_negate_T0_T1_u32)
.both_positive: ; Same as unsigned shifted by sign indicator bit.
shl T1_32, 1
shr T0_32, 31
or T1_32, T0_32
cmp T1_32, A2_32
jae .div_overflow
.div_no_overflow:
pop A2
%endif
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
mov eax, [A0]
%ifdef ASM_CALL64_GCC
mov T1, A2
mov eax, [A0]
mov edx, [A1]
%1 T1_32
mov [A0], eax
mov [A1], edx
%else
mov T1, A1
mov eax, [A0]
mov edx, [T1]
%1 A2_32
mov [A0], eax
mov [T1], edx
%endif
%if %6 == 2 ; AMD64 3990X: Set AF and clear PF, ZF and SF.
IEM_ADJUST_FLAGS A3, X86_EFL_PF | X86_EFL_ZF | X86_EFL_SF, X86_EFL_AF
%else
IEM_SAVE_FLAGS A3, %2, %3
%endif
xor eax, eax
.return:
EPILOGUE_4_ARGS
.div_overflow:
%if %4 != 0
pop A2
%endif
.div_zero:
mov eax, -1
jmp .return
ENDPROC iemAImpl_ %+ %1 %+ _u32 %+ %5
%ifdef RT_ARCH_AMD64 ; The 32-bit host version lives in IEMAllAImplC.cpp.
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64 %+ %5, 20
PROLOGUE_4_ARGS
test A2, A2
jz .div_zero
%if %4 == 0
cmp [A1], A2
jae .div_overflow
%else
push A2 ; save A2 so we modify it (we out of regs on x86).
mov T0, [A0] ; T0 = dividend low
mov T1, [A1] ; T1 = dividend high
test A2, A2
js .divisor_negative
test T1, T1
jns .both_positive
call NAME(iemAImpl_negate_T0_T1_u64)
.one_of_each: ; OK range is 2^(result-with - 1) + (divisor - 1).
push T0 ; Start off like unsigned below.
shl T1, 1
shr T0, 63
or T1, T0
cmp T1, A2
pop T0
jb .div_no_overflow
ja .div_overflow
mov T1, 0x7fffffffffffffff
and T0, T1 ; Special case for covering (divisor - 1).
cmp T0, A2
jae .div_overflow
jmp .div_no_overflow
.divisor_negative:
neg A2
test T1, T1
jns .one_of_each
call NAME(iemAImpl_negate_T0_T1_u64)
.both_positive: ; Same as unsigned shifted by sign indicator bit.
shl T1, 1
shr T0, 63
or T1, T0
cmp T1, A2
jae .div_overflow
.div_no_overflow:
pop A2
%endif
IEM_MAYBE_LOAD_FLAGS A3, %2, %3
mov rax, [A0]
%ifdef ASM_CALL64_GCC
mov T1, A2
mov rax, [A0]
mov rdx, [A1]
%1 T1
mov [A0], rax
mov [A1], rdx
%else
mov T1, A1
mov rax, [A0]
mov rdx, [T1]
%1 A2
mov [A0], rax
mov [T1], rdx
%endif
%if %6 == 2 ; AMD64 3990X: Set AF and clear PF, ZF and SF.
IEM_ADJUST_FLAGS A3, X86_EFL_PF | X86_EFL_ZF | X86_EFL_SF, X86_EFL_AF
%else
IEM_SAVE_FLAGS A3, %2, %3
%endif
xor eax, eax
.return:
EPILOGUE_4_ARGS_EX 12
.div_overflow:
%if %4 != 0
pop A2
%endif
.div_zero:
mov eax, -1
jmp .return
ENDPROC iemAImpl_ %+ %1 %+ _u64 %+ %5
%endif ; !RT_ARCH_AMD64
%endmacro
IEMIMPL_DIV_OP div, 0, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 0, , 0
IEMIMPL_DIV_OP div, 0, 0, 0, _intel, 1
IEMIMPL_DIV_OP div, 0, 0, 0, _amd, 2
IEMIMPL_DIV_OP idiv, 0, (X86_EFL_OF | X86_EFL_SF | X86_EFL_ZF | X86_EFL_AF | X86_EFL_PF | X86_EFL_CF), 1, , 0
IEMIMPL_DIV_OP idiv, 0, 0, 1, _intel, 1
IEMIMPL_DIV_OP idiv, 0, 0, 1, _amd, 2
;;
; Macro for implementing memory fence operation.
;
; No return value, no operands or anything.
;
; @param 1 The instruction.
;
%macro IEMIMPL_MEM_FENCE 1
BEGINCODE
BEGINPROC_FASTCALL iemAImpl_ %+ %1, 0
%1
ret
ENDPROC iemAImpl_ %+ %1
%endmacro
IEMIMPL_MEM_FENCE lfence
IEMIMPL_MEM_FENCE sfence
IEMIMPL_MEM_FENCE mfence
;;
; Alternative for non-SSE2 host.
;
BEGINPROC_FASTCALL iemAImpl_alt_mem_fence, 0
push xAX
xchg xAX, [xSP]
add xSP, xCB
ret
ENDPROC iemAImpl_alt_mem_fence
;;
; Initialize the FPU for the actual instruction being emulated, this means
; loading parts of the guest's control word and status word.
;
; @uses 24 bytes of stack. T0, T1
; @param 1 Expression giving the address of the FXSTATE of the guest.
;
%macro FPU_LD_FXSTATE_FCW_AND_SAFE_FSW 1
fnstenv [xSP]
; FCW - for exception, precision and rounding control.
movzx T0, word [%1 + X86FXSTATE.FCW]
and T0, X86_FCW_MASK_ALL | X86_FCW_PC_MASK | X86_FCW_RC_MASK
mov [xSP + X86FSTENV32P.FCW], T0_16
; FSW - for undefined C0, C1, C2, and C3.
movzx T1, word [%1 + X86FXSTATE.FSW]
and T1, X86_FSW_C_MASK
movzx T0, word [xSP + X86FSTENV32P.FSW]
and T0, X86_FSW_TOP_MASK
or T0, T1
mov [xSP + X86FSTENV32P.FSW], T0_16
fldenv [xSP]
%endmacro
;;
; Initialize the FPU for the actual instruction being emulated, this means
; loading parts of the guest's control word, status word, and update the
; tag word for the top register if it's empty.
;
; ASSUMES actual TOP=7
;
; @uses 24 bytes of stack. T0, T1
; @param 1 Expression giving the address of the FXSTATE of the guest.
;
%macro FPU_LD_FXSTATE_FCW_AND_SAFE_FSW_AND_FTW_0 1
fnstenv [xSP]
; FCW - for exception, precision and rounding control.
movzx T0_32, word [%1 + X86FXSTATE.FCW]
and T0_32, X86_FCW_MASK_ALL | X86_FCW_PC_MASK | X86_FCW_RC_MASK
mov [xSP + X86FSTENV32P.FCW], T0_16
; FSW - for undefined C0, C1, C2, and C3.
movzx T1_32, word [%1 + X86FXSTATE.FSW]
and T1_32, X86_FSW_C_MASK
movzx T0_32, word [xSP + X86FSTENV32P.FSW]
and T0_32, X86_FSW_TOP_MASK
or T0_32, T1_32
mov [xSP + X86FSTENV32P.FSW], T0_16
; FTW - Only for ST0 (in/out).
movzx T1_32, word [%1 + X86FXSTATE.FSW]
shr T1_32, X86_FSW_TOP_SHIFT
and T1_32, X86_FSW_TOP_SMASK
bt [%1 + X86FXSTATE.FTW], T1_16 ; Empty if FTW bit is clear. Fixed register order.
jc %%st0_not_empty
or word [xSP + X86FSTENV32P.FTW], 0c000h ; TOP=7, so set TAG(7)=3
%%st0_not_empty:
fldenv [xSP]
%endmacro
;;
; Need to move this as well somewhere better?
;
struc IEMFPURESULT
.r80Result resw 5
.FSW resw 1
endstruc
;;
; Need to move this as well somewhere better?
;
struc IEMFPURESULTTWO
.r80Result1 resw 5
.FSW resw 1
.r80Result2 resw 5
endstruc
;
;---------------------- 16-bit signed integer operations ----------------------
;
;;
; Converts a 16-bit floating point value to a 80-bit one (fpu register).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 16-bit floating point value to convert.
;
BEGINPROC_FASTCALL iemAImpl_fild_r80_from_i16, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fild word [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fild_r80_from_i16
;;
; Store a 80-bit floating point value (register) as a 16-bit signed integer (memory).
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 16-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fist_r80_to_i16, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fistp word [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fist_r80_to_i16
;;
; Store a 80-bit floating point value (register) as a 16-bit signed integer
; (memory) with truncation.
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 16-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fistt_r80_to_i16, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fisttp word [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fistt_r80_to_i16
;;
; FPU instruction working on one 80-bit and one 16-bit signed integer value.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 16-bit value.
;
%macro IEMIMPL_FPU_R80_BY_I16 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_i16, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 word [A3]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_i16
%endmacro
IEMIMPL_FPU_R80_BY_I16 fiadd
IEMIMPL_FPU_R80_BY_I16 fimul
IEMIMPL_FPU_R80_BY_I16 fisub
IEMIMPL_FPU_R80_BY_I16 fisubr
IEMIMPL_FPU_R80_BY_I16 fidiv
IEMIMPL_FPU_R80_BY_I16 fidivr
;;
; FPU instruction working on one 80-bit and one 16-bit signed integer value,
; only returning FSW.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Where to store the output FSW.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 64-bit value.
;
%macro IEMIMPL_FPU_R80_BY_I16_FSW 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_i16, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 word [A3]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_i16
%endmacro
IEMIMPL_FPU_R80_BY_I16_FSW ficom
;
;---------------------- 32-bit signed integer operations ----------------------
;
;;
; Converts a 32-bit floating point value to a 80-bit one (fpu register).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 32-bit floating point value to convert.
;
BEGINPROC_FASTCALL iemAImpl_fild_r80_from_i32, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fild dword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fild_r80_from_i32
;;
; Store a 80-bit floating point value (register) as a 32-bit signed integer (memory).
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 32-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fist_r80_to_i32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fistp dword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fist_r80_to_i32
;;
; Store a 80-bit floating point value (register) as a 32-bit signed integer
; (memory) with truncation.
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 32-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fistt_r80_to_i32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fisttp dword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fistt_r80_to_i32
;;
; FPU instruction working on one 80-bit and one 32-bit signed integer value.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 32-bit value.
;
%macro IEMIMPL_FPU_R80_BY_I32 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_i32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 dword [A3]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_i32
%endmacro
IEMIMPL_FPU_R80_BY_I32 fiadd
IEMIMPL_FPU_R80_BY_I32 fimul
IEMIMPL_FPU_R80_BY_I32 fisub
IEMIMPL_FPU_R80_BY_I32 fisubr
IEMIMPL_FPU_R80_BY_I32 fidiv
IEMIMPL_FPU_R80_BY_I32 fidivr
;;
; FPU instruction working on one 80-bit and one 32-bit signed integer value,
; only returning FSW.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Where to store the output FSW.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 64-bit value.
;
%macro IEMIMPL_FPU_R80_BY_I32_FSW 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_i32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 dword [A3]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_i32
%endmacro
IEMIMPL_FPU_R80_BY_I32_FSW ficom
;
;---------------------- 64-bit signed integer operations ----------------------
;
;;
; Converts a 64-bit floating point value to a 80-bit one (fpu register).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 64-bit floating point value to convert.
;
BEGINPROC_FASTCALL iemAImpl_fild_r80_from_i64, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fild qword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fild_r80_from_i64
;;
; Store a 80-bit floating point value (register) as a 64-bit signed integer (memory).
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 64-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fist_r80_to_i64, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fistp qword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fist_r80_to_i64
;;
; Store a 80-bit floating point value (register) as a 64-bit signed integer
; (memory) with truncation.
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 64-bit signed integer value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fistt_r80_to_i64, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fisttp qword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fistt_r80_to_i64
;
;---------------------- 32-bit floating point operations ----------------------
;
;;
; Converts a 32-bit floating point value to a 80-bit one (fpu register).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 32-bit floating point value to convert.
;
BEGINPROC_FASTCALL iemAImpl_fld_r80_from_r32, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fld dword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fld_r80_from_r32
;;
; Store a 80-bit floating point value (register) as a 32-bit one (memory).
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 32-bit value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fst_r80_to_r32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fst dword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fst_r80_to_r32
;;
; FPU instruction working on one 80-bit and one 32-bit floating point value.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 32-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R32 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 dword [A3]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r32
%endmacro
IEMIMPL_FPU_R80_BY_R32 fadd
IEMIMPL_FPU_R80_BY_R32 fmul
IEMIMPL_FPU_R80_BY_R32 fsub
IEMIMPL_FPU_R80_BY_R32 fsubr
IEMIMPL_FPU_R80_BY_R32 fdiv
IEMIMPL_FPU_R80_BY_R32 fdivr
;;
; FPU instruction working on one 80-bit and one 32-bit floating point value,
; only returning FSW.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Where to store the output FSW.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 64-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R32_FSW 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r32, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 dword [A3]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r32
%endmacro
IEMIMPL_FPU_R80_BY_R32_FSW fcom
;
;---------------------- 64-bit floating point operations ----------------------
;
;;
; Converts a 64-bit floating point value to a 80-bit one (fpu register).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 64-bit floating point value to convert.
;
BEGINPROC_FASTCALL iemAImpl_fld_r80_from_r64, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fld qword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fld_r80_from_r64
;;
; Store a 80-bit floating point value (register) as a 64-bit one (memory).
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 64-bit value.
; @param A3 Pointer to the 80-bit value.
;
BEGINPROC_FASTCALL iemAImpl_fst_r80_to_r64, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fst qword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fst_r80_to_r64
;;
; FPU instruction working on one 80-bit and one 64-bit floating point value.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 64-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R64 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r64, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 qword [A3]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r64
%endmacro
IEMIMPL_FPU_R80_BY_R64 fadd
IEMIMPL_FPU_R80_BY_R64 fmul
IEMIMPL_FPU_R80_BY_R64 fsub
IEMIMPL_FPU_R80_BY_R64 fsubr
IEMIMPL_FPU_R80_BY_R64 fdiv
IEMIMPL_FPU_R80_BY_R64 fdivr
;;
; FPU instruction working on one 80-bit and one 64-bit floating point value,
; only returning FSW.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Where to store the output FSW.
; @param A2 Pointer to the 80-bit value.
; @param A3 Pointer to the 64-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R64_FSW 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r64, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 qword [A3]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r64
%endmacro
IEMIMPL_FPU_R80_BY_R64_FSW fcom
;
;---------------------- 80-bit floating point operations ----------------------
;
;;
; Loads a 80-bit floating point register value from memory.
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit floating point value to load.
;
BEGINPROC_FASTCALL iemAImpl_fld_r80_from_r80, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fld tword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fld_r80_from_r80
;;
; Store a 80-bit floating point register to memory
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 80-bit value.
; @param A3 Pointer to the 80-bit register value.
;
BEGINPROC_FASTCALL iemAImpl_fst_r80_to_r80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fstp tword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fst_r80_to_r80
;;
; Loads an 80-bit floating point register value in BCD format from memory.
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit BCD value to load.
;
BEGINPROC_FASTCALL iemAImpl_fld_r80_from_d80, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fbld tword [A2]
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_fld_r80_from_d80
;;
; Store a 80-bit floating point register to memory as BCD
;
; @param A0 FPU context (fxsave).
; @param A1 Where to return the output FSW.
; @param A2 Where to store the 80-bit BCD value.
; @param A3 Pointer to the 80-bit register value.
;
BEGINPROC_FASTCALL iemAImpl_fst_r80_to_d80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
fbstp tword [A2]
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_fst_r80_to_d80
;;
; FPU instruction working on two 80-bit floating point values.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the first 80-bit value (ST0)
; @param A3 Pointer to the second 80-bit value (STn).
;
%macro IEMIMPL_FPU_R80_BY_R80 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 %2
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r80
%endmacro
IEMIMPL_FPU_R80_BY_R80 fadd, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fmul, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fsub, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fsubr, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fdiv, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fdivr, {st0, st1}
IEMIMPL_FPU_R80_BY_R80 fprem, {}
IEMIMPL_FPU_R80_BY_R80 fprem1, {}
IEMIMPL_FPU_R80_BY_R80 fscale, {}
;;
; FPU instruction working on two 80-bit floating point values, ST1 and ST0,
; storing the result in ST1 and popping the stack.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the first 80-bit value (ST1).
; @param A3 Pointer to the second 80-bit value (ST0).
;
%macro IEMIMPL_FPU_R80_BY_R80_ST1_ST0_POP 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A2]
fld tword [A3]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r80
%endmacro
IEMIMPL_FPU_R80_BY_R80_ST1_ST0_POP fpatan
IEMIMPL_FPU_R80_BY_R80_ST1_ST0_POP fyl2x
IEMIMPL_FPU_R80_BY_R80_ST1_ST0_POP fyl2xp1
;;
; FPU instruction working on two 80-bit floating point values, only
; returning FSW.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a uint16_t for the resulting FSW.
; @param A2 Pointer to the first 80-bit value.
; @param A3 Pointer to the second 80-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R80_FSW 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 st0, st1
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r80
%endmacro
IEMIMPL_FPU_R80_BY_R80_FSW fcom
IEMIMPL_FPU_R80_BY_R80_FSW fucom
;;
; FPU instruction working on two 80-bit floating point values,
; returning FSW and EFLAGS (eax).
;
; @param 1 The instruction
;
; @returns EFLAGS in EAX.
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a uint16_t for the resulting FSW.
; @param A2 Pointer to the first 80-bit value.
; @param A3 Pointer to the second 80-bit value.
;
%macro IEMIMPL_FPU_R80_BY_R80_EFL 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_by_r80, 16
PROLOGUE_4_ARGS
sub xSP, 20h
fninit
fld tword [A3]
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1 st1
fnstsw word [A1]
pushf
pop xAX
fninit
add xSP, 20h
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_by_r80
%endmacro
IEMIMPL_FPU_R80_BY_R80_EFL fcomi
IEMIMPL_FPU_R80_BY_R80_EFL fucomi
;;
; FPU instruction working on one 80-bit floating point value.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
; @param A2 Pointer to the 80-bit value.
;
%macro IEMIMPL_FPU_R80 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80
%endmacro
IEMIMPL_FPU_R80 fchs
IEMIMPL_FPU_R80 fabs
IEMIMPL_FPU_R80 f2xm1
IEMIMPL_FPU_R80 fsqrt
IEMIMPL_FPU_R80 frndint
IEMIMPL_FPU_R80 fsin
IEMIMPL_FPU_R80 fcos
;;
; FPU instruction working on one 80-bit floating point value, only
; returning FSW.
;
; @param 1 The instruction
; @param 2 Non-zero to also restore FTW.
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a uint16_t for the resulting FSW.
; @param A2 Pointer to the 80-bit value.
;
%macro IEMIMPL_FPU_R80_FSW 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
fld tword [A2]
%if %2 != 0
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW_AND_FTW_0 A0
%else
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%endif
%1
fnstsw word [A1]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80
%endmacro
IEMIMPL_FPU_R80_FSW ftst, 0
IEMIMPL_FPU_R80_FSW fxam, 1 ; No #IS or any other FP exceptions.
;;
; FPU instruction loading a 80-bit floating point constant.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULT for the output.
;
%macro IEMIMPL_FPU_R80_CONST 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1, 8
PROLOGUE_2_ARGS
sub xSP, 20h
fninit
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1
fnstsw word [A1 + IEMFPURESULT.FSW]
fnclex
fstp tword [A1 + IEMFPURESULT.r80Result]
fninit
add xSP, 20h
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+
%endmacro
IEMIMPL_FPU_R80_CONST fld1
IEMIMPL_FPU_R80_CONST fldl2t
IEMIMPL_FPU_R80_CONST fldl2e
IEMIMPL_FPU_R80_CONST fldpi
IEMIMPL_FPU_R80_CONST fldlg2
IEMIMPL_FPU_R80_CONST fldln2
IEMIMPL_FPU_R80_CONST fldz
;;
; FPU instruction working on one 80-bit floating point value, outputing two.
;
; @param 1 The instruction
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to a IEMFPURESULTTWO for the output.
; @param A2 Pointer to the 80-bit value.
;
%macro IEMIMPL_FPU_R80_R80 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _r80_r80, 12
PROLOGUE_3_ARGS
sub xSP, 20h
fninit
fld tword [A2]
FPU_LD_FXSTATE_FCW_AND_SAFE_FSW A0
%1
fnstsw word [A1 + IEMFPURESULTTWO.FSW]
fnclex
fstp tword [A1 + IEMFPURESULTTWO.r80Result2]
fnclex
fstp tword [A1 + IEMFPURESULTTWO.r80Result1]
fninit
add xSP, 20h
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _r80_r80
%endmacro
IEMIMPL_FPU_R80_R80 fptan
IEMIMPL_FPU_R80_R80 fxtract
IEMIMPL_FPU_R80_R80 fsincos
;---------------------- SSE and MMX Operations ----------------------
;; @todo what do we need to do for MMX?
%macro IEMIMPL_MMX_PROLOGUE 0
%endmacro
%macro IEMIMPL_MMX_EPILOGUE 0
%endmacro
;; @todo what do we need to do for SSE?
%macro IEMIMPL_SSE_PROLOGUE 0
%endmacro
%macro IEMIMPL_SSE_EPILOGUE 0
%endmacro
;; @todo what do we need to do for AVX?
%macro IEMIMPL_AVX_PROLOGUE 0
%endmacro
%macro IEMIMPL_AVX_EPILOGUE 0
%endmacro
;;
; Media instruction working on two full sized registers.
;
; @param 1 The instruction
; @param 2 Whether there is an MMX variant (1) or not (0).
;
; @param A0 FPU context (fxsave).
; @param A1 Pointer to the first media register size operand (input/output).
; @param A2 Pointer to the second media register size operand (input).
;
%macro IEMIMPL_MEDIA_F2 2
%if %2 != 0
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 12
PROLOGUE_3_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm0, [A1]
movq mm1, [A2]
%1 mm0, mm1
movq [A1], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A1]
movdqu xmm1, [A2]
%1 xmm0, xmm1
movdqu [A1], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_F2 pshufb, 1
IEMIMPL_MEDIA_F2 pand, 1
IEMIMPL_MEDIA_F2 pandn, 1
IEMIMPL_MEDIA_F2 por, 1
IEMIMPL_MEDIA_F2 pxor, 1
IEMIMPL_MEDIA_F2 pcmpeqb, 1
IEMIMPL_MEDIA_F2 pcmpeqw, 1
IEMIMPL_MEDIA_F2 pcmpeqd, 1
IEMIMPL_MEDIA_F2 pcmpeqq, 0
IEMIMPL_MEDIA_F2 pcmpgtb, 1
IEMIMPL_MEDIA_F2 pcmpgtw, 1
IEMIMPL_MEDIA_F2 pcmpgtd, 1
IEMIMPL_MEDIA_F2 pcmpgtq, 0
IEMIMPL_MEDIA_F2 paddb, 1
IEMIMPL_MEDIA_F2 paddw, 1
IEMIMPL_MEDIA_F2 paddd, 1
IEMIMPL_MEDIA_F2 paddq, 1
IEMIMPL_MEDIA_F2 paddsb, 1
IEMIMPL_MEDIA_F2 paddsw, 1
IEMIMPL_MEDIA_F2 paddusb, 1
IEMIMPL_MEDIA_F2 paddusw, 1
IEMIMPL_MEDIA_F2 psubb, 1
IEMIMPL_MEDIA_F2 psubw, 1
IEMIMPL_MEDIA_F2 psubd, 1
IEMIMPL_MEDIA_F2 psubq, 1
IEMIMPL_MEDIA_F2 psubsb, 1
IEMIMPL_MEDIA_F2 psubsw, 1
IEMIMPL_MEDIA_F2 psubusb, 1
IEMIMPL_MEDIA_F2 psubusw, 1
IEMIMPL_MEDIA_F2 pmullw, 1
IEMIMPL_MEDIA_F2 pmulld, 0
IEMIMPL_MEDIA_F2 pmulhw, 1
IEMIMPL_MEDIA_F2 pmaddwd, 1
IEMIMPL_MEDIA_F2 pminub, 1
IEMIMPL_MEDIA_F2 pminuw, 0
IEMIMPL_MEDIA_F2 pminud, 0
IEMIMPL_MEDIA_F2 pminsb, 0
IEMIMPL_MEDIA_F2 pminsw, 1
IEMIMPL_MEDIA_F2 pminsd, 0
IEMIMPL_MEDIA_F2 pmaxub, 1
IEMIMPL_MEDIA_F2 pmaxuw, 0
IEMIMPL_MEDIA_F2 pmaxud, 0
IEMIMPL_MEDIA_F2 pmaxsb, 0
IEMIMPL_MEDIA_F2 pmaxsw, 1
IEMIMPL_MEDIA_F2 pmaxsd, 0
IEMIMPL_MEDIA_F2 pabsb, 1
IEMIMPL_MEDIA_F2 pabsw, 1
IEMIMPL_MEDIA_F2 pabsd, 1
IEMIMPL_MEDIA_F2 psignb, 1
IEMIMPL_MEDIA_F2 psignw, 1
IEMIMPL_MEDIA_F2 psignd, 1
IEMIMPL_MEDIA_F2 phaddw, 1
IEMIMPL_MEDIA_F2 phaddd, 1
IEMIMPL_MEDIA_F2 phsubw, 1
IEMIMPL_MEDIA_F2 phsubd, 1
IEMIMPL_MEDIA_F2 phaddsw, 1
IEMIMPL_MEDIA_F2 phsubsw, 1
IEMIMPL_MEDIA_F2 pmaddubsw, 1
IEMIMPL_MEDIA_F2 pmulhrsw, 1
IEMIMPL_MEDIA_F2 pmuludq, 1
;;
; Media instruction working on two full sized registers, but no FXSAVE state argument.
;
; @param 1 The instruction
; @param 2 Whether there is an MMX variant (1) or not (0).
;
; @param A0 Pointer to the first media register size operand (input/output).
; @param A1 Pointer to the second media register size operand (input).
;
%macro IEMIMPL_MEDIA_OPT_F2 2
%if %2 != 0
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 8
PROLOGUE_2_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm0, [A0]
movq mm1, [A1]
%1 mm0, mm1
movq [A0], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 8
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
%1 xmm0, xmm1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_OPT_F2 packsswb, 1
IEMIMPL_MEDIA_OPT_F2 packssdw, 1
IEMIMPL_MEDIA_OPT_F2 packuswb, 1
IEMIMPL_MEDIA_OPT_F2 packusdw, 0
IEMIMPL_MEDIA_OPT_F2 psllw, 1
IEMIMPL_MEDIA_OPT_F2 pslld, 1
IEMIMPL_MEDIA_OPT_F2 psllq, 1
IEMIMPL_MEDIA_OPT_F2 psrlw, 1
IEMIMPL_MEDIA_OPT_F2 psrld, 1
IEMIMPL_MEDIA_OPT_F2 psrlq, 1
IEMIMPL_MEDIA_OPT_F2 psraw, 1
IEMIMPL_MEDIA_OPT_F2 psrad, 1
IEMIMPL_MEDIA_OPT_F2 pmulhuw, 1
IEMIMPL_MEDIA_OPT_F2 pavgb, 1
IEMIMPL_MEDIA_OPT_F2 pavgw, 1
IEMIMPL_MEDIA_OPT_F2 psadbw, 1
IEMIMPL_MEDIA_OPT_F2 pmuldq, 0
IEMIMPL_MEDIA_OPT_F2 unpcklps, 0
IEMIMPL_MEDIA_OPT_F2 unpcklpd, 0
IEMIMPL_MEDIA_OPT_F2 unpckhps, 0
IEMIMPL_MEDIA_OPT_F2 unpckhpd, 0
IEMIMPL_MEDIA_OPT_F2 phminposuw, 0
IEMIMPL_MEDIA_OPT_F2 aesimc, 0
IEMIMPL_MEDIA_OPT_F2 aesenc, 0
IEMIMPL_MEDIA_OPT_F2 aesdec, 0
IEMIMPL_MEDIA_OPT_F2 aesenclast, 0
IEMIMPL_MEDIA_OPT_F2 aesdeclast, 0
;;
; Media instruction working on one full sized and one half sized register (lower half).
;
; @param 1 The instruction
; @param 2 1 if MMX is included, 0 if not.
;
; @param A0 Pointer to the first full sized media register operand (input/output).
; @param A1 Pointer to the second half sized media register operand (input).
;
%macro IEMIMPL_MEDIA_F1L1 2
%if %2 != 0
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u64, 8
PROLOGUE_2_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm0, [A0]
movq mm1, [A1]
%1 mm0, mm1
movq [A0], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u64
%endif
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 8
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
%1 xmm0, xmm1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_F1L1 punpcklbw, 1
IEMIMPL_MEDIA_F1L1 punpcklwd, 1
IEMIMPL_MEDIA_F1L1 punpckldq, 1
IEMIMPL_MEDIA_F1L1 punpcklqdq, 0
;;
; Media instruction working two half sized input registers (lower half) and a full sized
; destination register (vpunpckh*).
;
; @param 1 The instruction
;
; @param A0 Pointer to the destination register (full sized, output only).
; @param A1 Pointer to the first full sized media source register operand, where we
; will only use the lower half as input - but we'll be loading it in full.
; @param A2 Pointer to the second full sized media source register operand, where we
; will only use the lower half as input - but we'll be loading it in full.
;
%macro IEMIMPL_MEDIA_F1L1L1 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_3_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu xmm0, [A1]
vmovdqu xmm1, [A2]
%1 xmm0, xmm0, xmm1
vmovdqu [A0], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 12
PROLOGUE_3_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
vmovdqu ymm1, [A2]
%1 ymm0, ymm0, ymm1
vmovdqu [A0], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_MEDIA_F1L1L1 vpunpcklbw
IEMIMPL_MEDIA_F1L1L1 vpunpcklwd
IEMIMPL_MEDIA_F1L1L1 vpunpckldq
IEMIMPL_MEDIA_F1L1L1 vpunpcklqdq
;;
; Media instruction working on one full sized and one half sized register (high half).
;
; @param 1 The instruction
; @param 2 1 if MMX is included, 0 if not.
;
; @param A0 Pointer to the first full sized media register operand (input/output).
; @param A1 Pointer to the second full sized media register operand, where we
; will only use the upper half as input - but we'll load it in full.
;
%macro IEMIMPL_MEDIA_F1H1 2
IEMIMPL_MEDIA_F1L1 %1, %2
%endmacro
IEMIMPL_MEDIA_F1L1 punpckhbw, 1
IEMIMPL_MEDIA_F1L1 punpckhwd, 1
IEMIMPL_MEDIA_F1L1 punpckhdq, 1
IEMIMPL_MEDIA_F1L1 punpckhqdq, 0
;;
; Media instruction working two half sized input registers (high half) and a full sized
; destination register (vpunpckh*).
;
; @param 1 The instruction
;
; @param A0 Pointer to the destination register (full sized, output only).
; @param A1 Pointer to the first full sized media source register operand, where we
; will only use the upper half as input - but we'll be loading it in full.
; @param A2 Pointer to the second full sized media source register operand, where we
; will only use the upper half as input - but we'll be loading it in full.
;
%macro IEMIMPL_MEDIA_F1H1H1 1
IEMIMPL_MEDIA_F1L1L1 %1
%endmacro
IEMIMPL_MEDIA_F1H1H1 vpunpckhbw
IEMIMPL_MEDIA_F1H1H1 vpunpckhwd
IEMIMPL_MEDIA_F1H1H1 vpunpckhdq
IEMIMPL_MEDIA_F1H1H1 vpunpckhqdq
;
; Shufflers with evil 8-bit immediates.
;
BEGINPROC_FASTCALL iemAImpl_pshufw_u64, 16
PROLOGUE_3_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm1, [A1]
movq mm0, mm0 ; paranoia!
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*8] ; sizeof(pshufw+ret) == 9
%else
lea T0, [A2 + A2*4] ; sizeof(pshufw+ret) == 5
%endif
lea T1, [T1 + T0]
IBT_NOTRACK
call T1
movq [A0], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pshufw mm0, mm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x500
ENDPROC iemAImpl_pshufw_u64
%macro IEMIMPL_MEDIA_SSE_PSHUFXX 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm1, [A1]
movdqu xmm0, xmm1 ; paranoia!
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(pshufXX+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(pshufXX+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_PSHUFXX pshufhw
IEMIMPL_MEDIA_SSE_PSHUFXX pshuflw
IEMIMPL_MEDIA_SSE_PSHUFXX pshufd
%macro IEMIMPL_MEDIA_AVX_VPSHUFXX 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
vmovdqu ymm1, [A1]
vmovdqu ymm0, ymm1 ; paranoia!
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(pshufXX+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(pshufXX+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
vmovdqu [A0], ymm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 ymm0, ymm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_MEDIA_AVX_VPSHUFXX vpshufhw
IEMIMPL_MEDIA_AVX_VPSHUFXX vpshuflw
IEMIMPL_MEDIA_AVX_VPSHUFXX vpshufd
;
; Shifts with evil 8-bit immediates.
;
%macro IEMIMPL_MEDIA_MMX_PSHIFTXX 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _imm_u64, 16
PROLOGUE_2_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm0, [A0]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A1 + A1*8] ; sizeof(psXX+ret) == 9
%else
lea T0, [A1 + A1*4] ; sizeof(psXX+ret) == 5
%endif
lea T1, [T1 + T0]
IBT_NOTRACK
call T1
movq [A0], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_2_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 mm0, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x500
ENDPROC iemAImpl_ %+ %1 %+ _imm_u64
%endmacro
IEMIMPL_MEDIA_MMX_PSHIFTXX psllw
IEMIMPL_MEDIA_MMX_PSHIFTXX pslld
IEMIMPL_MEDIA_MMX_PSHIFTXX psllq
IEMIMPL_MEDIA_MMX_PSHIFTXX psrlw
IEMIMPL_MEDIA_MMX_PSHIFTXX psrld
IEMIMPL_MEDIA_MMX_PSHIFTXX psrlq
IEMIMPL_MEDIA_MMX_PSHIFTXX psraw
IEMIMPL_MEDIA_MMX_PSHIFTXX psrad
%macro IEMIMPL_MEDIA_SSE_PSHIFTXX 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _imm_u128, 16
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A1 + A1*4] ; sizeof(psXX+ret) == 10: A1 * 10 = (A1 * 5) * 2
%else
lea T0, [A1 + A1*2] ; sizeof(psXX+ret) == 6: A1 * 6 = (A1 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_2_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _imm_u128
%endmacro
IEMIMPL_MEDIA_SSE_PSHIFTXX psllw
IEMIMPL_MEDIA_SSE_PSHIFTXX pslld
IEMIMPL_MEDIA_SSE_PSHIFTXX psllq
IEMIMPL_MEDIA_SSE_PSHIFTXX psrlw
IEMIMPL_MEDIA_SSE_PSHIFTXX psrld
IEMIMPL_MEDIA_SSE_PSHIFTXX psrlq
IEMIMPL_MEDIA_SSE_PSHIFTXX psraw
IEMIMPL_MEDIA_SSE_PSHIFTXX psrad
IEMIMPL_MEDIA_SSE_PSHIFTXX pslldq
IEMIMPL_MEDIA_SSE_PSHIFTXX psrldq
;
; Move byte mask.
;
BEGINPROC_FASTCALL iemAImpl_pmovmskb_u64, 8
PROLOGUE_2_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm1, [A1]
pmovmskb T0, mm1
mov [A0], T0
%ifdef RT_ARCH_X86
mov dword [A0 + 4], 0
%endif
IEMIMPL_MMX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_pmovmskb_u64
BEGINPROC_FASTCALL iemAImpl_pmovmskb_u128, 8
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm1, [A1]
pmovmskb T0, xmm1
mov [A0], T0
%ifdef RT_ARCH_X86
mov dword [A0 + 4], 0
%endif
IEMIMPL_SSE_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_pmovmskb_u128
BEGINPROC_FASTCALL iemAImpl_vpmovmskb_u256, 8
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm1, [A1]
vpmovmskb T0, ymm1
mov [A0], T0
%ifdef RT_ARCH_X86
mov dword [A0 + 4], 0
%endif
IEMIMPL_AVX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_vpmovmskb_u256
;;
; Media instruction working on two full sized source registers and one destination (AVX).
;
; @param 1 The instruction
;
; @param A0 Pointer to the extended CPU/FPU state (X86XSAVEAREA).
; @param A1 Pointer to the destination media register size operand (output).
; @param A2 Pointer to the first source media register size operand (input).
; @param A3 Pointer to the second source media register size operand (input).
;
%macro IEMIMPL_MEDIA_F3 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu xmm0, [A2]
vmovdqu xmm1, [A3]
%1 xmm0, xmm0, xmm1
vmovdqu [A1], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A2]
vmovdqu ymm1, [A3]
%1 ymm0, ymm0, ymm1
vmovdqu [A1], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_MEDIA_F3 vpshufb
IEMIMPL_MEDIA_F3 vpand
IEMIMPL_MEDIA_F3 vpminub
IEMIMPL_MEDIA_F3 vpminuw
IEMIMPL_MEDIA_F3 vpminud
IEMIMPL_MEDIA_F3 vpminsb
IEMIMPL_MEDIA_F3 vpminsw
IEMIMPL_MEDIA_F3 vpminsd
IEMIMPL_MEDIA_F3 vpmaxub
IEMIMPL_MEDIA_F3 vpmaxuw
IEMIMPL_MEDIA_F3 vpmaxud
IEMIMPL_MEDIA_F3 vpmaxsb
IEMIMPL_MEDIA_F3 vpmaxsw
IEMIMPL_MEDIA_F3 vpmaxsd
IEMIMPL_MEDIA_F3 vpandn
IEMIMPL_MEDIA_F3 vpor
IEMIMPL_MEDIA_F3 vpxor
IEMIMPL_MEDIA_F3 vpcmpeqb
IEMIMPL_MEDIA_F3 vpcmpeqw
IEMIMPL_MEDIA_F3 vpcmpeqd
IEMIMPL_MEDIA_F3 vpcmpeqq
IEMIMPL_MEDIA_F3 vpcmpgtb
IEMIMPL_MEDIA_F3 vpcmpgtw
IEMIMPL_MEDIA_F3 vpcmpgtd
IEMIMPL_MEDIA_F3 vpcmpgtq
IEMIMPL_MEDIA_F3 vpaddb
IEMIMPL_MEDIA_F3 vpaddw
IEMIMPL_MEDIA_F3 vpaddd
IEMIMPL_MEDIA_F3 vpaddq
IEMIMPL_MEDIA_F3 vpsubb
IEMIMPL_MEDIA_F3 vpsubw
IEMIMPL_MEDIA_F3 vpsubd
IEMIMPL_MEDIA_F3 vpsubq
;;
; Media instruction working on two full sized source registers and one destination (AVX),
; but no XSAVE state pointer argument.
;
; @param 1 The instruction
;
; @param A0 Pointer to the destination media register size operand (output).
; @param A1 Pointer to the first source media register size operand (input).
; @param A2 Pointer to the second source media register size operand (input).
;
%macro IEMIMPL_MEDIA_OPT_F3 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_3_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu xmm0, [A1]
vmovdqu xmm1, [A2]
%1 xmm0, xmm0, xmm1
vmovdqu [A0], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 12
PROLOGUE_3_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
vmovdqu ymm1, [A2]
%1 ymm0, ymm0, ymm1
vmovdqu [A0], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_MEDIA_OPT_F3 vpacksswb
IEMIMPL_MEDIA_OPT_F3 vpackssdw
IEMIMPL_MEDIA_OPT_F3 vpackuswb
IEMIMPL_MEDIA_OPT_F3 vpackusdw
IEMIMPL_MEDIA_OPT_F3 vpmullw
IEMIMPL_MEDIA_OPT_F3 vpmulld
IEMIMPL_MEDIA_OPT_F3 vpmulhw
IEMIMPL_MEDIA_OPT_F3 vpmulhuw
IEMIMPL_MEDIA_OPT_F3 vpavgb
IEMIMPL_MEDIA_OPT_F3 vpavgw
IEMIMPL_MEDIA_OPT_F3 vpsignb
IEMIMPL_MEDIA_OPT_F3 vpsignw
IEMIMPL_MEDIA_OPT_F3 vpsignd
IEMIMPL_MEDIA_OPT_F3 vphaddw
IEMIMPL_MEDIA_OPT_F3 vphaddd
IEMIMPL_MEDIA_OPT_F3 vphsubw
IEMIMPL_MEDIA_OPT_F3 vphsubd
IEMIMPL_MEDIA_OPT_F3 vphaddsw
IEMIMPL_MEDIA_OPT_F3 vphsubsw
IEMIMPL_MEDIA_OPT_F3 vpmaddubsw
IEMIMPL_MEDIA_OPT_F3 vpmulhrsw
IEMIMPL_MEDIA_OPT_F3 vpsadbw
IEMIMPL_MEDIA_OPT_F3 vpmuldq
IEMIMPL_MEDIA_OPT_F3 vpmuludq
IEMIMPL_MEDIA_OPT_F3 vunpcklps
IEMIMPL_MEDIA_OPT_F3 vunpcklpd
IEMIMPL_MEDIA_OPT_F3 vunpckhps
IEMIMPL_MEDIA_OPT_F3 vunpckhpd
;;
; Media instruction working on one full sized source registers and one destination (AVX),
; but no XSAVE state pointer argument.
;
; @param 1 The instruction
; @param 2 Flag whether the isntruction has a 256-bit (AVX2) variant (1) or not (0).
;
; @param A0 Pointer to the destination media register size operand (output).
; @param A1 Pointer to the source media register size operand (input).
;
%macro IEMIMPL_MEDIA_OPT_F2_AVX 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu xmm0, [A1]
%1 xmm0, xmm0
vmovdqu [A0], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%if %2 == 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 12
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
%1 ymm0, ymm0
vmovdqu [A0], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endif
%endmacro
IEMIMPL_MEDIA_OPT_F2_AVX vpabsb, 1
IEMIMPL_MEDIA_OPT_F2_AVX vpabsw, 1
IEMIMPL_MEDIA_OPT_F2_AVX vpabsd, 1
IEMIMPL_MEDIA_OPT_F2_AVX vphminposuw, 0
;
; The SSE 4.2 crc32
;
; @param A1 Pointer to the 32-bit destination.
; @param A2 The source operand, sized according to the suffix.
;
BEGINPROC_FASTCALL iemAImpl_crc32_u8, 8
PROLOGUE_2_ARGS
mov T0_32, [A0]
crc32 T0_32, A1_8
mov [A0], T0_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_crc32_u8
BEGINPROC_FASTCALL iemAImpl_crc32_u16, 8
PROLOGUE_2_ARGS
mov T0_32, [A0]
crc32 T0_32, A1_16
mov [A0], T0_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_crc32_u16
BEGINPROC_FASTCALL iemAImpl_crc32_u32, 8
PROLOGUE_2_ARGS
mov T0_32, [A0]
crc32 T0_32, A1_32
mov [A0], T0_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_crc32_u32
%ifdef RT_ARCH_AMD64
BEGINPROC_FASTCALL iemAImpl_crc32_u64, 8
PROLOGUE_2_ARGS
mov T0_32, [A0]
crc32 T0, A1
mov [A0], T0_32
EPILOGUE_2_ARGS
ENDPROC iemAImpl_crc32_u64
%endif
;
; PTEST (SSE 4.1)
;
; @param A0 Pointer to the first source operand (aka readonly destination).
; @param A1 Pointer to the second source operand.
; @param A2 Pointer to the EFLAGS register.
;
BEGINPROC_FASTCALL iemAImpl_ptest_u128, 12
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
ptest xmm0, xmm1
IEM_SAVE_FLAGS A2, X86_EFL_STATUS_BITS, 0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ptest_u128
BEGINPROC_FASTCALL iemAImpl_vptest_u256, 12
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
vmovdqu ymm0, [A0]
vmovdqu ymm1, [A1]
vptest ymm0, ymm1
IEM_SAVE_FLAGS A2, X86_EFL_STATUS_BITS, 0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_vptest_u256
;;
; Template for the [v]pmov{s,z}x* instructions
;
; @param 1 The instruction
;
; @param A0 Pointer to the destination media register size operand (output).
; @param A1 The source operand value (input).
;
%macro IEMIMPL_V_PMOV_SZ_X 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movd xmm0, A1
%1 xmm0, xmm0
vmovdqu [A0], xmm0
IEMIMPL_SSE_PROLOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128, 12
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
movd xmm0, A1
v %+ %1 xmm0, xmm0
vmovdqu [A0], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u256, 12
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
movdqu xmm0, [A1]
v %+ %1 ymm0, xmm0
vmovdqu [A0], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u256
%endmacro
IEMIMPL_V_PMOV_SZ_X pmovsxbw
IEMIMPL_V_PMOV_SZ_X pmovsxbd
IEMIMPL_V_PMOV_SZ_X pmovsxbq
IEMIMPL_V_PMOV_SZ_X pmovsxwd
IEMIMPL_V_PMOV_SZ_X pmovsxwq
IEMIMPL_V_PMOV_SZ_X pmovsxdq
IEMIMPL_V_PMOV_SZ_X pmovzxbw
IEMIMPL_V_PMOV_SZ_X pmovzxbd
IEMIMPL_V_PMOV_SZ_X pmovzxbq
IEMIMPL_V_PMOV_SZ_X pmovzxwd
IEMIMPL_V_PMOV_SZ_X pmovzxwq
IEMIMPL_V_PMOV_SZ_X pmovzxdq
;;
; Need to move this as well somewhere better?
;
struc IEMSSERESULT
.uResult resd 4
.MXCSR resd 1
endstruc
;;
; Need to move this as well somewhere better?
;
struc IEMAVX128RESULT
.uResult resd 4
.MXCSR resd 1
endstruc
;;
; Need to move this as well somewhere better?
;
struc IEMAVX256RESULT
.uResult resd 8
.MXCSR resd 1
endstruc
;;
; Initialize the SSE MXCSR register using the guest value partially to
; account for rounding mode.
;
; @uses 4 bytes of stack to save the original value, T0.
; @param 1 Expression giving the address of the FXSTATE of the guest.
;
%macro SSE_LD_FXSTATE_MXCSR 1
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [%1 + X86FXSTATE.MXCSR]
and T0_32, X86_MXCSR_FZ | X86_MXCSR_RC_MASK | X86_MXCSR_DAZ
or T0_32, X86_MXCSR_XCPT_MASK
sub xSP, 4
mov [xSP], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Restores the SSE MXCSR register with the original value.
;
; @uses 4 bytes of stack to save the content of MXCSR value, T0, T1.
; @param 1 Expression giving the address where to return the MXCSR value.
; @param 2 Expression giving the address of the FXSTATE of the guest.
;
; @note Restores the stack pointer.
;
%macro SSE_ST_FXSTATE_MXCSR 2
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [xSP]
add xSP, 4
; Merge the status bits into the original MXCSR value.
mov T1_32, [%2 + X86FXSTATE.MXCSR]
and T0_32, X86_MXCSR_XCPT_FLAGS
or T0_32, T1_32
mov [%1 + IEMSSERESULT.MXCSR], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Initialize the SSE MXCSR register using the guest value partially to
; account for rounding mode.
;
; @uses 4 bytes of stack to save the original value.
; @param 1 Expression giving the address of the FXSTATE of the guest.
;
%macro AVX_LD_XSAVEAREA_MXCSR 1
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [%1 + X86FXSTATE.MXCSR]
and T0_32, X86_MXCSR_FZ | X86_MXCSR_RC_MASK | X86_MXCSR_DAZ
sub xSP, 4
mov [xSP], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Restores the AVX128 MXCSR register with the original value.
;
; @param 1 Expression giving the address where to return the MXCSR value.
;
; @note Restores the stack pointer.
;
%macro AVX128_ST_XSAVEAREA_MXCSR 1
stmxcsr [%1 + IEMAVX128RESULT.MXCSR]
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Restores the AVX256 MXCSR register with the original value.
;
; @param 1 Expression giving the address where to return the MXCSR value.
;
; @note Restores the stack pointer.
;
%macro AVX256_ST_XSAVEAREA_MXCSR 1
stmxcsr [%1 + IEMAVX256RESULT.MXCSR]
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Floating point instruction working on two full sized registers.
;
; @param 1 The instruction
; @param 2 Flag whether the AVX variant of the instruction takes two or three operands, 0 to disable AVX variants
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the result including the MXCSR value.
; @param A2 Pointer to the first media register size operand (input/output).
; @param A3 Pointer to the second media register size operand (input).
;
%macro IEMIMPL_FP_F2 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 12
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
%1 xmm0, xmm1
movdqu [A1 + IEMSSERESULT.uResult], xmm0
SSE_ST_FXSTATE_MXCSR A1, A0
IEMIMPL_SSE_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%if %2 == 3
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128, 12
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu xmm0, [A2]
vmovdqu xmm1, [A3]
v %+ %1 xmm0, xmm0, xmm1
vmovdqu [A1 + IEMAVX128RESULT.uResult], xmm0
AVX128_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u256, 12
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu ymm0, [A2]
vmovdqu ymm1, [A3]
v %+ %1 ymm0, ymm0, ymm1
vmovdqu [A1 + IEMAVX256RESULT.uResult], ymm0
AVX256_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u256
%elif %2 == 2
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128, 12
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu xmm0, [A2]
vmovdqu xmm1, [A3]
v %+ %1 xmm0, xmm1
vmovdqu [A1 + IEMAVX128RESULT.uResult], xmm0
AVX128_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u256, 12
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu ymm0, [A2]
vmovdqu ymm1, [A3]
v %+ %1 ymm0, ymm1
vmovdqu [A1 + IEMAVX256RESULT.uResult], ymm0
AVX256_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u256
%endif
%endmacro
IEMIMPL_FP_F2 addps, 3
IEMIMPL_FP_F2 addpd, 3
IEMIMPL_FP_F2 mulps, 3
IEMIMPL_FP_F2 mulpd, 3
IEMIMPL_FP_F2 subps, 3
IEMIMPL_FP_F2 subpd, 3
IEMIMPL_FP_F2 minps, 3
IEMIMPL_FP_F2 minpd, 3
IEMIMPL_FP_F2 divps, 3
IEMIMPL_FP_F2 divpd, 3
IEMIMPL_FP_F2 maxps, 3
IEMIMPL_FP_F2 maxpd, 3
IEMIMPL_FP_F2 haddps, 3
IEMIMPL_FP_F2 haddpd, 3
IEMIMPL_FP_F2 hsubps, 3
IEMIMPL_FP_F2 hsubpd, 3
IEMIMPL_FP_F2 addsubps, 3
IEMIMPL_FP_F2 addsubpd, 3
;;
; These are actually unary operations but to keep it simple
; we treat them as binary for now, so the output result is
; always in sync with the register where the result might get written
; to.
IEMIMPL_FP_F2 sqrtps, 2
IEMIMPL_FP_F2 rsqrtps, 2
IEMIMPL_FP_F2 sqrtpd, 2
IEMIMPL_FP_F2 cvtdq2ps, 2
IEMIMPL_FP_F2 cvtps2dq, 2
IEMIMPL_FP_F2 cvttps2dq, 2
IEMIMPL_FP_F2 cvttpd2dq, 0 ; @todo AVX variants due to register size differences missing right now
IEMIMPL_FP_F2 cvtdq2pd, 0 ; @todo AVX variants due to register size differences missing right now
IEMIMPL_FP_F2 cvtpd2dq, 0 ; @todo AVX variants due to register size differences missing right now
;;
; Floating point instruction working on a full sized register and a single precision operand.
;
; @param 1 The instruction
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the result including the MXCSR value.
; @param A2 Pointer to the first media register size operand (input/output).
; @param A3 Pointer to the second single precision floating point value (input).
;
%macro IEMIMPL_FP_F2_R32 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
movdqu xmm0, [A2]
movd xmm1, [A3]
%1 xmm0, xmm1
movdqu [A1 + IEMSSERESULT.uResult], xmm0
SSE_ST_FXSTATE_MXCSR A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128_r32
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu xmm0, [A2]
vmovd xmm1, [A3]
v %+ %1 xmm0, xmm0, xmm1
vmovdqu [A1 + IEMAVX128RESULT.uResult], xmm0
AVX128_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128_r32
%endmacro
IEMIMPL_FP_F2_R32 addss
IEMIMPL_FP_F2_R32 mulss
IEMIMPL_FP_F2_R32 subss
IEMIMPL_FP_F2_R32 minss
IEMIMPL_FP_F2_R32 divss
IEMIMPL_FP_F2_R32 maxss
IEMIMPL_FP_F2_R32 cvtss2sd
IEMIMPL_FP_F2_R32 sqrtss
IEMIMPL_FP_F2_R32 rsqrtss
;;
; Floating point instruction working on a full sized register and a double precision operand.
;
; @param 1 The instruction
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the result including the MXCSR value.
; @param A2 Pointer to the first media register size operand (input/output).
; @param A3 Pointer to the second double precision floating point value (input).
;
%macro IEMIMPL_FP_F2_R64 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
movdqu xmm0, [A2]
movq xmm1, [A3]
%1 xmm0, xmm1
movdqu [A1 + IEMSSERESULT.uResult], xmm0
SSE_ST_FXSTATE_MXCSR A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128_r64
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu xmm0, [A2]
vmovq xmm1, [A3]
v %+ %1 xmm0, xmm0, xmm1
vmovdqu [A1 + IEMAVX128RESULT.uResult], xmm0
AVX128_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128_r64
%endmacro
IEMIMPL_FP_F2_R64 addsd
IEMIMPL_FP_F2_R64 mulsd
IEMIMPL_FP_F2_R64 subsd
IEMIMPL_FP_F2_R64 minsd
IEMIMPL_FP_F2_R64 divsd
IEMIMPL_FP_F2_R64 maxsd
IEMIMPL_FP_F2_R64 cvtsd2ss
IEMIMPL_FP_F2_R64 sqrtsd
;;
; Macro for the cvtpd2ps/cvtps2pd instructions.
;
; 1 The instruction name.
; 2 Whether the AVX256 result is 128-bit (0) or 256-bit (1).
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the result including the MXCSR value.
; @param A2 Pointer to the first media register size operand (input/output).
; @param A3 Pointer to the second media register size operand (input).
;
%macro IEMIMPL_CVT_F2 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
%1 xmm0, xmm1
movdqu [A1 + IEMSSERESULT.uResult], xmm0
SSE_ST_FXSTATE_MXCSR A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu xmm0, [A2]
vmovdqu xmm1, [A3]
v %+ %1 xmm0, xmm1
vmovdqu [A1 + IEMAVX128RESULT.uResult], xmm0
AVX128_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_v %+ %1 %+ _u256, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
AVX_LD_XSAVEAREA_MXCSR A0
vmovdqu ymm0, [A2]
vmovdqu ymm1, [A3]
%if %2 == 0
v %+ %1 xmm0, ymm1
%else
v %+ %1 ymm0, xmm1
%endif
vmovdqu [A1 + IEMAVX256RESULT.uResult], ymm0
AVX256_ST_XSAVEAREA_MXCSR A1
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_v %+ %1 %+ _u256
%endmacro
IEMIMPL_CVT_F2 cvtpd2ps, 0
IEMIMPL_CVT_F2 cvtps2pd, 1
;;
; shufps instructions with 8-bit immediates.
;
; @param A0 Pointer to the destination media register size operand (input/output).
; @param A1 Pointer to the first source media register size operand (input).
; @param A2 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_shufps_u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(shufpX+ret+int3) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(shufpX+ret+int3) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
shufps xmm0, xmm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_shufps_u128
;;
; shufpd instruction with 8-bit immediates.
;
; @param A0 Pointer to the destination media register size operand (input/output).
; @param A1 Pointer to the first source media register size operand (input).
; @param A2 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_shufpd_u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(shufpX+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(shufpX+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
shufpd xmm0, xmm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_shufpd_u128
;;
; vshufp{s,d} instructions with 8-bit immediates.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the destination media register size operand (output).
; @param A1 Pointer to the first source media register size operand (input).
; @param A2 Pointer to the second source media register size operand (input).
; @param A3 The 8-bit immediate
;
%macro IEMIMPL_MEDIA_AVX_VSHUFPX 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
movdqu xmm0, [A1]
movdqu xmm1, [A2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*4] ; sizeof(vshufpX+ret) == 10: A3 * 10 = (A3 * 5) * 2
%else
lea T0, [A3 + A3*2] ; sizeof(vshufpX+ret) == 6: A3 * 6 = (A3 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm0, xmm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
vmovdqu ymm1, [A2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*4] ; sizeof(vshufpX+ret) == 10: A3 * 10 = (A3 * 5) * 2
%else
lea T0, [A3 + A3*2] ; sizeof(vshufpX+ret) == 6: A3 * 6 = (A3 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
vmovdqu [A0], ymm0
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 ymm0, ymm0, ymm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_MEDIA_AVX_VSHUFPX vshufps
IEMIMPL_MEDIA_AVX_VSHUFPX vshufpd
;;
; One of the [p]blendv{b,ps,pd} variants
;
; @param 1 The instruction
;
; @param A0 Pointer to the first media register sized operand (input/output).
; @param A1 Pointer to the second media sized value (input).
; @param A2 Pointer to the media register sized mask value (input).
;
%macro IEMIMPL_P_BLEND 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A2] ; This is implicit
movdqu xmm1, [A0]
movdqu xmm2, [A1] ; @todo Do I need to save the original value here first?
%1 xmm1, xmm2
movdqu [A0], xmm1
IEMIMPL_SSE_PROLOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_P_BLEND pblendvb
IEMIMPL_P_BLEND blendvps
IEMIMPL_P_BLEND blendvpd
;;
; One of the v[p]blendv{b,ps,pd} variants
;
; @param 1 The instruction
;
; @param A0 Pointer to the first media register sized operand (output).
; @param A1 Pointer to the first media register sized operand (input).
; @param A2 Pointer to the second media register sized operand (input).
; @param A3 Pointer to the media register sized mask value (input).
%macro IEMIMPL_AVX_P_BLEND 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu xmm0, [A1]
vmovdqu xmm1, [A2]
vmovdqu xmm2, [A3]
%1 xmm0, xmm0, xmm1, xmm2
vmovdqu [A0], xmm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
vmovdqu ymm1, [A2]
vmovdqu ymm2, [A3]
%1 ymm0, ymm0, ymm1, ymm2
vmovdqu [A0], ymm0
IEMIMPL_AVX_PROLOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endmacro
IEMIMPL_AVX_P_BLEND vpblendvb
IEMIMPL_AVX_P_BLEND vblendvps
IEMIMPL_AVX_P_BLEND vblendvpd
;;
; palignr mm1, mm2/m64 instruction.
;
; @param A0 Pointer to the first media register sized operand (output).
; @param A1 The second register sized operand (input).
; @param A2 The 8-bit immediate.
BEGINPROC_FASTCALL iemAImpl_palignr_u64, 16
PROLOGUE_3_ARGS
IEMIMPL_MMX_PROLOGUE
movq mm0, [A0]
movq mm1, A1
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(endbrxx+palignr+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(palignr+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movq [A0], mm0
IEMIMPL_MMX_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
palignr mm0, mm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_palignr_u64
;;
; SSE instructions with 8-bit immediates of the form
; xxx xmm1, xmm2, imm8.
; where the instruction encoding takes up 6 bytes.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the first media register size operand (input/output).
; @param A1 Pointer to the second source media register size operand (input).
; @param A2 The 8-bit immediate
;
%macro IEMIMPL_MEDIA_SSE_INSN_IMM8_6 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
movdqu xmm1, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*2] ; sizeof(endbrxx+insnX+ret+int3) == 12: A2 * 12 = (A2 * 3) * 4
lea T1, [T1 + T0*4]
%else
lea T1, [T1 + A2*8] ; sizeof(insnX+ret+int3) == 8: A2 * 8
%endif
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x800
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 blendps
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 blendpd
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 pblendw
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 palignr
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 pclmulqdq
IEMIMPL_MEDIA_SSE_INSN_IMM8_6 aeskeygenassist
;;
; AVX instructions with 8-bit immediates of the form
; xxx {x,y}mm1, {x,y}mm2, {x,y}mm3, imm8.
; where the instruction encoding takes up 6 bytes.
;
; @param 1 The instruction name.
; @param 2 Whether the instruction has a 256-bit variant (1) or not (0).
;
; @param A0 Pointer to the destination media register size operand (output).
; @param A1 Pointer to the first source media register size operand (input).
; @param A2 Pointer to the second source media register size operand (input).
; @param A3 The 8-bit immediate
;
%macro IEMIMPL_MEDIA_AVX_INSN_IMM8_6 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
movdqu xmm0, [A1]
movdqu xmm1, [A2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*2] ; sizeof(endbrxx+insnX+ret+int3) == 12: A3 * 12 = (A3 * 3) * 4
lea T1, [T1 + T0*4]
%else
lea T1, [T1 + A3*8] ; sizeof(insnX+ret+int3) == 8: A3 * 8
%endif
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm0, xmm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x800
ENDPROC iemAImpl_ %+ %1 %+ _u128
%if %2 == 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u256, 16
PROLOGUE_4_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
vmovdqu ymm1, [A2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*2] ; sizeof(endbrxx+insnX+ret+int3) == 12: A3 * 12 = (A3 * 3) * 4
lea T1, [T1 + T0*4]
%else
lea T1, [T1 + A3*8] ; sizeof(insnX+ret+int3) == 8: A3 * 8
%endif
IBT_NOTRACK
call T1
vmovdqu [A0], ymm0
IEMIMPL_AVX_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 ymm0, ymm0, ymm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x800
ENDPROC iemAImpl_ %+ %1 %+ _u256
%endif
%endmacro
IEMIMPL_MEDIA_AVX_INSN_IMM8_6 vblendps, 1
IEMIMPL_MEDIA_AVX_INSN_IMM8_6 vblendpd, 1
IEMIMPL_MEDIA_AVX_INSN_IMM8_6 vpblendw, 1
IEMIMPL_MEDIA_AVX_INSN_IMM8_6 vpalignr, 1
IEMIMPL_MEDIA_AVX_INSN_IMM8_6 vpclmulqdq, 0
;;
; Need to move this as well somewhere better?
;
struc IEMPCMPISTRISRC
.uSrc1 resd 4
.uSrc2 resd 4
endstruc
;;
; The pcmpistri instruction.
;
; @param A0 Pointer to the ECX register to store the result to (output).
; @param A1 Pointer to the EFLAGS register.
; @param A2 Pointer to the structure containing the source operands (input).
; @param A3 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_pcmpistri_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A2 + IEMPCMPISTRISRC.uSrc1]
movdqu xmm1, [A2 + IEMPCMPISTRISRC.uSrc2]
mov T2, A0 ; A0 can be ecx/rcx in some calling conventions which gets overwritten later (T2 only available on AMD64)
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*2] ; sizeof(endbrxx+insnX+ret) == 12: A3 * 12 = (A3 * 3) * 4
lea T1, [T1 + T0*4]
%else
lea T1, [T1 + A3*8] ; sizeof(insnX+ret) == 8: A3 * 8
%endif
IBT_NOTRACK
call T1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
mov [T2], ecx
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pcmpistri xmm0, xmm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x800
ENDPROC iemAImpl_pcmpistri_u128
;;
; pinsrw instruction.
;
; @param A0 Pointer to the first media register size operand (input/output).
; @param A1 The 16 bit input operand (input).
; @param A2 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_pinsrw_u64, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movq mm0, [A0]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*8] ; sizeof(endbrxx+pinsrw+ret) == 9: A2 * 9
%else
lea T0, [A2 + A2*4] ; sizeof(pinsrw+ret) == 5: A2 * 5
%endif
lea T1, [T1 + T0]
IBT_NOTRACK
call T1
movq [A0], mm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pinsrw mm0, A1_32, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x500
ENDPROC iemAImpl_pinsrw_u64
BEGINPROC_FASTCALL iemAImpl_pinsrw_u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A0]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(endbrxx+pinsrw+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(pinsrw+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pinsrw xmm0, A1_32, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_pinsrw_u128
;;
; vpinsrw instruction.
;
; @param A0 Pointer to the first media register size operand (output).
; @param A1 Pointer to the source media register size operand (input).
; @param A2 The 16 bit input operand (input).
; @param A3 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_vpinsrw_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*4] ; sizeof(endbrxx+vpinsrw+ret) == 10: A3 * 10 = (A3 * 5) * 2
%else
lea T0, [A3 + A3*2] ; sizeof(vpinsrw+ret) == 6: A3 * 6 = (A3 * 3) * 2
%endif
lea T1, [T1 + T0*2]
mov A1, A2 ; A2 requires longer encoding on Windows
IBT_NOTRACK
call T1
movdqu [A0], xmm0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
vpinsrw xmm0, xmm0, A1_32, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_vpinsrw_u128
;;
; pextrw instruction.
;
; @param A0 Pointer to the 16bit output operand (output).
; @param A1 Pointer to the media register size operand (input).
; @param A2 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_pextrw_u64, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movq mm0, A1
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*8] ; sizeof(endbrxx+pextrw+ret) == 9: A2 * 9
%else
lea T0, [A2 + A2*4] ; sizeof(pextrw+ret) == 5: A2 * 5
%endif
lea T1, [T1 + T0]
IBT_NOTRACK
call T1
mov word [A0], T0_16
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pextrw T0_32, mm0, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x500
ENDPROC iemAImpl_pextrw_u64
BEGINPROC_FASTCALL iemAImpl_pextrw_u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(endbrxx+pextrw+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(pextrw+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
mov word [A0], T0_16
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
pextrw T0_32, xmm0, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_pextrw_u128
;;
; vpextrw instruction.
;
; @param A0 Pointer to the 16bit output operand (output).
; @param A1 Pointer to the source media register size operand (input).
; @param A2 The 8-bit immediate
;
BEGINPROC_FASTCALL iemAImpl_vpextrw_u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A1]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A2 + A2*4] ; sizeof(endbrxx+vpextrw+ret) == 10: A2 * 10 = (A2 * 5) * 2
%else
lea T0, [A2 + A2*2] ; sizeof(vpextrw+ret) == 6: A2 * 6 = (A2 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
mov word [A0], T0_16
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
vpextrw T0_32, xmm0, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_vpextrw_u128
;;
; movmskp{s,d} SSE instruction template
;
; @param 1 The SSE instruction name.
; @param 2 The AVX instruction name.
;
; @param A0 Pointer to the output register (output/byte sized).
; @param A1 Pointer to the source media register size operand (input).
;
%macro IEMIMPL_MEDIA_MOVMSK_P 2
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_2_ARGS
IEMIMPL_SSE_PROLOGUE
movdqu xmm0, [A1]
%1 T0, xmm0
mov byte [A0], T0_8
IEMIMPL_SSE_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %2 %+ _u128, 16
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
movdqu xmm0, [A1]
%2 T0, xmm0
mov byte [A0], T0_8
IEMIMPL_AVX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %2 %+ _u128
BEGINPROC_FASTCALL iemAImpl_ %+ %2 %+ _u256, 16
PROLOGUE_2_ARGS
IEMIMPL_AVX_PROLOGUE
vmovdqu ymm0, [A1]
%2 T0, ymm0
mov byte [A0], T0_8
IEMIMPL_AVX_EPILOGUE
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %2 %+ _u256
%endmacro
IEMIMPL_MEDIA_MOVMSK_P movmskps, vmovmskps
IEMIMPL_MEDIA_MOVMSK_P movmskpd, vmovmskpd
;;
; Restores the SSE MXCSR register with the original value.
;
; @uses 4 bytes of stack to save the content of MXCSR value, T0, T1.
; @param 1 Expression giving the address where to return the MXCSR value - only the MXCSR is stored, no IEMSSERESULT is used.
; @param 2 Expression giving the address of the FXSTATE of the guest.
;
; @note Restores the stack pointer.
;
%macro SSE_ST_FXSTATE_MXCSR_ONLY 2
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [xSP]
add xSP, 4
; Merge the status bits into the original MXCSR value.
mov T1_32, [%2 + X86FXSTATE.MXCSR]
and T0_32, X86_MXCSR_XCPT_FLAGS
or T0_32, T1_32
mov [%1], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; cvttsd2si instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvttsd2si_i32_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvttsd2si T0_32, [A3]
mov dword [A2], T0_32
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvttsd2si_i32_r64
;;
; cvttsd2si instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvttsd2si_i64_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvttsd2si T0, [A3]
mov qword [A2], T0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvttsd2si_i64_r64
;;
; cvtsd2si instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsd2si_i32_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsd2si T0_32, [A3]
mov dword [A2], T0_32
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsd2si_i32_r64
;;
; cvtsd2si instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsd2si_i64_r64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsd2si T0, [A3]
mov qword [A2], T0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsd2si_i64_r64
;;
; cvttss2si instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvttss2si_i32_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvttss2si T0_32, [A3]
mov dword [A2], T0_32
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvttss2si_i32_r32
;;
; cvttss2si instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvttss2si_i64_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvttss2si T0, [A3]
mov qword [A2], T0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvttss2si_i64_r32
;;
; cvtss2si instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtss2si_i32_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtss2si T0_32, [A3]
mov dword [A2], T0_32
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtss2si_i32_r32
;;
; cvtss2si instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtss2si_i64_r32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtss2si T0, [A3]
mov qword [A2], T0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtss2si_i64_r32
;;
; cvtsi2ss instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsi2ss_r32_i32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsi2ss xmm0, dword [A3]
movd dword [A2], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsi2ss_r32_i32
;;
; cvtsi2ss instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsi2ss_r32_i64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsi2ss xmm0, qword [A3]
movd dword [A2], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsi2ss_r32_i64
;;
; cvtsi2sd instruction - 32-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsi2sd_r64_i32, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsi2sd xmm0, dword [A3]
movq [A2], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsi2sd_r64_i32
;;
; cvtsi2sd instruction - 64-bit variant.
;
; @param A0 FPU context (FXSTATE or XSAVEAREA).
; @param A1 Where to return the MXCSR value.
; @param A2 Pointer to the result operand (output).
; @param A3 Pointer to the second operand (input).
;
BEGINPROC_FASTCALL iemAImpl_cvtsi2sd_r64_i64, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR A0
cvtsi2sd xmm0, qword [A3]
movq [A2], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY A1, A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_cvtsi2sd_r64_i64
;;
; Initialize the SSE MXCSR register using the guest value partially to
; account for rounding mode.
;
; @uses 4 bytes of stack to save the original value, T0.
; @param 1 Expression giving the address of the MXCSR register of the guest.
;
%macro SSE_LD_FXSTATE_MXCSR_ONLY 1
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [%1]
and T0_32, X86_MXCSR_FZ | X86_MXCSR_RC_MASK | X86_MXCSR_DAZ
or T0_32, X86_MXCSR_XCPT_MASK
sub xSP, 4
mov [xSP], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;;
; Restores the SSE MXCSR register with the original value.
;
; @uses 4 bytes of stack to save the content of MXCSR value, T0, T1.
; @param 1 Expression giving the address where to return the MXCSR value - only the MXCSR is stored, no IEMSSERESULT is used.
;
; @note Restores the stack pointer.
;
%macro SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE 1
sub xSP, 4
stmxcsr [xSP]
mov T0_32, [xSP]
add xSP, 4
; Merge the status bits into the original MXCSR value.
mov T1_32, [%1]
and T0_32, X86_MXCSR_XCPT_FLAGS
or T0_32, T1_32
mov [%1], T0_32
ldmxcsr [xSP]
add xSP, 4
%endmacro
;
; UCOMISS (SSE)
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the EFLAGS value (input/output).
; @param A2 Pointer to the first source operand (aka readonly destination).
; @param A3 Pointer to the second source operand.
;
BEGINPROC_FASTCALL iemAImpl_ucomiss_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
ucomiss xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ucomiss_u128
BEGINPROC_FASTCALL iemAImpl_vucomiss_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
vucomiss xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_vucomiss_u128
;
; UCOMISD (SSE)
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the EFLAGS value (input/output).
; @param A2 Pointer to the first source operand (aka readonly destination).
; @param A3 Pointer to the second source operand.
;
BEGINPROC_FASTCALL iemAImpl_ucomisd_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
ucomisd xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_ucomisd_u128
BEGINPROC_FASTCALL iemAImpl_vucomisd_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
vucomisd xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_vucomisd_u128
;
; COMISS (SSE)
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the EFLAGS value (input/output).
; @param A2 Pointer to the first source operand (aka readonly destination).
; @param A3 Pointer to the second source operand.
;
BEGINPROC_FASTCALL iemAImpl_comiss_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
comiss xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_comiss_u128
BEGINPROC_FASTCALL iemAImpl_vcomiss_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
vcomiss xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_vcomiss_u128
;
; COMISD (SSE)
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the EFLAGS value (input/output).
; @param A2 Pointer to the first source operand (aka readonly destination).
; @param A3 Pointer to the second source operand.
;
BEGINPROC_FASTCALL iemAImpl_comisd_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
comisd xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_comisd_u128
BEGINPROC_FASTCALL iemAImpl_vcomisd_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
movdqu xmm1, [A3]
vcomisd xmm0, xmm1
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
ENDPROC iemAImpl_vcomisd_u128
;;
; Need to move this as well somewhere better?
;
struc IEMMEDIAF2XMMSRC
.uSrc1 resd 4
.uSrc2 resd 4
endstruc
;
; CMPPS (SSE)
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first media register size operand (output).
; @param A2 Pointer to the two media register sized inputs - IEMMEDIAF2XMMSRC (input).
; @param A3 The 8-bit immediate (input).
;
BEGINPROC_FASTCALL iemAImpl_cmpps_u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2 + IEMMEDIAF2XMMSRC.uSrc1]
movdqu xmm1, [A2 + IEMMEDIAF2XMMSRC.uSrc2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*8] ; sizeof(endbrxx+cmpps+ret) == 9: A3 * 9
%else
lea T0, [A3 + A3*4] ; sizeof(cmpps+ret) == 5: A3 * 5
%endif
lea T1, [T1 + T0]
IBT_NOTRACK
call T1
movdqu [A1], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
cmpps xmm0, xmm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x500
ENDPROC iemAImpl_cmpps_u128
;;
; SSE instructions with 8-bit immediates of the form
; xxx xmm1, xmm2, imm8.
; where the instruction encoding takes up 5 bytes and we need to load and save the MXCSR
; register.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first media register size operand (output).
; @param A2 Pointer to the two media register sized inputs - IEMMEDIAF2XMMSRC (input).
; @param A3 The 8-bit immediate (input).
;
%macro IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_5 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2 + IEMMEDIAF2XMMSRC.uSrc1]
movdqu xmm1, [A2 + IEMMEDIAF2XMMSRC.uSrc2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*4] ; sizeof(endbrxx+cmpXX+ret) == 10: A3 * 10 = (A3 * 5) * 2
%else
lea T0, [A3 + A3*2] ; sizeof(cmpXX+ret) == 6: A3 * 6 = (A3 * 3) * 2
%endif
lea T1, [T1 + T0*2]
IBT_NOTRACK
call T1
movdqu [A1], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm1, bImm
ret
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x600
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_5 cmppd
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_5 cmpss
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_5 cmpsd
;;
; SSE instructions with 8-bit immediates of the form
; xxx xmm1, xmm2, imm8.
; where the instruction encoding takes up 6 bytes and we need to load and save the MXCSR
; register.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first media register size operand (output).
; @param A2 Pointer to the two media register sized inputs - IEMMEDIAF2XMMSRC (input).
; @param A3 The 8-bit immediate (input).
;
%macro IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_6 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_4_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2 + IEMMEDIAF2XMMSRC.uSrc1]
movdqu xmm1, [A2 + IEMMEDIAF2XMMSRC.uSrc2]
lea T1, [.imm0 xWrtRIP]
%ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
lea T0, [A3 + A3*2] ; sizeof(endbrxx+insn+ret+int3) == 12: A3 * 12 = (A3 * 3) * 4
lea T1, [T1 + T0*4]
%else
lea T1, [T1 + A3*8] ; sizeof(insn+ret+int3) == 8: A3 * 8
%endif
IBT_NOTRACK
call T1
movdqu [A1], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_4_ARGS
%assign bImm 0
%rep 256
.imm %+ bImm:
IBT_ENDBRxx_WITHOUT_NOTRACK
%1 xmm0, xmm1, bImm
ret
int3
%assign bImm bImm + 1
%endrep
.immEnd: IEMCHECK_256_JUMP_ARRAY_SIZE (.immEnd - .imm0), 0x800
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_6 roundps
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_6 roundpd
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_6 roundss
IEMIMPL_MEDIA_SSE_INSN_IMM8_MXCSR_6 roundsd
;;
; SSE instructions of the form
; xxx mm, xmm.
; and we need to load and save the MXCSR register.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first MMX register sized operand (output).
; @param A2 Pointer to the media register sized operand (input).
;
%macro IEMIMPL_MEDIA_SSE_MXCSR_I64_U128 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A2]
%1 mm0, xmm0
movq [A1], mm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_MXCSR_I64_U128 cvtpd2pi
IEMIMPL_MEDIA_SSE_MXCSR_I64_U128 cvttpd2pi
;;
; SSE instructions of the form
; xxx xmm, xmm/m64.
; and we need to load and save the MXCSR register.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first media register sized operand (input/output).
; @param A2 The 64bit source value from a MMX media register (input)
;
%macro IEMIMPL_MEDIA_SSE_MXCSR_U128_U64 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movdqu xmm0, [A1]
movq mm0, A2
%1 xmm0, mm0
movdqu [A1], xmm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_MXCSR_U128_U64 cvtpi2ps
IEMIMPL_MEDIA_SSE_MXCSR_U128_U64 cvtpi2pd
;;
; SSE instructions of the form
; xxx mm, xmm/m64.
; and we need to load and save the MXCSR register.
;
; @param 1 The instruction name.
;
; @param A0 Pointer to the MXCSR value (input/output).
; @param A1 Pointer to the first MMX media register sized operand (output).
; @param A2 The 64bit source value (input).
;
%macro IEMIMPL_MEDIA_SSE_MXCSR_U64_U64 1
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u128, 16
PROLOGUE_3_ARGS
IEMIMPL_SSE_PROLOGUE
SSE_LD_FXSTATE_MXCSR_ONLY A0
movq xmm0, A2
%1 mm0, xmm0
movq [A1], mm0
SSE_ST_FXSTATE_MXCSR_ONLY_NO_FXSTATE A0
IEMIMPL_SSE_EPILOGUE
EPILOGUE_3_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u128
%endmacro
IEMIMPL_MEDIA_SSE_MXCSR_U64_U64 cvtps2pi
IEMIMPL_MEDIA_SSE_MXCSR_U64_U64 cvttps2pi
;
; All forms of RDRAND and RDSEED
;
; @param A0 Pointer to the destination operand.
; @param A1 Pointer to the EFLAGS value (input/output).
;
%macro IEMIMPL_RDRAND_RDSEED 3
BEGINPROC_FASTCALL iemAImpl_ %+ %1 %+ _u %+ %3, 8
PROLOGUE_2_ARGS
%1 %2
mov [A0], %2
IEM_SAVE_FLAGS A1, X86_EFL_STATUS_BITS, 0
EPILOGUE_2_ARGS
ENDPROC iemAImpl_ %+ %1 %+ _u %+ %3
%endmacro
IEMIMPL_RDRAND_RDSEED rdrand, ax, 16
IEMIMPL_RDRAND_RDSEED rdrand, eax, 32
IEMIMPL_RDRAND_RDSEED rdrand, rax, 64
IEMIMPL_RDRAND_RDSEED rdseed, ax, 16
IEMIMPL_RDRAND_RDSEED rdseed, eax, 32
IEMIMPL_RDRAND_RDSEED rdseed, rax, 64
|