LCOV - code coverage report
Current view: top level - tests/checkasm - sbrdsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 180 191 94.2 %
Date: 2017-10-18 21:45:51 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation; either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License along
      15             :  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "libavcodec/sbrdsp.h"
      20             : 
      21             : #include "checkasm.h"
      22             : 
      23             : #define randomize(buf, len) do {                                \
      24             :     int i;                                                      \
      25             :     for (i = 0; i < len; i++) {                                 \
      26             :         const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX;          \
      27             :         (buf)[i] = f;                                           \
      28             :     }                                                           \
      29             : } while (0)
      30             : 
      31             : #define EPS 0.0001
      32             : 
      33           2 : static void test_sum64x5(void)
      34             : {
      35           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
      36           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
      37             : 
      38           2 :     declare_func(void, INTFLOAT *z);
      39             : 
      40           2 :     randomize((INTFLOAT *)dst0, 64 + 256);
      41           2 :     memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
      42           2 :     call_ref(dst0);
      43           2 :     call_new(dst1);
      44           2 :     if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
      45           0 :         fail();
      46           2 :     bench_new(dst1);
      47           2 : }
      48             : 
      49           2 : static void test_sum_square(void)
      50             : {
      51             :     INTFLOAT res0;
      52             :     INTFLOAT res1;
      53           2 :     LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
      54             : 
      55           2 :     declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
      56             : 
      57           2 :     randomize((INTFLOAT *)src, 256 * 2);
      58           2 :     res0 = call_ref(src, 256);
      59           2 :     res1 = call_new(src, 256);
      60           2 :     if (!float_near_abs_eps(res0, res1, EPS))
      61           0 :         fail();
      62           2 :     bench_new(src, 256);
      63           2 : }
      64             : 
      65           2 : static void test_neg_odd_64(void)
      66             : {
      67           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
      68           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
      69             : 
      70           2 :     declare_func(void, INTFLOAT *x);
      71             : 
      72           2 :     randomize((INTFLOAT *)dst0, 64);
      73           2 :     memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
      74           2 :     call_ref(dst0);
      75           2 :     call_new(dst1);
      76           2 :     if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
      77           0 :         fail();
      78           2 :     bench_new(dst1);
      79           2 : }
      80             : 
      81           2 : static void test_qmf_pre_shuffle(void)
      82             : {
      83           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
      84           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
      85             : 
      86           2 :     declare_func(void, INTFLOAT *z);
      87             : 
      88           2 :     randomize((INTFLOAT *)dst0, 128);
      89           2 :     memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
      90           2 :     call_ref(dst0);
      91           2 :     call_new(dst1);
      92           2 :     if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
      93           0 :         fail();
      94           2 :     bench_new(dst1);
      95           2 : }
      96             : 
      97           2 : static void test_qmf_post_shuffle(void)
      98             : {
      99           2 :     LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
     100           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
     101           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
     102             : 
     103           2 :     declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
     104             : 
     105           2 :     randomize((INTFLOAT *)src, 64);
     106           2 :     call_ref(dst0, src);
     107           2 :     call_new(dst1, src);
     108           2 :     if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
     109           0 :         fail();
     110           2 :     bench_new(dst1, src);
     111           2 : }
     112             : 
     113           2 : static void test_qmf_deint_neg(void)
     114             : {
     115           2 :     LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
     116           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
     117           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
     118             : 
     119           2 :     declare_func(void, INTFLOAT *v, const INTFLOAT *src);
     120             : 
     121           2 :     randomize((INTFLOAT *)src, 64);
     122           2 :     call_ref(dst0, src);
     123           2 :     call_new(dst1, src);
     124           2 :     if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
     125           0 :         fail();
     126           2 :     bench_new(dst1, src);
     127           2 : }
     128             : 
     129           3 : static void test_qmf_deint_bfly(void)
     130             : {
     131           3 :     LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
     132           3 :     LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
     133           3 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
     134           3 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
     135             : 
     136           3 :     declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
     137             : 
     138           3 :     memset(dst0, 0, 128 * sizeof(INTFLOAT));
     139           3 :     memset(dst1, 0, 128 * sizeof(INTFLOAT));
     140             : 
     141           3 :     randomize((INTFLOAT *)src0, 64);
     142           3 :     randomize((INTFLOAT *)src1, 64);
     143           3 :     call_ref(dst0, src0, src1);
     144           3 :     call_new(dst1, src0, src1);
     145           3 :     if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
     146           0 :         fail();
     147           3 :     bench_new(dst1, src0, src1);
     148           3 : }
     149             : 
     150           3 : static void test_autocorrelate(void)
     151             : {
     152           3 :     LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
     153           3 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
     154           3 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
     155             : 
     156           3 :     declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
     157             : 
     158           3 :     memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
     159           3 :     memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
     160             : 
     161           3 :     randomize((INTFLOAT *)src, 80);
     162           3 :     call_ref(src, dst0);
     163           3 :     call_new(src, dst1);
     164           3 :     if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
     165           0 :         fail();
     166           3 :     bench_new(src, dst1);
     167           3 : }
     168             : 
     169           2 : static void test_hf_gen(void)
     170             : {
     171           2 :     LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
     172           2 :     LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
     173           2 :     LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
     174           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
     175           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
     176           2 :     INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
     177             :     int i;
     178             : 
     179           2 :     declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
     180             :                        const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
     181             :                        INTFLOAT bw, int start, int end);
     182             : 
     183           2 :     randomize((INTFLOAT *)low, 128 * 2);
     184           2 :     randomize((INTFLOAT *)alpha0, 2);
     185           2 :     randomize((INTFLOAT *)alpha1, 2);
     186          64 :     for (i = 2; i < 64; i += 2) {
     187          62 :         memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
     188          62 :         memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
     189          62 :         call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128);
     190          62 :         call_new(dst1, low, alpha0, alpha1, 0.0, i, 128);
     191          62 :         if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
     192           0 :             fail();
     193          62 :         bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
     194             :     }
     195           2 : }
     196             : 
     197           2 : static void test_hf_g_filt(void)
     198             : {
     199           2 :     LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
     200           2 :     LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
     201           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
     202           2 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
     203             : 
     204           2 :     declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
     205             :                        const INTFLOAT *g_filt, int m_max, intptr_t ixh);
     206             : 
     207           2 :     randomize((INTFLOAT *)high, 128 * 40 * 2);
     208           2 :     randomize((INTFLOAT *)g_filt, 128);
     209             : 
     210           2 :     call_ref(dst0, high, g_filt, 128, 20);
     211           2 :     call_new(dst1, high, g_filt, 128, 20);
     212           2 :     if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
     213           0 :         fail();
     214           2 :     bench_new(dst1, high, g_filt, 128, 20);
     215           2 : }
     216             : 
     217          13 : static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
     218             : {
     219          13 :     LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
     220          13 :     LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
     221          13 :     LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
     222          13 :     LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
     223          13 :     LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
     224          13 :     int noise = 0x2a;
     225             :     int i, j;
     226             : 
     227          13 :     declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
     228             :                        const AAC_FLOAT *q_filt, int noise,
     229             :                        int kx, int m_max);
     230             : 
     231          13 :     randomize((INTFLOAT *)ref, 128 * 2);
     232          13 :     randomize((INTFLOAT *)s_m, 128);
     233          13 :     randomize((INTFLOAT *)q_filt, 128);
     234             : 
     235          65 :     for (i = 0; i < 4; i++) {
     236          52 :         if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
     237          24 :             for (j = 0; j < 2; j++) {
     238          16 :                 memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
     239          16 :                 memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
     240          16 :                 call_ref(dst0, s_m, q_filt, noise, j, 128);
     241          16 :                 call_new(dst1, s_m, q_filt, noise, j, 128);
     242          16 :                 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
     243           0 :                     fail();
     244          16 :                 bench_new(dst1, s_m, q_filt, noise, j, 128);
     245             :             }
     246             :         }
     247             :     }
     248          13 : }
     249             : 
     250          13 : void checkasm_check_sbrdsp(void)
     251             : {
     252             :     SBRDSPContext sbrdsp;
     253             : 
     254          13 :     ff_sbrdsp_init(&sbrdsp);
     255             : 
     256          13 :     if (check_func(sbrdsp.sum64x5, "sum64x5"))
     257           2 :         test_sum64x5();
     258          13 :     report("sum64x5");
     259             : 
     260          13 :     if (check_func(sbrdsp.sum_square, "sum_square"))
     261           2 :         test_sum_square();
     262          13 :     report("sum_square");
     263             : 
     264          13 :     if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
     265           2 :         test_neg_odd_64();
     266          13 :     report("neg_odd_64");
     267             : 
     268          13 :     if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
     269           2 :         test_qmf_pre_shuffle();
     270          13 :     report("qmf_pre_shuffle");
     271             : 
     272          13 :     if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
     273           2 :         test_qmf_post_shuffle();
     274          13 :     report("qmf_post_shuffle");
     275             : 
     276          13 :     if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
     277           2 :         test_qmf_deint_neg();
     278          13 :     report("qmf_deint_neg");
     279             : 
     280          13 :     if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
     281           3 :         test_qmf_deint_bfly();
     282          13 :     report("qmf_deint_bfly");
     283             : 
     284          13 :     if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
     285           3 :         test_autocorrelate();
     286          13 :     report("autocorrelate");
     287             : 
     288          13 :     if (check_func(sbrdsp.hf_gen, "hf_gen"))
     289           2 :         test_hf_gen();
     290          13 :     report("hf_gen");
     291             : 
     292          13 :     if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
     293           2 :         test_hf_g_filt();
     294          13 :     report("hf_g_filt");
     295             : 
     296          13 :     test_hf_apply_noise(&sbrdsp);
     297          13 :     report("hf_apply_noise");
     298          13 : }

Generated by: LCOV version 1.13