LCOV - code coverage report
Current view: top level - src/tests/checkasm - fixed_dsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 86 92 93.5 %
Date: 2017-06-23 19:00:59 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 James Almer
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 2 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
      18             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             :  */
      20             : 
      21             : #include "checkasm.h"
      22             : #include "libavutil/common.h"
      23             : #include "libavutil/fixed_dsp.h"
      24             : #include "libavutil/internal.h"
      25             : #include "libavutil/mem.h"
      26             : 
      27             : #define BUF_SIZE 256
      28             : 
      29             : #define randomize_buffers()                   \
      30             :     do {                                      \
      31             :         int i;                                \
      32             :         for (i = 0; i < BUF_SIZE; i++) {      \
      33             :             src0[i] = sign_extend(rnd(), 24); \
      34             :             src1[i] = sign_extend(rnd(), 24); \
      35             :             src2[i] = sign_extend(rnd(), 24); \
      36             :         }                                     \
      37             :     } while (0)
      38             : 
      39           2 : static void check_vector_fmul(const int *src0, const int *src1)
      40             : {
      41           2 :     LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
      42           2 :     LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
      43             : 
      44           2 :     declare_func(void, int *dst, const int *src0, const int *src1, int len);
      45             : 
      46           2 :     call_ref(ref, src0, src1, BUF_SIZE);
      47           2 :     call_new(new, src0, src1, BUF_SIZE);
      48           2 :     if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
      49           0 :         fail();
      50           2 :     bench_new(new, src0, src1, BUF_SIZE);
      51           2 : }
      52             : 
      53           1 : static void check_vector_fmul_add(const int *src0, const int *src1, const int *src2)
      54             : {
      55           1 :     LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
      56           1 :     LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
      57             : 
      58           1 :     declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len);
      59             : 
      60           1 :     call_ref(ref, src0, src1, src2, BUF_SIZE);
      61           1 :     call_new(new, src0, src1, src2, BUF_SIZE);
      62           1 :     if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
      63           0 :         fail();
      64           1 :     bench_new(new, src0, src1, src2, BUF_SIZE);
      65           1 : }
      66             : 
      67           1 : static void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win)
      68             : {
      69           1 :     LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]);
      70           1 :     LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]);
      71             : 
      72           1 :     declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len);
      73             : 
      74           1 :     call_ref(ref, src0, src1, win, BUF_SIZE / 2);
      75           1 :     call_new(new, src0, src1, win, BUF_SIZE / 2);
      76           1 :     if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t)))
      77           0 :         fail();
      78           1 :     bench_new(new, src0, src1, win, BUF_SIZE / 2);
      79           1 : }
      80             : 
      81           1 : static void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win)
      82             : {
      83           1 :     LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]);
      84           1 :     LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]);
      85             : 
      86           1 :     declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits);
      87             : 
      88           1 :     call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2);
      89           1 :     call_new(new, src0, src1, win, BUF_SIZE / 2, 2);
      90           1 :     if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t)))
      91           0 :         fail();
      92           1 :     bench_new(new, src0, src1, win, BUF_SIZE / 2, 2);
      93           1 : }
      94             : 
      95           2 : static void check_butterflies(const int *src0, const int *src1)
      96             : {
      97           2 :     LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]);
      98           2 :     LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]);
      99           2 :     LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]);
     100           2 :     LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]);
     101             : 
     102           2 :     declare_func(void, int *av_restrict src0, int *av_restrict src1, int len);
     103             : 
     104           2 :     memcpy(ref0, src0, BUF_SIZE * sizeof(*src0));
     105           2 :     memcpy(ref1, src1, BUF_SIZE * sizeof(*src1));
     106           2 :     memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
     107           2 :     memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
     108             : 
     109           2 :     call_ref(ref0, ref1, BUF_SIZE);
     110           2 :     call_new(new0, new1, BUF_SIZE);
     111           4 :     if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) ||
     112           2 :         memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1)))
     113           0 :         fail();
     114           2 :     memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
     115           2 :     memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
     116           2 :     bench_new(new0, new1, BUF_SIZE);
     117           2 : }
     118             : 
     119           1 : static void check_scalarproduct_fixed(const int *src0, const int *src1)
     120             : {
     121             :     int ref, new;
     122             : 
     123           1 :     declare_func(int, const int *src0, const int *src1, int len);
     124             : 
     125           1 :     ref = call_ref(src0, src1, BUF_SIZE);
     126           1 :     new = call_new(src0, src1, BUF_SIZE);
     127           1 :     if (ref != new)
     128           0 :         fail();
     129           1 :     bench_new(src0, src1, BUF_SIZE);
     130           1 : }
     131             : 
     132          13 : void checkasm_check_fixed_dsp(void)
     133             : {
     134          13 :     LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]);
     135          13 :     LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]);
     136          13 :     LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]);
     137          13 :     AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1);
     138             : 
     139          13 :     randomize_buffers();
     140          13 :     if (check_func(fdsp->vector_fmul, "vector_fmul_fixed"))
     141           1 :         check_vector_fmul(src0, src1);
     142          13 :     if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed"))
     143           1 :         check_vector_fmul_add(src0, src1, src2);
     144          13 :     if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed"))
     145           1 :         check_vector_fmul(src0, src1);
     146          13 :     if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed"))
     147           1 :         check_vector_fmul_window(src0, src1, src2);
     148          13 :     if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed"))
     149           1 :         check_vector_fmul_window_scaled(src0, src1, src2);
     150          13 :     report("vector_fmul");
     151          13 :     if (check_func(fdsp->butterflies_fixed, "butterflies_fixed"))
     152           2 :         check_butterflies(src0, src1);
     153          13 :     report("butterflies_fixed");
     154          13 :     if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed"))
     155           1 :         check_scalarproduct_fixed(src0, src1);
     156          13 :     report("scalarproduct_fixed");
     157             : 
     158          13 :     av_freep(&fdsp);
     159          13 : }

Generated by: LCOV version 1.13