LCOV - code coverage report
Current view: top level - tests/checkasm - vp9dsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 244 251 97.2 %
Date: 2017-10-18 21:45:51 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
       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 <math.h>
      22             : #include <string.h>
      23             : #include "checkasm.h"
      24             : #include "libavcodec/vp9data.h"
      25             : #include "libavcodec/vp9.h"
      26             : #include "libavutil/common.h"
      27             : #include "libavutil/internal.h"
      28             : #include "libavutil/intreadwrite.h"
      29             : #include "libavutil/mathematics.h"
      30             : 
      31             : static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
      32             : #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
      33             : 
      34             : #define randomize_buffers()                                        \
      35             :     do {                                                           \
      36             :         uint32_t mask = pixel_mask[(bit_depth - 8) >> 1];          \
      37             :         int k;                                                     \
      38             :         for (k = -4;  k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
      39             :             uint32_t r = rnd() & mask;                             \
      40             :             AV_WN32A(a + k, r);                                    \
      41             :         }                                                          \
      42             :         for (k = 0; k < size * SIZEOF_PIXEL; k += 4) {             \
      43             :             uint32_t r = rnd() & mask;                             \
      44             :             AV_WN32A(l + k, r);                                    \
      45             :         }                                                          \
      46             :     } while (0)
      47             : 
      48          13 : static void check_ipred(void)
      49             : {
      50          13 :     LOCAL_ALIGNED_32(uint8_t, a_buf, [64 * 2]);
      51          13 :     uint8_t *a = &a_buf[32 * 2];
      52          13 :     LOCAL_ALIGNED_32(uint8_t, l, [32 * 2]);
      53          13 :     LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
      54          13 :     LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
      55             :     VP9DSPContext dsp;
      56             :     int tx, mode, bit_depth;
      57          13 :     declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride,
      58             :                       const uint8_t *left, const uint8_t *top);
      59             :     static const char *const mode_names[N_INTRA_PRED_MODES] = {
      60             :         [VERT_PRED] = "vert",
      61             :         [HOR_PRED] = "hor",
      62             :         [DC_PRED] = "dc",
      63             :         [DIAG_DOWN_LEFT_PRED] = "diag_downleft",
      64             :         [DIAG_DOWN_RIGHT_PRED] = "diag_downright",
      65             :         [VERT_RIGHT_PRED] = "vert_right",
      66             :         [HOR_DOWN_PRED] = "hor_down",
      67             :         [VERT_LEFT_PRED] = "vert_left",
      68             :         [HOR_UP_PRED] = "hor_up",
      69             :         [TM_VP8_PRED] = "tm",
      70             :         [LEFT_DC_PRED] = "dc_left",
      71             :         [TOP_DC_PRED] = "dc_top",
      72             :         [DC_128_PRED] = "dc_128",
      73             :         [DC_127_PRED] = "dc_127",
      74             :         [DC_129_PRED] = "dc_129",
      75             :     };
      76             : 
      77          52 :     for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
      78          39 :         ff_vp9dsp_init(&dsp, bit_depth, 0);
      79         195 :         for (tx = 0; tx < 4; tx++) {
      80         156 :             int size = 4 << tx;
      81             : 
      82        2496 :             for (mode = 0; mode < N_INTRA_PRED_MODES; mode++) {
      83        2340 :                 if (check_func(dsp.intra_pred[tx][mode], "vp9_%s_%dx%d_%dbpp",
      84             :                                mode_names[mode], size, size, bit_depth)) {
      85         499 :                     randomize_buffers();
      86         499 :                     call_ref(dst0, size * SIZEOF_PIXEL, l, a);
      87         499 :                     call_new(dst1, size * SIZEOF_PIXEL, l, a);
      88         499 :                     if (memcmp(dst0, dst1, size * size * SIZEOF_PIXEL))
      89           0 :                         fail();
      90         499 :                     bench_new(dst1, size * SIZEOF_PIXEL,l, a);
      91             :                 }
      92             :             }
      93             :         }
      94             :     }
      95          13 :     report("ipred");
      96          13 : }
      97             : 
      98             : #undef randomize_buffers
      99             : 
     100             : #define randomize_buffers() \
     101             :     do { \
     102             :         uint32_t mask = pixel_mask[(bit_depth - 8) >> 1];                  \
     103             :         for (y = 0; y < sz; y++) {                                         \
     104             :             for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) {                   \
     105             :                 uint32_t r = rnd() & mask;                                 \
     106             :                 AV_WN32A(dst + y * sz * SIZEOF_PIXEL + x, r);              \
     107             :                 AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask);   \
     108             :             }                                                              \
     109             :             for (x = 0; x < sz; x++) {                                     \
     110             :                 if (bit_depth == 8) {                                      \
     111             :                     coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x];  \
     112             :                 } else {                                                   \
     113             :                     ((int32_t *) coef)[y * sz + x] =                       \
     114             :                         ((uint16_t *) src)[y * sz + x] -                   \
     115             :                         ((uint16_t *) dst)[y * sz + x];                    \
     116             :                 }                                                          \
     117             :             }                                                              \
     118             :         }                                                                  \
     119             :     } while(0)
     120             : 
     121             : // wht function copied from libvpx
     122          48 : static void fwht_1d(double *out, const double *in, int sz)
     123             : {
     124          48 :     double t0 = in[0] + in[1];
     125          48 :     double t3 = in[3] - in[2];
     126          48 :     double t4 = trunc((t0 - t3) * 0.5);
     127          48 :     double t1 = t4 - in[1];
     128          48 :     double t2 = t4 - in[2];
     129             : 
     130          48 :     out[0] = t0 - t2;
     131          48 :     out[1] = t2;
     132          48 :     out[2] = t3 + t1;
     133          48 :     out[3] = t1;
     134          48 : }
     135             : 
     136             : // standard DCT-II
     137        8672 : static void fdct_1d(double *out, const double *in, int sz)
     138             : {
     139             :     int k, n;
     140             : 
     141      231392 :     for (k = 0; k < sz; k++) {
     142      222720 :         out[k] = 0.0;
     143     6682112 :         for (n = 0; n < sz; n++)
     144     6459392 :             out[k] += in[n] * cos(M_PI * (2 * n + 1) * k / (sz * 2.0));
     145             :     }
     146        8672 :     out[0] *= M_SQRT1_2;
     147        8672 : }
     148             : 
     149             : // see "Towards jointly optimal spatial prediction and adaptive transform in
     150             : // video/image coding", by J. Han, A. Saxena, and K. Rose
     151             : // IEEE Proc. ICASSP, pp. 726-729, Mar. 2010.
     152         128 : static void fadst4_1d(double *out, const double *in, int sz)
     153             : {
     154             :     int k, n;
     155             : 
     156         640 :     for (k = 0; k < sz; k++) {
     157         512 :         out[k] = 0.0;
     158        2560 :         for (n = 0; n < sz; n++)
     159        2048 :             out[k] += in[n] * sin(M_PI * (n + 1) * (2 * k + 1) / (sz * 2.0 + 1.0));
     160             :     }
     161         128 : }
     162             : 
     163             : // see "A Butterfly Structured Design of The Hybrid Transform Coding Scheme",
     164             : // by Jingning Han, Yaowu Xu, and Debargha Mukherjee
     165             : // http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41418.pdf
     166         832 : static void fadst_1d(double *out, const double *in, int sz)
     167             : {
     168             :     int k, n;
     169             : 
     170       12096 :     for (k = 0; k < sz; k++) {
     171       11264 :         out[k] = 0.0;
     172      175104 :         for (n = 0; n < sz; n++)
     173      163840 :             out[k] += in[n] * sin(M_PI * (2 * n + 1) * (2 * k + 1) / (sz * 4.0));
     174             :     }
     175         832 : }
     176             : 
     177             : typedef void (*ftx1d_fn)(double *out, const double *in, int sz);
     178         281 : static void ftx_2d(double *out, const double *in, enum TxfmMode tx,
     179             :                    enum TxfmType txtp, int sz)
     180             : {
     181             :     static const double scaling_factors[5][4] = {
     182             :         { 4.0, 16.0 * M_SQRT1_2 / 3.0, 16.0 * M_SQRT1_2 / 3.0, 32.0 / 9.0 },
     183             :         { 2.0, 2.0, 2.0, 2.0 },
     184             :         { 1.0, 1.0, 1.0, 1.0 },
     185             :         { 0.25 },
     186             :         { 4.0 }
     187             :     };
     188             :     static const ftx1d_fn ftx1d_tbl[5][4][2] = {
     189             :         {
     190             :             { fdct_1d, fdct_1d },
     191             :             { fadst4_1d, fdct_1d },
     192             :             { fdct_1d, fadst4_1d },
     193             :             { fadst4_1d, fadst4_1d },
     194             :         }, {
     195             :             { fdct_1d, fdct_1d },
     196             :             { fadst_1d, fdct_1d },
     197             :             { fdct_1d, fadst_1d },
     198             :             { fadst_1d, fadst_1d },
     199             :         }, {
     200             :             { fdct_1d, fdct_1d },
     201             :             { fadst_1d, fdct_1d },
     202             :             { fdct_1d, fadst_1d },
     203             :             { fadst_1d, fadst_1d },
     204             :         }, {
     205             :             { fdct_1d, fdct_1d },
     206             :         }, {
     207             :             { fwht_1d, fwht_1d },
     208             :         },
     209             :     };
     210             :     double temp[1024];
     211         281 :     double scaling_factor = scaling_factors[tx][txtp];
     212             :     int i, j;
     213             : 
     214             :     // cols
     215        5121 :     for (i = 0; i < sz; ++i) {
     216             :         double temp_out[32];
     217             : 
     218        4840 :         ftx1d_tbl[tx][txtp][0](temp_out, &in[i * sz], sz);
     219             :         // scale and transpose
     220      122184 :         for (j = 0; j < sz; ++j)
     221      117344 :             temp[j * sz + i] = temp_out[j] * scaling_factor;
     222             :     }
     223             : 
     224             :     // rows
     225        5121 :     for (i = 0; i < sz; i++)
     226        4840 :         ftx1d_tbl[tx][txtp][1](&out[i * sz], &temp[i * sz], sz);
     227         281 : }
     228             : 
     229         281 : static void ftx(int16_t *buf, enum TxfmMode tx,
     230             :                 enum TxfmType txtp, int sz, int bit_depth)
     231             : {
     232             :     double ind[1024], outd[1024];
     233             :     int n;
     234             : 
     235         281 :     emms_c();
     236      117625 :     for (n = 0; n < sz * sz; n++) {
     237      117344 :         if (bit_depth == 8)
     238       64832 :             ind[n] = buf[n];
     239             :         else
     240       52512 :             ind[n] = ((int32_t *) buf)[n];
     241             :     }
     242         281 :     ftx_2d(outd, ind, tx, txtp, sz);
     243      117625 :     for (n = 0; n < sz * sz; n++) {
     244      117344 :         if (bit_depth == 8)
     245       64832 :             buf[n] = lrint(outd[n]);
     246             :         else
     247       52512 :             ((int32_t *) buf)[n] = lrint(outd[n]);
     248             :     }
     249         281 : }
     250             : 
     251         166 : static int copy_subcoefs(int16_t *out, const int16_t *in, enum TxfmMode tx,
     252             :                          enum TxfmType txtp, int sz, int sub, int bit_depth)
     253             : {
     254             :     // copy the topleft coefficients such that the return value (being the
     255             :     // coefficient scantable index for the eob token) guarantees that only
     256             :     // the topleft $sub out of $sz (where $sz >= $sub) coefficients in both
     257             :     // dimensions are non-zero. This leads to braching to specific optimized
     258             :     // simd versions (e.g. dc-only) so that we get full asm coverage in this
     259             :     // test
     260             : 
     261             :     int n;
     262         166 :     const int16_t *scan = ff_vp9_scans[tx][txtp];
     263             :     int eob;
     264             : 
     265       13087 :     for (n = 0; n < sz * sz; n++) {
     266       13087 :         int rc = scan[n], rcx = rc % sz, rcy = rc / sz;
     267             : 
     268             :         // find eob for this sub-idct
     269       13087 :         if (rcx >= sub || rcy >= sub)
     270             :             break;
     271             : 
     272             :         // copy coef
     273       12921 :         if (bit_depth == 8) {
     274        7164 :             out[rc] = in[rc];
     275             :         } else {
     276        5757 :             AV_COPY32(&out[rc * 2], &in[rc * 2]);
     277             :         }
     278             :     }
     279             : 
     280         166 :     eob = n;
     281             : 
     282       83501 :     for (; n < sz * sz; n++) {
     283       83335 :         int rc = scan[n];
     284             : 
     285             :         // zero
     286       83335 :         if (bit_depth == 8) {
     287       46180 :             out[rc] = 0;
     288             :         } else {
     289       37155 :             AV_ZERO32(&out[rc * 2]);
     290             :         }
     291             :     }
     292             : 
     293         166 :     return eob;
     294             : }
     295             : 
     296         562 : static int iszero(const int16_t *c, int sz)
     297             : {
     298             :     int n;
     299             : 
     300      170418 :     for (n = 0; n < sz / sizeof(int16_t); n += 2)
     301      169856 :         if (AV_RN32A(&c[n]))
     302           0 :             return 0;
     303             : 
     304         562 :     return 1;
     305             : }
     306             : 
     307             : #define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
     308             : 
     309          13 : static void check_itxfm(void)
     310             : {
     311          13 :     LOCAL_ALIGNED_32(uint8_t, src, [32 * 32 * 2]);
     312          13 :     LOCAL_ALIGNED_32(uint8_t, dst, [32 * 32 * 2]);
     313          13 :     LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
     314          13 :     LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
     315          13 :     LOCAL_ALIGNED_32(int16_t, coef, [32 * 32 * 2]);
     316          13 :     LOCAL_ALIGNED_32(int16_t, subcoef0, [32 * 32 * 2]);
     317          13 :     LOCAL_ALIGNED_32(int16_t, subcoef1, [32 * 32 * 2]);
     318          13 :     declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
     319             :     VP9DSPContext dsp;
     320             :     int y, x, tx, txtp, bit_depth, sub;
     321             :     static const char *const txtp_types[N_TXFM_TYPES] = {
     322             :         [DCT_DCT] = "dct_dct", [DCT_ADST] = "adst_dct",
     323             :         [ADST_DCT] = "dct_adst", [ADST_ADST] = "adst_adst"
     324             :     };
     325             : 
     326          52 :     for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
     327          39 :         ff_vp9dsp_init(&dsp, bit_depth, 0);
     328             : 
     329         234 :         for (tx = TX_4X4; tx <= N_TXFM_SIZES /* 4 = lossless */; tx++) {
     330         195 :             int sz = 4 << (tx & 3);
     331         195 :             int n_txtps = tx < TX_32X32 ? N_TXFM_TYPES : 1;
     332             : 
     333         741 :             for (txtp = 0; txtp < n_txtps; txtp++) {
     334             :                 // skip testing sub-IDCTs for WHT or ADST since they don't
     335             :                 // implement it in any of the SIMD functions. If they do,
     336             :                 // consider changing this to ensure we have complete test
     337             :                 // coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc,
     338             :                 // since the arm version can distinguish them at that level.
     339        2379 :                 for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz;
     340        1287 :                      sub < 4 ? (sub <<= 1) : (sub += 4)) {
     341        1287 :                     if (check_func(dsp.itxfm_add[tx][txtp],
     342             :                                    "vp9_inv_%s_%dx%d_sub%d_add_%d",
     343             :                                    tx == 4 ? "wht_wht" : txtp_types[txtp],
     344             :                                    sz, sz, sub, bit_depth)) {
     345             :                         int eob;
     346             : 
     347         281 :                         randomize_buffers();
     348         281 :                         ftx(coef, tx, txtp, sz, bit_depth);
     349             : 
     350         281 :                         if (sub < sz) {
     351         166 :                             eob = copy_subcoefs(subcoef0, coef, tx, txtp,
     352             :                                                 sz, sub, bit_depth);
     353             :                         } else {
     354         115 :                             eob = sz * sz;
     355         115 :                             memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
     356             :                         }
     357             : 
     358         281 :                         memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL);
     359         281 :                         memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL);
     360         281 :                         memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
     361         281 :                         call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob);
     362         281 :                         call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob);
     363         562 :                         if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) ||
     364         562 :                             !iszero(subcoef0, sz * sz * SIZEOF_COEF) ||
     365         281 :                             !iszero(subcoef1, sz * sz * SIZEOF_COEF))
     366           0 :                             fail();
     367             : 
     368         281 :                         bench_new(dst, sz * SIZEOF_PIXEL, coef, eob);
     369             :                     }
     370             :                 }
     371             :             }
     372             :         }
     373             :     }
     374          13 :     report("itxfm");
     375          13 : }
     376             : 
     377             : #undef randomize_buffers
     378             : 
     379             : #define setpx(a,b,c) \
     380             :     do { \
     381             :         if (SIZEOF_PIXEL == 1) { \
     382             :             buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
     383             :         } else { \
     384             :             ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
     385             :         } \
     386             :     } while (0)
     387             : 
     388             : // c can be an assignment and must not be put under ()
     389             : #define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
     390             : #define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
     391         298 : static void randomize_loopfilter_buffers(int bidx, int lineoff, int str,
     392             :                                          int bit_depth, int dir, const int *E,
     393             :                                          const int *F, const int *H, const int *I,
     394             :                                          uint8_t *buf0, uint8_t *buf1)
     395             : {
     396         298 :     uint32_t mask = (1 << bit_depth) - 1;
     397         298 :     int off = dir ? lineoff : lineoff * 16;
     398         298 :     int istride = dir ? 1 : 16;
     399         298 :     int jstride = dir ? str : 1;
     400             :     int i, j;
     401         894 :     for (i = 0; i < 2; i++) /* flat16 */ {
     402         596 :         int idx = off + i * istride, p0, q0;
     403         596 :         setpx(idx,  0, q0 = rnd() & mask);
     404         596 :         setsx(idx, -1, p0 = q0, E[bidx] >> 2);
     405        4768 :         for (j = 1; j < 8; j++) {
     406        4172 :             setsx(idx, -1 - j, p0, F[bidx]);
     407        4172 :             setsx(idx, j, q0, F[bidx]);
     408             :         }
     409             :     }
     410         894 :     for (i = 2; i < 4; i++) /* flat8 */ {
     411         596 :         int idx = off + i * istride, p0, q0;
     412         596 :         setpx(idx,  0, q0 = rnd() & mask);
     413         596 :         setsx(idx, -1, p0 = q0, E[bidx] >> 2);
     414        2384 :         for (j = 1; j < 4; j++) {
     415        1788 :             setsx(idx, -1 - j, p0, F[bidx]);
     416        1788 :             setsx(idx, j, q0, F[bidx]);
     417             :         }
     418        2980 :         for (j = 4; j < 8; j++) {
     419        2384 :             setpx(idx, -1 - j, rnd() & mask);
     420        2384 :             setpx(idx, j, rnd() & mask);
     421             :         }
     422             :     }
     423         894 :     for (i = 4; i < 6; i++) /* regular */ {
     424         596 :         int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
     425         596 :         setpx(idx,  0, q0 = rnd() & mask);
     426         596 :         setsx(idx,  1, q1 = q0, I[bidx]);
     427         596 :         setsx(idx,  2, q2 = q1, I[bidx]);
     428         596 :         setsx(idx,  3, q2,      I[bidx]);
     429         596 :         setsx(idx, -1, p0 = q0, E[bidx] >> 2);
     430         596 :         setsx(idx, -2, p1 = p0, I[bidx]);
     431         596 :         setsx(idx, -3, p2 = p1, I[bidx]);
     432         596 :         setsx(idx, -4, p2,      I[bidx]);
     433        2980 :         for (j = 4; j < 8; j++) {
     434        2384 :             setpx(idx, -1 - j, rnd() & mask);
     435        2384 :             setpx(idx, j, rnd() & mask);
     436             :         }
     437             :     }
     438         894 :     for (i = 6; i < 8; i++) /* off */ {
     439         596 :         int idx = off + i * istride;
     440        5364 :         for (j = 0; j < 8; j++) {
     441        4768 :             setpx(idx, -1 - j, rnd() & mask);
     442        4768 :             setpx(idx, j, rnd() & mask);
     443             :         }
     444             :     }
     445         298 : }
     446             : #define randomize_buffers(bidx, lineoff, str) \
     447             :         randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
     448             :                                      E, F, H, I, buf0, buf1)
     449             : 
     450          13 : static void check_loopfilter(void)
     451             : {
     452          13 :     LOCAL_ALIGNED_32(uint8_t, base0, [32 + 16 * 16 * 2]);
     453          13 :     LOCAL_ALIGNED_32(uint8_t, base1, [32 + 16 * 16 * 2]);
     454             :     VP9DSPContext dsp;
     455             :     int dir, wd, wd2, bit_depth;
     456             :     static const char *const dir_name[2] = { "h", "v" };
     457             :     static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
     458             :     static const int H[2] = { 7, 11 }, F[2] = { 1, 1 };
     459          13 :     declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
     460             : 
     461          52 :     for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
     462          39 :         ff_vp9dsp_init(&dsp, bit_depth, 0);
     463             : 
     464         117 :         for (dir = 0; dir < 2; dir++) {
     465          78 :             int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL;
     466          78 :             int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL;
     467          78 :             uint8_t *buf0 = base0 + midoff_aligned;
     468          78 :             uint8_t *buf1 = base1 + midoff_aligned;
     469             : 
     470         312 :             for (wd = 0; wd < 3; wd++) {
     471             :                 // 4/8/16wd_8px
     472         234 :                 if (check_func(dsp.loop_filter_8[wd][dir],
     473             :                                "vp9_loop_filter_%s_%d_8_%dbpp",
     474             :                                dir_name[dir], 4 << wd, bit_depth)) {
     475          58 :                     randomize_buffers(0, 0, 8);
     476          58 :                     memcpy(buf1 - midoff, buf0 - midoff,
     477          58 :                            16 * 8 * SIZEOF_PIXEL);
     478          58 :                     call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
     479          58 :                     call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
     480          58 :                     if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL))
     481           0 :                         fail();
     482          58 :                     bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
     483             :                 }
     484             :             }
     485             : 
     486          78 :             midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL;
     487          78 :             midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL;
     488             : 
     489          78 :             buf0 = base0 + midoff_aligned;
     490          78 :             buf1 = base1 + midoff_aligned;
     491             : 
     492             :             // 16wd_16px loopfilter
     493          78 :             if (check_func(dsp.loop_filter_16[dir],
     494             :                            "vp9_loop_filter_%s_16_16_%dbpp",
     495             :                            dir_name[dir], bit_depth)) {
     496          24 :                 randomize_buffers(0, 0, 16);
     497          24 :                 randomize_buffers(0, 8, 16);
     498          24 :                 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
     499          24 :                 call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
     500          24 :                 call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
     501          24 :                 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
     502           0 :                     fail();
     503          24 :                 bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
     504             :             }
     505             : 
     506         234 :             for (wd = 0; wd < 2; wd++) {
     507         468 :                 for (wd2 = 0; wd2 < 2; wd2++) {
     508             :                     // mix2 loopfilter
     509         312 :                     if (check_func(dsp.loop_filter_mix2[wd][wd2][dir],
     510             :                                    "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
     511             :                                    dir_name[dir], 4 << wd, 4 << wd2, bit_depth)) {
     512          96 :                         randomize_buffers(0, 0, 16);
     513          96 :                         randomize_buffers(1, 8, 16);
     514          96 :                         memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
     515             : #define M(a) (((a)[1] << 8) | (a)[0])
     516          96 :                         call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
     517          96 :                         call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
     518          96 :                         if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
     519           0 :                             fail();
     520          96 :                         bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
     521             : #undef M
     522             :                     }
     523             :                 }
     524             :             }
     525             :         }
     526             :     }
     527          13 :     report("loopfilter");
     528          13 : }
     529             : 
     530             : #undef setsx
     531             : #undef setpx
     532             : #undef setdx
     533             : #undef randomize_buffers
     534             : 
     535             : #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
     536             : #define SRC_BUF_STRIDE 72
     537             : #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
     538             : #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
     539             : 
     540             : #define randomize_buffers()                               \
     541             :     do {                                                  \
     542             :         uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
     543             :         int k;                                            \
     544             :         for (k = 0; k < SRC_BUF_SIZE; k += 4) {           \
     545             :             uint32_t r = rnd() & mask;                    \
     546             :             AV_WN32A(buf + k, r);                         \
     547             :         }                                                 \
     548             :         if (op == 1) {                                    \
     549             :             for (k = 0; k < DST_BUF_SIZE; k += 4) {       \
     550             :                 uint32_t r = rnd() & mask;                \
     551             :                 AV_WN32A(dst0 + k, r);                    \
     552             :                 AV_WN32A(dst1 + k, r);                    \
     553             :             }                                             \
     554             :         }                                                 \
     555             :     } while (0)
     556             : 
     557          13 : static void check_mc(void)
     558             : {
     559          13 :     LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
     560          13 :     LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
     561          13 :     LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
     562             :     VP9DSPContext dsp;
     563             :     int op, hsize, bit_depth, filter, dx, dy;
     564          13 :     declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t dst_stride,
     565             :                       const uint8_t *ref, ptrdiff_t ref_stride,
     566             :                  int h, int mx, int my);
     567             :     static const char *const filter_names[4] = {
     568             :         "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
     569             :     };
     570             :     static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
     571             :     static const char *const op_names[2] = { "put", "avg" };
     572             :     char str[256];
     573             : 
     574          39 :     for (op = 0; op < 2; op++) {
     575         104 :         for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
     576          78 :             ff_vp9dsp_init(&dsp, bit_depth, 0);
     577         468 :             for (hsize = 0; hsize < 5; hsize++) {
     578         390 :                 int size = 64 >> hsize;
     579             : 
     580        1950 :                 for (filter = 0; filter < 4; filter++) {
     581        4680 :                     for (dx = 0; dx < 2; dx++) {
     582        9360 :                         for (dy = 0; dy < 2; dy++) {
     583        6240 :                             if (dx || dy) {
     584        4680 :                                 snprintf(str, sizeof(str),
     585             :                                          "%s_%s_%d%s", op_names[op],
     586             :                                          filter_names[filter], size,
     587             :                                          subpel_names[dy][dx]);
     588             :                             } else {
     589        1560 :                                 snprintf(str, sizeof(str),
     590             :                                          "%s%d", op_names[op], size);
     591             :                             }
     592        6240 :                             if (check_func(dsp.mc[hsize][filter][op][dx][dy],
     593             :                                            "vp9_%s_%dbpp", str, bit_depth)) {
     594         940 :                                 int mx = dx ? 1 + (rnd() % 14) : 0;
     595         940 :                                 int my = dy ? 1 + (rnd() % 14) : 0;
     596         940 :                                 randomize_buffers();
     597         940 :                                 call_ref(dst0, size * SIZEOF_PIXEL,
     598             :                                          src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
     599             :                                          size, mx, my);
     600         940 :                                 call_new(dst1, size * SIZEOF_PIXEL,
     601             :                                          src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
     602             :                                          size, mx, my);
     603         940 :                                 if (memcmp(dst0, dst1, DST_BUF_SIZE))
     604           0 :                                     fail();
     605             : 
     606             :                                 // simd implementations for each filter of subpel
     607             :                                 // functions are identical
     608         940 :                                 if (filter >= 1 && filter <= 2) continue;
     609             :                                 // 10/12 bpp for bilin are identical
     610         424 :                                 if (bit_depth == 12 && filter == 3) continue;
     611             : 
     612         394 :                                 bench_new(dst1, size * SIZEOF_PIXEL,
     613             :                                           src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
     614             :                                           size, mx, my);
     615             :                             }
     616             :                         }
     617             :                     }
     618             :                 }
     619             :             }
     620             :         }
     621             :     }
     622          13 :     report("mc");
     623          13 : }
     624             : 
     625          13 : void checkasm_check_vp9dsp(void)
     626             : {
     627          13 :     check_ipred();
     628          13 :     check_itxfm();
     629          13 :     check_loopfilter();
     630          13 :     check_mc();
     631          13 : }

Generated by: LCOV version 1.13