sbrdsp.c 8.99 KB
Newer Older
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/*
 * 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 "libavcodec/sbrdsp.h"

#include "checkasm.h"

#define randomize(buf, len) do {                                \
    int i;                                                      \
    for (i = 0; i < len; i++) {                                 \
        const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX;          \
        (buf)[i] = f;                                           \
    }                                                           \
} while (0)

#define EPS 0.0001

static void test_sum64x5(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);

    declare_func(void, INTFLOAT *z);

    randomize((INTFLOAT *)dst0, 64 + 256);
    memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
    call_ref(dst0);
    call_new(dst1);
    if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
        fail();
    bench_new(dst1);
}

static void test_sum_square(void)
{
    INTFLOAT res0;
    INTFLOAT res1;
    LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);

55
    declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

    randomize((INTFLOAT *)src, 256 * 2);
    res0 = call_ref(src, 256);
    res1 = call_new(src, 256);
    if (!float_near_abs_eps(res0, res1, EPS))
        fail();
    bench_new(src, 256);
}

static void test_neg_odd_64(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);

    declare_func(void, INTFLOAT *x);

    randomize((INTFLOAT *)dst0, 64);
    memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
    call_ref(dst0);
    call_new(dst1);
    if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
        fail();
    bench_new(dst1);
}

static void test_qmf_pre_shuffle(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);

    declare_func(void, INTFLOAT *z);

    randomize((INTFLOAT *)dst0, 128);
    memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
    call_ref(dst0);
    call_new(dst1);
    if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
        fail();
    bench_new(dst1);
}

static void test_qmf_post_shuffle(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);

    declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);

    randomize((INTFLOAT *)src, 64);
    call_ref(dst0, src);
    call_new(dst1, src);
    if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
        fail();
    bench_new(dst1, src);
}

static void test_qmf_deint_neg(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);

    declare_func(void, INTFLOAT *v, const INTFLOAT *src);

    randomize((INTFLOAT *)src, 64);
    call_ref(dst0, src);
    call_new(dst1, src);
    if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
        fail();
    bench_new(dst1, src);
}

static void test_qmf_deint_bfly(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);

    declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);

    memset(dst0, 0, 128 * sizeof(INTFLOAT));
    memset(dst1, 0, 128 * sizeof(INTFLOAT));

    randomize((INTFLOAT *)src0, 64);
    randomize((INTFLOAT *)src1, 64);
    call_ref(dst0, src0, src1);
    call_new(dst1, src0, src1);
    if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
        fail();
    bench_new(dst1, src0, src1);
}

static void test_autocorrelate(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);

    declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);

    memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
    memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));

    randomize((INTFLOAT *)src, 80);
    call_ref(src, dst0);
    call_new(src, dst1);
    if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
        fail();
    bench_new(src, dst1);
}

static void test_hf_gen(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
    LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
    INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
    int i;

    declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
                       const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
                       INTFLOAT bw, int start, int end);

    randomize((INTFLOAT *)low, 128 * 2);
    randomize((INTFLOAT *)alpha0, 2);
    randomize((INTFLOAT *)alpha1, 2);
    for (i = 2; i < 64; i += 2) {
        memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
        memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
        call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128);
        call_new(dst1, low, alpha0, alpha1, 0.0, i, 128);
        if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
            fail();
        bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
    }
}

static void test_hf_g_filt(void)
{
    LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
    LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);

    declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
                       const INTFLOAT *g_filt, int m_max, intptr_t ixh);

    randomize((INTFLOAT *)high, 128 * 40 * 2);
    randomize((INTFLOAT *)g_filt, 128);

    call_ref(dst0, high, g_filt, 128, 20);
    call_new(dst1, high, g_filt, 128, 20);
    if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
        fail();
    bench_new(dst1, high, g_filt, 128, 20);
}

static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
{
    LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
    LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
    LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
    LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
    int noise = 0x2a;
    int i, j;

    declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
                       const AAC_FLOAT *q_filt, int noise,
                       int kx, int m_max);

    randomize((INTFLOAT *)ref, 128 * 2);
    randomize((INTFLOAT *)s_m, 128);
    randomize((INTFLOAT *)q_filt, 128);

    for (i = 0; i < 4; i++) {
        if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
            for (j = 0; j < 2; j++) {
                memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
                memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
                call_ref(dst0, s_m, q_filt, noise, j, 128);
                call_new(dst1, s_m, q_filt, noise, j, 128);
                if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
                    fail();
                bench_new(dst1, s_m, q_filt, noise, j, 128);
            }
        }
    }
}

void checkasm_check_sbrdsp(void)
{
    SBRDSPContext sbrdsp;

    ff_sbrdsp_init(&sbrdsp);

    if (check_func(sbrdsp.sum64x5, "sum64x5"))
        test_sum64x5();
    report("sum64x5");

    if (check_func(sbrdsp.sum_square, "sum_square"))
        test_sum_square();
    report("sum_square");

    if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
        test_neg_odd_64();
    report("neg_odd_64");

    if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
        test_qmf_pre_shuffle();
    report("qmf_pre_shuffle");

    if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
        test_qmf_post_shuffle();
    report("qmf_post_shuffle");

    if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
        test_qmf_deint_neg();
    report("qmf_deint_neg");

    if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
        test_qmf_deint_bfly();
    report("qmf_deint_bfly");

    if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
        test_autocorrelate();
    report("autocorrelate");

    if (check_func(sbrdsp.hf_gen, "hf_gen"))
        test_hf_gen();
    report("hf_gen");

    if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
        test_hf_g_filt();
    report("hf_g_filt");

    test_hf_apply_noise(&sbrdsp);
    report("hf_apply_noise");
}