summaryrefslogtreecommitdiffstats
path: root/media/ffvpx/libavcodec/aarch64/vp8dsp_neon.S
blob: 4bbf16d1a4c7f1db75bec8fa8785e03510b8d1a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
/*
 * VP8 NEON optimisations
 *
 * Copyright (c) 2010 Rob Clark <rob@ti.com>
 * Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
 * Copyright (c) 2018 Magnus Röös <mla2.roos@gmail.com>
 * Copyright (c) 2019 Martin Storsjo <martin@martin.st>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libavutil/aarch64/asm.S"
#include "neon.S"

function ff_vp8_luma_dc_wht_neon, export=1
        ld1             {v0.4h - v3.4h}, [x1]
        movi            v30.8h, #0

        add             v4.4h,  v0.4h,  v3.4h
        add             v6.4h,  v1.4h,  v2.4h
        st1             {v30.8h}, [x1], #16
        sub             v7.4h,  v1.4h,  v2.4h
        sub             v5.4h,  v0.4h,  v3.4h
        st1             {v30.8h}, [x1]
        add             v0.4h,  v4.4h,  v6.4h
        add             v1.4h,  v5.4h,  v7.4h
        sub             v2.4h,  v4.4h,  v6.4h
        sub             v3.4h,  v5.4h,  v7.4h

        movi            v16.4h, #3

        transpose_4x4H  v0, v1, v2, v3, v4, v5, v6, v7

        add             v0.4h,  v0.4h,  v16.4h

        add             v4.4h,  v0.4h,  v3.4h
        add             v6.4h,  v1.4h,  v2.4h
        sub             v7.4h,  v1.4h,  v2.4h
        sub             v5.4h,  v0.4h,  v3.4h
        add             v0.4h,  v4.4h,  v6.4h
        add             v1.4h,  v5.4h,  v7.4h
        sub             v2.4h,  v4.4h,  v6.4h
        sub             v3.4h,  v5.4h,  v7.4h

        sshr            v0.4h,  v0.4h,  #3
        sshr            v1.4h,  v1.4h,  #3
        sshr            v2.4h,  v2.4h,  #3
        sshr            v3.4h,  v3.4h,  #3

        mov             x3,  #32
        st1             {v0.h}[0],  [x0], x3
        st1             {v1.h}[0],  [x0], x3
        st1             {v2.h}[0],  [x0], x3
        st1             {v3.h}[0],  [x0], x3
        st1             {v0.h}[1],  [x0], x3
        st1             {v1.h}[1],  [x0], x3
        st1             {v2.h}[1],  [x0], x3
        st1             {v3.h}[1],  [x0], x3
        st1             {v0.h}[2],  [x0], x3
        st1             {v1.h}[2],  [x0], x3
        st1             {v2.h}[2],  [x0], x3
        st1             {v3.h}[2],  [x0], x3
        st1             {v0.h}[3],  [x0], x3
        st1             {v1.h}[3],  [x0], x3
        st1             {v2.h}[3],  [x0], x3
        st1             {v3.h}[3],  [x0], x3

        ret
endfunc

function ff_vp8_idct_add_neon, export=1
        ld1             {v0.8b - v3.8b},  [x1]
        mov             w4,  #20091
        movk            w4,  #35468/2, lsl #16
        dup             v4.2s, w4

        smull           v26.4s, v1.4h,  v4.h[0]
        smull           v27.4s, v3.4h,  v4.h[0]
        sqdmulh         v20.4h, v1.4h,  v4.h[1]
        sqdmulh         v23.4h, v3.4h,  v4.h[1]
        shrn            v21.4h, v26.4s, #16
        shrn            v22.4h, v27.4s, #16
        add             v21.4h, v21.4h, v1.4h
        add             v22.4h, v22.4h, v3.4h

        add             v16.4h,  v0.4h,   v2.4h
        sub             v17.4h,  v0.4h,   v2.4h

        add             v18.4h,  v21.4h,  v23.4h
        sub             v19.4h,  v20.4h,  v22.4h

        add             v0.4h,   v16.4h,  v18.4h
        add             v1.4h,   v17.4h,  v19.4h
        sub             v3.4h,   v16.4h,  v18.4h
        sub             v2.4h,   v17.4h,  v19.4h

        transpose_4x4H  v0, v1, v2, v3, v24, v5, v6, v7

        movi            v29.8h, #0
        smull           v26.4s,     v1.4h,  v4.h[0]
        st1             {v29.8h},   [x1],   #16
        smull           v27.4s,     v3.4h,  v4.h[0]
        st1             {v29.16b},  [x1]
        sqdmulh         v21.4h,     v1.4h,  v4.h[1]
        sqdmulh         v23.4h,     v3.4h,  v4.h[1]
        shrn            v20.4h,     v26.4s, #16
        shrn            v22.4h,     v27.4s, #16
        add             v20.4h,     v20.4h, v1.4h
        add             v22.4h,     v22.4h, v3.4h
        add             v16.4h,     v0.4h,  v2.4h
        sub             v17.4h,     v0.4h,  v2.4h

        add             v18.4h,     v20.4h, v23.4h
        ld1             {v24.s}[0], [x0],   x2
        sub             v19.4h, v21.4h, v22.4h
        ld1             {v25.s}[0], [x0],   x2
        add             v0.4h,      v16.4h, v18.4h
        add             v1.4h,      v17.4h, v19.4h
        ld1             {v26.s}[0], [x0],   x2
        sub             v3.4h,      v16.4h, v18.4h
        sub             v2.4h,      v17.4h, v19.4h
        ld1             {v27.s}[0], [x0],   x2
        srshr           v0.4h,      v0.4h,  #3
        srshr           v1.4h,      v1.4h,  #3
        srshr           v2.4h,      v2.4h,  #3
        srshr           v3.4h,      v3.4h,  #3

        sub             x0,  x0,  x2,  lsl #2

        transpose_4x4H  v0, v1, v2, v3, v5, v6, v7, v16

        uaddw           v0.8h,  v0.8h, v24.8b
        uaddw           v1.8h,  v1.8h, v25.8b
        uaddw           v2.8h,  v2.8h, v26.8b
        uaddw           v3.8h,  v3.8h, v27.8b
        sqxtun          v0.8b,  v0.8h
        sqxtun          v1.8b,  v1.8h
        sqxtun          v2.8b,  v2.8h
        sqxtun          v3.8b,  v3.8h

        st1             {v0.s}[0],  [x0], x2
        st1             {v1.s}[0],  [x0], x2
        st1             {v2.s}[0],  [x0], x2
        st1             {v3.s}[0],  [x0], x2

        ret
endfunc

function ff_vp8_idct_dc_add4uv_neon, export=1
        movi            v0.4h,  #0
        mov             x3,     #32
        ld1r            {v16.4h},  [x1]
        st1             {v0.h}[0], [x1], x3
        ld1r            {v17.4h},  [x1]
        st1             {v0.h}[0], [x1], x3
        ld1r            {v18.4h},  [x1]
        st1             {v0.h}[0], [x1], x3
        ld1r            {v19.4h},  [x1]
        st1             {v0.h}[0], [x1], x3
        ins             v16.d[1],  v17.d[0]
        ins             v18.d[1],  v19.d[0]
        mov             x3,  x0
        srshr           v16.8h,    v16.8h,  #3            // dc >>= 3
        ld1             {v0.8b},   [x0], x2
        srshr           v18.8h,    v18.8h,  #3
        ld1             {v1.8b},   [x0], x2
        uaddw           v20.8h,    v16.8h, v0.8b
        ld1             {v2.8b},   [x0], x2
        uaddw           v0.8h,     v16.8h, v1.8b
        ld1             {v3.8b},   [x0], x2
        uaddw           v22.8h,    v16.8h, v2.8b
        ld1             {v4.8b},   [x0], x2
        uaddw           v2.8h,     v16.8h, v3.8b
        ld1             {v5.8b},   [x0], x2
        uaddw           v24.8h,    v18.8h, v4.8b
        ld1             {v6.8b},   [x0], x2
        uaddw           v4.8h,     v18.8h, v5.8b
        ld1             {v7.8b},   [x0], x2
        uaddw           v26.8h,    v18.8h, v6.8b
        sqxtun          v20.8b,    v20.8h
        uaddw           v6.8h,     v18.8h, v7.8b
        sqxtun          v21.8b,    v0.8h
        sqxtun          v22.8b,    v22.8h
        st1             {v20.8b},  [x3], x2
        sqxtun          v23.8b,    v2.8h
        st1             {v21.8b},  [x3], x2
        sqxtun          v24.8b,    v24.8h
        st1             {v22.8b},  [x3], x2
        sqxtun          v25.8b,    v4.8h
        st1             {v23.8b},  [x3], x2
        sqxtun          v26.8b,    v26.8h
        st1             {v24.8b},  [x3], x2
        sqxtun          v27.8b,    v6.8h
        st1             {v25.8b},  [x3], x2
        st1             {v26.8b},  [x3], x2
        st1             {v27.8b},  [x3], x2

        ret
endfunc

function ff_vp8_idct_dc_add4y_neon, export=1
        movi            v0.16b,  #0
        mov             x3,  #32
        ld1r            {v16.4h},    [x1]
        st1             {v0.h}[0],   [x1], x3
        ld1r            {v17.4h},    [x1]
        st1             {v0.h}[0],   [x1], x3
        zip1            v16.2d,      v16.2d, v17.2d
        ld1r            {v18.4h},    [x1]
        st1             {v0.h}[0],   [x1], x3
        ld1r            {v19.4h},    [x1]
        st1             {v0.h}[0],   [x1], x3
        zip1            v18.2d,      v18.2d, v19.2d
        srshr           v16.8h,      v16.8h,  #3            // dc >>= 3
        ld1             {v0.16b},     [x0], x2
        srshr           v18.8h,       v18.8h,  #3
        ld1             {v1.16b},     [x0], x2
        uaddw           v20.8h,       v16.8h,  v0.8b
        ld1             {v2.16b},     [x0], x2
        uaddw2          v0.8h,        v18.8h,   v0.16b
        ld1             {v3.16b},     [x0], x2
        uaddw           v21.8h, v16.8h,  v1.8b
        uaddw2          v1.8h,  v18.8h,  v1.16b
        uaddw           v22.8h, v16.8h,  v2.8b
        uaddw2          v2.8h,  v18.8h,  v2.16b
        uaddw           v23.8h, v16.8h,  v3.8b
        uaddw2          v3.8h,  v18.8h,  v3.16b
        sub             x0,  x0,  x2,  lsl #2
        sqxtun          v20.8b,  v20.8h
        sqxtun2         v20.16b, v0.8h
        sqxtun          v21.8b,  v21.8h
        sqxtun2         v21.16b, v1.8h
        sqxtun          v22.8b,  v22.8h
        st1             {v20.16b},    [x0], x2
        sqxtun2         v22.16b, v2.8h
        st1             {v21.16b},    [x0], x2
        sqxtun          v23.8b,  v23.8h
        st1             {v22.16b},    [x0], x2
        sqxtun2         v23.16b, v3.8h
        st1             {v23.16b},    [x0], x2

        ret
endfunc

function ff_vp8_idct_dc_add_neon, export=1
        mov             w3,       #0
        ld1r            {v2.8h},  [x1]
        strh            w3,       [x1]
        srshr           v2.8h,  v2.8h,  #3
        ld1             {v0.s}[0],  [x0], x2
        ld1             {v0.s}[1],  [x0], x2
        uaddw           v3.8h,  v2.8h,  v0.8b
        ld1             {v1.s}[0],  [x0], x2
        ld1             {v1.s}[1],  [x0], x2
        uaddw           v4.8h,  v2.8h,  v1.8b
        sqxtun          v0.8b,  v3.8h
        sqxtun          v1.8b,  v4.8h
        sub             x0,  x0,  x2, lsl #2
        st1             {v0.s}[0],  [x0], x2
        st1             {v0.s}[1],  [x0], x2
        st1             {v1.s}[0],  [x0], x2
        st1             {v1.s}[1],  [x0], x2
        ret
endfunc

// Register layout:
//   P3..Q3 -> v0..v7
//   flim_E -> v22
//   flim_I -> v23
//   hev_thresh -> x5
//
.macro  vp8_loop_filter, inner=0, simple=0, hev_thresh
    .if \simple
        uabd            v17.16b, v3.16b,  v4.16b      // abs(P0-Q0)
        uabd            v23.16b, v2.16b,  v5.16b      // abs(P1-Q1)
        uqadd           v17.16b, v17.16b, v17.16b     // abs(P0-Q0) * 2
        ushr            v18.16b, v23.16b, #1          // abs(P1-Q1) / 2
        uqadd           v19.16b, v17.16b,  v18.16b    // (abs(P0-Q0)*2) + (abs(P1-Q1)/2)
        movi            v21.16b, #0x80
        cmhs            v16.16b, v22.16b, v19.16b    // (abs(P0-Q0)*2) + (abs(P1-Q1)/2) <= flim
    .else
        // calculate hev and normal_limit:
        uabd            v20.16b, v2.16b,  v3.16b      // abs(P1-P0)
        uabd            v21.16b, v5.16b,  v4.16b      // abs(Q1-Q0)
        uabd            v18.16b, v0.16b,  v1.16b      // abs(P3-P2)
        uabd            v19.16b, v1.16b,  v2.16b      // abs(P2-P1)
        cmhs            v16.16b, v23.16b, v20.16b     // abs(P1-P0) <= flim_I
        cmhs            v17.16b, v23.16b, v21.16b     // abs(Q1-Q0) <= flim_I
        cmhs            v18.16b, v23.16b, v18.16b     // abs(P3-P2) <= flim_I
        cmhs            v19.16b, v23.16b, v19.16b     // abs(P2-P1) <= flim_I
        and             v16.16b, v17.16b, v16.16b
        uabd            v17.16b, v7.16b,  v6.16b      // abs(Q3-Q2)
        and             v16.16b, v16.16b, v19.16b
        uabd            v19.16b, v6.16b,  v5.16b      // abs(Q2-Q1)
        and             v16.16b, v16.16b, v18.16b
        cmhs            v18.16b, v23.16b, v17.16b     // abs(Q3-Q2) <= flim_I
        cmhs            v19.16b, v23.16b, v19.16b     // abs(Q2-Q1) <= flim_I
        uabd            v17.16b, v3.16b,  v4.16b      // abs(P0-Q0)
        uabd            v23.16b, v2.16b,  v5.16b      // abs(P1-Q1)
        and             v16.16b, v16.16b, v18.16b
        uqadd           v17.16b, v17.16b, v17.16b     // abs(P0-Q0) * 2
        and             v16.16b, v16.16b, v19.16b
        ushr            v18.16b, v23.16b, #1          // abs(P1-Q1) / 2
        dup             v23.16b, \hev_thresh          // hev_thresh
        uqadd           v19.16b, v17.16b, v18.16b     // (abs(P0-Q0)*2) + (abs(P1-Q1)/2)
        cmhi            v20.16b, v20.16b, v23.16b     // abs(P1-P0) > hev_thresh
        cmhs            v19.16b, v22.16b, v19.16b     // (abs(P0-Q0)*2) + (abs(P1-Q1)/2) <= flim_E
        cmhi            v22.16b, v21.16b, v23.16b     // abs(Q1-Q0) > hev_thresh
        and             v16.16b, v16.16b, v19.16b
        movi            v21.16b, #0x80
        orr             v17.16b, v20.16b, v22.16b
    .endif

        // at this point:
        //   v16: normal_limit
        //   v17: hev

        // convert to signed value:
        eor            v3.16b, v3.16b, v21.16b           // PS0 = P0 ^ 0x80
        eor            v4.16b, v4.16b, v21.16b           // QS0 = Q0 ^ 0x80

        movi           v20.8h, #3
        ssubl          v18.8h, v4.8b,  v3.8b             // QS0 - PS0
        ssubl2         v19.8h, v4.16b, v3.16b            //   (widened to 16bit)
        eor            v2.16b, v2.16b, v21.16b           // PS1 = P1 ^ 0x80
        eor            v5.16b, v5.16b, v21.16b           // QS1 = Q1 ^ 0x80
        mul            v18.8h, v18.8h, v20.8h            // w = 3 * (QS0 - PS0)
        mul            v19.8h, v19.8h, v20.8h

        sqsub          v20.16b, v2.16b, v5.16b           // clamp(PS1-QS1)
        movi           v22.16b, #4
        movi           v23.16b, #3
    .if \inner
        and            v20.16b, v20.16b, v17.16b         // if(hev) w += clamp(PS1-QS1)
    .endif
        saddw          v18.8h,  v18.8h, v20.8b           // w += clamp(PS1-QS1)
        saddw2         v19.8h,  v19.8h, v20.16b
        sqxtn          v18.8b,  v18.8h                   // narrow result back into v18
        sqxtn2         v18.16b, v19.8h
    .if !\inner && !\simple
        eor            v1.16b,  v1.16b,  v21.16b         // PS2 = P2 ^ 0x80
        eor            v6.16b,  v6.16b,  v21.16b         // QS2 = Q2 ^ 0x80
    .endif
        and            v18.16b, v18.16b, v16.16b         // w &= normal_limit

        // registers used at this point..
        //   v0 -> P3  (don't corrupt)
        //   v1-v6 -> PS2-QS2
        //   v7 -> Q3  (don't corrupt)
        //   v17 -> hev
        //   v18 -> w
        //   v21 -> #0x80
        //   v22 -> #4
        //   v23 -> #3
        //   v16, v19, v29 -> unused
        //
        // filter_common:   is4tap==1
        //   c1 = clamp(w + 4) >> 3;
        //   c2 = clamp(w + 3) >> 3;
        //   Q0 = s2u(QS0 - c1);
        //   P0 = s2u(PS0 + c2);

    .if \simple
        sqadd          v19.16b, v18.16b, v22.16b           // c1 = clamp((w&hev)+4)
        sqadd          v20.16b, v18.16b, v23.16b           // c2 = clamp((w&hev)+3)
        sshr           v19.16b, v19.16b, #3                // c1 >>= 3
        sshr           v20.16b, v20.16b, #3                // c2 >>= 3
        sqsub          v4.16b,  v4.16b,  v19.16b           // QS0 = clamp(QS0-c1)
        sqadd          v3.16b,  v3.16b,  v20.16b           // PS0 = clamp(PS0+c2)
        eor            v4.16b,  v4.16b,  v21.16b           // Q0 = QS0 ^ 0x80
        eor            v3.16b,  v3.16b,  v21.16b           // P0 = PS0 ^ 0x80
        eor            v5.16b,  v5.16b,  v21.16b           // Q1 = QS1 ^ 0x80
        eor            v2.16b,  v2.16b,  v21.16b           // P1 = PS1 ^ 0x80
    .elseif \inner
        // the !is4tap case of filter_common, only used for inner blocks
        //   c3 = ((c1&~hev) + 1) >> 1;
        //   Q1 = s2u(QS1 - c3);
        //   P1 = s2u(PS1 + c3);
        sqadd          v19.16b, v18.16b, v22.16b           // c1 = clamp((w&hev)+4)
        sqadd          v20.16b, v18.16b, v23.16b           // c2 = clamp((w&hev)+3)
        sshr           v19.16b, v19.16b, #3                // c1 >>= 3
        sshr           v20.16b, v20.16b, #3                // c2 >>= 3
        sqsub          v4.16b,  v4.16b,  v19.16b           // QS0 = clamp(QS0-c1)
        sqadd          v3.16b,  v3.16b,  v20.16b           // PS0 = clamp(PS0+c2)
        bic            v19.16b, v19.16b, v17.16b           // c1 & ~hev
        eor            v4.16b,  v4.16b,  v21.16b           // Q0 = QS0 ^ 0x80
        srshr          v19.16b, v19.16b, #1                // c3 >>= 1
        eor            v3.16b,  v3.16b,  v21.16b           // P0 = PS0 ^ 0x80
        sqsub          v5.16b,  v5.16b,  v19.16b           // QS1 = clamp(QS1-c3)
        sqadd          v2.16b,  v2.16b,  v19.16b           // PS1 = clamp(PS1+c3)
        eor            v5.16b,  v5.16b,  v21.16b           // Q1 = QS1 ^ 0x80
        eor            v2.16b,  v2.16b,  v21.16b           // P1 = PS1 ^ 0x80
    .else
        and            v20.16b, v18.16b, v17.16b           // w & hev
        sqadd          v19.16b, v20.16b, v22.16b           // c1 = clamp((w&hev)+4)
        sqadd          v20.16b, v20.16b, v23.16b           // c2 = clamp((w&hev)+3)
        sshr           v19.16b, v19.16b, #3                // c1 >>= 3
        sshr           v20.16b, v20.16b, #3                // c2 >>= 3
        bic            v18.16b, v18.16b, v17.16b           // w &= ~hev
        sqsub          v4.16b,  v4.16b,  v19.16b           // QS0 = clamp(QS0-c1)
        sqadd          v3.16b,  v3.16b,  v20.16b           // PS0 = clamp(PS0+c2)

        // filter_mbedge:
        //   a = clamp((27*w + 63) >> 7);
        //   Q0 = s2u(QS0 - a);
        //   P0 = s2u(PS0 + a);
        //   a = clamp((18*w + 63) >> 7);
        //   Q1 = s2u(QS1 - a);
        //   P1 = s2u(PS1 + a);
        //   a = clamp((9*w + 63) >> 7);
        //   Q2 = s2u(QS2 - a);
        //   P2 = s2u(PS2 + a);
        movi           v17.8h,  #63
        sshll          v22.8h,  v18.8b, #3
        sshll2         v23.8h,  v18.16b, #3
        saddw          v22.8h,  v22.8h, v18.8b
        saddw2         v23.8h,  v23.8h, v18.16b
        add            v16.8h,  v17.8h, v22.8h
        add            v17.8h,  v17.8h, v23.8h           //  9*w + 63
        add            v19.8h,  v16.8h, v22.8h
        add            v20.8h,  v17.8h, v23.8h           // 18*w + 63
        add            v22.8h,  v19.8h, v22.8h
        add            v23.8h,  v20.8h, v23.8h           // 27*w + 63
        sqshrn         v16.8b,  v16.8h,  #7
        sqshrn2        v16.16b, v17.8h, #7              // clamp(( 9*w + 63)>>7)
        sqshrn         v19.8b,  v19.8h, #7
        sqshrn2        v19.16b, v20.8h, #7              // clamp((18*w + 63)>>7)
        sqshrn         v22.8b,  v22.8h, #7
        sqshrn2        v22.16b, v23.8h, #7              // clamp((27*w + 63)>>7)
        sqadd          v1.16b,  v1.16b,  v16.16b        // PS2 = clamp(PS2+a)
        sqsub          v6.16b,  v6.16b,  v16.16b        // QS2 = clamp(QS2-a)
        sqadd          v2.16b,  v2.16b,  v19.16b        // PS1 = clamp(PS1+a)
        sqsub          v5.16b,  v5.16b,  v19.16b        // QS1 = clamp(QS1-a)
        sqadd          v3.16b,  v3.16b,  v22.16b        // PS0 = clamp(PS0+a)
        sqsub          v4.16b,  v4.16b,  v22.16b        // QS0 = clamp(QS0-a)
        eor            v3.16b,  v3.16b,  v21.16b        // P0 = PS0 ^ 0x80
        eor            v4.16b,  v4.16b,  v21.16b        // Q0 = QS0 ^ 0x80
        eor            v2.16b,  v2.16b,  v21.16b        // P1 = PS1 ^ 0x80
        eor            v5.16b,  v5.16b,  v21.16b        // Q1 = QS1 ^ 0x80
        eor            v1.16b,  v1.16b,  v21.16b        // P2 = PS2 ^ 0x80
        eor            v6.16b,  v6.16b,  v21.16b        // Q2 = QS2 ^ 0x80
    .endif
.endm

.macro  vp8_v_loop_filter16 name, inner=0, simple=0
function ff_vp8_v_loop_filter16\name\()_neon, export=1
        sub             x0,  x0,  x1,  lsl #1+!\simple

        // Load pixels:
    .if !\simple
        ld1             {v0.16b},     [x0], x1 // P3
        ld1             {v1.16b},     [x0], x1 // P2
    .endif
        ld1             {v2.16b},     [x0], x1 // P1
        ld1             {v3.16b},     [x0], x1 // P0
        ld1             {v4.16b},     [x0], x1 // Q0
        ld1             {v5.16b},     [x0], x1 // Q1
    .if !\simple
        ld1             {v6.16b},     [x0], x1 // Q2
        ld1             {v7.16b},     [x0]     // Q3
        dup             v23.16b, w3                 // flim_I
    .endif
        dup             v22.16b, w2                 // flim_E

        vp8_loop_filter inner=\inner, simple=\simple, hev_thresh=w4

        // back up to P2:  dst -= stride * 6
        sub             x0,  x0,  x1,  lsl #2
    .if !\simple
        sub             x0,  x0,  x1,  lsl #1

        // Store pixels:
        st1             {v1.16b},     [x0], x1 // P2
    .endif
        st1             {v2.16b},     [x0], x1 // P1
        st1             {v3.16b},     [x0], x1 // P0
        st1             {v4.16b},     [x0], x1 // Q0
        st1             {v5.16b},     [x0], x1 // Q1
    .if !\simple
        st1             {v6.16b},     [x0]     // Q2
    .endif

        ret
endfunc
.endm

vp8_v_loop_filter16
vp8_v_loop_filter16 _inner,  inner=1
vp8_v_loop_filter16 _simple, simple=1

.macro  vp8_v_loop_filter8uv name, inner=0
function ff_vp8_v_loop_filter8uv\name\()_neon, export=1
        sub             x0,  x0,  x2,  lsl #2
        sub             x1,  x1,  x2,  lsl #2
        // Load pixels:
        ld1          {v0.d}[0],     [x0], x2  // P3
        ld1          {v0.d}[1],     [x1], x2  // P3
        ld1          {v1.d}[0],     [x0], x2  // P2
        ld1          {v1.d}[1],     [x1], x2  // P2
        ld1          {v2.d}[0],     [x0], x2  // P1
        ld1          {v2.d}[1],     [x1], x2  // P1
        ld1          {v3.d}[0],     [x0], x2  // P0
        ld1          {v3.d}[1],     [x1], x2  // P0
        ld1          {v4.d}[0],     [x0], x2  // Q0
        ld1          {v4.d}[1],     [x1], x2  // Q0
        ld1          {v5.d}[0],     [x0], x2  // Q1
        ld1          {v5.d}[1],     [x1], x2  // Q1
        ld1          {v6.d}[0],     [x0], x2  // Q2
        ld1          {v6.d}[1],     [x1], x2  // Q2
        ld1          {v7.d}[0],     [x0]      // Q3
        ld1          {v7.d}[1],     [x1]      // Q3

        dup          v22.16b, w3                 // flim_E
        dup          v23.16b, w4                 // flim_I

        vp8_loop_filter inner=\inner, hev_thresh=w5

        // back up to P2:  u,v -= stride * 6
        sub          x0,  x0,  x2,  lsl #2
        sub          x1,  x1,  x2,  lsl #2
        sub          x0,  x0,  x2,  lsl #1
        sub          x1,  x1,  x2,  lsl #1

        // Store pixels:

        st1          {v1.d}[0],     [x0], x2  // P2
        st1          {v1.d}[1],     [x1], x2  // P2
        st1          {v2.d}[0],     [x0], x2  // P1
        st1          {v2.d}[1],     [x1], x2  // P1
        st1          {v3.d}[0],     [x0], x2  // P0
        st1          {v3.d}[1],     [x1], x2  // P0
        st1          {v4.d}[0],     [x0], x2  // Q0
        st1          {v4.d}[1],     [x1], x2  // Q0
        st1          {v5.d}[0],     [x0], x2  // Q1
        st1          {v5.d}[1],     [x1], x2  // Q1
        st1          {v6.d}[0],     [x0]      // Q2
        st1          {v6.d}[1],     [x1]      // Q2

        ret
endfunc
.endm

vp8_v_loop_filter8uv
vp8_v_loop_filter8uv _inner, inner=1

.macro  vp8_h_loop_filter16 name, inner=0, simple=0
function ff_vp8_h_loop_filter16\name\()_neon, export=1

        sub             x0,  x0,  #4
        // Load pixels:
        ld1             {v0.d}[0], [x0], x1
        ld1             {v1.d}[0], [x0], x1
        ld1             {v2.d}[0], [x0], x1
        ld1             {v3.d}[0], [x0], x1
        ld1             {v4.d}[0], [x0], x1
        ld1             {v5.d}[0], [x0], x1
        ld1             {v6.d}[0], [x0], x1
        ld1             {v7.d}[0], [x0], x1
        ld1             {v0.d}[1], [x0], x1
        ld1             {v1.d}[1], [x0], x1
        ld1             {v2.d}[1], [x0], x1
        ld1             {v3.d}[1], [x0], x1
        ld1             {v4.d}[1], [x0], x1
        ld1             {v5.d}[1], [x0], x1
        ld1             {v6.d}[1], [x0], x1
        ld1             {v7.d}[1], [x0], x1

        transpose_8x16B   v0,  v1,  v2,  v3,  v4,  v5,  v6,  v7, v30, v31

        dup             v22.16b, w2                 // flim_E
    .if !\simple
        dup             v23.16b, w3                 // flim_I
    .endif

        vp8_loop_filter inner=\inner, simple=\simple, hev_thresh=w4

        sub             x0,  x0,  x1, lsl #4    // backup 16 rows

        transpose_8x16B   v0,  v1,  v2,  v3,  v4,  v5,  v6,  v7, v30, v31

        // Store pixels:
        st1             {v0.d}[0], [x0], x1
        st1             {v1.d}[0], [x0], x1
        st1             {v2.d}[0], [x0], x1
        st1             {v3.d}[0], [x0], x1
        st1             {v4.d}[0], [x0], x1
        st1             {v5.d}[0], [x0], x1
        st1             {v6.d}[0], [x0], x1
        st1             {v7.d}[0], [x0], x1
        st1             {v0.d}[1], [x0], x1
        st1             {v1.d}[1], [x0], x1
        st1             {v2.d}[1], [x0], x1
        st1             {v3.d}[1], [x0], x1
        st1             {v4.d}[1], [x0], x1
        st1             {v5.d}[1], [x0], x1
        st1             {v6.d}[1], [x0], x1
        st1             {v7.d}[1], [x0]

        ret
endfunc
.endm

vp8_h_loop_filter16
vp8_h_loop_filter16 _inner,  inner=1
vp8_h_loop_filter16 _simple, simple=1

.macro  vp8_h_loop_filter8uv name, inner=0
function ff_vp8_h_loop_filter8uv\name\()_neon, export=1
        sub             x0,  x0,  #4
        sub             x1,  x1,  #4

        // Load pixels:
        ld1          {v0.d}[0],     [x0], x2 // load u
        ld1          {v0.d}[1],     [x1], x2 // load v
        ld1          {v1.d}[0],     [x0], x2
        ld1          {v1.d}[1],     [x1], x2
        ld1          {v2.d}[0],     [x0], x2
        ld1          {v2.d}[1],     [x1], x2
        ld1          {v3.d}[0],     [x0], x2
        ld1          {v3.d}[1],     [x1], x2
        ld1          {v4.d}[0],     [x0], x2
        ld1          {v4.d}[1],     [x1], x2
        ld1          {v5.d}[0],     [x0], x2
        ld1          {v5.d}[1],     [x1], x2
        ld1          {v6.d}[0],     [x0], x2
        ld1          {v6.d}[1],     [x1], x2
        ld1          {v7.d}[0],     [x0], x2
        ld1          {v7.d}[1],     [x1], x2

        transpose_8x16B   v0,  v1,  v2,  v3,  v4,  v5,  v6,  v7, v30, v31

        dup             v22.16b, w3                 // flim_E
        dup             v23.16b, w4                 // flim_I

        vp8_loop_filter inner=\inner, hev_thresh=w5

        sub             x0,  x0,  x2, lsl #3    // backup u 8 rows
        sub             x1,  x1,  x2, lsl #3    // backup v 8 rows

        transpose_8x16B   v0,  v1,  v2,  v3,  v4,  v5,  v6,  v7, v30, v31

        // Store pixels:
        st1          {v0.d}[0],     [x0], x2 // load u
        st1          {v0.d}[1],     [x1], x2 // load v
        st1          {v1.d}[0],     [x0], x2
        st1          {v1.d}[1],     [x1], x2
        st1          {v2.d}[0],     [x0], x2
        st1          {v2.d}[1],     [x1], x2
        st1          {v3.d}[0],     [x0], x2
        st1          {v3.d}[1],     [x1], x2
        st1          {v4.d}[0],     [x0], x2
        st1          {v4.d}[1],     [x1], x2
        st1          {v5.d}[0],     [x0], x2
        st1          {v5.d}[1],     [x1], x2
        st1          {v6.d}[0],     [x0], x2
        st1          {v6.d}[1],     [x1], x2
        st1          {v7.d}[0],     [x0]
        st1          {v7.d}[1],     [x1]

        ret

endfunc
.endm

vp8_h_loop_filter8uv
vp8_h_loop_filter8uv _inner, inner=1


function ff_put_vp8_pixels16_neon, export=1
1:
        subs            w4, w4, #4
        ld1             {v0.16b},     [x2], x3
        ld1             {v1.16b},     [x2], x3
        ld1             {v2.16b},     [x2], x3
        ld1             {v3.16b},     [x2], x3
        st1             {v0.16b},     [x0], x1
        st1             {v1.16b},     [x0], x1
        st1             {v2.16b},     [x0], x1
        st1             {v3.16b},     [x0], x1
        b.gt            1b
        ret
endfunc

function ff_put_vp8_pixels8_neon, export=1
1:
        subs            w4, w4, #4
        ld1             {v0.8b},   [x2], x3
        ld1             {v0.d}[1], [x2], x3
        ld1             {v1.8b},   [x2], x3
        ld1             {v1.d}[1], [x2], x3
        st1             {v0.8b},   [x0], x1
        st1             {v0.d}[1], [x0], x1
        st1             {v1.8b},   [x0], x1
        st1             {v1.d}[1], [x0], x1
        b.gt            1b
        ret
endfunc

/* 4/6-tap 8th-pel MC */

.macro  vp8_epel8_h6    d,   s0,   s1
        ext             v22.8b, \s0\().8b,  \s1\().8b,  #1
        uxtl            v18.8h, \s0\().8b
        ext             v23.8b, \s0\().8b,  \s1\().8b,  #2
        uxtl            v19.8h, v22.8b
        ext             v24.8b, \s0\().8b,  \s1\().8b,  #3
        uxtl            v21.8h, v23.8b
        ext             v25.8b, \s0\().8b,  \s1\().8b,  #4
        uxtl            v22.8h, v24.8b
        ext             v26.8b, \s0\().8b,  \s1\().8b,  #5
        uxtl            v25.8h, v25.8b
        mul             v21.8h, v21.8h, v0.h[2]
        uxtl            v26.8h, v26.8b
        mul             v22.8h, v22.8h, v0.h[3]
        mls             v21.8h, v19.8h, v0.h[1]
        mls             v22.8h, v25.8h, v0.h[4]
        mla             v21.8h, v18.8h, v0.h[0]
        mla             v22.8h, v26.8h, v0.h[5]
        sqadd           v22.8h, v21.8h, v22.8h
        sqrshrun        \d\().8b, v22.8h, #7
.endm

.macro  vp8_epel16_h6   d0,  v0,  v1
        ext             v22.16b, \v0\().16b, \v1\().16b, #3
        ext             v23.16b, \v0\().16b, \v1\().16b, #4
        uxtl            v19.8h,  v22.8b
        uxtl2           v22.8h,  v22.16b
        ext             v3.16b,  \v0\().16b, \v1\().16b, #2
        uxtl            v20.8h,  v23.8b
        uxtl2           v23.8h,  v23.16b
        ext             v16.16b, \v0\().16b, \v1\().16b, #1
        uxtl            v18.8h,  v3.8b
        uxtl2           v3.8h,   v3.16b
        ext             v2.16b,  \v0\().16b, \v1\().16b, #5
        uxtl            v21.8h,  v2.8b
        uxtl2           v2.8h,   v2.16b
        uxtl            v17.8h,  v16.8b
        uxtl2           v16.8h,  v16.16b
        mul             v19.8h,  v19.8h, v0.h[3]
        mul             v18.8h,  v18.8h, v0.h[2]
        mul             v3.8h,   v3.8h,  v0.h[2]
        mul             v22.8h,  v22.8h, v0.h[3]
        mls             v19.8h,  v20.8h, v0.h[4]
        uxtl            v20.8h,  \v0\().8b
        uxtl2           v1.8h,   \v0\().16b
        mls             v18.8h,  v17.8h, v0.h[1]
        mls             v3.8h,   v16.8h, v0.h[1]
        mls             v22.8h,  v23.8h, v0.h[4]
        mla             v18.8h,  v20.8h, v0.h[0]
        mla             v19.8h,  v21.8h, v0.h[5]
        mla             v3.8h,   v1.8h,  v0.h[0]
        mla             v22.8h,  v2.8h,  v0.h[5]
        sqadd           v19.8h,  v18.8h, v19.8h
        sqadd           v22.8h,  v3.8h,  v22.8h
        sqrshrun        \d0\().8b,  v19.8h, #7
        sqrshrun2       \d0\().16b, v22.8h, #7
.endm

.macro  vp8_epel8_v6_y2 d0, d1, s0, s1, s2, s3, s4, s5, s6
        uxtl            \s0\().8h, \s0\().8b
        uxtl            \s3\().8h, \s3\().8b
        uxtl            \s6\().8h, \s6\().8b
        uxtl            \s1\().8h, \s1\().8b
        uxtl            \s4\().8h, \s4\().8b
        uxtl            \s2\().8h, \s2\().8b
        uxtl            \s5\().8h, \s5\().8b
        mul             \s0\().8h, \s0\().8h, v0.h[0]
        mul             v31.8h   , \s3\().8h, v0.h[3]
        mul             \s3\().8h, \s3\().8h, v0.h[2]
        mul             \s6\().8h, \s6\().8h, v0.h[5]

        mls             \s0\().8h, \s1\().8h, v0.h[1]
        mls             v31.8h   , \s4\().8h, v0.h[4]
        mls             \s3\().8h, \s2\().8h, v0.h[1]
        mls             \s6\().8h, \s5\().8h, v0.h[4]

        mla             \s0\().8h, \s2\().8h, v0.h[2]
        mla             v31.8h   , \s5\().8h, v0.h[5]
        mla             \s3\().8h, \s1\().8h, v0.h[0]
        mla             \s6\().8h, \s4\().8h, v0.h[3]
        sqadd           v31.8h   , \s0\().8h, v31.8h
        sqadd           \s6\().8h, \s3\().8h, \s6\().8h
        sqrshrun        \d0\().8b, v31.8h,    #7
        sqrshrun        \d1\().8b, \s6\().8h, #7
.endm

.macro  vp8_epel8_h4    d,   v0,   v1
        ext             v22.8b, \v0\().8b,  \v1\().8b,  #1
        uxtl            v19.8h, \v0\().8b
        ext             v23.8b, \v0\().8b,  \v1\().8b,  #2
        uxtl            v20.8h, v22.8b
        ext             v25.8b, \v0\().8b,  \v1\().8b,  #3
        uxtl            v22.8h, v23.8b
        uxtl            v25.8h, v25.8b
        mul             v20.8h, v20.8h, v0.h[2]
        mul             v22.8h, v22.8h, v0.h[3]
        mls             v20.8h, v19.8h, v0.h[1]
        mls             v22.8h, v25.8h, v0.h[4]
        sqadd           v22.8h, v20.8h, v22.8h
        sqrshrun        \d\().8b, v22.8h, #7
.endm

.macro  vp8_epel8_v4_y2 d0, s0, s1, s2, s3, s4
        uxtl            \s0\().8h,  \s0\().8b
        uxtl            \s1\().8h,  \s1\().8b
        uxtl            \s2\().8h,  \s2\().8b
        uxtl            \s3\().8h,  \s3\().8b
        uxtl            \s4\().8h,  \s4\().8b
        mul             v21.8h,     \s1\().8h, v0.h[2]
        mul             v23.8h,     \s2\().8h, v0.h[3]
        mul             \s2\().8h,  \s2\().8h, v0.h[2]
        mul             v22.8h,     \s3\().8h, v0.h[3]
        mls             v21.8h,     \s0\().8h, v0.h[1]
        mls             v23.8h,     \s3\().8h, v0.h[4]
        mls             \s2\().8h,  \s1\().8h, v0.h[1]
        mls             v22.8h,     \s4\().8h, v0.h[4]
        sqadd           v21.8h,     v21.8h,    v23.8h
        sqadd           \s2\().8h,  \s2\().8h, v22.8h
        sqrshrun        \d0\().8b,  v21.8h,    #7
        sqrshrun2       \d0\().16b, \s2\().8h, #7
.endm


// note: worst case sum of all 6-tap filter values * 255 is 0x7f80 so 16 bit
// arithmetic can be used to apply filters
const   subpel_filters, align=4
        .short     0,   6, 123,  12,   1,   0,   0,   0
        .short     2,  11, 108,  36,   8,   1,   0,   0
        .short     0,   9,  93,  50,   6,   0,   0,   0
        .short     3,  16,  77,  77,  16,   3,   0,   0
        .short     0,   6,  50,  93,   9,   0,   0,   0
        .short     1,   8,  36, 108,  11,   2,   0,   0
        .short     0,   1,  12, 123,   6,   0,   0,   0
endconst

function ff_put_vp8_epel16_v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1

        sxtw            x4,  w4
        sxtw            x6,  w6
        movrel          x17,  subpel_filters, -16
        add             x6,  x17,  x6, lsl #4  // y
        ld1             {v0.8h},     [x6]
1:
        ld1             {v1.1d - v2.1d},    [x2], x3
        ld1             {v3.1d - v4.1d},    [x2], x3
        ld1             {v16.1d - v17.1d},  [x2], x3
        ld1             {v18.1d - v19.1d},  [x2], x3
        ld1             {v20.1d - v21.1d},  [x2], x3
        ld1             {v22.1d - v23.1d},  [x2], x3
        ld1             {v24.1d - v25.1d},  [x2]
        sub             x2,  x2,  x3, lsl #2

        vp8_epel8_v6_y2 v1, v3, v1, v3, v16, v18, v20, v22, v24
        vp8_epel8_v6_y2 v2, v4, v2, v4, v17, v19, v21, v23, v25

        st1             {v1.1d - v2.1d}, [x0], x1
        st1             {v3.1d - v4.1d}, [x0], x1
        subs            x4, x4, #2
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel16_h6_neon, export=1
        sub             x2,  x2,  #2
        sxtw            x5,  w5 // x

        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        add             x5,  x17,  x5, lsl #4 // x
        ld1             {v0.8h},  [x5]
1:
        ld1             {v1.16b, v2.16b}, [x2], x3
        vp8_epel16_h6   v1, v1, v2
        st1             {v1.16b}, [x0], x1

        subs            w4, w4, #1
        b.ne            1b
        ret
endfunc


function ff_put_vp8_epel16_h6v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1
        sub             x2,  x2,  #2

        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        sxtw            x5,  w5 // x
        add             x16,  x17,  x5, lsl #4 // x
        sub             sp,  sp,  #336+16
        ld1             {v0.8h},  [x16]
        add             x7,  sp,  #15
        sxtw            x4,  w4
        add             x16, x4, #5   // h
        bic             x7,  x7,  #15
1:
        ld1             {v1.16b, v2.16b}, [x2], x3
        vp8_epel16_h6   v1, v1, v2
        st1             {v1.16b}, [x7], #16
        subs            x16, x16, #1
        b.ne            1b


        // second pass (vertical):
        sxtw            x6,  w6
        add             x6,  x17,  x6, lsl #4  // y
        add             x7,  sp,  #15
        ld1             {v0.8h},     [x6]
        bic             x7,  x7,  #15
2:
        ld1             {v1.8b - v4.8b},    [x7], #32
        ld1             {v16.8b - v19.8b},  [x7], #32
        ld1             {v20.8b - v23.8b},  [x7], #32
        ld1             {v24.8b - v25.8b},  [x7]
        sub             x7,  x7,  #64

        vp8_epel8_v6_y2 v1, v3, v1, v3, v16, v18, v20, v22, v24
        vp8_epel8_v6_y2 v2, v4, v2, v4, v17, v19, v21, v23, v25
        trn1            v1.2d, v1.2d, v2.2d
        trn1            v3.2d, v3.2d, v4.2d

        st1             {v1.16b}, [x0], x1
        st1             {v3.16b}, [x0], x1
        subs            x4, x4, #2
        b.ne            2b

        add             sp,  sp,  #336+16
        ret
endfunc

function ff_put_vp8_epel8_v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1

        movrel          x7,  subpel_filters, -16
        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},  [x6]
1:
        ld1             {v2.8b},  [x2], x3
        ld1             {v3.8b},  [x2], x3
        ld1             {v4.8b},  [x2], x3
        ld1             {v5.8b},  [x2], x3
        ld1             {v6.8b},  [x2], x3
        ld1             {v7.8b},  [x2], x3
        ld1             {v28.8b}, [x2]

        sub             x2,  x2,  x3,  lsl #2

        vp8_epel8_v6_y2 v2, v3, v2, v3, v4, v5, v6, v7, v28

        st1             {v2.8b}, [x0], x1
        st1             {v3.8b}, [x0], x1
        subs            w4,  w4,  #2
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel8_h6_neon, export=1
        sub             x2,  x2,  #2

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},        [x5]
1:
        ld1             {v2.8b, v3.8b}, [x2], x3

        vp8_epel8_h6    v2,  v2,  v3

        st1             {v2.8b}, [x0], x1
        subs            w4,  w4,  #1
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel8_h6v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1
        sub             x2,  x2,  #2
        sxtw            x4,  w4

        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        sxtw            x5,  w5
        add             x5,  x17,  x5, lsl #4 // x
        sub             sp,  sp,  #168+16
        ld1             {v0.8h},  [x5]
        add             x7,  sp,  #15
        add             x16, x4,  #5   // h
        bic             x7,  x7,  #15
1:
        ld1             {v1.8b, v2.8b}, [x2], x3

        vp8_epel8_h6    v1, v1, v2

        st1             {v1.8b}, [x7], #8
        subs            x16, x16, #1
        b.ne            1b

        // second pass (vertical):
        sxtw            x6,  w6
        add             x6,  x17,  x6, lsl #4  // y
        add             x7,  sp,   #15
        ld1             {v0.8h},   [x6]
        bic             x7,  x7,   #15
2:
        ld1             {v1.8b - v4.8b}, [x7], #32
        ld1             {v5.8b - v7.8b}, [x7]

        sub             x7,  x7,  #16

        vp8_epel8_v6_y2 v1, v2, v1, v2, v3, v4, v5, v6, v7

        st1             {v1.8b}, [x0], x1
        st1             {v2.8b}, [x0], x1
        subs            x4, x4, #2
        b.ne            2b

        add             sp,  sp,  #168+16
        ret
endfunc

function ff_put_vp8_epel8_v4_neon, export=1
        sub             x2,  x2,  x3

        movrel          x7,  subpel_filters, -16
        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},     [x6]
1:
        ld1             {v2.8b},     [x2], x3
        ld1             {v3.8b},     [x2], x3
        ld1             {v4.8b},     [x2], x3
        ld1             {v5.8b},     [x2], x3
        ld1             {v6.8b},     [x2]
        sub             x2,  x2,  x3,  lsl #1

        vp8_epel8_v4_y2 v2, v2, v3, v4, v5, v6

        st1             {v2.d}[0], [x0], x1
        st1             {v2.d}[1], [x0], x1
        subs            w4,  w4,  #2
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel8_h4_neon, export=1
        sub             x2,  x2,  #1

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]
1:
        ld1             {v2.8b,v3.8b}, [x2], x3

        vp8_epel8_h4    v2,  v2,  v3

        st1             {v2.8b}, [x0], x1
        subs            w4,  w4,  #1
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel8_h4v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1
        sub             x2,  x2,  #1
        sxtw            x4,  w4

        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        sxtw            x5,  w5
        add             x5,  x17,  x5, lsl #4 // x
        sub             sp,  sp,  #168+16
        ld1             {v0.8h},  [x5]
        add             x7,  sp,  #15
        add             x16, x4, #5   // h
        bic             x7,  x7,  #15
1:
        ld1             {v1.8b, v2.8b}, [x2], x3

        vp8_epel8_h4    v1, v1, v2

        st1             {v1.8b}, [x7], #8
        subs            x16, x16, #1
        b.ne            1b

        // second pass (vertical):
        sxtw            x6,  w6
        add             x6,  x17,  x6, lsl #4  // y
        add             x7,  sp,   #15
        ld1             {v0.8h},   [x6]
        bic             x7,  x7,   #15
2:
        ld1             {v1.8b - v4.8b}, [x7], #32
        ld1             {v5.8b - v7.8b}, [x7]

        sub             x7,  x7,  #16

        vp8_epel8_v6_y2 v1, v2, v1, v2, v3, v4, v5, v6, v7

        st1             {v1.8b}, [x0], x1
        st1             {v2.8b}, [x0], x1
        subs            x4, x4, #2
        b.ne            2b

        add             sp,  sp,  #168+16
        ret
endfunc

function ff_put_vp8_epel8_h4v4_neon, export=1
        sub             x2,  x2,  x3
        sub             x2,  x2,  #1
        sxtw            x4,  w4


        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        sxtw            x5,  w5
        add             x5,  x17,  x5, lsl #4 // x
        sub             sp,  sp,  #168+16
        ld1             {v0.8h},  [x5]
        add             x7,  sp,  #15
        add             x16, x4, #3   // h
        bic             x7,  x7,  #15
1:
        ld1             {v1.8b, v2.8b}, [x2], x3

        vp8_epel8_h4    v1, v1, v2

        st1             {v1.8b}, [x7], #8
        subs            x16, x16, #1
        b.ne            1b

        // second pass (vertical):
        sxtw            x6,  w6
        add             x6,  x17,  x6, lsl #4  // y
        add             x7,  sp,   #15
        ld1             {v0.8h},   [x6]
        bic             x7,  x7,   #15
2:
        ld1             {v1.8b - v2.8b}, [x7], #16
        ld1             {v3.8b - v5.8b}, [x7]

        vp8_epel8_v4_y2 v1, v1, v2, v3, v4, v5

        st1             {v1.d}[0], [x0], x1
        st1             {v1.d}[1], [x0], x1
        subs            x4, x4, #2
        b.ne            2b

        add             sp,  sp,  #168+16
        ret
endfunc

function ff_put_vp8_epel8_h6v4_neon, export=1
        sub             x2,  x2,  x3
        sub             x2,  x2,  #2
        sxtw            x4,  w4


        // first pass (horizontal):
        movrel          x17,  subpel_filters, -16
        sxtw            x5,  w5
        add             x5,  x17,  x5, lsl #4 // x
        sub             sp,  sp,  #168+16
        ld1             {v0.8h},  [x5]
        add             x7,  sp,  #15
        add             x16, x4, #3   // h
        bic             x7,  x7,  #15
1:
        ld1             {v1.8b, v2.8b}, [x2], x3

        vp8_epel8_h6    v1, v1, v2

        st1             {v1.8b}, [x7], #8
        subs            x16, x16, #1
        b.ne            1b

        // second pass (vertical):
        sxtw            x6,  w6
        add             x6,  x17,  x6, lsl #4  // y
        add             x7,  sp,   #15
        ld1             {v0.8h},   [x6]
        bic             x7,  x7,   #15
2:
        ld1             {v1.8b - v2.8b}, [x7], #16
        ld1             {v3.8b - v5.8b}, [x7]

        vp8_epel8_v4_y2 v1, v1, v2, v3, v4, v5

        st1             {v1.d}[0], [x0], x1
        st1             {v1.d}[1], [x0], x1
        subs            x4, x4, #2
        b.ne            2b

        add             sp,  sp,  #168+16
        ret
endfunc

function ff_put_vp8_epel4_v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1

        movrel          x7,  subpel_filters, -16
        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},    [x6]
1:
        ld1r            {v2.2s},    [x2], x3
        ld1r            {v3.2s},    [x2], x3
        ld1r            {v4.2s},    [x2], x3
        ld1r            {v5.2s},    [x2], x3
        ld1r            {v6.2s},    [x2], x3
        ld1r            {v7.2s},    [x2], x3
        ld1r            {v28.2s},   [x2]
        sub             x2,  x2,  x3,  lsl #2
        ld1             {v2.s}[1],  [x2], x3
        ld1             {v3.s}[1],  [x2], x3
        ld1             {v4.s}[1],  [x2], x3
        ld1             {v5.s}[1],  [x2], x3
        ld1             {v6.s}[1],  [x2], x3
        ld1             {v7.s}[1],  [x2], x3
        ld1             {v28.s}[1], [x2]
        sub             x2,  x2,  x3,  lsl #2

        vp8_epel8_v6_y2 v2, v3, v2, v3, v4, v5, v6, v7, v28

        st1             {v2.s}[0],  [x0], x1
        st1             {v3.s}[0],  [x0], x1
        st1             {v2.s}[1],  [x0], x1
        st1             {v3.s}[1],  [x0], x1
        subs            w4,  w4,  #4
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel4_h6_neon, export=1
        sub             x2,  x2,  #2

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]
1:
        ld1             {v2.8b,v3.8b}, [x2], x3
        vp8_epel8_h6    v2,  v2,  v3
        st1             {v2.s}[0], [x0], x1
        subs            w4,  w4,  #1
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel4_h6v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1
        sub             x2,  x2,  #2

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]

        sub             sp,  sp,  #52
        add             w8,  w4,  #5
        mov             x9,  sp
1:
        ld1             {v2.8b,v3.8b}, [x2], x3
        vp8_epel8_h6    v2,  v2,  v3
        st1             {v2.s}[0],     [x9], #4
        subs            w8,  w8,  #1
        b.ne            1b

        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},       [x6]
        mov             x9,  sp
2:
        ld1             {v2.8b,v3.8b}, [x9], #16
        ld1             {v6.8b},       [x9], #8
        ld1r            {v28.2s},      [x9]
        sub             x9,  x9,  #16
        ld1             {v4.8b,v5.8b}, [x9], #16
        ld1             {v7.8b},       [x9], #8
        ld1             {v28.s}[1],    [x9]
        sub             x9,  x9,  #16
        trn1            v1.2s, v2.2s, v4.2s
        trn2            v4.2s, v2.2s, v4.2s
        trn1            v2.2s, v3.2s, v5.2s
        trn2            v5.2s, v3.2s, v5.2s
        trn1            v3.2s, v6.2s, v7.2s
        trn2            v7.2s, v6.2s, v7.2s
        vp8_epel8_v6_y2 v2, v3, v1, v4, v2, v5, v3, v7, v28
        st1             {v2.s}[0],  [x0], x1
        st1             {v3.s}[0],  [x0], x1
        st1             {v2.s}[1],  [x0], x1
        st1             {v3.s}[1],  [x0], x1
        subs            w4,  w4,  #4
        b.ne            2b

        add             sp,  sp,  #52
        ret
endfunc

function ff_put_vp8_epel4_h4v6_neon, export=1
        sub             x2,  x2,  x3,  lsl #1
        sub             x2,  x2,  #1

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]

        sub             sp,  sp,  #52
        add             w8,  w4,  #5
        mov             x9,  sp
1:
        ld1             {v2.8b},       [x2], x3
        vp8_epel8_h4    v2,  v2,  v2
        st1             {v2.s}[0],     [x9], #4
        subs            w8,  w8,  #1
        b.ne            1b

        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},       [x6]
        mov             x9,  sp
2:
        ld1             {v2.8b,v3.8b}, [x9], #16
        ld1             {v6.8b},       [x9], #8
        ld1r            {v28.2s},      [x9]
        sub             x9,  x9,  #16
        ld1             {v4.8b,v5.8b}, [x9], #16
        ld1             {v7.8b},       [x9], #8
        ld1             {v28.s}[1],    [x9]
        sub             x9,  x9,  #16
        trn1            v1.2s, v2.2s, v4.2s
        trn2            v4.2s, v2.2s, v4.2s
        trn1            v2.2s, v3.2s, v5.2s
        trn2            v5.2s, v3.2s, v5.2s
        trn1            v3.2s, v6.2s, v7.2s
        trn2            v7.2s, v6.2s, v7.2s
        vp8_epel8_v6_y2 v2, v3, v1, v4, v2, v5, v3, v7, v28
        st1             {v2.s}[0],  [x0], x1
        st1             {v3.s}[0],  [x0], x1
        st1             {v2.s}[1],  [x0], x1
        st1             {v3.s}[1],  [x0], x1
        subs            w4,  w4,  #4
        b.ne            2b

        add             sp,  sp,  #52
        ret
endfunc

function ff_put_vp8_epel4_h6v4_neon, export=1
        sub             x2,  x2,  x3
        sub             x2,  x2,  #2

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]

        sub             sp,  sp,  #44
        add             w8,  w4,  #3
        mov             x9,  sp
1:
        ld1             {v2.8b,v3.8b}, [x2], x3
        vp8_epel8_h6    v2, v2, v3
        st1             {v2.s}[0],     [x9], #4
        subs            w8,  w8,  #1
        b.ne            1b

        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},       [x6]
        mov             x9,  sp
2:
        ld1             {v2.8b,v3.8b}, [x9], #16
        ld1r            {v6.2s},       [x9]
        sub             x9,  x9,  #8
        ld1             {v4.8b,v5.8b}, [x9], #16
        ld1             {v6.s}[1],     [x9]
        sub             x9,  x9,  #8
        trn1            v1.2s, v2.2s, v4.2s
        trn2            v4.2s, v2.2s, v4.2s
        trn1            v2.2s, v3.2s, v5.2s
        trn2            v5.2s, v3.2s, v5.2s
        vp8_epel8_v4_y2 v1, v1, v4, v2, v5, v6
        st1             {v1.s}[0],  [x0], x1
        st1             {v1.s}[2],  [x0], x1
        st1             {v1.s}[1],  [x0], x1
        st1             {v1.s}[3],  [x0], x1
        subs            w4,  w4,  #4
        b.ne            2b

        add             sp,  sp,  #44
        ret
endfunc

function ff_put_vp8_epel4_h4_neon, export=1
        sub             x2,  x2,  #1

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},    [x5]
1:
        ld1             {v2.8b},    [x2], x3
        vp8_epel8_h4    v2,  v2,  v2
        st1             {v2.s}[0],  [x0], x1
        subs            w4,  w4,  #1
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel4_v4_neon, export=1
        sub             x2,  x2,  x3

        movrel          x7,  subpel_filters, -16
        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},   [x6]
1:
        ld1r            {v2.2s},   [x2], x3
        ld1r            {v3.2s},   [x2], x3
        ld1r            {v4.2s},   [x2], x3
        ld1r            {v5.2s},   [x2], x3
        ld1r            {v6.2s},   [x2]
        sub             x2,  x2,  x3,  lsl #1
        ld1             {v2.s}[1], [x2], x3
        ld1             {v3.s}[1], [x2], x3
        ld1             {v4.s}[1], [x2], x3
        ld1             {v5.s}[1], [x2], x3
        ld1             {v6.s}[1], [x2]
        sub             x2,  x2,  x3,  lsl #1

        vp8_epel8_v4_y2 v2, v2, v3, v4, v5, v6

        st1             {v2.s}[0], [x0], x1
        st1             {v2.s}[2], [x0], x1
        st1             {v2.s}[1], [x0], x1
        st1             {v2.s}[3], [x0], x1
        subs            w4,  w4,  #4
        b.ne            1b

        ret
endfunc

function ff_put_vp8_epel4_h4v4_neon, export=1
        sub             x2,  x2,  x3
        sub             x2,  x2,  #1

        movrel          x7,  subpel_filters, -16
        add             x5,  x7,  w5, uxtw #4
        ld1             {v0.8h},       [x5]

        sub             sp,  sp,  #44
        add             w8,  w4,  #3
        mov             x9,  sp
1:
        ld1             {v2.8b},       [x2], x3
        vp8_epel8_h4    v2,  v2,  v3
        st1             {v2.s}[0],     [x9], #4
        subs            w8,  w8,  #1
        b.ne            1b

        add             x6,  x7,  w6, uxtw #4
        ld1             {v0.8h},       [x6]
        mov             x9,  sp
2:
        ld1             {v2.8b,v3.8b}, [x9], #16
        ld1r            {v6.2s},       [x9]
        sub             x9,  x9,  #8
        ld1             {v4.8b,v5.8b}, [x9], #16
        ld1             {v6.s}[1],     [x9]
        sub             x9,  x9,  #8
        trn1            v1.2s, v2.2s, v4.2s
        trn2            v4.2s, v2.2s, v4.2s
        trn1            v2.2s, v3.2s, v5.2s
        trn2            v5.2s, v3.2s, v5.2s
        vp8_epel8_v4_y2 v1, v1, v4, v2, v5, v6
        st1             {v1.s}[0], [x0], x1
        st1             {v1.s}[2], [x0], x1
        st1             {v1.s}[1], [x0], x1
        st1             {v1.s}[3], [x0], x1
        subs            w4,  w4,  #4
        b.ne            2b

        add             sp,  sp,  #44
        ret
endfunc

/* Bilinear MC */

function ff_put_vp8_bilin16_h_neon, export=1
        mov             w7,     #8
        dup             v0.8b,  w5
        sub             w5,     w7,     w5
        dup             v1.8b,  w5
1:
        subs            w4,     w4,     #2
        ld1             {v2.8b,v3.8b,v4.8b},    [x2], x3
        ext             v5.8b,  v3.8b,  v4.8b,  #1
        ext             v4.8b,  v2.8b,  v3.8b,  #1
        umull           v16.8h, v2.8b,  v1.8b
        umlal           v16.8h, v4.8b,  v0.8b
        ld1             {v18.8b,v19.8b,v20.8b}, [x2], x3
        umull           v6.8h,  v3.8b,  v1.8b
        umlal           v6.8h,  v5.8b,  v0.8b
        ext             v21.8b, v19.8b, v20.8b, #1
        ext             v20.8b, v18.8b, v19.8b, #1
        umull           v22.8h, v18.8b, v1.8b
        umlal           v22.8h, v20.8b, v0.8b
        umull           v24.8h, v19.8b, v1.8b
        umlal           v24.8h, v21.8b, v0.8b
        rshrn           v4.8b,  v16.8h, #3
        rshrn2          v4.16b, v6.8h,  #3
        rshrn           v6.8b,  v22.8h, #3
        rshrn2          v6.16b, v24.8h, #3
        st1             {v4.16b}, [x0], x1
        st1             {v6.16b}, [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin16_v_neon, export=1
        mov             w7,     #8
        dup             v0.16b, w6
        sub             w6,     w7,     w6
        dup             v1.16b, w6

        ld1             {v2.16b}, [x2], x3
1:
        subs            w4,     w4,     #2
        ld1             {v4.16b}, [x2], x3
        umull           v6.8h,  v2.8b,  v1.8b
        umlal           v6.8h,  v4.8b,  v0.8b
        umull2          v16.8h, v2.16b, v1.16b
        umlal2          v16.8h, v4.16b, v0.16b
        ld1             {v2.16b}, [x2], x3
        umull           v18.8h, v4.8b,  v1.8b
        umlal           v18.8h, v2.8b,  v0.8b
        umull2          v20.8h, v4.16b, v1.16b
        umlal2          v20.8h, v2.16b, v0.16b
        rshrn           v4.8b,  v6.8h,  #3
        rshrn2          v4.16b, v16.8h, #3
        rshrn           v6.8b,  v18.8h, #3
        rshrn2          v6.16b, v20.8h, #3
        st1             {v4.16b}, [x0], x1
        st1             {v6.16b}, [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin16_hv_neon, export=1
        mov             w7,      #8
        dup             v0.8b,   w5            // mx
        sub             w5,      w7,     w5
        dup             v1.8b,   w5
        dup             v2.16b,  w6            // my
        sub             w6,      w7,     w6
        dup             v3.16b,  w6

        ld1             {v4.8b,v5.8b,v6.8b},    [x2], x3

        ext             v7.8b,   v5.8b,  v6.8b, #1
        ext             v6.8b,   v4.8b,  v5.8b, #1
        umull           v16.8h,  v4.8b,  v1.8b
        umlal           v16.8h,  v6.8b,  v0.8b
        umull           v18.8h,  v5.8b,  v1.8b
        umlal           v18.8h,  v7.8b,  v0.8b
        rshrn           v4.8b,   v16.8h, #3
        rshrn2          v4.16b,  v18.8h, #3
1:
        subs            w4,  w4,  #2
        ld1             {v18.8b,v19.8b,v20.8b},  [x2], x3
        ext             v21.8b,  v19.8b, v20.8b, #1
        ext             v20.8b,  v18.8b, v19.8b, #1
        umull           v22.8h,  v18.8b, v1.8b
        umlal           v22.8h,  v20.8b, v0.8b
        ld1             {v26.8b,v27.8b,v28.8b},  [x2], x3
        umull           v24.8h,  v19.8b, v1.8b
        umlal           v24.8h,  v21.8b, v0.8b
        ext             v29.8b,  v27.8b, v28.8b, #1
        ext             v28.8b,  v26.8b, v27.8b, #1
        umull           v16.8h,  v26.8b, v1.8b
        umlal           v16.8h,  v28.8b, v0.8b
        umull           v18.8h,  v27.8b, v1.8b
        umlal           v18.8h,  v29.8b, v0.8b
        rshrn           v6.8b,   v22.8h, #3
        rshrn2          v6.16b,  v24.8h, #3
        umull           v24.8h,  v4.8b,  v3.8b
        umlal           v24.8h,  v6.8b,  v2.8b
        umull2          v30.8h,  v4.16b, v3.16b
        umlal2          v30.8h,  v6.16b, v2.16b
        rshrn           v4.8b,   v16.8h, #3
        rshrn2          v4.16b,  v18.8h, #3
        umull           v20.8h,  v6.8b,  v3.8b
        umlal           v20.8h,  v4.8b,  v2.8b
        umull2          v22.8h,  v6.16b, v3.16b
        umlal2          v22.8h,  v4.16b, v2.16b
        rshrn           v24.8b,  v24.8h, #3
        rshrn2          v24.16b, v30.8h, #3
        st1             {v24.16b}, [x0], x1
        rshrn           v20.8b,  v20.8h, #3
        rshrn2          v20.16b, v22.8h, #3
        st1             {v20.16b}, [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin8_h_neon, export=1
        mov             w7,     #8
        dup             v0.8b,  w5
        sub             w5,     w7,     w5
        dup             v1.8b,  w5
1:
        subs            w4,     w4,     #2
        ld1             {v2.8b,v3.8b},  [x2],  x3
        ext             v3.8b,  v2.8b,  v3.8b, #1
        umull           v4.8h,  v2.8b,  v1.8b
        umlal           v4.8h,  v3.8b,  v0.8b
        ld1             {v6.8b,v7.8b},  [x2],  x3
        ext             v7.8b,  v6.8b,  v7.8b, #1
        umull           v16.8h, v6.8b,  v1.8b
        umlal           v16.8h, v7.8b,  v0.8b
        rshrn           v4.8b,  v4.8h,  #3
        rshrn           v16.8b, v16.8h, #3
        st1             {v4.8b},  [x0], x1
        st1             {v16.8b}, [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin8_v_neon, export=1
        mov             w7,      #8
        dup             v0.8b,   w6
        sub             w6,      w7,    w6
        dup             v1.8b,   w6

        ld1             {v2.8b}, [x2],  x3
1:
        subs            w4,      w4,    #2
        ld1             {v3.8b}, [x2],  x3
        umull           v4.8h,   v2.8b, v1.8b
        umlal           v4.8h,   v3.8b, v0.8b
        ld1             {v2.8b}, [x2],  x3
        umull           v6.8h,   v3.8b, v1.8b
        umlal           v6.8h,   v2.8b, v0.8b
        rshrn           v4.8b,   v4.8h, #3
        rshrn           v6.8b,   v6.8h, #3
        st1             {v4.8b}, [x0],  x1
        st1             {v6.8b}, [x0],  x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin8_hv_neon, export=1
        mov             w7,     #8
        dup             v0.8b,  w5             // mx
        sub             w5,     w7,     w5
        dup             v1.8b,  w5
        dup             v2.8b,  w6             // my
        sub             w6,     w7,     w6
        dup             v3.8b,  w6

        ld1             {v4.8b,v5.8b},  [x2],  x3
        ext             v5.8b,  v4.8b,  v5.8b, #1
        umull           v18.8h, v4.8b,  v1.8b
        umlal           v18.8h, v5.8b,  v0.8b
        rshrn           v22.8b, v18.8h, #3
1:
        subs            w4,     w4,     #2
        ld1             {v6.8b,v7.8b},  [x2],  x3
        ext             v7.8b,  v6.8b,  v7.8b, #1
        umull           v16.8h, v6.8b,  v1.8b
        umlal           v16.8h, v7.8b,  v0.8b
        ld1             {v4.8b,v5.8b},  [x2],  x3
        ext             v5.8b,  v4.8b,  v5.8b, #1
        umull           v18.8h, v4.8b,  v1.8b
        umlal           v18.8h, v5.8b,  v0.8b
        rshrn           v16.8b, v16.8h, #3
        umull           v20.8h, v22.8b, v3.8b
        umlal           v20.8h, v16.8b, v2.8b
        rshrn           v22.8b, v18.8h, #3
        umull           v24.8h, v16.8b, v3.8b
        umlal           v24.8h, v22.8b, v2.8b
        rshrn           v20.8b, v20.8h, #3
        st1             {v20.8b}, [x0], x1
        rshrn           v23.8b, v24.8h, #3
        st1             {v23.8b}, [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin4_h_neon, export=1
        mov             w7,      #8
        dup             v0.8b,   w5
        sub             w5,      w7,     w5
        dup             v1.8b,   w5
1:
        subs            w4,      w4,     #2
        ld1             {v2.8b}, [x2],   x3
        ext             v3.8b,   v2.8b,  v3.8b,  #1
        ld1             {v6.8b}, [x2],   x3
        ext             v7.8b,   v6.8b,  v7.8b,  #1
        trn1            v2.2s,   v2.2s,  v6.2s
        trn1            v3.2s,   v3.2s,  v7.2s
        umull           v4.8h,   v2.8b,  v1.8b
        umlal           v4.8h,   v3.8b,  v0.8b
        rshrn           v4.8b,   v4.8h,  #3
        st1             {v4.s}[0], [x0], x1
        st1             {v4.s}[1], [x0], x1
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin4_v_neon, export=1
        mov             w7,     #8
        dup             v0.8b,  w6
        sub             w6,     w7,  w6
        dup             v1.8b,  w6

        ld1r            {v2.2s},    [x2], x3
1:
        ld1r            {v3.2s},   [x2]
        ld1             {v2.s}[1], [x2], x3
        ld1             {v3.s}[1], [x2], x3
        umull           v4.8h,  v2.8b,  v1.8b
        umlal           v4.8h,  v3.8b,  v0.8b
        trn2            v2.2s,  v3.2s,  v2.2s
        rshrn           v4.8b,  v4.8h,  #3
        st1             {v4.s}[0], [x0], x1
        st1             {v4.s}[1], [x0], x1
        subs            w4,     w4,     #2
        b.gt            1b

        ret
endfunc

function ff_put_vp8_bilin4_hv_neon, export=1
        mov             w7,      #8
        dup             v0.8b,   w5             // mx
        sub             w5,      w7,     w5
        dup             v1.8b,   w5
        dup             v2.8b,   w6             // my
        sub             w6,      w7,     w6
        dup             v3.8b,   w6

        ld1             {v4.8b}, [x2],   x3
        ext             v5.8b,   v4.8b,  v4.8b,  #1
        umull           v18.8h,  v4.8b,  v1.8b
        umlal           v18.8h,  v5.8b,  v0.8b
        rshrn           v22.8b,  v18.8h, #3
1:
        subs            w4,      w4,     #2
        ld1             {v6.8b}, [x2],   x3
        ext             v7.8b,   v6.8b,  v6.8b,  #1
        ld1             {v4.8b}, [x2],   x3
        ext             v5.8b,   v4.8b,  v4.8b,  #1
        trn1            v6.2s,   v6.2s,  v4.2s
        trn1            v7.2s,   v7.2s,  v5.2s
        umull           v16.8h,  v6.8b,  v1.8b
        umlal           v16.8h,  v7.8b,  v0.8b
        rshrn           v16.8b,  v16.8h, #3
        umull           v20.8h,  v16.8b, v2.8b
        trn1            v22.2s,  v22.2s, v16.2s
        umlal           v20.8h,  v22.8b, v3.8b
        rev64           v22.2s,  v16.2s
        rshrn           v20.8b,  v20.8h, #3
        st1             {v20.s}[0], [x0], x1
        st1             {v20.s}[1], [x0], x1
        b.gt            1b

        ret
endfunc