FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/ac3dsp.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 81 86 94.2%
Functions: 6 6 100.0%
Branches: 44 84 52.4%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
3 * Copyright (c) 2024 Geoff Hill <geoff@geoffhill.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <stdint.h>
23 #include <string.h>
24
25 #include "libavutil/mem.h"
26 #include "libavutil/mem_internal.h"
27
28 #include "libavcodec/ac3dsp.h"
29
30 #include "checkasm.h"
31
32 #define randomize_exp(buf, len) \
33 do { \
34 int i; \
35 for (i = 0; i < len; i++) { \
36 buf[i] = (uint8_t)rnd(); \
37 } \
38 } while (0)
39
40 #define randomize_i24(buf, len) \
41 do { \
42 int i; \
43 for (i = 0; i < len; i++) { \
44 int32_t v = (int32_t)rnd(); \
45 int32_t u = (v & 0xFFFFFF); \
46 buf[i] = (v < 0) ? -u : u; \
47 } \
48 } while (0)
49
50 #define randomize_float(buf, len) \
51 do { \
52 int i; \
53 for (i = 0; i < len; i++) { \
54 float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
55 buf[i] = f; \
56 } \
57 } while (0)
58
59 13 static void check_ac3_exponent_min(AC3DSPContext *c) {
60 #define MAX_COEFS 256
61 #define MAX_CTXT 6
62 #define EXP_SIZE (MAX_CTXT * MAX_COEFS)
63
64 13 LOCAL_ALIGNED_16(uint8_t, src, [EXP_SIZE]);
65 13 LOCAL_ALIGNED_16(uint8_t, v1, [EXP_SIZE]);
66 13 LOCAL_ALIGNED_16(uint8_t, v2, [EXP_SIZE]);
67 int n;
68
69 13 declare_func(void, uint8_t *, int, int);
70
71
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 13 times.
91 for (n = 0; n < MAX_CTXT; ++n) {
72
2/2
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 66 times.
78 if (check_func(c->ac3_exponent_min, "ac3_exponent_min_reuse%d", n)) {
73
2/2
✓ Branch 1 taken 18432 times.
✓ Branch 2 taken 12 times.
18444 randomize_exp(src, EXP_SIZE);
74
75 12 memcpy(v1, src, EXP_SIZE);
76 12 memcpy(v2, src, EXP_SIZE);
77
78 12 call_ref(v1, n, MAX_COEFS);
79 12 call_new(v2, n, MAX_COEFS);
80
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (memcmp(v1, v2, EXP_SIZE) != 0)
82 fail();
83
84
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 12 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.
12 bench_new(v2, n, MAX_COEFS);
85 }
86 }
87
88 13 report("ac3_exponent_min");
89 13 }
90
91 13 static void check_ac3_extract_exponents(AC3DSPContext *c) {
92 #define MAX_EXPS 3072
93 13 LOCAL_ALIGNED_16(int32_t, src, [MAX_EXPS]);
94 13 LOCAL_ALIGNED_16(uint8_t, v1, [MAX_EXPS]);
95 13 LOCAL_ALIGNED_16(uint8_t, v2, [MAX_EXPS]);
96 int n;
97
98 13 declare_func(void, uint8_t *, int32_t *, int);
99
100
2/2
✓ Branch 0 taken 143 times.
✓ Branch 1 taken 13 times.
156 for (n = 512; n <= MAX_EXPS; n += 256) {
101
2/2
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 110 times.
143 if (check_func(c->extract_exponents, "ac3_extract_exponents_n%d", n)) {
102
4/4
✓ Branch 1 taken 29790 times.
✓ Branch 2 taken 29346 times.
✓ Branch 3 taken 59136 times.
✓ Branch 4 taken 33 times.
59169 randomize_i24(src, n);
103
104 33 call_ref(v1, src, n);
105 33 call_new(v2, src, n);
106
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (memcmp(v1, v2, n) != 0)
108 fail();
109
110
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 33 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.
33 bench_new(v1, src, n);
111 }
112 }
113
114 13 report("ac3_extract_exponents");
115 13 }
116
117 13 static void check_float_to_fixed24(AC3DSPContext *c) {
118 #define BUF_SIZE 1024
119 13 LOCAL_ALIGNED_32(float, src, [BUF_SIZE]);
120
121 13 declare_func(void, int32_t *, const float *, size_t);
122
123
2/2
✓ Branch 1 taken 13312 times.
✓ Branch 2 taken 13 times.
13325 randomize_float(src, BUF_SIZE);
124
125
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 10 times.
13 if (check_func(c->float_to_fixed24, "float_to_fixed24")) {
126 3 LOCAL_ALIGNED_32(int32_t, dst, [BUF_SIZE]);
127 3 LOCAL_ALIGNED_32(int32_t, dst2, [BUF_SIZE]);
128
129 3 call_ref(dst, src, BUF_SIZE);
130 3 call_new(dst2, src, BUF_SIZE);
131
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (memcmp(dst, dst2, BUF_SIZE) != 0)
133 fail();
134
135
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(dst, src, BUF_SIZE);
136 }
137
138
139 13 report("float_to_fixed24");
140 13 }
141
142 13 static void check_ac3_sum_square_butterfly_int32(AC3DSPContext *c) {
143 #define ELEMS 240
144 13 LOCAL_ALIGNED_16(int32_t, lt, [ELEMS]);
145 13 LOCAL_ALIGNED_16(int32_t, rt, [ELEMS]);
146 13 LOCAL_ALIGNED_16(uint64_t, v1, [4]);
147 13 LOCAL_ALIGNED_16(uint64_t, v2, [4]);
148
149 13 declare_func(void, int64_t[4], const int32_t *, const int32_t *, int);
150
151
4/4
✓ Branch 1 taken 1561 times.
✓ Branch 2 taken 1559 times.
✓ Branch 3 taken 3120 times.
✓ Branch 4 taken 13 times.
3133 randomize_i24(lt, ELEMS);
152
4/4
✓ Branch 1 taken 1569 times.
✓ Branch 2 taken 1551 times.
✓ Branch 3 taken 3120 times.
✓ Branch 4 taken 13 times.
3133 randomize_i24(rt, ELEMS);
153
154
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 12 times.
13 if (check_func(c->sum_square_butterfly_int32,
155 "ac3_sum_square_bufferfly_int32")) {
156 1 call_ref(v1, lt, rt, ELEMS);
157 1 call_new(v2, lt, rt, ELEMS);
158
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (memcmp(v1, v2, sizeof(int64_t[4])) != 0)
160 fail();
161
162
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 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.
1 bench_new(v2, lt, rt, ELEMS);
163 }
164
165 13 report("ac3_sum_square_butterfly_int32");
166 13 }
167
168 13 static void check_ac3_sum_square_butterfly_float(AC3DSPContext *c) {
169 13 LOCAL_ALIGNED_32(float, lt, [ELEMS]);
170 13 LOCAL_ALIGNED_32(float, rt, [ELEMS]);
171 13 LOCAL_ALIGNED_16(float, v1, [4]);
172 13 LOCAL_ALIGNED_16(float, v2, [4]);
173
174 13 declare_func(void, float[4], const float *, const float *, int);
175
176
2/2
✓ Branch 1 taken 3120 times.
✓ Branch 2 taken 13 times.
3133 randomize_float(lt, ELEMS);
177
2/2
✓ Branch 1 taken 3120 times.
✓ Branch 2 taken 13 times.
3133 randomize_float(rt, ELEMS);
178
179
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 12 times.
13 if (check_func(c->sum_square_butterfly_float,
180 "ac3_sum_square_bufferfly_float")) {
181 1 call_ref(v1, lt, rt, ELEMS);
182 1 call_new(v2, lt, rt, ELEMS);
183
184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!float_near_ulp_array(v1, v2, 10, 4))
185 fail();
186
187
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 1 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.
1 bench_new(v2, lt, rt, ELEMS);
188 }
189
190 13 report("ac3_sum_square_butterfly_float");
191 13 }
192
193 13 void checkasm_check_ac3dsp(void)
194 {
195 AC3DSPContext c;
196 13 ff_ac3dsp_init(&c);
197
198 13 check_ac3_exponent_min(&c);
199 13 check_ac3_extract_exponents(&c);
200 13 check_float_to_fixed24(&c);
201 13 check_ac3_sum_square_butterfly_int32(&c);
202 13 check_ac3_sum_square_butterfly_float(&c);
203 13 }
204