FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/sbrdsp.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 182 193 94.3%
Functions: 12 12 100.0%
Branches: 86 174 49.4%

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 "libavutil/mem_internal.h"
20
21 #include "libavcodec/sbrdsp.h"
22 #include <float.h>
23
24 #include "checkasm.h"
25
26 #define randomize(buf, len) do { \
27 int i; \
28 for (i = 0; i < len; i++) { \
29 const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
30 (buf)[i] = f; \
31 } \
32 } while (0)
33
34 #define EPS 0.0001
35
36 2 static void test_sum64x5(void)
37 {
38 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
39 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
40
41 2 declare_func(void, INTFLOAT *z);
42
43
2/2
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 2 times.
642 randomize((INTFLOAT *)dst0, 64 + 256);
44 2 memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
45 2 call_ref(dst0);
46 2 call_new(dst1);
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
48 fail();
49
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1);
50 2 }
51
52 2 static void test_sum_square(void)
53 {
54 INTFLOAT res0;
55 INTFLOAT res1;
56 2 LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
57 2 double t = 4 * 256;
58
59 2 declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
60
61
2/2
✓ Branch 1 taken 1024 times.
✓ Branch 2 taken 2 times.
1026 randomize((INTFLOAT *)src, 256 * 2);
62 2 res0 = call_ref(src, 256);
63 2 res1 = call_new(src, 256);
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps(res0, res1, t * 2 * FLT_EPSILON))
65 fail();
66
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(src, 256);
67 2 }
68
69 2 static void test_neg_odd_64(void)
70 {
71 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
72 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
73
74 2 declare_func(void, INTFLOAT *x);
75
76
2/2
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
130 randomize((INTFLOAT *)dst0, 64);
77 2 memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
78 2 call_ref(dst0);
79 2 call_new(dst1);
80
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
81 fail();
82
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1);
83 2 }
84
85 2 static void test_qmf_pre_shuffle(void)
86 {
87 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
88 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
89
90 2 declare_func(void, INTFLOAT *z);
91
92
2/2
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2 times.
258 randomize((INTFLOAT *)dst0, 128);
93 2 memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
94 2 call_ref(dst0);
95 2 call_new(dst1);
96
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
97 fail();
98
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1);
99 2 }
100
101 2 static void test_qmf_post_shuffle(void)
102 {
103 2 LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
104 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
105 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
106
107 2 declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
108
109
2/2
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
130 randomize((INTFLOAT *)src, 64);
110 2 call_ref(dst0, src);
111 2 call_new(dst1, src);
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
113 fail();
114
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1, src);
115 2 }
116
117 2 static void test_qmf_deint_neg(void)
118 {
119 2 LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
120 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
121 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
122
123 2 declare_func(void, INTFLOAT *v, const INTFLOAT *src);
124
125
2/2
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
130 randomize((INTFLOAT *)src, 64);
126 2 call_ref(dst0, src);
127 2 call_new(dst1, src);
128
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
129 fail();
130
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1, src);
131 2 }
132
133 2 static void test_qmf_deint_bfly(void)
134 {
135 2 LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
136 2 LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
137 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
138 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
139
140 2 declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
141
142 2 memset(dst0, 0, 128 * sizeof(INTFLOAT));
143 2 memset(dst1, 0, 128 * sizeof(INTFLOAT));
144
145
2/2
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
130 randomize((INTFLOAT *)src0, 64);
146
2/2
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 2 times.
130 randomize((INTFLOAT *)src1, 64);
147 2 call_ref(dst0, src0, src1);
148 2 call_new(dst1, src0, src1);
149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
150 fail();
151
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1, src0, src1);
152 2 }
153
154 3 static void test_autocorrelate(void)
155 {
156 3 LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
157 3 LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
158 3 LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
159
160 3 declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
161
162 3 memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
163 3 memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
164
165
2/2
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 3 times.
243 randomize((INTFLOAT *)src, 80);
166 3 call_ref(src, dst0);
167 3 call_new(src, dst1);
168
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
169 fail();
170
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
3 bench_new(src, dst1);
171 3 }
172
173 2 static void test_hf_gen(void)
174 {
175 2 LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
176 2 LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
177 2 LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
178 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
179 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
180 2 INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
181 int i;
182
183 2 declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
184 const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
185 INTFLOAT bw, int start, int end);
186
187
2/2
✓ Branch 1 taken 512 times.
✓ Branch 2 taken 2 times.
514 randomize((INTFLOAT *)low, 128 * 2);
188
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
6 randomize((INTFLOAT *)alpha0, 2);
189
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
6 randomize((INTFLOAT *)alpha1, 2);
190
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 2 times.
64 for (i = 2; i < 64; i += 2) {
191 62 memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
192 62 memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
193 62 call_ref(dst0, low, alpha0, alpha1, bw, i, 128);
194 62 call_new(dst1, low, alpha0, alpha1, bw, i, 128);
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
62 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
196 fail();
197
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 62 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.
62 bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
198 }
199 2 }
200
201 2 static void test_hf_g_filt(void)
202 {
203 2 LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
204 2 LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
205 2 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
206 2 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
207
208 2 declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
209 const INTFLOAT *g_filt, int m_max, intptr_t ixh);
210
211
2/2
✓ Branch 1 taken 20480 times.
✓ Branch 2 taken 2 times.
20482 randomize((INTFLOAT *)high, 128 * 40 * 2);
212
2/2
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2 times.
258 randomize((INTFLOAT *)g_filt, 128);
213
214 2 call_ref(dst0, high, g_filt, 128, 20);
215 2 call_new(dst1, high, g_filt, 128, 20);
216
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
217 fail();
218
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 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.
2 bench_new(dst1, high, g_filt, 128, 20);
219 2 }
220
221 13 static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
222 {
223 13 LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
224 13 LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
225 13 LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
226 13 LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
227 13 LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
228 13 int noise = 0x2a;
229 int i, j;
230
231 13 declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
232 const AAC_FLOAT *q_filt, int noise,
233 int kx, int m_max);
234
235
2/2
✓ Branch 1 taken 3328 times.
✓ Branch 2 taken 13 times.
3341 randomize((INTFLOAT *)ref, 128 * 2);
236
237
2/2
✓ Branch 0 taken 1664 times.
✓ Branch 1 taken 13 times.
1677 for (int i = 0; i < 128; i++)
238
2/2
✓ Branch 1 taken 823 times.
✓ Branch 2 taken 841 times.
1664 s_m[i] = (rnd() & 1) ? ((INTFLOAT)rnd() / UINT_MAX) : (INTFLOAT)0;
239
240
2/2
✓ Branch 1 taken 1664 times.
✓ Branch 2 taken 13 times.
1677 randomize((INTFLOAT *)q_filt, 128);
241
242
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 13 times.
65 for (i = 0; i < 4; i++) {
243
2/2
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 44 times.
52 if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
244
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 for (j = 0; j < 2; j++) {
245 16 memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
246 16 memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
247 16 call_ref(dst0, s_m, q_filt, noise, j, 128);
248 16 call_new(dst1, s_m, q_filt, noise, j, 128);
249
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
250 fail();
251
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 16 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.
16 bench_new(dst1, s_m, q_filt, noise, j, 128);
252 }
253 }
254 }
255 13 }
256
257 13 void checkasm_check_sbrdsp(void)
258 {
259 SBRDSPContext sbrdsp;
260
261 13 ff_sbrdsp_init(&sbrdsp);
262
263
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.sum64x5, "sum64x5"))
264 2 test_sum64x5();
265 13 report("sum64x5");
266
267
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.sum_square, "sum_square"))
268 2 test_sum_square();
269 13 report("sum_square");
270
271
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
272 2 test_neg_odd_64();
273 13 report("neg_odd_64");
274
275
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
276 2 test_qmf_pre_shuffle();
277 13 report("qmf_pre_shuffle");
278
279
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
280 2 test_qmf_post_shuffle();
281 13 report("qmf_post_shuffle");
282
283
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
284 2 test_qmf_deint_neg();
285 13 report("qmf_deint_neg");
286
287
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
288 2 test_qmf_deint_bfly();
289 13 report("qmf_deint_bfly");
290
291
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 10 times.
13 if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
292 3 test_autocorrelate();
293 13 report("autocorrelate");
294
295
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.hf_gen, "hf_gen"))
296 2 test_hf_gen();
297 13 report("hf_gen");
298
299
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
300 2 test_hf_g_filt();
301 13 report("hf_g_filt");
302
303 13 test_hf_apply_noise(&sbrdsp);
304 13 report("hf_apply_noise");
305 13 }
306