cdef.c 5.22 KB
Newer Older
Ronald S. Bultje's avatar
Ronald S. Bultje committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Copyright © 2018, VideoLAN and dav1d authors
 * Copyright © 2018, Two Orioles, LLC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "tests/checkasm/checkasm.h"

#include <string.h>

#include "src/levels.h"
#include "src/cdef.h"

35
static void init_tmp(pixel *buf, int n, const int bitdepth_max) {
36
    while (n--)
37
        *buf++ = rand() & bitdepth_max;
38 39 40 41
}

static void check_cdef_filter(const cdef_fn fn, const int w, const int h,
                              const char *const name)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
42
{
43 44 45 46 47 48 49 50
    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;
    pixel left[8][2];

    declare_func(void, pixel *dst, ptrdiff_t dst_stride, const pixel (*left)[2],
                 pixel *const top[2], int pri_strength, int sec_strength,
51
                 int dir, int damping, enum CdefEdgeFlags edges HIGHBD_DECL_SUFFIX);
52 53 54 55 56 57 58

    if (check_func(fn, "%s_%dbpc", name, BITDEPTH)) {
        for (int dir = 0; dir < 8; dir++) {
            for (enum CdefEdgeFlags edges = 0; edges <= 0xf; edges++) {
                memcpy(a_src, src, (10 * 16 + 8) * sizeof(pixel));
                memcpy(c_src, src, (10 * 16 + 8) * sizeof(pixel));

59 60 61 62 63 64 65 66 67 68
#if BITDEPTH == 16
                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
#else
                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(top, 16 * 2 + 8, bitdepth_max);
                init_tmp((pixel *) left,8 * 2, bitdepth_max);

69
                const int lvl = 1 + (rand() % 62);
70 71
                const int damping = 3 + (rand() & 3) + bitdepth_min_8;
                const int pri_strength = (lvl >> 2) << bitdepth_min_8;
72 73
                int sec_strength = lvl & 3;
                sec_strength += sec_strength == 3;
74
                sec_strength <<= bitdepth_min_8;
75 76
                call_ref(c_src_ptr, 16 * sizeof(pixel), left,
                         (pixel *[2]) { top_ptr, top_ptr + 16 },
77 78
                         pri_strength, sec_strength, dir, damping, edges
                         HIGHBD_TAIL_SUFFIX);
79 80
                call_new(a_src_ptr, 16 * sizeof(pixel), left,
                         (pixel *[2]) { top_ptr, top_ptr + 16 },
81 82
                         pri_strength, sec_strength, dir, damping, edges
                         HIGHBD_TAIL_SUFFIX);
83 84 85
                if (memcmp(a_src, c_src, (10 * 16 + 8) * sizeof(pixel))) fail();
                bench_new(a_src_ptr, 16 * sizeof(pixel), left,
                          (pixel *[2]) { top_ptr, top_ptr + 16 },
86 87
                          pri_strength, sec_strength, dir, damping, edges
                          HIGHBD_TAIL_SUFFIX);
88 89
            }
        }
Ronald S. Bultje's avatar
Ronald S. Bultje committed
90
    }
91
    report(name);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
92 93 94 95 96
}

static void check_cdef_direction(const cdef_dir_fn fn) {
    ALIGN_STK_32(pixel, src, 8 * 8,);

97 98
    declare_func(int, pixel *src, ptrdiff_t dst_stride, unsigned *var
                 HIGHBD_DECL_SUFFIX);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
99 100 101

    if (check_func(fn, "cdef_dir_%dbpc", BITDEPTH)) {
        unsigned c_var, a_var;
102 103 104 105 106 107 108 109 110
#if BITDEPTH == 16
        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
#else
        const int bitdepth_max = 0xff;
#endif
        init_tmp(src, 64, bitdepth_max);

        const int c_dir = call_ref(src, 8 * sizeof(pixel), &c_var HIGHBD_TAIL_SUFFIX);
        const int a_dir = call_new(src, 8 * sizeof(pixel), &a_var HIGHBD_TAIL_SUFFIX);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
111
        if (c_var != a_var || c_dir != a_dir) fail();
112
        bench_new(src, 8 * sizeof(pixel), &a_var HIGHBD_TAIL_SUFFIX);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
113 114 115 116 117 118 119 120 121 122
    }
    report("cdef_dir");
}

void bitfn(checkasm_check_cdef)(void) {
    Dav1dCdefDSPContext c;

    bitfn(dav1d_cdef_dsp_init)(&c);

    check_cdef_direction(c.dir);
123 124 125
    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");
Ronald S. Bultje's avatar
Ronald S. Bultje committed
126
}