[PR] avcodec/x86/huffyuvdsp, tests/checkasm/huffyuvdsp: Various improvements (PR #23956)
mkver via ffmpeg-devel <[email protected]> Thu, 30 Jul 2026 00:01:32 -0000
| Newsgroups | gmane.comp.video.ffmpeg.devel |
|---|---|
| Message-ID | <178536969422.51.2909326783909156447@29965ddac10e> |
PR #23956 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23956 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23956.patch >From 8ad0266cce55f2a3956ef3bd578448f8da663b3c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 01:00:48 +0200 Subject: [PATCH 01/10] tests/checkasm/huffyuvdsp: Return early if there is no function to test Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/huffyuvdsp.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index 7491a8f14c..5e6dad7ea7 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -37,6 +37,9 @@ static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name) { + if (!check_func(c->add_int16, "%s", name)) + return; + uint16_t *src0 = av_mallocz(width * sizeof(uint16_t)); uint16_t *src1 = av_mallocz(width * sizeof(uint16_t)); uint16_t *dst0 = av_mallocz(width * sizeof(uint16_t)); @@ -50,13 +53,11 @@ static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, cons randomize_buffers(src0, width); memcpy(src1, src0, width * sizeof(uint16_t)); - if (check_func(c->add_int16, "%s", name)) { - call_ref(dst0, src0, mask, width); - call_new(dst1, src1, mask, width); - if (memcmp(dst0, dst1, width * sizeof(uint16_t))) - fail(); - bench_new(dst1, src1, mask, width); - } + call_ref(dst0, src0, mask, width); + call_new(dst1, src1, mask, width); + if (memcmp(dst0, dst1, width * sizeof(uint16_t))) + fail(); + bench_new(dst1, src1, mask, width); av_free(src0); av_free(src1); @@ -72,24 +73,23 @@ static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c) declare_func(void, uint8_t *d, const uint8_t *s, intptr_t w, uint8_t *l); + if (!check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32")) + return; + randomize_buffers(src, sizeof (src)); randomize_buffers(left, sizeof (left)); memcpy(left0, left, sizeof (left)); memcpy(left1, left, sizeof (left)); - if (check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32")) { - call_ref(dst0, src, BUF_SIZE, left0); - call_new(dst1, src, BUF_SIZE, left1); + call_ref(dst0, src, BUF_SIZE, left0); + call_new(dst1, src, BUF_SIZE, left1); - if (memcmp(dst0, dst1, sizeof (dst0)) != 0 || - memcmp(left0, left1, sizeof (left0)) != 0) { - fail(); - } - - bench_new(dst1, src, BUF_SIZE, left); + if (memcmp(dst0, dst1, sizeof (dst0)) != 0 || + memcmp(left0, left1, sizeof (left0)) != 0) { + fail(); } - report("add_hfyu_left_pred_bgr32"); + bench_new(dst1, src, BUF_SIZE, left); } void checkasm_check_huffyuvdsp(void) @@ -108,4 +108,5 @@ void checkasm_check_huffyuvdsp(void) report("add_int16_128"); check_add_hfyu_left_pred_bgr32(&c); + report("add_hfyu_left_pred_bgr32"); } -- 2.52.0 >From 37ae3ac1704b9f4960dd3ee9603690a10b14f5f4 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 17:11:29 +0200 Subject: [PATCH 02/10] tests/checkasm/huffyuvdsp: Actually test masks Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/huffyuvdsp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index 5e6dad7ea7..0cee315c24 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -35,6 +35,15 @@ buf[j] = rnd() & 0xFFFF; \ } while (0) +#define randomize_buffer_mask(buf, width, mask) \ + do { \ + unsigned mask2 = mask | (mask << 16); \ + for (size_t i = 0; i < (width & ~1); i += 2) \ + AV_WN32A((buf) + i, rnd() & mask2); \ + if (width & 1) \ + buf[width - 1] = rnd() & mask; \ + } while (0) + static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name) { if (!check_func(c->add_int16, "%s", name)) @@ -99,12 +108,15 @@ void checkasm_check_huffyuvdsp(void) ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P); + unsigned bps = 9 + rnd() % 8; + unsigned mask = (1 << bps) - 1; + /*! test width not multiple of mmsize */ - check_add_int16(&c, 65535, width, "add_int16_rnd_width"); + check_add_int16(&c, mask, width, "add_int16_rnd_width"); report("add_int16_rnd_width"); /*! test always with the same size (for perf test) */ - check_add_int16(&c, 65535, 16*128, "add_int16_128"); + check_add_int16(&c, mask, 16*128, "add_int16_128"); report("add_int16_128"); check_add_hfyu_left_pred_bgr32(&c); -- 2.52.0 >From 295ef5c8f042fec6bb9b61469e163c38be28fe92 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 17:21:44 +0200 Subject: [PATCH 03/10] tests/checkasm/huffyuvdsp: Actually test width not multiple of 16 Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/huffyuvdsp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index 0cee315c24..d4b58a5bd2 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -20,7 +20,6 @@ #include <string.h> -#include "libavutil/common.h" #include "libavutil/intreadwrite.h" #include "libavutil/mem.h" @@ -28,6 +27,10 @@ #include "checkasm.h" +enum { + MAX_WIDTH = 16*128, ///< arbitrary limit used for the tests +}; + #define randomize_buffers(buf, size) \ do { \ int j; \ @@ -104,19 +107,19 @@ static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c) void checkasm_check_huffyuvdsp(void) { HuffYUVDSPContext c; - int width = 16 * av_clip(rnd(), 16, 128); ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P); unsigned bps = 9 + rnd() % 8; unsigned mask = (1 << bps) - 1; + int width = 1 + rnd() % MAX_WIDTH; /*! test width not multiple of mmsize */ check_add_int16(&c, mask, width, "add_int16_rnd_width"); report("add_int16_rnd_width"); /*! test always with the same size (for perf test) */ - check_add_int16(&c, mask, 16*128, "add_int16_128"); + check_add_int16(&c, mask, MAX_WIDTH, "add_int16_128"); report("add_int16_128"); check_add_hfyu_left_pred_bgr32(&c); -- 2.52.0 >From 07dd514f3fb928cd911273ff8bb3e58d70ec37e3 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 18:06:41 +0200 Subject: [PATCH 04/10] avcodec/x86/huffyuvdsp: Remove unaligned add_int16 version Both source and dst are always properly aligned (to stride align) here; also document this fact. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/huffyuvdsp.h | 2 +- libavcodec/x86/huffyuvdsp.asm | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libavcodec/huffyuvdsp.h b/libavcodec/huffyuvdsp.h index 3f319b17c2..5644d75b06 100644 --- a/libavcodec/huffyuvdsp.h +++ b/libavcodec/huffyuvdsp.h @@ -23,7 +23,7 @@ #include "libavutil/pixfmt.h" typedef struct HuffYUVDSPContext { - void (*add_int16)(uint16_t *dst/*align 16*/, const uint16_t *src/*align 16*/, + void (*add_int16)(uint16_t *dst/*stride align*/, const uint16_t *src/*stride align*/, unsigned mask, int w); void (*add_hfyu_median_pred_int16)(uint16_t *dst, const uint16_t *top, diff --git a/libavcodec/x86/huffyuvdsp.asm b/libavcodec/x86/huffyuvdsp.asm index c1b375f479..114083436a 100644 --- a/libavcodec/x86/huffyuvdsp.asm +++ b/libavcodec/x86/huffyuvdsp.asm @@ -32,13 +32,7 @@ SECTION .text %macro ADD_INT16 0 cglobal add_int16, 4,4,5, dst, src, mask, w, tmp - test srcq, mmsize-1 - jnz .unaligned - test dstq, mmsize-1 - jnz .unaligned INT16_LOOP a, add -.unaligned: - INT16_LOOP u, add %endmacro INIT_XMM sse2 -- 2.52.0 >From d2f64803c188eca2090f0f8c3ac4626ba3d50599 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 18:12:10 +0200 Subject: [PATCH 05/10] avcodec/x86/huffyuvdsp_template: Don't push+pop reg unnecessarily All calling conventions on x64 have enough volatile GPRs. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/huffyuvdsp_template.asm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/x86/huffyuvdsp_template.asm b/libavcodec/x86/huffyuvdsp_template.asm index 89721f4ec3..2fd94d3071 100644 --- a/libavcodec/x86/huffyuvdsp_template.asm +++ b/libavcodec/x86/huffyuvdsp_template.asm @@ -26,7 +26,9 @@ add wd, wd test wq, 2*mmsize - 1 jz %%.tomainloop +%if ARCH_X86_32 push tmpq +%endif %%.wordloop: sub wq, 2 %ifidn %2, add @@ -40,7 +42,9 @@ mov [dstq+wq], tmpw test wq, 2*mmsize - 1 jnz %%.wordloop +%if ARCH_X86_32 pop tmpq +%endif %%.tomainloop: %ifidn %2, add add srcq, wq -- 2.52.0 >From 0f93a9d267ec15f643a2ea066d7ed79876002bbc Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 20:23:13 +0200 Subject: [PATCH 06/10] avcodec/x86/huffyuvdsp: Remove remnants of MMX Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/huffyuvdsp.asm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/x86/huffyuvdsp.asm b/libavcodec/x86/huffyuvdsp.asm index 114083436a..f8eaa921af 100644 --- a/libavcodec/x86/huffyuvdsp.asm +++ b/libavcodec/x86/huffyuvdsp.asm @@ -51,16 +51,16 @@ cglobal add_hfyu_left_pred_bgr32, 4,4,3, dst, src, w, left movd m0, [leftq] lea dstq, [dstq + wq] lea srcq, [srcq + wq] - LSHIFT m0, mmsize-4 + pslldq m0, mmsize-4 neg wq .loop: movu m1, [srcq+wq] mova m2, m1 - LSHIFT m1, 4 + pslldq m1, 4 paddb m1, m2 pshufd m0, m0, q3333 mova m2, m1 - LSHIFT m1, 8 + pslldq m1, 8 paddb m1, m2 paddb m0, m1 movu [dstq+wq], m0 -- 2.52.0 >From fa755d46c6c0e0810769e905155045a821a531d3 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 22:17:05 +0200 Subject: [PATCH 07/10] tests/checkasm/huffyuvdsp: Add test for add_hfyu_median_pred_int16 Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/checkasm/huffyuvdsp.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index d4b58a5bd2..4be043e586 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -22,6 +22,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mem.h" +#include "libavutil/mem_internal.h" #include "libavcodec/huffyuvdsp.h" @@ -77,6 +78,35 @@ static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, cons av_free(dst1); } +static void check_add_hfyu_median_pred_int16(const HuffYUVDSPContext *c, unsigned mask, int width) +{ + declare_func_emms(AV_CPU_FLAG_MMXEXT, void, uint16_t *dst, const uint16_t *top, + const uint16_t *diff, unsigned mask, + int w, int *left, int *left_top); + + if (!check_func(c->add_hfyu_median_pred_int16, "add_hfyu_median_pred_int16")) + return; + + DECLARE_ALIGNED(16, uint16_t, top)[MAX_WIDTH]; + DECLARE_ALIGNED(16, uint16_t, diff)[MAX_WIDTH]; + DECLARE_ALIGNED(16, uint16_t, dst_new)[MAX_WIDTH]; + DECLARE_ALIGNED(16, uint16_t, dst_ref)[MAX_WIDTH]; + int left_new = rnd() & mask, left_ref = left_new; + int lt_new = rnd() & mask, lt_ref = lt_new; + + randomize_buffer_mask(top, MAX_WIDTH, mask); + randomize_buffer_mask(diff, MAX_WIDTH, mask); + + call_ref(dst_ref, top, diff, mask, width, &left_ref, <_ref); + call_new(dst_new, top, diff, mask, width, &left_new, <_new); + + if (left_ref != left_new || lt_ref != lt_new || + memcmp(dst_ref, dst_new, width * sizeof(dst_ref[0]))) + fail(); + + bench_new(dst_new, top, diff, mask, width, &left_new, <_new); +} + static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c) { #define BUF_SIZE 1080 @@ -108,9 +138,9 @@ void checkasm_check_huffyuvdsp(void) { HuffYUVDSPContext c; - ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P); + ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P14); - unsigned bps = 9 + rnd() % 8; + unsigned bps = 9 + rnd() % 6; unsigned mask = (1 << bps) - 1; int width = 1 + rnd() % MAX_WIDTH; @@ -122,6 +152,9 @@ void checkasm_check_huffyuvdsp(void) check_add_int16(&c, mask, MAX_WIDTH, "add_int16_128"); report("add_int16_128"); + check_add_hfyu_median_pred_int16(&c, mask, width); + report("add_hfyu_median_pred_int16"); + check_add_hfyu_left_pred_bgr32(&c); report("add_hfyu_left_pred_bgr32"); } -- 2.52.0 >From 39e37a53511d7403c8384c68950d72afe3a53cc3 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 28 Jul 2026 22:43:21 +0200 Subject: [PATCH 08/10] avcodec/x86/huffyuvdsp: Add SSE4 add_hfyu_median_pred_int16 Heavily based upon the existing mmxext function, but it allows to use p{max,min}uw, so also supports 16bpp pixel formats. It is also faster: add_hfyu_median_pred_int16_c: 14368.1 add_hfyu_median_pred_int16_mmxext: 7384.2 ( 1.94x) add_hfyu_median_pred_int16_sse4: 6474.4 ( 2.21x) Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/huffyuvdsp.asm | 78 ++++++++++++++++++++++++++++++++ libavcodec/x86/huffyuvdsp_init.c | 6 +++ 2 files changed, 84 insertions(+) diff --git a/libavcodec/x86/huffyuvdsp.asm b/libavcodec/x86/huffyuvdsp.asm index f8eaa921af..3a6debd722 100644 --- a/libavcodec/x86/huffyuvdsp.asm +++ b/libavcodec/x86/huffyuvdsp.asm @@ -135,3 +135,81 @@ cglobal add_hfyu_median_pred_int16, 7,7,0, dst, top, diff, mask, w, left, left_t movzx r2d, word [topq-2] mov [left_topq], r2d RET + +; void ff_add_hfyu_median_prediction_sse4(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int mask, int w, int *left, int *left_top) +INIT_XMM sse4 +cglobal add_hfyu_median_pred_int16, 7,7,8, dst, top, diff, mask, w, left, left_top + movq m1, [topq] + movd m4, [left_topq] + add wd, wd + movd m6, maskd + add diffq, wq + psllq m2, m1, 16 + movd m3, [leftq] + add topq, wq + por m4, m2 + add dstq, wq + psubw m0, m1, m4 ; t-tl + neg wq + jmp .skip +.loop: +%if avx_enabled + movq m0, [topq+wq] + psllq m4, m0, 16 +%else + movq m4, [topq+wq] + mova m0, m4 + psllq m4, 16 +%endif + por m4, m1 + mova m1, m0 ; t + psubw m0, m4 ; t-tl +.skip: + movq m2, [diffq+wq] +%assign i 0 +%rep 4 +%if i<3 + paddw m4, m0, m3 ; t-tl+l +%else + SWAP 0, 4 + paddw m4, m3 ; t-tl+l +%endif +%if avx_enabled + SWAP 3,5 + pmaxuw m3, m5, m1 +%else + mova m5, m3 + pmaxuw m3, m1 +%endif +%if i==2 + punpcklwd m7, m5 +%elif i==3 + punpckldq m7, m5 +%endif + pand m4, m6 + pminuw m5, m1 + pminuw m3, m4 + pmaxuw m3, m5 ; median + paddw m3, m2 ; +residual + pand m3, m6 +%if i==0 + mova m7, m3 +%elif i == 3 + pshuflw m4, m3, 0 + pblendw m7, m4, 1000b +%endif +%if i<3 + psrlq m0, 16 + psrlq m1, 16 + psrlq m2, 16 +%endif +%assign i i+1 +%endrep + movq [dstq+wq], m7 + add wq, 8 + jl .loop + movzx r2d, word [dstq-2] + mov [leftq], r2d + movzx r2d, word [topq-2] + mov [left_topq], r2d + RET diff --git a/libavcodec/x86/huffyuvdsp_init.c b/libavcodec/x86/huffyuvdsp_init.c index b25a416d81..feca6a5a95 100644 --- a/libavcodec/x86/huffyuvdsp_init.c +++ b/libavcodec/x86/huffyuvdsp_init.c @@ -31,6 +31,8 @@ void ff_add_int16_avx2(uint16_t *dst, const uint16_t *src, unsigned mask, int w) void ff_add_hfyu_left_pred_bgr32_sse2(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left); void ff_add_hfyu_median_pred_int16_mmxext(uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top); +void ff_add_hfyu_median_pred_int16_sse4(uint16_t *dst, const uint16_t *top, const uint16_t *diff, + unsigned mask, int w, int *left, int *left_top); av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt) { @@ -46,6 +48,10 @@ av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix c->add_hfyu_left_pred_bgr32 = ff_add_hfyu_left_pred_bgr32_sse2; } + if (EXTERNAL_SSE4(cpu_flags)) { + c->add_hfyu_median_pred_int16 = ff_add_hfyu_median_pred_int16_sse4; + } + if (EXTERNAL_AVX2_FAST(cpu_flags)) { c->add_int16 = ff_add_int16_avx2; } -- 2.52.0 >From 5e931cdafc48b8789aa3a397f55a8c8c20744e16 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 30 Jul 2026 01:31:07 +0200 Subject: [PATCH 09/10] avcodec/x86/huffyuvdsp: Remove ff_add_hfyu_median_prediction_mmxext Superseded by SSE4. This makes the huffyuv decoders ABI compliant, e.g. nothing messes up the FPU state at all any more. Therefore the emms_c() can be removed from huffyuvdec.c. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/huffyuvdec.c | 3 -- libavcodec/x86/huffyuvdsp.asm | 66 -------------------------------- libavcodec/x86/huffyuvdsp_init.c | 7 ---- tests/checkasm/huffyuvdsp.c | 2 +- 4 files changed, 1 insertion(+), 77 deletions(-) diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index c98904d497..6b96788ff3 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -43,7 +43,6 @@ #include "huffyuvdsp.h" #include "lossless_videodsp.h" #include "thread.h" -#include "libavutil/emms.h" #include "libavutil/imgutils.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" @@ -887,7 +886,6 @@ static void draw_slice(HYuvDecContext *s, AVCodecContext *avctx, AVFrame *frame, offset[2] = frame->linesize[2] * cy; for (i = 3; i < AV_NUM_DATA_POINTERS; i++) offset[i] = 0; - emms_c(); avctx->draw_horiz_band(avctx, frame, offset, y, 3, h); @@ -1305,7 +1303,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, } ret = decode_slice(avctx, p, slice_height, slice_size, y_offset, table_size); - emms_c(); if (ret < 0) return ret; } diff --git a/libavcodec/x86/huffyuvdsp.asm b/libavcodec/x86/huffyuvdsp.asm index 3a6debd722..5d6379da84 100644 --- a/libavcodec/x86/huffyuvdsp.asm +++ b/libavcodec/x86/huffyuvdsp.asm @@ -70,72 +70,6 @@ cglobal add_hfyu_left_pred_bgr32, 4,4,3, dst, src, w, left movd [leftq], m0 RET - -; void add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int mask, int w, int *left, int *left_top) -INIT_MMX mmxext -cglobal add_hfyu_median_pred_int16, 7,7,0, dst, top, diff, mask, w, left, left_top - add wd, wd - movd mm6, maskd - SPLATW mm6, mm6 - movq mm0, [topq] - movq mm2, mm0 - movd mm4, [left_topq] - psllq mm2, 16 - movq mm1, mm0 - por mm4, mm2 - movd mm3, [leftq] - psubw mm0, mm4 ; t-tl - add dstq, wq - add topq, wq - add diffq, wq - neg wq - jmp .skip -.loop: - movq mm4, [topq+wq] - movq mm0, mm4 - psllq mm4, 16 - por mm4, mm1 - movq mm1, mm0 ; t - psubw mm0, mm4 ; t-tl -.skip: - movq mm2, [diffq+wq] -%assign i 0 -%rep 4 - movq mm4, mm0 - paddw mm4, mm3 ; t-tl+l - pand mm4, mm6 - movq mm5, mm3 - pmaxsw mm3, mm1 - pminsw mm5, mm1 - pminsw mm3, mm4 - pmaxsw mm3, mm5 ; median - paddw mm3, mm2 ; +residual - pand mm3, mm6 -%if i==0 - movq mm7, mm3 - psllq mm7, 48 -%else - movq mm4, mm3 - psrlq mm7, 16 - psllq mm4, 48 - por mm7, mm4 -%endif -%if i<3 - psrlq mm0, 16 - psrlq mm1, 16 - psrlq mm2, 16 -%endif -%assign i i+1 -%endrep - movq [dstq+wq], mm7 - add wq, 8 - jl .loop - movzx r2d, word [dstq-2] - mov [leftq], r2d - movzx r2d, word [topq-2] - mov [left_topq], r2d - RET - ; void ff_add_hfyu_median_prediction_sse4(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int mask, int w, int *left, int *left_top) INIT_XMM sse4 cglobal add_hfyu_median_pred_int16, 7,7,8, dst, top, diff, mask, w, left, left_top diff --git a/libavcodec/x86/huffyuvdsp_init.c b/libavcodec/x86/huffyuvdsp_init.c index feca6a5a95..e650232960 100644 --- a/libavcodec/x86/huffyuvdsp_init.c +++ b/libavcodec/x86/huffyuvdsp_init.c @@ -21,7 +21,6 @@ #include "config.h" #include "libavutil/attributes.h" #include "libavutil/cpu.h" -#include "libavutil/pixdesc.h" #include "libavutil/x86/cpu.h" #include "libavcodec/huffyuvdsp.h" @@ -30,18 +29,12 @@ void ff_add_int16_avx2(uint16_t *dst, const uint16_t *src, unsigned mask, int w) void ff_add_hfyu_left_pred_bgr32_sse2(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left); -void ff_add_hfyu_median_pred_int16_mmxext(uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top); void ff_add_hfyu_median_pred_int16_sse4(uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top); av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt) { int cpu_flags = av_get_cpu_flags(); - const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pix_fmt); - - if (EXTERNAL_MMXEXT(cpu_flags) && pix_desc && pix_desc->comp[0].depth<16) { - c->add_hfyu_median_pred_int16 = ff_add_hfyu_median_pred_int16_mmxext; - } if (EXTERNAL_SSE2(cpu_flags)) { c->add_int16 = ff_add_int16_sse2; diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index 4be043e586..2ed80a3727 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -80,7 +80,7 @@ static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, cons static void check_add_hfyu_median_pred_int16(const HuffYUVDSPContext *c, unsigned mask, int width) { - declare_func_emms(AV_CPU_FLAG_MMXEXT, void, uint16_t *dst, const uint16_t *top, + declare_func(void, uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top); -- 2.52.0 >From 4832504c3b477d9fc779a3e1e161edc9a9d94858 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 30 Jul 2026 01:56:32 +0200 Subject: [PATCH 10/10] avcodec/huffyuvdsp: Remove pix_fmt parameter from ff_huffyuvdsp_init() It is unused since the mmx add_hfyu_median_pred_int16 function has been removed. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/aarch64/huffyuvdsp_init_aarch64.c | 2 +- libavcodec/huffyuvdec.c | 2 +- libavcodec/huffyuvdsp.c | 8 ++++---- libavcodec/huffyuvdsp.h | 11 ++++------- libavcodec/riscv/huffyuvdsp_init.c | 3 +-- libavcodec/x86/huffyuvdsp_init.c | 2 +- tests/checkasm/huffyuvdsp.c | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/libavcodec/aarch64/huffyuvdsp_init_aarch64.c b/libavcodec/aarch64/huffyuvdsp_init_aarch64.c index 210c58589a..60f32b3f7a 100644 --- a/libavcodec/aarch64/huffyuvdsp_init_aarch64.c +++ b/libavcodec/aarch64/huffyuvdsp_init_aarch64.c @@ -25,7 +25,7 @@ void ff_add_int16_neon(uint16_t *dst, const uint16_t *src, unsigned mask, int w); -av_cold void ff_huffyuvdsp_init_aarch64(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt) +av_cold void ff_huffyuvdsp_init_aarch64(HuffYUVDSPContext *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index 6b96788ff3..89430511dd 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -350,7 +350,7 @@ static av_cold int decode_init(AVCodecContext *avctx) s->flags = avctx->flags; ff_bswapdsp_init(&s->bdsp); - ff_huffyuvdsp_init(&s->hdsp, avctx->pix_fmt); + ff_huffyuvdsp_init(&s->hdsp); ff_llviddsp_init(&s->llviddsp); s->interlaced = avctx->height > 288; diff --git a/libavcodec/huffyuvdsp.c b/libavcodec/huffyuvdsp.c index 71ff1bf1a4..3772fe9687 100644 --- a/libavcodec/huffyuvdsp.c +++ b/libavcodec/huffyuvdsp.c @@ -81,17 +81,17 @@ static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src, left[A] = a; } -av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt) +av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c) { c->add_int16 = add_int16_c; c->add_hfyu_median_pred_int16 = add_hfyu_median_pred_int16_c; c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c; #if ARCH_AARCH64 - ff_huffyuvdsp_init_aarch64(c, pix_fmt); + ff_huffyuvdsp_init_aarch64(c); #elif ARCH_RISCV - ff_huffyuvdsp_init_riscv(c, pix_fmt); + ff_huffyuvdsp_init_riscv(c); #elif ARCH_X86 && HAVE_X86ASM - ff_huffyuvdsp_init_x86(c, pix_fmt); + ff_huffyuvdsp_init_x86(c); #endif } diff --git a/libavcodec/huffyuvdsp.h b/libavcodec/huffyuvdsp.h index 5644d75b06..9869025086 100644 --- a/libavcodec/huffyuvdsp.h +++ b/libavcodec/huffyuvdsp.h @@ -20,7 +20,6 @@ #define AVCODEC_HUFFYUVDSP_H #include <stdint.h> -#include "libavutil/pixfmt.h" typedef struct HuffYUVDSPContext { void (*add_int16)(uint16_t *dst/*stride align*/, const uint16_t *src/*stride align*/, @@ -33,11 +32,9 @@ typedef struct HuffYUVDSPContext { intptr_t w, uint8_t *left); } HuffYUVDSPContext; -void ff_huffyuvdsp_init(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt); -void ff_huffyuvdsp_init_aarch64(HuffYUVDSPContext *c, - enum AVPixelFormat pix_fmt); -void ff_huffyuvdsp_init_riscv(HuffYUVDSPContext *c, - enum AVPixelFormat pix_fmt); -void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt); +void ff_huffyuvdsp_init(HuffYUVDSPContext *c); +void ff_huffyuvdsp_init_aarch64(HuffYUVDSPContext *c); +void ff_huffyuvdsp_init_riscv(HuffYUVDSPContext *c); +void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c); #endif /* AVCODEC_HUFFYUVDSP_H */ diff --git a/libavcodec/riscv/huffyuvdsp_init.c b/libavcodec/riscv/huffyuvdsp_init.c index 362ccb215f..613fe3e721 100644 --- a/libavcodec/riscv/huffyuvdsp_init.c +++ b/libavcodec/riscv/huffyuvdsp_init.c @@ -27,8 +27,7 @@ void ff_add_int16_rvv(uint16_t *dst, const uint16_t *src, unsigned m, int w); void ff_add_hfyu_left_pred_bgr32_rvv(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left); -av_cold void ff_huffyuvdsp_init_riscv(HuffYUVDSPContext *c, - enum AVPixelFormat pix_fmt) +av_cold void ff_huffyuvdsp_init_riscv(HuffYUVDSPContext *c) { #if HAVE_RVV int flags = av_get_cpu_flags(); diff --git a/libavcodec/x86/huffyuvdsp_init.c b/libavcodec/x86/huffyuvdsp_init.c index e650232960..e709d19e81 100644 --- a/libavcodec/x86/huffyuvdsp_init.c +++ b/libavcodec/x86/huffyuvdsp_init.c @@ -32,7 +32,7 @@ void ff_add_hfyu_left_pred_bgr32_sse2(uint8_t *dst, const uint8_t *src, void ff_add_hfyu_median_pred_int16_sse4(uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top); -av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt) +av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/huffyuvdsp.c index 2ed80a3727..a58f1a34c4 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/huffyuvdsp.c @@ -138,9 +138,9 @@ void checkasm_check_huffyuvdsp(void) { HuffYUVDSPContext c; - ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P14); + ff_huffyuvdsp_init(&c); - unsigned bps = 9 + rnd() % 6; + unsigned bps = 9 + rnd() % 8; unsigned mask = (1 << bps) - 1; int width = 1 + rnd() % MAX_WIDTH; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]