This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 21c81303cb7c6c407dac1a8c03991ab273f1fe13
Author:     Baptiste Coudurier <[email protected]>
AuthorDate: Tue Nov 10 22:08:57 2026 -0800
Commit:     Baptiste Coudurier <[email protected]>
CommitDate: Fri Nov 20 18:58:06 2026 +0000

    avfilter/x86: add SSE2 16-bit SAD for mpdecimate
    
    About 1.7x faster than the C version auto-vectorized by GCC 13.3, making
    the filter itself 1.56x faster on 1080p 10 and 16-bit input on Zen 3.
    
    Co-Authored-By: Claude Fable 5.2 <[email protected]>
    Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavcodec/h261enc.h => libavfilter/mpdecimate.h   | 23 +++----
 libavfilter/vf_mpdecimate.c                        | 16 ++++-
 libavfilter/x86/Makefile                           |  2 +
 .../x86/vf_mpdecimate.asm                          | 50 ++++++++-------
 .../x86/vf_mpdecimate_init.c                       | 16 ++---
 tests/checkasm/Makefile                            |  1 +
 tests/checkasm/checkasm.c                          |  3 +
 tests/checkasm/checkasm.h                          |  1 +
 tests/checkasm/vf_mpdecimate.c                     | 71 ++++++++++++++++++++++
 tests/fate/checkasm.mak                            |  1 +
 10 files changed, 140 insertions(+), 44 deletions(-)

diff --git a/libavcodec/h261enc.h b/libavfilter/mpdecimate.h
similarity index 70%
copy from libavcodec/h261enc.h
copy to libavfilter/mpdecimate.h
index 77f072a5e7..d8728792ab 100644
--- a/libavcodec/h261enc.h
+++ b/libavfilter/mpdecimate.h
@@ -1,8 +1,4 @@
 /*
- * H.261 encoder
- * Copyright (c) 2002-2004 Michael Niedermayer <[email protected]>
- * Copyright (c) 2004 Maarten Daniels
- *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -20,16 +16,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/**
- * @file
- * H.261 encoder header.
- */
+#ifndef AVFILTER_MPDECIMATE_H
+#define AVFILTER_MPDECIMATE_H
 
-#ifndef AVCODEC_H261ENC_H
-#define AVCODEC_H261ENC_H
+#include "libavutil/pixelutils.h"
 
-typedef struct MPVEncContext MPVEncContext;
+/**
+ * Get the SAD function for 8x8 blocks of 16-bit samples.
+ * Strides are in bytes.
+ */
+av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn(void);
 
-void ff_h261_reorder_mb_index(MPVEncContext *s);
+av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn_x86(void);
 
-#endif
+#endif /* AVFILTER_MPDECIMATE_H */
diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c
index 37cd8cb017..6bed7186cd 100644
--- a/libavfilter/vf_mpdecimate.c
+++ b/libavfilter/vf_mpdecimate.c
@@ -25,6 +25,8 @@
  * Rich Felker.
  */
 
+#include "config.h"
+
 #include "libavutil/bprint.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -32,6 +34,7 @@
 #include "libavutil/timestamp.h"
 #include "avfilter.h"
 #include "filters.h"
+#include "mpdecimate.h"
 #include "video.h"
 
 typedef enum {
@@ -101,6 +104,17 @@ static int sad_8x8_16(const uint8_t *src1, ptrdiff_t 
stride1,
     return sum;
 }
 
+av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn(void)
+{
+    av_pixelutils_sad_fn sad = NULL;
+
+#if ARCH_X86 && HAVE_X86ASM
+    sad = ff_mpdecimate_get_sad16_fn_x86();
+#endif
+
+    return sad ? sad : sad_8x8_16;
+}
+
 /**
  * Return 1 if the two planes are different, 0 otherwise.
  * The reason is appended to bp, which the caller prints with the frame's
@@ -271,7 +285,7 @@ static int config_input(AVFilterLink *inlink)
     decimate->lo_thr = av_clip64(decimate->lo * scale, INT_MIN, INT_MAX);
 
     if (depth > 8)
-        decimate->sad = sad_8x8_16;
+        decimate->sad = ff_mpdecimate_get_sad16_fn();
     else
         decimate->sad = av_pixelutils_get_sad_fn(3, 3, 0, ctx); // 8x8, not 
aligned on blocksize
     if (!decimate->sad)
diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
index cfbed4317c..895b33f483 100644
--- a/libavfilter/x86/Makefile
+++ b/libavfilter/x86/Makefile
@@ -43,6 +43,8 @@ X86ASM-OBJS-$(CONFIG_MASKEDCLAMP_FILTER)     += 
x86/vf_maskedclamp.o          \
                                                 x86/vf_maskedclamp_init.o
 X86ASM-OBJS-$(CONFIG_MASKEDMERGE_FILTER)     += x86/vf_maskedmerge.o          \
                                                 x86/vf_maskedmerge_init.o
+X86ASM-OBJS-$(CONFIG_MPDECIMATE_FILTER)      += x86/vf_mpdecimate.o           \
+                                                x86/vf_mpdecimate_init.o
 X86ASM-OBJS-$(CONFIG_NLMEANS_FILTER)         += x86/vf_nlmeans.o              \
                                                 x86/vf_nlmeans_init.o
 X86ASM-OBJS-$(CONFIG_OVERLAY_FILTER)         += x86/vf_overlay.o              \
diff --git a/libavutil/x86/fixed_dsp.asm b/libavfilter/x86/vf_mpdecimate.asm
similarity index 54%
copy from libavutil/x86/fixed_dsp.asm
copy to libavfilter/x86/vf_mpdecimate.asm
index 2f411850f4..1780585aa9 100644
--- a/libavutil/x86/fixed_dsp.asm
+++ b/libavfilter/x86/vf_mpdecimate.asm
@@ -1,7 +1,5 @@
 ;*****************************************************************************
-;* x86-optimized Float DSP functions
-;*
-;* Copyright 2016 James Almer
+;* x86-optimized functions for mpdecimate filter
 ;*
 ;* This file is part of FFmpeg.
 ;*
@@ -24,25 +22,33 @@
 
 SECTION .text
 
-;-----------------------------------------------------------------------------
-; void ff_butterflies_fixed(float *src0, float *src1, int len);
-;-----------------------------------------------------------------------------
+;------------------------------------------------------------------------------
+; int ff_mpdecimate_sad_8x8_16(const uint8_t *src1, ptrdiff_t stride1,
+;                              const uint8_t *src2, ptrdiff_t stride2);
+;
+; SAD of an 8x8 block of unaligned 16-bit samples, strides in bytes.
+;------------------------------------------------------------------------------
 INIT_XMM sse2
-cglobal butterflies_fixed, 3,3,3, src0, src1, len
-    shl       lend, 2
-    add      src0q, lenq
-    add      src1q, lenq
-    neg       lenq
-
-align 16
+cglobal mpdecimate_sad_8x8_16, 4, 5, 5, src1, stride1, src2, stride2, cnt
+    pxor            m0, m0
+    pxor            m4, m4
+    mov           cntd, 8
 .loop:
-    mova        m0, [src0q + lenq]
-    mova        m1, [src1q + lenq]
-    mova        m2, m0
-    paddd       m0, m1
-    psubd       m2, m1
-    mova        [src0q + lenq], m0
-    mova        [src1q + lenq], m2
-    add       lenq, mmsize
-    jl .loop
+    movu            m1, [src1q]
+    movu            m2, [src2q]
+    mova            m3, m1
+    psubusw         m1, m2
+    psubusw         m2, m3
+    por             m1, m2          ; |src1 - src2|, full 16-bit range
+    mova            m2, m1
+    punpcklwd       m1, m4
+    punpckhwd       m2, m4
+    paddd           m0, m1
+    paddd           m0, m2
+    add          src1q, stride1q
+    add          src2q, stride2q
+    dec           cntd
+    jg .loop
+    HADDD           m0, m1
+    movd           eax, m0
     RET
diff --git a/libavcodec/x86/g722dsp_init.c 
b/libavfilter/x86/vf_mpdecimate_init.c
similarity index 72%
copy from libavcodec/x86/g722dsp_init.c
copy to libavfilter/x86/vf_mpdecimate_init.c
index 614695193b..583277e1b2 100644
--- a/libavcodec/x86/g722dsp_init.c
+++ b/libavfilter/x86/vf_mpdecimate_init.c
@@ -1,6 +1,4 @@
 /*
- * Copyright (c) 2014 James Almer
- *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -18,18 +16,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <stdint.h>
-
 #include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/g722dsp.h"
+#include "libavfilter/mpdecimate.h"
 
-void ff_g722_apply_qmf_sse2(const int16_t *prev_samples, int xout[2]);
+int ff_mpdecimate_sad_8x8_16_sse2(const uint8_t *src1, ptrdiff_t stride1,
+                                  const uint8_t *src2, ptrdiff_t stride2);
 
-av_cold void ff_g722dsp_init_x86(G722DSPContext *dsp)
+av_cold av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn_x86(void)
 {
     int cpu_flags = av_get_cpu_flags();
 
     if (EXTERNAL_SSE2(cpu_flags))
-        dsp->apply_qmf = ff_g722_apply_qmf_sse2;
+        return ff_mpdecimate_sad_8x8_16_sse2;
+
+    return NULL;
 }
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index ab1cc17b56..28d7d8400c 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -82,6 +82,7 @@ AVFILTEROBJS-$(CONFIG_GBLUR_FILTER)      += vf_gblur.o
 AVFILTEROBJS-$(CONFIG_HFLIP_FILTER)      += vf_hflip.o
 AVFILTEROBJS-$(CONFIG_IDET_FILTER)       += vf_idet.o
 AVFILTEROBJS-$(CONFIG_LIMITER_FILTER)    += vf_limiter.o
+AVFILTEROBJS-$(CONFIG_MPDECIMATE_FILTER) += vf_mpdecimate.o
 AVFILTEROBJS-$(CONFIG_PP7_FILTER)        += vf_pp7.o
 AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER)  += vf_threshold.o
 AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER)    += vf_nlmeans.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 4d15a7b7d1..e0d8593d4f 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -285,6 +285,9 @@ static const CheckasmTest tests[] = {
     #if CONFIG_IDET_FILTER
         { "vf_idet", checkasm_check_idet },
     #endif
+    #if CONFIG_MPDECIMATE_FILTER
+        { "vf_mpdecimate", checkasm_check_mpdecimate },
+    #endif
     #if CONFIG_NLMEANS_FILTER
         { "vf_nlmeans", checkasm_check_nlmeans },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 0fc6823c4f..e00e5c63ea 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -82,6 +82,7 @@ void checkasm_check_llvidencdsp(void);
 void checkasm_check_lpc(void);
 void checkasm_check_motion(void);
 void checkasm_check_mpeg4videodsp(void);
+void checkasm_check_mpdecimate(void);
 void checkasm_check_mpegvideo_unquantize(void);
 void checkasm_check_mpegvideoencdsp(void);
 void checkasm_check_nlmeans(void);
diff --git a/tests/checkasm/vf_mpdecimate.c b/tests/checkasm/vf_mpdecimate.c
new file mode 100644
index 0000000000..1a74cc5ca5
--- /dev/null
+++ b/tests/checkasm/vf_mpdecimate.c
@@ -0,0 +1,71 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "checkasm.h"
+
+#include "libavfilter/mpdecimate.h"
+#include "libavutil/mem_internal.h"
+
+#define STRIDE 32
+
+static void check_sad16(int depth)
+{
+    LOCAL_ALIGNED_32(uint16_t, src1, [STRIDE * 9]);
+    LOCAL_ALIGNED_32(uint16_t, src2, [STRIDE * 9]);
+    const int mask = (1 << depth) - 1;
+
+    declare_func(int, const uint8_t *src1, ptrdiff_t stride1,
+                      const uint8_t *src2, ptrdiff_t stride2);
+
+    for (int i = 0; i < STRIDE * 9; i++) {
+        src1[i] = rnd() & mask;
+        src2[i] = rnd() & mask;
+    }
+    if (depth == 16) {
+        /* largest possible SAD */
+        for (int i = 0; i < STRIDE * 9; i++) {
+            src1[i] = 0;
+            src2[i] = 0xffff;
+        }
+    }
+
+    if (check_func(ff_mpdecimate_get_sad16_fn(), "sad_8x8_16_%d", depth)) {
+        /* blocks are not aligned in the filter */
+        for (int off = 0; off < 2; off++) {
+            const uint8_t *p1 = (const uint8_t *)(src1 + off * 3);
+            const uint8_t *p2 = (const uint8_t *)(src2 + off * 5);
+            int ref = call_ref(p1, STRIDE * 2, p2, STRIDE * 2);
+            int new = call_new(p1, STRIDE * 2, p2, STRIDE * 2);
+            if (ref != new) {
+                fprintf(stderr, "sad_8x8_16_%d: %d != %d\n", depth, ref, new);
+                fail();
+            }
+        }
+        bench_new((const uint8_t *)src1, STRIDE * 2,
+                  (const uint8_t *)src2, STRIDE * 2);
+    }
+}
+
+void checkasm_check_mpdecimate(void)
+{
+    static const int depths[] = { 10, 12, 15, 16 };
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(depths); i++)
+        check_sad16(depths[i]);
+    report("sad_8x8_16");
+}
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 19bbe7e571..df996cccec 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -88,6 +88,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                       
          \
                 fate-checkasm-vf_hflip                                  \
                 fate-checkasm-vf_idet                                   \
                                fate-checkasm-vf_limiter                        
        \
+                fate-checkasm-vf_mpdecimate                             \
                 fate-checkasm-vf_nlmeans                                \
                 fate-checkasm-vf_pp7                                    \
                 fate-checkasm-vf_threshold                              \

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to