-
Notifications
You must be signed in to change notification settings - Fork 5
/
ffmpeg-4.4-e2k.patch
16454 lines (16385 loc) · 582 KB
/
ffmpeg-4.4-e2k.patch
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
From ea7b7b4a469a7ea1d13a8f1bd0da8552f33cc211 Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
Date: Wed, 26 May 2021 16:08:59 +0700
Subject: [PATCH] ffmpeg-4.4 e2k support
---
configure | 22 +-
libavcodec/audiodsp.c | 2 +
libavcodec/audiodsp.h | 1 +
libavcodec/blockdsp.c | 2 +
libavcodec/blockdsp.h | 1 +
libavcodec/e2k/Makefile | 32 +
libavcodec/e2k/audiodsp.c | 62 +
libavcodec/e2k/blockdsp.c | 72 +
libavcodec/e2k/dctdsp.h | 29 +
libavcodec/e2k/fdctdsp.c | 389 ++++
libavcodec/e2k/fft.c | 1043 ++++++++++
libavcodec/e2k/fft.h | 29 +
libavcodec/e2k/fft_init.c | 152 ++
libavcodec/e2k/fmtconvert.c | 55 +
libavcodec/e2k/h264chroma.c | 57 +
libavcodec/e2k/h264chroma_template.c | 209 ++
libavcodec/e2k/h264dsp.c | 1012 +++++++++
libavcodec/e2k/h264qpel.c | 83 +
libavcodec/e2k/h264qpel_template.c | 504 +++++
libavcodec/e2k/hevcdsp.c | 2893 ++++++++++++++++++++++++++
libavcodec/e2k/hpeldsp.c | 490 +++++
libavcodec/e2k/hpeldsp.h | 30 +
libavcodec/e2k/idctdsp.c | 324 +++
libavcodec/e2k/lossless_audiodsp.c | 75 +
libavcodec/e2k/lossless_videodsp.c | 59 +
libavcodec/e2k/mdct15.c | 187 ++
libavcodec/e2k/me_cmp.c | 461 ++++
libavcodec/e2k/mpegaudiodsp.c | 142 ++
libavcodec/e2k/mpegvideo.c | 100 +
libavcodec/e2k/mpegvideodsp.c | 86 +
libavcodec/e2k/mpegvideoencdsp.c | 75 +
libavcodec/e2k/pixblockdsp.c | 83 +
libavcodec/e2k/svq1enc.c | 68 +
libavcodec/e2k/vc1dsp.c | 298 +++
libavcodec/e2k/videodsp.c | 36 +
libavcodec/e2k/vorbisdsp.c | 62 +
libavcodec/e2k/vp3dsp.c | 169 ++
libavcodec/e2k/vp8dsp.c | 428 ++++
libavcodec/e2k/vp9dsp.c | 1740 ++++++++++++++++
libavcodec/e2k/xvididct.c | 198 ++
libavcodec/fdctdsp.c | 2 +
libavcodec/fdctdsp.h | 2 +
libavcodec/fft.h | 1 +
libavcodec/fft_template.c | 1 +
libavcodec/fmtconvert.c | 2 +
libavcodec/fmtconvert.h | 1 +
libavcodec/h264chroma.c | 2 +
libavcodec/h264chroma.h | 1 +
libavcodec/h264dsp.c | 1 +
libavcodec/h264dsp.h | 2 +
libavcodec/h264qpel.c | 2 +
libavcodec/h264qpel.h | 1 +
libavcodec/hevcdsp.c | 2 +
libavcodec/hevcdsp.h | 1 +
libavcodec/hpeldsp.c | 2 +
libavcodec/hpeldsp.h | 1 +
libavcodec/idctdsp.c | 2 +
libavcodec/idctdsp.h | 2 +
libavcodec/lossless_audiodsp.c | 2 +
libavcodec/lossless_audiodsp.h | 1 +
libavcodec/lossless_videodsp.c | 2 +
libavcodec/lossless_videodsp.h | 1 +
libavcodec/mdct15.c | 2 +
libavcodec/mdct15.h | 1 +
libavcodec/me_cmp.c | 2 +
libavcodec/me_cmp.h | 1 +
libavcodec/mpegaudiodsp.c | 1 +
libavcodec/mpegaudiodsp.h | 1 +
libavcodec/mpegvideo.c | 2 +
libavcodec/mpegvideo.h | 1 +
libavcodec/mpegvideodsp.c | 2 +
libavcodec/mpegvideodsp.h | 1 +
libavcodec/mpegvideoencdsp.c | 2 +
libavcodec/mpegvideoencdsp.h | 2 +
libavcodec/pixblockdsp.c | 2 +
libavcodec/pixblockdsp.h | 2 +
libavcodec/svq1enc.c | 2 +
libavcodec/svq1enc.h | 1 +
libavcodec/tests/dct.c | 2 +
libavcodec/tests/e2k/dct.c | 33 +
libavcodec/vc1dsp.c | 2 +
libavcodec/vc1dsp.h | 1 +
libavcodec/videodsp.c | 2 +
libavcodec/videodsp.h | 1 +
libavcodec/vorbisdsp.c | 2 +
libavcodec/vorbisdsp.h | 1 +
libavcodec/vp3dsp.c | 2 +
libavcodec/vp3dsp.h | 1 +
libavcodec/vp8dsp.c | 2 +
libavcodec/vp8dsp.h | 1 +
libavcodec/vp9dsp.c | 1 +
libavcodec/vp9dsp.h | 1 +
libavcodec/xvididct.c | 2 +
libavcodec/xvididct.h | 2 +
libavutil/cpu.c | 8 +
libavutil/cpu.h | 2 +
libavutil/cpu_internal.h | 2 +
libavutil/e2k/Makefile | 2 +
libavutil/e2k/cpu.c | 41 +
libavutil/e2k/cpu.h | 27 +
libavutil/e2k/float_dsp.c | 188 ++
libavutil/e2k/intreadwrite.h | 54 +
libavutil/e2k/timer.h | 35 +
libavutil/e2k/util_e2k.h | 146 ++
libavutil/float_dsp.c | 2 +
libavutil/float_dsp.h | 1 +
libavutil/intreadwrite.h | 2 +
libavutil/tests/cpu.c | 2 +
libavutil/timer.h | 2 +
libswresample/audioconvert.c | 1 +
libswresample/e2k/Makefile | 1 +
libswresample/e2k/audio_convert.c | 110 +
libswresample/swresample_internal.h | 4 +
libswscale/e2k/Makefile | 3 +
libswscale/e2k/swscale.c | 2046 ++++++++++++++++++
libswscale/e2k/yuv2rgb.c | 248 +++
libswscale/e2k/yuv2rgb.h | 52 +
libswscale/e2k/yuv2yuv.c | 146 ++
libswscale/swscale.c | 2 +
libswscale/swscale_internal.h | 5 +
libswscale/swscale_unscaled.c | 2 +
libswscale/utils.c | 13 +
libswscale/yuv2rgb.c | 2 +
tests/checkasm/checkasm.c | 2 +
tests/checkasm/huffyuvdsp.c | 8 +-
125 files changed, 15028 insertions(+), 6 deletions(-)
create mode 100644 libavcodec/e2k/Makefile
create mode 100644 libavcodec/e2k/audiodsp.c
create mode 100644 libavcodec/e2k/blockdsp.c
create mode 100644 libavcodec/e2k/dctdsp.h
create mode 100644 libavcodec/e2k/fdctdsp.c
create mode 100644 libavcodec/e2k/fft.c
create mode 100644 libavcodec/e2k/fft.h
create mode 100644 libavcodec/e2k/fft_init.c
create mode 100644 libavcodec/e2k/fmtconvert.c
create mode 100644 libavcodec/e2k/h264chroma.c
create mode 100644 libavcodec/e2k/h264chroma_template.c
create mode 100644 libavcodec/e2k/h264dsp.c
create mode 100644 libavcodec/e2k/h264qpel.c
create mode 100644 libavcodec/e2k/h264qpel_template.c
create mode 100644 libavcodec/e2k/hevcdsp.c
create mode 100644 libavcodec/e2k/hpeldsp.c
create mode 100644 libavcodec/e2k/hpeldsp.h
create mode 100644 libavcodec/e2k/idctdsp.c
create mode 100644 libavcodec/e2k/lossless_audiodsp.c
create mode 100644 libavcodec/e2k/lossless_videodsp.c
create mode 100644 libavcodec/e2k/mdct15.c
create mode 100644 libavcodec/e2k/me_cmp.c
create mode 100644 libavcodec/e2k/mpegaudiodsp.c
create mode 100644 libavcodec/e2k/mpegvideo.c
create mode 100644 libavcodec/e2k/mpegvideodsp.c
create mode 100644 libavcodec/e2k/mpegvideoencdsp.c
create mode 100644 libavcodec/e2k/pixblockdsp.c
create mode 100644 libavcodec/e2k/svq1enc.c
create mode 100644 libavcodec/e2k/vc1dsp.c
create mode 100644 libavcodec/e2k/videodsp.c
create mode 100644 libavcodec/e2k/vorbisdsp.c
create mode 100644 libavcodec/e2k/vp3dsp.c
create mode 100644 libavcodec/e2k/vp8dsp.c
create mode 100644 libavcodec/e2k/vp9dsp.c
create mode 100644 libavcodec/e2k/xvididct.c
create mode 100644 libavcodec/tests/e2k/dct.c
create mode 100644 libavutil/e2k/Makefile
create mode 100644 libavutil/e2k/cpu.c
create mode 100644 libavutil/e2k/cpu.h
create mode 100644 libavutil/e2k/float_dsp.c
create mode 100644 libavutil/e2k/intreadwrite.h
create mode 100644 libavutil/e2k/timer.h
create mode 100644 libavutil/e2k/util_e2k.h
create mode 100644 libswresample/e2k/Makefile
create mode 100644 libswresample/e2k/audio_convert.c
create mode 100644 libswscale/e2k/Makefile
create mode 100644 libswscale/e2k/swscale.c
create mode 100644 libswscale/e2k/yuv2rgb.c
create mode 100644 libswscale/e2k/yuv2rgb.h
create mode 100644 libswscale/e2k/yuv2yuv.c
diff --git a/configure b/configure
index 4a3fac8..96ca53e 100755
--- a/configure
+++ b/configure
@@ -1996,6 +1996,7 @@ ARCH_LIST="
parisc
ppc
ppc64
+ e2k
s390
sh4
sparc
@@ -2067,6 +2068,10 @@ ARCH_EXT_LIST_PPC="
vsx
"
+ARCH_EXT_LIST_E2K="
+ e2k
+"
+
ARCH_EXT_LIST_X86="
$ARCH_EXT_LIST_X86_SIMD
cpunop
@@ -2076,6 +2081,7 @@ ARCH_EXT_LIST_X86="
ARCH_EXT_LIST="
$ARCH_EXT_LIST_ARM
$ARCH_EXT_LIST_PPC
+ $ARCH_EXT_LIST_E2K
$ARCH_EXT_LIST_X86
$ARCH_EXT_LIST_MIPS
$ARCH_EXT_LIST_LOONGSON
@@ -2605,10 +2611,10 @@ for ext in $(filter_out mmx $ARCH_EXT_LIST_X86_SIMD); do
done
aligned_stack_if_any="aarch64 ppc x86"
-fast_64bit_if_any="aarch64 alpha ia64 mips64 parisc64 ppc64 sparc64 x86_64"
-fast_clz_if_any="aarch64 alpha avr32 mips ppc x86"
-fast_unaligned_if_any="aarch64 ppc x86"
-simd_align_16_if_any="altivec neon sse"
+fast_64bit_if_any="aarch64 alpha ia64 mips64 parisc64 ppc64 e2k sparc64 x86_64"
+fast_clz_if_any="aarch64 alpha avr32 mips ppc e2k x86"
+fast_unaligned_if_any="aarch64 ppc e2k x86"
+simd_align_16_if_any="altivec e2k neon sse"
simd_align_32_if_any="avx"
simd_align_64_if_any="avx512"
@@ -4927,6 +4933,9 @@ case "$arch" in
"Power Macintosh"|ppc*|powerpc*)
arch="ppc"
;;
+ e2k|elbrus)
+ arch="e2k"
+ ;;
s390|s390x)
arch="s390"
;;
@@ -5214,6 +5223,11 @@ elif enabled ppc; then
;;
esac
+elif enabled e2k; then
+
+ cpu="e2k"
+ cpuflags="-msse4.1 -mno-avx"
+
elif enabled sparc; then
case $cpu in
diff --git a/libavcodec/audiodsp.c b/libavcodec/audiodsp.c
index efcb0a8..36b8528 100644
--- a/libavcodec/audiodsp.c
+++ b/libavcodec/audiodsp.c
@@ -113,6 +113,8 @@ av_cold void ff_audiodsp_init(AudioDSPContext *c)
ff_audiodsp_init_arm(c);
if (ARCH_PPC)
ff_audiodsp_init_ppc(c);
+ if (ARCH_E2K)
+ ff_audiodsp_init_e2k(c);
if (ARCH_X86)
ff_audiodsp_init_x86(c);
}
diff --git a/libavcodec/audiodsp.h b/libavcodec/audiodsp.h
index aa6fa78..9c05e28 100644
--- a/libavcodec/audiodsp.h
+++ b/libavcodec/audiodsp.h
@@ -55,6 +55,7 @@ typedef struct AudioDSPContext {
void ff_audiodsp_init(AudioDSPContext *c);
void ff_audiodsp_init_arm(AudioDSPContext *c);
void ff_audiodsp_init_ppc(AudioDSPContext *c);
+void ff_audiodsp_init_e2k(AudioDSPContext *c);
void ff_audiodsp_init_x86(AudioDSPContext *c);
#endif /* AVCODEC_AUDIODSP_H */
diff --git a/libavcodec/blockdsp.c b/libavcodec/blockdsp.c
index c7efe7e..704c723 100644
--- a/libavcodec/blockdsp.c
+++ b/libavcodec/blockdsp.c
@@ -71,6 +71,8 @@ av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
ff_blockdsp_init_arm(c);
if (ARCH_PPC)
ff_blockdsp_init_ppc(c);
+ if (ARCH_E2K)
+ ff_blockdsp_init_e2k(c);
if (ARCH_X86)
ff_blockdsp_init_x86(c, avctx);
if (ARCH_MIPS)
diff --git a/libavcodec/blockdsp.h b/libavcodec/blockdsp.h
index 26fc2ea..8eccb47 100644
--- a/libavcodec/blockdsp.h
+++ b/libavcodec/blockdsp.h
@@ -44,6 +44,7 @@ void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx);
void ff_blockdsp_init_alpha(BlockDSPContext *c);
void ff_blockdsp_init_arm(BlockDSPContext *c);
void ff_blockdsp_init_ppc(BlockDSPContext *c);
+void ff_blockdsp_init_e2k(BlockDSPContext *c);
void ff_blockdsp_init_x86(BlockDSPContext *c, AVCodecContext *avctx);
void ff_blockdsp_init_mips(BlockDSPContext *c);
diff --git a/libavcodec/e2k/Makefile b/libavcodec/e2k/Makefile
new file mode 100644
index 0000000..59f3237
--- /dev/null
+++ b/libavcodec/e2k/Makefile
@@ -0,0 +1,32 @@
+# subsystems
+OBJS-$(CONFIG_AUDIODSP) += e2k/audiodsp.o
+OBJS-$(CONFIG_BLOCKDSP) += e2k/blockdsp.o
+OBJS-$(CONFIG_FFT) += e2k/fft_init.o e2k/fft.o
+OBJS-$(CONFIG_FDCTDSP) += e2k/fdctdsp.o
+OBJS-$(CONFIG_FMTCONVERT) += e2k/fmtconvert.o
+OBJS-$(CONFIG_H264CHROMA) += e2k/h264chroma.o
+OBJS-$(CONFIG_H264DSP) += e2k/h264dsp.o e2k/hpeldsp.o
+OBJS-$(CONFIG_H264QPEL) += e2k/h264qpel.o
+OBJS-$(CONFIG_HPELDSP) += e2k/hpeldsp.o
+OBJS-$(CONFIG_IDCTDSP) += e2k/idctdsp.o
+OBJS-$(CONFIG_LLVIDDSP) += e2k/lossless_videodsp.o
+OBJS-$(CONFIG_MDCT15) += e2k/mdct15.o
+OBJS-$(CONFIG_ME_CMP) += e2k/me_cmp.o
+OBJS-$(CONFIG_MPEGAUDIODSP) += e2k/mpegaudiodsp.o
+OBJS-$(CONFIG_MPEGVIDEO) += e2k/mpegvideo.o e2k/mpegvideodsp.o
+OBJS-$(CONFIG_MPEGVIDEOENC) += e2k/mpegvideoencdsp.o
+OBJS-$(CONFIG_PIXBLOCKDSP) += e2k/pixblockdsp.o
+OBJS-$(CONFIG_VC1DSP) += e2k/vc1dsp.o
+OBJS-$(CONFIG_VIDEODSP) += e2k/videodsp.o
+OBJS-$(CONFIG_VP3DSP) += e2k/vp3dsp.o
+OBJS-$(CONFIG_VP8DSP) += e2k/vp8dsp.o
+
+# decoders/encoders
+OBJS-$(CONFIG_HEVC_DECODER) += e2k/hevcdsp.o
+OBJS-$(CONFIG_LLAUDDSP) += e2k/lossless_audiodsp.o
+OBJS-$(CONFIG_SVQ1_ENCODER) += e2k/svq1enc.o
+OBJS-$(CONFIG_VORBIS_DECODER) += e2k/vorbisdsp.o
+OBJS-$(CONFIG_VP7_DECODER) += e2k/vp8dsp.o
+OBJS-$(CONFIG_VP9_DECODER) += e2k/vp9dsp.o
+OBJS-$(CONFIG_MPEG4_DECODER) += e2k/xvididct.o
+
diff --git a/libavcodec/e2k/audiodsp.c b/libavcodec/e2k/audiodsp.c
new file mode 100644
index 0000000..c2e4433
--- /dev/null
+++ b/libavcodec/e2k/audiodsp.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 Ilya Kurdyukov <[email protected]> for BaseALT, Ltd
+ * Copyright (c) 2007 Luca Barbato <[email protected]>
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * miscellaneous audio operations
+ */
+
+#include "config.h"
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/e2k/cpu.h"
+#include "libavutil/e2k/util_e2k.h"
+
+#include "libavcodec/audiodsp.h"
+
+static int32_t scalarproduct_int16_e2k(const int16_t *v1, const int16_t *v2, int order)
+{
+ int i;
+ vec_s16 vec1, vec2;
+ vec_s32 res = _mm_setzero_si128(), tmp;
+
+ PRAGMA_E2K("ivdep")
+ for (i = 0; i < order; i += 8) {
+ vec1 = VEC_LD(v1);
+ vec2 = VEC_LD(v2);
+ tmp = _mm_madd_epi16(vec1, vec2);
+ res = _mm_add_epi32(res, tmp);
+ v1 += 8;
+ v2 += 8;
+ }
+
+ res = _mm_hadd_epi32(res, res);
+ return _mm_extract_epi32(res, 0) + _mm_extract_epi32(res, 1);
+}
+
+av_cold void ff_audiodsp_init_e2k(AudioDSPContext *c)
+{
+ if (!E2K_BASE(av_get_cpu_flags()))
+ return;
+
+ c->scalarproduct_int16 = scalarproduct_int16_e2k;
+}
diff --git a/libavcodec/e2k/blockdsp.c b/libavcodec/e2k/blockdsp.c
new file mode 100644
index 0000000..f85dce1
--- /dev/null
+++ b/libavcodec/e2k/blockdsp.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2021 Ilya Kurdyukov <[email protected]> for BaseALT, Ltd
+ * Copyright (c) 2002 Brian Foley
+ * Copyright (c) 2002 Dieter Shirley
+ * Copyright (c) 2003-2004 Romain Dolbeau <[email protected]>
+ *
+ * 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 "config.h"
+
+#include <string.h>
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/mem.h"
+#include "libavutil/e2k/cpu.h"
+#include "libavutil/e2k/util_e2k.h"
+
+#include "libavcodec/blockdsp.h"
+
+static void clear_block_e2k(int16_t *block)
+{
+ LOAD_ZERO;
+ VEC_ST(block, zerov);
+ VEC_ST(block + 8, zerov);
+ VEC_ST(block + 8 * 2, zerov);
+ VEC_ST(block + 8 * 3, zerov);
+ VEC_ST(block + 8 * 4, zerov);
+ VEC_ST(block + 8 * 5, zerov);
+ VEC_ST(block + 8 * 6, zerov);
+ VEC_ST(block + 8 * 7, zerov);
+}
+
+static void clear_blocks_e2k(int16_t *blocks)
+{
+ int i;
+ LOAD_ZERO;
+ for (i = 0; i < 6; i++, blocks += 64) {
+ VEC_ST(blocks, zerov);
+ VEC_ST(blocks + 8, zerov);
+ VEC_ST(blocks + 8 * 2, zerov);
+ VEC_ST(blocks + 8 * 3, zerov);
+ VEC_ST(blocks + 8 * 4, zerov);
+ VEC_ST(blocks + 8 * 5, zerov);
+ VEC_ST(blocks + 8 * 6, zerov);
+ VEC_ST(blocks + 8 * 7, zerov);
+ }
+}
+
+av_cold void ff_blockdsp_init_e2k(BlockDSPContext *c)
+{
+ if (!E2K_BASE(av_get_cpu_flags()))
+ return;
+
+ c->clear_block = clear_block_e2k;
+ c->clear_blocks = clear_blocks_e2k;
+}
diff --git a/libavcodec/e2k/dctdsp.h b/libavcodec/e2k/dctdsp.h
new file mode 100644
index 0000000..d1ba599
--- /dev/null
+++ b/libavcodec/e2k/dctdsp.h
@@ -0,0 +1,29 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_E2K_DCTDSP_H
+#define AVCODEC_E2K_DCTDSP_H
+
+#include <stdint.h>
+
+void ff_fdct_e2k(int16_t *block);
+void ff_simple_idct_e2k(int16_t *block);
+void ff_fast_idct_e2k(int16_t *block);
+void ff_xvid_idct_e2k(int16_t *block);
+
+#endif /* AVCODEC_E2K_DCTDSP_H */
diff --git a/libavcodec/e2k/fdctdsp.c b/libavcodec/e2k/fdctdsp.c
new file mode 100644
index 0000000..568a67f
--- /dev/null
+++ b/libavcodec/e2k/fdctdsp.c
@@ -0,0 +1,389 @@
+/*
+ * Copyright (C) 2021 Ilya Kurdyukov <[email protected]> for BaseALT, Ltd
+ * Copyright (C) 2003 James Klicman <[email protected]>
+ *
+ * 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 "config.h"
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/e2k/cpu.h"
+#include "libavutil/e2k/util_e2k.h"
+
+#include "libavcodec/fdctdsp.h"
+
+#include "dctdsp.h"
+
+#define C1 0.98078528040323044912618224 /* cos(1 * PI / 16) */
+#define C2 0.92387953251128675612818319 /* cos(2 * PI / 16) */
+#define C3 0.83146961230254523707878838 /* cos(3 * PI / 16) */
+#define C4 0.70710678118654752440084436 /* cos(4 * PI / 16) */
+#define C5 0.55557023301960222474283081 /* cos(5 * PI / 16) */
+#define C6 0.38268343236508977172845998 /* cos(6 * PI / 16) */
+#define C7 0.19509032201612826784828487 /* cos(7 * PI / 16) */
+
+#define W0 -(2 * C2)
+#define W1 (2 * C6)
+#define W2 (M_SQRT2 * C6)
+#define W3 (M_SQRT2 * C3)
+#define W4 (M_SQRT2 * (-C1 + C3 + C5 - C7))
+#define W5 (M_SQRT2 * (C1 + C3 - C5 + C7))
+#define W6 (M_SQRT2 * (C1 + C3 + C5 - C7))
+#define W7 (M_SQRT2 * (C1 + C3 - C5 - C7))
+#define W8 (M_SQRT2 * (C7 - C3))
+#define W9 (M_SQRT2 * (-C1 - C3))
+#define WA (M_SQRT2 * (-C3 - C5))
+#define WB (M_SQRT2 * (C5 - C3))
+
+#define LD_W0 _mm_set1_ps(W0)
+#define LD_W1 _mm_set1_ps(W1)
+#define LD_W2 _mm_set1_ps(W2)
+#define LD_W3 _mm_set1_ps(W3)
+#define LD_W4 _mm_set1_ps(W4)
+#define LD_W5 _mm_set1_ps(W5)
+#define LD_W6 _mm_set1_ps(W6)
+#define LD_W7 _mm_set1_ps(W7)
+#define LD_W8 _mm_set1_ps(W8)
+#define LD_W9 _mm_set1_ps(W9)
+#define LD_WA _mm_set1_ps(WA)
+#define LD_WB _mm_set1_ps(WB)
+
+#define _mm_madd_ps(a, b, c) _mm_add_ps(_mm_mul_ps(a, b), c)
+
+#define FDCTROW(b0, b1, b2, b3, b4, b5, b6, b7) /* {{{ */ \
+ x0 = _mm_add_ps(b0, b7); /* x0 = b0 + b7; */ \
+ x7 = _mm_sub_ps(b0, b7); /* x7 = b0 - b7; */ \
+ x1 = _mm_add_ps(b1, b6); /* x1 = b1 + b6; */ \
+ x6 = _mm_sub_ps(b1, b6); /* x6 = b1 - b6; */ \
+ x2 = _mm_add_ps(b2, b5); /* x2 = b2 + b5; */ \
+ x5 = _mm_sub_ps(b2, b5); /* x5 = b2 - b5; */ \
+ x3 = _mm_add_ps(b3, b4); /* x3 = b3 + b4; */ \
+ x4 = _mm_sub_ps(b3, b4); /* x4 = b3 - b4; */ \
+ \
+ b7 = _mm_add_ps(x0, x3); /* b7 = x0 + x3; */ \
+ b1 = _mm_add_ps(x1, x2); /* b1 = x1 + x2; */ \
+ b0 = _mm_add_ps(b7, b1); /* b0 = b7 + b1; */ \
+ b4 = _mm_sub_ps(b7, b1); /* b4 = b7 - b1; */ \
+ \
+ b2 = _mm_sub_ps(x0, x3); /* b2 = x0 - x3; */ \
+ b6 = _mm_sub_ps(x1, x2); /* b6 = x1 - x2; */ \
+ b5 = _mm_add_ps(b6, b2); /* b5 = b6 + b2; */ \
+ cnst = LD_W2; \
+ b5 = _mm_mul_ps(cnst, b5); /* b5 = b5 * W2; */ \
+ cnst = LD_W1; \
+ b2 = _mm_madd_ps(cnst, b2, b5); /* b2 = b5 + b2 * W1; */ \
+ cnst = LD_W0; \
+ b6 = _mm_madd_ps(cnst, b6, b5); /* b6 = b5 + b6 * W0; */ \
+ \
+ x0 = _mm_add_ps(x4, x7); /* x0 = x4 + x7; */ \
+ x1 = _mm_add_ps(x5, x6); /* x1 = x5 + x6; */ \
+ x2 = _mm_add_ps(x4, x6); /* x2 = x4 + x6; */ \
+ x3 = _mm_add_ps(x5, x7); /* x3 = x5 + x7; */ \
+ x8 = _mm_add_ps(x2, x3); /* x8 = x2 + x3; */ \
+ cnst = LD_W3; \
+ x8 = _mm_mul_ps(cnst, x8); /* x8 = x8 * W3; */ \
+ \
+ cnst = LD_W8; \
+ x0 = _mm_mul_ps(cnst, x0); /* x0 *= W8; */ \
+ cnst = LD_W9; \
+ x1 = _mm_mul_ps(cnst, x1); /* x1 *= W9; */ \
+ cnst = LD_WA; \
+ x2 = _mm_madd_ps(cnst, x2, x8); /* x2 = x2 * WA + x8; */ \
+ cnst = LD_WB; \
+ x3 = _mm_madd_ps(cnst, x3, x8); /* x3 = x3 * WB + x8; */ \
+ \
+ cnst = LD_W4; \
+ b7 = _mm_madd_ps(cnst, x4, x0); /* b7 = x4 * W4 + x0; */ \
+ cnst = LD_W5; \
+ b5 = _mm_madd_ps(cnst, x5, x1); /* b5 = x5 * W5 + x1; */ \
+ cnst = LD_W6; \
+ b3 = _mm_madd_ps(cnst, x6, x1); /* b3 = x6 * W6 + x1; */ \
+ cnst = LD_W7; \
+ b1 = _mm_madd_ps(cnst, x7, x0); /* b1 = x7 * W7 + x0; */ \
+ \
+ b7 = _mm_add_ps(b7, x2); /* b7 = b7 + x2; */ \
+ b5 = _mm_add_ps(b5, x3); /* b5 = b5 + x3; */ \
+ b3 = _mm_add_ps(b3, x2); /* b3 = b3 + x2; */ \
+ b1 = _mm_add_ps(b1, x3) /* b1 = b1 + x3; */ \
+ /* }}} */
+
+#define FDCTCOL(b0, b1, b2, b3, b4, b5, b6, b7) /* {{{ */ \
+ x0 = _mm_add_ps(b0, b7); /* x0 = b0 + b7; */ \
+ x7 = _mm_sub_ps(b0, b7); /* x7 = b0 - b7; */ \
+ x1 = _mm_add_ps(b1, b6); /* x1 = b1 + b6; */ \
+ x6 = _mm_sub_ps(b1, b6); /* x6 = b1 - b6; */ \
+ x2 = _mm_add_ps(b2, b5); /* x2 = b2 + b5; */ \
+ x5 = _mm_sub_ps(b2, b5); /* x5 = b2 - b5; */ \
+ x3 = _mm_add_ps(b3, b4); /* x3 = b3 + b4; */ \
+ x4 = _mm_sub_ps(b3, b4); /* x4 = b3 - b4; */ \
+ \
+ b7 = _mm_add_ps(x0, x3); /* b7 = x0 + x3; */ \
+ b1 = _mm_add_ps(x1, x2); /* b1 = x1 + x2; */ \
+ b0 = _mm_add_ps(b7, b1); /* b0 = b7 + b1; */ \
+ b4 = _mm_sub_ps(b7, b1); /* b4 = b7 - b1; */ \
+ \
+ b2 = _mm_sub_ps(x0, x3); /* b2 = x0 - x3; */ \
+ b6 = _mm_sub_ps(x1, x2); /* b6 = x1 - x2; */ \
+ b5 = _mm_add_ps(b6, b2); /* b5 = b6 + b2; */ \
+ cnst = LD_W2; \
+ b5 = _mm_mul_ps(cnst, b5); /* b5 = b5 * W2; */ \
+ cnst = LD_W1; \
+ b2 = _mm_madd_ps(cnst, b2, b5); /* b2 = b5 + b2 * W1; */ \
+ cnst = LD_W0; \
+ b6 = _mm_madd_ps(cnst, b6, b5); /* b6 = b5 + b6 * W0; */ \
+ \
+ x0 = _mm_add_ps(x4, x7); /* x0 = x4 + x7; */ \
+ x1 = _mm_add_ps(x5, x6); /* x1 = x5 + x6; */ \
+ x2 = _mm_add_ps(x4, x6); /* x2 = x4 + x6; */ \
+ x3 = _mm_add_ps(x5, x7); /* x3 = x5 + x7; */ \
+ x8 = _mm_add_ps(x2, x3); /* x8 = x2 + x3; */ \
+ cnst = LD_W3; \
+ x8 = _mm_mul_ps(cnst, x8); /* x8 = x8 * W3; */ \
+ \
+ cnst = LD_W8; \
+ x0 = _mm_mul_ps(cnst, x0); /* x0 *= W8; */ \
+ cnst = LD_W9; \
+ x1 = _mm_mul_ps(cnst, x1); /* x1 *= W9; */ \
+ cnst = LD_WA; \
+ x2 = _mm_madd_ps(cnst, x2, x8); /* x2 = x2 * WA + x8; */ \
+ cnst = LD_WB; \
+ x3 = _mm_madd_ps(cnst, x3, x8); /* x3 = x3 * WB + x8; */ \
+ \
+ cnst = LD_W4; \
+ b7 = _mm_madd_ps(cnst, x4, x0); /* b7 = x4 * W4 + x0; */ \
+ cnst = LD_W5; \
+ b5 = _mm_madd_ps(cnst, x5, x1); /* b5 = x5 * W5 + x1; */ \
+ cnst = LD_W6; \
+ b3 = _mm_madd_ps(cnst, x6, x1); /* b3 = x6 * W6 + x1; */ \
+ cnst = LD_W7; \
+ b1 = _mm_madd_ps(cnst, x7, x0); /* b1 = x7 * W7 + x0; */ \
+ \
+ b7 = _mm_add_ps(b7, x2); /* b7 += x2; */ \
+ b5 = _mm_add_ps(b5, x3); /* b5 += x3; */ \
+ b3 = _mm_add_ps(b3, x2); /* b3 += x2; */ \
+ b1 = _mm_add_ps(b1, x3) /* b1 += x3; */ \
+ /* }}} */
+
+/* two dimensional discrete cosine transform */
+void ff_fdct_e2k(int16_t *block)
+{
+ vec_f b00, b10, b20, b30, b40, b50, b60, b70;
+ vec_f b01, b11, b21, b31, b41, b51, b61, b71;
+ vec_f cnst;
+ vec_f x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ vec_s16 a0, a1, a2, a3, a4, a5, a6, a7;
+ vec_s16 z0, z1, z2, z3, z4, z5, z6, z7;
+
+ a0 = VEC_LD(block + 8 * 0);
+ a4 = VEC_LD(block + 8 * 4);
+ a1 = VEC_LD(block + 8 * 1);
+ a5 = VEC_LD(block + 8 * 5);
+ a2 = VEC_LD(block + 8 * 2);
+ a6 = VEC_LD(block + 8 * 6);
+ a3 = VEC_LD(block + 8 * 3);
+ a7 = VEC_LD(block + 8 * 7);
+
+ TRANSPOSE8(a0, a1, a2, a3, a4, a5, a6, a7);
+
+ /* Some of the initial calculations can be done as vector short
+ * before conversion to vec_f. The following code section
+ * takes advantage of this. */
+
+ /* fdct rows {{{ */
+ z0 = _mm_add_epi16(a0, a7);
+ z7 = _mm_sub_epi16(a0, a7);
+ z1 = _mm_add_epi16(a1, a6);
+ z6 = _mm_sub_epi16(a1, a6);
+ z2 = _mm_add_epi16(a2, a5);
+ z5 = _mm_sub_epi16(a2, a5);
+ z3 = _mm_add_epi16(a3, a4);
+ z4 = _mm_sub_epi16(a3, a4);
+
+#define CTF0(n) \
+ b##n##0 = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpacklo_epi16(a##n, a##n), 16));\
+ b##n##1 = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpackhi_epi16(a##n, a##n), 16));
+
+ a7 = _mm_add_epi16(z0, z3);
+ a1 = _mm_add_epi16(z1, z2);
+ a0 = _mm_add_epi16(a7, a1);
+ a4 = _mm_sub_epi16(a7, a1);
+ CTF0(0);
+ CTF0(4);
+
+ a2 = _mm_sub_epi16(z0, z3);
+ a6 = _mm_sub_epi16(z1, z2);
+ CTF0(2);
+ CTF0(6);
+
+#undef CTF0
+
+ x0 = _mm_add_ps(b60, b20);
+ x1 = _mm_add_ps(b61, b21);
+
+ cnst = LD_W2;
+ x0 = _mm_mul_ps(cnst, x0);
+ x1 = _mm_mul_ps(cnst, x1);
+ cnst = LD_W1;
+ b20 = _mm_madd_ps(cnst, b20, x0);
+ b21 = _mm_madd_ps(cnst, b21, x1);
+ cnst = LD_W0;
+ b60 = _mm_madd_ps(cnst, b60, x0);
+ b61 = _mm_madd_ps(cnst, b61, x1);
+
+#define CTFX(x, b) \
+ b##0 = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpacklo_epi16(x, x), 16)); \
+ b##1 = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpackhi_epi16(x, x), 16));
+
+ CTFX(z4, b7);
+ CTFX(z5, b5);
+ CTFX(z6, b3);
+ CTFX(z7, b1);
+
+#undef CTFX
+
+ x0 = _mm_add_ps(b70, b10);
+ x1 = _mm_add_ps(b50, b30);
+ x2 = _mm_add_ps(b70, b30);
+ x3 = _mm_add_ps(b50, b10);
+ x8 = _mm_add_ps(x2, x3);
+ cnst = LD_W3;
+ x8 = _mm_mul_ps(cnst, x8);
+
+ cnst = LD_W8;
+ x0 = _mm_mul_ps(cnst, x0);
+ cnst = LD_W9;
+ x1 = _mm_mul_ps(cnst, x1);
+ cnst = LD_WA;
+ x2 = _mm_madd_ps(cnst, x2, x8);
+ cnst = LD_WB;
+ x3 = _mm_madd_ps(cnst, x3, x8);
+
+ cnst = LD_W4;
+ b70 = _mm_madd_ps(cnst, b70, x0);
+ cnst = LD_W5;
+ b50 = _mm_madd_ps(cnst, b50, x1);
+ cnst = LD_W6;
+ b30 = _mm_madd_ps(cnst, b30, x1);
+ cnst = LD_W7;
+ b10 = _mm_madd_ps(cnst, b10, x0);
+
+ b70 = _mm_add_ps(b70, x2);
+ b50 = _mm_add_ps(b50, x3);
+ b30 = _mm_add_ps(b30, x2);
+ b10 = _mm_add_ps(b10, x3);
+
+ x0 = _mm_add_ps(b71, b11);
+ x1 = _mm_add_ps(b51, b31);
+ x2 = _mm_add_ps(b71, b31);
+ x3 = _mm_add_ps(b51, b11);
+ x8 = _mm_add_ps(x2, x3);
+ cnst = LD_W3;
+ x8 = _mm_mul_ps(cnst, x8);
+
+ cnst = LD_W8;
+ x0 = _mm_mul_ps(cnst, x0);
+ cnst = LD_W9;
+ x1 = _mm_mul_ps(cnst, x1);
+ cnst = LD_WA;
+ x2 = _mm_madd_ps(cnst, x2, x8);
+ cnst = LD_WB;
+ x3 = _mm_madd_ps(cnst, x3, x8);
+
+ cnst = LD_W4;
+ b71 = _mm_madd_ps(cnst, b71, x0);
+ cnst = LD_W5;
+ b51 = _mm_madd_ps(cnst, b51, x1);
+ cnst = LD_W6;
+ b31 = _mm_madd_ps(cnst, b31, x1);
+ cnst = LD_W7;
+ b11 = _mm_madd_ps(cnst, b11, x0);
+
+ b71 = _mm_add_ps(b71, x2);
+ b51 = _mm_add_ps(b51, x3);
+ b31 = _mm_add_ps(b31, x2);
+ b11 = _mm_add_ps(b11, x3);
+ /* }}} */
+
+ /* 8x8 matrix transpose (vec_f[8][2]) {{{ */
+ x0 = _mm_unpacklo_ps(b00, b10);
+ x1 = _mm_unpackhi_ps(b00, b10);
+ x2 = _mm_unpacklo_ps(b20, b30);
+ x3 = _mm_unpackhi_ps(b20, b30);
+ b00 = _mm_unpacklo_ps2(x0, x2);
+ b10 = _mm_unpackhi_ps2(x0, x2);
+ b20 = _mm_unpacklo_ps2(x1, x3);
+ b30 = _mm_unpackhi_ps2(x1, x3);
+
+ x4 = _mm_unpacklo_ps(b41, b51);
+ x5 = _mm_unpackhi_ps(b41, b51);
+ x6 = _mm_unpacklo_ps(b61, b71);
+ x7 = _mm_unpackhi_ps(b61, b71);
+ b41 = _mm_unpacklo_ps2(x4, x6);
+ b51 = _mm_unpackhi_ps2(x4, x6);
+ b61 = _mm_unpacklo_ps2(x5, x7);
+ b71 = _mm_unpackhi_ps2(x5, x7);
+
+ x0 = _mm_unpacklo_ps(b01, b11);
+ x1 = _mm_unpackhi_ps(b01, b11);
+ x2 = _mm_unpacklo_ps(b21, b31);
+ x3 = _mm_unpackhi_ps(b21, b31);
+ x4 = _mm_unpacklo_ps(b40, b50);
+ x5 = _mm_unpackhi_ps(b40, b50);
+ x6 = _mm_unpacklo_ps(b60, b70);
+ x7 = _mm_unpackhi_ps(b60, b70);
+ b40 = _mm_unpacklo_ps2(x0, x2);
+ b50 = _mm_unpackhi_ps2(x0, x2);
+ b60 = _mm_unpacklo_ps2(x1, x3);
+ b70 = _mm_unpackhi_ps2(x1, x3);
+ b01 = _mm_unpacklo_ps2(x4, x6);
+ b11 = _mm_unpackhi_ps2(x4, x6);
+ b21 = _mm_unpacklo_ps2(x5, x7);
+ b31 = _mm_unpackhi_ps2(x5, x7);
+ /* }}} */
+
+ FDCTCOL(b00, b10, b20, b30, b40, b50, b60, b70);
+ FDCTCOL(b01, b11, b21, b31, b41, b51, b61, b71);
+
+ /* round, convert back to short */
+#define CTS(n) \
+ a##n = _mm_packs_epi32(_mm_cvtps_epi32(b##n##0), _mm_cvtps_epi32(b##n##1)); \
+ VEC_ST(block + 8 * n, a##n)
+
+ CTS(0); CTS(1); CTS(2); CTS(3);
+ CTS(4); CTS(5); CTS(6); CTS(7);
+
+#undef CTS
+}
+
+av_cold void ff_fdctdsp_init_e2k(FDCTDSPContext *c, AVCodecContext *avctx,
+ unsigned high_bit_depth)
+{
+ if (!E2K_BASE(av_get_cpu_flags()))
+ return;
+
+ // !checkasm
+ // libavcodec/tests/dct
+
+ if (!high_bit_depth) {
+ if (avctx->dct_algo == FF_DCT_AUTO ||
+ avctx->dct_algo == FF_DCT_ALTIVEC) {
+ c->fdct = ff_fdct_e2k;
+ }
+ }
+}
diff --git a/libavcodec/e2k/fft.c b/libavcodec/e2k/fft.c
new file mode 100644
index 0000000..5b58202
--- /dev/null
+++ b/libavcodec/e2k/fft.c
@@ -0,0 +1,1043 @@
+/*
+ * FFT transform
+ * Copyright (C) 2021 Ilya Kurdyukov <[email protected]> for BaseALT, Ltd
+ * Copyright (c) 2014 Rong Yan
+ * Copyright (c) 2009 Loren Merritt
+ *
+ * This algorithm (though not any of the implementation details) is
+ * based on libdjbfft by D. J. Bernstein.
+ *
+ * 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 "config.h"
+#include "libavutil/cpu.h"
+#include "libavutil/e2k/util_e2k.h"
+#include "libavcodec/fft.h"
+#include "libavcodec/fft-internal.h"
+#include "fft.h"
+
+#define _mm_madd_ps(a, b, c) _mm_add_ps(_mm_mul_ps(a, b), c)
+#define _mm_msub_ps(a, b, c) _mm_sub_ps(_mm_mul_ps(a, b), c)
+#define _mm_nmsub_ps(a, b, c) _mm_sub_ps(c, _mm_mul_ps(a, b))
+
+static av_always_inline
+void pass_e2k_interleave(FFTComplex *z, const FFTSample *wre, unsigned int n)
+{
+ int i1 = n * 4, i2 = n * 8, i3 = n * 12;
+ FFTSample *out = (FFTSample*)z;
+ const FFTSample *wim = wre + n * 2;
+ vec_f vz0, vzo1, vzo2, vzo3;
+ vec_f x0, x1, x2, x3;
+ vec_f x4, x5, x6, x7;
+ vec_f x8, x9, x10, x11;
+ vec_f x12, x13, x14, x15;
+ vec_f x16, x17, x18, x19;
+ vec_f x20, x21, x22, x23;
+ vec_f vz0plus1, vzo1plus1, vzo2plus1, vzo3plus1;
+ vec_f y0, y1, y2, y3;
+ vec_f y4, y5, y8, y9;
+ vec_f y10, y13, y14, y15;
+ vec_f y16, y17, y18, y19;
+ vec_f y20, y21, y22, y23;
+ vec_f wr1, wi1, wr0, wi0;
+ vec_f wr2, wi2, wr3, wi3;
+ vec_f xmulwi0, xmulwi1, ymulwi2, ymulwi3;
+
+ n = n - 2;
+ vzo2 = _mm_loadu_ps(out + i2); // zo2.r zo2.i z(o2+1).r z(o2+1).i
+ vzo2plus1 = _mm_loadu_ps(out + i2 + 4);
+ vzo3 = _mm_loadu_ps(out + i3); // zo3.r zo3.i z(o3+1).r z(o3+1).i
+ vzo3plus1 = _mm_loadu_ps(out + i3 + 4);
+ vz0 = _mm_loadu_ps(out); // z0.r z0.i z1.r z1.i
+ vz0plus1 = _mm_loadu_ps(out + 4);
+ vzo1 = _mm_loadu_ps(out + i1); // zo1.r zo1.i z(o1+1).r z(o1+1).i
+ vzo1plus1 = _mm_loadu_ps(out + i1 + 4);
+
+ x0 = _mm_add_ps(vzo2, vzo3);
+ x1 = _mm_sub_ps(vzo2, vzo3);
+ y0 = _mm_add_ps(vzo2plus1, vzo3plus1);
+ y1 = _mm_sub_ps(vzo2plus1, vzo3plus1);
+
+ wr1 = _mm_set1_ps(wre[1]);
+ wi1 = _mm_set1_ps(wim[-1]);
+ wi2 = _mm_set1_ps(wim[-2]);