FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/af_afir.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 72 80 90.0%
Functions: 3 3 100.0%
Branches: 24 40 60.0%

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 "config.h"
20
21 #include <float.h>
22 #include <stdint.h>
23
24 #include "libavfilter/af_afirdsp.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/mem_internal.h"
27 #include "checkasm.h"
28
29 #define LEN 256
30
31 #define randomize_buffer(buf) \
32 do { \
33 int i; \
34 double bmg[2], stddev = 10.0, mean = 0.0; \
35 \
36 for (i = 0; i < BUF_SIZE; i += 2) { \
37 av_bmg_get(&checkasm_lfg, bmg); \
38 buf[i] = bmg[0] * stddev + mean; \
39 buf[i + 1] = bmg[1] * stddev + mean; \
40 } \
41 } while(0);
42
43 13 static void test_fcmul_add(AudioFIRDSPContext *fir)
44 {
45 #define BUF_SIZE LEN*2+8
46 13 LOCAL_ALIGNED_32(float, src0, [BUF_SIZE]);
47 13 LOCAL_ALIGNED_32(float, src1, [BUF_SIZE]);
48 13 LOCAL_ALIGNED_32(float, src2, [BUF_SIZE]);
49
50
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src0);
51
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src1);
52
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src2);
53
54
2/2
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 9 times.
13 if (check_func(fir->fcmul_add, "fcmul_add")) {
55 4 LOCAL_ALIGNED_32(float, cdst, [BUF_SIZE]);
56 4 LOCAL_ALIGNED_32(float, odst, [BUF_SIZE]);
57 int i;
58
59 4 declare_func(void, float *sum, const float *t, const float *c,
60 ptrdiff_t len);
61
62 4 memcpy(cdst, src0, (BUF_SIZE) * sizeof(float));
63 4 memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
64 4 call_ref(cdst, src1, src2, LEN);
65 4 call_new(odst, src1, src2, LEN);
66
2/2
✓ Branch 0 taken 2052 times.
✓ Branch 1 taken 4 times.
2056 for (i = 0; i <= LEN*2; i++) {
67 2052 int idx = i & ~1;
68 2052 float cre = src2[idx];
69 2052 float cim = src2[idx + 1];
70 2052 float tre = src1[idx];
71 2052 float tim = src1[idx + 1];
72 2052 double t = fabs(src0[i]) +
73 2052 fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
74 2052 fabs(tre * cre) + fabs(tim * cim) +
75 2052 fabs(tre * cim) + fabs(tim * cre) +
76 2052 fabs(tre * cre - tim * cim) +
77 2052 fabs(tre * cim + tim * cre) +
78 2052 fabs(cdst[i]) + 1.0;
79
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2052 times.
2052 if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
80 fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
81 i, cdst[i], odst[i], cdst[i] - odst[i]);
82 fail();
83 break;
84 }
85 }
86 4 memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
87
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 4 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.
4 bench_new(odst, src1, src2, LEN);
88 }
89
90 13 report("fcmul_add");
91 13 }
92
93 13 static void test_dcmul_add(AudioFIRDSPContext *fir)
94 {
95 #define BUF_SIZE LEN*2+8
96 13 LOCAL_ALIGNED_32(double, src0, [BUF_SIZE]);
97 13 LOCAL_ALIGNED_32(double, src1, [BUF_SIZE]);
98 13 LOCAL_ALIGNED_32(double, src2, [BUF_SIZE]);
99
100
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src0);
101
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src1);
102
2/2
✓ Branch 1 taken 3380 times.
✓ Branch 2 taken 13 times.
3393 randomize_buffer(src2);
103
104
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 12 times.
13 if (check_func(fir->dcmul_add, "dcmul_add")) {
105 1 LOCAL_ALIGNED_32(double, cdst, [BUF_SIZE]);
106 1 LOCAL_ALIGNED_32(double, odst, [BUF_SIZE]);
107 int i;
108
109 1 declare_func(void, double *sum, const double *t, const double *c,
110 ptrdiff_t len);
111
112 1 memcpy(cdst, src0, (BUF_SIZE) * sizeof(double));
113 1 memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
114 1 call_ref(cdst, src1, src2, LEN);
115 1 call_new(odst, src1, src2, LEN);
116
2/2
✓ Branch 0 taken 513 times.
✓ Branch 1 taken 1 times.
514 for (i = 0; i <= LEN*2; i++) {
117 513 int idx = i & ~1;
118 513 double cre = src2[idx];
119 513 double cim = src2[idx + 1];
120 513 double tre = src1[idx];
121 513 double tim = src1[idx + 1];
122 513 double t = fabs(src0[i]) +
123 513 fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
124 513 fabs(tre * cre) + fabs(tim * cim) +
125 513 fabs(tre * cim) + fabs(tim * cre) +
126 513 fabs(tre * cre - tim * cim) +
127 513 fabs(tre * cim + tim * cre) +
128 513 fabs(cdst[i]) + 1.0;
129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 513 times.
513 if (!double_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
130 fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
131 i, cdst[i], odst[i], cdst[i] - odst[i]);
132 fail();
133 break;
134 }
135 }
136 1 memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
137
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(odst, src1, src2, LEN);
138 }
139
140 13 report("dcmul_add");
141 13 }
142
143
144 13 void checkasm_check_afir(void)
145 {
146 13 AudioFIRDSPContext fir = { 0 };
147
148 13 ff_afir_init(&fir);
149 13 test_fcmul_add(&fir);
150 13 test_dcmul_add(&fir);
151 13 }
152