FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/hpeldsp.c
Date: 2026-08-31 23:16:59
Exec Total Coverage
Lines: 35 36 97.2%
Functions: 1 1 100.0%
Branches: 25 46 54.3%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <assert.h>
20 #include <stddef.h>
21
22 #include "checkasm.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/macros.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavcodec/avcodec.h"
27 #include "libavcodec/hpeldsp.h"
28
29 #define MAX_BLOCK_SIZE 16
30 #define MAX_HEIGHT 16
31 #define MAX_STRIDE 64
32 // BUF_SIZE is bigger than necessary in order to test strides > block width.
33 #define BUF_SIZE ((MAX_HEIGHT - 1) * MAX_STRIDE + MAX_BLOCK_SIZE)
34 // Due to hpel interpolation the input needs to have one more line than
35 // the output and the last line needs one more element.
36 // The input is not subject to alignment requirements; making the input buffer
37 // bigger (by MAX_BLOCK_SIZE - 1) allows us to use a random misalignment.
38 #define INPUT_BUF_SIZE (MAX_HEIGHT * MAX_STRIDE + MAX_BLOCK_SIZE + 1 + (MAX_BLOCK_SIZE - 1))
39
40 #define randomize_buffers(buf0, buf1) \
41 do { \
42 static_assert(sizeof(buf0) == sizeof(buf1), "Incompatible buffers"); \
43 static_assert(!(sizeof(buf0) % 4), "Tail handling needed"); \
44 static_assert(sizeof(buf0[0]) == 1 && sizeof(buf1[0]) == 1, \
45 "Pointer arithmetic needs to be adapted"); \
46 for (size_t k = 0; k < sizeof(buf0); k += 4) { \
47 uint32_t r = rnd(); \
48 AV_WN32A(buf0 + k, r); \
49 AV_WN32A(buf1 + k, r); \
50 } \
51 } while (0)
52
53
54 14 void checkasm_check_hpeldsp(void)
55 {
56 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf0)[INPUT_BUF_SIZE];
57 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf1)[INPUT_BUF_SIZE];
58 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf0)[BUF_SIZE];
59 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf1)[BUF_SIZE];
60 HpelDSPContext hdsp;
61 static const struct {
62 const char *name;
63 size_t offset;
64 unsigned nb_blocksizes;
65 } tests[] = {
66 #define TEST(NAME, NB) { .name = #NAME, .offset = offsetof(HpelDSPContext, NAME), .nb_blocksizes = NB }
67 TEST(put_pixels_tab, 4),
68 TEST(avg_pixels_tab, 4),
69 TEST(put_no_rnd_pixels_tab, 2), // put_no_rnd_pixels_tab only has two usable blocksizes
70 TEST(avg_no_rnd_pixels_tab, 1),
71 };
72 14 declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h);
73
74 14 ff_hpeldsp_init(&hdsp, AV_CODEC_FLAG_BITEXACT);
75
76 int heights[FF_ARRAY_ELEMS(tests)][4][4];
77
78 // Always use the same height for each test, so that comparisons of benchmarks
79 // from different instruction sets are meaningful. To do so, initialize
80 // the heights before any function is checked. This works because the seed
81 // for the sequence of rnd() outputs is always the same at the start of
82 // each test.
83
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
70 for (size_t i = 0; i < FF_ARRAY_ELEMS(heights); ++i)
84
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 56 times.
280 for (size_t j = 0; j < FF_ARRAY_ELEMS(heights[0]); ++j) {
85 224 const unsigned blocksize = MAX_BLOCK_SIZE >> j;
86 // h must always be a multiple of four, except when width is two or four.
87
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 112 times.
224 const unsigned h_mult = blocksize <= 4 ? 2 : 4;
88
2/2
✓ Branch 0 taken 896 times.
✓ Branch 1 taken 224 times.
1120 for (size_t k = 0; k < FF_ARRAY_ELEMS(heights[0][0]); ++k)
89 896 heights[i][j][k] = (rnd() % (MAX_HEIGHT / h_mult) + 1) * h_mult;
90 }
91
92
93
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
70 for (size_t i = 0; i < FF_ARRAY_ELEMS(tests); ++i) {
94 56 op_pixels_func (*func_tab)[4] = (op_pixels_func (*)[4])((char*)&hdsp + tests[i].offset);
95
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 56 times.
210 for (unsigned j = 0; j < tests[i].nb_blocksizes; ++j) {
96 154 const unsigned blocksize = MAX_BLOCK_SIZE >> j;
97
98
2/2
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 154 times.
770 for (unsigned dxy = 0; dxy < 4; ++dxy) {
99
2/2
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 542 times.
616 if (check_func(func_tab[j][dxy], "%s[%u][%u]", tests[i].name, j, dxy)) {
100 // Don't always use output that is 16-aligned.
101 74 size_t dst_offset = (rnd() % (MAX_BLOCK_SIZE / blocksize)) * blocksize;
102 74 size_t src_offset = rnd() % MAX_BLOCK_SIZE;
103 74 ptrdiff_t stride = (rnd() % (MAX_STRIDE / blocksize) + 1) * blocksize;
104 74 const uint8_t *src0 = srcbuf0 + src_offset, *src1 = srcbuf1 + src_offset;
105 74 uint8_t *dst0 = dstbuf0 + dst_offset, *dst1 = dstbuf1 + dst_offset;
106
107 74 int h = heights[i][j][dxy];
108
109
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 if (rnd() & 1) {
110 // Flip stride.
111 74 dst1 += (h - 1) * stride;
112 74 dst0 += (h - 1) * stride;
113 // Due to interpolation potentially h + 1 lines are read
114 // from src, hence h * stride.
115 74 src0 += h * stride;
116 74 src1 += h * stride;
117 74 stride = -stride;
118 }
119
120
2/2
✓ Branch 1 taken 19536 times.
✓ Branch 2 taken 74 times.
19610 randomize_buffers(srcbuf0, srcbuf1);
121
2/2
✓ Branch 1 taken 18056 times.
✓ Branch 2 taken 74 times.
18130 randomize_buffers(dstbuf0, dstbuf1);
122
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
74 call_ref(dst0, src0, stride, h);
123 74 call_new(dst1, src1, stride, h);
124
2/4
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
74 if (memcmp(srcbuf0, srcbuf1, sizeof(srcbuf0)) || memcmp(dstbuf0, dstbuf1, sizeof(dstbuf0)))
125 fail();
126
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
74 bench_new(dst0, src0, stride, h);
127 }
128 }
129 }
130 }
131 14 report("hpeldsp");
132 14 }
133