ref: fad6db2053b69b3dff9d1f9bd9ee68a7a2080dc2
parent: 6385cde2d09be5f63fd6685265f1476af078c750
author: Henrik Gramner <gramner@twoorioles.com>
date: Mon Jan 27 12:41:54 EST 2020
checkasm: Improve cdef_filter test
--- a/tests/checkasm/cdef.c
+++ b/tests/checkasm/cdef.c
@@ -35,27 +35,30 @@
#include "src/levels.h"
#include "src/cdef.h"
+static int to_binary(int x) { /* 0-15 -> 0000-1111 */
+ return (x & 1) + 5 * (x & 2) + 25 * (x & 4) + 125 * (x & 8);
+}
+
static void init_tmp(pixel *buf, int n, const int bitdepth_max) {
while (n--)
*buf++ = rnd() & bitdepth_max;
}
-static void check_cdef_filter(const cdef_fn fn, const int w, const int h,
- const char *const name)
-{
- ALIGN_STK_32(pixel, src, 10 * 16 + 8, );
- ALIGN_STK_32(pixel, c_src, 10 * 16 + 8, ), *const c_src_ptr = c_src + 8;
- ALIGN_STK_32(pixel, a_src, 10 * 16 + 8, ), *const a_src_ptr = a_src + 8;
- ALIGN_STK_32(pixel, top, 16 * 2 + 8, ), *const top_ptr = top + 8;
+static void check_cdef_filter(const cdef_fn fn, const int w, const int h) {
+ ALIGN_STK_32(pixel, c_src, 10 * 16 + 8, ), *const c_dst = c_src + 8;
+ ALIGN_STK_32(pixel, a_src, 10 * 16 + 8, ), *const a_dst = a_src + 8;
+ ALIGN_STK_32(pixel, top, 16 * 2 + 8, );
pixel left[8][2];
+ pixel *const top_ptrs[2] = { top + 8, top + 24 };
+ const ptrdiff_t stride = 16 * sizeof(pixel);
declare_func(void, pixel *dst, ptrdiff_t dst_stride, const pixel (*left)[2],
pixel *const top[2], int pri_strength, int sec_strength,
int dir, int damping, enum CdefEdgeFlags edges HIGHBD_DECL_SUFFIX);
- if (check_func(fn, "%s_%dbpc", name, BITDEPTH)) {
+ if (check_func(fn, "cdef_filter_%dx%d_%dbpc", w, h, BITDEPTH)) {
for (int dir = 0; dir < 8; dir++) {
- for (enum CdefEdgeFlags edges = 0; edges <= 0xf; edges++) {
+ for (enum CdefEdgeFlags edges = 0x0; edges <= 0xf; edges++) {
#if BITDEPTH == 16
const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
#else
@@ -62,41 +65,41 @@
const int bitdepth_max = 0xff;
#endif
const int bitdepth_min_8 = bitdepth_from_max(bitdepth_max) - 8;
- init_tmp(src, 10 * 16 + 8, bitdepth_max);
+
+ init_tmp(c_src, 10 * 16 + 8, bitdepth_max);
init_tmp(top, 16 * 2 + 8, bitdepth_max);
- init_tmp((pixel *) left,8 * 2, bitdepth_max);
+ init_tmp((pixel *) left, 8 * 2, bitdepth_max);
+ memcpy(a_src, c_src, (10 * 16 + 8) * sizeof(pixel));
- memcpy(a_src, src, (10 * 16 + 8) * sizeof(pixel));
- memcpy(c_src, src, (10 * 16 + 8) * sizeof(pixel));
-
const int lvl = 1 + (rnd() % 62);
const int damping = 3 + (rnd() & 3) + bitdepth_min_8 - (w == 4 || (rnd() & 1));
- const int pri_strength = (lvl >> 2) << bitdepth_min_8;
+ int pri_strength = (lvl >> 2) << bitdepth_min_8;
int sec_strength = lvl & 3;
sec_strength += sec_strength == 3;
sec_strength <<= bitdepth_min_8;
- call_ref(c_src_ptr, 16 * sizeof(pixel), left,
- (pixel *[2]) { top_ptr, top_ptr + 16 },
- pri_strength, sec_strength, dir, damping, edges
- HIGHBD_TAIL_SUFFIX);
- call_new(a_src_ptr, 16 * sizeof(pixel), left,
- (pixel *[2]) { top_ptr, top_ptr + 16 },
- pri_strength, sec_strength, dir, damping, edges
- HIGHBD_TAIL_SUFFIX);
- checkasm_check_pixel(c_src, 16 * sizeof(pixel),
- a_src, 16 * sizeof(pixel),
- 16, 10, "src");
- checkasm_check_pixel(c_src + 16 * 10, 16 * sizeof(pixel),
- a_src + 16 * 10, 16 * sizeof(pixel),
- 8, 1, "src last row");
- bench_new(a_src_ptr, 16 * sizeof(pixel), left,
- (pixel *[2]) { top_ptr, top_ptr + 16 },
- pri_strength, sec_strength, dir, damping, edges
- HIGHBD_TAIL_SUFFIX);
+ call_ref(c_dst, stride, left, top_ptrs, pri_strength, sec_strength,
+ dir, damping, edges HIGHBD_TAIL_SUFFIX);
+ call_new(a_dst, stride, left, top_ptrs, pri_strength, sec_strength,
+ dir, damping, edges HIGHBD_TAIL_SUFFIX);
+ if (checkasm_check_pixel(c_dst, stride, a_dst, stride, w, h, "dst")) {
+ fprintf(stderr, "strength = %d:%d, dir = %d, damping = %d, edges = %04d\n",
+ pri_strength, sec_strength, dir, damping, to_binary(edges));
+ return;
+ }
+ if (dir == 7 && (edges == 0x5 || edges == 0xa || edges == 0xf)) {
+ /* Benchmark a fixed set of cases to get consistent results:
+ * 1) top/left edges and pri_strength only
+ * 2) bottom/right edges and sec_strength only
+ * 3) all edges and both pri_strength and sec_strength
+ */
+ pri_strength = (edges & 1) << bitdepth_min_8;
+ sec_strength = edges & 2;
+ bench_new(a_dst, stride, left, top_ptrs, pri_strength, sec_strength,
+ dir, damping, edges HIGHBD_TAIL_SUFFIX);
+ }
}
}
}
- report(name);
}
static void check_cdef_direction(const cdef_dir_fn fn) {
@@ -129,11 +132,12 @@
void bitfn(checkasm_check_cdef)(void) {
Dav1dCdefDSPContext c;
-
bitfn(dav1d_cdef_dsp_init)(&c);
check_cdef_direction(c.dir);
- check_cdef_filter(c.fb[0], 8, 8, "cdef_filter_8x8");
- check_cdef_filter(c.fb[1], 4, 8, "cdef_filter_4x8");
- check_cdef_filter(c.fb[2], 4, 4, "cdef_filter_4x4");
+
+ check_cdef_filter(c.fb[0], 8, 8);
+ check_cdef_filter(c.fb[1], 4, 8);
+ check_cdef_filter(c.fb[2], 4, 4);
+ report("cdef_filter");
}