LCOV - code coverage report
Current view: top level - tests/checkasm - audiodsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 54 57 94.7 %
Date: 2017-12-16 01:21:47 Functions: 1 1 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 <math.h>
      20             : #include <string.h>
      21             : #include <stdio.h>
      22             : #include <stdlib.h>
      23             : 
      24             : #include "libavcodec/audiodsp.h"
      25             : 
      26             : #include "libavutil/common.h"
      27             : #include "libavutil/intreadwrite.h"
      28             : 
      29             : #include "checkasm.h"
      30             : 
      31             : #define MAX_SIZE (32 * 128)
      32             : 
      33             : #define randomize_float(buf, len)                               \
      34             :     do {                                                        \
      35             :         int i;                                                  \
      36             :         for (i = 0; i < len; i++) {                             \
      37             :             float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f;   \
      38             :             buf[i] = f;                                         \
      39             :         }                                                       \
      40             :     } while (0)
      41             : 
      42             : #define randomize_int(buf, len, size, bits)                         \
      43             :     do {                                                            \
      44             :         int i;                                                      \
      45             :         for (i = 0; i < len; i++) {                                 \
      46             :             uint ## size ## _t r = rnd() & ((1LL << bits) - 1);     \
      47             :             AV_WN ## size ## A(buf + i, -(1LL << (bits - 1)) + r);  \
      48             :         }                                                           \
      49             :     } while (0)
      50             : 
      51          13 : void checkasm_check_audiodsp(void)
      52             : {
      53             :     AudioDSPContext adsp;
      54             : 
      55          13 :     ff_audiodsp_init(&adsp);
      56             : 
      57          13 :     if (check_func(adsp.scalarproduct_int16, "audiodsp.scalarproduct_int16")) {
      58           3 :         LOCAL_ALIGNED(32, int16_t, v1, [MAX_SIZE]);
      59           3 :         LOCAL_ALIGNED(32, int16_t, v2, [MAX_SIZE]);
      60             :         unsigned int len_bits_minus4, v1_bits, v2_bits, len;
      61             :         int32_t res0, res1;
      62             : 
      63           3 :         declare_func_emms(AV_CPU_FLAG_MMX, int32_t, const int16_t *v1, const int16_t *v2, int len);
      64             : 
      65             :         // generate random 5-12bit vector length
      66           3 :         len_bits_minus4 = rnd() % 8;
      67           3 :         len = rnd() & ((1 << len_bits_minus4) - 1);
      68           3 :         len = 16 * FFMAX(len, 1);
      69             : 
      70             :         // generate the bit counts for each of the vectors such that the result
      71             :         // fits into int32
      72           3 :         v1_bits = 1 + rnd() % 15;
      73           3 :         v2_bits = FFMIN(32 - (len_bits_minus4 + 4) - v1_bits - 1, 15);
      74             : 
      75           3 :         randomize_int(v1, MAX_SIZE, 16, v1_bits + 1);
      76           3 :         randomize_int(v2, MAX_SIZE, 16, v2_bits + 1);
      77             : 
      78           3 :         res0 = call_ref(v1, v2, len);
      79           3 :         res1 = call_new(v1, v2, len);
      80           3 :         if (res0 != res1)
      81           0 :             fail();
      82           3 :         bench_new(v1, v2, MAX_SIZE);
      83             :     }
      84             : 
      85          13 :     if (check_func(adsp.vector_clip_int32, "audiodsp.vector_clip_int32")) {
      86           4 :         LOCAL_ALIGNED(32, int32_t, src,  [MAX_SIZE]);
      87           4 :         LOCAL_ALIGNED(32, int32_t, dst0, [MAX_SIZE]);
      88           4 :         LOCAL_ALIGNED(32, int32_t, dst1, [MAX_SIZE]);
      89             :         int32_t val1, val2, min, max;
      90             :         int len;
      91             : 
      92           4 :         declare_func_emms(AV_CPU_FLAG_MMX, void, int32_t *dst, const int32_t *src,
      93             :                           int32_t min, int32_t max, unsigned int len);
      94             : 
      95           4 :         val1 = ((int32_t)rnd());
      96           4 :         val1 = FFSIGN(val1) * (val1 & ((1 << 24) - 1));
      97           4 :         val2 = ((int32_t)rnd());
      98           4 :         val2 = FFSIGN(val2) * (val2 & ((1 << 24) - 1));
      99             : 
     100           4 :         min = FFMIN(val1, val2);
     101           4 :         max = FFMAX(val1, val2);
     102             : 
     103           4 :         randomize_int(src, MAX_SIZE, 32, 32);
     104             : 
     105           4 :         len = rnd() % 128;
     106           4 :         len = 32 * FFMAX(len, 1);
     107             : 
     108           4 :         call_ref(dst0, src, min, max, len);
     109           4 :         call_new(dst1, src, min, max, len);
     110           4 :         if (memcmp(dst0, dst1, len * sizeof(*dst0)))
     111           0 :             fail();
     112           4 :         bench_new(dst1, src, min, max, MAX_SIZE);
     113             :     }
     114             : 
     115          13 :     if (check_func(adsp.vector_clipf, "audiodsp.vector_clipf")) {
     116           2 :         LOCAL_ALIGNED(32, float, src, [MAX_SIZE]);
     117           2 :         LOCAL_ALIGNED(32, float, dst0, [MAX_SIZE]);
     118           2 :         LOCAL_ALIGNED(32, float, dst1, [MAX_SIZE]);
     119             :         float val1, val2, min, max;
     120             :         int i, len;
     121             : 
     122           2 :         declare_func_emms(AV_CPU_FLAG_MMX, void, float *dst, const float *src,
     123             :                           int len, float min, float max);
     124             : 
     125           2 :         val1 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
     126           2 :         val2 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
     127             : 
     128           2 :         min = FFMIN(val1, val2);
     129           2 :         max = FFMAX(val1, val2);
     130             : 
     131           2 :         randomize_float(src, MAX_SIZE);
     132             : 
     133           2 :         len = rnd() % 128;
     134           2 :         len = 16 * FFMAX(len, 1);
     135             : 
     136           2 :         call_ref(dst0, src, len, min, max);
     137           2 :         call_new(dst1, src, len, min, max);
     138        1682 :         for (i = 0; i < len; i++) {
     139        1680 :             if (!float_near_ulp_array(dst0, dst1, 3, len))
     140           0 :                 fail();
     141             :         }
     142           2 :         bench_new(dst1, src, MAX_SIZE, min, max);
     143             :     }
     144             : 
     145          13 :     report("audiodsp");
     146          13 : }

Generated by: LCOV version 1.13