dd37077adf6f5272d9d0ff7ca49f86568c92f5e6
[ffmpeg.git] / tests / checkasm / vp9dsp.c
1 /*
2  * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include <string.h>
22
23 #include "libavutil/common.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/intreadwrite.h"
26
27 #include "libavcodec/vp9.h"
28
29 #include "checkasm.h"
30
31 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
32
33 #define BIT_DEPTH 8
34 #define SIZEOF_PIXEL ((BIT_DEPTH + 7) / 8)
35 #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
36 #define SRC_BUF_STRIDE 72
37 #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
38 #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
39
40 #define randomize_buffers()                               \
41     do {                                                  \
42         uint32_t mask = pixel_mask[(BIT_DEPTH - 8) >> 1]; \
43         int k;                                            \
44         for (k = 0; k < SRC_BUF_SIZE; k += 4) {           \
45             uint32_t r = rnd() & mask;                    \
46             AV_WN32A(buf + k, r);                         \
47         }                                                 \
48         if (op == 1) {                                    \
49             for (k = 0; k < DST_BUF_SIZE; k += 4) {       \
50                 uint32_t r = rnd() & mask;                \
51                 AV_WN32A(dst0 + k, r);                    \
52                 AV_WN32A(dst1 + k, r);                    \
53             }                                             \
54         }                                                 \
55     } while (0)
56
57 static void check_mc(void)
58 {
59     static const char *const filter_names[4] = {
60         "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
61     };
62     static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
63     static const char *const op_names[2] = { "put", "avg" };
64
65     LOCAL_ALIGNED_32(uint8_t, buf,  [72 * 72 * 2]);
66     LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
67     LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
68     char str[256];
69     VP9DSPContext dsp;
70     int op, hsize, filter, dx, dy;
71
72     declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
73                       void, uint8_t *dst, const uint8_t *ref,
74                       ptrdiff_t dst_stride, ptrdiff_t ref_stride,
75                       int h, int mx, int my);
76
77     for (op = 0; op < 2; op++) {
78         ff_vp9dsp_init(&dsp);
79         for (hsize = 0; hsize < 5; hsize++) {
80             int size = 64 >> hsize;
81
82             for (filter = 0; filter < 4; filter++) {
83                 for (dx = 0; dx < 2; dx++) {
84                     for (dy = 0; dy < 2; dy++) {
85                         if (dx || dy) {
86                             snprintf(str, sizeof(str), "%s_%s_%d%s", op_names[op],
87                                      filter_names[filter], size,
88                                      subpel_names[dy][dx]);
89                         } else {
90                             snprintf(str, sizeof(str), "%s%d", op_names[op], size);
91                         }
92                         if (check_func(dsp.mc[hsize][filter][op][dx][dy],
93                                        "vp9_%s", str)) {
94                             int mx = dx ? 1 + (rnd() % 14) : 0;
95                             int my = dy ? 1 + (rnd() % 14) : 0;
96                             randomize_buffers();
97                             call_ref(dst0, src,
98                                      size * SIZEOF_PIXEL,
99                                      SRC_BUF_STRIDE * SIZEOF_PIXEL,
100                                      size, mx, my);
101                             call_new(dst1, src,
102                                      size * SIZEOF_PIXEL,
103                                      SRC_BUF_STRIDE * SIZEOF_PIXEL,
104                                      size, mx, my);
105                             if (memcmp(dst0, dst1, DST_BUF_SIZE))
106                                 fail();
107
108                             // SIMD implementations for each filter of subpel
109                             // functions are identical
110                             if (filter >= 1 && filter <= 2) continue;
111
112                             bench_new(dst1, src, size * SIZEOF_PIXEL,
113                                       SRC_BUF_STRIDE * SIZEOF_PIXEL,
114                                       size, mx, my);
115                         }
116                     }
117                 }
118             }
119         }
120     }
121     report("mc");
122 }
123
124 void checkasm_check_vp9dsp(void)
125 {
126     check_mc();
127 }