Commit 7087649421 for ffmpeg

commit 7087649421e28d3dc799569dc13b602e1394dad2
Author: Marcos Ashton Iglesias <marcosashiglesias@gmail.com>
Date:   Thu Sep 24 19:22:55 2026 +0100

    tests/checkasm/hevc_idct: test sparse blocks with a real col_limit

    Only col_limit == block size was tested. Fill blocks like the decoder
    does for every last significant position, derive col_limit as in
    cabac.c, and also compare against C with the full block size. Bench
    col_limit 8, the most common value.

diff --git a/tests/checkasm/hevc_idct.c b/tests/checkasm/hevc_idct.c
index 139ae81727..05389064ab 100644
--- a/tests/checkasm/hevc_idct.c
+++ b/tests/checkasm/hevc_idct.c
@@ -20,6 +20,7 @@

 #include <string.h>

+#include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem_internal.h"

@@ -36,11 +37,50 @@
         }                                       \
     } while (0)

+/* Fill groups and coefficients in up-right diagonal order up to scan position
+ * last, like the decoder. Returns col_limit as hevc/cabac.c derives it. */
+static int fill_sparse(int16_t *coeffs, int log2_size, int last)
+{
+    int size = 1 << log2_size, ncg = size >> 2;
+    int n = 0, last_x = 0, last_y = 0, max_xy, col_limit;
+
+    memset(coeffs, 0, sizeof(*coeffs) * size * size);
+    for (int d = 0; d < 2 * ncg - 1; d++) {
+        for (int x_cg = FFMAX(0, d - ncg + 1); x_cg <= FFMIN(d, ncg - 1); x_cg++) {
+            for (int e = 0; e < 7; e++) {
+                for (int x_c = FFMAX(0, e - 3); x_c <= FFMIN(e, 3); x_c++) {
+                    int x = 4 * x_cg + x_c;
+                    int y = 4 * (d - x_cg) + e - x_c;
+
+                    if (n > last)
+                        goto done;
+                    coeffs[y * size + x] = n == last ? (rnd() | 1) :
+                                           rnd() & 1 ? rnd() : 0;
+                    last_x = x;
+                    last_y = y;
+                    n++;
+                }
+            }
+        }
+    }
+done:
+    max_xy    = FFMAX(last_x, last_y);
+    col_limit = last_x + last_y + 4;
+    if (max_xy < 4)
+        col_limit = FFMIN(4, col_limit);
+    else if (max_xy < 8)
+        col_limit = FFMIN(8, col_limit);
+    else if (max_xy < 12)
+        col_limit = FFMIN(24, col_limit);
+    return col_limit;
+}
+
 static void check_idct(HEVCDSPContext *h, int bit_depth)
 {
     int i;
     LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
     LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
+    LOCAL_ALIGNED(32, int16_t, coeffs2, [32 * 32]);

     for (i = 2; i <= 5; i++) {
         int block_size = 1 << i;
@@ -57,6 +97,30 @@ static void check_idct(HEVCDSPContext *h, int bit_depth)
                 fail();
             bench_new(coeffs1, col_limit);
         }
+
+        if (check_func(h->idct[i - 2], "hevc_idct_%dx%d_%d_sparse", block_size, block_size, bit_depth)) {
+            int last, limit;
+
+            for (last = 0; last < size; last++) {
+                limit = fill_sparse(coeffs0, i, last);
+                memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
+                memcpy(coeffs2, coeffs0, sizeof(*coeffs0) * size);
+                call_ref(coeffs0, limit);
+                call_new(coeffs1, limit);
+                /* limit must not change the C result */
+                call_ref(coeffs2, block_size);
+                if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size) ||
+                    memcmp(coeffs0, coeffs2, sizeof(*coeffs0) * size)) {
+                    fail();
+                    break;
+                }
+            }
+            /* bench col_limit 8 */
+            for (last = 0; last < size; last++)
+                if ((limit = fill_sparse(coeffs1, i, last)) >= FFMIN(8, block_size))
+                    break;
+            bench_new(coeffs1, limit);
+        }
     }
 }