Commit dd7179559c for ffmpeg
commit dd7179559cf0dd20ef52b8d32c1694063f7ae298
Author: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu Dec 3 08:30:17 2026 +0100
avcodec/x86/proresdsp: Pre-permute block
Old benchmarks:
prores_idct_put_12_c: 267.7
prores_idct_put_12_avx2: 52.1 ( 5.13x)
New benchmarks:
prores_idct_put_12_c: 266.9
prores_idct_put_12_avx2: 47.3 ( 5.63x)
Reviewed-by: Marcos Ashton Iglesias <marcosashiglesias@gmail.com>
Reviewed-by: Kyle Swanson <k@ylo.ph>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h
index 7783d7098a..12e8382763 100644
--- a/libavcodec/idctdsp.h
+++ b/libavcodec/idctdsp.h
@@ -31,6 +31,7 @@ enum idct_permutation_type {
FF_IDCT_PERM_TRANSPOSE,
FF_IDCT_PERM_PARTTRANS,
FF_IDCT_PERM_SSE2,
+ FF_IDCT_PERM_TRANSPOSE_SHUFFLE,
};
void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64],
diff --git a/libavcodec/x86/idctdsp_init.c b/libavcodec/x86/idctdsp_init.c
index fce62e5590..014703fd00 100644
--- a/libavcodec/x86/idctdsp_init.c
+++ b/libavcodec/x86/idctdsp_init.c
@@ -39,6 +39,19 @@ static const uint8_t simple_mmx_permutation[64] = {
static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 };
+/// transposition followed by interleaving rows 0,2, then rows 1,5,
+/// then rows 4,6, then rows 7,3
+static const uint8_t transpose_shuffle_perm[64] = {
+ 0, 16, 1, 49, 32, 17, 33, 48,
+ 2, 18, 3, 51, 34, 19, 35, 50,
+ 4, 20, 5, 53, 36, 21, 37, 52,
+ 6, 22, 7, 55, 38, 23, 39, 54,
+ 8, 24, 9, 57, 40, 25, 41, 56,
+ 10, 26, 11, 59, 42, 27, 43, 58,
+ 12, 28, 13, 61, 44, 29, 45, 60,
+ 14, 30, 15, 63, 46, 31, 47, 62,
+};
+
av_cold int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
enum idct_permutation_type perm_type)
{
@@ -55,6 +68,12 @@ av_cold int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
for (i = 0; i < 64; i++)
idct_permutation[i] = (i & 0x38) | idct_sse2_row_perm[i & 7];
return 1;
+#if ARCH_X86_64
+ case FF_IDCT_PERM_TRANSPOSE_SHUFFLE:
+ for (int i = 0; i < 64; ++i)
+ idct_permutation[i] = transpose_shuffle_perm[i];
+ return 1;
+#endif
}
return 0;
diff --git a/libavcodec/x86/proresdsp.asm b/libavcodec/x86/proresdsp.asm
index 2049d1b0de..43dbc485ff 100644
--- a/libavcodec/x86/proresdsp.asm
+++ b/libavcodec/x86/proresdsp.asm
@@ -186,19 +186,6 @@ cglobal prores_idct_put_12, 4, 5, 14, pixels, lsize, block, qmat
mova m3, [blockq + 3*32]
pmullw m3, [qmatq + 3*32]
- vpermq m0, m0, q3120
- vpermq m1, m1, q3120
- vpermq m2, m2, q3120
- vpermq m3, m3, q3120
-
- punpcklwd m4, m0, m1 ; rows (0,2) interleaved
- punpcklwd m5, m2, m3 ; rows 4,6 interleaved
- punpckhwd m0, m2 ; rows 1,5 interleaved
- punpckhwd m3, m1 ; rows 7,3 interleaved
- SWAP 0, 1
- SWAP 4, 0
- SWAP 5, 2
-
pxor xm13, xm13
pblendw m7, m13, m0, 10101010b ; even-numbered words contain DC coeffs
por m5, m2, m3
diff --git a/libavcodec/x86/proresdsp_init.c b/libavcodec/x86/proresdsp_init.c
index 9f92adf518..598576336e 100644
--- a/libavcodec/x86/proresdsp_init.c
+++ b/libavcodec/x86/proresdsp_init.c
@@ -49,7 +49,7 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, int bits_per_raw_sampl
}
} else if (bits_per_raw_sample == 12) {
if (EXTERNAL_AVX2(cpu_flags)) {
- dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE;
+ dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE_SHUFFLE;
dsp->idct_put = ff_prores_idct_put_12_avx2;
}
}