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
|
; Copyright © 2021, VideoLAN and dav1d authors
; Copyright © 2021, Two Orioles, LLC
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%include "config.asm"
%include "ext/x86/x86inc.asm"
SECTION_RODATA
filter_shuf: db 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 2, 3, -1, -1
pal_pred_shuf: db 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15
z_base_inc: dw 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64
z_base_inc_z2: dw 7*64, 6*64, 5*64, 4*64, 3*64, 2*64, 1*64, 0*64
z_upsample: db 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15
z2_upsample_l: db -1, -1, -2, -1, -3, -1, -4, -1, 8, 9, 8, 9, 10, 11, 12, 13
db 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
z2_top_shufA: db 0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 8, 9
z2_top_shufB: db 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15
z2_left_shufA: db 14, 15, 12, 13, 10, 11, 8, 9, 12, 13, 10, 11, 8, 9, 6, 7
z2_left_shufB: db 14, 15, 10, 11, 6, 7, 2, 3, 12, 13, 8, 9, 4, 5, 0, 1
z_filt_wh16: db 19, 19, 19, 23, 23, 23, 31, 31, 31, 47, 47, 47, 79, 79, 79, -1
z_filt_t_w48: db 55,127, 7,127, 15, 31, 39, 31,127, 39,127, 39, 7, 15, 31, 15
db 39, 63, 3, 63, 3, 3, 19, 3, 47, 19, 47, 19, 3, 3, 3, 3
z_filt_t_w16: db 15, 31, 7, 15, 31, 7, 3, 31, 3, 3, 3, 3, 3, 3, 0, 0
z_filt_wh4: db 7, 7, 19, 7,
z_filt_wh8: db 19, 19, 11, 19, 11, 15, 15, 15, 23, 23, 23, 23, 39, 39, 39, 39
ALIGN 8
pb_2_3: times 4 db 2, 3
z2_dy_offset: dw 96*64, 96*64, 95*64, 95*64
z_filt_k: times 4 dw 8
times 4 dw 6
times 4 dw 4
times 4 dw 5
pw_m3584: times 4 dw -3584
pw_m3072: times 4 dw -3072
pw_m2560: times 4 dw -2560
pw_m2048: times 4 dw -2048
pw_m1536: times 4 dw -1536
pw_m1024: times 4 dw -1024
pw_m512: times 4 dw -512
pw_1: times 4 dw 1
pw_2: times 4 dw 2
pw_3: times 4 dw 3
pw_62: times 4 dw 62
pw_256: times 4 dw 256
pw_512: times 4 dw 512
pw_2048: times 4 dw 2048
%define pw_4 (z_filt_k+8*2)
%define pw_8 (z_filt_k+8*0)
%define pw_m1to4 z2_upsample_l
%macro JMP_TABLE 3-*
%xdefine %1_%2_table (%%table - 2*4)
%xdefine %%base mangle(private_prefix %+ _%1_%2)
%%table:
%rep %0 - 2
dd %%base %+ .%3 - (%%table - 2*4)
%rotate 1
%endrep
%endmacro
%define ipred_dc_splat_16bpc_ssse3_table (ipred_dc_16bpc_ssse3_table + 10*4)
%define ipred_dc_128_16bpc_ssse3_table (ipred_dc_16bpc_ssse3_table + 15*4)
%define ipred_cfl_splat_16bpc_ssse3_table (ipred_cfl_16bpc_ssse3_table + 8*4)
JMP_TABLE ipred_dc_left_16bpc, ssse3, h4, h8, h16, h32, h64
JMP_TABLE ipred_dc_16bpc, ssse3, h4, h8, h16, h32, h64, w4, w8, w16, w32, w64, \
s4-10*4, s8-10*4, s16-10*4, s32-10*4, s64-10*4, \
s4-15*4, s8-15*4, s16c-15*4, s32c-15*4, s64-15*4
JMP_TABLE ipred_h_16bpc, ssse3, w4, w8, w16, w32, w64
JMP_TABLE ipred_z1_16bpc, ssse3, w4, w8, w16, w32, w64
JMP_TABLE ipred_z2_16bpc, ssse3, w4, w8, w16, w32, w64
JMP_TABLE ipred_z3_16bpc, ssse3, h4, h8, h16, h32, h64
JMP_TABLE ipred_cfl_16bpc, ssse3, h4, h8, h16, h32, w4, w8, w16, w32, \
s4-8*4, s8-8*4, s16-8*4, s32-8*4
JMP_TABLE ipred_cfl_left_16bpc, ssse3, h4, h8, h16, h32
JMP_TABLE ipred_cfl_ac_444_16bpc, ssse3, w4, w8, w16, w32
JMP_TABLE pal_pred_16bpc, ssse3, w4, w8, w16, w32, w64
cextern smooth_weights_1d_16bpc
cextern smooth_weights_2d_16bpc
cextern dr_intra_derivative
cextern filter_intra_taps
SECTION .text
INIT_XMM ssse3
cglobal ipred_dc_top_16bpc, 3, 7, 6, dst, stride, tl, w, h
LEA r5, ipred_dc_left_16bpc_ssse3_table
movd m4, wm
tzcnt wd, wm
add tlq, 2
movifnidn hd, hm
pxor m3, m3
pavgw m4, m3
movd m5, wd
movu m0, [tlq]
movsxd r6, [r5+wq*4]
add r6, r5
add r5, ipred_dc_128_16bpc_ssse3_table-ipred_dc_left_16bpc_ssse3_table
movsxd wq, [r5+wq*4]
add wq, r5
jmp r6
cglobal ipred_dc_left_16bpc, 3, 7, 6, dst, stride, tl, w, h, stride3
LEA r5, ipred_dc_left_16bpc_ssse3_table
mov hd, hm
movd m4, hm
tzcnt r6d, hd
sub tlq, hq
tzcnt wd, wm
pxor m3, m3
sub tlq, hq
pavgw m4, m3
movd m5, r6d
movu m0, [tlq]
movsxd r6, [r5+r6*4]
add r6, r5
add r5, ipred_dc_128_16bpc_ssse3_table-ipred_dc_left_16bpc_ssse3_table
movsxd wq, [r5+wq*4]
add wq, r5
jmp r6
.h64:
movu m2, [tlq+112]
movu m1, [tlq+ 96]
paddw m0, m2
movu m2, [tlq+ 80]
paddw m1, m2
movu m2, [tlq+ 64]
paddw m0, m2
paddw m0, m1
.h32:
movu m1, [tlq+ 48]
movu m2, [tlq+ 32]
paddw m1, m2
paddw m0, m1
.h16:
movu m1, [tlq+ 16]
paddw m0, m1
.h8:
movhlps m1, m0
paddw m0, m1
.h4:
punpcklwd m0, m3
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m4, m0, q1032
paddd m0, m4
psrld m0, m5
lea stride3q, [strideq*3]
pshuflw m0, m0, q0000
punpcklqdq m0, m0
jmp wq
cglobal ipred_dc_16bpc, 4, 7, 6, dst, stride, tl, w, h, stride3
movifnidn hd, hm
tzcnt r6d, hd
lea r5d, [wq+hq]
movd m4, r5d
tzcnt r5d, r5d
movd m5, r5d
LEA r5, ipred_dc_16bpc_ssse3_table
tzcnt wd, wd
movsxd r6, [r5+r6*4]
movsxd wq, [r5+wq*4+5*4]
pxor m3, m3
psrlw m4, 1
add r6, r5
add wq, r5
lea stride3q, [strideq*3]
jmp r6
.h4:
movq m0, [tlq-8]
jmp wq
.w4:
movq m1, [tlq+2]
paddw m1, m0
punpckhwd m0, m3
punpcklwd m1, m3
paddd m0, m1
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m1, m0, q1032
paddd m0, m1
cmp hd, 4
jg .w4_mul
psrlw m0, 3
jmp .w4_end
.w4_mul:
mov r2d, 0xAAAB
mov r3d, 0x6667
cmp hd, 16
cmove r2d, r3d
psrld m0, 2
movd m1, r2d
pmulhuw m0, m1
psrlw m0, 1
.w4_end:
pshuflw m0, m0, q0000
.s4:
movq [dstq+strideq*0], m0
movq [dstq+strideq*1], m0
movq [dstq+strideq*2], m0
movq [dstq+stride3q ], m0
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s4
RET
.h8:
mova m0, [tlq-16]
jmp wq
.w8:
movu m1, [tlq+2]
paddw m0, m1
punpcklwd m1, m0, m3
punpckhwd m0, m3
paddd m0, m1
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m1, m0, q1032
paddd m0, m1
psrld m0, m5
cmp hd, 8
je .w8_end
mov r2d, 0xAAAB
mov r3d, 0x6667
cmp hd, 32
cmove r2d, r3d
movd m1, r2d
pmulhuw m0, m1
psrlw m0, 1
.w8_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s8:
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m0
mova [dstq+strideq*2], m0
mova [dstq+stride3q ], m0
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s8
RET
.h16:
mova m0, [tlq-32]
paddw m0, [tlq-16]
jmp wq
.w16:
movu m1, [tlq+ 2]
movu m2, [tlq+18]
paddw m1, m2
paddw m0, m1
punpckhwd m1, m0, m3
punpcklwd m0, m3
paddd m0, m1
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m1, m0, q1032
paddd m0, m1
psrld m0, m5
cmp hd, 16
je .w16_end
mov r2d, 0xAAAB
mov r3d, 0x6667
test hd, 8|32
cmovz r2d, r3d
movd m1, r2d
pmulhuw m0, m1
psrlw m0, 1
.w16_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s16c:
mova m1, m0
.s16:
mova [dstq+strideq*0+16*0], m0
mova [dstq+strideq*0+16*1], m1
mova [dstq+strideq*1+16*0], m0
mova [dstq+strideq*1+16*1], m1
mova [dstq+strideq*2+16*0], m0
mova [dstq+strideq*2+16*1], m1
mova [dstq+stride3q +16*0], m0
mova [dstq+stride3q +16*1], m1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s16
RET
.h32:
mova m0, [tlq-64]
paddw m0, [tlq-48]
paddw m0, [tlq-32]
paddw m0, [tlq-16]
jmp wq
.w32:
movu m1, [tlq+ 2]
movu m2, [tlq+18]
paddw m1, m2
movu m2, [tlq+34]
paddw m0, m2
movu m2, [tlq+50]
paddw m1, m2
paddw m0, m1
punpcklwd m1, m0, m3
punpckhwd m0, m3
paddd m0, m1
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m1, m0, q1032
paddd m0, m1
psrld m0, m5
cmp hd, 32
je .w32_end
mov r2d, 0xAAAB
mov r3d, 0x6667
cmp hd, 8
cmove r2d, r3d
movd m1, r2d
pmulhuw m0, m1
psrlw m0, 1
.w32_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s32c:
mova m1, m0
mova m2, m0
mova m3, m0
.s32:
mova [dstq+strideq*0+16*0], m0
mova [dstq+strideq*0+16*1], m1
mova [dstq+strideq*0+16*2], m2
mova [dstq+strideq*0+16*3], m3
mova [dstq+strideq*1+16*0], m0
mova [dstq+strideq*1+16*1], m1
mova [dstq+strideq*1+16*2], m2
mova [dstq+strideq*1+16*3], m3
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .s32
RET
.h64:
mova m0, [tlq-128]
mova m1, [tlq-112]
paddw m0, [tlq- 96]
paddw m1, [tlq- 80]
paddw m0, [tlq- 64]
paddw m1, [tlq- 48]
paddw m0, [tlq- 32]
paddw m1, [tlq- 16]
paddw m0, m1
jmp wq
.w64:
movu m1, [tlq+ 2]
movu m2, [tlq+ 18]
paddw m1, m2
movu m2, [tlq+ 34]
paddw m0, m2
movu m2, [tlq+ 50]
paddw m1, m2
movu m2, [tlq+ 66]
paddw m0, m2
movu m2, [tlq+ 82]
paddw m1, m2
movu m2, [tlq+ 98]
paddw m0, m2
movu m2, [tlq+114]
paddw m1, m2
paddw m0, m1
punpcklwd m1, m0, m3
punpckhwd m0, m3
paddd m0, m1
paddd m4, m0
punpckhqdq m0, m0
paddd m0, m4
pshuflw m1, m0, q1032
paddd m0, m1
psrld m0, m5
cmp hd, 64
je .w64_end
mov r2d, 0xAAAB
mov r3d, 0x6667
cmp hd, 16
cmove r2d, r3d
movd m1, r2d
pmulhuw m0, m1
psrlw m0, 1
.w64_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s64:
mova [dstq+16*0], m0
mova [dstq+16*1], m0
mova [dstq+16*2], m0
mova [dstq+16*3], m0
mova [dstq+16*4], m0
mova [dstq+16*5], m0
mova [dstq+16*6], m0
mova [dstq+16*7], m0
add dstq, strideq
dec hd
jg .s64
RET
cglobal ipred_dc_128_16bpc, 2, 7, 6, dst, stride, tl, w, h, stride3
mov r6d, r8m
LEA r5, ipred_dc_128_16bpc_ssse3_table
tzcnt wd, wm
shr r6d, 11
movifnidn hd, hm
movsxd wq, [r5+wq*4]
movddup m0, [r5-ipred_dc_128_16bpc_ssse3_table+pw_512+r6*8]
add wq, r5
lea stride3q, [strideq*3]
jmp wq
cglobal ipred_v_16bpc, 4, 7, 6, dst, stride, tl, w, h, stride3
LEA r5, ipred_dc_splat_16bpc_ssse3_table
movifnidn hd, hm
movu m0, [tlq+ 2]
movu m1, [tlq+ 18]
movu m2, [tlq+ 34]
movu m3, [tlq+ 50]
cmp wd, 64
je .w64
tzcnt wd, wd
movsxd wq, [r5+wq*4]
add wq, r5
lea stride3q, [strideq*3]
jmp wq
.w64:
WIN64_SPILL_XMM 8
movu m4, [tlq+ 66]
movu m5, [tlq+ 82]
movu m6, [tlq+ 98]
movu m7, [tlq+114]
.w64_loop:
mova [dstq+16*0], m0
mova [dstq+16*1], m1
mova [dstq+16*2], m2
mova [dstq+16*3], m3
mova [dstq+16*4], m4
mova [dstq+16*5], m5
mova [dstq+16*6], m6
mova [dstq+16*7], m7
add dstq, strideq
dec hd
jg .w64_loop
RET
cglobal ipred_h_16bpc, 3, 6, 4, dst, stride, tl, w, h, stride3
%define base r5-ipred_h_16bpc_ssse3_table
tzcnt wd, wm
LEA r5, ipred_h_16bpc_ssse3_table
movifnidn hd, hm
movsxd wq, [r5+wq*4]
movddup m2, [base+pw_256]
movddup m3, [base+pb_2_3]
add wq, r5
lea stride3q, [strideq*3]
jmp wq
.w4:
sub tlq, 8
movq m3, [tlq]
pshuflw m0, m3, q3333
pshuflw m1, m3, q2222
pshuflw m2, m3, q1111
pshuflw m3, m3, q0000
movq [dstq+strideq*0], m0
movq [dstq+strideq*1], m1
movq [dstq+strideq*2], m2
movq [dstq+stride3q ], m3
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4
RET
.w8:
sub tlq, 8
movq m3, [tlq]
punpcklwd m3, m3
pshufd m0, m3, q3333
pshufd m1, m3, q2222
pshufd m2, m3, q1111
pshufd m3, m3, q0000
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
mova [dstq+strideq*2], m2
mova [dstq+stride3q ], m3
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w8
RET
.w16:
sub tlq, 4
movd m1, [tlq]
pshufb m0, m1, m3
pshufb m1, m2
mova [dstq+strideq*0+16*0], m0
mova [dstq+strideq*0+16*1], m0
mova [dstq+strideq*1+16*0], m1
mova [dstq+strideq*1+16*1], m1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w16
RET
.w32:
sub tlq, 4
movd m1, [tlq]
pshufb m0, m1, m3
pshufb m1, m2
mova [dstq+strideq*0+16*0], m0
mova [dstq+strideq*0+16*1], m0
mova [dstq+strideq*0+16*2], m0
mova [dstq+strideq*0+16*3], m0
mova [dstq+strideq*1+16*0], m1
mova [dstq+strideq*1+16*1], m1
mova [dstq+strideq*1+16*2], m1
mova [dstq+strideq*1+16*3], m1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w32
RET
.w64:
sub tlq, 2
movd m0, [tlq]
pshufb m0, m2
mova [dstq+16*0], m0
mova [dstq+16*1], m0
mova [dstq+16*2], m0
mova [dstq+16*3], m0
mova [dstq+16*4], m0
mova [dstq+16*5], m0
mova [dstq+16*6], m0
mova [dstq+16*7], m0
add dstq, strideq
dec hd
jg .w64
RET
cglobal ipred_paeth_16bpc, 4, 6, 8, dst, stride, tl, w, h, left
%define base r5-ipred_paeth_16bpc_ssse3_table
movifnidn hd, hm
pshuflw m4, [tlq], q0000
mov leftq, tlq
add hd, hd
punpcklqdq m4, m4 ; topleft
sub leftq, hq
and wd, ~7
jnz .w8
movddup m5, [tlq+2] ; top
psubw m6, m5, m4
pabsw m7, m6
.w4_loop:
movd m1, [leftq+hq-4]
punpcklwd m1, m1
punpckldq m1, m1 ; left
%macro PAETH 0
paddw m0, m6, m1
psubw m2, m4, m0 ; tldiff
psubw m0, m5 ; tdiff
pabsw m2, m2
pabsw m0, m0
pminsw m2, m0
pcmpeqw m0, m2
pand m3, m5, m0
pandn m0, m4
por m0, m3
pcmpgtw m3, m7, m2
pand m0, m3
pandn m3, m1
por m0, m3
%endmacro
PAETH
movhps [dstq+strideq*0], m0
movq [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
sub hd, 2*2
jg .w4_loop
RET
.w8:
%if ARCH_X86_32
PUSH r6
%define r7d hm
%assign regs_used 7
%elif WIN64
movaps r4m, m8
PUSH r7
%assign regs_used 8
%endif
%if ARCH_X86_64
movddup m8, [pw_256]
%endif
lea tlq, [tlq+wq*2+2]
neg wq
mov r7d, hd
.w8_loop0:
movu m5, [tlq+wq*2]
mov r6, dstq
add dstq, 16
psubw m6, m5, m4
pabsw m7, m6
.w8_loop:
movd m1, [leftq+hq-2]
%if ARCH_X86_64
pshufb m1, m8
%else
pshuflw m1, m1, q0000
punpcklqdq m1, m1
%endif
PAETH
mova [r6], m0
add r6, strideq
sub hd, 1*2
jg .w8_loop
mov hd, r7d
add wq, 8
jl .w8_loop0
%if WIN64
movaps m8, r4m
%endif
RET
%if ARCH_X86_64
DECLARE_REG_TMP 7
%else
DECLARE_REG_TMP 4
%endif
cglobal ipred_smooth_v_16bpc, 4, 6, 6, dst, stride, tl, w, h, weights
LEA weightsq, smooth_weights_1d_16bpc
mov hd, hm
lea weightsq, [weightsq+hq*4]
neg hq
movd m5, [tlq+hq*2] ; bottom
pshuflw m5, m5, q0000
punpcklqdq m5, m5
cmp wd, 4
jne .w8
movddup m4, [tlq+2] ; top
lea r3, [strideq*3]
psubw m4, m5 ; top - bottom
.w4_loop:
movq m1, [weightsq+hq*2]
punpcklwd m1, m1
pshufd m0, m1, q1100
punpckhdq m1, m1
pmulhrsw m0, m4
pmulhrsw m1, m4
paddw m0, m5
paddw m1, m5
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
movq [dstq+strideq*2], m1
movhps [dstq+r3 ], m1
lea dstq, [dstq+strideq*4]
add hq, 4
jl .w4_loop
RET
.w8:
%if ARCH_X86_32
PUSH r6
%assign regs_used 7
mov hm, hq
%define hq hm
%elif WIN64
PUSH r7
%assign regs_used 8
%endif
.w8_loop0:
mov t0, hq
movu m4, [tlq+2]
add tlq, 16
mov r6, dstq
add dstq, 16
psubw m4, m5
.w8_loop:
movq m3, [weightsq+t0*2]
punpcklwd m3, m3
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
REPX {paddw x, m5}, m0, m1, m2, m3
mova [r6+strideq*0], m0
mova [r6+strideq*1], m1
lea r6, [r6+strideq*2]
mova [r6+strideq*0], m2
mova [r6+strideq*1], m3
lea r6, [r6+strideq*2]
add t0, 4
jl .w8_loop
sub wd, 8
jg .w8_loop0
RET
cglobal ipred_smooth_h_16bpc, 3, 6, 6, dst, stride, tl, w, h, weights
LEA weightsq, smooth_weights_1d_16bpc
mov wd, wm
movifnidn hd, hm
movd m5, [tlq+wq*2] ; right
sub tlq, 8
add hd, hd
pshuflw m5, m5, q0000
sub tlq, hq
punpcklqdq m5, m5
cmp wd, 4
jne .w8
movddup m4, [weightsq+4*2]
lea r3, [strideq*3]
.w4_loop:
movq m1, [tlq+hq] ; left
punpcklwd m1, m1
psubw m1, m5 ; left - right
pshufd m0, m1, q3322
punpckldq m1, m1
pmulhrsw m0, m4
pmulhrsw m1, m4
paddw m0, m5
paddw m1, m5
movhps [dstq+strideq*0], m0
movq [dstq+strideq*1], m0
movhps [dstq+strideq*2], m1
movq [dstq+r3 ], m1
lea dstq, [dstq+strideq*4]
sub hd, 4*2
jg .w4_loop
RET
.w8:
lea weightsq, [weightsq+wq*4]
neg wq
%if ARCH_X86_32
PUSH r6
%assign regs_used 7
%define hd hm
%elif WIN64
PUSH r7
%assign regs_used 8
%endif
.w8_loop0:
mov t0d, hd
mova m4, [weightsq+wq*2]
mov r6, dstq
add dstq, 16
.w8_loop:
movq m3, [tlq+t0*(1+ARCH_X86_32)]
punpcklwd m3, m3
psubw m3, m5
pshufd m0, m3, q3333
pshufd m1, m3, q2222
pshufd m2, m3, q1111
pshufd m3, m3, q0000
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
REPX {paddw x, m5}, m0, m1, m2, m3
mova [r6+strideq*0], m0
mova [r6+strideq*1], m1
lea r6, [r6+strideq*2]
mova [r6+strideq*0], m2
mova [r6+strideq*1], m3
lea r6, [r6+strideq*2]
sub t0d, 4*(1+ARCH_X86_64)
jg .w8_loop
add wq, 8
jl .w8_loop0
RET
%if ARCH_X86_64
DECLARE_REG_TMP 10
%else
DECLARE_REG_TMP 3
%endif
cglobal ipred_smooth_16bpc, 3, 7, 8, dst, stride, tl, w, h, \
h_weights, v_weights, top
LEA h_weightsq, smooth_weights_2d_16bpc
mov wd, wm
mov hd, hm
movd m7, [tlq+wq*2] ; right
lea v_weightsq, [h_weightsq+hq*8]
neg hq
movd m6, [tlq+hq*2] ; bottom
pshuflw m7, m7, q0000
pshuflw m6, m6, q0000
cmp wd, 4
jne .w8
movq m4, [tlq+2] ; top
mova m5, [h_weightsq+4*4]
punpcklwd m4, m6 ; top, bottom
pxor m6, m6
.w4_loop:
movq m1, [v_weightsq+hq*4]
sub tlq, 4
movd m3, [tlq] ; left
pshufd m0, m1, q0000
pshufd m1, m1, q1111
pmaddwd m0, m4
punpcklwd m3, m7 ; left, right
pmaddwd m1, m4
pshufd m2, m3, q1111
pshufd m3, m3, q0000
pmaddwd m2, m5
pmaddwd m3, m5
paddd m0, m2
paddd m1, m3
psrld m0, 8
psrld m1, 8
packssdw m0, m1
pavgw m0, m6
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
add hq, 2
jl .w4_loop
RET
.w8:
%if ARCH_X86_32
lea h_weightsq, [h_weightsq+wq*4]
mov t0, tlq
mov r1m, tlq
mov r2m, hq
%define m8 [h_weightsq+16*0]
%define m9 [h_weightsq+16*1]
%else
%if WIN64
movaps r4m, m8
movaps r6m, m9
PUSH r7
PUSH r8
%endif
PUSH r9
PUSH r10
%assign regs_used 11
lea h_weightsq, [h_weightsq+wq*8]
lea topq, [tlq+wq*2]
neg wq
mov r8, tlq
mov r9, hq
%endif
punpcklqdq m6, m6
.w8_loop0:
%if ARCH_X86_32
movu m5, [t0+2]
add t0, 16
mov r0m, t0
%else
movu m5, [topq+wq*2+2]
mova m8, [h_weightsq+wq*4+16*0]
mova m9, [h_weightsq+wq*4+16*1]
%endif
mov t0, dstq
add dstq, 16
punpcklwd m4, m5, m6
punpckhwd m5, m6
.w8_loop:
movd m1, [v_weightsq+hq*4]
sub tlq, 2
movd m3, [tlq] ; left
pshufd m1, m1, q0000
pmaddwd m0, m4, m1
pshuflw m3, m3, q0000
pmaddwd m1, m5
punpcklwd m3, m7 ; left, right
pmaddwd m2, m8, m3
pmaddwd m3, m9
paddd m0, m2
paddd m1, m3
psrld m0, 8
psrld m1, 8
packssdw m0, m1
pxor m1, m1
pavgw m0, m1
mova [t0], m0
add t0, strideq
inc hq
jl .w8_loop
%if ARCH_X86_32
mov t0, r0m
mov tlq, r1m
add h_weightsq, 16*2
mov hq, r2m
sub dword wm, 8
jg .w8_loop0
%else
mov tlq, r8
mov hq, r9
add wq, 8
jl .w8_loop0
%endif
%if WIN64
movaps m8, r4m
movaps m9, r6m
%endif
RET
%if ARCH_X86_64
cglobal ipred_z1_16bpc, 3, 8, 8, 16*18, dst, stride, tl, w, h, angle, dx
%define base r7-$$
%define bdmaxm r8m
lea r7, [$$]
%else
cglobal ipred_z1_16bpc, 3, 7, 8, -16*18, dst, stride, tl, w, h, angle, dx
%define base r1-$$
%define stridemp [rsp+4*0]
%define bdmaxm [rsp+4*1]
mov r3, r8m
mov stridemp, r1
mov bdmaxm, r3
LEA r1, $$
%endif
tzcnt wd, wm
movifnidn angled, anglem
movifnidn hd, hm
add tlq, 2
movsxd wq, [base+ipred_z1_16bpc_ssse3_table+wq*4]
mov dxd, angled
movddup m0, [base+pw_256]
and dxd, 0x7e
movddup m7, [base+pw_62]
add angled, 165 ; ~90
lea wq, [base+wq+ipred_z1_16bpc_ssse3_table]
movzx dxd, word [base+dr_intra_derivative+dxq]
xor angled, 0x4ff ; d = 90 - angle
jmp wq
.w4:
lea r3d, [angleq+88]
test r3d, 0x480
jnz .w4_no_upsample ; !enable_intra_edge_filter || angle >= 40
sar r3d, 9
add r3d, hd
cmp r3d, 8
jg .w4_no_upsample ; h > 8 || (w == h && is_sm)
movd m3, [tlq+14]
movu m2, [tlq+ 0] ; 1 2 3 4 5 6 7 8
movd m1, bdmaxm
pshufb m3, m0
palignr m4, m3, m2, 4 ; 3 4 5 6 7 8 8 8
paddw m4, [tlq- 2] ; 0 1 2 3 4 5 6 7
add dxd, dxd
mova [rsp+32], m3
palignr m3, m2, 2 ; 2 3 4 5 6 7 8 8
pshufb m1, m0
paddw m3, m2 ; -1 * a + 9 * b + 9 * c + -1 * d
psubw m5, m3, m4 ; = (b + c - a - d + (b + c) << 3 + 8) >> 4
movd m4, dxd
psraw m5, 3 ; = ((b + c - a - d) >> 3 + b + c + 1) >> 1
paddw m3, m5
pxor m5, m5
pmaxsw m3, m5
mov r3d, dxd
pavgw m3, m5
pshufb m4, m0
pminsw m3, m1
punpcklwd m1, m2, m3
punpckhwd m2, m3
mova m3, [base+z_upsample]
movifnidn strideq, stridemp
mova [rsp+ 0], m1
paddw m5, m4, m4
mova [rsp+16], m2
punpcklqdq m4, m5 ; xpos0 xpos1
.w4_upsample_loop:
lea r2d, [r3+dxq]
shr r3d, 6 ; base0
movu m1, [rsp+r3*2]
lea r3d, [r2+dxq]
shr r2d, 6 ; base1
movu m2, [rsp+r2*2]
pshufb m1, m3
pshufb m2, m3
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
pand m2, m7, m4 ; frac
psllw m2, 9 ; (a * (64 - frac) + b * frac + 32) >> 6
psubw m1, m0 ; = a + (((b - a) * frac + 32) >> 6)
pmulhrsw m1, m2 ; = a + (((b - a) * (frac << 9) + 16384) >> 15)
paddw m4, m5 ; xpos += dx
paddw m0, m1
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w4_upsample_loop
RET
.w4_no_upsample:
mov r3d, 7 ; max_base
test angled, 0x400 ; !enable_intra_edge_filter
jnz .w4_main
lea r3d, [hq+3]
movd m1, r3d
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
pcmpeqb m1, [base+z_filt_wh4]
pand m1, m3
pcmpgtb m1, [base+z_filt_t_w48+angleq*8]
pmovmskb r5d, m1
mov r3d, 7
test r5d, r5d
jz .w4_main ; filter_strength == 0
pshuflw m1, [tlq-2], q0000
movu m2, [tlq+16*0]
imul r5d, 0x55555555
movd m3, [tlq+r3*2]
shr r5d, 30 ; filter_strength
movd [rsp+12], m1
pshuflw m3, m3, q0000
mova [rsp+16*1], m2
lea r2d, [r3+2]
movq [rsp+r3*2+18], m3
cmp hd, 8
cmovae r3d, r2d
lea tlq, [rsp+16*1]
call .filter_edge
.w4_main:
lea tlq, [tlq+r3*2]
movd m4, dxd
movddup m1, [base+z_base_inc] ; base_inc << 6
movd m6, [tlq] ; top[max_base_x]
shl r3d, 6
movd m3, r3d
pshufb m4, m0
mov r5d, dxd ; xpos
pshufb m6, m0
sub r5, r3
pshufb m3, m0
paddw m5, m4, m4
psubw m3, m1 ; max_base_x
punpcklqdq m4, m5 ; xpos0 xpos1
movifnidn strideq, stridemp
.w4_loop:
lea r3, [r5+dxq]
sar r5, 6 ; base0
movq m0, [tlq+r5*2+0]
movq m1, [tlq+r5*2+2]
lea r5, [r3+dxq]
sar r3, 6 ; base1
movhps m0, [tlq+r3*2+0]
movhps m1, [tlq+r3*2+2]
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
pcmpgtw m2, m3, m4 ; xpos < max_base_x
paddw m4, m5 ; xpos += dx
paddw m0, m1
pand m0, m2
pandn m2, m6
por m0, m2
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
sub hd, 2
jz .w4_end
lea dstq, [dstq+strideq*2]
test r5d, r5d
jl .w4_loop
.w4_end_loop:
movq [dstq+strideq*0], m6
movq [dstq+strideq*1], m6
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w4_end_loop
.w4_end:
RET
.w8:
lea r3d, [angleq+88]
and r3d, ~0x7f
or r3d, hd
cmp r3d, 8
ja .w8_no_upsample ; !enable_intra_edge_filter || is_sm || d >= 40 || h > 8
movu m1, [tlq+ 0] ; 1 2 3 4 5 6 7 8
movu m5, [tlq+ 2] ; 2 3 4 5 6 7 8 9
movu m3, [tlq+ 4] ; 3 4 5 6 7 8 9 a
paddw m5, m1
paddw m3, [tlq- 2] ; 0 1 2 3 4 5 6 7
psubw m2, m5, m3
movu m6, [tlq+18] ; a b c d e f g _
psraw m2, 3
movu m3, [tlq+20] ; b c d e f g _ _
paddw m5, m2
movu m2, [tlq+16] ; 9 a b c d e f g
paddw m6, m2
add dxd, dxd
cmp hd, 4
jne .w8_upsample_h8 ; awkward single-pixel edge case
pshuflw m3, m3, q1110 ; b c c _ _ _ _ _
.w8_upsample_h8:
paddw m3, [tlq+14] ; 8 9 a b c d e f
psubw m4, m6, m3
movd m3, bdmaxm
psraw m4, 3
mov r3d, dxd
paddw m6, m4
pxor m4, m4
pmaxsw m5, m4
pmaxsw m6, m4
pshufb m3, m0
pavgw m5, m4
pavgw m6, m4
movd m4, dxd
pminsw m5, m3
pminsw m6, m3
mova m3, [base+z_upsample]
pshufb m4, m0
movifnidn strideq, stridemp
punpcklwd m0, m1, m5
mova [rsp+ 0], m0
punpckhwd m1, m5
mova [rsp+16], m1
punpcklwd m0, m2, m6
mova [rsp+32], m0
punpckhwd m2, m6
mova [rsp+48], m2
mova m5, m4
.w8_upsample_loop:
mov r2d, r3d
shr r2d, 6
movu m1, [rsp+r2*2+ 0]
movu m2, [rsp+r2*2+16]
add r3d, dxd
pshufb m1, m3
pshufb m2, m3
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m4, m5
paddw m0, m1
mova [dstq], m0
add dstq, strideq
dec hd
jg .w8_upsample_loop
RET
.w8_no_upsample:
lea r3d, [hq+7]
movd m1, r3d
and r3d, 7
or r3d, 8 ; imin(h+7, 15)
test angled, 0x400
jnz .w8_main
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
movu m2, [base+z_filt_wh8]
psrldq m4, [base+z_filt_t_w48+angleq*8], 4
pcmpeqb m2, m1
pand m2, m3
pcmpgtb m2, m4
pmovmskb r5d, m2
test r5d, r5d
jz .w8_main ; filter_strength == 0
pshuflw m1, [tlq-2], q0000
movu m2, [tlq+16*0]
imul r5d, 0x55555555
movu m3, [tlq+16*1]
movd m4, [tlq+r3*2]
shr r5d, 30 ; filter_strength
movd [rsp+12], m1
mova [rsp+16*1], m2
pshuflw m4, m4, q0000
mova [rsp+16*2], m3
lea r2d, [r3+2]
movq [rsp+r3*2+18], m4
cmp hd, 16
cmovae r3d, r2d
lea tlq, [rsp+16*1]
call .filter_edge
.w8_main:
lea tlq, [tlq+r3*2]
movd m5, dxd
mova m4, [base+z_base_inc]
shl r3d, 6
movd m6, [tlq] ; top[max_base_x]
movd m1, r3d
pshufb m5, m0
mov r5d, dxd ; xpos
pshufb m1, m0
sub r5, r3
psubw m4, m1 ; max_base_x
pshufb m6, m0
paddw m4, m5
movifnidn strideq, stridemp
.w8_loop:
mov r3, r5
sar r3, 6
movu m0, [tlq+r3*2+0]
movu m1, [tlq+r3*2+2]
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m4, 15 ; xpos < max_base_x
paddw m4, m5 ; xpos += dx
paddw m0, m1
pand m0, m2
pandn m2, m6
por m0, m2
mova [dstq], m0
dec hd
jz .w8_end
add dstq, strideq
add r5, dxq
jl .w8_loop
.w8_end_loop:
mova [dstq], m6
add dstq, strideq
dec hd
jg .w8_end_loop
.w8_end:
RET
.w16:
%if ARCH_X86_32
%define strideq r3
%endif
lea r3d, [hq+15]
movd m1, r3d
and r3d, 15
or r3d, 16 ; imin(h+15, 31)
test angled, 0x400
jnz .w16_main
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
movq m4, [base+z_filt_t_w16+angleq*4]
pcmpeqb m1, [base+z_filt_wh16]
pand m1, m3
pcmpgtb m1, m4
pmovmskb r5d, m1
test r5d, r5d
jz .w16_main ; filter_strength == 0
pshuflw m1, [tlq-2], q0000
movu m2, [tlq+16*0]
imul r5d, 0x24924924
movu m3, [tlq+16*1]
movu m4, [tlq+16*2]
shr r5d, 30
movu m5, [tlq+16*3]
movd m6, [tlq+r3*2]
adc r5d, -1 ; filter_strength
movd [rsp+12], m1
mova [rsp+16*1], m2
mova [rsp+16*2], m3
pshuflw m6, m6, q0000
mova [rsp+16*3], m4
mova [rsp+16*4], m5
lea r2d, [r3+2]
movq [rsp+r3*2+18], m6
cmp hd, 32
cmovae r3d, r2d
lea tlq, [rsp+16*1]
call .filter_edge
.w16_main:
lea tlq, [tlq+r3*2]
movd m5, dxd
mova m4, [base+z_base_inc]
shl r3d, 6
movd m6, [tlq] ; top[max_base_x]
movd m1, r3d
pshufb m5, m0
mov r5d, dxd ; xpos
pshufb m1, m0
sub r5, r3
psubw m4, m1 ; max_base_x
pshufb m6, m0
paddw m4, m5
.w16_loop:
mov r3, r5
sar r3, 6
movu m0, [tlq+r3*2+ 0]
movu m2, [tlq+r3*2+ 2]
pand m3, m7, m4
psllw m3, 9
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+16]
paddw m0, m2
movu m2, [tlq+r3*2+18]
psubw m2, m1
pmulhrsw m2, m3
movddup m3, [base+pw_m512]
paddw m1, m2
psraw m2, m4, 15
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [dstq+16*0], m0
por m1, m3
mova [dstq+16*1], m1
dec hd
jz .w16_end
movifnidn strideq, stridemp
add dstq, strideq
add r5, dxq
jl .w16_loop
.w16_end_loop:
mova [dstq+16*0], m6
mova [dstq+16*1], m6
add dstq, strideq
dec hd
jg .w16_end_loop
.w16_end:
RET
.w32:
lea r3d, [hq+31]
and r3d, 31
or r3d, 32 ; imin(h+31, 63)
test angled, 0x400 ; !enable_intra_edge_filter
jnz .w32_main
call .filter_copy
lea r5d, [r3+2]
cmp hd, 64
cmove r3d, r5d
call .filter_edge_s3
.w32_main:
lea tlq, [tlq+r3*2]
movd m5, dxd
mova m4, [base+z_base_inc]
shl r3d, 6
movd m6, [tlq] ; top[max_base_x]
movd m1, r3d
pshufb m5, m0
mov r5d, dxd ; xpos
pshufb m1, m0
sub r5, r3
psubw m4, m1 ; max_base_x
pshufb m6, m0
paddw m4, m5
.w32_loop:
mov r3, r5
sar r3, 6
movu m0, [tlq+r3*2+ 0]
movu m2, [tlq+r3*2+ 2]
pand m3, m7, m4
psllw m3, 9
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+16]
paddw m0, m2
movu m2, [tlq+r3*2+18]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
psraw m2, m4, 15
pand m0, m2
pandn m2, m6
por m0, m2
movddup m2, [base+pw_m512]
pcmpgtw m2, m4
pand m1, m2
pandn m2, m6
mova [dstq+16*0], m0
por m1, m2
mova [dstq+16*1], m1
movu m0, [tlq+r3*2+32]
movu m2, [tlq+r3*2+34]
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+48]
paddw m0, m2
movu m2, [tlq+r3*2+50]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
movddup m2, [base+pw_m1024]
movddup m3, [base+pw_m1536]
pcmpgtw m2, m4
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [dstq+16*2], m0
por m1, m3
mova [dstq+16*3], m1
dec hd
jz .w32_end
movifnidn strideq, stridemp
add dstq, strideq
add r5, dxq
jl .w32_loop
.w32_end_loop:
REPX {mova [dstq+16*x], m6}, 0, 1, 2, 3
add dstq, strideq
dec hd
jg .w32_end_loop
.w32_end:
RET
.w64:
lea r3d, [hq+63]
test angled, 0x400 ; !enable_intra_edge_filter
jnz .w64_main
call .filter_copy
call .filter_edge_s3
.w64_main:
lea tlq, [tlq+r3*2]
movd m5, dxd
mova m4, [base+z_base_inc]
shl r3d, 6
movd m6, [tlq] ; top[max_base_x]
movd m1, r3d
pshufb m5, m0
mov r5d, dxd ; xpos
pshufb m1, m0
sub r5, r3
psubw m4, m1 ; max_base_x
pshufb m6, m0
paddw m4, m5
.w64_loop:
mov r3, r5
sar r3, 6
movu m0, [tlq+r3*2+ 0]
movu m2, [tlq+r3*2+ 2]
pand m3, m7, m4
psllw m3, 9
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+16]
paddw m0, m2
movu m2, [tlq+r3*2+18]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
psraw m2, m4, 15
pand m0, m2
pandn m2, m6
por m0, m2
movddup m2, [base+pw_m512]
pcmpgtw m2, m4
pand m1, m2
pandn m2, m6
mova [dstq+16*0], m0
por m1, m2
mova [dstq+16*1], m1
movu m0, [tlq+r3*2+32]
movu m2, [tlq+r3*2+34]
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+48]
paddw m0, m2
movu m2, [tlq+r3*2+50]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
movddup m2, [base+pw_m1024]
pcmpgtw m2, m4
pand m0, m2
pandn m2, m6
por m0, m2
movddup m2, [base+pw_m1536]
pcmpgtw m2, m4
pand m1, m2
pandn m2, m6
mova [dstq+16*2], m0
por m1, m2
mova [dstq+16*3], m1
movu m0, [tlq+r3*2+64]
movu m2, [tlq+r3*2+66]
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+80]
paddw m0, m2
movu m2, [tlq+r3*2+82]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
movddup m2, [base+pw_m2048]
pcmpgtw m2, m4
pand m0, m2
pandn m2, m6
por m0, m2
movddup m2, [base+pw_m2560]
pcmpgtw m2, m4
pand m1, m2
pandn m2, m6
mova [dstq+16*4], m0
por m1, m2
mova [dstq+16*5], m1
movu m0, [tlq+r3*2+96]
movu m2, [tlq+r3*2+98]
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r3*2+112]
paddw m0, m2
movu m2, [tlq+r3*2+114]
psubw m2, m1
pmulhrsw m2, m3
paddw m1, m2
movddup m2, [base+pw_m3072]
movddup m3, [base+pw_m3584]
pcmpgtw m2, m4
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [dstq+16*6], m0
por m1, m3
mova [dstq+16*7], m1
dec hd
jz .w64_end
movifnidn strideq, stridemp
add dstq, strideq
add r5, dxq
jl .w64_loop
.w64_end_loop:
REPX {mova [dstq+16*x], m6}, 0, 1, 2, 3, 4, 5, 6, 7
add dstq, strideq
dec hd
jg .w64_end_loop
.w64_end:
RET
ALIGN function_align
.filter_copy:
pshuflw m2, [tlq-2], q0000
pshuflw m3, [tlq+r3*2], q0000
xor r5d, r5d
movd [rsp+gprsize+12], m2
.filter_copy_loop:
movu m1, [tlq+r5*2+16*0]
movu m2, [tlq+r5*2+16*1]
add r5d, 16
mova [rsp+r5*2+gprsize-16*1], m1
mova [rsp+r5*2+gprsize-16*0], m2
cmp r5d, r3d
jle .filter_copy_loop
lea tlq, [rsp+gprsize+16*1]
movq [tlq+r3*2+2], m3
ret
.filter_edge:
cmp r5d, 3
je .filter_edge_s3
movddup m4, [base+z_filt_k+r5*8-8]
movddup m5, [base+z_filt_k+r5*8+8]
xor r5d, r5d
movddup m6, [base+pw_8]
movu m2, [tlq-2]
jmp .filter_edge_start
.filter_edge_loop:
movu m2, [tlq+r5*2-2]
mova [tlq+r5*2-16], m1
.filter_edge_start:
pmullw m1, m4, [tlq+r5*2]
movu m3, [tlq+r5*2+2]
paddw m2, m3
pmullw m2, m5
add r5d, 8
paddw m1, m6
paddw m1, m2
psrlw m1, 4
cmp r5d, r3d
jl .filter_edge_loop
mova [tlq+r5*2-16], m1
ret
.filter_edge_s3:
movddup m5, [base+pw_3]
xor r5d, r5d
movu m2, [tlq-2]
movu m3, [tlq-4]
jmp .filter_edge_s3_start
.filter_edge_s3_loop:
movu m2, [tlq+r5*2-2]
movu m3, [tlq+r5*2-4]
mova [tlq+r5*2-16], m1
.filter_edge_s3_start:
paddw m2, [tlq+r5*2+0]
paddw m3, m5
movu m1, [tlq+r5*2+2]
movu m4, [tlq+r5*2+4]
add r5d, 8
paddw m1, m2
pavgw m3, m4
paddw m1, m3
psrlw m1, 2
cmp r5d, r3d
jl .filter_edge_s3_loop
mova [tlq+r5*2-16], m1
ret
%if ARCH_X86_64
cglobal ipred_z2_16bpc, 4, 12, 11, 16*24, dst, stride, tl, w, h, angle, dx, _, dy
%define base r7-$$
%define maxwm r6m
%define maxhm r7m
%define bdmaxm r8m
lea r7, [$$]
mov hd, hm
movddup m8, [base+pw_62]
lea r9d, [wq-4]
shl r9d, 6
mova m9, [base+z2_top_shufA]
or r9d, hd
mova m10, [base+z2_left_shufA]
%else
cglobal ipred_z2_16bpc, 4, 7, 8, -16*27, dst, _, tl, w, h, angle, dx
%define base r1-$$
%define r9b byte [rsp+16*26+4*0]
%define r9d dword [rsp+16*26+4*0]
%define r10d dword [rsp+16*26+4*1]
%define r11d dword [rsp+16*26+4*2]
%define maxwm [rsp+16*2+4*0]
%define maxhm [rsp+16*2+4*1]
%define bdmaxm [rsp+16*2+4*2]
%define stridemp [rsp+16*26+4*3]
%define strideq r3
%define dyd r4
%define dyq r4
mov stridemp, r1
mov r1d, r6m
mov r4d, r7m
mov r5d, r8m
mov maxwm, r1d
mov maxhm, r4d
mov bdmaxm, r5d
LEA r1, $$
lea hd, [wq-4]
mova m0, [base+z2_top_shufA]
shl hd, 6
mova m1, [base+z2_left_shufA]
or hd, hm
mova [rsp+16*24], m0
mov r9d, hd
mova [rsp+16*25], m1
%endif
tzcnt wd, wd
movifnidn angled, anglem
mova m0, [tlq-16*8]
mova m1, [tlq-16*7]
mova m2, [tlq-16*6]
mova m3, [tlq-16*5]
movsxd wq, [base+ipred_z2_16bpc_ssse3_table+wq*4]
%if ARCH_X86_64
movzx dxd, angleb
%else
movzx dxd, byte anglem
%endif
mova m4, [tlq-16*4]
mova m5, [tlq-16*3]
mova m6, [tlq-16*2]
mova m7, [tlq-16*1]
mova [rsp+16* 5], m0
xor angled, 0x400
mova [rsp+16* 6], m1
mov dyd, dxd
mova [rsp+16* 7], m2
neg dxq
mova [rsp+16* 8], m3
and dyd, ~1
mova [rsp+16* 9], m4
and dxq, ~1
mova [rsp+16*10], m5
lea wq, [base+ipred_z2_16bpc_ssse3_table+wq]
mova [rsp+16*11], m6
pxor m3, m3
mova [rsp+16*12], m7
movzx dyd, word [base+dr_intra_derivative+dyq-90] ; angle - 90
movzx dxd, word [base+dr_intra_derivative+dxq+180] ; 180 - angle
movddup m0, [base+pw_256] ; 4<<6
movd m4, [tlq]
movu m5, [tlq+16*0+2]
movu m6, [tlq+16*1+2]
movsldup m1, [base+z2_dy_offset]
pshufb m4, m0
movq m7, [base+z_base_inc+2]
mov r11d, (112-4)<<6
mova [rsp+16*13], m4
neg dxd
mova [rsp+16*14], m5
or dyd, 4<<16
mova [rsp+16*15], m6
%if ARCH_X86_64
lea r10d, [dxq+(112<<6)] ; xpos
%else
mov [rsp+8*3], dyd
lea r4d, [dxq+(112<<6)]
mov r10d, r4d
movzx hd, r9b
%endif
movq [rsp+8*0], m1
movq [rsp+8*1], m0
movq [rsp+8*2], m7
jmp wq
.w4:
test angled, 0x400
jnz .w4_main
lea r3d, [hq+2]
add angled, 1022
pshuflw m1, m5, q3333
shl r3d, 6
movq [rsp+16*14+8], m1
test r3d, angled
jnz .w4_no_upsample_above ; angle >= 130 || h > 8 || (is_sm && h == 8)
call .upsample_above
sub angled, 1075 ; angle - 53
lea r3d, [hq+3]
xor angled, 0x7f ; 180 - angle
movd m2, r3d
movd m7, angled
shr angled, 8 ; is_sm << 1
pshufb m2, m3
pshufb m7, m3
pcmpeqb m2, [base+z_filt_wh4]
pand m7, m2
pcmpgtb m7, [base+z_filt_t_w48+angleq*8]
jmp .w8_filter_left
.upsample_above: ; w4/w8
paddw m2, m5, [tlq]
movu m1, [rsp+gprsize+16*14+2]
movu m4, [rsp+gprsize+16*14-4]
%if ARCH_X86_64
movd m6, r9m ; bdmax, offset due to call
%else
movd m6, [rsp+gprsize+16*2+4*2]
%endif
paddw m4, m1
psubw m1, m2, m4
pshufb m6, m0
psraw m1, 3
paddw m2, m1
add dxd, dxd
pmaxsw m2, m3
paddw m7, m7
pavgw m2, m3
pminsw m2, m6
%if ARCH_X86_64
mova m9, [base+z2_top_shufB]
lea r10d, [dxq+(113<<6)]
mov r11d, (112-7)<<6
%else
mova m1, [base+z2_top_shufB]
lea r3d, [dxq+(113<<6)]
mov dword [rsp+gprsize+16*26+4*2], (112-7)<<6
mov [rsp+gprsize+16*26+4*1], r3d
mova [rsp+gprsize+16*24], m1
%endif
punpcklwd m1, m2, m5
punpckhwd m2, m5
movq [rsp+gprsize+8*2], m7
mova [rsp+gprsize+16*14], m1
mova [rsp+gprsize+16*15], m2
ret
.w4_no_upsample_above:
lea r3d, [hq+3]
mov [rsp+16*4], angled
sub angled, 1112 ; angle - 90
movd m2, r3d
mov r3d, 90
movd m1, angled
sub r3d, angled ; 180 - angle
shr angled, 8 ; is_sm << 1
mova m4, [base+z_filt_wh4]
movd m7, r3d
mova m5, [base+z_filt_t_w48+angleq*8]
mov r3d, 4
call .w8_filter_top
mov angled, [rsp+16*4]
lea r3d, [hq+2]
sub angled, 139
shl r3d, 6
test r3d, angled
jnz .w8_filter_left ; angle <= 140 || h > 8 || (is_sm && h == 8)
.upsample_left: ; w4/w8
mova m2, [tlq-16]
lea r3d, [hq-4]
movu m3, [tlq-14]
movu m4, [rsp+16*12+4]
pshufb m1, m2, [base+z2_upsample_l+r3*4]
movd m6, bdmaxm
pxor m5, m5
paddw m3, m2
paddw m4, m1
psubw m1, m3, m4
movshdup m4, [base+z2_dy_offset]
psraw m1, 3
pshufb m6, m0
paddw m3, m1
pmaxsw m3, m5
pavgw m3, m5
pminsw m3, m6
%if ARCH_X86_64
mova m10, [base+z2_left_shufB]
add dyd, dyd
%else
mova m1, [base+z2_left_shufB]
shl dword [rsp+8*3], 1
mova [rsp+16*25], m1
%endif
punpckhwd m1, m2, m3
punpcklwd m2, m3
movq [rsp+8*0], m4
mova [rsp+16*12], m1
mova [rsp+16*11], m2
.w4_main:
movd m6, dxd
%if ARCH_X86_64
movd m3, dyd
%else
movd m3, [rsp+8*3]
%endif
pshufb m6, m0
movddup m0, [rsp+8*2]
paddw m7, m6, m6
movq m5, [base+pw_m1to4]
pshuflw m4, m3, q0000
punpcklqdq m6, m7
pmullw m4, m5
pshuflw m3, m3, q1111
paddw m6, m0
mov r2d, r10d
pshuflw m0, m4, q3333
psubw m4, [rsp+8*0]
movq [rsp+8*3], m3
movq [rsp+8*5], m0 ; dy*4
mov r5, dstq
.w4_loop0:
mova [rsp+16*4], m6
movq [rsp+8*4], m4
%if ARCH_X86_64
pand m0, m8, m4
%else
movq m0, [base+pw_62]
pand m0, m4
%endif
psraw m4, 6
psllw m0, 9 ; frac_y << 9
movq [rsp+8*7], m0
pabsw m4, m4
movq [rsp+8*6], m4
movzx hd, r9b
.w4_loop:
lea r3d, [r2+dxq]
shr r2d, 6 ; base_x0
movu m2, [rsp+r2*2]
lea r2d, [r3+dxq]
shr r3d, 6 ; base_x1
movu m1, [rsp+r3*2]
lea r3d, [r2+dxq]
shr r2d, 6 ; base_x2
movu m3, [rsp+r2*2]
lea r2d, [r3+dxq]
shr r3d, 6 ; base_x3
movu m4, [rsp+r3*2]
%if ARCH_X86_64
REPX {pshufb x, m9}, m2, m1, m3, m4
%else
mova m0, [rsp+16*24]
REPX {pshufb x, m0}, m2, m1, m3, m4
%endif
punpcklqdq m0, m2, m1
punpckhqdq m2, m1
punpcklqdq m1, m3, m4
punpckhqdq m3, m4
%if ARCH_X86_64
pand m5, m8, m6
%else
movddup m5, [base+pw_62]
pand m5, m6
%endif
psllw m5, 9
psubw m2, m0
pmulhrsw m2, m5
paddw m5, m6, m7
psubw m3, m1
paddw m0, m2
%if ARCH_X86_64
pand m2, m8, m5
%else
movddup m2, [base+pw_62]
pand m2, m5
%endif
psllw m2, 9
pmulhrsw m3, m2
paddw m1, m3
cmp r3d, 111 ; topleft
jge .w4_toponly
mova [rsp+16*22], m0
mova [rsp+16*23], m1
movzx r3d, byte [rsp+8*6+0] ; base_y0
movu m3, [rsp+r3*2]
movzx r3d, byte [rsp+8*6+2] ; base_y1
movu m2, [rsp+r3*2]
movzx r3d, byte [rsp+8*6+4] ; base_y2
movu m4, [rsp+r3*2]
movzx r3d, byte [rsp+8*6+6] ; base_y3
movu m0, [rsp+r3*2]
%if ARCH_X86_64
REPX {pshufb x, m10}, m3, m2, m4, m0
%else
mova m1, [rsp+16*25]
REPX {pshufb x, m1}, m3, m2, m4, m0
%endif
punpcklwd m1, m3, m2
punpckhwd m3, m2 ; 01
punpcklwd m2, m4, m0
punpckhwd m4, m0 ; 23
punpckldq m0, m1, m2 ; y0 d1
punpckhdq m1, m2 ; y2 y3
punpckldq m2, m3, m4
punpckhdq m3, m4
movddup m4, [rsp+8*7]
psubw m2, m0
psubw m3, m1
pmulhrsw m2, m4
pmulhrsw m3, m4
psraw m6, 15 ; base_x < topleft
psraw m4, m5, 15
paddw m0, m2
paddw m1, m3
pand m0, m6
pandn m6, [rsp+16*22]
pand m1, m4
pandn m4, [rsp+16*23]
por m0, m6
por m1, m4
.w4_toponly:
movifnidn strideq, stridemp
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
movq [dstq+strideq*0], m1
movhps [dstq+strideq*1], m1
sub hd, 4
jz .w4_end
movq m4, [rsp+8*6]
paddsw m6, m5, m7 ; xpos += dx
movq m5, [rsp+8*3]
psubw m4, m5
lea dstq, [dstq+strideq*2]
movq [rsp+8*6], m4
cmp r2d, r11d
jge .w4_loop
.w4_leftonly_loop:
movzx r2d, byte [rsp+8*6+0] ; base_y0
movu m3, [rsp+r2*2]
movzx r2d, byte [rsp+8*6+2] ; base_y1
movu m2, [rsp+r2*2]
movzx r2d, byte [rsp+8*6+4] ; base_y2
movu m6, [rsp+r2*2]
movzx r2d, byte [rsp+8*6+6] ; base_y3
movu m0, [rsp+r2*2]
psubw m4, m5
%if ARCH_X86_64
REPX {pshufb x, m10}, m3, m2, m6, m0
%else
mova m1, [rsp+16*25]
REPX {pshufb x, m1}, m3, m2, m6, m0
%endif
movq [rsp+8*6], m4
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m6, m0
punpckhwd m6, m0
punpckldq m0, m1, m2
punpckhdq m1, m2
punpckldq m2, m3, m6
punpckhdq m3, m6
movddup m6, [rsp+8*7]
psubw m2, m0
psubw m3, m1
pmulhrsw m2, m6
pmulhrsw m3, m6
paddw m0, m2
paddw m1, m3
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
movq [dstq+strideq*0], m1
movhps [dstq+strideq*1], m1
lea dstq, [dstq+strideq*2]
sub hd, 4
jg .w4_leftonly_loop
.w4_end:
sub r9d, 1<<8
jl .w4_ret
movq m4, [rsp+8*5]
add r5, 8
mov dstq, r5
paddw m4, [rsp+8*4] ; base_y += 4*dy
movzx r2d, word [rsp+8*1]
movddup m6, [rsp+8*1]
paddw m6, [rsp+16*4] ; base_x += (4 << upsample_above)
add r2d, r10d
mov r10d, r2d
jmp .w4_loop0
.w4_ret:
RET
.w8:
test angled, 0x400
jnz .w4_main
lea r3d, [angleq+126]
pshufhw m1, m5, q3333
%if ARCH_X86_64
mov r3b, hb
%else
xor r3b, r3b
or r3d, hd
%endif
movhps [rsp+16*15], m1
cmp r3d, 8
ja .w8_no_upsample_above ; angle >= 130 || h > 8 || is_sm
call .upsample_above
sub angled, 53
lea r3d, [hq+7]
xor angled, 0x7f ; 180 - angle
movu m1, [base+z_filt_wh8]
movd m2, r3d
movd m7, angled
shr angled, 8 ; is_sm << 1
psrldq m4, [base+z_filt_t_w48+angleq*8], 4
pshufb m2, m3
pshufb m7, m3
pcmpeqb m2, m1
movq m1, [base+pw_512]
pand m7, m2
pcmpgtb m7, m4
movq [rsp+8*1], m1 ; 8<<6
jmp .w8_filter_left
.w8_no_upsample_above:
lea r3d, [hq+7]
mov [rsp+16*4], angled
sub angled, 90
movd m2, r3d
mov r3d, 90
movd m1, angled
sub r3d, angled ; 180 - angle
shr angled, 8 ; is_sm << 1
movu m4, [base+z_filt_wh8]
movd m7, r3d
psrldq m5, [base+z_filt_t_w48+angleq*8], 4
mov r3d, 8
call .w8_filter_top
mov r3d, [rsp+16*4]
sub r3d, 141
%if ARCH_X86_64
mov r3b, hb
%else
xor r3b, r3b
or r3d, hd
%endif
cmp r3d, 8
jbe .upsample_left ; angle > 140 && h <= 8 && !is_sm
.w8_filter_left:
pmovmskb r5d, m7
test r5d, r5d
jz .w4_main
imul r5d, 0x55555555
neg hq
mov r3, tlq
movd m1, [tlq+hq*2]
shr r5d, 30 ; filter_strength
lea tlq, [rsp+16*13-2]
pshuflw m1, m1, q0000
movq [tlq+hq*2-6], m1
call mangle(private_prefix %+ _ipred_z3_16bpc_ssse3).filter_edge
jmp .filter_left_end
.w8_filter_top:
REPX {pshufb x, m3}, m2, m1, m7
pcmpeqb m2, m4
pand m1, m2
pand m7, m2
pcmpgtb m1, m5
pcmpgtb m7, m5
pmovmskb r5d, m1
test r5d, r5d
jz .w8_filter_top_end ; filter_strength == 0
imul r5d, 0x55555555
mov [dstq], tlq
lea tlq, [rsp+16*14+gprsize]
shr r5d, 30 ; filter_strength
call mangle(private_prefix %+ _ipred_z1_16bpc_ssse3).filter_edge
%if ARCH_X86_64
mov r3d, r7m ; maxw, offset due to call
%else
mov r3d, [rsp+16*2+4*1]
%endif
mov tlq, [dstq]
cmp r3d, 8
jge .w8_filter_top_end
movu m1, [tlq+r3*2+16*0+2]
movu m2, [tlq+r3*2+16*1+2]
movu [rsp+r3*2+16*14+gprsize], m1
movu [rsp+r3*2+16*15+gprsize], m2
.w8_filter_top_end:
ret
.w16:
test angled, 0x400
jnz .w4_main
lea r3d, [hq+15]
sub angled, 90
movd m2, r3d
mov r3d, 90
movd m1, angled
sub r3d, angled ; 180 - angle
shr angled, 8 ; is_sm << 1
movd m7, r3d
REPX {pshufb x, m3}, m2, m1, m7
movq m4, [base+z_filt_t_w16+angleq*4]
pcmpeqb m2, [base+z_filt_wh16]
pand m1, m2
pand m7, m2
pcmpgtb m1, m4
pcmpgtb m7, m4
pmovmskb r5d, m1
test r5d, r5d
jz .w16_filter_left ; filter_strength == 0
imul r5d, 0x24924924
pshufhw m6, m6, q3333
mov [dstq], tlq
lea tlq, [rsp+16*14]
shr r5d, 30
movhps [tlq+16*2], m6
adc r5d, -1 ; filter_strength
mov r3d, 16
call mangle(private_prefix %+ _ipred_z1_16bpc_ssse3).filter_edge
mov r3d, maxwm
mov tlq, [dstq]
cmp r3d, 16
jge .w16_filter_left
movu m1, [tlq+r3*2+16*0+2]
movu m2, [tlq+r3*2+16*1+2]
movu [rsp+r3*2+16*14], m1
movu [rsp+r3*2+16*15], m2
.w16_filter_left:
pmovmskb r5d, m7
test r5d, r5d
jz .w4_main
imul r5d, 0x24924924
neg hq
mov r3, tlq
movd m1, [tlq+hq*2]
shr r5d, 30
lea tlq, [rsp+16*13-2]
pshuflw m1, m1, q0000
adc r5d, -1 ; filter_strength
movq [tlq+hq*2-6], m1
call mangle(private_prefix %+ _ipred_z3_16bpc_ssse3).filter_edge
jmp .filter_left_end
.w32:
movu m1, [tlq+16*2+2]
movu m2, [tlq+16*3+2]
mova [rsp+16*16], m1
mova [rsp+16*17], m2
test angled, 0x400
jnz .w4_main
mov [dstq], tlq
lea tlq, [rsp+16*14]
pshufhw m2, m2, q3333
mov r3d, 32
movhps [tlq+16*4], m2
call mangle(private_prefix %+ _ipred_z1_16bpc_ssse3).filter_edge_s3
mov r3d, maxwm
mov tlq, [dstq]
cmp r3d, 32
jge .filter_left
movu m1, [tlq+r3*2+16*0+2]
movu m2, [tlq+r3*2+16*1+2]
movu [rsp+r3*2+16*14], m1
movu [rsp+r3*2+16*15], m2
cmp r3d, 16
jge .filter_left
movu m1, [tlq+r3*2+16*2+2]
movu m2, [tlq+r3*2+16*3+2]
movu [rsp+r3*2+16*16], m1
movu [rsp+r3*2+16*17], m2
.filter_left:
neg hq
mov r3, tlq
pshuflw m1, [tlq+hq*2], q0000
lea tlq, [rsp+16*13-2]
movq [tlq+hq*2-6], m1
call mangle(private_prefix %+ _ipred_z3_16bpc_ssse3).filter_edge_s3
.filter_left_end:
mov r2d, maxhm
cmp r2d, hd
jge .w4_main
neg r2
movu m1, [r3+r2*2-16*1]
movu m2, [r3+r2*2-16*2]
movu [rsp+r2*2+16*12], m1
movu [rsp+r2*2+16*11], m2
cmp r2d, -48
jle .w4_main
movu m1, [r3+r2*2-16*3]
movu m2, [r3+r2*2-16*4]
movu [rsp+r2*2+16*10], m1
movu [rsp+r2*2+16* 9], m2
cmp r2d, -32
jle .w4_main
movu m1, [r3+r2*2-16*5]
movu m2, [r3+r2*2-16*6]
movu [rsp+r2*2+16* 8], m1
movu [rsp+r2*2+16* 7], m2
cmp r2d, -16
jle .w4_main
movu m1, [r3+r2*2-16*7]
movu m2, [r3+r2*2-16*8]
movu [rsp+r2*2+16* 6], m1
movu [rsp+r2*2+16* 5], m2
jmp .w4_main
.w64:
movu m1, [tlq+16*2+2]
movu m2, [tlq+16*3+2]
movu m3, [tlq+16*4+2]
movu m4, [tlq+16*5+2]
movu m5, [tlq+16*6+2]
movu m6, [tlq+16*7+2]
mov [dstq], tlq
lea tlq, [rsp+16*14]
mova [tlq+16*2], m1
mova [tlq+16*3], m2
mova [tlq+16*4], m3
mova [tlq+16*5], m4
mova [tlq+16*6], m5
mova [tlq+16*7], m6
test angled, 0x400
jnz .w4_main
pshufhw m6, m6, q3333
mov r3d, 64
movhps [tlq+16*8], m6
call mangle(private_prefix %+ _ipred_z1_16bpc_ssse3).filter_edge_s3
mov r3d, maxwm
mov tlq, [dstq]
cmp r3d, 64
jge .filter_left
movu m1, [tlq+r3*2+16*0+2]
movu m2, [tlq+r3*2+16*1+2]
movu [rsp+r3*2+16*14], m1
movu [rsp+r3*2+16*15], m2
cmp r3d, 48
jge .filter_left
movu m1, [tlq+r3*2+16*2+2]
movu m2, [tlq+r3*2+16*3+2]
movu [rsp+r3*2+16*16], m1
movu [rsp+r3*2+16*17], m2
cmp r3d, 32
jge .filter_left
movu m1, [tlq+r3*2+16*4+2]
movu m2, [tlq+r3*2+16*5+2]
movu [rsp+r3*2+16*18], m1
movu [rsp+r3*2+16*19], m2
cmp r3d, 16
jge .filter_left
movu m1, [tlq+r3*2+16*6+2]
movu m2, [tlq+r3*2+16*7+2]
movu [rsp+r3*2+16*20], m1
movu [rsp+r3*2+16*21], m2
jmp .filter_left
%if ARCH_X86_64
cglobal ipred_z3_16bpc, 4, 9, 8, 16*18, dst, stride, tl, w, h, angle, dy, _, org_w
%define base r7-$$
lea r7, [$$]
mov org_wd, wd
%else
cglobal ipred_z3_16bpc, 4, 7, 8, -16*18, dst, stride, tl, w, h, angle, dy
%define base r1-$$
%define org_wd r5
%define org_wq r5
movd m6, r8m ; pixel_max
mov [dstq+4*0], strideq
LEA r1, $$
mov [dstq+4*1], wd
%endif
tzcnt hd, hm
movifnidn angled, anglem
sub tlq, 2
movsxd hq, [base+ipred_z3_16bpc_ssse3_table+hq*4]
sub angled, 180
movddup m0, [base+pw_256]
mov dyd, angled
neg dyd
xor angled, 0x400
movddup m7, [base+pw_62]
or dyq, ~0x7e
lea hq, [base+ipred_z3_16bpc_ssse3_table+hq]
movzx dyd, word [base+dr_intra_derivative+45*2-1+dyq]
jmp hq
.h4:
lea r4d, [angleq+88]
test r4d, 0x480
jnz .h4_no_upsample ; !enable_intra_edge_filter || angle >= 40
sar r4d, 9
add r4d, wd
cmp r4d, 8
jg .h4_no_upsample ; w > 8 || (w == 8 && is_sm)
mova m2, [tlq-14] ; 7 6 5 4 3 2 1 0
movu m3, [tlq-12] ; 8 7 6 5 4 3 2 1
%if ARCH_X86_64
movd m6, r8m
%endif
pshufb m4, m2, m0
mov tlq, rsp
palignr m1, m2, m4, 14 ; 8 8 7 6 5 4 3 2
add dyd, dyd
palignr m5, m2, m4, 12 ; 8 8 8 7 6 5 4 3
paddw m1, m2
paddw m3, m5
psubw m5, m1, m3
mova m3, [base+z_upsample]
mova [tlq+ 0], m4
movd m4, dyd
psraw m5, 3
neg dyd
paddw m1, m5
pxor m5, m5
lea r5d, [dyq+(16<<6)+63] ; ypos
pmaxsw m1, m5
pshufb m6, m0
shl wd, 3
pavgw m1, m5
pshufb m4, m0
pminsw m1, m6
sub rsp, wq
punpckhwd m0, m1, m2
paddw m5, m4, m4
punpcklwd m1, m2
mova [tlq+32], m0
movsd m4, m5
mova [tlq+16], m1
.h4_upsample_loop:
lea r4d, [r5+dyq]
sar r5d, 6
movu m2, [tlq+r5*2]
lea r5d, [r4+dyq]
sar r4d, 6
movu m1, [tlq+r4*2]
pshufb m2, m3
pshufb m1, m3
punpckhqdq m0, m1, m2
punpcklqdq m1, m2
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m4, m5
paddw m0, m1
mova [rsp+wq-16], m0
sub wd, 16
jg .h4_upsample_loop
or r3d, 4*2
jmp .end_transpose
.h4_no_upsample:
mov r4d, 7
test angled, 0x400 ; !enable_intra_edge_filter
jnz .h4_main
lea r4d, [wq+3]
movd m1, r4d
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
pcmpeqb m1, [base+z_filt_wh4]
pand m1, m3
pcmpgtb m1, [base+z_filt_t_w48+angleq*8]
pmovmskb r5d, m1
mov r4d, 7
test r5d, r5d
jz .h4_main ; filter_strength == 0
pshuflw m1, [tlq+2], q0000
imul r5d, 0x55555555
mova m2, [tlq-14]
neg r4
movd m3, [tlq+r4*2]
shr r5d, 30
movd [rsp+16*17], m1
pshuflw m3, m3, q0000
mova [rsp+16*16], m2
lea r2, [r4-2]
movq [rsp+16*17+r4*2-10], m3
cmp wd, 8
cmovae r4, r2
lea tlq, [rsp+16*17-2]
call .filter_edge
.h4_main:
movd m4, dyd
sub tlq, r4
movddup m1, [base+z_base_inc_z2+8] ; base_inc << 6
sub tlq, r4
shl r4d, 6
movd m6, [tlq]
movd m3, r4d
pshufb m4, m0
neg dyq
pshufb m6, m0
lea r5, [dyq+r4+63] ; ypos
pshufb m3, m0
shl wd, 3
paddw m5, m4, m4
sub rsp, wq
psubw m3, m1 ; max_base_y
movsd m4, m5 ; ypos1 ypos0
.h4_loop:
lea r4, [r5+dyq]
sar r5, 6
movddup m0, [tlq+r5*2-6]
movddup m1, [tlq+r5*2-8]
lea r5, [r4+dyq]
sar r4, 6
movlps m0, [tlq+r4*2-6]
movlps m1, [tlq+r4*2-8]
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
pcmpgtw m2, m3, m4
paddw m4, m5
paddw m0, m1
pand m0, m2
pandn m2, m6
por m0, m2
mova [rsp+wq-16], m0
sub wd, 16
jz .h4_transpose
test r5d, r5d
jg .h4_loop
.h4_end_loop:
mova [rsp+wq-16], m6
sub wd, 16
jg .h4_end_loop
.h4_transpose:
or r3d, 4*2
jmp .end_transpose
.h8:
lea r4d, [angleq+88]
and r4d, ~0x7f
or r4d, wd
cmp r4d, 8
ja .h8_no_upsample ; !enable_intra_edge_filter || is_sm || d >= 40 || w > 8
mova m2, [tlq-30] ; g f e d c b a 9
movu m1, [tlq-32] ; _ g f e d c b a
movu m3, [tlq-16] ; 9 8 7 6 5 4 3 2
paddw m3, [tlq-14] ; 8 7 6 5 4 3 2 1
pshufd m4, m2, q2100 ; _ _ g f e d c b
paddw m1, m2
movu m5, [tlq-28] ; f e d c b a 9 8
add dyd, dyd
cmp wd, 8
je .h8_upsample_w8
pshufhw m4, m2, q1000 ; _ _ _ _ c c c b
.h8_upsample_w8:
paddw m4, m5
psubw m5, m1, m4
movu m4, [tlq-18] ; a 9 8 7 6 5 4 3
psraw m5, 3
paddw m1, m5
movu m5, [tlq-12] ; 7 6 5 4 3 2 1 0
%if ARCH_X86_64
movd m6, r8m ; pixel_max
%endif
paddw m4, m5
shl wd, 4
psubw m5, m3, m4
movd m4, dyd
psraw m5, 3
neg dyd
paddw m3, m5
pshufb m6, m0
mova m5, [tlq-14]
pshufb m4, m0
pxor m0, m0
pmaxsw m1, m0
pmaxsw m3, m0
mov tlq, rsp
pavgw m1, m0
pavgw m3, m0
sub rsp, wq
pminsw m1, m6
pminsw m6, m3
mova m3, [base+z_upsample]
lea r5d, [dyq+(16<<6)+63] ; ypos
punpcklwd m0, m1, m2
mova [tlq+16*0], m0
punpckhwd m1, m2
mova [tlq+16*1], m1
punpcklwd m0, m6, m5
mova [tlq+16*2], m0
punpckhwd m6, m5
mova [tlq+16*3], m6
mova m5, m4
.h8_upsample_loop:
mov r4d, r5d
sar r4d, 6
movu m1, [tlq+r4*2+16*0]
movu m2, [tlq+r4*2+16*1]
add r5d, dyd
pshufb m2, m3
pshufb m1, m3
punpckhqdq m0, m1, m2
punpcklqdq m1, m2
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m4, m5
paddw m0, m1
mova [rsp+wq-16], m0
sub wd, 16
jg .h8_upsample_loop
or r3d, 8*2
jmp .end_transpose
.h8_no_upsample:
lea r4d, [wq+7]
movd m1, r4d
and r4d, 7
or r4d, 8 ; imin(w+7, 15)
test angled, 0x400
jnz .h8_main
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
movu m2, [base+z_filt_wh8]
psrldq m4, [base+z_filt_t_w48+angleq*8], 4
pcmpeqb m2, m1
pand m2, m3
pcmpgtb m2, m4
pmovmskb r5d, m2
test r5d, r5d
jz .h8_main ; filter_strength == 0
pshuflw m1, [tlq+2], q0000
imul r5d, 0x55555555
mova m2, [tlq-16*1+2]
neg r4
mova m3, [tlq-16*2+2]
shr r5d, 30
movd m4, [tlq+r4*2]
movd [rsp+16*17], m1
mova [rsp+16*16], m2
pshuflw m4, m4, q0000
mova [rsp+16*15], m3
lea r2, [r4-2]
movq [rsp+16*17+r4*2-10], m4
cmp wd, 16
cmovae r4, r2
lea tlq, [rsp+16*17-2]
call .filter_edge
.h8_main:
sub tlq, r4
movd m4, dyd
sub tlq, r4
shl r4d, 6
movd m6, [tlq]
movd m3, r4d
pshufb m4, m0
neg dyq
pshufb m6, m0
lea r5, [dyq+r4+63]
pshufb m3, m0
shl wd, 4
mova m5, m4
sub rsp, wq
psubw m3, [base+z_base_inc_z2]
.h8_loop:
mov r4, r5
sar r4, 6
movu m0, [tlq+r4*2-14]
movu m1, [tlq+r4*2-16]
pand m2, m7, m4
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
pcmpgtw m2, m3, m4
paddw m4, m5
paddw m0, m1
pand m0, m2
pandn m2, m6
por m0, m2
mova [rsp+wq-16], m0
sub wd, 8*2
jz .h8_transpose
add r5, dyq
jg .h8_loop
.h8_end_loop:
mova [rsp+wq-16], m6
sub wd, 8*2
jg .h8_end_loop
.h8_transpose:
or r3d, 8*2
jmp .end_transpose
.h16:
lea r4d, [wq+15]
movd m1, r4d
and r4d, 15
or r4d, 16 ; imin(w+15, 31)
test angled, 0x400
jnz .h16_main
movd m3, angled
shr angled, 8 ; is_sm << 1
pxor m2, m2
pshufb m1, m2
pshufb m3, m2
movq m4, [base+z_filt_t_w16+angleq*4]
pcmpeqb m1, [base+z_filt_wh16]
pand m1, m3
pcmpgtb m1, m4
pmovmskb r5d, m1
test r5d, r5d
jz .h16_main ; filter_strength == 0
pshuflw m1, [tlq+2], q0000
mova m2, [tlq-16*1+2]
imul r5d, 0x24924924
mova m3, [tlq-16*2+2]
neg r4
mova m4, [tlq-16*3+2]
shr r5d, 30
mova m5, [tlq-16*4+2]
movd m6, [tlq+r4*2]
adc r5d, -1 ; filter_strength
movd [rsp+16*17], m1
mova [rsp+16*16], m2
mova [rsp+16*15], m3
pshuflw m6, m6, q0000
mova [rsp+16*14], m4
mova [rsp+16*13], m5
lea r2, [r4-2]
movq [rsp+16*17+r4*2-10], m6
cmp wd, 32
cmovae r4, r2
lea tlq, [rsp+16*17-2]
call .filter_edge
.h16_main:
sub tlq, r4
movd m5, dyd
sub tlq, r4
shl r4d, 6
movd m6, [tlq]
movd m3, r4d
pshufb m5, m0
neg dyq
pshufb m6, m0
lea r5, [dyq+r4+63]
pshufb m3, m0
shl wd, 5
paddw m4, m5, [base+z_base_inc_z2]
sub rsp, wq
psubw m4, m3
.h16_loop:
mov r4, r5
sar r4, 6
movu m0, [tlq+r4*2-14]
movu m2, [tlq+r4*2-16]
pand m3, m7, m4
psllw m3, 9
psubw m2, m0
pmulhrsw m2, m3
movu m1, [tlq+r4*2-30]
paddw m0, m2
movu m2, [tlq+r4*2-32]
psubw m2, m1
pmulhrsw m2, m3
movddup m3, [base+pw_m512]
paddw m1, m2
psraw m2, m4, 15
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [rsp+wq-16*1], m0
por m1, m3
mova [rsp+wq-16*2], m1
sub wd, 16*2
jz .h16_transpose
add r5, dyq
jg .h16_loop
.h16_end_loop:
mova [rsp+wq-16*1], m6
mova [rsp+wq-16*2], m6
sub wd, 16*2
jg .h16_end_loop
.h16_transpose:
or r3d, 16*2
jmp .end_transpose
.h32:
lea r4d, [wq+31]
and r4d, 31
or r4d, 32 ; imin(w+31, 63)
test angled, 0x400 ; !enable_intra_edge_filter
jnz .h32_main
call .filter_copy
lea r5, [r4-2]
cmp wd, 64
cmove r4, r5
call .filter_edge_s3
.h32_main:
sub tlq, r4
movd m5, dyd
sub tlq, r4
shl r4d, 6
movd m6, [tlq]
movd m3, r4d
pshufb m5, m0
neg dyq
pshufb m6, m0
lea r5, [dyq+r4+63]
pshufb m3, m0
paddw m4, m5, [base+z_base_inc_z2]
psubw m4, m3
.h32_loop:
mov r4, r5
sar r4, 6
movu m0, [tlq+r4*2-14]
movu m3, [tlq+r4*2-16]
pand m2, m7, m4
psllw m2, 9
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2-30]
paddw m0, m3
movu m3, [tlq+r4*2-32]
psubw m3, m1
pmulhrsw m3, m2
sub rsp, 16*4
paddw m1, m3
psraw m3, m4, 15
pand m0, m3
pandn m3, m6
por m0, m3
movddup m3, [base+pw_m512]
pcmpgtw m3, m4
pand m1, m3
pandn m3, m6
mova [rsp+16*3], m0
por m1, m3
mova [rsp+16*2], m1
movu m0, [tlq+r4*2-46]
movu m3, [tlq+r4*2-48]
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2-62]
paddw m0, m3
movu m3, [tlq+r4*2-64]
psubw m3, m1
pmulhrsw m3, m2
movddup m2, [base+pw_m1024]
paddw m1, m3
movddup m3, [base+pw_m1536]
pcmpgtw m2, m4
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [rsp+16*1], m0
por m1, m3
mova [rsp+16*0], m1
dec wd
jz .h32_transpose
add r5, dyq
jg .h32_loop
.h32_end_loop:
sub rsp, 16*4
REPX {mova [rsp+16*x], m6}, 3, 2, 1, 0
dec wd
jg .h32_end_loop
.h32_transpose:
or r3d, 32*2
jmp .end_transpose
.h64:
lea r4d, [wq+63]
test angled, 0x400 ; !enable_intra_edge_filter
jnz .h64_main
call .filter_copy
call .filter_edge_s3
.h64_main:
sub tlq, r4
movd m5, dyd
sub tlq, r4
shl r4d, 6
movd m6, [tlq]
movd m3, r4d
pshufb m5, m0
neg dyq
pshufb m6, m0
lea r5, [dyq+r4+63]
pshufb m3, m0
paddw m4, m5, [base+z_base_inc_z2]
psubw m4, m3
.h64_loop:
mov r4, r5
sar r4, 6
movu m0, [tlq+r4*2- 14]
movu m3, [tlq+r4*2- 16]
pand m2, m7, m4
psllw m2, 9
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2- 30]
paddw m0, m3
movu m3, [tlq+r4*2- 32]
psubw m3, m1
pmulhrsw m3, m2
sub rsp, 16*8
paddw m1, m3
psraw m3, m4, 15
pand m0, m3
pandn m3, m6
por m0, m3
movddup m3, [base+pw_m512]
pcmpgtw m3, m4
pand m1, m3
pandn m3, m6
mova [rsp+16*7], m0
por m1, m3
mova [rsp+16*6], m1
movu m0, [tlq+r4*2- 46]
movu m3, [tlq+r4*2- 48]
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2- 62]
paddw m0, m3
movu m3, [tlq+r4*2- 64]
psubw m3, m1
pmulhrsw m3, m2
paddw m1, m3
movddup m3, [base+pw_m1024]
pcmpgtw m3, m4
pand m0, m3
pandn m3, m6
por m0, m3
movddup m3, [base+pw_m1536]
pcmpgtw m3, m4
pand m1, m3
pandn m3, m6
mova [rsp+16*5], m0
por m1, m3
mova [rsp+16*4], m1
movu m0, [tlq+r4*2- 78]
movu m3, [tlq+r4*2- 80]
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2- 94]
paddw m0, m3
movu m3, [tlq+r4*2- 96]
psubw m3, m1
pmulhrsw m3, m2
paddw m1, m3
movddup m3, [base+pw_m2048]
pcmpgtw m3, m4
pand m0, m3
pandn m3, m6
por m0, m3
movddup m3, [base+pw_m2560]
pcmpgtw m3, m4
pand m1, m3
pandn m3, m6
mova [rsp+16*3], m0
por m1, m3
mova [rsp+16*2], m1
movu m0, [tlq+r4*2-110]
movu m3, [tlq+r4*2-112]
psubw m3, m0
pmulhrsw m3, m2
movu m1, [tlq+r4*2-126]
paddw m0, m3
movu m3, [tlq+r4*2-128]
psubw m3, m1
pmulhrsw m3, m2
movddup m2, [base+pw_m3072]
paddw m1, m3
movddup m3, [base+pw_m3584]
pcmpgtw m2, m4
pcmpgtw m3, m4
paddw m4, m5
pand m0, m2
pandn m2, m6
pand m1, m3
pandn m3, m6
por m0, m2
mova [rsp+16*1], m0
por m1, m3
mova [rsp+16*0], m1
dec wd
jz .h64_transpose
add r5, dyq
jg .h64_loop
.h64_end_loop:
sub rsp, 16*8
REPX {mova [rsp+16*x], m6}, 7, 6, 5, 4, 3, 2, 1, 0
dec wd
jg .h64_end_loop
.h64_transpose:
add r3d, 64*2
.end_transpose:
%if ARCH_X86_64
lea r7, [strideq*3]
%else
mov strideq, [dstq+4*0]
mov org_wd, [dstq+4*1]
%endif
lea r4d, [r3*3]
.end_transpose_loop:
lea r2, [rsp+r3-8]
lea r6, [dstq+org_wq*2-8]
.end_transpose_loop_y:
movq m0, [r2+r4 ]
movq m1, [r2+r3*2]
movq m2, [r2+r3*1]
movq m3, [r2+r3*0]
sub r2, 8
punpcklwd m0, m1
punpcklwd m2, m3
punpckhdq m1, m0, m2
punpckldq m0, m2
movhps [r6+strideq*0], m1
movq [r6+strideq*1], m1
%if ARCH_X86_64
movhps [r6+strideq*2], m0
movq [r6+r7 ], m0
lea r6, [r6+strideq*4]
%else
lea r6, [r6+strideq*2]
movhps [r6+strideq*0], m0
movq [r6+strideq*1], m0
lea r6, [r6+strideq*2]
%endif
cmp r2, rsp
jae .end_transpose_loop_y
lea rsp, [rsp+r3*4]
sub org_wd, 4
jg .end_transpose_loop
RET
.filter_copy:
neg r4
pshuflw m2, [tlq+2], q0000
xor r5d, r5d
pshuflw m3, [tlq+r4*2], q0000
movq [rsp+gprsize+16*17], m2
.filter_copy_loop:
mova m1, [tlq+r5*2-16*1+2]
mova m2, [tlq+r5*2-16*2+2]
sub r5, 16
mova [rsp+r5*2+gprsize+16*18], m1
mova [rsp+r5*2+gprsize+16*17], m2
cmp r5d, r4d
jg .filter_copy_loop
lea tlq, [rsp+gprsize+16*17-2]
movq [tlq+r4*2-8], m3
ret
.filter_edge:
cmp r5d, 3
je .filter_edge_s3
movddup m4, [base+z_filt_k+r5*8-8]
movddup m5, [base+z_filt_k+r5*8+8]
xor r5d, r5d
movddup m6, [base+pw_8]
movu m2, [tlq-12]
jmp .filter_edge_start
.filter_edge_loop:
movu m2, [tlq+r5*2-12]
mova [tlq+r5*2+2], m1
.filter_edge_start:
pmullw m1, m4, [tlq+r5*2-14]
movu m3, [tlq+r5*2-16]
sub r5, 8
paddw m2, m3
pmullw m2, m5
paddw m1, m6
paddw m1, m2
psrlw m1, 4
cmp r5d, r4d
jg .filter_edge_loop
mova [tlq+r5*2+2], m1
neg r4d
ret
.filter_edge_s3:
movddup m5, [base+pw_3]
xor r5d, r5d
movu m2, [tlq-12]
movu m3, [tlq-10]
jmp .filter_edge_s3_start
.filter_edge_s3_loop:
movu m2, [tlq+r5*2-12]
movu m3, [tlq+r5*2-10]
mova [tlq+r5*2+2], m1
.filter_edge_s3_start:
paddw m2, [tlq+r5*2-14]
paddw m3, m5
movu m1, [tlq+r5*2-16]
movu m4, [tlq+r5*2-18]
sub r5, 8
paddw m1, m2
pavgw m3, m4
paddw m1, m3
psrlw m1, 2
cmp r5d, r4d
jg .filter_edge_s3_loop
mova [tlq+r5*2+2], m1
neg r4d
ret
%if ARCH_X86_64
cglobal ipred_filter_16bpc, 4, 7, 16, dst, stride, tl, w, h, filter
%else
cglobal ipred_filter_16bpc, 4, 7, 8, -16*8, dst, stride, tl, w, h, filter
%define m8 [esp+16*0]
%define m9 [esp+16*1]
%define m10 [esp+16*2]
%define m11 [esp+16*3]
%define m12 [esp+16*4]
%define m13 [esp+16*5]
%define m14 [esp+16*6]
%define m15 [esp+16*7]
%endif
%define base r6-$$
movifnidn hd, hm
movd m6, r8m ; bitdepth_max
%ifidn filterd, filterm
movzx filterd, filterb
%else
movzx filterd, byte filterm
%endif
LEA r6, $$
shl filterd, 6
movu m0, [tlq-6] ; __ l1 l0 tl t0 t1 t2 t3
mova m1, [base+filter_intra_taps+filterq+16*0]
mova m2, [base+filter_intra_taps+filterq+16*1]
mova m3, [base+filter_intra_taps+filterq+16*2]
mova m4, [base+filter_intra_taps+filterq+16*3]
pxor m5, m5
%if ARCH_X86_64
punpcklbw m8, m5, m1 ; place 8-bit coefficients in the upper
punpckhbw m9, m5, m1 ; half of each 16-bit word to avoid
punpcklbw m10, m5, m2 ; having to perform sign-extension.
punpckhbw m11, m5, m2
punpcklbw m12, m5, m3
punpckhbw m13, m5, m3
punpcklbw m14, m5, m4
punpckhbw m15, m5, m4
%else
punpcklbw m7, m5, m1
mova m8, m7
punpckhbw m7, m5, m1
mova m9, m7
punpcklbw m7, m5, m2
mova m10, m7
punpckhbw m7, m5, m2
mova m11, m7
punpcklbw m7, m5, m3
mova m12, m7
punpckhbw m7, m5, m3
mova m13, m7
punpcklbw m7, m5, m4
mova m14, m7
punpckhbw m7, m5, m4
mova m15, m7
%endif
mova m7, [base+filter_shuf]
add hd, hd
mov r5, dstq
pshuflw m6, m6, q0000
mov r6, tlq
punpcklqdq m6, m6
sub tlq, hq
.left_loop:
pshufb m0, m7 ; tl t0 t1 t2 t3 l0 l1 __
pshufd m1, m0, q0000
pmaddwd m2, m8, m1
pmaddwd m1, m9
pshufd m4, m0, q1111
pmaddwd m3, m10, m4
pmaddwd m4, m11
paddd m2, m3
paddd m1, m4
pshufd m4, m0, q2222
pmaddwd m3, m12, m4
pmaddwd m4, m13
paddd m2, m3
paddd m1, m4
pshufd m3, m0, q3333
pmaddwd m0, m14, m3
pmaddwd m3, m15
paddd m0, m2
paddd m1, m3
psrad m0, 11 ; x >> 3
psrad m1, 11
packssdw m0, m1
pmaxsw m0, m5
pavgw m0, m5 ; (x + 8) >> 4
pminsw m0, m6
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
movlps m0, [tlq+hq-10]
lea dstq, [dstq+strideq*2]
sub hd, 2*2
jg .left_loop
sub wd, 4
jz .end
sub tld, r6d ; -h*2
sub r6, r5 ; tl-dst
.right_loop0:
add r5, 8
mov hd, tld
movu m0, [r5+r6] ; tl t0 t1 t2 t3 __ __ __
mov dstq, r5
.right_loop:
pshufd m2, m0, q0000
pmaddwd m1, m8, m2
pmaddwd m2, m9
pshufd m4, m0, q1111
pmaddwd m3, m10, m4
pmaddwd m4, m11
pinsrw m0, [dstq+strideq*0-2], 5
paddd m1, m3
paddd m2, m4
pshufd m0, m0, q2222
movddup m4, [dstq+strideq*1-8]
pmaddwd m3, m12, m0
pmaddwd m0, m13
paddd m1, m3
paddd m0, m2
pshuflw m2, m4, q3333
punpcklwd m2, m5
pmaddwd m3, m14, m2
pmaddwd m2, m15
paddd m1, m3
paddd m0, m2
psrad m1, 11
psrad m0, 11
packssdw m0, m1
pmaxsw m0, m5
pavgw m0, m5
pminsw m0, m6
movhps [dstq+strideq*0], m0
movq [dstq+strideq*1], m0
palignr m0, m4, 14
lea dstq, [dstq+strideq*2]
add hd, 2*2
jl .right_loop
sub wd, 4
jg .right_loop0
.end:
RET
%if UNIX64
DECLARE_REG_TMP 7
%else
DECLARE_REG_TMP 5
%endif
cglobal ipred_cfl_top_16bpc, 4, 7, 8, dst, stride, tl, w, h, ac
LEA t0, ipred_cfl_left_16bpc_ssse3_table
movd m4, wd
tzcnt wd, wd
movifnidn hd, hm
add tlq, 2
movsxd r6, [t0+wq*4]
movd m5, wd
jmp mangle(private_prefix %+ _ipred_cfl_left_16bpc_ssse3.start)
cglobal ipred_cfl_left_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac, alpha
movifnidn hd, hm
LEA t0, ipred_cfl_left_16bpc_ssse3_table
tzcnt wd, wm
lea r6d, [hq*2]
movd m4, hd
sub tlq, r6
tzcnt r6d, hd
movd m5, r6d
movsxd r6, [t0+r6*4]
.start:
movd m7, r7m
movu m0, [tlq]
add r6, t0
add t0, ipred_cfl_splat_16bpc_ssse3_table-ipred_cfl_left_16bpc_ssse3_table
movsxd wq, [t0+wq*4]
pxor m6, m6
pshuflw m7, m7, q0000
pcmpeqw m3, m3
add wq, t0
movifnidn acq, acmp
pavgw m4, m6
punpcklqdq m7, m7
jmp r6
.h32:
movu m1, [tlq+48]
movu m2, [tlq+32]
paddw m0, m1
paddw m0, m2
.h16:
movu m1, [tlq+16]
paddw m0, m1
.h8:
pshufd m1, m0, q1032
paddw m0, m1
.h4:
pmaddwd m0, m3
psubd m4, m0
pshuflw m0, m4, q1032
paddd m0, m4
psrld m0, m5
pshuflw m0, m0, q0000
punpcklqdq m0, m0
jmp wq
%macro IPRED_CFL 2 ; dst, src
pabsw m%1, m%2
pmulhrsw m%1, m2
psignw m%2, m1
psignw m%1, m%2
paddw m%1, m0
pmaxsw m%1, m6
pminsw m%1, m7
%endmacro
cglobal ipred_cfl_16bpc, 4, 7, 8, dst, stride, tl, w, h, ac, alpha
movifnidn hd, hm
tzcnt r6d, hd
lea t0d, [wq+hq]
movd m4, t0d
tzcnt t0d, t0d
movd m5, t0d
LEA t0, ipred_cfl_16bpc_ssse3_table
tzcnt wd, wd
movd m7, r7m
movsxd r6, [t0+r6*4]
movsxd wq, [t0+wq*4+4*4]
psrlw m4, 1
pxor m6, m6
pshuflw m7, m7, q0000
add r6, t0
add wq, t0
movifnidn acq, acmp
pcmpeqw m3, m3
punpcklqdq m7, m7
jmp r6
.h4:
movq m0, [tlq-8]
jmp wq
.w4:
movq m1, [tlq+2]
paddw m0, m1
pmaddwd m0, m3
psubd m4, m0
pshufd m0, m4, q1032
paddd m0, m4
pshuflw m4, m0, q1032
paddd m0, m4
cmp hd, 4
jg .w4_mul
psrld m0, 3
jmp .w4_end
.w4_mul:
mov r6d, 0xAAAB
mov r2d, 0x6667
cmp hd, 16
cmove r6d, r2d
movd m1, r6d
psrld m0, 2
pmulhuw m0, m1
psrlw m0, 1
.w4_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s4:
movd m1, alpham
lea r6, [strideq*3]
pshuflw m1, m1, q0000
punpcklqdq m1, m1
pabsw m2, m1
psllw m2, 9
.s4_loop:
mova m4, [acq+16*0]
mova m5, [acq+16*1]
add acq, 16*2
IPRED_CFL 3, 4
IPRED_CFL 4, 5
movq [dstq+strideq*0], m3
movhps [dstq+strideq*1], m3
movq [dstq+strideq*2], m4
movhps [dstq+r6 ], m4
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s4_loop
RET
.h8:
mova m0, [tlq-16]
jmp wq
.w8:
movu m1, [tlq+2]
paddw m0, m1
pmaddwd m0, m3
psubd m4, m0
pshufd m0, m4, q1032
paddd m0, m4
pshuflw m4, m0, q1032
paddd m0, m4
psrld m0, m5
cmp hd, 8
je .w8_end
mov r6d, 0xAAAB
mov r2d, 0x6667
cmp hd, 32
cmove r6d, r2d
movd m1, r6d
pmulhuw m0, m1
psrlw m0, 1
.w8_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s8:
movd m1, alpham
pshuflw m1, m1, q0000
punpcklqdq m1, m1
pabsw m2, m1
psllw m2, 9
.s8_loop:
mova m4, [acq+16*0]
mova m5, [acq+16*1]
add acq, 16*2
IPRED_CFL 3, 4
IPRED_CFL 4, 5
mova [dstq+strideq*0], m3
mova [dstq+strideq*1], m4
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .s8_loop
RET
.h16:
mova m0, [tlq-32]
paddw m0, [tlq-16]
jmp wq
.w16:
movu m1, [tlq+ 2]
movu m2, [tlq+18]
paddw m1, m2
paddw m0, m1
pmaddwd m0, m3
psubd m4, m0
pshufd m0, m4, q1032
paddd m0, m4
pshuflw m4, m0, q1032
paddd m0, m4
psrld m0, m5
cmp hd, 16
je .w16_end
mov r6d, 0xAAAB
mov r2d, 0x6667
test hd, 8|32
cmovz r6d, r2d
movd m1, r6d
pmulhuw m0, m1
psrlw m0, 1
.w16_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s16:
movd m1, alpham
pshuflw m1, m1, q0000
punpcklqdq m1, m1
pabsw m2, m1
psllw m2, 9
.s16_loop:
mova m4, [acq+16*0]
mova m5, [acq+16*1]
add acq, 16*2
IPRED_CFL 3, 4
IPRED_CFL 4, 5
mova [dstq+16*0], m3
mova [dstq+16*1], m4
add dstq, strideq
dec hd
jg .s16_loop
RET
.h32:
mova m0, [tlq-64]
paddw m0, [tlq-48]
paddw m0, [tlq-32]
paddw m0, [tlq-16]
jmp wq
.w32:
movu m1, [tlq+ 2]
movu m2, [tlq+18]
paddw m1, m2
movu m2, [tlq+34]
paddw m1, m2
movu m2, [tlq+50]
paddw m1, m2
paddw m0, m1
pmaddwd m0, m3
psubd m4, m0
pshufd m0, m4, q1032
paddd m0, m4
pshuflw m4, m0, q1032
paddd m0, m4
psrld m0, m5
cmp hd, 32
je .w32_end
mov r6d, 0xAAAB
mov r2d, 0x6667
cmp hd, 8
cmove r6d, r2d
movd m1, r6d
pmulhuw m0, m1
psrlw m0, 1
.w32_end:
pshuflw m0, m0, q0000
punpcklqdq m0, m0
.s32:
movd m1, alpham
pshuflw m1, m1, q0000
punpcklqdq m1, m1
pabsw m2, m1
psllw m2, 9
.s32_loop:
mova m4, [acq+16*0]
mova m5, [acq+16*1]
IPRED_CFL 3, 4
IPRED_CFL 4, 5
mova [dstq+16*0], m3
mova [dstq+16*1], m4
mova m4, [acq+16*2]
mova m5, [acq+16*3]
add acq, 16*4
IPRED_CFL 3, 4
IPRED_CFL 4, 5
mova [dstq+16*2], m3
mova [dstq+16*3], m4
add dstq, strideq
dec hd
jg .s32_loop
RET
cglobal ipred_cfl_128_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac
tzcnt wd, wm
LEA t0, ipred_cfl_splat_16bpc_ssse3_table
mov r6d, r7m
movifnidn hd, hm
shr r6d, 11
movd m7, r7m
movsxd wq, [t0+wq*4]
movddup m0, [t0-ipred_cfl_splat_16bpc_ssse3_table+pw_512+r6*8]
pshuflw m7, m7, q0000
pxor m6, m6
add wq, t0
movifnidn acq, acmp
punpcklqdq m7, m7
jmp wq
cglobal ipred_cfl_ac_420_16bpc, 3, 7, 6, ac, ypx, stride, wpad, hpad, w, h
movifnidn hpadd, hpadm
%if ARCH_X86_32 && PIC
pcmpeqw m5, m5
pabsw m5, m5
paddw m5, m5
%else
movddup m5, [pw_2]
%endif
mov hd, hm
shl hpadd, 2
pxor m4, m4
sub hd, hpadd
cmp dword wm, 8
mov r5, acq
jg .w16
je .w8
lea r3, [strideq*3]
.w4_loop:
pmaddwd m0, m5, [ypxq+strideq*0]
pmaddwd m1, m5, [ypxq+strideq*1]
pmaddwd m2, m5, [ypxq+strideq*2]
pmaddwd m3, m5, [ypxq+r3 ]
lea ypxq, [ypxq+strideq*4]
paddd m0, m1
paddd m2, m3
paddd m4, m0
packssdw m0, m2
paddd m4, m2
mova [acq], m0
add acq, 16
sub hd, 2
jg .w4_loop
test hpadd, hpadd
jz .dc
punpckhqdq m0, m0
pslld m2, 2
.w4_hpad:
mova [acq+16*0], m0
paddd m4, m2
mova [acq+16*1], m0
add acq, 16*2
sub hpadd, 4
jg .w4_hpad
jmp .dc
.w8:
%if ARCH_X86_32
cmp dword wpadm, 0
%else
test wpadd, wpadd
%endif
jnz .w8_wpad1
.w8_loop:
pmaddwd m0, m5, [ypxq+strideq*0+16*0]
pmaddwd m2, m5, [ypxq+strideq*1+16*0]
pmaddwd m1, m5, [ypxq+strideq*0+16*1]
pmaddwd m3, m5, [ypxq+strideq*1+16*1]
lea ypxq, [ypxq+strideq*2]
paddd m0, m2
paddd m1, m3
paddd m2, m0, m1
packssdw m0, m1
paddd m4, m2
mova [acq], m0
add acq, 16
dec hd
jg .w8_loop
.w8_hpad:
test hpadd, hpadd
jz .dc
pslld m2, 2
mova m1, m0
jmp .hpad
.w8_wpad1:
pmaddwd m0, m5, [ypxq+strideq*0]
pmaddwd m1, m5, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
paddd m0, m1
pshufd m1, m0, q3333
paddd m2, m0, m1
packssdw m0, m1
paddd m4, m2
mova [acq], m0
add acq, 16
dec hd
jg .w8_wpad1
jmp .w8_hpad
.w16_wpad3:
pshufd m3, m0, q3333
mova m1, m3
mova m2, m3
jmp .w16_wpad_end
.w16_wpad2:
pshufd m1, m3, q3333
mova m2, m1
jmp .w16_wpad_end
.w16_wpad1:
pshufd m2, m1, q3333
jmp .w16_wpad_end
.w16:
movifnidn wpadd, wpadm
WIN64_SPILL_XMM 7
.w16_loop:
pmaddwd m0, m5, [ypxq+strideq*0+16*0]
pmaddwd m6, m5, [ypxq+strideq*1+16*0]
paddd m0, m6
cmp wpadd, 2
jg .w16_wpad3
pmaddwd m3, m5, [ypxq+strideq*0+16*1]
pmaddwd m6, m5, [ypxq+strideq*1+16*1]
paddd m3, m6
je .w16_wpad2
pmaddwd m1, m5, [ypxq+strideq*0+16*2]
pmaddwd m6, m5, [ypxq+strideq*1+16*2]
paddd m1, m6
jp .w16_wpad1
pmaddwd m2, m5, [ypxq+strideq*0+16*3]
pmaddwd m6, m5, [ypxq+strideq*1+16*3]
paddd m2, m6
.w16_wpad_end:
lea ypxq, [ypxq+strideq*2]
paddd m6, m0, m3
packssdw m0, m3
paddd m6, m1
mova [acq+16*0], m0
packssdw m1, m2
paddd m2, m6
mova [acq+16*1], m1
add acq, 16*2
paddd m4, m2
dec hd
jg .w16_loop
WIN64_RESTORE_XMM
add hpadd, hpadd
jz .dc
paddd m2, m2
.hpad:
mova [acq+16*0], m0
mova [acq+16*1], m1
paddd m4, m2
mova [acq+16*2], m0
mova [acq+16*3], m1
add acq, 16*4
sub hpadd, 4
jg .hpad
.dc:
sub r5, acq ; -w*h*2
pshufd m2, m4, q1032
tzcnt r1d, r5d
paddd m2, m4
sub r1d, 2
pshufd m4, m2, q2301
movd m0, r1d
paddd m2, m4
psrld m2, m0
pxor m0, m0
pavgw m2, m0
packssdw m2, m2
.dc_loop:
mova m0, [acq+r5+16*0]
mova m1, [acq+r5+16*1]
psubw m0, m2
psubw m1, m2
mova [acq+r5+16*0], m0
mova [acq+r5+16*1], m1
add r5, 16*2
jl .dc_loop
RET
cglobal ipred_cfl_ac_422_16bpc, 3, 7, 6, ac, ypx, stride, wpad, hpad, w, h
movifnidn hpadd, hpadm
%if ARCH_X86_32 && PIC
pcmpeqw m5, m5
pabsw m5, m5
psllw m5, 2
%else
movddup m5, [pw_4]
%endif
mov hd, hm
shl hpadd, 2
pxor m4, m4
sub hd, hpadd
cmp dword wm, 8
mov r5, acq
jg .w16
je .w8
lea r3, [strideq*3]
.w4_loop:
pmaddwd m0, m5, [ypxq+strideq*0]
pmaddwd m3, m5, [ypxq+strideq*1]
pmaddwd m1, m5, [ypxq+strideq*2]
pmaddwd m2, m5, [ypxq+r3 ]
lea ypxq, [ypxq+strideq*4]
paddd m4, m0
packssdw m0, m3
paddd m3, m1
packssdw m1, m2
paddd m4, m2
paddd m4, m3
mova [acq+16*0], m0
mova [acq+16*1], m1
add acq, 16*2
sub hd, 4
jg .w4_loop
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
punpckhqdq m1, m1
pslld m2, 3
mova [acq+16*0], m1
mova [acq+16*1], m1
paddd m4, m2
mova [acq+16*2], m1
mova [acq+16*3], m1
add acq, 16*4
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
.w8:
%if ARCH_X86_32
cmp dword wpadm, 0
%else
test wpadd, wpadd
%endif
jnz .w8_wpad1
.w8_loop:
pmaddwd m0, m5, [ypxq+strideq*0+16*0]
pmaddwd m2, m5, [ypxq+strideq*0+16*1]
pmaddwd m1, m5, [ypxq+strideq*1+16*0]
pmaddwd m3, m5, [ypxq+strideq*1+16*1]
lea ypxq, [ypxq+strideq*2]
paddd m4, m0
packssdw m0, m2
paddd m4, m2
mova [acq+16*0], m0
paddd m2, m1, m3
packssdw m1, m3
paddd m4, m2
mova [acq+16*1], m1
add acq, 16*2
sub hd, 2
jg .w8_loop
.w8_hpad:
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
pslld m2, 2
mova m0, m1
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).hpad
.w8_wpad1:
pmaddwd m0, m5, [ypxq+strideq*0]
pmaddwd m1, m5, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
pshufd m2, m0, q3333
pshufd m3, m1, q3333
paddd m4, m0
packssdw m0, m2
paddd m4, m2
paddd m2, m1, m3
packssdw m1, m3
paddd m4, m2
mova [acq+16*0], m0
mova [acq+16*1], m1
add acq, 16*2
sub hd, 2
jg .w8_wpad1
jmp .w8_hpad
.w16_wpad3:
pshufd m3, m0, q3333
mova m1, m3
mova m2, m3
jmp .w16_wpad_end
.w16_wpad2:
pshufd m1, m3, q3333
mova m2, m1
jmp .w16_wpad_end
.w16_wpad1:
pshufd m2, m1, q3333
jmp .w16_wpad_end
.w16:
movifnidn wpadd, wpadm
WIN64_SPILL_XMM 7
.w16_loop:
pmaddwd m0, m5, [ypxq+16*0]
cmp wpadd, 2
jg .w16_wpad3
pmaddwd m3, m5, [ypxq+16*1]
je .w16_wpad2
pmaddwd m1, m5, [ypxq+16*2]
jp .w16_wpad1
pmaddwd m2, m5, [ypxq+16*3]
.w16_wpad_end:
add ypxq, strideq
paddd m6, m0, m3
packssdw m0, m3
mova [acq+16*0], m0
paddd m6, m1
packssdw m1, m2
paddd m2, m6
mova [acq+16*1], m1
add acq, 16*2
paddd m4, m2
dec hd
jg .w16_loop
WIN64_RESTORE_XMM
add hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
paddd m2, m2
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).hpad
cglobal ipred_cfl_ac_444_16bpc, 3, 7, 6, ac, ypx, stride, wpad, hpad, w, h
%define base r6-ipred_cfl_ac_444_16bpc_ssse3_table
LEA r6, ipred_cfl_ac_444_16bpc_ssse3_table
tzcnt wd, wm
movifnidn hpadd, hpadm
pxor m4, m4
movsxd wq, [r6+wq*4]
movddup m5, [base+pw_1]
add wq, r6
mov hd, hm
shl hpadd, 2
sub hd, hpadd
jmp wq
.w4:
lea r3, [strideq*3]
mov r5, acq
.w4_loop:
movq m0, [ypxq+strideq*0]
movhps m0, [ypxq+strideq*1]
movq m1, [ypxq+strideq*2]
movhps m1, [ypxq+r3 ]
lea ypxq, [ypxq+strideq*4]
psllw m0, 3
psllw m1, 3
mova [acq+16*0], m0
pmaddwd m0, m5
mova [acq+16*1], m1
pmaddwd m2, m5, m1
add acq, 16*2
paddd m4, m0
paddd m4, m2
sub hd, 4
jg .w4_loop
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
punpckhqdq m1, m1
mova [acq+16*0], m1
pslld m2, 2
mova [acq+16*1], m1
punpckhqdq m2, m2
mova [acq+16*2], m1
paddd m4, m2
mova [acq+16*3], m1
add acq, 16*4
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
.w8:
mov r5, acq
.w8_loop:
mova m0, [ypxq+strideq*0]
mova m1, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
psllw m0, 3
psllw m1, 3
mova [acq+16*0], m0
pmaddwd m0, m5
mova [acq+16*1], m1
pmaddwd m2, m5, m1
add acq, 16*2
paddd m4, m0
paddd m4, m2
sub hd, 2
jg .w8_loop
.w8_hpad:
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
pslld m2, 2
mova m0, m1
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).hpad
.w16_wpad2:
pshufhw m3, m2, q3333
pshufhw m1, m0, q3333
punpckhqdq m3, m3
punpckhqdq m1, m1
jmp .w16_wpad_end
.w16:
movifnidn wpadd, wpadm
mov r5, acq
.w16_loop:
mova m2, [ypxq+strideq*0+16*0]
mova m0, [ypxq+strideq*1+16*0]
psllw m2, 3
psllw m0, 3
test wpadd, wpadd
jnz .w16_wpad2
mova m3, [ypxq+strideq*0+16*1]
mova m1, [ypxq+strideq*1+16*1]
psllw m3, 3
psllw m1, 3
.w16_wpad_end:
lea ypxq, [ypxq+strideq*2]
mova [acq+16*0], m2
pmaddwd m2, m5
mova [acq+16*1], m3
pmaddwd m3, m5
paddd m4, m2
pmaddwd m2, m5, m0
mova [acq+16*2], m0
paddd m4, m3
pmaddwd m3, m5, m1
mova [acq+16*3], m1
add acq, 16*4
paddd m2, m3
paddd m4, m2
sub hd, 2
jg .w16_loop
add hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
paddd m2, m2
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).hpad
.w32_wpad6:
pshufhw m1, m0, q3333
punpckhqdq m1, m1
mova m2, m1
mova m3, m1
jmp .w32_wpad_end
.w32_wpad4:
pshufhw m2, m1, q3333
punpckhqdq m2, m2
mova m3, m2
jmp .w32_wpad_end
.w32_wpad2:
pshufhw m3, m2, q3333
punpckhqdq m3, m3
jmp .w32_wpad_end
.w32:
movifnidn wpadd, wpadm
mov r5, acq
WIN64_SPILL_XMM 8
.w32_loop:
mova m0, [ypxq+16*0]
psllw m0, 3
cmp wpadd, 4
jg .w32_wpad6
mova m1, [ypxq+16*1]
psllw m1, 3
je .w32_wpad4
mova m2, [ypxq+16*2]
psllw m2, 3
jnp .w32_wpad2
mova m3, [ypxq+16*3]
psllw m3, 3
.w32_wpad_end:
add ypxq, strideq
pmaddwd m6, m5, m0
mova [acq+16*0], m0
pmaddwd m7, m5, m1
mova [acq+16*1], m1
paddd m6, m7
pmaddwd m7, m5, m2
mova [acq+16*2], m2
paddd m6, m7
pmaddwd m7, m5, m3
mova [acq+16*3], m3
add acq, 16*4
paddd m6, m7
paddd m4, m6
dec hd
jg .w32_loop
%if WIN64
mova m5, m6
WIN64_RESTORE_XMM
SWAP 5, 6
%endif
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
.w32_hpad_loop:
mova [acq+16*0], m0
mova [acq+16*1], m1
paddd m4, m6
mova [acq+16*2], m2
mova [acq+16*3], m3
add acq, 16*4
dec hpadd
jg .w32_hpad_loop
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_ssse3).dc
cglobal pal_pred_16bpc, 4, 5, 6, dst, stride, pal, idx, w, h
%define base r2-pal_pred_16bpc_ssse3_table
%if ARCH_X86_32
%define hd r2d
%endif
mova m4, [palq]
LEA r2, pal_pred_16bpc_ssse3_table
tzcnt wd, wm
pshufb m4, [base+pal_pred_shuf]
movsxd wq, [r2+wq*4]
pshufd m5, m4, q1032
add wq, r2
movifnidn hd, hm
jmp wq
.w4:
movq m0, [idxq]
add idxq, 8
psrlw m1, m0, 4
punpcklbw m0, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
movq [dstq+strideq*0], m0
movhps [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
movq [dstq+strideq*0], m1
movhps [dstq+strideq*1], m1
lea dstq, [dstq+strideq*2]
sub hd, 4
jg .w4
RET
.w8:
movu m3, [idxq]
add idxq, 16
psrlw m1, m3, 4
punpcklbw m0, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
lea dstq, [dstq+strideq*2]
pshufb m1, m4, m3
pshufb m2, m5, m3
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
lea dstq, [dstq+strideq*2]
sub hd, 4
jg .w8
RET
.w16:
movu m3, [idxq]
add idxq, 16
psrlw m1, m3, 4
punpcklbw m0, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+ 0], m0
mova [dstq+16], m1
pshufb m1, m4, m3
pshufb m2, m5, m3
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+strideq+ 0], m0
mova [dstq+strideq+16], m1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w16
RET
.w32:
movu m3, [idxq]
add idxq, 16
psrlw m1, m3, 4
punpcklbw m0, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*0], m0
mova [dstq+16*1], m1
pshufb m1, m4, m3
pshufb m2, m5, m3
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*2], m0
mova [dstq+16*3], m1
add dstq, strideq
dec hd
jg .w32
RET
.w64:
movu m3, [idxq+16*0]
psrlw m1, m3, 4
punpcklbw m0, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*0], m0
mova [dstq+16*1], m1
pshufb m1, m4, m3
pshufb m2, m5, m3
movu m3, [idxq+16*1]
add idxq, 32
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*2], m0
mova [dstq+16*3], m1
psrlw m1, m3, 4
punpcklbw m0, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m0
pshufb m2, m5, m0
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*4], m0
mova [dstq+16*5], m1
pshufb m1, m4, m3
pshufb m2, m5, m3
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+16*6], m0
mova [dstq+16*7], m1
add dstq, strideq
dec hd
jg .w64
RET
|