PR #22689 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22689 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22689.patch
>From dfd3ea02a07912aaace1800045e49f52a9e8a49e Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 01:01:28 +0200 Subject: [PATCH 01/10] avcodec/x86/cavsidct: Use tmp reg in SUMSUB_BA if possible It allows to exchange a paddw by a movdqa. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/cavsidct.asm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libavcodec/x86/cavsidct.asm b/libavcodec/x86/cavsidct.asm index f133c73546..a0af002a78 100644 --- a/libavcodec/x86/cavsidct.asm +++ b/libavcodec/x86/cavsidct.asm @@ -61,7 +61,8 @@ SECTION .text mova m6, m7 mova m0, m3 mova m2, m1 - SUMSUB_BA w, 7, 5 ; m7 = a0 + a1, m5 = a0 - a1 + paddw m7, m5 ; m7 = a0 + a1 + psubw m5, m6 ; m5 = a0 - a1 paddw m7, m3 ; m7 = a0 + a1 + a3 paddw m5, m1 ; m5 = a0 - a1 + a2 paddw m7, m7 @@ -69,7 +70,8 @@ SECTION .text paddw m7, m6 ; m7 = b4 paddw m5, m4 ; m5 = b5 - SUMSUB_BA w, 1, 3 ; m1 = a3 + a2, m3 = a3 - a2 + paddw m1, m3 ; m1 = a3 + a2 + psubw m3, m2 ; m3 = a3 - a2 psubw m4, m1 ; m4 = a0 - a2 - a3 mova m1, m4 ; m1 = a0 - a2 - a3 psubw m3, m6 ; m3 = a3 - a2 - a1 @@ -93,18 +95,31 @@ SECTION .text mova m2, [%1+0*16] ; m2 = src0 mova m0, [%1+4*16] ; m0 = src4 +%if ARCH_X86_64 + SUMSUB_BA w, 0, 2, 8 ; m0 = src0 + src4, m2 = src0 - src4 +%else SUMSUB_BA w, 0, 2 ; m0 = src0 + src4, m2 = src0 - src4 +%endif psllw m0, 3 psllw m2, 3 paddw m0, %2 ; add rounding bias paddw m2, %2 ; add rounding bias +%if ARCH_X86_64 + SUMSUB_BA w, 6, 0, 8 ; m6 = a4 + a6, m0 = a4 - a6 + SUMSUB_BA w, 4, 2, 8 ; m4 = a5 + a7, m2 = a5 - a7 + SUMSUB_BA w, 7, 6, 8 ; m7 = dst0, m6 = dst7 + SUMSUB_BA w, 5, 4, 8 ; m5 = dst1, m4 = dst6 + SUMSUB_BA w, 3, 2, 8 ; m3 = dst2, m2 = dst5 + SUMSUB_BA w, 1, 0, 8 ; m1 = dst3, m0 = dst4 +%else SUMSUB_BA w, 6, 0 ; m6 = a4 + a6, m0 = a4 - a6 SUMSUB_BA w, 4, 2 ; m4 = a5 + a7, m2 = a5 - a7 SUMSUB_BA w, 7, 6 ; m7 = dst0, m6 = dst7 SUMSUB_BA w, 5, 4 ; m5 = dst1, m4 = dst6 SUMSUB_BA w, 3, 2 ; m3 = dst2, m2 = dst5 SUMSUB_BA w, 1, 0 ; m1 = dst3, m0 = dst4 +%endif %endmacro INIT_XMM sse2 -- 2.52.0 >From 2212bae85660e5f05600d392c0514853e095be6b Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 11:36:47 +0200 Subject: [PATCH 02/10] tests/checkasm/sw_yuv2rgb: Don't use declare_func_emms unnecessarily The last MMX(EXT) convert_unscaled functions have been removed in 61e851381f3c039dd8c06073f22da12fcc7409b0. And anyway, there is no emms_c cleaning up after these functions, so they must not clobber the fpu state; that they did it at the time this checkasm test has been added was a bug introduced by e934194b6a4159b7960cabefb0dd8b998c1961e8 and fixed by the removal of said MMX(EXT) functions. Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/sw_yuv2rgb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/checkasm/sw_yuv2rgb.c b/tests/checkasm/sw_yuv2rgb.c index ba579d0545..07b967b168 100644 --- a/tests/checkasm/sw_yuv2rgb.c +++ b/tests/checkasm/sw_yuv2rgb.c @@ -108,10 +108,9 @@ static void check_yuv2rgb(int src_pix_fmt) #define NUM_LINES 4 static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE}; - declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, - int, SwsInternal *c, const uint8_t *const src[], - const int srcStride[], int srcSliceY, int srcSliceH, - uint8_t *const dst[], const int dstStride[]); + declare_func(int, SwsInternal *c, const uint8_t *const src[], + const int srcStride[], int srcSliceY, int srcSliceH, + uint8_t *const dst[], const int dstStride[]); LOCAL_ALIGNED_8(uint8_t, src_y, [(MAX_LINE_SIZE + SRC_STRIDE_PAD) * NUM_LINES]); LOCAL_ALIGNED_8(uint8_t, src_u, [(MAX_LINE_SIZE + SRC_STRIDE_PAD) * NUM_LINES]); -- 2.52.0 >From c40e867ddd027c00d0e959cfa116a93ffca22302 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 11:58:04 +0200 Subject: [PATCH 03/10] tests/checkasm/vf_fspp: Don't use declare_func_emms for store_slice Forgotten in ff85a20b7db4d3226ada8533b181989944f30e75. Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/vf_fspp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/checkasm/vf_fspp.c b/tests/checkasm/vf_fspp.c index f102afb798..457b8f46a5 100644 --- a/tests/checkasm/vf_fspp.c +++ b/tests/checkasm/vf_fspp.c @@ -52,9 +52,9 @@ static void check_store_slice(void) }; FSPPDSPContext fspp; ff_fsppdsp_init(&fspp); - declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *src, - ptrdiff_t dst_stride, ptrdiff_t src_stride, - ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale); + declare_func(void, uint8_t *dst, int16_t *src, + ptrdiff_t dst_stride, ptrdiff_t src_stride, + ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale); for (int i = 0; i < 2; ++i) { if (check_func(i ? fspp.store_slice2 : fspp.store_slice, "store_slice%s", i ? "2" : "")) { -- 2.52.0 >From bba6285ef17254d007b03e6ba20d6ebd6a6cd47e Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 12:19:43 +0200 Subject: [PATCH 04/10] tests/checkasm/png: Don't use declare_func_emms for add_paeth_pred There is an x86 implementation using MMX registers, but it actually issues emms on its own (since 57a29f2e7dd2374a1df27316c6cf7c0225e86758). Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/png.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/checkasm/png.c b/tests/checkasm/png.c index 0fe049cf9c..98888b99db 100644 --- a/tests/checkasm/png.c +++ b/tests/checkasm/png.c @@ -69,8 +69,8 @@ static void check_add_paeth_prediction(const PNGDSPContext *c) randomize_buf(src, BUF_SIZE); randomize_buf(top_buf, BUF_SIZE); - declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t * dst, const uint8_t *src, - const uint8_t *top, int w, int bpp); + declare_func(void, uint8_t * dst, const uint8_t *src, + const uint8_t *top, int w, int bpp); const int bpps[] = {3, 4, 6, 8}; for (int i = 0; i < FF_ARRAY_ELEMS(bpps); i++) { -- 2.52.0 >From 4b2871ffdf2c060ee33f05bff9eb3d6363874b3d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 12:23:24 +0200 Subject: [PATCH 05/10] tests/checkasm/sw_yuv2yuv: Don't use declare_func_emms It is not needed (there are no MMX functions here) and given that there is no emms_c() cleaning up after convert_unscaled, convert_unscaled must not clobber the fpu state. Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/sw_yuv2yuv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/checkasm/sw_yuv2yuv.c b/tests/checkasm/sw_yuv2yuv.c index 6a7a7a8b9a..251fdde277 100644 --- a/tests/checkasm/sw_yuv2yuv.c +++ b/tests/checkasm/sw_yuv2yuv.c @@ -45,10 +45,9 @@ static void check_semiplanar(int dst_pix_fmt) #define MAX_LINE_SIZE 1920 static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE}; - declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, - int, SwsInternal *c, const uint8_t *const src[], - const int srcStride[], int srcSliceY, int srcSliceH, - uint8_t *const dstParam[], const int dstStride[]); + declare_func(int, SwsInternal *c, const uint8_t *const src[], + const int srcStride[], int srcSliceY, int srcSliceH, + uint8_t *const dstParam[], const int dstStride[]); LOCAL_ALIGNED_8(uint8_t, src_y, [MAX_LINE_SIZE * NUM_LINES]); LOCAL_ALIGNED_8(uint8_t, src_uv, [MAX_LINE_SIZE * NUM_LINES * 2]); -- 2.52.0 >From a45941cb55e4d607e64b92ee276e22ba4aa6618d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 12:38:12 +0200 Subject: [PATCH 06/10] tests/checkasm/sw_scale: Don't use declare_func_emms in yuv2nv12cX check There are no implementations of yuv2nv12cX clobbering the fpu state, so make the test stricter to ensure that it stays that way. Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/sw_scale.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c index 52e3ebf75c..f3dd0019e5 100644 --- a/tests/checkasm/sw_scale.c +++ b/tests/checkasm/sw_scale.c @@ -289,10 +289,10 @@ static void check_yuv2nv12cX(int accurate) static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; const char *accurate_str = (accurate) ? "accurate" : "approximate"; - declare_func_emms(AV_CPU_FLAG_MMX, void, enum AVPixelFormat dstFormat, - const uint8_t *chrDither, const int16_t *chrFilter, - int chrFilterSize, const int16_t **chrUSrc, - const int16_t **chrVSrc, uint8_t *dest, int dstW); + declare_func(void, enum AVPixelFormat dstFormat, + const uint8_t *chrDither, const int16_t *chrFilter, + int chrFilterSize, const int16_t **chrUSrc, + const int16_t **chrVSrc, uint8_t *dest, int dstW); const int16_t *srcU[LARGEST_FILTER], *srcV[LARGEST_FILTER]; LOCAL_ALIGNED_16(int16_t, srcU_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]); -- 2.52.0 >From 6a0a0c49b3e8a6fd30b281a34b5a83234fad1a2c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 13:20:01 +0200 Subject: [PATCH 07/10] avcodec/hevc/dsp_template: Add restrict to add_residual functions Allows the compiler to optimize the the aliasing checks away and saves 5376B here (GCC 15, -O3). Also, avoid converting the stride to uint16_t for >8bpp: stride /= sizeof(pixel) will use an unsigned division (i.e. a logical right shift)*, which is not what is intended here. *: If size_t is the corresponding unsigned type to ptrdiff_t Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/hevc/dsp_template.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc/dsp_template.c b/libavcodec/hevc/dsp_template.c index f703f6d071..e7b21127ba 100644 --- a/libavcodec/hevc/dsp_template.c +++ b/libavcodec/hevc/dsp_template.c @@ -43,20 +43,18 @@ static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height } } -static av_always_inline void FUNC(add_residual)(uint8_t *_dst, const int16_t *res, +static av_always_inline void FUNC(add_residual)(uint8_t *restrict dst8, const int16_t *restrict res, ptrdiff_t stride, int size) { int x, y; - pixel *dst = (pixel *)_dst; - - stride /= sizeof(pixel); for (y = 0; y < size; y++) { + pixel *restrict dst = (pixel *)dst8; for (x = 0; x < size; x++) { dst[x] = av_clip_pixel(dst[x] + *res); res++; } - dst += stride; + dst8 += stride; } } -- 2.52.0 >From 3e5d2b4411d9623715c75f2f43e758d89c80cf59 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 14:01:26 +0200 Subject: [PATCH 08/10] avcodec/x86/me_cmp: Use tmp reg in SUMSUB_BA if possible It allows to exchange a paddw by a movdqa. Old benchmarks: hadamard8_diff_0_c: 366.1 ( 1.00x) hadamard8_diff_0_sse2: 56.4 ( 6.49x) hadamard8_diff_0_ssse3: 53.0 ( 6.90x) hadamard8_diff_1_c: 183.0 ( 1.00x) hadamard8_diff_1_sse2: 28.0 ( 6.53x) hadamard8_diff_1_ssse3: 26.0 ( 7.03x) New benchmarks: hadamard8_diff_0_c: 371.4 ( 1.00x) hadamard8_diff_0_sse2: 55.0 ( 6.76x) hadamard8_diff_0_ssse3: 49.5 ( 7.50x) hadamard8_diff_1_c: 183.4 ( 1.00x) hadamard8_diff_1_sse2: 26.8 ( 6.85x) hadamard8_diff_1_ssse3: 23.1 ( 7.92x) Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/me_cmp.asm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavcodec/x86/me_cmp.asm b/libavcodec/x86/me_cmp.asm index 3ac8acee2c..314b091fc8 100644 --- a/libavcodec/x86/me_cmp.asm +++ b/libavcodec/x86/me_cmp.asm @@ -67,12 +67,21 @@ SECTION .text %endmacro %macro HADAMARD8 0 +%if ARCH_X86_64 + SUMSUB_BADC w, 0, 1, 2, 3, 8 + SUMSUB_BADC w, 4, 5, 6, 7, 8 + SUMSUB_BADC w, 0, 2, 1, 3, 8 + SUMSUB_BADC w, 4, 6, 5, 7, 8 + SUMSUB_BADC w, 0, 4, 1, 5, 8 + SUMSUB_BADC w, 2, 6, 3, 7, 8 +%else SUMSUB_BADC w, 0, 1, 2, 3 SUMSUB_BADC w, 4, 5, 6, 7 SUMSUB_BADC w, 0, 2, 1, 3 SUMSUB_BADC w, 4, 6, 5, 7 SUMSUB_BADC w, 0, 4, 1, 5 SUMSUB_BADC w, 2, 6, 3, 7 +%endif %endmacro %macro ABS1_SUM 3 -- 2.52.0 >From 71d455bb85eb6fdbebfad0a2f11ac24760c3bdd7 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 16:52:32 +0200 Subject: [PATCH 09/10] avcodec/x86/h264_idct: Use tmp reg in SUMSUB_BA if possible It allows to exchange a paddw by a movdqa. Old benchmarks: idct8_add4_8bpp_c: 664.6 ( 1.00x) idct8_add4_8bpp_sse2: 142.2 ( 4.67x) idct8_add_8bpp_c: 215.5 ( 1.00x) idct8_add_8bpp_sse2: 35.1 ( 6.14x) New benchmarks: idct8_add4_8bpp_c: 666.9 ( 1.00x) idct8_add4_8bpp_sse2: 135.3 ( 4.93x) idct8_add_8bpp_c: 217.7 ( 1.00x) idct8_add_8bpp_sse2: 34.0 ( 6.41x) Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/h264_idct.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libavcodec/x86/h264_idct.asm b/libavcodec/x86/h264_idct.asm index 0ced412a3e..7f917a4424 100644 --- a/libavcodec/x86/h264_idct.asm +++ b/libavcodec/x86/h264_idct.asm @@ -142,6 +142,15 @@ SECTION .text mova m2, %1 mova m5, %2 +%if ARCH_X86_64 + SUMSUB_BA w, 5, 2, 8 + SUMSUB_BA w, 6, 5, 8 + SUMSUB_BA w, 4, 2, 8 + SUMSUB_BA w, 7, 6, 8 + SUMSUB_BA w, 0, 4, 8 + SUMSUB_BA w, 3, 2, 8 + SUMSUB_BA w, 1, 5, 8 +%else SUMSUB_BA w, 5, 2 SUMSUB_BA w, 6, 5 SUMSUB_BA w, 4, 2 @@ -149,6 +158,7 @@ SECTION .text SUMSUB_BA w, 0, 4 SUMSUB_BA w, 3, 2 SUMSUB_BA w, 1, 5 +%endif SWAP 7, 6, 4, 5, 2, 3, 1, 0 ; 70315246 -> 01234567 %endmacro -- 2.52.0 >From 13696c87a94c3a1f7cb0aaca65b6fbb68a17ebae Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 2 Apr 2026 17:02:17 +0200 Subject: [PATCH 10/10] avfilter/x86/vf_atadenoise: Don't load args unnecessarily These args will be read directly from the stack into xmm register, so loading them into GPRs is unnecessary. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavfilter/x86/vf_atadenoise.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/x86/vf_atadenoise.asm b/libavfilter/x86/vf_atadenoise.asm index 2ef65a0202..ea80e3aa59 100644 --- a/libavfilter/x86/vf_atadenoise.asm +++ b/libavfilter/x86/vf_atadenoise.asm @@ -37,7 +37,7 @@ SECTION .text ;------------------------------------------------------------------------------ INIT_XMM sse4 -cglobal atadenoise_filter_row8, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x +cglobal atadenoise_filter_row8, 6,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x movsxdifnidn wq, wd movsxdifnidn midq, midd movsxdifnidn sizeq, sized @@ -151,7 +151,7 @@ cglobal atadenoise_filter_row8, 8,10,13, src, dst, srcf, w, mid, size, i, j, src RET INIT_XMM sse4 -cglobal atadenoise_filter_row8_serial, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x +cglobal atadenoise_filter_row8_serial, 6,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x movsxdifnidn wq, wd movsxdifnidn midq, midd movsxdifnidn sizeq, sized -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
