Commit 1d08d999c7 for ffmpeg

commit 1d08d999c7ed5083507a6471d483002cd0facfa0
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date:   Tue Nov 17 15:18:44 2026 -0800

    avfilter/x86/scene_sad: skip the SIMD loop for rows narrower than a vector

    The loop runs at least once, so a zero width or height counted one vector
    that the C tail then counted again.

    Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>

diff --git a/libavfilter/x86/scene_sad_init.c b/libavfilter/x86/scene_sad_init.c
index a35f02c560..169a93d8b3 100644
--- a/libavfilter/x86/scene_sad_init.c
+++ b/libavfilter/x86/scene_sad_init.c
@@ -27,7 +27,8 @@ static void FUNC_NAME(SCENE_SAD_PARAMS) {                                     \
     uint64_t sad[MMSIZE / 8] = {0};                                           \
     ptrdiff_t awidth = width & ~(MMSIZE - 1);                                 \
     *sum = 0;                                                                 \
-    ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad);         \
+    if (awidth && height > 0)                                                 \
+        ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad);     \
     for (int i = 0; i < MMSIZE / 8; i++)                                      \
         *sum += sad[i];                                                       \
     ff_scene_sad_c(src1 + awidth, stride1,                                    \
@@ -43,7 +44,8 @@ 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);          \
+    if (bytes && height > 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,                                   \
diff --git a/tests/checkasm/scene_sad.c b/tests/checkasm/scene_sad.c
index c67f2fb103..1f534d480c 100644
--- a/tests/checkasm/scene_sad.c
+++ b/tests/checkasm/scene_sad.c
@@ -51,13 +51,24 @@ static void check_scene_sad(int depth)
     }

     if (check_func(ff_scene_sad_get_fn(depth), "scene_sad%d", depth)) {
+        /* include rows narrower than and around each vector width */
+        const int widths[] = { 1, 7, 8, 15, 16, 17, 31, 32, 33, 63, 64, 65, width };
+        const int heights[] = { 0, 1, HEIGHT };
         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();
+
+        for (int w = 0; w < FF_ARRAY_ELEMS(widths); w++) {
+            for (int h = 0; h < FF_ARRAY_ELEMS(heights); h++) {
+                if (widths[w] > width)
+                    continue;
+                call_ref(src1, STRIDE, src2, STRIDE, widths[w], heights[h], &sum1);
+                call_new(src1, STRIDE, src2, STRIDE, widths[w], heights[h], &sum2);
+                if (sum1 != sum2) {
+                    fprintf(stderr, "scene_sad%d: sum mismatch for %dx%d: %llu != %llu\n",
+                            depth, widths[w], heights[h],
+                            (unsigned long long) sum1, (unsigned long long) sum2);
+                    fail();
+                }
+            }
         }
         if (depth == 8) {
             for (int offset1 = 0; offset1 < 16; offset1++) {