FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/h264dsp.c
Date: 2025-06-23 20:06:14
Exec Total Coverage
Lines: 200 202 99.0%
Functions: 12 12 100.0%
Branches: 254 409 62.1%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2016 Martin Storsjo
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 <string.h>
22 #include "checkasm.h"
23 #include "libavcodec/h264dsp.h"
24 #include "libavcodec/h264data.h"
25 #include "libavcodec/h264idct.h"
26 #include "libavcodec/h264_parse.h"
27 #include "libavutil/common.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem_internal.h"
30
31 static const uint32_t pixel_mask[5] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff, 0x0fff0fff, 0x3fff3fff };
32 static const uint32_t pixel_mask_lf[3] = { 0xff0fff0f, 0x01ff000f, 0x03ff000f };
33
34 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
35 #define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
36 #define PIXEL_STRIDE 16
37
38 #define randomize_buffers(idx) \
39 do { \
40 int x, y; \
41 uint32_t mask = pixel_mask[(idx)]; \
42 for (y = 0; y < sz; y++) { \
43 for (x = 0; x < PIXEL_STRIDE; x += 4) { \
44 AV_WN32A(src + y * PIXEL_STRIDE + x, rnd() & mask); \
45 AV_WN32A(dst + y * PIXEL_STRIDE + x, rnd() & mask); \
46 } \
47 for (x = 0; x < sz; x++) { \
48 if (bit_depth == 8) { \
49 coef[y * sz + x] = src[y * PIXEL_STRIDE + x] - \
50 dst[y * PIXEL_STRIDE + x]; \
51 } else { \
52 ((int32_t *)coef)[y * sz + x] = \
53 ((uint16_t *)src)[y * (PIXEL_STRIDE/2) + x] - \
54 ((uint16_t *)dst)[y * (PIXEL_STRIDE/2) + x]; \
55 } \
56 } \
57 } \
58 } while (0)
59
60 #define dct4x4_impl(size, dctcoef) \
61 static void dct4x4_##size(dctcoef *coef) \
62 { \
63 int i, y, x; \
64 dctcoef tmp[16]; \
65 for (i = 0; i < 4; i++) { \
66 const int z0 = coef[i*4 + 0] + coef[i*4 + 3]; \
67 const int z1 = coef[i*4 + 1] + coef[i*4 + 2]; \
68 const int z2 = coef[i*4 + 0] - coef[i*4 + 3]; \
69 const int z3 = coef[i*4 + 1] - coef[i*4 + 2]; \
70 tmp[i + 4*0] = z0 + z1; \
71 tmp[i + 4*1] = 2*z2 + z3; \
72 tmp[i + 4*2] = z0 - z1; \
73 tmp[i + 4*3] = z2 - 2*z3; \
74 } \
75 for (i = 0; i < 4; i++) { \
76 const int z0 = tmp[i*4 + 0] + tmp[i*4 + 3]; \
77 const int z1 = tmp[i*4 + 1] + tmp[i*4 + 2]; \
78 const int z2 = tmp[i*4 + 0] - tmp[i*4 + 3]; \
79 const int z3 = tmp[i*4 + 1] - tmp[i*4 + 2]; \
80 coef[i*4 + 0] = z0 + z1; \
81 coef[i*4 + 1] = 2*z2 + z3; \
82 coef[i*4 + 2] = z0 - z1; \
83 coef[i*4 + 3] = z2 - 2*z3; \
84 } \
85 for (y = 0; y < 4; y++) { \
86 for (x = 0; x < 4; x++) { \
87 const int64_t scale[] = { 13107 * 10, 8066 * 13, 5243 * 16 }; \
88 const int idx = (y & 1) + (x & 1); \
89 coef[y*4 + x] = (coef[y*4 + x] * scale[idx] + (1 << 14)) >> 15; \
90 } \
91 } \
92 }
93
94 #define DCT8_1D(src, srcstride, dst, dststride) do { \
95 const int a0 = (src)[srcstride * 0] + (src)[srcstride * 7]; \
96 const int a1 = (src)[srcstride * 0] - (src)[srcstride * 7]; \
97 const int a2 = (src)[srcstride * 1] + (src)[srcstride * 6]; \
98 const int a3 = (src)[srcstride * 1] - (src)[srcstride * 6]; \
99 const int a4 = (src)[srcstride * 2] + (src)[srcstride * 5]; \
100 const int a5 = (src)[srcstride * 2] - (src)[srcstride * 5]; \
101 const int a6 = (src)[srcstride * 3] + (src)[srcstride * 4]; \
102 const int a7 = (src)[srcstride * 3] - (src)[srcstride * 4]; \
103 const int b0 = a0 + a6; \
104 const int b1 = a2 + a4; \
105 const int b2 = a0 - a6; \
106 const int b3 = a2 - a4; \
107 const int b4 = a3 + a5 + (a1 + (a1 >> 1)); \
108 const int b5 = a1 - a7 - (a5 + (a5 >> 1)); \
109 const int b6 = a1 + a7 - (a3 + (a3 >> 1)); \
110 const int b7 = a3 - a5 + (a7 + (a7 >> 1)); \
111 (dst)[dststride * 0] = b0 + b1; \
112 (dst)[dststride * 1] = b4 + (b7 >> 2); \
113 (dst)[dststride * 2] = b2 + (b3 >> 1); \
114 (dst)[dststride * 3] = b5 + (b6 >> 2); \
115 (dst)[dststride * 4] = b0 - b1; \
116 (dst)[dststride * 5] = b6 - (b5 >> 2); \
117 (dst)[dststride * 6] = (b2 >> 1) - b3; \
118 (dst)[dststride * 7] = (b4 >> 2) - b7; \
119 } while (0)
120
121 #define dct8x8_impl(size, dctcoef) \
122 static void dct8x8_##size(dctcoef *coef) \
123 { \
124 int i, x, y; \
125 dctcoef tmp[64]; \
126 for (i = 0; i < 8; i++) \
127 DCT8_1D(coef + i, 8, tmp + i, 8); \
128 \
129 for (i = 0; i < 8; i++) \
130 DCT8_1D(tmp + 8*i, 1, coef + i, 8); \
131 \
132 for (y = 0; y < 8; y++) { \
133 for (x = 0; x < 8; x++) { \
134 static const int scale[] = { \
135 13107 * 20, 11428 * 18, 20972 * 32, \
136 12222 * 19, 16777 * 25, 15481 * 24, \
137 }; \
138 static const int idxmap[] = { \
139 0, 3, 4, 3, \
140 3, 1, 5, 1, \
141 4, 5, 2, 5, \
142 3, 1, 5, 1, \
143 }; \
144 const int idx = idxmap[(y & 3) * 4 + (x & 3)]; \
145 coef[y*8 + x] = ((int64_t)coef[y*8 + x] * \
146 scale[idx] + (1 << 17)) >> 18; \
147 } \
148 } \
149 }
150
151
8/8
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 455 times.
✓ Branch 2 taken 1820 times.
✓ Branch 3 taken 455 times.
✓ Branch 4 taken 7280 times.
✓ Branch 5 taken 1820 times.
✓ Branch 6 taken 1820 times.
✓ Branch 7 taken 455 times.
13195 dct4x4_impl(16, int16_t)
152
8/8
✓ Branch 0 taken 3952 times.
✓ Branch 1 taken 988 times.
✓ Branch 2 taken 3952 times.
✓ Branch 3 taken 988 times.
✓ Branch 4 taken 15808 times.
✓ Branch 5 taken 3952 times.
✓ Branch 6 taken 3952 times.
✓ Branch 7 taken 988 times.
28652 dct4x4_impl(32, int32_t)
153
154
8/8
✓ Branch 0 taken 728 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 728 times.
✓ Branch 3 taken 91 times.
✓ Branch 4 taken 5824 times.
✓ Branch 5 taken 728 times.
✓ Branch 6 taken 728 times.
✓ Branch 7 taken 91 times.
8099 dct8x8_impl(16, int16_t)
155
8/8
✓ Branch 0 taken 2080 times.
✓ Branch 1 taken 260 times.
✓ Branch 2 taken 2080 times.
✓ Branch 3 taken 260 times.
✓ Branch 4 taken 16640 times.
✓ Branch 5 taken 2080 times.
✓ Branch 6 taken 2080 times.
✓ Branch 7 taken 260 times.
23140 dct8x8_impl(32, int32_t)
156
157 1443 static void dct4x4(int16_t *coef, int bit_depth)
158 {
159
2/2
✓ Branch 0 taken 455 times.
✓ Branch 1 taken 988 times.
1443 if (bit_depth == 8)
160 455 dct4x4_16(coef);
161 else
162 988 dct4x4_32((int32_t *) coef);
163 1443 }
164
165 351 static void dct8x8(int16_t *coef, int bit_depth)
166 {
167
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 260 times.
351 if (bit_depth == 8) {
168 91 dct8x8_16(coef);
169 } else {
170 260 dct8x8_32((int32_t *) coef);
171 }
172 351 }
173
174
175 13 static void check_idct(void)
176 {
177 static const int depths[5] = { 8, 9, 10, 12, 14 };
178 13 LOCAL_ALIGNED_16(uint8_t, src, [8 * 8 * 2]);
179 13 LOCAL_ALIGNED_16(uint8_t, dst, [8 * 8 * 2]);
180 13 LOCAL_ALIGNED_16(uint8_t, dst0, [8 * 8 * 2]);
181 13 LOCAL_ALIGNED_16(uint8_t, dst1_base, [8 * 8 * 2 + 32]);
182 13 LOCAL_ALIGNED_16(int16_t, coef, [8 * 8 * 2]);
183 13 LOCAL_ALIGNED_16(int16_t, subcoef0, [8 * 8 * 2]);
184 13 LOCAL_ALIGNED_16(int16_t, subcoef1, [8 * 8 * 2]);
185 H264DSPContext h;
186 int bit_depth, sz, align, dc, i;
187
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
13 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, int stride);
188
189
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 13 times.
78 for (i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
190 65 bit_depth = depths[i];
191 65 ff_h264dsp_init(&h, bit_depth, 1);
192
193
2/2
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 65 times.
260 for (dc = 0; dc <= 2; dc++) {
194
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 195 times.
585 for (sz = 4; sz <= 8; sz += 4) {
195 390 void (*idct)(uint8_t *, int16_t *, int) = NULL;
196 390 const char fmts[3][28] = {
197 "h264_idct%d_add_%dbpp", "h264_idct%d_dc_add_%dbpp",
198 "h264_add_pixels%d_%dbpp",
199 };
200
201
8/8
✓ Branch 2 taken 9360 times.
✓ Branch 3 taken 2340 times.
✓ Branch 4 taken 3120 times.
✓ Branch 5 taken 12480 times.
✓ Branch 6 taken 15600 times.
✓ Branch 7 taken 2340 times.
✓ Branch 8 taken 2340 times.
✓ Branch 9 taken 390 times.
27690 randomize_buffers(i);
202
203
2/2
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 195 times.
390 if (sz == 4)
204 195 dct4x4(coef, bit_depth);
205 else
206 195 dct8x8(coef, bit_depth);
207
208
6/7
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 65 times.
✓ Branch 3 taken 65 times.
✓ Branch 4 taken 65 times.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
390 switch ((sz << 2) | dc) {
209 65 case (4 << 2) | 0: idct = h.h264_idct_add; break;
210 65 case (4 << 2) | 1: idct = h.h264_idct_dc_add; break;
211 65 case (4 << 2) | 2: idct = h.h264_add_pixels4_clear; break;
212 65 case (8 << 2) | 0: idct = h.h264_idct8_add; break;
213 65 case (8 << 2) | 1: idct = h.h264_idct8_dc_add; break;
214 65 case (8 << 2) | 2: idct = h.h264_add_pixels8_clear; break;
215 }
216
217
2/2
✓ Branch 3 taken 44 times.
✓ Branch 4 taken 346 times.
390 if (check_func(idct, fmts[dc], sz, bit_depth)) {
218
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 44 times.
130 for (align = 0; align < 16; align += sz * SIZEOF_PIXEL) {
219 86 uint8_t *dst1 = dst1_base + align;
220
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 34 times.
86 if (dc) {
221 52 memset(subcoef0, 0, sz * sz * SIZEOF_COEF);
222 52 memcpy(subcoef0, coef, SIZEOF_COEF);
223 } else {
224 34 memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
225 }
226 86 memcpy(dst0, dst, sz * PIXEL_STRIDE);
227 86 memcpy(dst1, dst, sz * PIXEL_STRIDE);
228 86 memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
229 86 call_ref(dst0, subcoef0, PIXEL_STRIDE);
230 86 call_new(dst1, subcoef1, PIXEL_STRIDE);
231
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if (memcmp(dst0, dst1, sz * PIXEL_STRIDE) ||
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
86 memcmp(subcoef0, subcoef1, sz * sz * SIZEOF_COEF))
233 fail();
234
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 86 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
86 bench_new(dst1, subcoef1, sz * SIZEOF_PIXEL);
235 }
236 }
237 }
238 }
239 }
240 13 }
241
242 13 static void check_idct_multiple(void)
243 {
244 13 LOCAL_ALIGNED_16(uint8_t, dst_full, [16 * 16 * 2]);
245 13 LOCAL_ALIGNED_16(int16_t, coef_full, [16 * 16 * 2]);
246 13 LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16 * 2]);
247 13 LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16 * 2]);
248 13 LOCAL_ALIGNED_16(int16_t, coef0, [16 * 16 * 2]);
249 13 LOCAL_ALIGNED_16(int16_t, coef1, [16 * 16 * 2]);
250 13 LOCAL_ALIGNED_16(uint8_t, nnzc, [15 * 8]);
251 H264DSPContext h;
252 int bit_depth, i, y, func;
253
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
13 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]);
254
255
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
256 39 ff_h264dsp_init(&h, bit_depth, 1);
257
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 39 times.
156 for (func = 0; func < 3; func++) {
258 117 void (*idct)(uint8_t *, const int *, int16_t *, int, const uint8_t[]) = NULL;
259 const char *name;
260 117 int sz = 4, intra = 0;
261 117 int block_offset[16] = { 0 };
262
3/4
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
117 switch (func) {
263 39 case 0:
264 39 idct = h.h264_idct_add16;
265 39 name = "h264_idct_add16";
266 39 break;
267 39 case 1:
268 39 idct = h.h264_idct_add16intra;
269 39 name = "h264_idct_add16intra";
270 39 intra = 1;
271 39 break;
272 39 case 2:
273 39 idct = h.h264_idct8_add4;
274 39 name = "h264_idct8_add4";
275 39 sz = 8;
276 39 break;
277 }
278 117 memset(nnzc, 0, 15 * 8);
279 117 memset(coef_full, 0, 16 * 16 * SIZEOF_COEF);
280
2/2
✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 117 times.
1521 for (i = 0; i < 16 * 16; i += sz * sz) {
281 uint8_t src[8 * 8 * 2];
282 uint8_t dst[8 * 8 * 2];
283 int16_t coef[8 * 8 * 2];
284 1404 int index = i / sz;
285 1404 int block_y = (index / 16) * sz;
286 1404 int block_x = index % 16;
287 1404 int offset = (block_y * 16 + block_x) * SIZEOF_PIXEL;
288 1404 int nnz = rnd() % 3;
289
290
8/8
✓ Branch 2 taken 24960 times.
✓ Branch 3 taken 6240 times.
✓ Branch 4 taken 9984 times.
✓ Branch 5 taken 19968 times.
✓ Branch 6 taken 29952 times.
✓ Branch 7 taken 6240 times.
✓ Branch 8 taken 6240 times.
✓ Branch 9 taken 1404 times.
62556 randomize_buffers(bit_depth - 8);
291
2/2
✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 156 times.
1404 if (sz == 4)
292 1248 dct4x4(coef, bit_depth);
293 else
294 156 dct8x8(coef, bit_depth);
295
296
2/2
✓ Branch 0 taken 6240 times.
✓ Branch 1 taken 1404 times.
7644 for (y = 0; y < sz; y++)
297 6240 memcpy(&dst_full[offset + y * 16 * SIZEOF_PIXEL],
298 6240 &dst[PIXEL_STRIDE * y], sz * SIZEOF_PIXEL);
299
300
2/2
✓ Branch 0 taken 465 times.
✓ Branch 1 taken 939 times.
1404 if (nnz > 1)
301 465 nnz = sz * sz;
302 1404 memcpy(&coef_full[i * SIZEOF_COEF/sizeof(coef[0])],
303 1404 coef, nnz * SIZEOF_COEF);
304
305
4/4
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 780 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 402 times.
1404 if (intra && nnz == 1)
306 222 nnz = 0;
307
308 1404 nnzc[scan8[i / 16]] = nnz;
309 1404 block_offset[i / 16] = offset;
310 }
311
312
2/2
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 99 times.
117 if (check_func(idct, "%s_%dbpp", name, bit_depth)) {
313 18 memcpy(coef0, coef_full, 16 * 16 * SIZEOF_COEF);
314 18 memcpy(coef1, coef_full, 16 * 16 * SIZEOF_COEF);
315 18 memcpy(dst0, dst_full, 16 * 16 * SIZEOF_PIXEL);
316 18 memcpy(dst1, dst_full, 16 * 16 * SIZEOF_PIXEL);
317 18 call_ref(dst0, block_offset, coef0, 16 * SIZEOF_PIXEL, nnzc);
318 18 call_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
319
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (memcmp(dst0, dst1, 16 * 16 * SIZEOF_PIXEL) ||
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 memcmp(coef0, coef1, 16 * 16 * SIZEOF_COEF))
321 fail();
322
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
18 bench_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
323 }
324 }
325 }
326 13 }
327
328 13 static void check_idct_dequant(void)
329 {
330 static const int depths[5] = { 8, 9, 10, 12, 14 };
331 13 LOCAL_ALIGNED_16(int16_t, src, [16]);
332 /* Ensure dst buffers are large enough to hold dctcoefs of all bit-depths. */
333 13 LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16 * sizeof(int32_t)]);
334 13 LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16 * sizeof(int32_t)]);
335 13 int16_t *dst_ref = (int16_t *)dst0;
336 13 int16_t *dst_new = (int16_t *)dst1;
337 H264DSPContext h;
338 int bit_depth, i, qmul;
339
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
13 declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_SSE2, void, int16_t *output, int16_t *input, int qmul);
340
341
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 13 times.
221 for (int j = 0; j < 16; j++)
342 208 src[j] = (rnd() % 512) - 256;
343
344 13 qmul = rnd() % 4096;
345
346
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 13 times.
78 for (i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
347 65 bit_depth = depths[i];
348 65 ff_h264dsp_init(&h, bit_depth, 1);
349
350 65 memset(dst0, 0, 16 * 16 * SIZEOF_COEF);
351 65 memset(dst1, 0, 16 * 16 * SIZEOF_COEF);
352
353
2/2
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 59 times.
65 if (check_func(h.h264_luma_dc_dequant_idct, "h264_luma_dc_dequant_idct_%d", bit_depth)) {
354
355 6 call_ref(dst_ref, src, qmul);
356 6 call_new(dst_new, src, qmul);
357
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 checkasm_check_dctcoef(dst_ref, 16*SIZEOF_COEF, dst_new, 16*SIZEOF_COEF, 16, 16, "dst");
358
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
6 bench_new(dst_new, src, qmul);
359 }
360 }
361 13 }
362
363
364 13 static void check_loop_filter(void)
365 {
366 13 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
367 13 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
368 13 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
369 H264DSPContext h;
370 int bit_depth;
371 int alphas[36], betas[36];
372 int8_t tc0[36][4];
373
374
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
13 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *pix, ptrdiff_t stride,
375 int alpha, int beta, int8_t *tc0);
376
377
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
378 int i, j, a, c;
379 39 uint32_t mask = pixel_mask_lf[bit_depth - 8];
380 39 ff_h264dsp_init(&h, bit_depth, 1);
381
2/2
✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 39 times.
1443 for (i = 35, a = 255, c = 250; i >= 0; i--) {
382 1404 alphas[i] = a << (bit_depth - 8);
383 1404 betas[i] = (i + 1) / 2 << (bit_depth - 8);
384 1404 tc0[i][0] = tc0[i][3] = (c + 6) / 10;
385 1404 tc0[i][1] = (c + 7) / 15;
386 1404 tc0[i][2] = (c + 9) / 20;
387 1404 a = a*9/10;
388 1404 c = c*9/10;
389 }
390
391 #define CHECK_LOOP_FILTER(name, align, idc) \
392 do { \
393 if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
394 for (j = 0; j < 36; j++) { \
395 intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
396 for (i = 0; i < 1024; i+=4) { \
397 AV_WN32A(dst + i, rnd() & mask); \
398 } \
399 memcpy(dst0, dst, 32 * 16 * 2); \
400 memcpy(dst1, dst, 32 * 16 * 2); \
401 \
402 call_ref(dst0 + off, 32, alphas[j], betas[j], tc0[j]); \
403 call_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]); \
404 if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
405 fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d " \
406 "tc0:{%d,%d,%d,%d}\n", j, alphas[j], betas[j], \
407 tc0[j][0], tc0[j][1], tc0[j][2], tc0[j][3]); \
408 fail(); \
409 } \
410 bench_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]);\
411 } \
412 } \
413 } while (0)
414
415
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_v_loop_filter_luma, 1,);
416
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_h_loop_filter_luma, 0,);
417
8/16
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 34 times.
✓ Branch 6 taken 46080 times.
✓ Branch 7 taken 180 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 180 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 180 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 180 times.
✓ Branch 40 taken 5 times.
46299 CHECK_LOOP_FILTER(h264_h_loop_filter_luma_mbaff, 0,);
418
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_v_loop_filter_chroma, 1,);
419
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma, 0,);
420
8/16
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
✓ Branch 6 taken 27648 times.
✓ Branch 7 taken 108 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 108 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 108 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 108 times.
✓ Branch 40 taken 3 times.
27795 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff, 0,);
421
422 39 ff_h264dsp_init(&h, bit_depth, 2);
423
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma, 0, 422);
424
8/16
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
✓ Branch 6 taken 27648 times.
✓ Branch 7 taken 108 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 108 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 108 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 108 times.
✓ Branch 40 taken 3 times.
27795 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff, 0, 422);
425 #undef CHECK_LOOP_FILTER
426 }
427 13 }
428
429 13 static void check_loop_filter_intra(void)
430 {
431 13 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
432 13 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
433 13 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
434 H264DSPContext h;
435 int bit_depth;
436 int alphas[36], betas[36];
437
438
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
13 declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *pix, ptrdiff_t stride,
439 int alpha, int beta);
440
441
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
442 int i, j, a;
443 39 uint32_t mask = pixel_mask_lf[bit_depth - 8];
444 39 ff_h264dsp_init(&h, bit_depth, 1);
445
2/2
✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 39 times.
1443 for (i = 35, a = 255; i >= 0; i--) {
446 1404 alphas[i] = a << (bit_depth - 8);
447 1404 betas[i] = (i + 1) / 2 << (bit_depth - 8);
448 1404 a = a*9/10;
449 }
450
451 #define CHECK_LOOP_FILTER(name, align, idc) \
452 do { \
453 if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
454 for (j = 0; j < 36; j++) { \
455 intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
456 for (i = 0; i < 1024; i+=4) { \
457 AV_WN32A(dst + i, rnd() & mask); \
458 } \
459 memcpy(dst0, dst, 32 * 16 * 2); \
460 memcpy(dst1, dst, 32 * 16 * 2); \
461 \
462 call_ref(dst0 + off, 32, alphas[j], betas[j]); \
463 call_new(dst1 + off, 32, alphas[j], betas[j]); \
464 if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
465 fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d\n", \
466 j, alphas[j], betas[j]); \
467 fail(); \
468 } \
469 bench_new(dst1 + off, 32, alphas[j], betas[j]); \
470 } \
471 } \
472 } while (0)
473
474
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_v_loop_filter_luma_intra, 1,);
475
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_h_loop_filter_luma_intra, 0,);
476
8/16
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
✓ Branch 6 taken 27648 times.
✓ Branch 7 taken 108 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 108 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 108 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 108 times.
✓ Branch 40 taken 3 times.
27795 CHECK_LOOP_FILTER(h264_h_loop_filter_luma_mbaff_intra, 0,);
477
8/16
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 64512 times.
✓ Branch 7 taken 252 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 252 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 252 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 252 times.
✓ Branch 40 taken 7 times.
64803 CHECK_LOOP_FILTER(h264_v_loop_filter_chroma_intra, 1,);
478
8/16
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 34 times.
✓ Branch 6 taken 46080 times.
✓ Branch 7 taken 180 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 180 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 180 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 180 times.
✓ Branch 40 taken 5 times.
46299 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_intra, 0,);
479
8/16
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
✓ Branch 6 taken 27648 times.
✓ Branch 7 taken 108 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 108 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 108 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 108 times.
✓ Branch 40 taken 3 times.
27795 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff_intra, 0,);
480
481 39 ff_h264dsp_init(&h, bit_depth, 2);
482
8/16
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 34 times.
✓ Branch 6 taken 46080 times.
✓ Branch 7 taken 180 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 180 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 180 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 180 times.
✓ Branch 40 taken 5 times.
46299 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_intra, 0, 422);
483
8/16
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
✓ Branch 6 taken 27648 times.
✓ Branch 7 taken 108 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 108 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 108 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 108 times.
✓ Branch 40 taken 3 times.
27795 CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff_intra, 0, 422);
484 #undef CHECK_LOOP_FILTER
485 }
486 13 }
487
488 13 void checkasm_check_h264dsp(void)
489 {
490 13 check_idct();
491 13 check_idct_multiple();
492 13 check_idct_dequant();
493 13 report("idct");
494
495 13 check_loop_filter();
496 13 report("loop_filter");
497
498 13 check_loop_filter_intra();
499 13 report("loop_filter_intra");
500 13 }
501