Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/4] avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn()
@ 2025-07-12  9:22 Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 2/4] tests/checkasm: add scene_sad checkasm test Niklas Haas
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Niklas Haas @ 2025-07-12  9:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

I need to be able to distinguish between 10/12/14 and 16 bit depths, for
overflow reasons.
---
 libavfilter/f_select.c           | 2 +-
 libavfilter/scene_sad.c          | 5 ++---
 libavfilter/vf_framerate.c       | 2 +-
 libavfilter/vf_freezedetect.c    | 2 +-
 libavfilter/vf_identity.c        | 2 +-
 libavfilter/vf_minterpolate.c    | 2 +-
 libavfilter/vf_scdet.c           | 2 +-
 libavfilter/x86/scene_sad_init.c | 2 +-
 8 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index a5609ec178..46208a7b76 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -272,7 +272,7 @@ static int config_input(AVFilterLink *inlink)
         inlink->type == AVMEDIA_TYPE_AUDIO ? inlink->sample_rate : NAN;
 
     if (CONFIG_SELECT_FILTER && select->do_scene_detect) {
-        select->sad = ff_scene_sad_get_fn(select->bitdepth == 8 ? 8 : 16);
+        select->sad = ff_scene_sad_get_fn(select->bitdepth);
         if (!select->sad)
             return AVERROR(EINVAL);
     }
diff --git a/libavfilter/scene_sad.c b/libavfilter/scene_sad.c
index caf911eb5d..05dd97e055 100644
--- a/libavfilter/scene_sad.c
+++ b/libavfilter/scene_sad.c
@@ -63,11 +63,10 @@ ff_scene_sad_fn ff_scene_sad_get_fn(int depth)
     sad = ff_scene_sad_get_fn_x86(depth);
 #endif
     if (!sad) {
-        if (depth == 8)
+        if (depth <= 8)
             sad = ff_scene_sad_c;
-        if (depth == 16)
+        else if (depth <= 16)
             sad = ff_scene_sad16_c;
     }
     return sad;
 }
-
diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c
index 9976db8d93..a6598f97bb 100644
--- a/libavfilter/vf_framerate.c
+++ b/libavfilter/vf_framerate.c
@@ -282,7 +282,7 @@ static int config_input(AVFilterLink *inlink)
 
     s->bitdepth = pix_desc->comp[0].depth;
 
-    s->sad = ff_scene_sad_get_fn(s->bitdepth == 8 ? 8 : 16);
+    s->sad = ff_scene_sad_get_fn(s->bitdepth);
     if (!s->sad)
         return AVERROR(EINVAL);
 
diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c
index ce67eed3ae..465a2e640b 100644
--- a/libavfilter/vf_freezedetect.c
+++ b/libavfilter/vf_freezedetect.c
@@ -103,7 +103,7 @@ static int config_input(AVFilterLink *inlink)
         s->height[plane] = inlink->h >> ((plane == 1 || plane == 2) ? pix_desc->log2_chroma_h : 0);
     }
 
-    s->sad = ff_scene_sad_get_fn(s->bitdepth == 8 ? 8 : 16);
+    s->sad = ff_scene_sad_get_fn(s->bitdepth);
     if (!s->sad)
         return AVERROR(EINVAL);
 
diff --git a/libavfilter/vf_identity.c b/libavfilter/vf_identity.c
index fc44bfaea0..6a94a92355 100644
--- a/libavfilter/vf_identity.c
+++ b/libavfilter/vf_identity.c
@@ -304,7 +304,7 @@ static int config_input_ref(AVFilterLink *inlink)
     s->filter_slice = !s->is_msad ? compute_images_identity : compute_images_msad;
     s->filter_line = desc->comp[0].depth > 8 ? identity_line_16bit : identity_line_8bit;
 
-    s->sad = ff_scene_sad_get_fn(desc->comp[0].depth <= 8 ? 8 : 16);
+    s->sad = ff_scene_sad_get_fn(desc->comp[0].depth);
     if (!s->sad)
         return AVERROR(EINVAL);
 
diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
index 93d331f2ff..d034783bc5 100644
--- a/libavfilter/vf_minterpolate.c
+++ b/libavfilter/vf_minterpolate.c
@@ -387,7 +387,7 @@ static int config_input(AVFilterLink *inlink)
     }
 
     if (mi_ctx->scd_method == SCD_METHOD_FDIFF) {
-        mi_ctx->sad = ff_scene_sad_get_fn(mi_ctx->bitdepth == 8 ? 8 : 16);
+        mi_ctx->sad = ff_scene_sad_get_fn(mi_ctx->bitdepth);
         if (!mi_ctx->sad)
             return AVERROR(EINVAL);
     }
diff --git a/libavfilter/vf_scdet.c b/libavfilter/vf_scdet.c
index 1568a0a496..8aa2f0a73b 100644
--- a/libavfilter/vf_scdet.c
+++ b/libavfilter/vf_scdet.c
@@ -91,7 +91,7 @@ static int config_input(AVFilterLink *inlink)
         s->height[plane] = inlink->h >> ((plane == 1 || plane == 2) ? desc->log2_chroma_h : 0);
     }
 
-    s->sad = ff_scene_sad_get_fn(s->bitdepth == 8 ? 8 : 16);
+    s->sad = ff_scene_sad_get_fn(s->bitdepth);
     if (!s->sad)
         return AVERROR(EINVAL);
 
diff --git a/libavfilter/x86/scene_sad_init.c b/libavfilter/x86/scene_sad_init.c
index 2c3729ceee..4a4c40195f 100644
--- a/libavfilter/x86/scene_sad_init.c
+++ b/libavfilter/x86/scene_sad_init.c
@@ -47,7 +47,7 @@ ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
 {
 #if HAVE_X86ASM
     int cpu_flags = av_get_cpu_flags();
-    if (depth == 8) {
+    if (depth <= 8) {
 #if HAVE_AVX2_EXTERNAL
         if (EXTERNAL_AVX2_FAST(cpu_flags))
             return scene_sad_avx2;
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] tests/checkasm: add scene_sad checkasm test
  2025-07-12  9:22 [FFmpeg-devel] [PATCH 1/4] avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn() Niklas Haas
@ 2025-07-12  9:22 ` Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 3/4] avfilter/x86/scene_sad: add AVX512 implementation Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 4/4] avfilter/x86/scene_sad: add high bit depth AVX2/AVX512 version Niklas Haas
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Haas @ 2025-07-12  9:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

---
 tests/checkasm/Makefile    |  1 +
 tests/checkasm/checkasm.c  |  3 ++
 tests/checkasm/checkasm.h  |  1 +
 tests/checkasm/scene_sad.c | 73 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+)
 create mode 100644 tests/checkasm/scene_sad.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index afd62d95ba..1938468bbd 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -52,6 +52,7 @@ AVCODECOBJS-$(CONFIG_VVC_DECODER)       += vvc_alf.o vvc_mc.o vvc_sao.o
 CHECKASMOBJS-$(CONFIG_AVCODEC)          += $(AVCODECOBJS-yes)
 
 # libavfilter tests
+AVFILTEROBJS-$(CONFIG_SCENE_SAD)         += scene_sad.o
 AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o
 AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o
 AVFILTEROBJS-$(CONFIG_BWDIF_FILTER)      += vf_bwdif.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index f4e3d4f433..66a8f8ff86 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -260,6 +260,9 @@ static const struct {
     #endif
 #endif
 #if CONFIG_AVFILTER
+    #if CONFIG_SCENE_SAD
+        { "scene_sad", checkasm_check_scene_sad },
+    #endif
     #if CONFIG_AFIR_FILTER
         { "af_afir", checkasm_check_afir },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index e829942d58..825e7ef52f 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -124,6 +124,7 @@ void checkasm_check_pixblockdsp(void);
 void checkasm_check_sbrdsp(void);
 void checkasm_check_rv34dsp(void);
 void checkasm_check_rv40dsp(void);
+void checkasm_check_scene_sad(void);
 void checkasm_check_svq1enc(void);
 void checkasm_check_synth_filter(void);
 void checkasm_check_sw_gbrp(void);
diff --git a/tests/checkasm/scene_sad.c b/tests/checkasm/scene_sad.c
new file mode 100644
index 0000000000..bc33c428c6
--- /dev/null
+++ b/tests/checkasm/scene_sad.c
@@ -0,0 +1,73 @@
+/*
+ * 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/scene_sad.h"
+#include "libavutil/mem_internal.h"
+
+#define WIDTH  256
+#define HEIGHT 256
+#define STRIDE WIDTH
+
+#define randomize_buffers(type, buf, size, mask)  \
+    do {                                          \
+        int j;                                    \
+        type *tmp_buf = (type *) buf;             \
+        for (j = 0; j < size; j++)                \
+            tmp_buf[j] = rnd() & mask;            \
+    } while (0)
+
+static void check_scene_sad(int depth)
+{
+    LOCAL_ALIGNED_32(uint8_t, src1, [WIDTH * HEIGHT * 2]);
+    LOCAL_ALIGNED_32(uint8_t, src2, [WIDTH * HEIGHT * 2]);
+    declare_func(void, const uint8_t *src1, ptrdiff_t stride1,
+                       const uint8_t *src2, ptrdiff_t stride2,
+                       ptrdiff_t width, ptrdiff_t height, uint64_t *sum);
+
+    const int width = WIDTH >> (depth > 8);
+    int mask = (1 << depth) - 1;
+    if (depth <= 8) {
+        randomize_buffers(uint8_t,  src1, width * HEIGHT, mask);
+        randomize_buffers(uint8_t,  src2, width * HEIGHT, mask);
+    } else if (depth <= 16) {
+        randomize_buffers(uint16_t, src1, width * HEIGHT, mask);
+        randomize_buffers(uint16_t, src2, width * HEIGHT, mask);
+    }
+
+    if (check_func(ff_scene_sad_get_fn(depth), "scene_sad%d", depth)) {
+        uint64_t sum1, sum2;
+        call_ref(src1, STRIDE, src2, STRIDE, width, HEIGHT, &sum1);
+        call_new(src1, STRIDE, src2, STRIDE, width, HEIGHT, &sum2);
+        if (sum1 != sum2) {
+            fprintf(stderr, "scene_sad%d: sum mismatch: %llu != %llu\n",
+                    depth, (unsigned long long) sum1, (unsigned long long) sum2);
+            fail();
+        }
+        bench_new(src1, STRIDE, src2, STRIDE, WIDTH, HEIGHT, &sum2);
+    }
+}
+
+void checkasm_check_scene_sad(void)
+{
+    const int depths[] = { 8, 10, 12, 14, 15, 16 };
+    for (int i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
+        check_scene_sad(depths[i]);
+        report("scene_sad%d", depths[i]);
+    }
+}
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH 3/4] avfilter/x86/scene_sad: add AVX512 implementation
  2025-07-12  9:22 [FFmpeg-devel] [PATCH 1/4] avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn() Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 2/4] tests/checkasm: add scene_sad checkasm test Niklas Haas
@ 2025-07-12  9:22 ` Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 4/4] avfilter/x86/scene_sad: add high bit depth AVX2/AVX512 version Niklas Haas
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Haas @ 2025-07-12  9:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

Trivial to add, but a lot faster (on my machine).

scene_sad8_c:                                       114476.4 ( 1.00x)
scene_sad8_sse2:                                      8644.3 (13.24x)
scene_sad8_avx2:                                      4520.1 (25.33x)
scene_sad8_avx512:                                    3153.0 (36.31x)
---
 libavfilter/x86/scene_sad.asm    | 7 +++++++
 libavfilter/x86/scene_sad_init.c | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/libavfilter/x86/scene_sad.asm b/libavfilter/x86/scene_sad.asm
index bf7236b3a3..2cd9dddb5c 100644
--- a/libavfilter/x86/scene_sad.asm
+++ b/libavfilter/x86/scene_sad.asm
@@ -72,3 +72,10 @@ INIT_YMM avx2
 SAD_FRAMES
 
 %endif
+
+%if HAVE_AVX512_EXTERNAL
+
+INIT_ZMM avx512
+SAD_FRAMES
+
+%endif
diff --git a/libavfilter/x86/scene_sad_init.c b/libavfilter/x86/scene_sad_init.c
index 4a4c40195f..2d631b376a 100644
--- a/libavfilter/x86/scene_sad_init.c
+++ b/libavfilter/x86/scene_sad_init.c
@@ -41,6 +41,9 @@ SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad_sse2, 16)
 #if HAVE_AVX2_EXTERNAL
 SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad_avx2, 32)
 #endif
+#if HAVE_AVX512_EXTERNAL
+SCENE_SAD_FUNC(scene_sad_avx512, ff_scene_sad_avx512, 64)
+#endif
 #endif
 
 ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
@@ -48,6 +51,10 @@ ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
 #if HAVE_X86ASM
     int cpu_flags = av_get_cpu_flags();
     if (depth <= 8) {
+#if HAVE_AVX512_EXTERNAL
+        if (EXTERNAL_AVX512(cpu_flags))
+            return scene_sad_avx512;
+#endif
 #if HAVE_AVX2_EXTERNAL
         if (EXTERNAL_AVX2_FAST(cpu_flags))
             return scene_sad_avx2;
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] avfilter/x86/scene_sad: add high bit depth AVX2/AVX512 version
  2025-07-12  9:22 [FFmpeg-devel] [PATCH 1/4] avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn() Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 2/4] tests/checkasm: add scene_sad checkasm test Niklas Haas
  2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 3/4] avfilter/x86/scene_sad: add AVX512 implementation Niklas Haas
@ 2025-07-12  9:22 ` Niklas Haas
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Haas @ 2025-07-12  9:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

From: Niklas Haas <git@haasn.dev>

Since psadbw only exists for 8-bits, we have to emulate it for 16-bit
inputs. The simplest sequence is to use a normal subtraction, which is safe
as long as the inputs do not exceed 32767 - so limit this implementation
to 15-bit inputs and below.

For 16-bit inputs, we could in theory instead use a pminw / pmaxw to ensure
the resulting difference does not overflow, but this is slower, and also
breaks the subsequent use of pmaddwd, so I opted to skip 16-bit SIMD for
now.

scene_sad10_c:                                      114175.6 ( 1.00x)
scene_sad10_avx2:                                     9617.7 (11.87x)
scene_sad10_avx512:                                   5208.8 (21.92x)
scene_sad12_c:                                      114537.8 ( 1.00x)
scene_sad12_avx2:                                     9614.0 (11.91x)
scene_sad12_avx512:                                   5186.3 (22.08x)
scene_sad14_c:                                      114113.9 ( 1.00x)
scene_sad14_avx2:                                     9612.9 (11.87x)
scene_sad14_avx512:                                   5186.0 (22.00x)
scene_sad15_c:                                      114108.9 ( 1.00x)
scene_sad15_avx2:                                     9612.3 (11.87x)
scene_sad15_avx512:                                   5186.4 (22.00x)
scene_sad16_c:                                      114136.0 ( 1.00x)
---
 libavfilter/x86/scene_sad.asm    | 44 ++++++++++++++++++++++++--------
 libavfilter/x86/scene_sad_init.c | 33 +++++++++++++++++++++---
 2 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/libavfilter/x86/scene_sad.asm b/libavfilter/x86/scene_sad.asm
index 2cd9dddb5c..181c290893 100644
--- a/libavfilter/x86/scene_sad.asm
+++ b/libavfilter/x86/scene_sad.asm
@@ -24,25 +24,47 @@
 
 %include "libavutil/x86/x86util.asm"
 
+SECTION_RODATA
+
+pw_1: times 32 dw 1
+
 SECTION .text
 
 
-%macro SAD_INIT 0
-cglobal scene_sad, 6, 7, 2, src1, stride1, src2, stride2, width, end, x
+%macro SAD_INIT 1 ; depth
+cglobal scene_sad%1, 6, 7, 3, src1, stride1, src2, stride2, width, end, x
     add     src1q, widthq
     add     src2q, widthq
     neg    widthq
     pxor       m1, m1
 %endmacro
 
+%macro PSADQ 4 ; depth, dst, [src2], tmp
+%if %1 == 8
+        psadbw %2, %3
+%else
+        psubw     %2, %3
+        pabsw     %2, %2
+        pmaddwd   %2, [pw_1]
+    %if mmsize == 64
+        vextracti32x8 ymm%4, %2, 1
+        paddd     ymm%2, ymm%4
+        pmovzxdq  %2, ymm%2
+    %else
+        vextracti128 xmm%4, %2, 1
+        paddd     xmm%2, xmm%4
+        pmovzxdq  %2, xmm%2
+    %endif
+%endif
+%endmacro
 
-%macro SAD_LOOP 0
+%macro SAD_LOOP 1 ; depth
 .nextrow:
     mov        xq, widthq
 
     .loop:
         movu            m0, [src1q + xq]
-        psadbw          m0, [src2q + xq]
+        PSADQ %1,       m0, [src2q + xq], m2
         paddq           m1, m0
         add             xq, mmsize
     jl .loop
@@ -57,25 +79,27 @@ RET
 %endmacro
 
 
-%macro SAD_FRAMES 0
-    SAD_INIT
-    SAD_LOOP
+%macro SAD_FRAMES 1 ; depth
+    SAD_INIT %1
+    SAD_LOOP %1
 %endmacro
 
 
 INIT_XMM sse2
-SAD_FRAMES
+SAD_FRAMES 8
 
 %if HAVE_AVX2_EXTERNAL
 
 INIT_YMM avx2
-SAD_FRAMES
+SAD_FRAMES 8
+SAD_FRAMES 16
 
 %endif
 
 %if HAVE_AVX512_EXTERNAL
 
 INIT_ZMM avx512
-SAD_FRAMES
+SAD_FRAMES 8
+SAD_FRAMES 16
 
 %endif
diff --git a/libavfilter/x86/scene_sad_init.c b/libavfilter/x86/scene_sad_init.c
index 2d631b376a..9863839b4e 100644
--- a/libavfilter/x86/scene_sad_init.c
+++ b/libavfilter/x86/scene_sad_init.c
@@ -36,13 +36,31 @@ static void FUNC_NAME(SCENE_SAD_PARAMS) {                                     \
     *sum += sad[0];                                                           \
 }
 
+#define SCENE_SAD16_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE)                    \
+void ASM_FUNC_NAME(SCENE_SAD_PARAMS);                                         \
+                                                                              \
+static void FUNC_NAME(SCENE_SAD_PARAMS) {                                     \
+    uint64_t sad[MMSIZE / 8] = {0};                                           \
+    ptrdiff_t bytes = (width << 1) & ~(MMSIZE - 1);                           \
+    *sum = 0;                                                                 \
+    ASM_FUNC_NAME(src1, stride1, src2, stride2, bytes, height, sad);          \
+    for (int i = 0; i < MMSIZE / 8; i++)                                      \
+        *sum += sad[i];                                                       \
+    ff_scene_sad16_c(src1 + bytes, stride1,                                   \
+                     src2 + bytes, stride2,                                   \
+                     width - (bytes >> 1), height, sad);                      \
+    *sum += sad[0];                                                           \
+}
+
 #if HAVE_X86ASM
-SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad_sse2, 16)
+SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad8_sse2, 16)
 #if HAVE_AVX2_EXTERNAL
-SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad_avx2, 32)
+SCENE_SAD_FUNC(scene_sad_avx2,     ff_scene_sad8_avx2,  32)
+SCENE_SAD16_FUNC(scene_sad16_avx2, ff_scene_sad16_avx2, 32)
 #endif
 #if HAVE_AVX512_EXTERNAL
-SCENE_SAD_FUNC(scene_sad_avx512, ff_scene_sad_avx512, 64)
+SCENE_SAD_FUNC(scene_sad_avx512,     ff_scene_sad8_avx512,  64)
+SCENE_SAD16_FUNC(scene_sad16_avx512, ff_scene_sad16_avx512, 64)
 #endif
 #endif
 
@@ -61,6 +79,15 @@ ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
 #endif
         if (EXTERNAL_SSE2(cpu_flags))
             return scene_sad_sse2;
+    } else if (depth < 16) { /* this routine is only safe up to 15 bits */
+#if HAVE_AVX512_EXTERNAL
+        if (EXTERNAL_AVX512(cpu_flags))
+            return scene_sad16_avx512;
+#endif
+#if HAVE_AVX2_EXTERNAL
+        if (EXTERNAL_AVX2_FAST(cpu_flags))
+            return scene_sad16_avx2;
+#endif
     }
 #endif
     return NULL;
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-12  9:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-12  9:22 [FFmpeg-devel] [PATCH 1/4] avfilter/scene_sad: pass true depth to ff_scene_sad_get_fn() Niklas Haas
2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 2/4] tests/checkasm: add scene_sad checkasm test Niklas Haas
2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 3/4] avfilter/x86/scene_sad: add AVX512 implementation Niklas Haas
2025-07-12  9:22 ` [FFmpeg-devel] [PATCH 4/4] avfilter/x86/scene_sad: add high bit depth AVX2/AVX512 version Niklas Haas

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git