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
|
/*
* Copyright (c) 2017, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <tmmintrin.h>
#include "config/aom_dsp_rtcd.h"
#include "aom_dsp/intrapred_common.h"
// -----------------------------------------------------------------------------
// PAETH_PRED
// Return 8 16-bit pixels in one row
static INLINE __m128i paeth_8x1_pred(const __m128i *left, const __m128i *top,
const __m128i *topleft) {
const __m128i base = _mm_sub_epi16(_mm_add_epi16(*top, *left), *topleft);
__m128i pl = _mm_abs_epi16(_mm_sub_epi16(base, *left));
__m128i pt = _mm_abs_epi16(_mm_sub_epi16(base, *top));
__m128i ptl = _mm_abs_epi16(_mm_sub_epi16(base, *topleft));
__m128i mask1 = _mm_cmpgt_epi16(pl, pt);
mask1 = _mm_or_si128(mask1, _mm_cmpgt_epi16(pl, ptl));
__m128i mask2 = _mm_cmpgt_epi16(pt, ptl);
pl = _mm_andnot_si128(mask1, *left);
ptl = _mm_and_si128(mask2, *topleft);
pt = _mm_andnot_si128(mask2, *top);
pt = _mm_or_si128(pt, ptl);
pt = _mm_and_si128(mask1, pt);
return _mm_or_si128(pl, pt);
}
void aom_paeth_predictor_4x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_loadl_epi64((const __m128i *)left);
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 4; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
*(uint32_t *)dst = _mm_cvtsi128_si32(_mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_4x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_loadl_epi64((const __m128i *)left);
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 8; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
*(uint32_t *)dst = _mm_cvtsi128_si32(_mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_4x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_load_si128((const __m128i *)left);
const __m128i t = _mm_cvtsi32_si128(((const uint32_t *)above)[0]);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
for (int i = 0; i < 16; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
*(uint32_t *)dst = _mm_cvtsi128_si32(_mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_8x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_loadl_epi64((const __m128i *)left);
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 4; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
_mm_storel_epi64((__m128i *)dst, _mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_8x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_loadl_epi64((const __m128i *)left);
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 8; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
_mm_storel_epi64((__m128i *)dst, _mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_8x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_load_si128((const __m128i *)left);
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 16; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
_mm_storel_epi64((__m128i *)dst, _mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_8x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
const __m128i t = _mm_loadl_epi64((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i t16 = _mm_unpacklo_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
for (int j = 0; j < 2; ++j) {
const __m128i l = _mm_load_si128((const __m128i *)(left + j * 16));
__m128i rep = _mm_set1_epi16(0x8000);
for (int i = 0; i < 16; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_8x1_pred(&l16, &t16, &tl16);
_mm_storel_epi64((__m128i *)dst, _mm_packus_epi16(row, row));
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
}
// Return 16 8-bit pixels in one row
static INLINE __m128i paeth_16x1_pred(const __m128i *left, const __m128i *top0,
const __m128i *top1,
const __m128i *topleft) {
const __m128i p0 = paeth_8x1_pred(left, top0, topleft);
const __m128i p1 = paeth_8x1_pred(left, top1, topleft);
return _mm_packus_epi16(p0, p1);
}
void aom_paeth_predictor_16x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_cvtsi32_si128(((const uint32_t *)left)[0]);
const __m128i t = _mm_load_si128((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i top0 = _mm_unpacklo_epi8(t, zero);
const __m128i top1 = _mm_unpackhi_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
for (int i = 0; i < 4; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_16x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i l = _mm_loadl_epi64((const __m128i *)left);
const __m128i t = _mm_load_si128((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i top0 = _mm_unpacklo_epi8(t, zero);
const __m128i top1 = _mm_unpackhi_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 8; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_16x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i l = _mm_load_si128((const __m128i *)left);
const __m128i t = _mm_load_si128((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i top0 = _mm_unpacklo_epi8(t, zero);
const __m128i top1 = _mm_unpackhi_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
int i;
for (i = 0; i < 16; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_16x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i l = _mm_load_si128((const __m128i *)left);
const __m128i t = _mm_load_si128((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i top0 = _mm_unpacklo_epi8(t, zero);
const __m128i top1 = _mm_unpackhi_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
__m128i l16;
int i;
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
l = _mm_load_si128((const __m128i *)(left + 16));
rep = _mm_set1_epi16(0x8000);
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_16x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i t = _mm_load_si128((const __m128i *)above);
const __m128i zero = _mm_setzero_si128();
const __m128i top0 = _mm_unpacklo_epi8(t, zero);
const __m128i top1 = _mm_unpackhi_epi8(t, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
for (int j = 0; j < 4; ++j) {
const __m128i l = _mm_load_si128((const __m128i *)(left + j * 16));
__m128i rep = _mm_set1_epi16(0x8000);
for (int i = 0; i < 16; ++i) {
const __m128i l16 = _mm_shuffle_epi8(l, rep);
const __m128i row = paeth_16x1_pred(&l16, &top0, &top1, &tl16);
_mm_store_si128((__m128i *)dst, row);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
}
void aom_paeth_predictor_32x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
const __m128i l = _mm_loadl_epi64((const __m128i *)left);
__m128i l16;
for (int i = 0; i < 8; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r32l = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r32h = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
_mm_store_si128((__m128i *)dst, r32l);
_mm_store_si128((__m128i *)(dst + 16), r32h);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_32x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
__m128i l = _mm_load_si128((const __m128i *)left);
__m128i l16;
int i;
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r32l = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r32h = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
_mm_store_si128((__m128i *)dst, r32l);
_mm_store_si128((__m128i *)(dst + 16), r32h);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_32x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
__m128i rep = _mm_set1_epi16(0x8000);
const __m128i one = _mm_set1_epi16(1);
__m128i l = _mm_load_si128((const __m128i *)left);
__m128i l16;
int i;
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r32l = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r32h = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
_mm_store_si128((__m128i *)dst, r32l);
_mm_store_si128((__m128i *)(dst + 16), r32h);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
rep = _mm_set1_epi16(0x8000);
l = _mm_load_si128((const __m128i *)(left + 16));
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r32l = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r32h = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
_mm_store_si128((__m128i *)dst, r32l);
_mm_store_si128((__m128i *)(dst + 16), r32h);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_paeth_predictor_32x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
__m128i l16;
int i, j;
for (j = 0; j < 4; ++j) {
const __m128i l = _mm_load_si128((const __m128i *)(left + j * 16));
__m128i rep = _mm_set1_epi16(0x8000);
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r32l = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r32h = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
_mm_store_si128((__m128i *)dst, r32l);
_mm_store_si128((__m128i *)(dst + 16), r32h);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
}
void aom_paeth_predictor_64x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i c = _mm_load_si128((const __m128i *)(above + 32));
const __m128i d = _mm_load_si128((const __m128i *)(above + 48));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i cl = _mm_unpacklo_epi8(c, zero);
const __m128i ch = _mm_unpackhi_epi8(c, zero);
const __m128i dl = _mm_unpacklo_epi8(d, zero);
const __m128i dh = _mm_unpackhi_epi8(d, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
__m128i l16;
int i, j;
for (j = 0; j < 2; ++j) {
const __m128i l = _mm_load_si128((const __m128i *)(left + j * 16));
__m128i rep = _mm_set1_epi16(0x8000);
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r0 = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r1 = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
const __m128i r2 = paeth_16x1_pred(&l16, &cl, &ch, &tl16);
const __m128i r3 = paeth_16x1_pred(&l16, &dl, &dh, &tl16);
_mm_store_si128((__m128i *)dst, r0);
_mm_store_si128((__m128i *)(dst + 16), r1);
_mm_store_si128((__m128i *)(dst + 32), r2);
_mm_store_si128((__m128i *)(dst + 48), r3);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
}
void aom_paeth_predictor_64x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i c = _mm_load_si128((const __m128i *)(above + 32));
const __m128i d = _mm_load_si128((const __m128i *)(above + 48));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i cl = _mm_unpacklo_epi8(c, zero);
const __m128i ch = _mm_unpackhi_epi8(c, zero);
const __m128i dl = _mm_unpacklo_epi8(d, zero);
const __m128i dh = _mm_unpackhi_epi8(d, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
__m128i l16;
int i, j;
for (j = 0; j < 4; ++j) {
const __m128i l = _mm_load_si128((const __m128i *)(left + j * 16));
__m128i rep = _mm_set1_epi16(0x8000);
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r0 = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r1 = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
const __m128i r2 = paeth_16x1_pred(&l16, &cl, &ch, &tl16);
const __m128i r3 = paeth_16x1_pred(&l16, &dl, &dh, &tl16);
_mm_store_si128((__m128i *)dst, r0);
_mm_store_si128((__m128i *)(dst + 16), r1);
_mm_store_si128((__m128i *)(dst + 32), r2);
_mm_store_si128((__m128i *)(dst + 48), r3);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
}
void aom_paeth_predictor_64x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
const __m128i a = _mm_load_si128((const __m128i *)above);
const __m128i b = _mm_load_si128((const __m128i *)(above + 16));
const __m128i c = _mm_load_si128((const __m128i *)(above + 32));
const __m128i d = _mm_load_si128((const __m128i *)(above + 48));
const __m128i zero = _mm_setzero_si128();
const __m128i al = _mm_unpacklo_epi8(a, zero);
const __m128i ah = _mm_unpackhi_epi8(a, zero);
const __m128i bl = _mm_unpacklo_epi8(b, zero);
const __m128i bh = _mm_unpackhi_epi8(b, zero);
const __m128i cl = _mm_unpacklo_epi8(c, zero);
const __m128i ch = _mm_unpackhi_epi8(c, zero);
const __m128i dl = _mm_unpacklo_epi8(d, zero);
const __m128i dh = _mm_unpackhi_epi8(d, zero);
const __m128i tl16 = _mm_set1_epi16((uint16_t)above[-1]);
const __m128i one = _mm_set1_epi16(1);
__m128i l16;
int i;
const __m128i l = _mm_load_si128((const __m128i *)left);
__m128i rep = _mm_set1_epi16(0x8000);
for (i = 0; i < 16; ++i) {
l16 = _mm_shuffle_epi8(l, rep);
const __m128i r0 = paeth_16x1_pred(&l16, &al, &ah, &tl16);
const __m128i r1 = paeth_16x1_pred(&l16, &bl, &bh, &tl16);
const __m128i r2 = paeth_16x1_pred(&l16, &cl, &ch, &tl16);
const __m128i r3 = paeth_16x1_pred(&l16, &dl, &dh, &tl16);
_mm_store_si128((__m128i *)dst, r0);
_mm_store_si128((__m128i *)(dst + 16), r1);
_mm_store_si128((__m128i *)(dst + 32), r2);
_mm_store_si128((__m128i *)(dst + 48), r3);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
// -----------------------------------------------------------------------------
// SMOOTH_PRED
// pixels[0]: above and below_pred interleave vector
// pixels[1]: left vector
// pixels[2]: right_pred vector
static INLINE void load_pixel_w4(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
__m128i d = _mm_cvtsi32_si128(((const uint32_t *)above)[0]);
if (height == 4)
pixels[1] = _mm_cvtsi32_si128(((const uint32_t *)left)[0]);
else if (height == 8)
pixels[1] = _mm_loadl_epi64(((const __m128i *)left));
else
pixels[1] = _mm_loadu_si128(((const __m128i *)left));
pixels[2] = _mm_set1_epi16((uint16_t)above[3]);
const __m128i bp = _mm_set1_epi16((uint16_t)left[height - 1]);
const __m128i zero = _mm_setzero_si128();
d = _mm_unpacklo_epi8(d, zero);
pixels[0] = _mm_unpacklo_epi16(d, bp);
}
// weight_h[0]: weight_h vector
// weight_h[1]: scale - weight_h vector
// weight_h[2]: same as [0], second half for height = 16 only
// weight_h[3]: same as [1], second half for height = 16 only
// weight_w[0]: weights_w and scale - weights_w interleave vector
static INLINE void load_weight_w4(const uint8_t *weight_array, int height,
__m128i *weight_h, __m128i *weight_w) {
const __m128i zero = _mm_setzero_si128();
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i t = _mm_cvtsi32_si128(((const uint32_t *)weight_array)[1]);
weight_h[0] = _mm_unpacklo_epi8(t, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_w[0] = _mm_unpacklo_epi16(weight_h[0], weight_h[1]);
if (height == 8) {
const __m128i weight = _mm_loadl_epi64((const __m128i *)&weight_array[8]);
weight_h[0] = _mm_unpacklo_epi8(weight, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
} else if (height == 16) {
const __m128i weight = _mm_loadu_si128((const __m128i *)&weight_array[16]);
weight_h[0] = _mm_unpacklo_epi8(weight, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_h[2] = _mm_unpackhi_epi8(weight, zero);
weight_h[3] = _mm_sub_epi16(d, weight_h[2]);
}
}
static INLINE void smooth_pred_4xh(const __m128i *pixel, const __m128i *wh,
const __m128i *ww, int h, uint8_t *dst,
ptrdiff_t stride, int second_half) {
const __m128i round = _mm_set1_epi32((1 << sm_weight_log2_scale));
const __m128i one = _mm_set1_epi16(1);
const __m128i inc = _mm_set1_epi16(0x202);
const __m128i gat = _mm_set1_epi32(0xc080400);
__m128i rep = second_half ? _mm_set1_epi16(0x8008) : _mm_set1_epi16(0x8000);
__m128i d = _mm_set1_epi16(0x100);
for (int i = 0; i < h; ++i) {
const __m128i wg_wg = _mm_shuffle_epi8(wh[0], d);
const __m128i sc_sc = _mm_shuffle_epi8(wh[1], d);
const __m128i wh_sc = _mm_unpacklo_epi16(wg_wg, sc_sc);
__m128i s = _mm_madd_epi16(pixel[0], wh_sc);
__m128i b = _mm_shuffle_epi8(pixel[1], rep);
b = _mm_unpacklo_epi16(b, pixel[2]);
__m128i sum = _mm_madd_epi16(b, ww[0]);
sum = _mm_add_epi32(s, sum);
sum = _mm_add_epi32(sum, round);
sum = _mm_srai_epi32(sum, 1 + sm_weight_log2_scale);
sum = _mm_shuffle_epi8(sum, gat);
*(uint32_t *)dst = _mm_cvtsi128_si32(sum);
dst += stride;
rep = _mm_add_epi16(rep, one);
d = _mm_add_epi16(d, inc);
}
}
void aom_smooth_predictor_4x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i pixels[3];
load_pixel_w4(above, left, 4, pixels);
__m128i wh[4], ww[2];
load_weight_w4(sm_weight_arrays, 4, wh, ww);
smooth_pred_4xh(pixels, wh, ww, 4, dst, stride, 0);
}
void aom_smooth_predictor_4x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i pixels[3];
load_pixel_w4(above, left, 8, pixels);
__m128i wh[4], ww[2];
load_weight_w4(sm_weight_arrays, 8, wh, ww);
smooth_pred_4xh(pixels, wh, ww, 8, dst, stride, 0);
}
void aom_smooth_predictor_4x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[3];
load_pixel_w4(above, left, 16, pixels);
__m128i wh[4], ww[2];
load_weight_w4(sm_weight_arrays, 16, wh, ww);
smooth_pred_4xh(pixels, wh, ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_pred_4xh(pixels, &wh[2], ww, 8, dst, stride, 1);
}
// pixels[0]: above and below_pred interleave vector, first half
// pixels[1]: above and below_pred interleave vector, second half
// pixels[2]: left vector
// pixels[3]: right_pred vector
// pixels[4]: above and below_pred interleave vector, first half
// pixels[5]: above and below_pred interleave vector, second half
// pixels[6]: left vector + 16
// pixels[7]: right_pred vector
static INLINE void load_pixel_w8(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
const __m128i zero = _mm_setzero_si128();
const __m128i bp = _mm_set1_epi16((uint16_t)left[height - 1]);
__m128i d = _mm_loadl_epi64((const __m128i *)above);
d = _mm_unpacklo_epi8(d, zero);
pixels[0] = _mm_unpacklo_epi16(d, bp);
pixels[1] = _mm_unpackhi_epi16(d, bp);
pixels[3] = _mm_set1_epi16((uint16_t)above[7]);
if (height == 4) {
pixels[2] = _mm_cvtsi32_si128(((const uint32_t *)left)[0]);
} else if (height == 8) {
pixels[2] = _mm_loadl_epi64((const __m128i *)left);
} else if (height == 16) {
pixels[2] = _mm_load_si128((const __m128i *)left);
} else {
pixels[2] = _mm_load_si128((const __m128i *)left);
pixels[4] = pixels[0];
pixels[5] = pixels[1];
pixels[6] = _mm_load_si128((const __m128i *)(left + 16));
pixels[7] = pixels[3];
}
}
// weight_h[0]: weight_h vector
// weight_h[1]: scale - weight_h vector
// weight_h[2]: same as [0], offset 8
// weight_h[3]: same as [1], offset 8
// weight_h[4]: same as [0], offset 16
// weight_h[5]: same as [1], offset 16
// weight_h[6]: same as [0], offset 24
// weight_h[7]: same as [1], offset 24
// weight_w[0]: weights_w and scale - weights_w interleave vector, first half
// weight_w[1]: weights_w and scale - weights_w interleave vector, second half
static INLINE void load_weight_w8(const uint8_t *weight_array, int height,
__m128i *weight_h, __m128i *weight_w) {
const __m128i zero = _mm_setzero_si128();
const int we_offset = height < 8 ? 4 : 8;
__m128i we = _mm_loadu_si128((const __m128i *)&weight_array[we_offset]);
weight_h[0] = _mm_unpacklo_epi8(we, zero);
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
if (height == 4) {
we = _mm_srli_si128(we, 4);
__m128i tmp1 = _mm_unpacklo_epi8(we, zero);
__m128i tmp2 = _mm_sub_epi16(d, tmp1);
weight_w[0] = _mm_unpacklo_epi16(tmp1, tmp2);
weight_w[1] = _mm_unpackhi_epi16(tmp1, tmp2);
} else {
weight_w[0] = _mm_unpacklo_epi16(weight_h[0], weight_h[1]);
weight_w[1] = _mm_unpackhi_epi16(weight_h[0], weight_h[1]);
}
if (height == 16) {
we = _mm_loadu_si128((const __m128i *)&weight_array[16]);
weight_h[0] = _mm_unpacklo_epi8(we, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_h[2] = _mm_unpackhi_epi8(we, zero);
weight_h[3] = _mm_sub_epi16(d, weight_h[2]);
} else if (height == 32) {
const __m128i weight_lo =
_mm_loadu_si128((const __m128i *)&weight_array[32]);
weight_h[0] = _mm_unpacklo_epi8(weight_lo, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_h[2] = _mm_unpackhi_epi8(weight_lo, zero);
weight_h[3] = _mm_sub_epi16(d, weight_h[2]);
const __m128i weight_hi =
_mm_loadu_si128((const __m128i *)&weight_array[32 + 16]);
weight_h[4] = _mm_unpacklo_epi8(weight_hi, zero);
weight_h[5] = _mm_sub_epi16(d, weight_h[4]);
weight_h[6] = _mm_unpackhi_epi8(weight_hi, zero);
weight_h[7] = _mm_sub_epi16(d, weight_h[6]);
}
}
static INLINE void smooth_pred_8xh(const __m128i *pixels, const __m128i *wh,
const __m128i *ww, int h, uint8_t *dst,
ptrdiff_t stride, int second_half) {
const __m128i round = _mm_set1_epi32((1 << sm_weight_log2_scale));
const __m128i one = _mm_set1_epi16(1);
const __m128i inc = _mm_set1_epi16(0x202);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
__m128i rep = second_half ? _mm_set1_epi16(0x8008) : _mm_set1_epi16(0x8000);
__m128i d = _mm_set1_epi16(0x100);
int i;
for (i = 0; i < h; ++i) {
const __m128i wg_wg = _mm_shuffle_epi8(wh[0], d);
const __m128i sc_sc = _mm_shuffle_epi8(wh[1], d);
const __m128i wh_sc = _mm_unpacklo_epi16(wg_wg, sc_sc);
__m128i s0 = _mm_madd_epi16(pixels[0], wh_sc);
__m128i s1 = _mm_madd_epi16(pixels[1], wh_sc);
__m128i b = _mm_shuffle_epi8(pixels[2], rep);
b = _mm_unpacklo_epi16(b, pixels[3]);
__m128i sum0 = _mm_madd_epi16(b, ww[0]);
__m128i sum1 = _mm_madd_epi16(b, ww[1]);
s0 = _mm_add_epi32(s0, sum0);
s0 = _mm_add_epi32(s0, round);
s0 = _mm_srai_epi32(s0, 1 + sm_weight_log2_scale);
s1 = _mm_add_epi32(s1, sum1);
s1 = _mm_add_epi32(s1, round);
s1 = _mm_srai_epi32(s1, 1 + sm_weight_log2_scale);
sum0 = _mm_packus_epi16(s0, s1);
sum0 = _mm_shuffle_epi8(sum0, gat);
_mm_storel_epi64((__m128i *)dst, sum0);
dst += stride;
rep = _mm_add_epi16(rep, one);
d = _mm_add_epi16(d, inc);
}
}
void aom_smooth_predictor_8x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i pixels[4];
load_pixel_w8(above, left, 4, pixels);
__m128i wh[4], ww[2];
load_weight_w8(sm_weight_arrays, 4, wh, ww);
smooth_pred_8xh(pixels, wh, ww, 4, dst, stride, 0);
}
void aom_smooth_predictor_8x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left) {
__m128i pixels[4];
load_pixel_w8(above, left, 8, pixels);
__m128i wh[4], ww[2];
load_weight_w8(sm_weight_arrays, 8, wh, ww);
smooth_pred_8xh(pixels, wh, ww, 8, dst, stride, 0);
}
void aom_smooth_predictor_8x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[4];
load_pixel_w8(above, left, 16, pixels);
__m128i wh[4], ww[2];
load_weight_w8(sm_weight_arrays, 16, wh, ww);
smooth_pred_8xh(pixels, wh, ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_pred_8xh(pixels, &wh[2], ww, 8, dst, stride, 1);
}
void aom_smooth_predictor_8x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[8];
load_pixel_w8(above, left, 32, pixels);
__m128i wh[8], ww[2];
load_weight_w8(sm_weight_arrays, 32, wh, ww);
smooth_pred_8xh(&pixels[0], wh, ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_pred_8xh(&pixels[0], &wh[2], ww, 8, dst, stride, 1);
dst += stride << 3;
smooth_pred_8xh(&pixels[4], &wh[4], ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_pred_8xh(&pixels[4], &wh[6], ww, 8, dst, stride, 1);
}
static INLINE void smooth_predictor_wxh(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left, uint32_t bw,
uint32_t bh) {
const uint8_t *const sm_weights_w = sm_weight_arrays + bw;
const uint8_t *const sm_weights_h = sm_weight_arrays + bh;
const __m128i zero = _mm_setzero_si128();
const __m128i scale_value =
_mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i bottom_left = _mm_cvtsi32_si128((uint32_t)left[bh - 1]);
const __m128i dup16 = _mm_set1_epi32(0x01000100);
const __m128i top_right =
_mm_shuffle_epi8(_mm_cvtsi32_si128((uint32_t)above[bw - 1]), dup16);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
const __m128i round = _mm_set1_epi32((uint16_t)(1 << sm_weight_log2_scale));
for (uint32_t y = 0; y < bh; ++y) {
const __m128i weights_y = _mm_cvtsi32_si128((uint32_t)sm_weights_h[y]);
const __m128i left_y = _mm_cvtsi32_si128((uint32_t)left[y]);
const __m128i scale_m_weights_y = _mm_sub_epi16(scale_value, weights_y);
__m128i pred_scaled_bl = _mm_mullo_epi16(scale_m_weights_y, bottom_left);
const __m128i wl_y =
_mm_shuffle_epi32(_mm_unpacklo_epi16(weights_y, left_y), 0);
pred_scaled_bl = _mm_add_epi32(pred_scaled_bl, round);
pred_scaled_bl = _mm_shuffle_epi32(pred_scaled_bl, 0);
for (uint32_t x = 0; x < bw; x += 8) {
const __m128i top_x = _mm_loadl_epi64((const __m128i *)(above + x));
const __m128i weights_x =
_mm_loadl_epi64((const __m128i *)(sm_weights_w + x));
const __m128i tw_x = _mm_unpacklo_epi8(top_x, weights_x);
const __m128i tw_x_lo = _mm_unpacklo_epi8(tw_x, zero);
const __m128i tw_x_hi = _mm_unpackhi_epi8(tw_x, zero);
__m128i pred_lo = _mm_madd_epi16(tw_x_lo, wl_y);
__m128i pred_hi = _mm_madd_epi16(tw_x_hi, wl_y);
const __m128i scale_m_weights_x =
_mm_sub_epi16(scale_value, _mm_unpacklo_epi8(weights_x, zero));
const __m128i swxtr = _mm_mullo_epi16(scale_m_weights_x, top_right);
const __m128i swxtr_lo = _mm_unpacklo_epi16(swxtr, zero);
const __m128i swxtr_hi = _mm_unpackhi_epi16(swxtr, zero);
pred_lo = _mm_add_epi32(pred_lo, pred_scaled_bl);
pred_hi = _mm_add_epi32(pred_hi, pred_scaled_bl);
pred_lo = _mm_add_epi32(pred_lo, swxtr_lo);
pred_hi = _mm_add_epi32(pred_hi, swxtr_hi);
pred_lo = _mm_srai_epi32(pred_lo, (1 + sm_weight_log2_scale));
pred_hi = _mm_srai_epi32(pred_hi, (1 + sm_weight_log2_scale));
__m128i pred = _mm_packus_epi16(pred_lo, pred_hi);
pred = _mm_shuffle_epi8(pred, gat);
_mm_storel_epi64((__m128i *)(dst + x), pred);
}
dst += stride;
}
}
void aom_smooth_predictor_16x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 16, 4);
}
void aom_smooth_predictor_16x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 16, 8);
}
void aom_smooth_predictor_16x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 16, 16);
}
void aom_smooth_predictor_16x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 16, 32);
}
void aom_smooth_predictor_32x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 32, 8);
}
void aom_smooth_predictor_32x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 32, 16);
}
void aom_smooth_predictor_32x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 32, 32);
}
void aom_smooth_predictor_32x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 32, 64);
}
void aom_smooth_predictor_64x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 64, 64);
}
void aom_smooth_predictor_64x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 64, 32);
}
void aom_smooth_predictor_64x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 64, 16);
}
void aom_smooth_predictor_16x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_predictor_wxh(dst, stride, above, left, 16, 64);
}
// -----------------------------------------------------------------------------
// SMOOTH_V_PRED
// pixels[0]: above and below_pred interleave vector
static INLINE void load_pixel_v_w4(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
const __m128i zero = _mm_setzero_si128();
__m128i d = _mm_cvtsi32_si128(((const uint32_t *)above)[0]);
const __m128i bp = _mm_set1_epi16((uint16_t)left[height - 1]);
d = _mm_unpacklo_epi8(d, zero);
pixels[0] = _mm_unpacklo_epi16(d, bp);
}
// weights[0]: weights_h vector
// weights[1]: scale - weights_h vector
static INLINE void load_weight_v_w4(const uint8_t *weight_array, int height,
__m128i *weights) {
const __m128i zero = _mm_setzero_si128();
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
if (height == 4) {
const __m128i weight =
_mm_cvtsi32_si128(((const uint32_t *)weight_array)[1]);
weights[0] = _mm_unpacklo_epi8(weight, zero);
weights[1] = _mm_sub_epi16(d, weights[0]);
} else if (height == 8) {
const __m128i weight = _mm_loadl_epi64((const __m128i *)&weight_array[8]);
weights[0] = _mm_unpacklo_epi8(weight, zero);
weights[1] = _mm_sub_epi16(d, weights[0]);
} else {
const __m128i weight = _mm_loadu_si128((const __m128i *)&weight_array[16]);
weights[0] = _mm_unpacklo_epi8(weight, zero);
weights[1] = _mm_sub_epi16(d, weights[0]);
weights[2] = _mm_unpackhi_epi8(weight, zero);
weights[3] = _mm_sub_epi16(d, weights[2]);
}
}
static INLINE void smooth_v_pred_4xh(const __m128i *pixel,
const __m128i *weight, int h, uint8_t *dst,
ptrdiff_t stride) {
const __m128i pred_round = _mm_set1_epi32((1 << (sm_weight_log2_scale - 1)));
const __m128i inc = _mm_set1_epi16(0x202);
const __m128i gat = _mm_set1_epi32(0xc080400);
__m128i d = _mm_set1_epi16(0x100);
for (int i = 0; i < h; ++i) {
const __m128i wg_wg = _mm_shuffle_epi8(weight[0], d);
const __m128i sc_sc = _mm_shuffle_epi8(weight[1], d);
const __m128i wh_sc = _mm_unpacklo_epi16(wg_wg, sc_sc);
__m128i sum = _mm_madd_epi16(pixel[0], wh_sc);
sum = _mm_add_epi32(sum, pred_round);
sum = _mm_srai_epi32(sum, sm_weight_log2_scale);
sum = _mm_shuffle_epi8(sum, gat);
*(uint32_t *)dst = _mm_cvtsi128_si32(sum);
dst += stride;
d = _mm_add_epi16(d, inc);
}
}
void aom_smooth_v_predictor_4x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels;
load_pixel_v_w4(above, left, 4, &pixels);
__m128i weights[2];
load_weight_v_w4(sm_weight_arrays, 4, weights);
smooth_v_pred_4xh(&pixels, weights, 4, dst, stride);
}
void aom_smooth_v_predictor_4x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels;
load_pixel_v_w4(above, left, 8, &pixels);
__m128i weights[2];
load_weight_v_w4(sm_weight_arrays, 8, weights);
smooth_v_pred_4xh(&pixels, weights, 8, dst, stride);
}
void aom_smooth_v_predictor_4x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels;
load_pixel_v_w4(above, left, 16, &pixels);
__m128i weights[4];
load_weight_v_w4(sm_weight_arrays, 16, weights);
smooth_v_pred_4xh(&pixels, weights, 8, dst, stride);
dst += stride << 3;
smooth_v_pred_4xh(&pixels, &weights[2], 8, dst, stride);
}
// pixels[0]: above and below_pred interleave vector, first half
// pixels[1]: above and below_pred interleave vector, second half
static INLINE void load_pixel_v_w8(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
const __m128i zero = _mm_setzero_si128();
__m128i d = _mm_loadl_epi64((const __m128i *)above);
const __m128i bp = _mm_set1_epi16((uint16_t)left[height - 1]);
d = _mm_unpacklo_epi8(d, zero);
pixels[0] = _mm_unpacklo_epi16(d, bp);
pixels[1] = _mm_unpackhi_epi16(d, bp);
}
// weight_h[0]: weight_h vector
// weight_h[1]: scale - weight_h vector
// weight_h[2]: same as [0], offset 8
// weight_h[3]: same as [1], offset 8
// weight_h[4]: same as [0], offset 16
// weight_h[5]: same as [1], offset 16
// weight_h[6]: same as [0], offset 24
// weight_h[7]: same as [1], offset 24
static INLINE void load_weight_v_w8(const uint8_t *weight_array, int height,
__m128i *weight_h) {
const __m128i zero = _mm_setzero_si128();
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
if (height < 16) {
const int offset = height < 8 ? 4 : 8;
const __m128i weight =
_mm_loadu_si128((const __m128i *)&weight_array[offset]);
weight_h[0] = _mm_unpacklo_epi8(weight, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
} else if (height == 16) {
const __m128i weight = _mm_loadu_si128((const __m128i *)&weight_array[16]);
weight_h[0] = _mm_unpacklo_epi8(weight, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_h[2] = _mm_unpackhi_epi8(weight, zero);
weight_h[3] = _mm_sub_epi16(d, weight_h[2]);
} else {
const __m128i weight_lo =
_mm_loadu_si128((const __m128i *)&weight_array[32]);
weight_h[0] = _mm_unpacklo_epi8(weight_lo, zero);
weight_h[1] = _mm_sub_epi16(d, weight_h[0]);
weight_h[2] = _mm_unpackhi_epi8(weight_lo, zero);
weight_h[3] = _mm_sub_epi16(d, weight_h[2]);
const __m128i weight_hi =
_mm_loadu_si128((const __m128i *)&weight_array[32 + 16]);
weight_h[4] = _mm_unpacklo_epi8(weight_hi, zero);
weight_h[5] = _mm_sub_epi16(d, weight_h[4]);
weight_h[6] = _mm_unpackhi_epi8(weight_hi, zero);
weight_h[7] = _mm_sub_epi16(d, weight_h[6]);
}
}
static INLINE void smooth_v_pred_8xh(const __m128i *pixels, const __m128i *wh,
int h, uint8_t *dst, ptrdiff_t stride) {
const __m128i pred_round = _mm_set1_epi32((1 << (sm_weight_log2_scale - 1)));
const __m128i inc = _mm_set1_epi16(0x202);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
__m128i d = _mm_set1_epi16(0x100);
for (int i = 0; i < h; ++i) {
const __m128i wg_wg = _mm_shuffle_epi8(wh[0], d);
const __m128i sc_sc = _mm_shuffle_epi8(wh[1], d);
const __m128i wh_sc = _mm_unpacklo_epi16(wg_wg, sc_sc);
__m128i s0 = _mm_madd_epi16(pixels[0], wh_sc);
__m128i s1 = _mm_madd_epi16(pixels[1], wh_sc);
s0 = _mm_add_epi32(s0, pred_round);
s0 = _mm_srai_epi32(s0, sm_weight_log2_scale);
s1 = _mm_add_epi32(s1, pred_round);
s1 = _mm_srai_epi32(s1, sm_weight_log2_scale);
__m128i sum01 = _mm_packus_epi16(s0, s1);
sum01 = _mm_shuffle_epi8(sum01, gat);
_mm_storel_epi64((__m128i *)dst, sum01);
dst += stride;
d = _mm_add_epi16(d, inc);
}
}
void aom_smooth_v_predictor_8x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_v_w8(above, left, 4, pixels);
__m128i wh[2];
load_weight_v_w8(sm_weight_arrays, 4, wh);
smooth_v_pred_8xh(pixels, wh, 4, dst, stride);
}
void aom_smooth_v_predictor_8x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_v_w8(above, left, 8, pixels);
__m128i wh[2];
load_weight_v_w8(sm_weight_arrays, 8, wh);
smooth_v_pred_8xh(pixels, wh, 8, dst, stride);
}
void aom_smooth_v_predictor_8x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_v_w8(above, left, 16, pixels);
__m128i wh[4];
load_weight_v_w8(sm_weight_arrays, 16, wh);
smooth_v_pred_8xh(pixels, wh, 8, dst, stride);
dst += stride << 3;
smooth_v_pred_8xh(pixels, &wh[2], 8, dst, stride);
}
void aom_smooth_v_predictor_8x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_v_w8(above, left, 32, pixels);
__m128i wh[8];
load_weight_v_w8(sm_weight_arrays, 32, wh);
smooth_v_pred_8xh(pixels, &wh[0], 8, dst, stride);
dst += stride << 3;
smooth_v_pred_8xh(pixels, &wh[2], 8, dst, stride);
dst += stride << 3;
smooth_v_pred_8xh(pixels, &wh[4], 8, dst, stride);
dst += stride << 3;
smooth_v_pred_8xh(pixels, &wh[6], 8, dst, stride);
}
static INLINE void smooth_v_predictor_wxh(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left, uint32_t bw,
uint32_t bh) {
const uint8_t *const sm_weights_h = sm_weight_arrays + bh;
const __m128i zero = _mm_setzero_si128();
const __m128i scale_value =
_mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i dup16 = _mm_set1_epi32(0x01000100);
const __m128i bottom_left =
_mm_shuffle_epi8(_mm_cvtsi32_si128((uint32_t)left[bh - 1]), dup16);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
const __m128i round =
_mm_set1_epi32((uint16_t)(1 << (sm_weight_log2_scale - 1)));
for (uint32_t y = 0; y < bh; ++y) {
const __m128i weights_y = _mm_cvtsi32_si128((uint32_t)sm_weights_h[y]);
const __m128i scale_m_weights_y =
_mm_shuffle_epi8(_mm_sub_epi16(scale_value, weights_y), dup16);
const __m128i wl_y =
_mm_shuffle_epi32(_mm_unpacklo_epi16(weights_y, bottom_left), 0);
for (uint32_t x = 0; x < bw; x += 8) {
const __m128i top_x = _mm_loadl_epi64((const __m128i *)(above + x));
// 8 -> 16
const __m128i tw_x = _mm_unpacklo_epi8(top_x, zero);
const __m128i tw_x_lo = _mm_unpacklo_epi16(tw_x, scale_m_weights_y);
const __m128i tw_x_hi = _mm_unpackhi_epi16(tw_x, scale_m_weights_y);
// top_x * weights_y + scale_m_weights_y * bottom_left
__m128i pred_lo = _mm_madd_epi16(tw_x_lo, wl_y);
__m128i pred_hi = _mm_madd_epi16(tw_x_hi, wl_y);
pred_lo = _mm_add_epi32(pred_lo, round);
pred_hi = _mm_add_epi32(pred_hi, round);
pred_lo = _mm_srai_epi32(pred_lo, sm_weight_log2_scale);
pred_hi = _mm_srai_epi32(pred_hi, sm_weight_log2_scale);
__m128i pred = _mm_packus_epi16(pred_lo, pred_hi);
pred = _mm_shuffle_epi8(pred, gat);
_mm_storel_epi64((__m128i *)(dst + x), pred);
}
dst += stride;
}
}
void aom_smooth_v_predictor_16x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 16, 4);
}
void aom_smooth_v_predictor_16x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 16, 8);
}
void aom_smooth_v_predictor_16x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 16, 16);
}
void aom_smooth_v_predictor_16x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 16, 32);
}
void aom_smooth_v_predictor_32x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 32, 8);
}
void aom_smooth_v_predictor_32x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 32, 16);
}
void aom_smooth_v_predictor_32x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 32, 32);
}
void aom_smooth_v_predictor_32x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 32, 64);
}
void aom_smooth_v_predictor_64x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 64, 64);
}
void aom_smooth_v_predictor_64x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 64, 32);
}
void aom_smooth_v_predictor_64x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 64, 16);
}
void aom_smooth_v_predictor_16x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_v_predictor_wxh(dst, stride, above, left, 16, 64);
}
// -----------------------------------------------------------------------------
// SMOOTH_H_PRED
// pixels[0]: left vector
// pixels[1]: right_pred vector
static INLINE void load_pixel_h_w4(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
if (height == 4)
pixels[0] = _mm_cvtsi32_si128(((const uint32_t *)left)[0]);
else if (height == 8)
pixels[0] = _mm_loadl_epi64(((const __m128i *)left));
else
pixels[0] = _mm_loadu_si128(((const __m128i *)left));
pixels[1] = _mm_set1_epi16((uint16_t)above[3]);
}
// weights[0]: weights_w and scale - weights_w interleave vector
static INLINE void load_weight_h_w4(const uint8_t *weight_array, int height,
__m128i *weights) {
(void)height;
const __m128i t = _mm_loadu_si128((const __m128i *)&weight_array[4]);
const __m128i zero = _mm_setzero_si128();
const __m128i weights_0 = _mm_unpacklo_epi8(t, zero);
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i weights_1 = _mm_sub_epi16(d, weights_0);
weights[0] = _mm_unpacklo_epi16(weights_0, weights_1);
}
static INLINE void smooth_h_pred_4xh(const __m128i *pixel,
const __m128i *weight, int h, uint8_t *dst,
ptrdiff_t stride) {
const __m128i pred_round = _mm_set1_epi32((1 << (sm_weight_log2_scale - 1)));
const __m128i one = _mm_set1_epi16(1);
const __m128i gat = _mm_set1_epi32(0xc080400);
__m128i rep = _mm_set1_epi16(0x8000);
for (int i = 0; i < h; ++i) {
__m128i b = _mm_shuffle_epi8(pixel[0], rep);
b = _mm_unpacklo_epi16(b, pixel[1]);
__m128i sum = _mm_madd_epi16(b, weight[0]);
sum = _mm_add_epi32(sum, pred_round);
sum = _mm_srai_epi32(sum, sm_weight_log2_scale);
sum = _mm_shuffle_epi8(sum, gat);
*(uint32_t *)dst = _mm_cvtsi128_si32(sum);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_smooth_h_predictor_4x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w4(above, left, 4, pixels);
__m128i weights;
load_weight_h_w4(sm_weight_arrays, 4, &weights);
smooth_h_pred_4xh(pixels, &weights, 4, dst, stride);
}
void aom_smooth_h_predictor_4x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w4(above, left, 8, pixels);
__m128i weights;
load_weight_h_w4(sm_weight_arrays, 8, &weights);
smooth_h_pred_4xh(pixels, &weights, 8, dst, stride);
}
void aom_smooth_h_predictor_4x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w4(above, left, 16, pixels);
__m128i weights;
load_weight_h_w4(sm_weight_arrays, 8, &weights);
smooth_h_pred_4xh(pixels, &weights, 8, dst, stride);
dst += stride << 3;
pixels[0] = _mm_srli_si128(pixels[0], 8);
smooth_h_pred_4xh(pixels, &weights, 8, dst, stride);
}
// pixels[0]: left vector
// pixels[1]: right_pred vector
// pixels[2]: left vector + 16
// pixels[3]: right_pred vector
static INLINE void load_pixel_h_w8(const uint8_t *above, const uint8_t *left,
int height, __m128i *pixels) {
pixels[1] = _mm_set1_epi16((uint16_t)above[7]);
if (height == 4) {
pixels[0] = _mm_cvtsi32_si128(((const uint32_t *)left)[0]);
} else if (height == 8) {
pixels[0] = _mm_loadl_epi64((const __m128i *)left);
} else if (height == 16) {
pixels[0] = _mm_load_si128((const __m128i *)left);
} else {
pixels[0] = _mm_load_si128((const __m128i *)left);
pixels[2] = _mm_load_si128((const __m128i *)(left + 16));
pixels[3] = pixels[1];
}
}
// weight_w[0]: weights_w and scale - weights_w interleave vector, first half
// weight_w[1]: weights_w and scale - weights_w interleave vector, second half
static INLINE void load_weight_h_w8(const uint8_t *weight_array, int height,
__m128i *weight_w) {
(void)height;
const __m128i zero = _mm_setzero_si128();
const __m128i d = _mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i we = _mm_loadu_si128((const __m128i *)&weight_array[8]);
const __m128i tmp1 = _mm_unpacklo_epi8(we, zero);
const __m128i tmp2 = _mm_sub_epi16(d, tmp1);
weight_w[0] = _mm_unpacklo_epi16(tmp1, tmp2);
weight_w[1] = _mm_unpackhi_epi16(tmp1, tmp2);
}
static INLINE void smooth_h_pred_8xh(const __m128i *pixels, const __m128i *ww,
int h, uint8_t *dst, ptrdiff_t stride,
int second_half) {
const __m128i pred_round = _mm_set1_epi32((1 << (sm_weight_log2_scale - 1)));
const __m128i one = _mm_set1_epi16(1);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
__m128i rep = second_half ? _mm_set1_epi16(0x8008) : _mm_set1_epi16(0x8000);
for (int i = 0; i < h; ++i) {
__m128i b = _mm_shuffle_epi8(pixels[0], rep);
b = _mm_unpacklo_epi16(b, pixels[1]);
__m128i sum0 = _mm_madd_epi16(b, ww[0]);
__m128i sum1 = _mm_madd_epi16(b, ww[1]);
sum0 = _mm_add_epi32(sum0, pred_round);
sum0 = _mm_srai_epi32(sum0, sm_weight_log2_scale);
sum1 = _mm_add_epi32(sum1, pred_round);
sum1 = _mm_srai_epi32(sum1, sm_weight_log2_scale);
sum0 = _mm_packus_epi16(sum0, sum1);
sum0 = _mm_shuffle_epi8(sum0, gat);
_mm_storel_epi64((__m128i *)dst, sum0);
dst += stride;
rep = _mm_add_epi16(rep, one);
}
}
void aom_smooth_h_predictor_8x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w8(above, left, 4, pixels);
__m128i ww[2];
load_weight_h_w8(sm_weight_arrays, 4, ww);
smooth_h_pred_8xh(pixels, ww, 4, dst, stride, 0);
}
void aom_smooth_h_predictor_8x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w8(above, left, 8, pixels);
__m128i ww[2];
load_weight_h_w8(sm_weight_arrays, 8, ww);
smooth_h_pred_8xh(pixels, ww, 8, dst, stride, 0);
}
void aom_smooth_h_predictor_8x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[2];
load_pixel_h_w8(above, left, 16, pixels);
__m128i ww[2];
load_weight_h_w8(sm_weight_arrays, 16, ww);
smooth_h_pred_8xh(pixels, ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_h_pred_8xh(pixels, ww, 8, dst, stride, 1);
}
void aom_smooth_h_predictor_8x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
__m128i pixels[4];
load_pixel_h_w8(above, left, 32, pixels);
__m128i ww[2];
load_weight_h_w8(sm_weight_arrays, 32, ww);
smooth_h_pred_8xh(&pixels[0], ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_h_pred_8xh(&pixels[0], ww, 8, dst, stride, 1);
dst += stride << 3;
smooth_h_pred_8xh(&pixels[2], ww, 8, dst, stride, 0);
dst += stride << 3;
smooth_h_pred_8xh(&pixels[2], ww, 8, dst, stride, 1);
}
static INLINE void smooth_h_predictor_wxh(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left, uint32_t bw,
uint32_t bh) {
const uint8_t *const sm_weights_w = sm_weight_arrays + bw;
const __m128i zero = _mm_setzero_si128();
const __m128i scale_value =
_mm_set1_epi16((uint16_t)(1 << sm_weight_log2_scale));
const __m128i top_right = _mm_cvtsi32_si128((uint32_t)above[bw - 1]);
const __m128i gat = _mm_set_epi32(0, 0, 0xe0c0a08, 0x6040200);
const __m128i pred_round = _mm_set1_epi32((1 << (sm_weight_log2_scale - 1)));
for (uint32_t y = 0; y < bh; ++y) {
const __m128i left_y = _mm_cvtsi32_si128((uint32_t)left[y]);
const __m128i tr_ly =
_mm_shuffle_epi32(_mm_unpacklo_epi16(top_right, left_y), 0);
for (uint32_t x = 0; x < bw; x += 8) {
const __m128i weights_x =
_mm_loadl_epi64((const __m128i *)(sm_weights_w + x));
const __m128i weights_xw = _mm_unpacklo_epi8(weights_x, zero);
const __m128i scale_m_weights_x = _mm_sub_epi16(scale_value, weights_xw);
const __m128i wx_lo = _mm_unpacklo_epi16(scale_m_weights_x, weights_xw);
const __m128i wx_hi = _mm_unpackhi_epi16(scale_m_weights_x, weights_xw);
__m128i pred_lo = _mm_madd_epi16(wx_lo, tr_ly);
__m128i pred_hi = _mm_madd_epi16(wx_hi, tr_ly);
pred_lo = _mm_add_epi32(pred_lo, pred_round);
pred_hi = _mm_add_epi32(pred_hi, pred_round);
pred_lo = _mm_srai_epi32(pred_lo, sm_weight_log2_scale);
pred_hi = _mm_srai_epi32(pred_hi, sm_weight_log2_scale);
__m128i pred = _mm_packus_epi16(pred_lo, pred_hi);
pred = _mm_shuffle_epi8(pred, gat);
_mm_storel_epi64((__m128i *)(dst + x), pred);
}
dst += stride;
}
}
void aom_smooth_h_predictor_16x4_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 16, 4);
}
void aom_smooth_h_predictor_16x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 16, 8);
}
void aom_smooth_h_predictor_16x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 16, 16);
}
void aom_smooth_h_predictor_16x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 16, 32);
}
void aom_smooth_h_predictor_16x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 16, 64);
}
void aom_smooth_h_predictor_32x8_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 32, 8);
}
void aom_smooth_h_predictor_32x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 32, 16);
}
void aom_smooth_h_predictor_32x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 32, 32);
}
void aom_smooth_h_predictor_32x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 32, 64);
}
void aom_smooth_h_predictor_64x64_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 64, 64);
}
void aom_smooth_h_predictor_64x32_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 64, 32);
}
void aom_smooth_h_predictor_64x16_ssse3(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above,
const uint8_t *left) {
smooth_h_predictor_wxh(dst, stride, above, left, 64, 16);
}
|