1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
|
; 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 64
%macro SMOOTH_WEIGHTS 1-*
const smooth_weights_1d_16bpc ; sm_weights[] << 7
%rep %0
dw %1*128
%rotate 1
%endrep
const smooth_weights_2d_16bpc ; sm_weights[], 256 - sm_weights[]
%rep %0
dw %1, 256-%1
%rotate 1
%endrep
%endmacro
SMOOTH_WEIGHTS 0, 0, 255, 128, 255, 149, 85, 64, \
255, 197, 146, 105, 73, 50, 37, 32, \
255, 225, 196, 170, 145, 123, 102, 84, \
68, 54, 43, 33, 26, 20, 17, 16, \
255, 240, 225, 210, 196, 182, 169, 157, \
145, 133, 122, 111, 101, 92, 83, 74, \
66, 59, 52, 45, 39, 34, 29, 25, \
21, 17, 14, 12, 10, 9, 8, 8, \
255, 248, 240, 233, 225, 218, 210, 203, \
196, 189, 182, 176, 169, 163, 156, 150, \
144, 138, 133, 127, 121, 116, 111, 106, \
101, 96, 91, 86, 82, 77, 73, 69, \
65, 61, 57, 54, 50, 47, 44, 41, \
38, 35, 32, 29, 27, 25, 22, 20, \
18, 16, 15, 13, 12, 10, 9, 8, \
7, 6, 6, 5, 5, 4, 4, 4
%if ARCH_X86_64
ipred_hv_shuf: db 6, 7, 6, 7, 0, 1, 2, 3, 2, 3, 2, 3, 8, 9, 10, 11
db 4, 5, 4, 5, 4, 5, 6, 7, 0, 1, 0, 1, 12, 13, 14, 15
filter_shuf1: db 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 14, 15, 12, 13, -1, -1
filter_shuf2: db 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 2, 3, -1, -1
filter_shuf3: db 12, 13, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 8, 9, -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
dw 8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64
z_filter_t0: db 55,127, 39,127, 39,127, 7, 15, 31, 7, 15, 31, 0, 3, 31, 0
z_filter_t1: db 39, 63, 19, 47, 19, 47, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0
z_filter_wh: db 7, 7, 11, 11, 15, 15, 19, 19, 19, 23, 23, 23, 31, 31, 31, 39
db 39, 39, 47, 47, 47, 63, 63, 63, 79, 79, 79, -1
pw_m1024: times 2 dw -1024
pw_1to16: dw 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
pw_16to1: dw 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
z2_ymul: dw 1, 2, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 3, 4
z2_ymul8: dw 1, 2, 5, 6, 3, 4, 7, 8, 5, 6, 16, 16, 7, 8
pb_90: times 4 db 90
z2_y_shuf_h4: dd 3, 7, 2, 6, 1, 5, 0, 4
z_upsample: db 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15
z2_x_shuf: db 0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 8, 9
z2_y_shuf: db 6, 7, 14, 15, 4, 5, 12, 13, 4, 5, 12, 13, 2, 3, 10, 11
z2_y_shuf_us: db 6, 7, 14, 15, 2, 3, 10, 11, 4, 5, 12, 13, 0, 1, 8, 9
z_filter_k: dw 4, 4, 5, 5, 4, 4
dw 8, 8, 6, 6, 4, 4
dw 0, 0, 0, 0, 2, 2
%define pw_2 (z_filter_k+32)
%define pw_4 (z_filter_k+ 0)
%define pw_16 (z2_ymul8 +20)
pw_1: times 2 dw 1
pw_3: times 2 dw 3
pw_62: times 2 dw 62
pw_512: times 2 dw 512
pw_2048: times 2 dw 2048
pd_8: dd 8
%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_avx2_table (ipred_dc_16bpc_avx2_table + 10*4)
%define ipred_cfl_splat_16bpc_avx2_table (ipred_cfl_16bpc_avx2_table + 8*4)
JMP_TABLE ipred_dc_16bpc, avx2, 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
JMP_TABLE ipred_dc_left_16bpc, avx2, h4, h8, h16, h32, h64
JMP_TABLE ipred_h_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_paeth_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_smooth_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_smooth_h_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_smooth_v_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_z1_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_z2_16bpc, avx2, w4, w8, w16, w32, w64
JMP_TABLE ipred_z3_16bpc, avx2, h4, h8, h16, h32, h64
JMP_TABLE ipred_filter_16bpc, avx2, w4, w8, w16, w32
JMP_TABLE ipred_cfl_16bpc, avx2, 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, avx2, h4, h8, h16, h32
JMP_TABLE ipred_cfl_ac_444_16bpc, avx2, w4, w8, w16, w32
JMP_TABLE pal_pred_16bpc, avx2, w4, w8, w16, w32, w64
cextern dr_intra_derivative
cextern filter_intra_taps
SECTION .text
INIT_YMM avx2
cglobal ipred_dc_top_16bpc, 3, 7, 6, dst, stride, tl, w, h
movifnidn hd, hm
add tlq, 2
movd xm4, wd
pxor xm3, xm3
pavgw xm4, xm3
tzcnt wd, wd
movd xm5, wd
movu m0, [tlq]
lea r5, [ipred_dc_left_16bpc_avx2_table]
movsxd r6, [r5+wq*4]
add r6, r5
add r5, ipred_dc_splat_16bpc_avx2_table-ipred_dc_left_16bpc_avx2_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
mov hd, hm
sub tlq, hq
movd xm4, hd
sub tlq, hq
pxor xm3, xm3
pavgw xm4, xm3
tzcnt r6d, hd
movd xm5, r6d
movu m0, [tlq]
lea r5, [ipred_dc_left_16bpc_avx2_table]
movsxd r6, [r5+r6*4]
add r6, r5
add r5, ipred_dc_splat_16bpc_avx2_table-ipred_dc_left_16bpc_avx2_table
tzcnt wd, wd
movsxd wq, [r5+wq*4]
add wq, r5
jmp r6
.h64:
paddw m0, [tlq+96]
paddw m0, [tlq+64]
.h32:
paddw m0, [tlq+32]
.h16:
vextracti128 xm1, m0, 1
paddw xm0, xm1
.h8:
psrldq xm1, xm0, 8
paddw xm0, xm1
.h4:
punpcklwd xm0, xm3
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
paddd xm0, xm4
psrld xm0, xm5
lea stride3q, [strideq*3]
vpbroadcastw m0, xm0
mova m1, m0
mova m2, m0
mova m3, m0
jmp wq
cglobal ipred_dc_16bpc, 3, 7, 6, dst, stride, tl, w, h, stride3
movifnidn hd, hm
tzcnt r6d, hd
lea r5d, [wq+hq]
movd xm4, r5d
tzcnt r5d, r5d
movd xm5, r5d
lea r5, [ipred_dc_16bpc_avx2_table]
tzcnt wd, wd
movsxd r6, [r5+r6*4]
movsxd wq, [r5+wq*4+5*4]
pxor m3, m3
psrlw xm4, 1
add r6, r5
add wq, r5
lea stride3q, [strideq*3]
jmp r6
.h4:
movq xm0, [tlq-8]
jmp wq
.w4:
movq xm1, [tlq+2]
paddw m0, m4
paddw m0, m1
psrlq m1, m0, 32
paddw m0, m1
psrld m1, m0, 16
paddw m0, m1
cmp hd, 4
jg .w4_mul
psrlw xm0, 3
jmp .w4_end
.w4_mul:
vextracti128 xm1, m0, 1
paddw xm0, xm1
lea r2d, [hq*2]
mov r6d, 0xAAAB6667
shrx r6d, r6d, r2d
punpckhwd xm1, xm0, xm3
punpcklwd xm0, xm3
paddd xm0, xm1
movd xm1, r6d
psrld xm0, 2
pmulhuw xm0, xm1
psrlw xm0, 1
.w4_end:
vpbroadcastw xm0, xm0
.s4:
movq [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm0
movq [dstq+stride3q ], xm0
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s4
RET
ALIGN function_align
.h8:
mova xm0, [tlq-16]
jmp wq
.w8:
vextracti128 xm1, m0, 1
paddw xm0, [tlq+2]
paddw xm0, xm4
paddw xm0, xm1
psrld xm1, xm0, 16
paddw xm0, xm1
pblendw xm0, xm3, 0xAA
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 8
je .w8_end
mov r6d, 0xAAAB
mov r2d, 0x6667
cmp hd, 32
cmovz r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w8_end:
vpbroadcastw xm0, xm0
.s8:
mova [dstq+strideq*0], xm0
mova [dstq+strideq*1], xm0
mova [dstq+strideq*2], xm0
mova [dstq+stride3q ], xm0
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s8
RET
ALIGN function_align
.h16:
mova m0, [tlq-32]
jmp wq
.w16:
paddw m0, [tlq+2]
vextracti128 xm1, m0, 1
paddw xm0, xm4
paddw xm0, xm1
punpckhwd xm1, xm0, xm3
punpcklwd xm0, xm3
paddd xm0, xm1
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 16
je .w16_end
mov r6d, 0xAAAB
mov r2d, 0x6667
test hb, 8|32
cmovz r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w16_end:
vpbroadcastw m0, xm0
.s16:
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 .s16
RET
ALIGN function_align
.h32:
mova m0, [tlq-64]
paddw m0, [tlq-32]
jmp wq
.w32:
paddw m0, [tlq+ 2]
paddw m0, [tlq+34]
vextracti128 xm1, m0, 1
paddw xm0, xm4
paddw xm0, xm1
punpcklwd xm1, xm0, xm3
punpckhwd xm0, xm3
paddd xm0, xm1
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 32
je .w32_end
lea r2d, [hq*2]
mov r6d, 0x6667AAAB
shrx r6d, r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w32_end:
vpbroadcastw m0, xm0
mova m1, m0
.s32:
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m1
mova [dstq+strideq*1+32*0], m0
mova [dstq+strideq*1+32*1], m1
mova [dstq+strideq*2+32*0], m0
mova [dstq+strideq*2+32*1], m1
mova [dstq+stride3q +32*0], m0
mova [dstq+stride3q +32*1], m1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .s32
RET
ALIGN function_align
.h64:
mova m0, [tlq-128]
mova m1, [tlq- 96]
paddw m0, [tlq- 64]
paddw m1, [tlq- 32]
paddw m0, m1
jmp wq
.w64:
movu m1, [tlq+ 2]
paddw m0, [tlq+34]
paddw m1, [tlq+66]
paddw m0, [tlq+98]
paddw m0, m1
vextracti128 xm1, m0, 1
paddw xm0, xm1
punpcklwd xm1, xm0, xm3
punpckhwd xm0, xm3
paddd xm1, xm4
paddd xm0, xm1
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 64
je .w64_end
mov r6d, 0x6667AAAB
shrx r6d, r6d, hd
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w64_end:
vpbroadcastw m0, xm0
mova m1, m0
mova m2, m0
mova m3, m0
.s64:
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m1
mova [dstq+strideq*0+32*2], m2
mova [dstq+strideq*0+32*3], m3
mova [dstq+strideq*1+32*0], m0
mova [dstq+strideq*1+32*1], m1
mova [dstq+strideq*1+32*2], m2
mova [dstq+strideq*1+32*3], m3
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .s64
RET
cglobal ipred_dc_128_16bpc, 2, 7, 6, dst, stride, tl, w, h, stride3
mov r6d, r8m
shr r6d, 11
lea r5, [ipred_dc_splat_16bpc_avx2_table]
tzcnt wd, wd
movifnidn hd, hm
movsxd wq, [r5+wq*4]
vpbroadcastd m0, [r5-ipred_dc_splat_16bpc_avx2_table+pw_512+r6*4]
mova m1, m0
mova m2, m0
mova m3, m0
add wq, r5
lea stride3q, [strideq*3]
jmp wq
cglobal ipred_v_16bpc, 3, 7, 6, dst, stride, tl, w, h, stride3
movifnidn hd, hm
movu m0, [tlq+ 2]
movu m1, [tlq+34]
movu m2, [tlq+66]
movu m3, [tlq+98]
lea r5, [ipred_dc_splat_16bpc_avx2_table]
tzcnt wd, wd
movsxd wq, [r5+wq*4]
add wq, r5
lea stride3q, [strideq*3]
jmp wq
%macro IPRED_H 2 ; w, store_type
vpbroadcastw m0, [tlq-2]
vpbroadcastw m1, [tlq-4]
vpbroadcastw m2, [tlq-6]
vpbroadcastw m3, [tlq-8]
sub tlq, 8
mov%2 [dstq+strideq*0], m0
mov%2 [dstq+strideq*1], m1
mov%2 [dstq+strideq*2], m2
mov%2 [dstq+stride3q ], m3
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w%1
RET
ALIGN function_align
%endmacro
cglobal ipred_h_16bpc, 3, 6, 4, dst, stride, tl, w, h, stride3
movifnidn hd, hm
lea r5, [ipred_h_16bpc_avx2_table]
tzcnt wd, wd
movsxd wq, [r5+wq*4]
add wq, r5
lea stride3q, [strideq*3]
jmp wq
INIT_XMM avx2
.w4:
IPRED_H 4, q
.w8:
IPRED_H 8, a
INIT_YMM avx2
.w16:
IPRED_H 16, a
.w32:
vpbroadcastw m0, [tlq-2]
vpbroadcastw m1, [tlq-4]
vpbroadcastw m2, [tlq-6]
vpbroadcastw m3, [tlq-8]
sub tlq, 8
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m0
mova [dstq+strideq*1+32*0], m1
mova [dstq+strideq*1+32*1], m1
mova [dstq+strideq*2+32*0], m2
mova [dstq+strideq*2+32*1], m2
mova [dstq+stride3q +32*0], m3
mova [dstq+stride3q +32*1], m3
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w32
RET
.w64:
vpbroadcastw m0, [tlq-2]
vpbroadcastw m1, [tlq-4]
sub tlq, 4
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m0
mova [dstq+strideq*0+32*2], m0
mova [dstq+strideq*0+32*3], m0
mova [dstq+strideq*1+32*0], m1
mova [dstq+strideq*1+32*1], m1
mova [dstq+strideq*1+32*2], m1
mova [dstq+strideq*1+32*3], m1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w64
RET
%macro PAETH 3 ; top, signed_ldiff, ldiff
paddw m0, m%2, m1
psubw m7, m3, m0 ; tldiff
psubw m0, m%1 ; tdiff
pabsw m7, m7
pabsw m0, m0
pminsw m7, m0
pcmpeqw m0, m7
pcmpgtw m7, m%3, m7
vpblendvb m0, m3, m%1, m0
vpblendvb m0, m1, m0, m7
%endmacro
cglobal ipred_paeth_16bpc, 3, 6, 8, dst, stride, tl, w, h
%define base r5-ipred_paeth_16bpc_avx2_table
movifnidn hd, hm
lea r5, [ipred_paeth_16bpc_avx2_table]
tzcnt wd, wd
movsxd wq, [r5+wq*4]
vpbroadcastw m3, [tlq] ; topleft
add wq, r5
jmp wq
.w4:
vpbroadcastq m2, [tlq+2] ; top
movsldup m6, [base+ipred_hv_shuf]
lea r3, [strideq*3]
psubw m4, m2, m3
pabsw m5, m4
.w4_loop:
sub tlq, 8
vpbroadcastq m1, [tlq]
pshufb m1, m6 ; left
PAETH 2, 4, 5
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm1
movhps [dstq+strideq*2], xm0
movhps [dstq+r3 ], xm1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4_loop
RET
ALIGN function_align
.w8:
vbroadcasti128 m2, [tlq+2]
movsldup m6, [base+ipred_hv_shuf]
psubw m4, m2, m3
pabsw m5, m4
.w8_loop:
sub tlq, 4
vpbroadcastd m1, [tlq]
pshufb m1, m6
PAETH 2, 4, 5
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w8_loop
RET
ALIGN function_align
.w16:
movu m2, [tlq+2]
psubw m4, m2, m3
pabsw m5, m4
.w16_loop:
sub tlq, 2
vpbroadcastw m1, [tlq]
PAETH 2, 4, 5
mova [dstq], m0
add dstq, strideq
dec hd
jg .w16_loop
RET
ALIGN function_align
.w32:
movu m2, [tlq+2]
movu m6, [tlq+34]
%if WIN64
movaps r4m, xmm8
movaps r6m, xmm9
%endif
psubw m4, m2, m3
psubw m8, m6, m3
pabsw m5, m4
pabsw m9, m8
.w32_loop:
sub tlq, 2
vpbroadcastw m1, [tlq]
PAETH 2, 4, 5
mova [dstq+32*0], m0
PAETH 6, 8, 9
mova [dstq+32*1], m0
add dstq, strideq
dec hd
jg .w32_loop
%if WIN64
movaps xmm8, r4m
movaps xmm9, r6m
%endif
RET
ALIGN function_align
.w64:
WIN64_SPILL_XMM 16
movu m2, [tlq+ 2]
movu m6, [tlq+34]
movu m10, [tlq+66]
movu m13, [tlq+98]
psubw m4, m2, m3
psubw m8, m6, m3
psubw m11, m10, m3
psubw m14, m13, m3
pabsw m5, m4
pabsw m9, m8
pabsw m12, m11
pabsw m15, m14
.w64_loop:
sub tlq, 2
vpbroadcastw m1, [tlq]
PAETH 2, 4, 5
mova [dstq+32*0], m0
PAETH 6, 8, 9
mova [dstq+32*1], m0
PAETH 10, 11, 12
mova [dstq+32*2], m0
PAETH 13, 14, 15
mova [dstq+32*3], m0
add dstq, strideq
dec hd
jg .w64_loop
RET
cglobal ipred_smooth_v_16bpc, 3, 7, 6, dst, stride, tl, w, h, weights
%define base r6-ipred_smooth_v_16bpc_avx2_table
lea r6, [ipred_smooth_v_16bpc_avx2_table]
tzcnt wd, wm
mov hd, hm
movsxd wq, [r6+wq*4]
lea weightsq, [base+smooth_weights_1d_16bpc+hq*4]
neg hq
vpbroadcastw m5, [tlq+hq*2] ; bottom
add wq, r6
jmp wq
.w4:
vpbroadcastq m4, [tlq+2] ; top
movsldup m3, [base+ipred_hv_shuf]
lea r6, [strideq*3]
psubw m4, m5 ; top - bottom
.w4_loop:
vpbroadcastq m0, [weightsq+hq*2]
pshufb m0, m3
pmulhrsw m0, m4
paddw m0, m5
vextracti128 xm1, m0, 1
movhps [dstq+strideq*0], xm1
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movq [dstq+r6 ], xm0
lea dstq, [dstq+strideq*4]
add hq, 4
jl .w4_loop
.ret:
RET
.w8:
vbroadcasti128 m4, [tlq+2]
movsldup m3, [base+ipred_hv_shuf]
lea r6, [strideq*3]
psubw m4, m5
.w8_loop:
vpbroadcastd m0, [weightsq+hq*2+0]
vpbroadcastd m1, [weightsq+hq*2+4]
pshufb m0, m3
pshufb m1, m3
pmulhrsw m0, m4
pmulhrsw m1, m4
paddw m0, m5
paddw m1, m5
vextracti128 [dstq+strideq*0], m0, 1
mova [dstq+strideq*1], xm0
vextracti128 [dstq+strideq*2], m1, 1
mova [dstq+r6 ], xm1
lea dstq, [dstq+strideq*4]
add hq, 4
jl .w8_loop
RET
.w16:
movu m4, [tlq+2]
lea r6, [strideq*3]
psubw m4, m5
.w16_loop:
vpbroadcastw m0, [weightsq+hq*2+0]
vpbroadcastw m1, [weightsq+hq*2+2]
vpbroadcastw m2, [weightsq+hq*2+4]
vpbroadcastw m3, [weightsq+hq*2+6]
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
REPX {paddw x, m5}, m0, m1, m2, m3
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
mova [dstq+strideq*2], m2
mova [dstq+r6 ], m3
lea dstq, [dstq+strideq*4]
add hq, 4
jl .w16_loop
RET
.w32:
WIN64_SPILL_XMM 7
movu m4, [tlq+ 2]
movu m6, [tlq+34]
psubw m4, m5
psubw m6, m5
.w32_loop:
vpbroadcastw m1, [weightsq+hq*2+0]
vpbroadcastw m3, [weightsq+hq*2+2]
pmulhrsw m0, m4, m1
pmulhrsw m1, m6
pmulhrsw m2, m4, m3
pmulhrsw m3, m6
REPX {paddw x, m5}, m0, m1, m2, m3
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m1
mova [dstq+strideq*1+32*0], m2
mova [dstq+strideq*1+32*1], m3
lea dstq, [dstq+strideq*2]
add hq, 2
jl .w32_loop
RET
.w64:
WIN64_SPILL_XMM 8
movu m3, [tlq+ 2]
movu m4, [tlq+34]
movu m6, [tlq+66]
movu m7, [tlq+98]
REPX {psubw x, m5}, m3, m4, m6, m7
.w64_loop:
vpbroadcastw m2, [weightsq+hq*2]
pmulhrsw m0, m3, m2
pmulhrsw m1, m4, m2
paddw m0, m5
paddw m1, m5
mova [dstq+32*0], m0
pmulhrsw m0, m6, m2
mova [dstq+32*1], m1
pmulhrsw m1, m7, m2
paddw m0, m5
paddw m1, m5
mova [dstq+32*2], m0
mova [dstq+32*3], m1
add dstq, strideq
inc hq
jl .w64_loop
RET
cglobal ipred_smooth_h_16bpc, 3, 7, 6, dst, stride, tl, w, h, stride3
%define base r6-ipred_smooth_h_16bpc_avx2_table
lea r6, [ipred_smooth_h_16bpc_avx2_table]
mov wd, wm
movifnidn hd, hm
vpbroadcastw m5, [tlq+wq*2] ; right
tzcnt wd, wd
add hd, hd
movsxd wq, [r6+wq*4]
sub tlq, hq
lea stride3q, [strideq*3]
add wq, r6
jmp wq
.w4:
vpbroadcastq m4, [base+smooth_weights_1d_16bpc+4*2]
movsldup m3, [base+ipred_hv_shuf]
.w4_loop:
vpbroadcastq m0, [tlq+hq-8] ; left
pshufb m0, m3
psubw m0, m5 ; left - right
pmulhrsw m0, m4
paddw m0, m5
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm1
movhps [dstq+strideq*2], xm0
movhps [dstq+stride3q ], xm1
lea dstq, [dstq+strideq*4]
sub hd, 4*2
jg .w4_loop
RET
.w8:
vbroadcasti128 m4, [base+smooth_weights_1d_16bpc+8*2]
movsldup m3, [base+ipred_hv_shuf]
.w8_loop:
vpbroadcastd m0, [tlq+hq-4]
vpbroadcastd m1, [tlq+hq-8]
pshufb m0, m3
pshufb m1, m3
psubw m0, m5
psubw m1, m5
pmulhrsw m0, m4
pmulhrsw m1, m4
paddw m0, m5
paddw m1, m5
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
mova [dstq+strideq*2], xm1
vextracti128 [dstq+stride3q ], m1, 1
lea dstq, [dstq+strideq*4]
sub hq, 4*2
jg .w8_loop
RET
.w16:
movu m4, [base+smooth_weights_1d_16bpc+16*2]
.w16_loop:
vpbroadcastq m3, [tlq+hq-8]
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 [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
mova [dstq+strideq*2], m2
mova [dstq+stride3q ], m3
lea dstq, [dstq+strideq*4]
sub hq, 4*2
jg .w16_loop
RET
.w32:
WIN64_SPILL_XMM 7
movu m4, [base+smooth_weights_1d_16bpc+32*2]
movu m6, [base+smooth_weights_1d_16bpc+32*3]
.w32_loop:
vpbroadcastw m1, [tlq+hq-2]
vpbroadcastw m3, [tlq+hq-4]
psubw m1, m5
psubw m3, m5
pmulhrsw m0, m4, m1
pmulhrsw m1, m6
pmulhrsw m2, m4, m3
pmulhrsw m3, m6
REPX {paddw x, m5}, m0, m1, m2, m3
mova [dstq+strideq*0+32*0], m0
mova [dstq+strideq*0+32*1], m1
mova [dstq+strideq*1+32*0], m2
mova [dstq+strideq*1+32*1], m3
lea dstq, [dstq+strideq*2]
sub hq, 2*2
jg .w32_loop
RET
.w64:
WIN64_SPILL_XMM 8
movu m3, [base+smooth_weights_1d_16bpc+32*4]
movu m4, [base+smooth_weights_1d_16bpc+32*5]
movu m6, [base+smooth_weights_1d_16bpc+32*6]
movu m7, [base+smooth_weights_1d_16bpc+32*7]
.w64_loop:
vpbroadcastw m2, [tlq+hq-2]
psubw m2, m5
pmulhrsw m0, m3, m2
pmulhrsw m1, m4, m2
paddw m0, m5
paddw m1, m5
mova [dstq+32*0], m0
pmulhrsw m0, m6, m2
mova [dstq+32*1], m1
pmulhrsw m1, m7, m2
paddw m0, m5
paddw m1, m5
mova [dstq+32*2], m0
mova [dstq+32*3], m1
add dstq, strideq
sub hq, 1*2
jg .w64_loop
RET
%macro SMOOTH_2D_END 6 ; src[1-2], mul[1-2], add[1-2]
pmaddwd m0, m%1, m%3
pmaddwd m1, m%2, m%4
paddd m0, m%5
paddd m1, m%6
psrld m0, 8
psrld m1, 8
packssdw m0, m1
pavgw m0, m5
%endmacro
cglobal ipred_smooth_16bpc, 3, 7, 6, dst, stride, tl, w, h, v_weights
%define base r6-ipred_smooth_16bpc_avx2_table
lea r6, [ipred_smooth_16bpc_avx2_table]
mov wd, wm
vpbroadcastw m4, [tlq+wq*2] ; right
tzcnt wd, wd
mov hd, hm
sub tlq, hq
sub tlq, hq
movsxd wq, [r6+wq*4]
pxor m5, m5
add wq, r6
lea v_weightsq, [base+smooth_weights_2d_16bpc+hq*4]
jmp wq
.w4:
WIN64_SPILL_XMM 11
vpbroadcastw m0, [tlq] ; bottom
vpbroadcastq m6, [tlq+hq*2+2]
movsldup m7, [base+ipred_hv_shuf]
movshdup m9, [base+ipred_hv_shuf]
vbroadcasti128 m10, [base+smooth_weights_2d_16bpc+4*4]
punpcklwd m6, m0 ; top, bottom
punpcklqdq m8, m9, m9
punpckhqdq m9, m9
lea r3, [strideq*3]
.w4_loop:
vpbroadcastq m3, [tlq+hq*2-8]
vbroadcasti128 m1, [v_weightsq]
pshufb m3, m7
punpcklwd m2, m3, m4 ; left, right
punpckhwd m3, m4
pmaddwd m2, m10
pmaddwd m3, m10
pshufb m0, m1, m8
pshufb m1, m9
SMOOTH_2D_END 0, 1, 6, 6, 2, 3
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm1
movhps [dstq+strideq*2], xm0
movhps [dstq+r3 ], xm1
lea dstq, [dstq+strideq*4]
add v_weightsq, 16
sub hd, 4
jg .w4_loop
RET
.w8:
WIN64_SPILL_XMM 12
vpbroadcastw m0, [tlq] ; bottom
vbroadcasti128 m7, [tlq+hq*2+2]
movsldup m8, [base+ipred_hv_shuf]
movshdup m9, [base+ipred_hv_shuf]
vbroadcasti128 m10, [base+smooth_weights_2d_16bpc+8*4+16*0]
vbroadcasti128 m11, [base+smooth_weights_2d_16bpc+8*4+16*1]
punpcklwd m6, m7, m0 ; top, bottom
punpckhwd m7, m0
.w8_loop:
vpbroadcastd m3, [tlq+hq*2-4]
vpbroadcastq m1, [v_weightsq]
pshufb m3, m8
punpcklwd m2, m3, m4 ; left, right
punpckhwd m3, m4
pmaddwd m2, m10
pmaddwd m3, m11
pshufb m1, m9
SMOOTH_2D_END 1, 1, 6, 7, 2, 3
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
lea dstq, [dstq+strideq*2]
add v_weightsq, 8
sub hd, 2
jg .w8_loop
RET
.w16:
WIN64_SPILL_XMM 11
vpbroadcastw m0, [tlq] ; bottom
movu m7, [tlq+hq*2+2]
mova xm8, [base+smooth_weights_2d_16bpc+16*4+16*0]
mova xm9, [base+smooth_weights_2d_16bpc+16*4+16*1]
vinserti128 m8, [base+smooth_weights_2d_16bpc+16*4+16*2], 1
vinserti128 m9, [base+smooth_weights_2d_16bpc+16*4+16*3], 1
punpcklwd m6, m7, m0 ; top, bottom
punpckhwd m7, m0
.w16_loop:
vpbroadcastd m3, [tlq+hq*2-4]
vpbroadcastd m1, [v_weightsq+0]
punpcklwd m3, m4 ; left, right
pshufd m2, m3, q1111
pmaddwd m10, m8, m2
pmaddwd m2, m9
pshufd m3, m3, q0000
SMOOTH_2D_END 1, 1, 6, 7, 10, 2
vpbroadcastd m1, [v_weightsq+4]
pmaddwd m2, m8, m3
pmaddwd m3, m9
mova [dstq+strideq*0], m0
SMOOTH_2D_END 1, 1, 6, 7, 2, 3
mova [dstq+strideq*1], m0
lea dstq, [dstq+strideq*2]
add v_weightsq, 8
sub hq, 2
jg .w16_loop
RET
.w32:
WIN64_SPILL_XMM 15
vpbroadcastw m0, [tlq] ; bottom
movu m7, [tlq+hq*2+ 2]
movu m9, [tlq+hq*2+34]
mova xm10, [base+smooth_weights_2d_16bpc+32*4+16*0]
mova xm11, [base+smooth_weights_2d_16bpc+32*4+16*1]
vinserti128 m10, [base+smooth_weights_2d_16bpc+32*4+16*2], 1
vinserti128 m11, [base+smooth_weights_2d_16bpc+32*4+16*3], 1
mova xm12, [base+smooth_weights_2d_16bpc+32*4+16*4]
mova xm13, [base+smooth_weights_2d_16bpc+32*4+16*5]
vinserti128 m12, [base+smooth_weights_2d_16bpc+32*4+16*6], 1
vinserti128 m13, [base+smooth_weights_2d_16bpc+32*4+16*7], 1
punpcklwd m6, m7, m0
punpckhwd m7, m0
punpcklwd m8, m9, m0
punpckhwd m9, m0
.w32_loop:
vpbroadcastw m3, [tlq+hq*2-2]
vpbroadcastd m14, [v_weightsq]
punpcklwd m3, m4
pmaddwd m1, m10, m3
pmaddwd m2, m11, m3
pmaddwd m0, m6, m14
paddd m0, m1
pmaddwd m1, m7, m14
paddd m1, m2
pmaddwd m2, m12, m3
pmaddwd m3, m13
psrld m0, 8
psrld m1, 8
packssdw m0, m1
pavgw m0, m5
mova [dstq+32*0], m0
SMOOTH_2D_END 14, 14, 8, 9, 2, 3
mova [dstq+32*1], m0
add dstq, strideq
add v_weightsq, 4
dec hd
jg .w32_loop
RET
.w64:
PROLOGUE 0, 11, 16, dst, stride, tl, tl_base, h, v_weights, dummy, v_weights_base, x, y, dst_base
mov dst_baseq, dstq
mov tl_baseq, tlq
mov v_weights_baseq, v_weightsq
xor xq, xq
.w64_loop_x:
mov yq, hq
lea tlq, [tl_baseq+hq*2]
vpbroadcastw m0, [tl_baseq] ; bottom
movu m7, [tlq+xq*2+ 2]
movu m9, [tlq+xq*2+34]
mova xm10, [base+smooth_weights_2d_16bpc+64*4+16*0]
mova xm11, [base+smooth_weights_2d_16bpc+64*4+16*1]
vinserti128 m10, [base+smooth_weights_2d_16bpc+64*4+16*2], 1
vinserti128 m11, [base+smooth_weights_2d_16bpc+64*4+16*3], 1
mova xm12, [base+smooth_weights_2d_16bpc+64*4+16*4]
mova xm13, [base+smooth_weights_2d_16bpc+64*4+16*5]
vinserti128 m12, [base+smooth_weights_2d_16bpc+64*4+16*6], 1
vinserti128 m13, [base+smooth_weights_2d_16bpc+64*4+16*7], 1
punpcklwd m6, m7, m0
punpckhwd m7, m0
punpcklwd m8, m9, m0
punpckhwd m9, m0
lea tlq, [tl_baseq-2]
.w64_loop_y:
vpbroadcastw m3, [tlq+yq*2]
vpbroadcastd m1, [v_weightsq]
punpcklwd m3, m4
pmaddwd m14, m10, m3
pmaddwd m15, m11, m3
pmaddwd m2, m12, m3
pmaddwd m3, m13
pmaddwd m0, m6, m1
paddd m0, m14
pmaddwd m14, m7, m1
paddd m14, m15
psrld m0, 8
psrld m14, 8
packssdw m0, m14
pavgw m0, m5
mova [dstq+32*0], m0
SMOOTH_2D_END 8, 9, 1, 1, 2, 3
mova [dstq+32*1], m0
add dstq, strideq
add v_weightsq, 4
dec yq
jg .w64_loop_y
lea dstq, [dst_baseq+32*2]
add r6, 16*8
mov v_weightsq, v_weights_baseq
add xq, 32
test xb, 64
jz .w64_loop_x
RET
cglobal ipred_z1_16bpc, 3, 8, 0, dst, stride, tl, w, h, angle, dx, maxbase
lea r6, [ipred_z1_16bpc_avx2_table]
tzcnt wd, wm
movifnidn angled, anglem
movifnidn hd, hm
lea r7, [dr_intra_derivative]
movsxd wq, [r6+wq*4]
add tlq, 2
add wq, r6
mov dxd, angled
and dxd, 0x7e
add angled, 165 ; ~90
movzx dxd, word [r7+dxq]
xor angled, 0x4ff ; d = 90 - angle
vpbroadcastd m5, [pw_62]
jmp wq
.w4:
ALLOC_STACK -64, 7
cmp angleb, 40
jae .w4_no_upsample
lea r3d, [angleq-1024]
sar r3d, 7
add r3d, hd
jg .w4_no_upsample ; !enable_intra_edge_filter || h > 8 || (h == 8 && is_sm)
vpbroadcastw xm3, [tlq+14]
movu xm1, [tlq+ 0] ; 1 2 3 4 5 6 7 8
palignr xm0, xm3, xm1, 4 ; 3 4 5 6 7 8 8 8
paddw xm0, [tlq- 2] ; 0 1 2 3 4 5 6 7
add dxd, dxd
palignr xm2, xm3, xm1, 2 ; 2 3 4 5 6 7 8 8
paddw xm2, xm1 ; -1 * a + 9 * b + 9 * c + -1 * d
psubw xm0, xm2, xm0 ; = (b + c - a - d + (b + c) << 3 + 8) >> 4
psraw xm0, 3 ; = ((b + c - a - d) >> 3 + b + c + 1) >> 1
pxor xm4, xm4
paddw xm2, xm0
vpbroadcastw xm0, r8m ; pixel_max
mova [rsp+32], xm3
movd xm3, dxd
pmaxsw xm2, xm4
mov r3d, dxd
pavgw xm2, xm4
vpbroadcastw m3, xm3
pminsw xm2, xm0
punpcklwd xm0, xm1, xm2
punpckhwd xm1, xm2
lea r5, [strideq*3]
pslldq m2, m3, 8
mova [rsp+ 0], xm0
mova [rsp+16], xm1
paddw m6, m3, m3
paddw m3, m2
vpblendd m4, m6, 0xf0
paddw m6, m6
paddw m3, m4 ; xpos0 xpos1 xpos2 xpos3
vbroadcasti128 m4, [z_upsample]
.w4_upsample_loop:
lea r2d, [r3+dxq]
shr r3d, 6 ; base0
movu xm1, [rsp+r3*2]
lea r3d, [r2+dxq]
shr r2d, 6 ; base1
movu xm2, [rsp+r2*2]
lea r2d, [r3+dxq]
shr r3d, 6 ; base2
vinserti128 m1, [rsp+r3*2], 1 ; 0 2
lea r3d, [r2+dxq]
shr r2d, 6 ; base3
vinserti128 m2, [rsp+r2*2], 1 ; 1 3
pshufb m1, m4
pshufb m2, m4
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
pand m2, m5, m3 ; 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 m3, m6 ; xpos += dx
paddw m0, m1
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r5 ], xm1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4_upsample_loop
RET
ALIGN function_align
.filter_strength: ; w4/w8/w16
%define base r3-z_filter_t0
movd xm0, maxbased
lea r3, [z_filter_t0]
movd xm1, angled
shr angled, 8 ; is_sm << 1
vpbroadcastb m0, xm0
vpbroadcastb m1, xm1
pcmpeqb m0, [base+z_filter_wh]
mova xm2, [r3+angleq*8]
pand m0, m1
pcmpgtb m0, m2
pmovmskb r5d, m0
ret
.w4_no_upsample:
mov maxbased, 7
test angled, 0x400 ; !enable_intra_edge_filter
jnz .w4_main
lea maxbased, [hq+3]
call .filter_strength
mov maxbased, 7
test r5d, r5d
jz .w4_main ; filter_strength == 0
popcnt r5d, r5d
vpbroadcastw xm3, [tlq+14]
mova xm0, [tlq- 2] ; 0 1 2 3 4 5 6 7
vpbroadcastd xm1, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd xm4, [base+z_filter_k-4+r5*4+12*0]
palignr xm2, xm3, xm0, 4 ; 2 3 4 5 6 7 8 8
pmullw xm1, [tlq+ 0] ; 1 2 3 4 5 6 7 8
paddw xm2, xm0
pmullw xm2, xm4
movd [rsp+16], xm3
cmp r5d, 3
jne .w4_3tap
paddw xm1, xm2
palignr xm2, xm3, xm0, 6 ; 3 4 5 6 7 8 8 8
pblendw xm0, [tlq-4], 0xfe ; 0 0 1 2 3 4 5 6
movzx r3d, word [tlq+14]
movzx r2d, word [tlq+12]
inc maxbased
paddw xm2, xm0
sub r2d, r3d
paddw xm2, xm2
lea r2d, [r2+r3*8+4]
shr r2d, 3 ; (1 * top[6] + 7 * top[7] + 4) >> 3
mov [rsp+16], r2w
.w4_3tap:
pxor xm0, xm0
paddw xm1, xm2
mov tlq, rsp
psrlw xm1, 3
cmp hd, 8
sbb maxbased, -1
pavgw xm0, xm1
mova [tlq], xm0
.w4_main:
movd xm3, dxd
vpbroadcastq m1, [z_base_inc]
vpbroadcastw m6, [tlq+maxbaseq*2] ; top[max_base_x]
shl maxbased, 6
vpbroadcastw m3, xm3
movd xm0, maxbased
mov r3d, dxd ; xpos
vpbroadcastw m0, xm0
paddw m4, m3, m3
psubw m1, m0 ; -max_base_x
vpblendd m3, m4, 0xcc
paddw m0, m4, m3
vpblendd m3, m0, 0xf0 ; xpos0 xpos1 xpos2 xpos3
paddw m4, m4
paddw m3, m1
.w4_loop:
lea r5d, [r3+dxq]
shr r3d, 6 ; base0
movu xm1, [tlq+r3*2]
lea r3d, [r5+dxq]
shr r5d, 6 ; base1
movu xm2, [tlq+r5*2]
lea r5d, [r3+dxq]
shr r3d, 6 ; base2
vinserti128 m1, [tlq+r3*2], 1 ; 0 2
lea r3d, [r5+dxq]
shr r5d, 6 ; base3
vinserti128 m2, [tlq+r5*2], 1 ; 1 3
punpcklqdq m0, m1, m2
psrldq m1, 2
pslldq m2, 6
vpblendd m1, m2, 0xcc
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m3, 15 ; xpos < max_base_x
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
lea dstq, [dstq+strideq*2]
movq [dstq+strideq*0], xm1
movhps [dstq+strideq*1], xm1
sub hd, 4
jz .w4_end
lea dstq, [dstq+strideq*2]
cmp r3d, maxbased
jb .w4_loop
lea r6, [strideq*3]
.w4_end_loop:
movq [dstq+strideq*0], xm6
movq [dstq+strideq*1], xm6
movq [dstq+strideq*2], xm6
movq [dstq+r6 ], xm6
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4_end_loop
.w4_end:
RET
.w8:
ALLOC_STACK -64, 7
lea r3d, [angleq+216]
mov r3b, hb
cmp r3d, 8
ja .w8_no_upsample ; !enable_intra_edge_filter || is_sm || d >= 40 || h > 8
movu m2, [tlq+2] ; 2 3 4 5 6 7 8 9 a b c d e f g _
movu m0, [tlq+4] ; 3 4 5 6 7 8 9 a b c d e f g _ _
movu m1, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
cmp hd, 4
jne .w8_upsample_h8 ; awkward single-pixel edge case
vpblendd m0, m2, 0x20 ; 3 4 5 6 7 8 9 a b c c _ _ _ _ _
.w8_upsample_h8:
paddw m2, m1
paddw m0, [tlq-2] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
add dxd, dxd
psubw m0, m2, m0
psraw m0, 3
pxor m4, m4
paddw m2, m0
vpbroadcastw m0, r8m
movd xm3, dxd
pmaxsw m2, m4
mov r3d, dxd
pavgw m2, m4
vpbroadcastw m3, xm3
pminsw m2, m0
punpcklwd m0, m1, m2
punpckhwd m1, m2
vbroadcasti128 m4, [z_upsample]
mova [rsp+ 0], xm0
mova [rsp+16], xm1
paddw m6, m3, m3
vextracti128 [rsp+32], m0, 1
vextracti128 [rsp+48], m1, 1
vpblendd m3, m6, 0xf0 ; xpos0 xpos1
.w8_upsample_loop:
lea r2d, [r3+dxq]
shr r3d, 6 ; base0
movu xm1, [rsp+r3*2]
movu xm2, [rsp+r3*2+16]
lea r3d, [r2+dxq]
shr r2d, 6 ; base1
vinserti128 m1, [rsp+r2*2], 1
vinserti128 m2, [rsp+r2*2+16], 1
pshufb m1, m4
pshufb m2, m4
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m3, m6
paddw m0, m1
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w8_upsample_loop
RET
.w8_no_intra_edge_filter:
and maxbased, 7
or maxbased, 8 ; imin(h+7, 15)
jmp .w8_main
.w8_no_upsample:
lea maxbased, [hq+7]
test angled, 0x400
jnz .w8_no_intra_edge_filter
call .filter_strength
test r5d, r5d
jz .w8_main
popcnt r5d, r5d
vpbroadcastd m1, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd m4, [base+z_filter_k-4+r5*4+12*0]
mova m0, [tlq-2] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
movu m2, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pmullw m1, m2
cmp hd, 8
jl .w8_filter_h4
punpckhwd m2, m2
vpblendd m3, m2, [tlq+2], 0x7f ; 2 3 4 5 6 7 8 9 a b c d e f g g
je .w8_filter_end ; 8x4 and 8x8 are always 3-tap
movzx r3d, word [tlq+30]
mov maxbased, 16
mov [rsp+32], r3d
cmp r5d, 3
jne .w8_filter_end
punpcklwd xm6, xm0, xm0
vpblendd m2, [tlq+4], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g g g
vpblendd m6, [tlq-4], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
movzx r5d, word [tlq+28]
mov [rsp+34], r3w
paddw m2, m6
sub r5d, r3d
inc maxbased
paddw m2, m2
lea r3d, [r5+r3*8+4]
paddw m1, m2
shr r3d, 3
mov [rsp+32], r3w
jmp .w8_filter_end
.w8_filter_h4:
pshuflw m3, m2, q3321
vinserti128 m3, [tlq+2], 0 ; 2 3 4 5 6 7 8 9 a b c c _ _ _ _
.w8_filter_end:
paddw m0, m3
pmullw m0, m4
mov tlq, rsp
pxor m2, m2
paddw m0, m1
psrlw m0, 3
pavgw m0, m2
mova [tlq], m0
.w8_main:
movd xm3, dxd
vbroadcasti128 m1, [z_base_inc]
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m3, xm3
movd xm0, maxbased
mov r3d, dxd
vpbroadcastw m0, xm0
paddw m4, m3, m3
psubw m1, m0
vpblendd m3, m4, 0xf0 ; xpos0 xpos1
paddw m3, m1
.w8_loop:
lea r5d, [r3+dxq]
shr r3d, 6
movu xm0, [tlq+r3*2]
movu xm1, [tlq+r3*2+2]
lea r3d, [r5+dxq]
shr r5d, 6
vinserti128 m0, [tlq+r5*2], 1
vinserti128 m1, [tlq+r5*2+2], 1
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m3, 15
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
sub hd, 2
jz .w8_end
lea dstq, [dstq+strideq*2]
cmp r3d, maxbased
jb .w8_loop
.w8_end_loop:
mova [dstq+strideq*0], xm6
mova [dstq+strideq*1], xm6
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w8_end_loop
.w8_end:
RET
.w16_no_intra_edge_filter:
and maxbased, 15
or maxbased, 16 ; imin(h+15, 31)
jmp .w16_main
.w16:
ALLOC_STACK -96, 7
lea maxbased, [hq+15]
test angled, 0x400
jnz .w16_no_intra_edge_filter
call .filter_strength
test r5d, r5d
jz .w16_main
popcnt r5d, r5d
mova m0, [tlq-2] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m1, m0, [tlq+2] ; 2 3 4 5 6 7 8 9 a b c d e f g h
cmp r5d, 3
jne .w16_filter_3tap
vpbroadcastd m2, [base+pw_3]
punpcklwd xm0, xm0
vpblendd m0, [tlq-4], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
paddw m1, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
paddw m0, m2
pavgw m0, [tlq+4] ; 3 4 5 6 7 8 9 a b c d e f g h i
paddw m0, m1
psrlw m0, 2
movu m3, [tlq+32] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m2, [tlq+28] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m1, m3, [tlq+30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
cmp hd, 8
jl .w16_filter_5tap_h4
punpckhwd m3, m3
je .w16_filter_5tap_h8
vpblendd m4, m3, [tlq+36], 0x7f ; 4 5 6 7 8 9 a b c d e f g h h h
vpblendd m3, [tlq+34], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g h h
movzx r3d, word [tlq+62]
movzx r2d, word [tlq+60]
pavgw m2, m4
sub r2d, r3d
paddw m1, m3
lea r2d, [r2+r3*8+4]
paddw m1, m2
shr r2d, 3
psrlw m1, 2
mov [rsp+66], r3w
mov [rsp+64], r2w
mov tlq, rsp
mov r3d, 33
cmp hd, 16
cmovg maxbased, r3d
jmp .w16_filter_end2
.w16_filter_5tap_h8:
vpblendd xm4, xm3, [tlq+36], 0x07 ; 4 5 6 7 8 9 9 9
vpblendd xm3, [tlq+34], 0x07 ; 3 4 5 6 7 8 9 9
pavgw xm2, xm4
paddw xm1, xm3
paddw xm1, xm2
psrlw xm1, 2
jmp .w16_filter_end2
.w16_filter_5tap_h4:
pshuflw xm4, xm3, q3332 ; 4 5 5 5
pshuflw xm3, xm3, q3321 ; 3 4 5 5
pavgw xm2, xm4
paddw xm1, xm3
paddw xm1, xm2
psrlw xm1, 2
jmp .w16_filter_end2
.w16_filter_3tap:
vpbroadcastd m3, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd m4, [base+z_filter_k-4+r5*4+12*0]
pmullw m0, m3, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
movu m2, [tlq+32] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pmullw m1, m4
pmullw m3, m2
paddw m0, m1
cmp hd, 8
je .w16_filter_3tap_h8
jl .w16_filter_3tap_h4
punpckhwd m2, m2
vpblendd m2, [tlq+34], 0x7f ; 2 3 4 5 6 7 8 9 a b c d e f g g
jmp .w16_filter_end
.w16_filter_3tap_h4:
pshuflw xm2, xm2, q3321 ; 2 3 4 4 _ _ _ _
jmp .w16_filter_end
.w16_filter_3tap_h8:
psrldq xm2, 2
pshufhw xm2, xm2, q2210 ; 2 3 4 5 6 7 8 8
.w16_filter_end:
paddw m2, [tlq+30] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
pmullw m2, m4
psrlw m0, 3
pxor m1, m1
paddw m2, m3
psrlw m2, 3
pavgw m0, m1
pavgw m1, m2
.w16_filter_end2:
mov tlq, rsp
mova [tlq+ 0], m0
mova [tlq+32], m1
.w16_main:
movd xm4, dxd
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m4, xm4
movd xm0, maxbased
mov r3d, dxd
vpbroadcastw m0, xm0
paddw m3, m4, [z_base_inc]
psubw m3, m0
.w16_loop:
lea r5d, [r3+dxq]
shr r3d, 6
movu m0, [tlq+r3*2]
movu m1, [tlq+r3*2+2]
lea r3d, [r5+dxq]
shr r5d, 6
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m3, 15
paddw m3, m4
paddw m1, m0
movu m0, [tlq+r5*2]
vpblendvb m2, m6, m1, m2
movu m1, [tlq+r5*2+2]
mova [dstq+strideq*0], m2
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m3, 15
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
mova [dstq+strideq*1], m0
sub hd, 2
jz .w16_end
lea dstq, [dstq+strideq*2]
cmp r3d, maxbased
jb .w16_loop
.w16_end_loop:
mova [dstq+strideq*0], m6
mova [dstq+strideq*1], m6
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w16_end_loop
.w16_end:
RET
.w32:
ALLOC_STACK -160, 8
lea maxbased, [hq+31]
mov r3d, 63
cmp hd, 32
cmova maxbased, r3d
test angled, 0x400
jnz .w32_main
vpbroadcastd m2, [pw_3]
mova m0, [tlq-2] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
punpcklwd xm1, xm0, xm0
vpblendd m1, [tlq-4], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
paddw m0, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
paddw m1, m2
paddw m0, [tlq+2] ; 2 3 4 5 6 7 8 9 a b c d e f g h
pavgw m1, [tlq+4] ; 3 4 5 6 7 8 9 a b c d e f g h i
mov r3, rsp
paddw m0, m1
lea r5d, [maxbaseq-31]
psrlw m0, 2
mova [r3], m0
.w32_filter_loop:
mova m0, [tlq+30]
paddw m1, m2, [tlq+28]
add tlq, 32
paddw m0, [tlq+0]
pavgw m1, [tlq+4]
paddw m0, [tlq+2]
add r3, 32
paddw m0, m1
psrlw m0, 2
mova [r3], m0
sub r5d, 16
jg .w32_filter_loop
movu m0, [tlq+32] ; 2 3 4 5 6 7 8 9 a b c d e f g h
punpckhwd m1, m0, m0
paddw m2, [tlq+28] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m0, [tlq+30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
jl .w32_filter_h8
vpblendd m3, m1, [tlq+36], 0x7f ; 4 5 6 7 8 9 a b c d e f g h h h
vpblendd m1, [tlq+34], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g h h
movzx r5d, word [tlq+62]
movzx r2d, word [tlq+60]
pavgw m2, m3
sub r2d, r5d
paddw m0, m1
lea r2d, [r2+r5*8+4]
paddw m0, m2
shr r2d, 3
psrlw m0, 2
mova [r3+32], m0
mov [r3+66], r5w
mov [r3+64], r2w
mov tlq, rsp
mov r3d, 65
cmp hd, 64
cmove maxbased, r3d
jmp .w32_main
.w32_filter_h8:
vpblendd xm3, xm1, [tlq+36], 0x07 ; 4 5 6 7 8 9 9 9
vpblendd xm1, [tlq+34], 0x07 ; 3 4 5 6 7 8 9 9
pavgw xm2, xm3
paddw xm0, xm1
mov tlq, rsp
paddw xm0, xm2
psrlw xm0, 2
mova [r3+32], xm0
.w32_main:
movd xm4, dxd
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m4, xm4
movd xm0, maxbased
mov r5d, dxd
vpbroadcastd m7, [pw_m1024] ; -16 * 64
vpbroadcastw m0, xm0
paddw m3, m4, [z_base_inc]
psubw m3, m0
.w32_loop:
mov r3d, r5d
shr r3d, 6
movu m0, [tlq+r3*2]
movu m1, [tlq+r3*2+2]
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
psraw m1, m3, 15
vpblendvb m0, m6, m0, m1
mova [dstq+32*0], m0
movu m0, [tlq+r3*2+32]
movu m1, [tlq+r3*2+34]
add r5d, dxd
psubw m1, m0
pmulhrsw m1, m2
pcmpgtw m2, m7, m3
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
mova [dstq+32*1], m0
dec hd
jz .w32_end
add dstq, strideq
cmp r5d, maxbased
jb .w32_loop
.w32_end_loop:
mova [dstq+32*0], m6
mova [dstq+32*1], m6
add dstq, strideq
dec hd
jg .w32_end_loop
.w32_end:
RET
.w64:
ALLOC_STACK -256, 10
lea maxbased, [hq+63]
test angled, 0x400
jnz .w64_main
vpbroadcastd m2, [pw_3]
mova m0, [tlq-2] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
punpcklwd xm1, xm0, xm0
vpblendd m1, [tlq-4], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
paddw m0, [tlq+0] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
paddw m1, m2
paddw m0, [tlq+2] ; 2 3 4 5 6 7 8 9 a b c d e f g h
pavgw m1, [tlq+4] ; 3 4 5 6 7 8 9 a b c d e f g h i
mov r3, rsp
paddw m0, m1
lea r5d, [hq+32]
psrlw m0, 2
mova [r3], m0
.w64_filter_loop:
mova m0, [tlq+30]
paddw m1, m2, [tlq+28]
add tlq, 32
paddw m0, [tlq+0]
pavgw m1, [tlq+4]
paddw m0, [tlq+2]
add r3, 32
paddw m0, m1
psrlw m0, 2
mova [r3], m0
sub r5d, 16
jg .w64_filter_loop
movu m0, [tlq+32] ; 2 3 4 5 6 7 8 9 a b c d e f g h
punpckhwd m1, m0, m0
paddw m2, [tlq+28] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m0, [tlq+30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpblendd m3, m1, [tlq+36], 0x7f ; 4 5 6 7 8 9 a b c d e f g h h h
vpblendd m1, [tlq+34], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g h h
pavgw m2, m3
paddw m0, m1
paddw m0, m2
mov tlq, rsp
psrlw m0, 2
mova [r3+32], m0
.w64_main:
movd xm4, dxd
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m4, xm4
movd xm0, maxbased
mov r5d, dxd
vpbroadcastd m7, [pw_m1024] ; -16 * 64
vpbroadcastw m0, xm0
paddw m3, m4, [z_base_inc]
paddw m8, m7, m7 ; -32 * 64
psubw m3, m0
paddw m9, m8, m7 ; -48 * 64
.w64_loop:
mov r3d, r5d
shr r3d, 6
movu m0, [tlq+r3*2]
movu m1, [tlq+r3*2+2]
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
psraw m1, m3, 15
vpblendvb m0, m6, m0, m1
mova [dstq+32*0], m0
movu m0, [tlq+r3*2+32]
movu m1, [tlq+r3*2+34]
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
pcmpgtw m1, m7, m3
vpblendvb m0, m6, m0, m1
mova [dstq+32*1], m0
movu m0, [tlq+r3*2+64]
movu m1, [tlq+r3*2+66]
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
pcmpgtw m1, m8, m3
vpblendvb m0, m6, m0, m1
mova [dstq+32*2], m0
movu m0, [tlq+r3*2+96]
movu m1, [tlq+r3*2+98]
add r5d, dxd
psubw m1, m0
pmulhrsw m1, m2
pcmpgtw m2, m9, m3
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
mova [dstq+32*3], m0
dec hd
jz .w64_end
add dstq, strideq
cmp r5d, maxbased
jb .w64_loop
.w64_end_loop:
mova [dstq+32*0], m6
mova [dstq+32*1], m6
mova [dstq+32*2], m6
mova [dstq+32*3], m6
add dstq, strideq
dec hd
jg .w64_end_loop
.w64_end:
RET
cglobal ipred_z2_16bpc, 3, 12, 12, 352, dst, stride, tl, w, h, angle, dx, dy
%define base r9-z_filter_t0
lea r9, [ipred_z2_16bpc_avx2_table]
tzcnt wd, wm
movifnidn angled, anglem
movifnidn hd, hm
lea dxq, [dr_intra_derivative-90]
movsxd wq, [r9+wq*4]
mova m1, [tlq- 0]
movzx dyd, angleb
xor angled, 0x400
mova m2, [tlq- 32]
mov r8, dxq
sub dxq, dyq
mova m3, [tlq- 64]
add wq, r9
add r9, z_filter_t0-ipred_z2_16bpc_avx2_table
mova m4, [tlq- 96]
and dyd, ~1
mova m5, [tlq-128]
and dxq, ~1
movzx dyd, word [r8+dyq] ; angle - 90
movzx dxd, word [dxq+270] ; 180 - angle
vpbroadcastd m11, [base+pw_62]
mova [rsp+128], m1
mova [rsp+ 96], m2
mova [rsp+ 64], m3
neg dxd
mova [rsp+ 32], m4
neg dyq
mova [rsp+ 0], m5
jmp wq
.w4:
vbroadcasti128 m10, [base+z2_x_shuf]
vpbroadcastq m6, [base+z_base_inc+2]
lea r8d, [dxq+(65<<6)] ; xpos
mov r10d, (63-4)<<6
test angled, 0x400
jnz .w4_main ; !enable_intra_edge_filter
lea r3d, [hq+2]
add angled, 1022
shl r3d, 6
test r3d, angled
jnz .w4_no_upsample_above ; angle >= 130 || h > 8 || (is_sm && h == 8)
movq xm0, [tlq+2] ; 1 2 3 4
movq xm1, [tlq+0] ; 0 1 2 3
pshuflw xm2, xm0, q3321 ; 2 3 4 4
pshuflw xm3, xm1, q2100 ; 0 0 1 2
vpbroadcastw xm4, r8m ; pixel_max
vbroadcasti128 m10, [base+z_upsample]
paddw xm1, xm0
paddw xm2, xm3
lea r8d, [r8+dxq+(1<<6)]
psubw xm2, xm1, xm2
add dxd, dxd
psraw xm2, 3
pxor xm3, xm3
sub r10d, 3<<6
paddw xm1, xm2
paddw m6, m6
pmaxsw xm1, xm3
sub angled, 1075 ; angle - 53
pavgw xm1, xm3
lea r3d, [hq+3]
pminsw xm1, xm4
xor angled, 0x7f ; 180 - angle
punpcklwd xm1, xm0
movu [rsp+130], xm1
call .filter_strength
jmp .w4_filter_left
ALIGN function_align
.filter_strength:
movd xm8, r3d
mov r3d, angled
movd xm7, angled
vpbroadcastb m8, xm8
shr r3d, 8 ; is_sm << 1
vpbroadcastb m7, xm7
pcmpeqb m8, [base+z_filter_wh]
mova xm9, [r9+r3*8]
pand m0, m8, m7
pcmpgtb m0, m9
pmovmskb r3d, m0
ret
ALIGN function_align
.upsample_left: ; h4/h8
mova xm0, [tlq-16] ; 8 7 6 5 4 3 2 1
movu xm1, [tlq-14] ; 7 6 5 4 3 2 1 0
vpbroadcastw xm4, r8m ; pixel_max
cmp hd, 8
je .upsample_left_h8
pshufhw xm2, xm0, q2100 ; _ _ _ _ 4 4 3 2
pshufhw xm3, xm1, q3321 ; _ _ _ _ 2 1 0 0
jmp .upsample_left_end
.upsample_left_h8:
pblendw xm2, xm0, [tlq-18], 0xfe ; 8 8 7 6 5 4 3 2
pblendw xm3, xm1, [tlq-12], 0x7f ; 6 5 4 3 2 1 0 0
.upsample_left_end:
paddw xm1, xm0
paddw xm2, xm3
psubw xm2, xm1, xm2
add dyq, dyq
psraw xm2, 3
pxor xm3, xm3
paddw xm1, xm2
pmaxsw xm1, xm3
pavgw xm1, xm3
pminsw xm1, xm4
punpcklwd xm2, xm0, xm1
punpckhwd xm0, xm1
mova [rsp+ 96+gprsize], xm2
mova [rsp+112+gprsize], xm0
ret
.w4_no_upsample_above:
lea r3d, [hq+3]
sub angled, 1112 ; angle - 90
call .filter_strength
test r3d, r3d
jz .w4_no_filter_above
popcnt r3d, r3d
vpbroadcastd xm4, [base+z_filter_k-4+r3*4+12*1]
vpbroadcastd xm5, [base+z_filter_k-4+r3*4+12*0]
psrldq xm0, xm1, 2 ; 1 2 3 4
pshuflw xm2, xm1, q2100 ; 0 0 1 2
pmullw xm4, xm0
pshuflw xm3, xm0, q3321 ; 2 3 4 4
paddw xm1, xm3
pshuflw xm3, xm0, q3332 ; 3 4 4 4
pmullw xm1, xm5
vpbroadcastd xm5, [base+z_filter_k-4+r3*4+12*2]
paddw xm2, xm3
vpbroadcastd xm3, r6m ; max_width
pmullw xm2, xm5
packssdw xm3, xm3
paddw xm1, xm4
paddw xm1, xm2
psubw xm3, [base+pw_1to16]
pxor xm4, xm4
psrlw xm1, 3
pminsw xm3, xm11 ; clip to byte range since there's no variable word blend
pavgw xm1, xm4
vpblendvb xm1, xm0, xm3
movq [rsp+130], xm1
.w4_no_filter_above:
lea r3d, [hq+2]
add angled, 973 ; angle + 883
shl r3d, 6
test r3d, angled
jz .w4_upsample_left ; angle <= 140 || h > 8 || (is_sm && h == 8)
vpbroadcastd xm0, [base+pb_90]
psubb xm0, xm7 ; 180 - angle
pand xm0, xm8 ; reuse from previous filter_strength call
pcmpgtb xm0, xm9
pmovmskb r3d, xm0
.w4_filter_left:
test r3d, r3d
jz .w4_main
popcnt r3d, r3d
mova m0, [tlq-32] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
vpbroadcastd m5, r7m ; max_height
cmp r3d, 3
je .w4_filter_left_s3
vpbroadcastd m2, [base+z_filter_k-4+r3*4+12*1]
vpbroadcastd m3, [base+z_filter_k-4+r3*4+12*0]
pmullw m2, m0
cmp hd, 8
jl .w4_filter_left_h4
movu m4, [tlq-34]
punpcklwd m1, m0, m0
vpblendd m1, m4, 0xee ; 0 0 1 2 3 4 5 6 8 8 9 a b c d e
je .w4_filter_left_end
vpblendd m1, m4, 0x10 ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
jmp .w4_filter_left_end
.w4_upsample_left:
call .upsample_left
mov r11, -16
vbroadcasti128 m9, [base+z_upsample]
jmp .w4_main_upsample_left
.w4_filter_left_s3: ; can only be h16
movu m2, [tlq-30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpbroadcastd m4, [base+pw_3]
paddw m1, m0, m2
punpckhwd m2, m2
vpblendd m2, [tlq-28], 0x7f ; 2 3 4 5 6 7 8 9 a b c d e f g g
punpcklwd xm3, xm0, xm0
paddw m2, m4
vpblendd m4, m3, [tlq-34], 0xfe ; 0 0 1 2 3 4 5 6 8 8 9 a b c d e
vpblendd m3, [tlq-36], 0xfe ; 0 0 0 1 2 3 4 5 6 8 8 9 a b c d
paddw m1, m4
pavgw m2, m3
paddw m1, m2
psrlw m1, 2
jmp .w4_filter_left_end2
.w4_filter_left_h4:
pshufhw m1, m0, q2100 ; _ _ _ _ _ _ _ _ _ _ _ _ c c d e
.w4_filter_left_end:
paddw m1, [tlq-30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pmullw m1, m3
paddw m1, m2
pxor m2, m2
psrlw m1, 3
pavgw m1, m2
.w4_filter_left_end2:
packssdw m5, m5
psubw m5, [base+pw_16to1]
pminsw m5, m11
vpblendvb m1, m0, m5
mova [rsp+96], m1
.w4_main:
vbroadcasti128 m9, [base+z2_x_shuf]
mov r11, -8
.w4_main_upsample_left:
movd xm5, dyd
mova m4, [base+z2_y_shuf_h4]
mov r2d, r8d
movd xm0, dxd
vpbroadcastw m5, xm5
rorx r5, dyq, 5
lea r8d, [dyq*3]
pmullw m5, [base+z2_ymul]
rorx r9, dyq, 4
sar dyd, 6
vpbroadcastw m0, xm0
sar r8d, 6
pand m5, m11 ; frac_y
neg dyd
psllw m5, 9
add r5d, dyd
add r8d, dyd
add r9d, dyd
paddw m7, m0, m0
lea dyq, [rsp+dyq*2+126]
vpblendd m0, m7, 0xcc
add dyq, r11
neg r5d
paddw m1, m0, m7
neg r8d
vpblendd m0, m1, 0xf0 ; xpos0 xpos1 xpos2 xpos3
neg r9d
paddw m7, m7
paddw m6, m0
.w4_loop:
lea r3d, [r2+dxq]
shr r2d, 6 ; base_x0
movu xm1, [rsp+r2*2]
lea r2d, [r3+dxq]
shr r3d, 6 ; base_x1
movu xm3, [rsp+r3*2]
lea r3d, [r2+dxq]
shr r2d, 6 ; base_x2
vinserti128 m1, [rsp+r2*2], 1
lea r2d, [r3+dxq]
shr r3d, 6 ; base_x3
vinserti128 m3, [rsp+r3*2], 1
pshufb m1, m10 ; a0 a1 a2 a3 A0 A1 A2 A3
pshufb m3, m10 ; b0 b1 b2 b3 B0 B1 B2 B3
pand m2, m11, m6
punpcklqdq m0, m1, m3
punpckhqdq m1, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
cmp r3d, 64
jge .w4_toponly
movu xm2, [dyq]
vinserti128 m2, [dyq+r8*2], 1
movu xm3, [dyq+r5*2]
vinserti128 m3, [dyq+r9*2], 1
pshufb m2, m9
pshufb m3, m9
punpckhwd m1, m2, m3 ; a3 b3 a2 b2 a1 b1 a0 b0
punpcklwd m2, m3
psubw m2, m1
pmulhrsw m2, m5
psraw m3, m6, 15 ; base_x < topleft
paddw m1, m2
vpermd m1, m4, m1 ; a0 b0 c0 d0 a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3
vpblendvb m0, m1, m3
.w4_toponly:
paddw m6, m7 ; xpos += dx
lea r3, [strideq*3]
add dyq, r11
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r3 ], xm1
sub hd, 4
jz .w4_end
lea dstq, [dstq+strideq*4]
cmp r2d, r10d
jge .w4_loop
.w4_leftonly_loop:
movu xm1, [dyq]
vinserti128 m1, [dyq+r8*2], 1
movu xm2, [dyq+r5*2]
vinserti128 m2, [dyq+r9*2], 1
add dyq, r11
pshufb m1, m9
pshufb m2, m9
punpckhwd m0, m1, m2
punpcklwd m1, m2
psubw m1, m0
pmulhrsw m1, m5
paddw m0, m1
vpermd m0, m4, m0
vextracti128 xm1, m0, 1
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r3 ], xm1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4_leftonly_loop
.w4_end:
RET
.w8:
mov r10d, hd
test angled, 0x400
jnz .w8_main
lea r3d, [angleq+126]
xor r8d, r8d
mov r3b, hb
cmp r3d, 8
ja .w8_no_upsample_above ; angle >= 130 || h > 8 || is_sm
movu xm0, [tlq+2] ; 1 2 3 4 5 6 7 8
mova xm1, [tlq+0] ; 0 1 2 3 4 5 6 7
pblendw xm2, xm0, [tlq+4], 0x7f ; 2 3 4 5 6 7 8 8
pblendw xm3, xm1, [tlq-2], 0xfe ; 0 0 1 2 3 4 5 6
vpbroadcastw xm4, r8m ; pixel_max
paddw xm1, xm0
paddw xm2, xm3
not r8d
psubw xm2, xm1, xm2
add dxd, dxd
psraw xm2, 3
sub angled, 53 ; angle - 53
pxor xm3, xm3
paddw xm2, xm1
lea r3d, [hq+7]
pmaxsw xm2, xm3
xor angled, 0x7f ; 180 - angle
pavgw xm2, xm3
pminsw xm2, xm4
punpcklwd xm1, xm2, xm0
punpckhwd xm2, xm0
movu [rsp+130], xm1
movu [rsp+146], xm2
call .filter_strength
jmp .w8_filter_left
.w8_no_upsample_above:
lea r3d, [hq+7]
sub angled, 90 ; angle - 90
call .filter_strength
test r3d, r3d
jz .w8_no_filter_above
popcnt r3d, r3d
vpbroadcastd xm4, [base+z_filter_k-4+r3*4+12*1]
vpbroadcastd xm5, [base+z_filter_k-4+r3*4+12*0]
vpbroadcastd xm6, [base+z_filter_k-4+r3*4+12*2]
movu xm0, [tlq+2] ; 1 2 3 4 5 6 7 8 x
pblendw xm2, xm1, [tlq-2], 0xfe ; 0 0 1 2 3 4 5 6 x
pmullw xm4, xm0
pblendw xm3, xm0, [tlq+4], 0x7f ; 2 3 4 5 6 7 8 8 x
paddw xm1, xm3
vpblendd xm3, [tlq+6], 0x07 ; 3 4 5 6 7 8 8 8 x
paddw xm2, xm3
vpbroadcastd xm3, r6m ; max_width
pmullw xm1, xm5
pmullw xm2, xm6
packssdw xm3, xm3
paddw xm1, xm4
paddw xm1, xm2
psubw xm3, [base+pw_1to16]
pxor xm4, xm4
psrlw xm1, 3
pminsw xm3, xm11
pavgw xm1, xm4
vpblendvb xm1, xm0, xm3
movu [rsp+130], xm1
.w8_no_filter_above:
lea r3d, [angleq-51]
mov r3b, hb
cmp r3d, 8
jbe .w8_upsample_left ; angle > 140 && h <= 8 && !is_sm
vpbroadcastd m0, [base+pb_90]
psubb m0, m7
pand m0, m8
pcmpgtb m0, m9
pmovmskb r3d, m0
.w8_filter_left:
test r3d, r3d
jz .w8_main
popcnt r3d, r3d
cmp r3d, 3
jne .w8_filter_left_s12
vpbroadcastd m6, [base+pw_3]
vpbroadcastd m7, [base+pw_16]
cmp hd, 16 ; flags needed for later
jmp .filter_left_s3b
.w8_upsample_left:
call .upsample_left
vbroadcasti128 m7, [base+z2_y_shuf_us]
lea r11, [rsp+118]
mov r8, -8
jmp .w8_main_upsample_left
.w16_filter_left_s12:
xor r8d, r8d
.w8_filter_left_s12:
mova m0, [tlq-32] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
vpbroadcastd m5, r7m ; max_height
vpbroadcastd m2, [base+z_filter_k-4+r3*4+12*1]
vpbroadcastd m3, [base+z_filter_k-4+r3*4+12*0]
pmullw m2, m0
cmp hd, 8
jl .w8_filter_left_h4
movu m4, [tlq-34]
punpcklwd m1, m0, m0
vpblendd m1, m4, 0xee ; 0 0 1 2 3 4 5 6 8 8 9 a b c d e
je .w8_filter_left_end
vpblendd m1, m4, 0x10 ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
jmp .w8_filter_left_end
.w8_filter_left_h4:
pshufhw m1, m0, q2100 ; _ _ _ _ _ _ _ _ _ _ _ _ c c d e
.w8_filter_left_end:
paddw m1, [tlq-30] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pmullw m1, m3
paddw m1, m2
pxor m2, m2
psrlw m1, 3
pavgw m1, m2
packssdw m5, m5
psubw m5, [base+pw_16to1]
pminsw m5, m11
vpblendvb m1, m0, m5
mova [rsp+96], m1
test r8d, r8d
jz .w8_main
; upsample_main
vbroadcasti128 m10, [base+z_upsample]
vbroadcasti128 m7, [base+z2_y_shuf]
lea r5, [rsp+120]
movd xm1, dyd
vbroadcasti128 m4, [base+z_base_inc+2]
movd xm2, dxd
vpbroadcastw m1, xm1
vpbroadcastw m2, xm2
mov r7, dstq
paddw m4, m4
pmullw m0, m1, [base+z2_ymul8]
paddw m5, m2, m2
psllw xm1, 3
vpblendd m2, m5, 0xf0
lea r2d, [dxq+(66<<6)] ; xpos
paddw m4, m2
pshufd m6, m0, q2020
psraw xm0, 6
pxor xm1, xm1
psubw xm8, xm1, xm0
pand m6, m11
punpckhwd xm9, xm8, xm1
psllw m6, 9
punpcklwd xm8, xm1
.w8_upsample_above_loop:
lea r3d, [r2+dxq]
shr r2d, 6
movu xm1, [rsp+r2*2]
movu xm2, [rsp+r2*2+16]
lea r2d, [r3+dxq]
shr r3d, 6
vinserti128 m1, [rsp+r3*2], 1
vinserti128 m2, [rsp+r3*2+16], 1
pshufb m1, m10
pshufb m2, m10
punpcklqdq m0, m1, m2 ; a0 b0 c0 d0 e0 f0 g0 h0
punpckhqdq m1, m2
pand m2, m11, m4
psubw m1, m0
psllw m2, 9
pmulhrsw m1, m2
paddw m0, m1
cmp r3d, 64
jge .w8_upsample_above_toponly
mova m1, m5
vpgatherdq m3, [r5+xm9*2], m5
mova m5, m1
vpgatherdq m2, [r5+xm8*2], m1
pshufb m3, m7
pshufb m2, m7
punpckldq m1, m2, m3
punpckhdq m2, m3
psubw m2, m1
pmulhrsw m2, m6
paddw m1, m2
vpermq m1, m1, q3120
psraw m2, m4, 15
vpblendvb m0, m1, m2
.w8_upsample_above_toponly:
paddw m4, m5
sub r5, 4
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
sub hd, 2
jz .w8_ret
lea dstq, [dstq+strideq*2]
jmp .w8_upsample_above_loop
.w8_main:
vbroadcasti128 m7, [base+z2_y_shuf]
lea r11, [rsp+120]
mov r8, -4
.w8_main_upsample_left:
movd xm1, dyd
vbroadcasti128 m4, [base+z_base_inc+2]
movd xm2, dxd
vpbroadcastw m1, xm1
vpbroadcastw m2, xm2
mov r7, dstq
pmullw m0, m1, [base+z2_ymul8]
paddw m5, m2, m2
psllw xm1, 3
vpblendd m2, m5, 0xf0 ; xpos0 xpos1
lea r9d, [dxq+(65<<6)] ; xpos
paddw m4, m2
movd [rsp+284], xm1
.w8_loop0:
mov r2d, r9d
mova [rsp+288], m0
mov r5, r11
mova [rsp+320], m4
pshufd m6, m0, q2020
psraw xm0, 6
pxor xm1, xm1
psubw xm8, xm1, xm0 ; base_y
pand m6, m11 ; frac_y
punpckhwd xm9, xm8, xm1 ; base_y 2 3 6 7
psllw m6, 9
punpcklwd xm8, xm1 ; base_y 0 1 4 5
.w8_loop:
lea r3d, [r2+dxq]
shr r2d, 6 ; base_x0
movu xm0, [rsp+r2*2]
movu xm1, [rsp+r2*2+2]
lea r2d, [r3+dxq]
shr r3d, 6 ; base_x1
vinserti128 m0, [rsp+r3*2], 1
vinserti128 m1, [rsp+r3*2+2], 1
pand m2, m11, m4
psubw m1, m0
psllw m2, 9
pmulhrsw m1, m2
paddw m0, m1
cmp r3d, 64
jge .w8_toponly
mova m1, m5
vpgatherdq m3, [r5+xm9*2], m5
mova m5, m1
vpgatherdq m2, [r5+xm8*2], m1
pshufb m3, m7 ; c0 d0 c1 d1 g0 h0 g1 h1
pshufb m2, m7 ; a0 b0 a1 b1 e0 f0 e1 f1
punpckldq m1, m2, m3 ; a0 b0 c0 d0 a1 b1 c1 d1 e0 f0 g0 h0 e1 f1 g1 h1
punpckhdq m2, m3
psubw m2, m1
pmulhrsw m2, m6
paddw m1, m2
vpermq m1, m1, q3120
psraw m2, m4, 15 ; base_x < topleft
vpblendvb m0, m1, m2
.w8_toponly:
paddw m4, m5 ; xpos += dx
add r5, r8
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
sub hd, 2
jz .w8_end
lea dstq, [dstq+strideq*2]
cmp r2d, (63-8)<<6
jge .w8_loop
.w8_leftonly_loop:
mova m0, m5
vpgatherdq m4, [r5+xm9*2], m5
mova m5, m0
vpgatherdq m3, [r5+xm8*2], m0
add r5, r8
pshufb m2, m4, m7
pshufb m1, m3, m7
punpckldq m0, m1, m2
punpckhdq m1, m2
psubw m1, m0
pmulhrsw m1, m6
paddw m0, m1
vpermq m0, m0, q3120
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w8_leftonly_loop
.w8_end:
sub r10d, 1<<8
jl .w8_ret
vpbroadcastd m0, [rsp+284]
add r7, 16
paddw m0, [rsp+288] ; base_y += 8*dy
add r9d, 8<<6
vpbroadcastd m4, [pw_512]
movzx hd, r10b
paddw m4, [rsp+320] ; base_x += 8*64
mov dstq, r7
jmp .w8_loop0
.w8_ret:
RET
.w16:
movd xm0, [tlq+32]
lea r10d, [hq+(1<<8)]
movd [rsp+160], xm0
test angled, 0x400
jnz .w8_main
lea r3d, [hq+15]
sub angled, 90
call .filter_strength
test r3d, r3d
jz .w16_no_filter_above
popcnt r3d, r3d
vpbroadcastd m4, [base+z_filter_k-4+r3*4+12*1]
vpbroadcastd m5, [base+z_filter_k-4+r3*4+12*0]
vpbroadcastd m6, [base+z_filter_k-4+r3*4+12*2]
movu m0, [tlq+2] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
punpcklwd xm2, xm1, xm1
vpblendd m2, [tlq-2], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
punpckhwd m3, m0, m0
pmullw m4, m0
vpblendd m3, [tlq+4], 0x7f ; 2 3 4 5 6 7 8 9 a b c d e f g g
paddw m1, m3
vpblendd m3, [tlq+6], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g g g
paddw m2, m3
vpbroadcastd m3, r6m ; max_width
pmullw m1, m5
pmullw m2, m6
packssdw m3, m3
paddw m1, m4
paddw m1, m2
psubw m3, [base+pw_1to16]
pxor m4, m4
psrlw m1, 3
pminsw m3, m11
pavgw m1, m4
vpblendvb m1, m0, m3
movu [rsp+130], m1
.w16_no_filter_above:
vpbroadcastd m0, [base+pb_90]
psubb m0, m7
pand m0, m8
pcmpgtb m0, m9
pmovmskb r3d, m0
test r3d, r3d
jz .w8_main
popcnt r3d, r3d
cmp r3d, 3
jne .w16_filter_left_s12
vpbroadcastd m6, [base+pw_3]
vpbroadcastd m7, [base+pw_16]
cmp hd, 4
jne .filter_left_s3
movq xm0, [tlq-8] ; 0 1 2 3
movq xm1, [tlq-6] ; 1 2 3 4
vpbroadcastd xm5, r7m ; max_height
movq xm4, [base+pw_16to1+24] ; 4to1
pshuflw xm2, xm0, q2100 ; 0 0 1 2
pshuflw xm3, xm1, q3321 ; 2 3 4 4
paddw xm1, xm0
paddw xm1, xm2
pshuflw xm2, xm0, q1000 ; 0 0 0 1
paddw xm3, xm6
packssdw xm5, xm5
pavgw xm2, xm3
psubw xm5, xm4
paddw xm1, xm2
pminsw xm5, xm11
psrlw xm1, 2
vpblendvb xm1, xm0, xm5
movq [rsp+120], xm1
jmp .w8_main
.w32:
mova m2, [tlq+32]
movd xm0, [tlq+64]
lea r10d, [hq+(3<<8)]
mova [rsp+160], m2
movd [rsp+192], xm0
test angled, 0x400
jnz .w8_main
vpbroadcastd m6, [base+pw_3]
vpbroadcastd m0, r6m ; max_width
vpbroadcastd m7, [base+pw_16]
mov r3d, 32
packssdw m0, m0
psubw m0, [base+pw_1to16]
pminsw m8, m0, m11
psubw m9, m8, m7
.w32_filter_above:
movu m0, [tlq+2]
punpcklwd xm4, xm1, xm1
paddw m2, m6, [tlq+6]
paddw m1, m0
vpblendd m4, [tlq-2], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
paddw m1, [tlq+4]
movu m3, [tlq+r3+2]
paddw m5, m6, [tlq+r3-2]
pavgw m2, m4
punpckhwd m4, m3, m3
paddw m1, m2
vpblendd m2, m4, [tlq+r3+6], 0x7f ; 4 5 6 7 8 9 a b c d e f g h h h
vpblendd m4, [tlq+r3+4], 0x7f ; 3 4 5 6 7 8 9 a b c d e f g h h
pavgw m2, m5
paddw m5, m3, [tlq+r3]
paddw m4, m5
psrlw m1, 2
paddw m2, m4
vpblendvb m1, m0, m8
psrlw m2, 2
vpblendvb m2, m3, m9
movu [rsp+130], m1
movu [rsp+r3+130], m2
.filter_left_s3:
cmp hd, 16
jl .filter_left_s3_h8 ; h8
.filter_left_s3b:
mova m0, [tlq-32] ; 2 3 4 5 6 7 8 9 a b c d e f g h
movu m2, [tlq-30] ; 3 4 5 6 7 8 9 a b c d e f g h i
vpbroadcastd m5, r7m ; max_height
paddw m1, m0, m2
punpckhwd m2, m2
mov r3d, hd
vpblendd m2, [tlq-28], 0x7f ; 4 5 6 7 8 9 a b c d e f g h i i
packssdw m5, m5
not r3
psubw m5, [base+pw_16to1]
paddw m2, m6
pminsw m8, m11, m5
je .filter_left_s3_end ; h16
paddw m1, [tlq-34] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pavgw m2, [tlq-36] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m1, m2
psrlw m1, 2
vpblendvb m3, m1, m0, m8
mova m0, [tlq-64] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m1, m0, [tlq-62] ; 3 4 5 6 7 8 9 a b c d e f g h i
paddw m2, m6, [tlq-60] ; 4 5 6 7 8 9 a b c d e f g h i j
psubw m8, m7
mova [rsp+96], m3
jnp .filter_left_s3_end ; h32
mova m5, [tlq-96]
paddw m1, [tlq-66]
pavgw m2, [tlq-68]
paddw m1, m2
paddw m4, m5, [tlq-94]
paddw m2, m6, [tlq-92]
psrlw m1, 2
paddw m4, [tlq- 98]
pavgw m2, [tlq-100]
vpblendvb m3, m1, m0, m8
mova m0, [tlq-128]
psubw m8, m7
paddw m4, m2
paddw m1, m0, [tlq-126]
paddw m2, m6, [tlq-124]
psrlw m4, 2
mova [rsp+64], m3
vpblendvb m4, m5, m8
psubw m8, m7
mova [rsp+32], m4
.filter_left_s3_end:
punpcklwd xm3, xm0, xm0
vpblendd m4, m3, [tlq+r3*2], 0xfe ; 2 2 3 4 5 6 7 8 9 a b c d e f g
vpblendd m3, [tlq+r3*2-2], 0xfe ; 2 2 2 3 4 5 6 7 8 9 a b c d e f
paddw m1, m4
pavgw m2, m3
paddw m1, m2
psrlw m1, 2
vpblendvb m1, m0, m8
mova [rsp+r3*2+130], m1
jmp .w8_main
.filter_left_s3_h8:
mova xm0, [tlq-16] ; 0 1 2 3 4 5 6 7
movu xm3, [tlq-14] ; 1 2 3 4 5 6 7 8
pblendw xm2, xm0, [tlq-18], 0xfe ; 0 0 1 2 3 4 5 6
vpbroadcastd xm5, r7m ; max_height
paddw xm1, xm0, xm3
pblendw xm3, [tlq-12], 0x7f ; 2 3 4 5 6 7 8 8
paddw xm1, xm2
vpblendd xm2, [tlq-20], 0x0e ; 0 0 0 1 2 3 4 5
paddw xm3, xm6
packssdw xm5, xm5
pavgw xm2, xm3
psubw xm5, [base+pw_16to1+16] ; 8to1
paddw xm1, xm2
pminsw xm5, xm11
psrlw xm1, 2
vpblendvb xm1, xm0, xm5
mova [rsp+112], xm1
jmp .w8_main
.w64:
mova m2, [tlq+ 32]
mova m3, [tlq+ 64]
mova m4, [tlq+ 96]
movd xm0, [tlq+128]
lea r10d, [hq+(7<<8)]
mova [rsp+160], m2
mova [rsp+192], m3
mova [rsp+224], m4
movd [rsp+256], xm0
test angled, 0x400
jnz .w8_main
vpbroadcastd m6, [base+pw_3]
movu m0, [tlq+34] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m2, m6, [tlq+30] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m5, m0, [tlq+32] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pavgw m2, [tlq+38] ; 4 5 6 7 8 9 a b c d e f g h h h
paddw m5, [tlq+36] ; 3 4 5 6 7 8 9 a b c d e f g h h
movu m4, [tlq+66]
paddw m3, m6, [tlq+62]
paddw m7, m4, [tlq+64]
pavgw m3, [tlq+70]
paddw m7, [tlq+68]
paddw m2, m5
vpbroadcastd m5, r6m ; max_width
mov r3d, 96
packssdw m5, m5
paddw m3, m7
psubw m5, [base+pw_1to16]
psrlw m2, 2
vpbroadcastd m7, [base+pw_16]
psrlw m3, 2
pminsw m8, m11, m5
psubw m9, m8, m7
vpblendvb m2, m0, m9
psubw m9, m7
vpblendvb m3, m4, m9
psubw m9, m7
movu [rsp+162], m2
movu [rsp+194], m3
jmp .w32_filter_above
cglobal ipred_z3_16bpc, 4, 9, 0, dst, stride, tl, w, h, angle, dy, org_w, maxbase
lea r6, [ipred_z3_16bpc_avx2_table]
tzcnt hd, hm
movifnidn angled, anglem
lea r7, [dr_intra_derivative+45*2-1]
sub tlq, 2
movsxd hq, [r6+hq*4]
sub angled, 180
add hq, r6
mov dyd, angled
neg dyd
xor angled, 0x400
or dyq, ~0x7e
movzx dyd, word [r7+dyq]
vpbroadcastd m5, [pw_62]
mov org_wd, wd
jmp hq
.h4:
ALLOC_STACK -64, 7
lea r7, [strideq*3]
cmp angleb, 40
jae .h4_no_upsample
lea r4d, [angleq-1024]
sar r4d, 7
add r4d, wd
jg .h4_no_upsample ; !enable_intra_edge_filter || w > 8 || (w == 8 && is_sm)
mova xm2, [tlq-14] ; 0 1 2 3 4 5 6 7
pblendw xm1, xm2, [tlq-16], 0xfe ; 0 0 1 2 3 4 5 6
vpblendd xm0, xm1, [tlq-18], 0x0e ; 0 0 0 1 2 3 4 5
pshufd xm3, xm1, q0000
paddw xm1, xm2
paddw xm0, [tlq-12] ; 1 2 3 4 5 6 7 8
vpbroadcastw xm4, r8m ; pixel_max
add dyd, dyd
psubw xm0, xm1, xm0
mova [rsp+ 0], xm3
movd xm3, dyd
psraw xm0, 3
neg dyd
paddw xm1, xm0
pxor xm0, xm0
lea r2d, [dyq+(16<<6)+63] ; ypos
pmaxsw xm1, xm0
pavgw xm1, xm0
vpbroadcastw m3, xm3
pminsw xm1, xm4
punpckhwd xm0, xm1, xm2
punpcklwd xm1, xm2
paddw m2, m3, m3
mova [rsp+32], xm0
punpcklwd m3, m2
mova [rsp+16], xm1
paddw m4, m2, m2
paddw m2, m3
vpblendd m3, m2, 0xf0 ; ypos0 ypos1 ypos2 ypos3
.h4_upsample_loop:
lea r4d, [r2+dyq]
shr r2d, 6
movu xm1, [rsp+r2*2]
lea r2d, [r4+dyq]
shr r4d, 6
movu xm2, [rsp+r4*2]
lea r4d, [r2+dyq]
shr r2d, 6
vinserti128 m1, [rsp+r2*2], 1
lea r2d, [r4+dyq]
shr r4d, 6
vinserti128 m2, [rsp+r4*2], 1
psrld m0, m1, 16
pblendw m0, m2, 0xaa ; a3 b3 a2 b2 a1 b1 a0 b0 c3 d3 c2 d2 c1 d1 c0 d0
pslld m2, 16
pblendw m1, m2, 0xaa
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
paddw m3, m4
paddw m1, m0
vextracti128 xm2, m1, 1
punpckhdq xm0, xm1, xm2 ; a1 b1 c1 d1 a0 b0 c0 d0
punpckldq xm1, xm2 ; a3 b3 c3 d3 a2 b2 c2 d2
movhps [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm0
movhps [dstq+strideq*2], xm1
movq [dstq+r7 ], xm1
add dstq, 8
sub wd, 4
jg .h4_upsample_loop
RET
ALIGN function_align
.filter_strength: ; h4/h8/h16
%define base r4-z_filter_t0
lea r4, [z_filter_t0]
movd xm0, maxbased
movd xm1, angled
shr angled, 8 ; is_sm << 1
vpbroadcastb m0, xm0
vpbroadcastb m1, xm1
pcmpeqb m0, [base+z_filter_wh]
pand m0, m1
mova xm1, [r4+angleq*8]
pcmpgtb m0, m1
pmovmskb r5d, m0
ret
.h4_no_upsample:
mov maxbased, 7
test angled, 0x400 ; !enable_intra_edge_filter
jnz .h4_main
lea maxbased, [wq+3]
call .filter_strength
mov maxbased, 7
test r5d, r5d
jz .h4_main ; filter_strength == 0
popcnt r5d, r5d
mova xm0, [tlq-14] ; 0 1 2 3 4 5 6 7
movu xm3, [tlq-12] ; 1 2 3 4 5 6 7 8
vpbroadcastd xm2, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd xm4, [base+z_filter_k-4+r5*4+12*0]
pmullw xm2, xm0
pblendw xm0, [tlq-16], 0xfe ; 0 0 1 2 3 4 5 6
paddw xm1, xm0, xm3
movd [rsp+12], xm0
pmullw xm1, xm4
cmp r5d, 3
jne .h4_filter_3tap
pblendw xm3, [tlq-10], 0x7f ; 2 3 4 5 6 7 8 8
vpblendd xm0, [tlq-18], 0x0e ; 0 0 0 1 2 3 4 5
movzx r4d, word [tlq-14]
movzx r2d, word [tlq-12]
inc maxbased
paddw xm1, xm2
paddw xm0, xm3
sub r2d, r4d
paddw xm2, xm0, xm0
lea r2d, [r2+r4*8+4]
shr r2d, 3
mov [rsp+14], r2w
.h4_filter_3tap:
pxor xm0, xm0
paddw xm1, xm2
lea tlq, [rsp+30]
psrlw xm1, 3
cmp wd, 8
sbb maxbased, -1
pavgw xm0, xm1
mova [rsp+16], xm0
.h4_main:
movd xm3, dyd
neg maxbaseq
vbroadcasti128 m1, [z_base_inc]
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m3, xm3
lea r4d, [maxbaseq+3*64]
neg dyq
movd xm2, r4d
sub tlq, 8
lea r4, [dyq+63] ; ypos
punpcklwd m1, m1
paddw m0, m3, m3
vpbroadcastw m2, xm2
punpcklwd m3, m0
paddw m4, m0, m0
paddw m0, m3
psubw m2, m1
vpblendd m3, m0, 0xf0 ; ypos0 ypos1 ypos2 ypos3
or maxbased, 63
paddw m3, m2
.h4_loop:
lea r5, [r4+dyq]
sar r4, 6 ; base0
movu xm1, [tlq+r4*2]
lea r4, [r5+dyq]
sar r5, 6 ; base1
movu xm2, [tlq+r5*2]
lea r5, [r4+dyq]
sar r4, 6 ; base2
vinserti128 m1, [tlq+r4*2], 1
lea r4, [r5+dyq]
sar r5, 6 ; base3
vinserti128 m2, [tlq+r5*2], 1
punpckhwd m0, m1, m2
punpcklwd m1, m2
pand m2, m5, m3
palignr m0, m1, 4 ; a3 b3 a2 b2 a1 b1 a0 b0 c3 d3 c2 d2 c1 d1 c0 d0
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
psraw m2, m3, 15 ; ypos < max_base_y
paddw m3, m4
paddw m1, m0
vpblendvb m1, m6, m1, m2
vextracti128 xm2, m1, 1
punpckhdq xm0, xm1, xm2 ; a1 b1 c1 d1 a0 b0 c0 d0
punpckldq xm1, xm2 ; a3 b3 c3 d3 a2 b2 c2 d2
movhps [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm0
movhps [dstq+strideq*2], xm1
movq [dstq+r7 ], xm1
sub wd, 4
jz .h4_end
add dstq, 8
cmp r4d, maxbased
jg .h4_loop
.h4_end_loop:
movq [dstq+strideq*0], xm6
movq [dstq+strideq*1], xm6
movq [dstq+strideq*2], xm6
movq [dstq+r7 ], xm6
add dstq, 8
sub wd, 4
jg .h4_end_loop
.h4_end:
RET
.h8:
lea r4d, [angleq+216]
ALLOC_STACK -64, 8
mov r4b, wb
lea r7, [strideq*3]
cmp r4d, 8
ja .h8_no_upsample ; !enable_intra_edge_filter || is_sm || d >= 40 || w > 8
mova m2, [tlq-30] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw m1, m2, [tlq-32] ; _ 0 1 2 3 4 5 6 7 8 9 a b c d e
movu m0, [tlq-34] ; _ _ 0 1 2 3 4 5 6 7 8 9 a b c d
cmp wd, 8
je .h8_upsample_w8
pshufhw xm3, xm2, q1000
vpblendd m0, m3, 0x0f ; _ _ _ _ 4 4 4 5 6 7 8 9 a b c d
.h8_upsample_w8:
paddw m0, [tlq-28] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpbroadcastw m4, r8m ; pixel_max
add dyd, dyd
psubw m0, m1, m0
movd xm6, dyd
psraw m0, 3
neg dyd
paddw m1, m0
pxor m0, m0
pmaxsw m1, m0
lea r4d, [dyq+(16<<6)+63] ; ypos
pavgw m1, m0
vpbroadcastw m6, xm6
pminsw m1, m4
punpckhwd m0, m1, m2
punpcklwd m1, m2
vextracti128 [rsp+48], m0, 1
vextracti128 [rsp+32], m1, 1
paddw m7, m6, m6
mova [rsp+16], xm0
mova [rsp+ 0], xm1
punpcklwd m6, m7 ; ypos0 ypos1
.h8_upsample_loop:
lea r2d, [r4+dyq]
shr r4d, 6 ; base0
movu m1, [rsp+r4*2]
lea r4d, [r2+dyq]
shr r2d, 6 ; base1
movu m2, [rsp+r2*2]
lea r2d, [r4+dyq]
shr r4d, 6 ; base2
movu m3, [rsp+r4*2]
lea r4d, [r2+dyq]
shr r2d, 6 ; base3
movu m4, [rsp+r2*2]
psrld m0, m1, 16
pblendw m0, m2, 0xaa ; a7 b7 a6 b6 a5 b5 a4 b4 a3 b3 a2 b2 a1 b1 a0 b0
pslld m2, 16
pblendw m1, m2, 0xaa
psrld m2, m3, 16
pblendw m2, m4, 0xaa ; c7 d7 c6 d6 c5 d5 c4 d4 c3 d3 c2 d2 c1 d1 c0 d0
pslld m4, 16
pblendw m3, m4, 0xaa
pand m4, m5, m6
paddw m6, m7
psllw m4, 9
psubw m1, m0
pmulhrsw m1, m4
pand m4, m5, m6
psllw m4, 9
psubw m3, m2
pmulhrsw m3, m4
paddw m6, m7
lea r2, [dstq+strideq*4]
paddw m1, m0
paddw m3, m2
punpckhdq m0, m1, m3 ; a5 b5 c5 d5 a4 b4 c4 d4 a1 b1 c1 d1 a0 b0 c0 d0
punpckldq m1, m3 ; a7 b7 c7 d7 a6 b6 c6 d6 a3 b3 c3 d3 a2 b2 c2 d2
vextracti128 xm2, m0, 1
vextracti128 xm3, m1, 1
movhps [r2 +strideq*0], xm0
movq [r2 +strideq*1], xm0
movhps [r2 +strideq*2], xm1
movq [r2 +r7 ], xm1
movhps [dstq+strideq*0], xm2
movq [dstq+strideq*1], xm2
movhps [dstq+strideq*2], xm3
movq [dstq+r7 ], xm3
add dstq, 8
sub wd, 4
jg .h8_upsample_loop
RET
.h8_no_intra_edge_filter:
and maxbased, 7
or maxbased, 8 ; imin(w+7, 15)
jmp .h8_main
.h8_no_upsample:
lea maxbased, [wq+7]
test angled, 0x400
jnz .h8_no_intra_edge_filter
call .filter_strength
test r5d, r5d
jz .h8_main
popcnt r5d, r5d
mova m0, [tlq-30] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
movu m3, [tlq-28] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpbroadcastd m2, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd m4, [base+z_filter_k-4+r5*4+12*0]
pmullw m2, m0
cmp wd, 8
jl .h8_filter_w4
punpcklwd xm0, xm0
vpblendd m1, m0, [tlq-32], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
movd [rsp+28], xm0
paddw m1, m3
mov r4d, 16
pmullw m1, m4
cmovg maxbased, r4d
cmp r5d, 3
jne .h8_filter_3tap
punpckhwd m3, m3
vpblendd m0, [tlq-34], 0xfe ; 0 0 0 1 2 3 4 5 6 7 8 9 a b c d
vpblendd m3, [tlq-26], 0x7f ; 2 3 4 5 6 7 8 9 a b c d e f g g
movzx r4d, word [tlq-30]
movzx r2d, word [tlq-28]
inc maxbased
paddw m1, m2
paddw m0, m3
sub r2d, r4d
paddw m2, m0, m0
lea r2d, [r2+r4*8+4]
shr r2d, 3
mov [rsp+30], r2w
jmp .h8_filter_3tap
.h8_filter_w4:
pshufhw xm1, xm0, q2100
vinserti128 m1, [tlq-16], 1 ; _ _ _ _ 4 4 5 6 7 8 9 a b c d e
paddw m1, m3
pmullw m1, m4
.h8_filter_3tap:
pxor m0, m0
paddw m1, m2
lea tlq, [rsp+62]
psrlw m1, 3
pavgw m0, m1
mova [rsp+32], m0
.h8_main:
movd xm4, dyd
neg maxbaseq
vbroadcasti128 m1, [z_base_inc]
vpbroadcastw m7, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m4, xm4
lea r4d, [maxbaseq+7*64]
neg dyq
movd xm2, r4d
sub tlq, 16
lea r4, [dyq+63]
paddw m6, m4, m4
vpbroadcastw m2, xm2
vpblendd m4, m6, 0xf0 ; ypos0 ypos1
psubw m2, m1
or maxbased, 63
paddw m4, m2
.h8_loop:
lea r5, [r4+dyq]
sar r4, 6 ; base0
movu xm0, [tlq+r4*2+2]
movu xm1, [tlq+r4*2]
lea r4, [r5+dyq]
sar r5, 6 ; base1
vinserti128 m0, [tlq+r5*2+2], 1
vinserti128 m1, [tlq+r5*2], 1
lea r5, [r4+dyq]
sar r4, 6 ; base2
pand m3, m5, m4
psllw m3, 9
psubw m1, m0
pmulhrsw m1, m3
psraw m3, m4, 15
paddw m4, m6
paddw m0, m1
movu xm1, [tlq+r4*2+2]
movu xm2, [tlq+r4*2]
lea r4, [r5+dyq]
sar r5, 6 ; base3
vpblendvb m0, m7, m0, m3
vinserti128 m1, [tlq+r5*2+2], 1
vinserti128 m2, [tlq+r5*2], 1
pand m3, m5, m4
psllw m3, 9
psubw m2, m1
pmulhrsw m2, m3
psraw m3, m4, 15
paddw m4, m6
lea r5, [dstq+strideq*4]
paddw m1, m2
vpblendvb m1, m7, m1, m3
punpckhwd m2, m0, m1 ; a3 c3 a2 c2 a1 c1 a0 c0 b3 d3 b2 d2 b1 d1 b0 d0
vextracti128 xm3, m2, 1
punpcklwd m0, m1 ; a7 c7 a6 c6 a5 c5 a4 c5 b7 d7 b6 d6 b5 d5 b4 d4
punpckhwd xm1, xm2, xm3 ; a1 b1 c1 d1 a0 b0 c0 d0
punpcklwd xm2, xm3 ; a3 b3 c3 d3 a2 b2 c2 d2
vextracti128 xm3, m0, 1
movhps [dstq+strideq*0], xm1
movq [dstq+strideq*1], xm1
movhps [dstq+strideq*2], xm2
movq [dstq+r7 ], xm2
punpckhwd xm1, xm0, xm3 ; a5 b5 c5 d5 a4 b4 c4 d4
punpcklwd xm0, xm3 ; a7 b7 c7 d7 a6 b6 c6 d6
movhps [r5 +strideq*0], xm1
movq [r5 +strideq*1], xm1
movhps [r5 +strideq*2], xm0
movq [r5 +r7 ], xm0
sub wd, 4
jz .h8_end
add dstq, 8
cmp r4d, maxbased
jg .h8_loop
lea r6, [strideq*5]
lea r2, [strideq+r7*2] ; stride*7
test wd, 4
jz .h8_end_loop
movq [dstq+strideq*0], xm7
movq [dstq+strideq*1], xm7
movq [dstq+strideq*2], xm7
movq [dstq+r7 ], xm7
movq [dstq+strideq*4], xm7
movq [dstq+r6 ], xm7
movq [dstq+r7*2 ], xm7
movq [dstq+r2 ], xm7
add dstq, 8
sub wd, 4
jz .h8_end
.h8_end_loop:
mova [dstq+strideq*0], xm7
mova [dstq+strideq*1], xm7
mova [dstq+strideq*2], xm7
mova [dstq+r7 ], xm7
mova [dstq+strideq*4], xm7
mova [dstq+r6 ], xm7
mova [dstq+r7*2 ], xm7
mova [dstq+r2 ], xm7
add dstq, 16
sub wd, 8
jg .h8_end_loop
.h8_end:
RET
.h16_no_intra_edge_filter:
and maxbased, 15
or maxbased, 16 ; imin(w+15, 31)
jmp .h16_main
ALIGN function_align
.h16:
ALLOC_STACK -96, 10
lea maxbased, [wq+15]
lea r7, [strideq*3]
test angled, 0x400
jnz .h16_no_intra_edge_filter
call .filter_strength
test r5d, r5d
jz .h16_main ; filter_strength == 0
popcnt r5d, r5d
movu m0, [tlq-28] ; 3 4 5 6 7 8 9 a b c d e f g h i
paddw m1, m0, [tlq-32] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpbroadcastd m6, [base+z_filter_k-4+r5*4+12*1]
vpbroadcastd m7, [base+z_filter_k-4+r5*4+12*0]
pmullw m2, m6, [tlq-30] ; 2 3 4 5 6 7 8 9 a b c d e f g h
pmullw m1, m7
paddw m1, m2
cmp wd, 8
jg .h16_filter_w16
mova xm3, [tlq-46] ; 0 1 2 3 4 5 6 7
pmullw xm6, xm3
jl .h16_filter_w4
pblendw xm3, [tlq-48], 0xfe ; 0 0 1 2 3 4 5 6
cmp r5d, 3
jne .h16_filter_w8_3tap
vpblendd xm4, xm3, [tlq-50], 0x0e ; 0 0 0 1 2 3 4 5
.h16_filter_w8_5tap:
punpckhwd m0, m0
vpblendd m0, [tlq-26], 0x7f ; 4 5 6 7 8 9 a b c d e f g h i i
paddw xm4, [tlq-42] ; 2 3 4 5 6 7 8 9
paddw m0, [tlq-34] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
paddw xm4, xm4
paddw m0, m0
paddw xm6, xm4
paddw m1, m0
.h16_filter_w8_3tap:
paddw xm3, [tlq-44] ; 1 2 3 4 5 6 7 8
pmullw xm3, xm7
pxor m0, m0
paddw xm3, xm6
psrlw xm3, 3
pavgw xm3, xm0
mova [rsp+48], xm3
jmp .h16_filter_end
.h16_filter_w4:
pshufhw xm3, xm3, q2100 ; _ _ _ _ 4 4 5 6
cmp r5d, 3
jne .h16_filter_w8_3tap
pshufhw xm4, xm3, q2100 ; _ _ _ _ 4 4 4 5
jmp .h16_filter_w8_5tap
.h16_filter_w16:
mova m3, [tlq-62] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
pmullw m6, m3
punpcklwd xm3, xm3
vpblendd m4, m3, [tlq-64], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
paddw m4, [tlq-60] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
mov r4d, 32
cmp wd, 16
cmovg maxbased, r4d
movd [rsp+28], xm3
pmullw m4, m7
cmp r5d, 3
jne .h16_filter_w16_3tap
punpckhwd m0, m0
vpblendd m3, [tlq-66], 0xfe ; 0 0 0 1 2 3 4 5 6 7 8 9 a b c d
vpblendd m0, [tlq-26], 0x7f ; 4 5 6 7 8 9 a b c d e f g h i i
paddw m3, [tlq-58] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m0, [tlq-34] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
movzx r4d, word [tlq-62]
movzx r2d, word [tlq-60]
or maxbased, 1
paddw m3, m3
sub r2d, r4d
paddw m0, m0
lea r2d, [r2+r4*8+4]
paddw m4, m3
shr r2d, 3
paddw m1, m0
mov [rsp+30], r2w
.h16_filter_w16_3tap:
pxor m0, m0
paddw m4, m6
psrlw m4, 3
pavgw m4, m0
mova [rsp+32], m4
.h16_filter_end:
psrlw m1, 3
lea tlq, [rsp+94]
pavgw m1, m0
mova [rsp+64], m1
.h16_main:
movd xm8, dyd
neg maxbaseq
vpbroadcastw m9, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m8, xm8
lea r4d, [maxbaseq+dyq+15*64]
neg dyq
movd xm7, r4d
sub tlq, 32
lea r4, [dyq+63]
vpbroadcastw m7, xm7
or maxbased, 63
psubw m7, [z_base_inc]
.h16_loop:
lea r5, [r4+dyq]
sar r4, 6 ; base0
movu m0, [tlq+r4*2+2]
movu m2, [tlq+r4*2]
lea r4, [r5+dyq]
sar r5, 6 ; base1
movu m1, [tlq+r5*2+2]
movu m3, [tlq+r5*2]
lea r5, [r4+dyq]
sar r4, 6 ; base3
pand m6, m5, m7
psllw m6, 9
psubw m2, m0
pmulhrsw m2, m6
psraw m6, m7, 15
paddw m7, m8
paddw m0, m2
movu m2, [tlq+r4*2+2]
movu m4, [tlq+r4*2]
lea r4, [r5+dyq]
sar r5, 6 ; base3
vpblendvb m0, m9, m0, m6
pand m6, m5, m7
psllw m6, 9
psubw m3, m1
pmulhrsw m3, m6
psraw m6, m7, 15
paddw m7, m8
paddw m1, m3
vpblendvb m1, m9, m1, m6
pand m6, m5, m7
psllw m6, 9
psubw m4, m2
pmulhrsw m4, m6
psraw m6, m7, 15
paddw m7, m8
paddw m2, m4
movu m3, [tlq+r5*2+2]
movu m4, [tlq+r5*2]
vpblendvb m2, m9, m2, m6
pand m6, m5, m7
psllw m6, 9
psubw m4, m3
pmulhrsw m4, m6
psraw m6, m7, 15
paddw m7, m8
lea r5, [dstq+strideq*4]
paddw m3, m4
vpblendvb m3, m9, m3, m6
punpckhwd m4, m0, m1 ; ab bb aa ba a9 b9 a8 b8 a3 b3 a2 b2 a1 b1 a0 b0
punpcklwd m0, m1 ; af bf ae be ad bd ac bc a7 b7 a6 b6 a5 b5 a4 b4
punpckhwd m1, m2, m3 ; cb db ca da c9 d9 c8 d8 c3 d3 c2 d2 c1 d1 c0 d0
punpcklwd m2, m3 ; cf df ce de cd dd cc dc c7 d7 c6 d6 c5 d5 c4 d4
punpckhdq m3, m4, m1 ; a9 b9 c9 d9 a8 b8 c8 d8 a1 b1 c1 d1 a0 b0 c0 d0
vextracti128 xm6, m3, 1
punpckldq m4, m1 ; ab bb cb db aa ba ca da a3 b3 c3 d3 a2 b2 c2 d2
punpckhdq m1, m0, m2 ; ad bd cd dd ac bc cc dc a5 b5 c5 d5 a4 b4 c4 d4
punpckldq m0, m2 ; af bf cf df ae be ce de a7 b7 c7 d7 a6 b6 c6 d6
vextracti128 xm2, m4, 1
movhps [dstq+strideq*0], xm6
movq [dstq+strideq*1], xm6
vextracti128 xm6, m1, 1
movhps [dstq+strideq*2], xm2
movq [dstq+r7 ], xm2
vextracti128 xm2, m0, 1
movhps [r5 +strideq*0], xm6
movq [r5 +strideq*1], xm6
movhps [r5 +strideq*2], xm2
movq [r5 +r7 ], xm2
lea r5, [dstq+strideq*8]
movhps [r5 +strideq*0], xm3
movq [r5 +strideq*1], xm3
movhps [r5 +strideq*2], xm4
movq [r5 +r7 ], xm4
lea r5, [r5+strideq*4]
movhps [r5 +strideq*0], xm1
movq [r5 +strideq*1], xm1
movhps [r5 +strideq*2], xm0
movq [r5 +r7 ], xm0
sub wd, 4
jz .h16_end
add dstq, 8
cmp r4d, maxbased
jg .h16_loop
mov hd, 4
.h16_end_loop0:
mov r6d, wd
mov r2, dstq
test wb, 4
jz .h16_end_loop
movq [dstq+strideq*0], xm9
movq [dstq+strideq*1], xm9
movq [dstq+strideq*2], xm9
movq [dstq+r7 ], xm9
and r6d, 120
jz .h16_end_w4
add dstq, 8
.h16_end_loop:
mova [dstq+strideq*0], xm9
mova [dstq+strideq*1], xm9
mova [dstq+strideq*2], xm9
mova [dstq+r7 ], xm9
add dstq, 16
sub r6d, 8
jg .h16_end_loop
.h16_end_w4:
lea dstq, [r2+strideq*4]
dec hd
jg .h16_end_loop0
.h16_end:
RET
.h32:
ALLOC_STACK -160, 9
lea maxbased, [wq+31]
and maxbased, 31
or maxbased, 32 ; imin(w+31, 63)
test angled, 0x400
jnz .h32_main
vpbroadcastd m2, [pw_3]
movu m0, [tlq-28] ; 3 4 5 6 7 8 9 a b c d e f g h i
punpckhwd m1, m0, m0
vpblendd m1, [tlq-26], 0x7f ; 4 5 6 7 8 9 a b c d e f g h i i
paddw m0, [tlq-30] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m1, m2
paddw m0, [tlq-32] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pavgw m1, [tlq-34] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
lea r4, [rsp+128]
paddw m0, m1
lea r5d, [maxbaseq-31]
psrlw m0, 2
mova [r4], m0
.h32_filter_loop:
mova m0, [tlq-62]
paddw m1, m2, [tlq-66]
paddw m0, [tlq-64]
pavgw m1, [tlq-58]
paddw m0, [tlq-60]
sub tlq, 32
sub r4, 32
paddw m0, m1
psrlw m0, 2
mova [r4], m0
sub r5d, 16
jg .h32_filter_loop
jl .h32_filter_h8
mova m0, [tlq-62] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
punpcklwd xm1, xm0, xm0
paddw m2, [tlq-58] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m0, [tlq-60] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpblendd m3, m1, [tlq-66], 0xfe ; 0 0 0 1 2 3 4 5 6 7 8 9 a b c d
vpblendd m1, [tlq-64], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
movzx r5d, word [tlq-62]
movzx r2d, word [tlq-60]
pavgw m2, m3
sub r2d, r5d
paddw m0, m1
lea r2d, [r2+r5*8+4]
paddw m0, m2
shr r2d, 3
psrlw m0, 2
mova [r4-32], m0
mov [r4-36], r5w
mov [r4-34], r2w
lea tlq, [rsp+158]
mov r4d, 65
cmp wd, 64
cmove maxbased, r4d
jmp .h32_main
.h32_filter_h8:
mova xm0, [tlq-46] ; 0 1 2 3 4 5 6 7
pblendw xm1, xm0, [tlq-48], 0xfe ; 0 0 1 2 3 4 5 6
paddw xm2, [tlq-42] ; 2 3 4 5 6 7 8 9
paddw xm0, [tlq-44] ; 1 2 3 4 5 6 7 8
vpblendd xm3, xm1, [tlq-50], 0x0e ; 0 0 0 1 2 3 4 5
lea tlq, [rsp+158]
pavgw xm2, xm3
paddw xm0, xm1
paddw xm0, xm2
psrlw xm0, 2
mova [r4-16], xm0
.h32_main:
movd xm6, dyd
neg maxbaseq
vpbroadcastw m7, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m6, xm6
lea r4d, [maxbaseq+dyq+15*64]
neg dyq
movd xm4, r4d
vpbroadcastd m8, [pw_m1024]
lea r4, [dyq+63]
vpbroadcastw m4, xm4
or maxbased, 63
psubw m4, [z_base_inc]
.h32_loop:
mov r5, r4
sar r5, 6
movu m1, [tlq+r5*2-64]
movu m0, [tlq+r5*2-62]
pand m3, m5, m4
psllw m3, 9
psubw m1, m0
pmulhrsw m1, m3
pcmpgtw m2, m8, m4
paddw m0, m1
vpblendvb m0, m7, m0, m2
movu m2, [tlq+r5*2-32]
movu m1, [tlq+r5*2-30]
add r4, dyq
sub rsp, 64
psubw m2, m1
pmulhrsw m2, m3
psraw m3, m4, 15
paddw m4, m6
mova [rsp+32*0], m0
paddw m1, m2
vpblendvb m1, m7, m1, m3
mova [rsp+32*1], m1
dec wd
jz .h32_transpose
cmp r4d, maxbased
jg .h32_loop
.h32_end_loop:
sub rsp, 64
mova [rsp+32*0], m7
mova [rsp+32*1], m7
dec wd
jg .h32_end_loop
.h32_transpose:
lea r3, [strideq*3]
lea r4, [strideq*5]
mov r8, dstq
lea r5, [strideq+r3*2]
.h32_transpose_loop0:
lea r6, [rsp+32]
lea r2, [r8+org_wq*2-16]
.h32_transpose_loop:
mova m0, [r6+64*7]
mova m1, [r6+64*6]
mova m2, [r6+64*5]
mova m3, [r6+64*4]
mova m4, [r6+64*3]
mova m5, [r6+64*2]
mova m6, [r6+64*1]
mova m7, [r6+64*0]
punpckhwd m8, m0, m1 ; a3 b3 a2 b2 a1 b1 a0 b0
punpcklwd m0, m1 ; a7 b7 a6 b6 a5 b5 a4 b4
punpckhwd m1, m2, m3 ; c3 d3 c2 d2 c1 d1 c0 d0
punpcklwd m2, m3 ; c7 d7 c6 d6 c5 d5 c4 d4
punpckhwd m3, m4, m5 ; e3 f3 e2 f2 e1 f1 e0 f0
punpcklwd m4, m5 ; e7 f7 e6 f6 e5 f5 e4 f4
punpckhwd m5, m6, m7 ; g3 h3 g2 h2 g1 h1 g0 h0
punpcklwd m6, m7 ; g7 h7 g6 h6 g5 h5 g4 h4
lea dstq, [r2+strideq*8]
sub r6, 32
punpckhdq m7, m8, m1 ; a1 b1 c1 d1 a0 b0 c0 d0
punpckldq m8, m1 ; a3 b3 c3 d3 a2 b2 c2 d2
punpckhdq m1, m3, m5 ; e1 f1 g1 h1 e0 f0 g0 h0
punpckldq m3, m5 ; e3 f3 g3 h3 e2 f2 g2 h2
punpckhqdq m5, m7, m1 ; 8 0
vextracti128 [r2 +strideq*0], m5, 1
punpcklqdq m7, m1 ; 9 1
mova [dstq+strideq*0], xm5
punpckhqdq m1, m8, m3 ; 10 2
vextracti128 [r2 +strideq*1], m7, 1
punpcklqdq m8, m3 ; 11 3
mova [dstq+strideq*1], xm7
punpckhdq m3, m0, m2 ; a5 b5 c5 d5 a4 b4 c4 d4
vextracti128 [r2 +strideq*2], m1, 1
punpckldq m0, m2 ; a7 b7 c7 d7 a6 b6 c6 d6
mova [dstq+strideq*2], xm1
punpckhdq m2, m4, m6 ; e5 f5 g5 h5 e4 f4 g4 h4
vextracti128 [r2 +r3 ], m8, 1
punpckldq m4, m6 ; e7 f7 g7 h7 e6 f6 g6 h6
mova [dstq+r3 ], xm8
punpckhqdq m6, m3, m2 ; 12 4
vextracti128 [r2 +strideq*4], m6, 1
punpcklqdq m3, m2 ; 13 5
mova [dstq+strideq*4], xm6
punpckhqdq m2, m0, m4 ; 14 6
vextracti128 [r2 +r4 ], m3, 1
punpcklqdq m0, m4 ; 15 7
mova [dstq+r4 ], xm3
vextracti128 [r2 +r3*2 ], m2, 1
mova [dstq+r3*2 ], xm2
vextracti128 [r2 +r5 ], m0, 1
mova [dstq+r5 ], xm0
lea r2, [dstq+strideq*8]
cmp r6, rsp
jae .h32_transpose_loop
add rsp, 64*8
sub org_wd, 8
jg .h32_transpose_loop0
.h32_end:
RET
.h64:
ALLOC_STACK -256, 10
lea maxbased, [wq+63]
test angled, 0x400
jnz .h64_main
vpbroadcastd m2, [pw_3]
movu m0, [tlq-28] ; 3 4 5 6 7 8 9 a b c d e f g h i
punpckhwd m1, m0, m0
vpblendd m1, [tlq-26], 0x7f ; 4 5 6 7 8 9 a b c d e f g h i i
paddw m0, [tlq-30] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m1, m2
paddw m0, [tlq-32] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
pavgw m1, [tlq-34] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
lea r4, [rsp+224]
paddw m0, m1
lea r5d, [wq+32]
psrlw m0, 2
mova [r4], m0
.h64_filter_loop:
mova m0, [tlq-62]
paddw m1, m2, [tlq-66]
paddw m0, [tlq-64]
pavgw m1, [tlq-58]
paddw m0, [tlq-60]
sub tlq, 32
sub r4, 32
paddw m0, m1
psrlw m0, 2
mova [r4], m0
sub r5d, 16
jg .h64_filter_loop
mova m0, [tlq-62] ; 0 1 2 3 4 5 6 7 8 9 a b c d e f
punpcklwd xm1, xm0, xm0
paddw m2, [tlq-58] ; 2 3 4 5 6 7 8 9 a b c d e f g h
paddw m0, [tlq-60] ; 1 2 3 4 5 6 7 8 9 a b c d e f g
vpblendd m3, m1, [tlq-66], 0xfe ; 0 0 0 1 2 3 4 5 6 7 8 9 a b c d
vpblendd m1, [tlq-64], 0xfe ; 0 0 1 2 3 4 5 6 7 8 9 a b c d e
lea tlq, [rsp+254]
pavgw m2, m3
paddw m0, m1
paddw m0, m2
psrlw m0, 2
mova [r4-32], m0
.h64_main:
neg maxbaseq
movd xm4, dyd
vpbroadcastw m6, [tlq+maxbaseq*2]
shl maxbased, 6
vpbroadcastw m4, xm4
lea r4d, [maxbaseq+dyq+15*64]
neg dyq
vpbroadcastd m7, [pw_m1024]
movd xm3, r4d
lea r4, [dyq+63]
paddw m8, m7, m7
vpbroadcastw m3, xm3
or maxbased, 63
paddw m9, m8, m7
psubw m3, [z_base_inc]
.h64_loop:
mov r5, r4
sar r5, 6
movu m1, [tlq+r5*2-128]
movu m0, [tlq+r5*2-126]
pand m2, m5, m3
psllw m2, 9
psubw m1, m0
pmulhrsw m1, m2
sub rsp, 128
paddw m0, m1
pcmpgtw m1, m9, m3
vpblendvb m0, m6, m0, m1
mova [rsp+32*0], m0
movu m1, [tlq+r5*2-96]
movu m0, [tlq+r5*2-94]
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
pcmpgtw m1, m8, m3
vpblendvb m0, m6, m0, m1
mova [rsp+32*1], m0
movu m1, [tlq+r5*2-64]
movu m0, [tlq+r5*2-62]
psubw m1, m0
pmulhrsw m1, m2
paddw m0, m1
pcmpgtw m1, m7, m3
vpblendvb m0, m6, m0, m1
mova [rsp+32*2], m0
movu m1, [tlq+r5*2-32]
movu m0, [tlq+r5*2-30]
psubw m1, m0
pmulhrsw m1, m2
add r4, dyq
psraw m2, m3, 15
paddw m3, m4
paddw m0, m1
vpblendvb m0, m6, m0, m2
mova [rsp+32*3], m0
dec wd
jz .h64_transpose
cmp r4d, maxbased
jg .h64_loop
.h64_end_loop:
sub rsp, 128
mova [rsp+32*0], m6
mova [rsp+32*1], m6
mova [rsp+32*2], m6
mova [rsp+32*3], m6
dec wd
jg .h64_end_loop
.h64_transpose:
lea r2, [strideq*3]
lea r3, [strideq*5]
mov r5, dstq
lea r4, [strideq+r2*2]
.h64_transpose_loop0:
lea r6, [rsp+112]
lea dstq, [r5+org_wq*2-32]
.h64_transpose_loop:
mova xm0, [r6+128*15]
vinserti128 m0, [r6+128* 7], 1
mova xm1, [r6+128*14]
vinserti128 m1, [r6+128* 6], 1
mova xm2, [r6+128*13]
vinserti128 m2, [r6+128* 5], 1
mova xm3, [r6+128*12]
vinserti128 m3, [r6+128* 4], 1
mova xm4, [r6+128*11]
vinserti128 m4, [r6+128* 3], 1
mova xm5, [r6+128*10]
vinserti128 m5, [r6+128* 2], 1
mova xm6, [r6+128* 9]
vinserti128 m6, [r6+128* 1], 1
mova xm7, [r6+128* 8]
vinserti128 m7, [r6+128* 0], 1
punpckhwd m8, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhwd m3, m4, m5
punpcklwd m4, m5
punpckhwd m5, m6, m7
punpcklwd m6, m7
sub r6, 16
punpckhdq m7, m8, m1
punpckldq m8, m1
punpckhdq m1, m3, m5
punpckldq m3, m5
punpckhqdq m5, m7, m1
punpcklqdq m7, m1
punpckhqdq m1, m8, m3
punpcklqdq m8, m3
punpckhdq m3, m0, m2
mova [dstq+strideq*0], m5
punpckldq m0, m2
mova [dstq+strideq*1], m7
punpckhdq m2, m4, m6
mova [dstq+strideq*2], m1
punpckldq m4, m6
mova [dstq+r2 ], m8
punpckhqdq m6, m3, m2
mova [dstq+strideq*4], m6
punpcklqdq m3, m2
mova [dstq+r3 ], m3
punpckhqdq m2, m0, m4
mova [dstq+r2*2 ], m2
punpcklqdq m0, m4
mova [dstq+r4 ], m0
lea dstq, [dstq+strideq*8]
cmp r6, rsp
jae .h64_transpose_loop
add rsp, 128*16
sub org_wd, 16
jg .h64_transpose_loop0
.h64_end:
RET
%macro FILTER_1BLK 5 ; dst, src, tmp, shuf, bdmax
%ifnum %4
pshufb xm%2, xm%4
%else
pshufb xm%2, %4
%endif
vinserti128 m%2, xm%2, 1
pshufd m%1, m%2, q0000
pmaddwd m%1, m2
pshufd m%3, m%2, q1111
pmaddwd m%3, m3
paddd m%1, m1
paddd m%1, m%3
pshufd m%3, m%2, q2222
pmaddwd m%3, m4
paddd m%1, m%3
pshufd m%3, m%2, q3333
pmaddwd m%3, m5
paddd m%1, m%3
psrad m%1, 4
packusdw m%1, m%1
pminsw m%1, m%5
%endmacro
%macro FILTER_2BLK 7 ; dst, src, tmp_dst, tmp_src, tmp, shuf, bdmax
pshufb m%2, m%6
vpermq m%4, m%2, q3232
vinserti128 m%2, xm%2, 1
pshufd m%1, m%2, q0000
pshufd m%3, m%4, q0000
pmaddwd m%1, m2
pmaddwd m%3, m2
paddd m%1, m1
paddd m%3, m1
pshufd m%5, m%2, q1111
pmaddwd m%5, m3
paddd m%1, m%5
pshufd m%5, m%4, q1111
pmaddwd m%5, m3
paddd m%3, m%5
pshufd m%5, m%2, q2222
pmaddwd m%5, m4
paddd m%1, m%5
pshufd m%5, m%4, q2222
pmaddwd m%5, m4
paddd m%3, m%5
pshufd m%5, m%2, q3333
pmaddwd m%5, m5
paddd m%1, m%5
pshufd m%5, m%4, q3333
pmaddwd m%5, m5
paddd m%3, m%5
psrad m%1, 4
psrad m%3, 4
packusdw m%1, m%3
pminsw m%1, m%7
%endmacro
; The ipred_filter SIMD processes 4x2 blocks in the following order which
; increases parallelism compared to doing things row by row. One redundant
; block is calculated for w8 and w16, two for w32.
; w4 w8 w16 w32
; 1 1 2 1 2 3 5 1 2 3 5 b c d f
; 2 2 3 2 4 5 7 2 4 5 7 c e f h
; 3 3 4 4 6 7 9 4 6 7 9 e g h j
; ___ 4 ___ 4 5 ___ 6 8 9 a ___ 6 8 9 a g i j k ___
; 5 8 8 i
cglobal ipred_filter_16bpc, 3, 9, 0, dst, stride, tl, w, h, filter
%define base r6-ipred_filter_16bpc_avx2_table
lea r6, [filter_intra_taps]
tzcnt wd, wm
%ifidn filterd, filterm
movzx filterd, filterb
%else
movzx filterd, byte filterm
%endif
shl filterd, 6
add filterq, r6
lea r6, [ipred_filter_16bpc_avx2_table]
vbroadcasti128 m0, [tlq-6]
movsxd wq, [r6+wq*4]
vpbroadcastd m1, [base+pd_8]
pmovsxbw m2, [filterq+16*0]
pmovsxbw m3, [filterq+16*1]
pmovsxbw m4, [filterq+16*2]
pmovsxbw m5, [filterq+16*3]
add wq, r6
mov hd, hm
jmp wq
.w4:
WIN64_SPILL_XMM 10
mova xm8, [base+filter_shuf2]
vpbroadcastw m9, r8m ; bitdepth_max
lea r7, [6+hq*2]
sub tlq, r7
jmp .w4_loop_start
.w4_loop:
pinsrq xm0, [tlq+hq*2], 0
lea dstq, [dstq+strideq*2]
.w4_loop_start:
FILTER_1BLK 6, 0, 7, 8, 9
vextracti128 xm0, m6, 1
movq [dstq+strideq*0], xm6
movq [dstq+strideq*1], xm0
sub hd, 2
jg .w4_loop
RET
ALIGN function_align
.w8:
WIN64_SPILL_XMM 16
vbroadcasti128 m14, [base+filter_shuf3]
vpbroadcastw m15, r8m ; bitdepth_max
FILTER_1BLK 10, 0, 7, [base+filter_shuf2], 15
vpermq m6, m10, q1302 ; ____ ____ | ____ 4321
pslldq m8, m0, 4
psrldq m7, m6, 2
psrldq m0, m6, 10
punpcklwd m7, m0
vpblendd m8, m6, 0x33 ; _0__ 4321 | ____ 4321
vpblendd m8, m7, 0x40 ; _056 4321 | ____ 4321
vpblendd m8, [tlq-6], 0x30 ; _056 4321 | ____ 4321
lea r7, [16+hq*2]
sub tlq, r7
jmp .w8_loop_start
.w8_loop:
vpermq m8, m9, q1302 ; ____ 4321 | ____ 4321
vpermq m6, m9, q2031
psrldq m0, m6, 2
psrldq m6, 10
punpcklwd m6, m0
vpblendd m8, m7, 0x80 ; _0__ 4321 | ____ 4321
vpblendd m8, m6, 0x40 ; _056 4321 | ____ 4321
mova m10, m9
.w8_loop_start:
vpblendd m8, [tlq+hq*2], 0x0C ; _056 4321 | _056 4321
call .main
vpblendd m10, m9, 0xCC
mova [dstq+strideq*0], xm10
vextracti128 [dstq+strideq*1], m10, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w8_loop
RET
ALIGN function_align
.w16:
ALLOC_STACK 32, 16
vpbroadcastw m15, r8m ; bitdepth_max
sub hd, 2
TAIL_CALL .w16_main, 0
.w16_main:
mova xm10, [base+filter_shuf2]
FILTER_1BLK 13, 0, 6, 10, 15
vpermq m12, m13, q3120
mova xm14, [base+filter_shuf3]
vinserti128 m14, [base+filter_shuf1], 1
vpbroadcastq m0, [tlq+10]
vpblendd m0, [tlq-16], 0x4C ; ___0 4321 | _056 ____
psrldq m6, m12, 8
vpblendd m0, m6, 0x03 ; ___0 4321 | _056 4321
punpcklwd m6, m12
vpblendd m0, m6, 0x80 ; 56_0 4321 | _056 4321
FILTER_2BLK 12, 0, 6, 7, 8, 14, 15
vpblendd m13, m12, 0xCC
vpermq m12, m12, q2031 ; 6___ 5___
psrldq xm6, xm12, 2
psrldq xm8, xm12, 12
vpblendd xm6, xm8, 0x01
pblendw xm6, [tlq+10], 0xF8 ; 4321 056_
FILTER_1BLK 11, 6, 8, 10, 15
vpermq m11, m11, q3120
pshufd m9, m11, q1032
movu m8, [tlq+6] ; __43 210_ | ____ ____
pshufd m8, m8, q3021 ; __0_ 4321 | ____ ____
pshufhw m8, m8, q3201 ; ___0 4321 | ____ ____
vpblendd m9, m8, 0x70 ; ___0 4321 | ____ 4321
mova [dstq+strideq*0], xm13
vextracti128 [dstq+strideq*1], m13, 1
lea r7, [20+hq*2]
sub tlq, r7
vpermq m6, m12, q0123 ; ____ 4321 | ____ 4321
jmp .w16_loop_start
.w16_loop:
vpermq m13, m13, q3322
vpermq m11, m9, q2020
vpermq m9, m9, q1302
vpermq m6, m12, q0123
psrldq m7, 4
vpblendd m13, m10, 0xCC
vpblendd m9, m7, 0x40
mova m0, [rsp+8]
mova [dstq+strideq*0], xm13
vextracti128 [dstq+strideq*1], m13, 1
.w16_loop_start:
mova m13, m12
vpblendd m0, [tlq+hq*2], 0x0C
psrldq m7, m12, 8
punpcklwd m7, m12
vpblendd m0, m6, 0x33 ; ___0 4321 | _056 4321
vpblendd m0, m7, 0x80 ; 56_0 4321 | _056 4321
FILTER_2BLK 10, 0, 6, 7, 8, 14, 15
vpermq m12, m10, q2031
mova [rsp+8], m0
psrldq m8, m11, 8
psrldq xm6, xm12, 2
psrldq xm7, xm12, 10
psrldq xm0, xm13, 2
punpcklwd m8, m11
punpcklwd xm7, xm6
vpblendd m8, m9, 0x73 ; 56_0 4321 | ____ 4321
vpblendd m8, m7, 0x04 ; 56_0 4321 | __56 4321
vpblendd m8, m0, 0x08 ; 56_0 4321 | _056 4321
call .main
vpermq m8, m11, q3120
vpblendd m6, m8, m9, 0xCC
mova [dstq+strideq*0+16], xm6
vextracti128 [dstq+strideq*1+16], m6, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w16_loop
vpermq m8, m9, q3120
vextracti128 xm0, m8, 1 ; 4321 ____
pshufd xm11, xm11, q1032
vpblendd xm0, xm11, 0x02 ; 4321 0___
psrldq xm6, xm8, 2
psrldq xm7, xm8, 12
pblendw xm0, xm6, 0x4 ; 4321 05__
pblendw xm0, xm7, 0x2 ; 4321 056_
FILTER_1BLK 6, 0, 7, [base+filter_shuf2], 15
vpermq m12, m13, q1302
vpblendd m12, m10, 0xCC
vpblendd m9, m6, 0xCC
mova [dstq+strideq*0+ 0], xm12
mova [dstq+strideq*0+16], xm9
vextracti128 [dstq+strideq*1+ 0], m12, 1
vextracti128 [dstq+strideq*1+16], m9, 1
ret
ALIGN function_align
.w32:
ALLOC_STACK 64, 16
vpbroadcastw m15, r8m ; bitdepth_max
sub hd, 2
lea r3, [dstq+32]
lea r5d, [hd*2+20]
call .w16_main
mov dstq, r3
lea tlq, [tlq+r5+32]
sub r5d, 20
shr r5d, 1
sub r5d, 2
lea r4, [dstq+strideq*2-2]
DEFINE_ARGS dst, stride, tl, stride3, left, h
lea stride3q, [strideq*3]
movu m8, [tlq-6] ; 4321 0___
mova xm10, [base+filter_shuf2]
pinsrw xm0, xm8, [dstq+strideq*0-2], 2
pinsrw xm0, xm0, [dstq+strideq*1-2], 1 ; 4321 056_
pinsrw xm9, [leftq+strideq*0], 5
pinsrw xm9, [leftq+strideq*1], 4
FILTER_1BLK 13, 0, 6, 10, 15
vpermq m12, m13, q3120
mova xm14, [base+filter_shuf3]
vinserti128 m14, [base+filter_shuf1], 1
psrldq m6, m12, 8
punpcklwd m7, m6, m12
vpblendd m0, m6, 0x03 ; ___0 ____ | _0__ 4321
vpblendd m0, m7, 0x80 ; 56_0 ____ | _0__ 4321
vpblendd m0, m8, 0x30 ; 56_0 4321 | _0__ 4321
vpblendd m0, m9, 0x04 ; 56_0 4321 | _056 4321
FILTER_2BLK 12, 0, 6, 7, 8, 14, 15
vpblendd m13, m12, 0xCC
pinsrw xm9, [leftq+strideq*2], 3
pinsrw xm9, [leftq+stride3q ], 2
lea leftq, [leftq+strideq*4]
pinsrw xm9, [leftq+strideq*0], 1
pinsrw xm9, [leftq+strideq*1], 0
movq [rsp+32], xm9
mov r7d, 1
pslldq m8, m9, 4
vpblendd m0, m8, 0x0C ; ___0 ____ | _056 ____
vpermq m12, m12, q2031 ; 6___ 5___
psrldq xm6, xm12, 2
psrldq xm7, xm12, 12
vpblendd xm6, xm7, 0x01 ; ____ _56_
pblendw xm6, [tlq+10], 0xF8 ; 4321 056_
FILTER_1BLK 11, 6, 7, 10, 15
vpermq m11, m11, q3120
pshufd m9, m11, q1032
vbroadcasti128 m8, [tlq+22] ; __43 210_ | ____ ____
pshufd m8, m8, q3021 ; __0_ 4321 | ____ ____
pshufhw m8, m8, q3201 ; ___0 4321 | ____ ____
vpblendd m9, m8, 0x70 ; ___0 4321 | ____ 4321
mova [dstq+strideq*0], xm13
vextracti128 [dstq+strideq*1], m13, 1
vpermq m6, m12, q0123 ; ____ 4321 | ____ 4321
jmp .w32_loop_start
.w32_loop_last:
mova m0, [rsp+0]
jmp .w32_loop
.w32_loop_left:
mova m0, [rsp+0]
vpblendd m0, [rsp+32+r7*4-12], 0x0C
dec r7d
jg .w32_loop
cmp hd, 2
je .w32_loop
pinsrw xm6, [rsp+32], 6
pinsrw xm6, [leftq+strideq*2], 5
pinsrw xm6, [leftq+stride3q ], 4
lea leftq, [leftq+strideq*4]
pinsrw xm6, [leftq+strideq*0], 3
pinsrw xm6, [leftq+strideq*1], 2
pinsrw xm6, [leftq+strideq*2], 1
pinsrw xm6, [leftq+stride3q ], 0
lea leftq, [leftq+strideq*4]
movu [rsp+36], xm6
pinsrw xm6, [leftq+strideq*0], 1
pinsrw xm6, [leftq+strideq*1], 0
movd [rsp+32], xm6
mov r7d, 4
.w32_loop:
vpermq m13, m13, q3322
vpermq m11, m9, q2020
vpermq m9, m9, q1302
vpermq m6, m12, q0123
psrldq m7, 4
vpblendd m13, m10, 0xCC
vpblendd m9, m7, 0x40 ; ___0 4321 | ____ 4321
mova [dstq+strideq*0], xm13
vextracti128 [dstq+strideq*1], m13, 1
.w32_loop_start:
mova m13, m12
psrldq m7, m12, 8
punpcklwd m7, m12
vpblendd m0, m6, 0x33 ; ___0 4321 | _056 4321
vpblendd m0, m7, 0x80 ; 56_0 4321 | _056 4321
FILTER_2BLK 10, 0, 6, 7, 8, 14, 15
vpermq m12, m10, q2031
mova [rsp+0], m0
psrldq m8, m11, 8
psrldq xm6, xm12, 2
psrldq xm7, xm12, 10
psrldq xm0, xm13, 2
punpcklwd m8, m11
punpcklwd xm7, xm6
vpblendd m8, m9, 0x73 ; 56_0 4321 | ____ 4321
vpblendd m8, m7, 0x04 ; 56_0 4321 | __56 4321
vpblendd m8, m0, 0x08 ; 56_0 4321 | _056 4321
call .main
vpermq m8, m11, q3120
vpblendd m6, m8, m9, 0xCC
mova [dstq+strideq*0+16], xm6
vextracti128 [dstq+strideq*1+16], m6, 1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w32_loop_left
jz .w32_loop_last
vpermq m8, m9, q3120
vextracti128 xm0, m8, 1 ; 4321 ____
pshufd xm11, xm11, q1032
vpblendd xm0, xm11, 0x02 ; 4321 0___
psrldq xm6, xm8, 2
psrldq xm7, xm8, 12
pblendw xm0, xm6, 0x4 ; 4321 05__
pblendw xm0, xm7, 0x2 ; 4321 056_
FILTER_1BLK 6, 0, 7, [base+filter_shuf2], 15
vpermq m12, m13, q1302
vpblendd m12, m10, 0xCC
vpblendd m9, m6, 0xCC
mova [dstq+strideq*0+ 0], xm12
mova [dstq+strideq*0+16], xm9
vextracti128 [dstq+strideq*1+ 0], m12, 1
vextracti128 [dstq+strideq*1+16], m9, 1
RET
.main:
FILTER_2BLK 9, 8, 6, 7, 0, 14, 15
ret
%if WIN64
DECLARE_REG_TMP 5
%else
DECLARE_REG_TMP 7
%endif
%macro IPRED_CFL 1 ; ac in, unpacked pixels out
psignw m3, m%1, m1
pabsw m%1, m%1
pmulhrsw m%1, m2
psignw m%1, m3
paddw m%1, m0
%endmacro
cglobal ipred_cfl_top_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac, alpha
movifnidn hd, hm
add tlq, 2
movd xm4, wd
pxor m6, m6
vpbroadcastw m7, r7m
pavgw xm4, xm6
tzcnt wd, wd
movd xm5, wd
movu m0, [tlq]
lea t0, [ipred_cfl_left_16bpc_avx2_table]
movsxd r6, [t0+wq*4]
add r6, t0
add t0, ipred_cfl_splat_16bpc_avx2_table-ipred_cfl_left_16bpc_avx2_table
movsxd wq, [t0+wq*4]
add wq, t0
movifnidn acq, acmp
jmp r6
cglobal ipred_cfl_left_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac, alpha
mov hd, hm ; zero upper half
sub tlq, hq
movd xm4, hd
sub tlq, hq
pxor m6, m6
vpbroadcastw m7, r7m
pavgw xm4, xm6
tzcnt r6d, hd
movd xm5, r6d
movu m0, [tlq]
lea t0, [ipred_cfl_left_16bpc_avx2_table]
movsxd r6, [t0+r6*4]
add r6, t0
add t0, ipred_cfl_splat_16bpc_avx2_table-ipred_cfl_left_16bpc_avx2_table
tzcnt wd, wd
movsxd wq, [t0+wq*4]
add wq, t0
movifnidn acq, acmp
jmp r6
.h32:
paddw m0, [tlq+32]
.h16:
vextracti128 xm1, m0, 1
paddw xm0, xm1
.h8:
psrldq xm1, xm0, 8
paddw xm0, xm1
.h4:
punpcklwd xm0, xm6
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
paddd xm0, xm4
psrld xm0, xm5
vpbroadcastw m0, xm0
jmp wq
cglobal ipred_cfl_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac, alpha
movifnidn hd, hm
movifnidn wd, wm
tzcnt r6d, hd
lea t0d, [wq+hq]
movd xm4, t0d
tzcnt t0d, t0d
movd xm5, t0d
lea t0, [ipred_cfl_16bpc_avx2_table]
tzcnt wd, wd
movsxd r6, [t0+r6*4]
movsxd wq, [t0+wq*4+4*4]
psrlw xm4, 1
pxor m6, m6
vpbroadcastw m7, r7m
add r6, t0
add wq, t0
movifnidn acq, acmp
jmp r6
.h4:
movq xm0, [tlq-8]
jmp wq
.w4:
movq xm1, [tlq+2]
paddw m0, m4
paddw m0, m1
psrlq m1, m0, 32
paddw m0, m1
psrld m1, m0, 16
paddw m0, m1
cmp hd, 4
jg .w4_mul
psrlw xm0, 3
jmp .w4_end
.w4_mul:
vextracti128 xm1, m0, 1
paddw xm0, xm1
lea r2d, [hq*2]
mov r6d, 0xAAAB6667
shrx r6d, r6d, r2d
punpckhwd xm1, xm0, xm6
punpcklwd xm0, xm6
paddd xm0, xm1
movd xm1, r6d
psrld xm0, 2
pmulhuw xm0, xm1
psrlw xm0, 1
.w4_end:
vpbroadcastw m0, xm0
.s4:
vpbroadcastw m1, alpham
lea r6, [strideq*3]
pabsw m2, m1
psllw m2, 9
.s4_loop:
mova m4, [acq]
IPRED_CFL 4
pmaxsw m4, m6
pminsw m4, m7
vextracti128 xm5, m4, 1
movq [dstq+strideq*0], xm4
movq [dstq+strideq*2], xm5
movhps [dstq+strideq*1], xm4
movhps [dstq+r6 ], xm5
lea dstq, [dstq+strideq*4]
add acq, 32
sub hd, 4
jg .s4_loop
RET
ALIGN function_align
.h8:
mova xm0, [tlq-16]
jmp wq
.w8:
vextracti128 xm1, m0, 1
paddw xm0, [tlq+2]
paddw xm0, xm4
paddw xm0, xm1
psrld xm1, xm0, 16
paddw xm0, xm1
pblendw xm0, xm6, 0xAA
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 8
je .w8_end
mov r6d, 0xAAAB
mov r2d, 0x6667
cmp hd, 32
cmovz r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w8_end:
vpbroadcastw m0, xm0
.s8:
vpbroadcastw m1, alpham
lea r6, [strideq*3]
pabsw m2, m1
psllw m2, 9
.s8_loop:
mova m4, [acq]
mova m5, [acq+32]
IPRED_CFL 4
IPRED_CFL 5
pmaxsw m4, m6
pmaxsw m5, m6
pminsw m4, m7
pminsw m5, m7
mova [dstq+strideq*0], xm4
mova [dstq+strideq*2], xm5
vextracti128 [dstq+strideq*1], m4, 1
vextracti128 [dstq+r6 ], m5, 1
lea dstq, [dstq+strideq*4]
add acq, 64
sub hd, 4
jg .s8_loop
RET
ALIGN function_align
.h16:
mova m0, [tlq-32]
jmp wq
.w16:
paddw m0, [tlq+2]
vextracti128 xm1, m0, 1
paddw xm0, xm4
paddw xm0, xm1
punpckhwd xm1, xm0, xm6
punpcklwd xm0, xm6
paddd xm0, xm1
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 16
je .w16_end
mov r6d, 0xAAAB
mov r2d, 0x6667
test hb, 8|32
cmovz r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w16_end:
vpbroadcastw m0, xm0
.s16:
vpbroadcastw m1, alpham
pabsw m2, m1
psllw m2, 9
.s16_loop:
mova m4, [acq]
mova m5, [acq+32]
IPRED_CFL 4
IPRED_CFL 5
pmaxsw m4, m6
pmaxsw m5, m6
pminsw m4, m7
pminsw m5, m7
mova [dstq+strideq*0], m4
mova [dstq+strideq*1], m5
lea dstq, [dstq+strideq*2]
add acq, 64
sub hd, 2
jg .s16_loop
RET
ALIGN function_align
.h32:
mova m0, [tlq-64]
paddw m0, [tlq-32]
jmp wq
.w32:
paddw m0, [tlq+ 2]
paddw m0, [tlq+34]
vextracti128 xm1, m0, 1
paddw xm0, xm4
paddw xm0, xm1
punpcklwd xm1, xm0, xm6
punpckhwd xm0, xm6
paddd xm0, xm1
psrlq xm1, xm0, 32
paddd xm0, xm1
psrldq xm1, xm0, 8
paddd xm0, xm1
psrld xm0, xm5
cmp hd, 32
je .w32_end
lea r2d, [hq*2]
mov r6d, 0x6667AAAB
shrx r6d, r6d, r2d
movd xm1, r6d
pmulhuw xm0, xm1
psrlw xm0, 1
.w32_end:
vpbroadcastw m0, xm0
.s32:
vpbroadcastw m1, alpham
pabsw m2, m1
psllw m2, 9
.s32_loop:
mova m4, [acq]
mova m5, [acq+32]
IPRED_CFL 4
IPRED_CFL 5
pmaxsw m4, m6
pmaxsw m5, m6
pminsw m4, m7
pminsw m5, m7
mova [dstq+32*0], m4
mova [dstq+32*1], m5
add dstq, strideq
add acq, 64
dec hd
jg .s32_loop
RET
cglobal ipred_cfl_128_16bpc, 3, 7, 8, dst, stride, tl, w, h, ac, alpha
mov r6d, r7m
shr r6d, 11
lea t0, [ipred_cfl_splat_16bpc_avx2_table]
tzcnt wd, wd
movifnidn hd, hm
movsxd wq, [t0+wq*4]
vpbroadcastd m0, [t0-ipred_cfl_splat_16bpc_avx2_table+pw_512+r6*4]
pxor m6, m6
vpbroadcastw m7, r7m
add wq, t0
movifnidn acq, acmp
jmp wq
cglobal ipred_cfl_ac_420_16bpc, 4, 7, 6, ac, ypx, stride, wpad, hpad, w, h
movifnidn hpadd, hpadm
vpbroadcastd m5, [pw_2]
mov hd, hm
shl hpadd, 2
pxor m4, m4
sub hd, hpadd
cmp dword wm, 8
jg .w16
je .w8
.w4:
lea r3, [strideq*3]
mov r5, acq
.w4_loop:
mova xm0, [ypxq+strideq*2]
mova xm1, [ypxq+r3 ]
vinserti128 m0, [ypxq+strideq*0], 1
vinserti128 m1, [ypxq+strideq*1], 1
lea ypxq, [ypxq+strideq*4]
pmaddwd m0, m5
pmaddwd m1, m5
paddd m0, m1
vextracti128 xm1, m0, 1
paddd m4, m0
packssdw xm1, xm0
mova [acq], xm1
add acq, 16
sub hd, 2
jg .w4_loop
test hpadd, hpadd
jz .dc
vpermq m1, m1, q1111
pslld xm0, 2
.w4_hpad_loop:
mova [acq], m1
paddd m4, m0
add acq, 32
sub hpadd, 4
jg .w4_hpad_loop
jmp .dc
.w8:
mov r5, acq
test wpadd, wpadd
jnz .w8_wpad1
.w8_loop:
pmaddwd m0, m5, [ypxq+strideq*0]
pmaddwd m1, m5, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
paddd m0, m1
vextracti128 xm1, m0, 1
paddd m4, m0
packssdw xm1, xm0, xm1
mova [acq], xm1
add acq, 16
dec hd
jg .w8_loop
.w8_hpad:
test hpadd, hpadd
jz .dc
vinserti128 m1, xm1, 1
pslld m0, 2
jmp .hpad
.w8_wpad1:
pmaddwd xm0, xm5, [ypxq+strideq*0]
pmaddwd xm3, xm5, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
paddd xm0, xm3
pshufd xm3, xm0, q3333
packssdw xm1, xm0, xm3
paddd xm0, xm3
paddd xm4, xm0
mova [acq], xm1
add acq, 16
dec hd
jg .w8_wpad1
jmp .w8_hpad
.w16_wpad:
mova m0, [ypxq+strideq*0+ 0]
mova m1, [ypxq+strideq*1+ 0]
cmp wpadd, 2
jl .w16_wpad1
je .w16_wpad2
vpbroadcastd m2, [ypxq+strideq*0+12]
vpbroadcastd m3, [ypxq+strideq*1+12]
vpblendd m0, m2, 0xf0
vpblendd m1, m3, 0xf0
jmp .w16_wpad_end
.w16_wpad2:
vpbroadcastd m2, [ypxq+strideq*0+28]
vpbroadcastd m3, [ypxq+strideq*1+28]
jmp .w16_wpad_end
.w16_wpad1:
vpbroadcastd m2, [ypxq+strideq*0+44]
vpbroadcastd m3, [ypxq+strideq*1+44]
vinserti128 m2, [ypxq+strideq*0+32], 0
vinserti128 m3, [ypxq+strideq*1+32], 0
.w16_wpad_end:
lea ypxq, [ypxq+strideq*2]
REPX {pmaddwd x, m5}, m0, m1, m2, m3
paddd m0, m1
paddd m2, m3
packssdw m1, m0, m2
paddd m0, m2
vpermq m1, m1, q3120
paddd m4, m0
mova [acq], m1
add acq, 32
dec hd
jg .w16_wpad
jmp .w16_hpad
.w16:
mov r5, acq
test wpadd, wpadd
jnz .w16_wpad
.w16_loop:
pmaddwd m0, m5, [ypxq+strideq*0+ 0]
pmaddwd m2, m5, [ypxq+strideq*0+32]
pmaddwd m1, m5, [ypxq+strideq*1+ 0]
pmaddwd m3, m5, [ypxq+strideq*1+32]
lea ypxq, [ypxq+strideq*2]
paddd m0, m1
paddd m2, m3
packssdw m1, m0, m2
paddd m0, m2
vpermq m1, m1, q3120
paddd m4, m0
mova [acq], m1
add acq, 32
dec hd
jg .w16_loop
.w16_hpad:
add hpadd, hpadd
jz .dc
paddd m0, m0
.hpad:
mova [acq+32*0], m1
paddd m4, m0
mova [acq+32*1], m1
add acq, 32*2
sub hpadd, 4
jg .hpad
.dc:
vextracti128 xm1, m4, 1
sub r5, acq ; -w*h*2
tzcnt r1d, r5d
paddd xm4, xm1
sub r1d, 2
punpckhqdq xm1, xm4, xm4
movd xm0, r1d
paddd xm1, xm4
pshuflw xm4, xm1, q1032
paddd xm1, xm4
psrld xm1, xm0
pxor xm0, xm0
pavgw xm1, xm0
vpbroadcastw m1, xm1
.dc_loop:
mova m0, [acq+r5]
psubw m0, m1
mova [acq+r5], m0
add r5, 32
jl .dc_loop
RET
cglobal ipred_cfl_ac_422_16bpc, 4, 7, 6, ac, ypx, stride, wpad, hpad, w, h
movifnidn hpadd, hpadm
vpbroadcastd m5, [pw_4]
mov hd, hm
shl hpadd, 2
pxor m4, m4
sub hd, hpadd
cmp dword wm, 8
jg .w16
je .w8
.w4:
lea r3, [strideq*3]
mov r5, acq
.w4_loop:
mova xm0, [ypxq+strideq*0]
mova xm1, [ypxq+strideq*1]
vinserti128 m0, [ypxq+strideq*2], 1
vinserti128 m1, [ypxq+r3 ], 1
lea ypxq, [ypxq+strideq*4]
pmaddwd m0, m5
pmaddwd m1, m5
paddd m4, m0
packssdw m0, m1
paddd m4, m1
mova [acq], m0
add acq, 32
sub hd, 4
jg .w4_loop
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
vextracti128 xm1, m1, 1
vpermq m0, m0, q3333
pslld xm1, 2
.w4_hpad_loop:
mova [acq], m0
paddd m4, m1
add acq, 32
sub hpadd, 4
jg .w4_hpad_loop
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
.w8:
mov r5, acq
test wpadd, wpadd
jnz .w8_wpad1
.w8_loop:
pmaddwd m1, m5, [ypxq+strideq*0]
pmaddwd m0, m5, [ypxq+strideq*1]
lea ypxq, [ypxq+strideq*2]
paddd m4, m1
packssdw m1, m0
paddd m4, m0
vpermq m2, m1, q3120
mova [acq], m2
add acq, 32
sub hd, 2
jg .w8_loop
.w8_hpad:
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
vpermq m1, m1, q3131
pslld m0, 2
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).hpad
.w8_wpad1:
vpbroadcastd m1, [ypxq+strideq*0+12]
vpbroadcastd m0, [ypxq+strideq*1+12]
vinserti128 m1, [ypxq+strideq*0+ 0], 0
vinserti128 m0, [ypxq+strideq*1+ 0], 0
lea ypxq, [ypxq+strideq*2]
pmaddwd m1, m5
pmaddwd m0, m5
paddd m4, m1
packssdw m1, m0
paddd m4, m0
vpermq m2, m1, q3120
mova [acq], m2
add acq, 32
sub hd, 2
jg .w8_wpad1
jmp .w8_hpad
.w16:
mov r5, acq
test wpadd, wpadd
jnz .w16_wpad
.w16_loop:
pmaddwd m2, m5, [ypxq+strideq*0+ 0]
pmaddwd m1, m5, [ypxq+strideq*0+32]
pmaddwd m0, m5, [ypxq+strideq*1+ 0]
pmaddwd m3, m5, [ypxq+strideq*1+32]
lea ypxq, [ypxq+strideq*2]
paddd m4, m2
packssdw m2, m1
paddd m4, m1
packssdw m1, m0, m3
paddd m0, m3
vpermq m2, m2, q3120
paddd m4, m0
vpermq m1, m1, q3120
mova [acq+32*0], m2
mova [acq+32*1], m1
add acq, 32*2
sub hd, 2
jg .w16_loop
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).w16_hpad
.w16_wpad:
mova m2, [ypxq+strideq*0+ 0]
mova m0, [ypxq+strideq*1+ 0]
cmp wpadd, 2
jl .w16_wpad1
je .w16_wpad2
vpbroadcastd m1, [ypxq+strideq*0+12]
vpbroadcastd m3, [ypxq+strideq*1+12]
vpblendd m2, m1, 0xf0
vpblendd m0, m3, 0xf0
jmp .w16_wpad_end
.w16_wpad2:
vpbroadcastd m1, [ypxq+strideq*0+28]
vpbroadcastd m3, [ypxq+strideq*1+28]
jmp .w16_wpad_end
.w16_wpad1:
vpbroadcastd m1, [ypxq+strideq*0+44]
vpbroadcastd m3, [ypxq+strideq*1+44]
vinserti128 m1, [ypxq+strideq*0+32], 0
vinserti128 m3, [ypxq+strideq*1+32], 0
.w16_wpad_end:
lea ypxq, [ypxq+strideq*2]
REPX {pmaddwd x, m5}, m2, m0, m1, m3
paddd m4, m2
packssdw m2, m1
paddd m4, m1
packssdw m1, m0, m3
paddd m0, m3
vpermq m2, m2, q3120
paddd m4, m0
vpermq m1, m1, q3120
mova [acq+32*0], m2
mova [acq+32*1], m1
add acq, 32*2
sub hd, 2
jg .w16_wpad
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).w16_hpad
cglobal ipred_cfl_ac_444_16bpc, 4, 7, 6, ac, ypx, stride, wpad, hpad, w, h
lea r6, [ipred_cfl_ac_444_16bpc_avx2_table]
tzcnt wd, wm
movifnidn hpadd, hpadm
vpbroadcastd m5, [pw_1]
movsxd wq, [r6+wq*4]
shl hpadd, 2
add wq, r6
mov hd, hm
pxor m4, m4
sub hd, hpadd
jmp wq
.w4:
lea r3, [strideq*3]
mov r5, acq
.w4_loop:
movq xm0, [ypxq+strideq*0]
movhps xm0, [ypxq+strideq*1]
vpbroadcastq m1, [ypxq+strideq*2]
vpbroadcastq m2, [ypxq+r3 ]
lea ypxq, [ypxq+strideq*4]
vpblendd m0, m1, 0x30
vpblendd m0, m2, 0xc0
psllw m0, 3
pmaddwd m1, m0, m5
mova [acq], m0
add acq, 32
paddd m4, m1
sub hd, 4
jg .w4_loop
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
vpermq m0, m0, q3333
paddd m1, m1
mova [acq+32*0], m0
vpermq m1, m1, q3333
mova [acq+32*1], m0
add acq, 32*2
paddd m4, m1
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
.w8:
lea r3, [strideq*3]
mov r5, acq
.w8_loop:
mova xm2, [ypxq+strideq*0]
vinserti128 m2, [ypxq+strideq*1], 1
mova xm1, [ypxq+strideq*2]
vinserti128 m1, [ypxq+r3 ], 1
lea ypxq, [ypxq+strideq*4]
psllw m2, 3
psllw m1, 3
mova [acq+32*0], m2
pmaddwd m2, m5
mova [acq+32*1], m1
pmaddwd m0, m1, m5
add acq, 32*2
paddd m4, m2
paddd m4, m0
sub hd, 4
jg .w8_loop
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
vperm2i128 m1, m1, 0x11
pslld m0, 2
pxor m2, m2
vpblendd m0, m2, 0x0f
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).hpad
.w16_wpad2:
vpbroadcastw m3, [ypxq+strideq*0+14]
vpbroadcastw m0, [ypxq+strideq*1+14]
vpblendd m2, m3, 0xf0
vpblendd m1, m0, 0xf0
jmp .w16_wpad_end
.w16:
mov r5, acq
.w16_loop:
mova m2, [ypxq+strideq*0]
mova m1, [ypxq+strideq*1]
test wpadd, wpadd
jnz .w16_wpad2
.w16_wpad_end:
lea ypxq, [ypxq+strideq*2]
psllw m2, 3
psllw m1, 3
mova [acq+32*0], m2
pmaddwd m2, m5
mova [acq+32*1], m1
pmaddwd m0, m1, m5
add acq, 32*2
paddd m4, m2
paddd m4, m0
sub hd, 2
jg .w16_loop
add hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
paddd m0, m0
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).hpad
.w32:
mov r5, acq
test wpadd, wpadd
jnz .w32_wpad
.w32_loop:
mova m0, [ypxq+ 0]
mova m1, [ypxq+32]
add ypxq, strideq
psllw m0, 3
psllw m1, 3
pmaddwd m2, m0, m5
mova [acq+32*0], m0
pmaddwd m3, m1, m5
mova [acq+32*1], m1
add acq, 32*2
paddd m2, m3
paddd m4, m2
dec hd
jg .w32_loop
.w32_hpad:
test hpadd, hpadd
jz mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
paddd m2, m2
.w32_hpad_loop:
mova [acq+32*0], m0
mova [acq+32*1], m1
paddd m4, m2
mova [acq+32*2], m0
mova [acq+32*3], m1
add acq, 32*4
sub hpadd, 2
jg .w32_hpad_loop
jmp mangle(private_prefix %+ _ipred_cfl_ac_420_16bpc_avx2).dc
.w32_wpad:
mova m0, [ypxq+ 0]
cmp wpadd, 4
jl .w32_wpad2
je .w32_wpad4
vpbroadcastw m1, [ypxq+14]
vpblendd m0, m1, 0xf0
jmp .w32_wpad_end
.w32_wpad4:
vpbroadcastw m1, [ypxq+30]
jmp .w32_wpad_end
.w32_wpad2:
vpbroadcastw m1, [ypxq+46]
vinserti128 m1, [ypxq+32], 0
.w32_wpad_end:
add ypxq, strideq
psllw m0, 3
psllw m1, 3
pmaddwd m2, m0, m5
mova [acq+32*0], m0
pmaddwd m3, m1, m5
mova [acq+32*1], m1
add acq, 32*2
paddd m2, m3
paddd m4, m2
dec hd
jg .w32_wpad
jmp .w32_hpad
cglobal pal_pred_16bpc, 4, 6, 6, dst, stride, pal, idx, w, h
vbroadcasti128 m4, [palq]
lea r2, [pal_pred_16bpc_avx2_table]
tzcnt wd, wm
vbroadcasti128 m5, [pal_pred_shuf]
movifnidn hd, hm
movsxd wq, [r2+wq*4]
pshufb m4, m5
punpckhqdq m5, m4, m4
add wq, r2
DEFINE_ARGS dst, stride, stride3, idx, w, h
lea stride3q, [strideq*3]
jmp wq
.w4:
movq xm0, [idxq]
add idxq, 8
psrlw xm1, xm0, 4
punpcklbw xm0, xm1
pshufb xm1, xm4, xm0
pshufb xm2, xm5, xm0
punpcklbw xm0, xm1, xm2
punpckhbw xm1, xm2
movq [dstq+strideq*0], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+strideq*1], xm0
movhps [dstq+stride3q ], xm1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w4
RET
.w8:
pmovzxbw m2, [idxq]
add idxq, 16
psllw m1, m2, 4
por m2, m1
pshufb m1, m4, m2
pshufb m2, m5, m2
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+strideq*0], xm0
mova [dstq+strideq*1], xm1
vextracti128 [dstq+strideq*2], m0, 1
vextracti128 [dstq+stride3q ], m1, 1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w8
RET
.w16:
pshufd m3, [idxq], q3120
add idxq, 32
vpermq m3, m3, q3120
psrlw m1, m3, 4
punpcklbw m2, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m2
pshufb m2, m5, m2
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
pshufb m1, m4, m3
pshufb m3, m5, m3
punpcklbw m0, m1, m3
punpckhbw m1, m3
mova [dstq+strideq*2], m0
mova [dstq+stride3q ], m1
lea dstq, [dstq+strideq*4]
sub hd, 4
jg .w16
RET
.w32:
pshufd m3, [idxq], q3120
add idxq, 32
vpermq m3, m3, q3120
psrlw m1, m3, 4
punpcklbw m2, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m2
pshufb m2, m5, m2
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+ 0], m0
mova [dstq+32], m1
pshufb m1, m4, m3
pshufb m3, m5, m3
punpcklbw m0, m1, m3
punpckhbw m1, m3
mova [dstq+strideq+ 0], m0
mova [dstq+strideq+32], m1
lea dstq, [dstq+strideq*2]
sub hd, 2
jg .w32
RET
.w64:
pshufd m3, [idxq], q3120
add idxq, 32
vpermq m3, m3, q3120
psrlw m1, m3, 4
punpcklbw m2, m3, m1
punpckhbw m3, m1
pshufb m1, m4, m2
pshufb m2, m5, m2
punpcklbw m0, m1, m2
punpckhbw m1, m2
mova [dstq+32*0], m0
mova [dstq+32*1], m1
pshufb m1, m4, m3
pshufb m3, m5, m3
punpcklbw m0, m1, m3
punpckhbw m1, m3
mova [dstq+32*2], m0
mova [dstq+32*3], m1
add dstq, strideq
dec hd
jg .w64
RET
%endif
|