FFmpeg
Loading...
Searching...
No Matches
h264dsp.c
Go to the documentation of this file.
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"
27#include "libavutil/common.h"
30
31static const uint32_t pixel_mask[5] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff, 0x0fff0fff, 0x3fff3fff };
32static 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) \
61static 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) \
122static 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
151dct4x4_impl(16, int16_t)
153
154dct8x8_impl(16, int16_t)
156
157static void dct4x4(int16_t *coef, int bit_depth)
158{
159 if (bit_depth == 8)
160 dct4x4_16(coef);
161 else
162 dct4x4_32((int32_t *) coef);
163}
164
165static void dct8x8(int16_t *coef, int bit_depth)
166{
167 if (bit_depth == 8) {
168 dct8x8_16(coef);
169 } else {
170 dct8x8_32((int32_t *) coef);
171 }
172}
173
174
175static void check_idct(void)
176{
177 static const int depths[5] = { 8, 9, 10, 12, 14 };
178 LOCAL_ALIGNED_16(uint8_t, src, [8 * 8 * 2]);
179 LOCAL_ALIGNED_16(uint8_t, dst, [8 * 8 * 2]);
180 LOCAL_ALIGNED_16(uint8_t, dst0, [8 * 8 * 2]);
181 LOCAL_ALIGNED_16(uint8_t, dst1_base, [8 * 8 * 2 + 32]);
182 LOCAL_ALIGNED_16(int16_t, coef, [8 * 8 * 2]);
183 LOCAL_ALIGNED_16(int16_t, subcoef0, [8 * 8 * 2]);
184 LOCAL_ALIGNED_16(int16_t, subcoef1, [8 * 8 * 2]);
186 int bit_depth, sz, align, dc, i;
187 declare_func(void, uint8_t *dst, int16_t *block, ptrdiff_t stride);
188
189 for (i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
190 bit_depth = depths[i];
192
193 for (dc = 0; dc <= 2; dc++) {
194 for (sz = 4; sz <= 8; sz += 4) {
195 void (*idct)(uint8_t *, int16_t *, ptrdiff_t) = NULL;
196 const char fmts[3][28] = {
197 "idct%d_add_%dbpp", "idct%d_dc_add_%dbpp",
198 "add_pixels%d_%dbpp",
199 };
200
202
203 if (sz == 4)
204 dct4x4(coef, bit_depth);
205 else
206 dct8x8(coef, bit_depth);
207
208 switch ((sz << 2) | dc) {
209 case (4 << 2) | 0: idct = h.idct_add; break;
210 case (4 << 2) | 1: idct = h.idct_dc_add; break;
211 case (4 << 2) | 2: idct = h.add_pixels4_clear; break;
212 case (8 << 2) | 0: idct = h.idct8_add; break;
213 case (8 << 2) | 1: idct = h.idct8_dc_add; break;
214 case (8 << 2) | 2: idct = h.add_pixels8_clear; break;
215 }
216
217 if (check_func(idct, fmts[dc], sz, bit_depth)) {
218 for (align = 0; align < 16; align += sz * SIZEOF_PIXEL) {
219 uint8_t *dst1 = dst1_base + align;
220 if (dc) {
221 memset(subcoef0, 0, sz * sz * SIZEOF_COEF);
222 memcpy(subcoef0, coef, SIZEOF_COEF);
223 } else {
224 memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
225 }
226 memcpy(dst0, dst, sz * PIXEL_STRIDE);
227 memcpy(dst1, dst, sz * PIXEL_STRIDE);
228 memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
229 call_ref(dst0, subcoef0, PIXEL_STRIDE);
230 call_new(dst1, subcoef1, PIXEL_STRIDE);
231 if (memcmp(dst0, dst1, sz * PIXEL_STRIDE) ||
232 memcmp(subcoef0, subcoef1, sz * sz * SIZEOF_COEF))
233 fail();
234 bench_new(dst1, subcoef1, sz * SIZEOF_PIXEL);
235 }
236 }
237 }
238 }
239 }
240}
241
242static void check_idct_multiple(void)
243{
244 LOCAL_ALIGNED_16(uint8_t, dst_full, [16 * 16 * 2]);
245 LOCAL_ALIGNED_16(int16_t, coef_full, [16 * 16 * 2]);
246 LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16 * 2]);
247 LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16 * 2]);
248 LOCAL_ALIGNED_16(int16_t, coef0, [16 * 16 * 2]);
249 LOCAL_ALIGNED_16(int16_t, coef1, [16 * 16 * 2]);
250 LOCAL_ALIGNED_16(uint8_t, nnzc, [15 * 8]);
252 int bit_depth, i, y, func;
253 declare_func(void, uint8_t *dst, const int *block_offset, int16_t *block, ptrdiff_t stride, const uint8_t nnzc[15*8]);
254
255 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
257 for (func = 0; func < 3; func++) {
258 void (*idct)(uint8_t *, const int *, int16_t *, ptrdiff_t, const uint8_t[]) = NULL;
259 const char *name;
260 int sz = 4, intra = 0;
261 int block_offset[16] = { 0 };
262 switch (func) {
263 case 0:
264 idct = h.idct_add16;
265 name = "idct_add16";
266 break;
267 case 1:
268 idct = h.idct_add16intra;
269 name = "idct_add16intra";
270 intra = 1;
271 break;
272 case 2:
273 idct = h.idct8_add4;
274 name = "idct8_add4";
275 sz = 8;
276 break;
277 }
278 memset(nnzc, 0, 15 * 8);
279 memset(coef_full, 0, 16 * 16 * SIZEOF_COEF);
280 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 int index = i / sz;
285 int block_y = (index / 16) * sz;
286 int block_x = index % 16;
287 int offset = (block_y * 16 + block_x) * SIZEOF_PIXEL;
288 int nnz = rnd() % 3;
289
291 if (sz == 4)
292 dct4x4(coef, bit_depth);
293 else
294 dct8x8(coef, bit_depth);
295
296 for (y = 0; y < sz; y++)
297 memcpy(&dst_full[offset + y * 16 * SIZEOF_PIXEL],
298 &dst[PIXEL_STRIDE * y], sz * SIZEOF_PIXEL);
299
300 if (nnz > 1)
301 nnz = sz * sz;
302 memcpy(&coef_full[i * SIZEOF_COEF/sizeof(coef[0])],
303 coef, nnz * SIZEOF_COEF);
304
305 if (intra && nnz == 1)
306 nnz = 0;
307
308 nnzc[scan8[i / 16]] = nnz;
309 block_offset[i / 16] = offset;
310 }
311
312 if (check_func(idct, "%s_%dbpp", name, bit_depth)) {
313 memcpy(coef0, coef_full, 16 * 16 * SIZEOF_COEF);
314 memcpy(coef1, coef_full, 16 * 16 * SIZEOF_COEF);
315 memcpy(dst0, dst_full, 16 * 16 * SIZEOF_PIXEL);
316 memcpy(dst1, dst_full, 16 * 16 * SIZEOF_PIXEL);
317 call_ref(dst0, block_offset, coef0, 16 * SIZEOF_PIXEL, nnzc);
318 call_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
319 if (memcmp(dst0, dst1, 16 * 16 * SIZEOF_PIXEL) ||
320 memcmp(coef0, coef1, 16 * 16 * SIZEOF_COEF))
321 fail();
322 bench_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
323 }
324 }
325 }
326}
327
328static void check_idct_add8(void)
329{
330 LOCAL_ALIGNED_16(uint8_t, dst_full, [16 * 32 * 2]);
331 LOCAL_ALIGNED_16(int16_t, coef_full, [48 * 16 * 2]);
332 LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 32 * 2]);
333 LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 32 * 2]);
334 LOCAL_ALIGNED_16(int16_t, coef0, [48 * 16 * 2]);
335 LOCAL_ALIGNED_16(int16_t, coef1, [48 * 16 * 2]);
336 LOCAL_ALIGNED_16(uint8_t, nnzc, [15 * 8]);
338 int bit_depth, format, j, k;
339 int sz = 4;
340 int block_offset[48] = { 0 };
341 declare_func(void, uint8_t **dst, const int *block_offset,
342 int16_t *block, ptrdiff_t stride, const uint8_t nnzc[15*8]);
343
344 for (bit_depth = 8; bit_depth <= 10; bit_depth += 2) {
345 for (format = 1; format <= 2; format++) {
346 void (*idct)(uint8_t **, const int *, int16_t *, ptrdiff_t, const uint8_t[]) = NULL;
347 const char *name = format == 1 ? "idct_add8" : "idct_add8_422";
348 uint8_t *dstp0[2], *dstp1[2];
349
351 idct = h.idct_add8;
352
353 memset(nnzc, 0, 15 * 8);
354 memset(coef_full, 0, 48 * 16 * SIZEOF_COEF);
355 for (j = 1; j < 3; j++) {
356 for (k = 0; k < (format == 1 ? 4 : 8); k++) {
357 uint8_t src[8 * 8 * 2];
358 uint8_t dst[8 * 8 * 2];
359 int16_t coef[16 * 2];
360 int second = k >= 4;
361 int i = j * 16 + (k % 4) + (second ? 4 : 0);
362 int bo = second ? i + 4 : i;
363 int row = (second ? 8 : 0);
364 int col = (k % 4) * 4;
365 int offset = (row * 16 + col) * SIZEOF_PIXEL +
366 (j - 1) * 16 * 16 * SIZEOF_PIXEL;
367 int nnz = rnd() % 3;
368 int16_t *cblk = &coef_full[i * 16 * SIZEOF_COEF / 2];
369
371 dct4x4(coef, bit_depth);
372
373 if (nnz > 1)
374 nnz = 16;
375 memcpy(cblk, coef, nnz * SIZEOF_COEF);
376
377 for (int y = 0; y < 4; y++)
378 memcpy(&dst_full[offset + y * 16 * SIZEOF_PIXEL],
379 &dst[y * 4 * SIZEOF_PIXEL], 4 * SIZEOF_PIXEL);
380
381 nnzc[scan8[second ? i + 4 : i]] = nnz;
382 block_offset[bo] = offset - (j - 1) * 16 * 16 * SIZEOF_PIXEL;
383 }
384 }
385
386 dstp0[0] = dst0;
387 dstp0[1] = dst0 + 16 * 16 * SIZEOF_PIXEL;
388 dstp1[0] = dst1;
389 dstp1[1] = dst1 + 16 * 16 * SIZEOF_PIXEL;
390
391 if (check_func(idct, "%s_%dbpp", name, bit_depth)) {
392 memcpy(coef0, coef_full, 48 * 16 * SIZEOF_COEF);
393 memcpy(coef1, coef_full, 48 * 16 * SIZEOF_COEF);
394 memcpy(dst0, dst_full, 16 * 32 * 2);
395 memcpy(dst1, dst_full, 16 * 32 * 2);
396 call_ref(dstp0, block_offset, coef0, 16 * SIZEOF_PIXEL, nnzc);
397 call_new(dstp1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
398 if (memcmp(dst0, dst1, 16 * 32 * 2) ||
399 memcmp(coef0, coef1, 48 * 16 * SIZEOF_COEF))
400 fail();
401 bench_new(dstp1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
402 }
403 }
404 }
405}
406
407static void check_idct_dequant(void)
408{
409 static const int depths[5] = { 8, 9, 10, 12, 14 };
410 LOCAL_ALIGNED_16(int16_t, src16, [16]);
411 LOCAL_ALIGNED_16(int32_t, src32, [16]);
412 LOCAL_ALIGNED_16(int16_t, dst0_16, [16 * 16]);
413 LOCAL_ALIGNED_16(int16_t, dst1_16, [16 * 16]);
414 LOCAL_ALIGNED_16(int32_t, dst0_32, [16 * 16]);
415 LOCAL_ALIGNED_16(int32_t, dst1_32, [16 * 16]);
417 int bit_depth, i, qmul;
418 declare_func(void, int16_t *output, int16_t *input, int qmul);
419
420 qmul = rnd() % 4096;
421
422 for (i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
423 bit_depth = depths[i];
425
426 void *src, *dst_ref, *dst_new;
427 if (bit_depth == 8) {
428 src = src16;
429 dst_ref = dst0_16;
430 dst_new = dst1_16;
431 for (int j = 0; j < 16; j++)
432 src16[j] = (rnd() % 512) - 256;
433 } else {
434 src = src32;
435 dst_ref = dst0_32;
436 dst_new = dst1_32;
437 for (int j = 0; j < 16; j++)
438 src32[j] = (rnd() % (1 << (bit_depth + 1))) - (1 << bit_depth);
439 }
440 memset(dst_ref, 0, 16 * 16 * SIZEOF_COEF);
441 memset(dst_new, 0, 16 * 16 * SIZEOF_COEF);
442
443 if (check_func(h.luma_dc_dequant_idct, "luma_dc_dequant_idct_%d", bit_depth)) {
444
445 call_ref(dst_ref, src, qmul);
446 call_new(dst_new, src, qmul);
447 checkasm_check_dctcoef(dst0, 16*SIZEOF_COEF, dst1, 16*SIZEOF_COEF, 16, 16, "dst");
448 bench_new(dst_new, src, qmul);
449 }
450 }
451}
452
453
454static void check_loop_filter(void)
455{
456 enum {
457 N = 35,
458 };
459 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
460 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
461 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
463 int bit_depth;
464 int alphas[N], betas[N];
465 int8_t tc0[N][4];
466
467 declare_func(void, uint8_t *pix, ptrdiff_t stride,
468 int alpha, int beta, int8_t *tc0);
469
470 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
471 uint32_t mask = pixel_mask_lf[bit_depth - 8];
473 for (int i = N, a = 255, c = 250; --i >= 0;) {
474 alphas[i] = a << (bit_depth - 8);
475 betas[i] = (i + 2) / 2 << (bit_depth - 8);
476 tc0[i][0] = tc0[i][3] = (c + 6) / 10;
477 tc0[i][1] = (c + 7) / 15;
478 tc0[i][2] = (c + 9) / 20;
479 a = a*9/10;
480 c = c*9/10;
481 }
482
483#define CHECK_LOOP_FILTER(name, align, idc) \
484 do { \
485 if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
486 for (int j = 0; j < N; ++j) { \
487 intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
488 for (int i = 0; i < 1024; i += 4) { \
489 AV_WN32A(dst + i, rnd() & mask); \
490 } \
491 memcpy(dst0, dst, 32 * 16 * 2); \
492 memcpy(dst1, dst, 32 * 16 * 2); \
493 \
494 call_ref(dst0 + off, 32, alphas[j], betas[j], tc0[j]); \
495 call_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]); \
496 if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
497 fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d " \
498 "tc0:{%d,%d,%d,%d}\n", j, alphas[j], betas[j], \
499 tc0[j][0], tc0[j][1], tc0[j][2], tc0[j][3]); \
500 fail(); \
501 } \
502 bench_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]);\
503 } \
504 } \
505 } while (0)
506
507 CHECK_LOOP_FILTER(v_loop_filter_luma, 1,);
508 CHECK_LOOP_FILTER(h_loop_filter_luma, 0,);
509 CHECK_LOOP_FILTER(h_loop_filter_luma_mbaff, 0,);
510 CHECK_LOOP_FILTER(v_loop_filter_chroma, 1,);
511 CHECK_LOOP_FILTER(h_loop_filter_chroma, 0,);
512 CHECK_LOOP_FILTER(h_loop_filter_chroma_mbaff, 0,);
513
515 CHECK_LOOP_FILTER(h_loop_filter_chroma, 0, 422);
516 CHECK_LOOP_FILTER(h_loop_filter_chroma_mbaff, 0, 422);
517#undef CHECK_LOOP_FILTER
518 }
519}
520
521static void check_loop_filter_intra(void)
522{
523 enum {
524 N = 35,
525 };
526 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
527 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
528 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
530 int bit_depth;
531 int alphas[N], betas[N];
532
533 declare_func(void, uint8_t *pix, ptrdiff_t stride,
534 int alpha, int beta);
535
536 for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
537 uint32_t mask = pixel_mask_lf[bit_depth - 8];
539 for (int i = N, a = 255; --i >= 0;) {
540 alphas[i] = a << (bit_depth - 8);
541 betas[i] = (i + 2) / 2 << (bit_depth - 8);
542 a = a*9/10;
543 }
544
545#define CHECK_LOOP_FILTER(name, align, idc) \
546 do { \
547 if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
548 for (int j = 0; j < N; ++j) { \
549 intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
550 for (int i = 0; i < 1024; i += 4) { \
551 AV_WN32A(dst + i, rnd() & mask); \
552 } \
553 memcpy(dst0, dst, 32 * 16 * 2); \
554 memcpy(dst1, dst, 32 * 16 * 2); \
555 \
556 call_ref(dst0 + off, 32, alphas[j], betas[j]); \
557 call_new(dst1 + off, 32, alphas[j], betas[j]); \
558 if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
559 fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d\n", \
560 j, alphas[j], betas[j]); \
561 fail(); \
562 } \
563 bench_new(dst1 + off, 32, alphas[j], betas[j]); \
564 } \
565 } \
566 } while (0)
567
568 CHECK_LOOP_FILTER(v_loop_filter_luma_intra, 1,);
569 CHECK_LOOP_FILTER(h_loop_filter_luma_intra, 0,);
570 CHECK_LOOP_FILTER(h_loop_filter_luma_mbaff_intra, 0,);
571 CHECK_LOOP_FILTER(v_loop_filter_chroma_intra, 1,);
572 CHECK_LOOP_FILTER(h_loop_filter_chroma_intra, 0,);
573 CHECK_LOOP_FILTER(h_loop_filter_chroma_mbaff_intra, 0,);
574
576 CHECK_LOOP_FILTER(h_loop_filter_chroma_intra, 0, 422);
577 CHECK_LOOP_FILTER(h_loop_filter_chroma_mbaff_intra, 0, 422);
578#undef CHECK_LOOP_FILTER
579 }
580}
581
582static void check_weight(void)
583{
584 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 32 * 2]);
585 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 32 * 2]);
586 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 32 * 2]);
588 declare_func(void, uint8_t *dst, ptrdiff_t stride, int height,
589 int log2_denom, int weight, int offset);
590
591 for (int bit_depth = 8; bit_depth <= 10; bit_depth += 2) {
593 uint32_t mask = pixel_mask[bit_depth - 8];
594 for (int w = 16; w >= 2; w >>= 1) {
595 int idx = 4 - av_log2(w);
596
597 if (check_func(h.weight_pixels_tab[idx], "weight_%dx%d_%d",
598 w, 16, bit_depth)) {
599 for (int hgt = FFMIN(16, 2 * w);
600 hgt >= FFMAX(2, w / 2); hgt >>= 1) {
601 for (int i = 0; i < 32; i++) {
602 int stride = 32 * SIZEOF_PIXEL;
603 int log2_denom = rnd() % 8;
604 int weight = (rnd() % 256) - 128;
605 int offset = (rnd() % 256) - 128;
606
607 memset(dst, 0, 32 * 32 * 2);
608 for (int y = 0; y < hgt; y++) {
609 for (int x = 0; x < w * SIZEOF_PIXEL; x += 4) {
610 AV_WN32A(dst + y * stride + x, rnd() & mask);
611 }
612 }
613 memcpy(dst0, dst, 32 * 32 * 2);
614 memcpy(dst1, dst, 32 * 32 * 2);
615 call_ref(dst0, stride, hgt, log2_denom, weight, offset);
616 call_new(dst1, stride, hgt, log2_denom, weight, offset);
617 if (memcmp(dst0, dst1, 32 * 32 * 2))
618 fail();
619 bench_new(dst, stride, hgt, log2_denom, weight, offset);
620 }
621 }
622 }
623 }
624 }
625}
626
627static void check_biweight(void)
628{
629 LOCAL_ALIGNED_16(uint8_t, dst, [32 * 32 * 2]);
630 LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 32 * 2]);
631 LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 32 * 2]);
632 LOCAL_ALIGNED_16(uint8_t, src, [32 * 32 * 2]);
633 LOCAL_ALIGNED_16(uint8_t, src0, [32 * 32 * 2]);
634 LOCAL_ALIGNED_16(uint8_t, src1, [32 * 32 * 2]);
636 declare_func(void, uint8_t *dst, uint8_t *src, ptrdiff_t stride, int height,
637 int log2_denom, int weightd, int weights, int offset);
638
639 for (int bit_depth = 8; bit_depth <= 10; bit_depth += 2) {
640 uint32_t mask = pixel_mask[bit_depth - 8];
642 for (int w = 16; w >= 2; w >>= 1) {
643 int idx = 4 - av_log2(w);
644
645 if (check_func(h.biweight_pixels_tab[idx], "biweight_%dx%d_%d",
646 w, 16, bit_depth)) {
647 for (int hgt = FFMIN(16, 2 * w);
648 hgt >= FFMAX(2, w / 2); hgt >>= 1) {
649 for (int i = 0; i < 32; i++) {
650 int stride = 32 * SIZEOF_PIXEL;
651 // Spec allows for 0 <= log2_denom <= 7 regardless
652 // of bit depth, but x86 asm impl. is bit accurate
653 // only up to 6 for 8bpp.
654 //
655 // In practice, log2_denom > 3 is rarely used.
656 int max_log2_denom_8b = 6;
657 int log2_denom = rnd() %
658 (bit_depth == 8 ? (max_log2_denom_8b + 1) : 8);
659
660 int weightd, weights;
661 do {
662 weightd = rnd() % 256 - 128;
663 weights = rnd() % 256 - 128;
664 } while (weightd + weights < -128 ||
665 weightd + weights > (log2_denom == 7 ? 127 : 128));
666 int offset = (rnd() % 256 - 128) + (rnd() % 256 - 128);
667
668 memset(dst, 0, 32 * 32 * 2);
669 memset(src, 0, 32 * 32 * 2);
670 for (int y = 0; y < hgt; y++) {
671 for (int x = 0; x < w * SIZEOF_PIXEL; x += 4) {
672 AV_WN32A(dst + y * stride + x, rnd() & mask);
673 AV_WN32A(src + y * stride + x, rnd() & mask);
674 }
675 }
676 memcpy(dst0, dst, 32 * 32 * 2);
677 memcpy(dst1, dst, 32 * 32 * 2);
678 memcpy(src0, src, 32 * 32 * 2);
679 memcpy(src1, src, 32 * 32 * 2);
680 call_ref(dst0, src0, stride, hgt, log2_denom, weightd,
681 weights, offset);
682 call_new(dst1, src1, stride, hgt, log2_denom, weightd,
683 weights, offset);
684 if (memcmp(dst0, dst1, 32 * 32 * 2))
685 fail();
686 bench_new(dst, src, stride, hgt, log2_denom, weightd,
687 weights, offset);
688 }
689 }
690 }
691 }
692 }
693}
694
696{
697 check_idct();
701 report("idct");
702
704 report("loop_filter");
705
707 report("loop_filter_intra");
708
709 check_weight();
710 report("weight");
711
713 report("biweight");
714}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static const char *const format[]
Definition af_aiir.c:445
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
#define N
Definition af_mcompand.c:54
int32_t
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:140
#define checkasm_check_dctcoef(buf1, stride1, buf2, stride2,...)
Definition checkasm.h:181
common internal and external API header
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
int index
Definition gxfenc.c:90
H.264 decoder/parser shared code.
static const uint8_t scan8[16 *3+3]
Definition h264_parse.h:40
H.264 DSP functions.
int a
static const int weights[]
Definition hevc_pel.c:32
static const int16_t alpha[]
Definition ilbcdata.h:55
#define av_log2
Definition intmath.h:84
#define AV_WN32A(p, v)
unsigned offset
Definition libaomenc.c:763
static void idct(int16_t block[64])
Definition 4xm.c:167
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
Definition h264dsp.c:66
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition jacosubdec.c:67
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define LOCAL_ALIGNED_16(t, v,...)
enum AVPixelFormat pix
Definition ohcodec.c:55
const char * name
Definition qsvenc.c:142
const h264_weight_func weight
#define FF_ARRAY_ELEMS(a)
Context for storing H.264 DSP functions.
Definition h264dsp.h:42
#define stride
#define SIZEOF_PIXEL
Definition h264chroma.c:28
void checkasm_check_h264dsp(void)
Definition h264dsp.c:695
static void check_loop_filter(void)
Definition h264dsp.c:454
static void check_biweight(void)
Definition h264dsp.c:627
static const uint32_t pixel_mask[5]
Definition h264dsp.c:31
#define PIXEL_STRIDE
Definition h264dsp.c:36
static void check_idct_multiple(void)
Definition h264dsp.c:242
static void check_loop_filter_intra(void)
Definition h264dsp.c:521
static void check_idct_dequant(void)
Definition h264dsp.c:407
static const uint32_t pixel_mask_lf[3]
Definition h264dsp.c:32
static void check_weight(void)
Definition h264dsp.c:582
static void check_idct(void)
Definition h264dsp.c:175
#define CHECK_LOOP_FILTER(name, align, idc)
static void dct8x8(int16_t *coef, int bit_depth)
Definition h264dsp.c:165
static void check_idct_add8(void)
Definition h264dsp.c:328
#define dct4x4_impl(size, dctcoef)
Definition h264dsp.c:60
#define dct8x8_impl(size, dctcoef)
Definition h264dsp.c:121
#define randomize_buffers(idx)
Definition h264dsp.c:38
#define SIZEOF_COEF
Definition h264dsp.c:35
#define src1
Definition h264pred.c:141
#define src0
Definition h264pred.c:140
#define src
Definition vp8dsp.c:248
static void dct4x4(int16_t *coef)
Definition vp8dsp.c:47
#define height
Definition dsp.h:99
static double c[64]