FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/flacdsp_lpc_template.c
Date: 2026-07-21 08:37:06
Exec Total Coverage
Lines: 44 64 68.8%
Functions: 4 4 100.0%
Branches: 25 49 51.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
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdint.h>
20 #include "libavutil/common.h"
21 #include "mathops.h"
22
23 #undef FUNC
24 #undef sum_type
25 #undef MUL
26 #undef CLIP
27 #undef FSUF
28
29 #define FUNC(n) AV_JOIN(n ## _, SAMPLE_SIZE)
30
31 #if SAMPLE_SIZE == 32
32 # define sum_type int64_t
33 # define MUL(a, b) MUL64(a, b)
34 # define CLIP(x) av_clipl_int32(x)
35 #else
36 # define sum_type int32_t
37 # define MUL(a, b) ((a) * (b))
38 # define CLIP(x) (x)
39 #endif
40
41 #define LPC1(x) { \
42 int c = coefs[(x)-1]; \
43 p0 += MUL(c, s); \
44 s = smp[i-(x)+1]; \
45 p1 += MUL(c, s); \
46 }
47
48 171002 static av_always_inline void FUNC(lpc_encode_unrolled)(int32_t *res,
49 const int32_t *smp, int len, int order,
50 const int32_t *coefs, int shift, int big)
51 {
52 int i;
53
2/2
✓ Branch 0 taken 157068091 times.
✓ Branch 1 taken 85501 times.
314307184 for (i = order; i < len; i += 2) {
54 314136182 int s = smp[i-order];
55 314136182 sum_type p0 = 0, p1 = 0;
56
2/2
✓ Branch 0 taken 5723294 times.
✓ Branch 1 taken 151344797 times.
314136182 if (big) {
57
2/25
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 3395124 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 2328170 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
11446588 switch (order) {
58 case 32: LPC1(32); av_fallthrough;
59 case 31: LPC1(31); av_fallthrough;
60 case 30: LPC1(30); av_fallthrough;
61 case 29: LPC1(29); av_fallthrough;
62 case 28: LPC1(28); av_fallthrough;
63 case 27: LPC1(27); av_fallthrough;
64 case 26: LPC1(26); av_fallthrough;
65 case 25: LPC1(25); av_fallthrough;
66 case 24: LPC1(24); av_fallthrough;
67 case 23: LPC1(23); av_fallthrough;
68 case 22: LPC1(22); av_fallthrough;
69 case 21: LPC1(21); av_fallthrough;
70 case 20: LPC1(20); av_fallthrough;
71 case 19: LPC1(19); av_fallthrough;
72 case 18: LPC1(18); av_fallthrough;
73 case 17: LPC1(17); av_fallthrough;
74 case 16: LPC1(16); av_fallthrough;
75 case 15: LPC1(15); av_fallthrough;
76 case 14: LPC1(14); av_fallthrough;
77 case 13: LPC1(13); av_fallthrough;
78 6790248 case 12: LPC1(12); av_fallthrough;
79 6790248 case 11: LPC1(11); av_fallthrough;
80 11446588 case 10: LPC1(10); av_fallthrough;
81 11446588 case 9: LPC1( 9)
82 11446588 LPC1( 8)
83 11446588 LPC1( 7)
84 11446588 LPC1( 6)
85 11446588 LPC1( 5)
86 11446588 LPC1( 4)
87 11446588 LPC1( 3)
88 11446588 LPC1( 2)
89 11446588 LPC1( 1)
90 }
91 } else {
92
8/9
✓ Branch 0 taken 131177983 times.
✓ Branch 1 taken 14467183 times.
✓ Branch 2 taken 3250024 times.
✓ Branch 3 taken 263042 times.
✓ Branch 4 taken 2119010 times.
✓ Branch 5 taken 57316 times.
✓ Branch 6 taken 2047 times.
✓ Branch 7 taken 8192 times.
✗ Branch 8 not taken.
302689594 switch (order) {
93 262355966 case 8: LPC1( 8); av_fallthrough;
94 291290332 case 7: LPC1( 7); av_fallthrough;
95 297790380 case 6: LPC1( 6); av_fallthrough;
96 298316464 case 5: LPC1( 5); av_fallthrough;
97 302554484 case 4: LPC1( 4); av_fallthrough;
98 302669116 case 3: LPC1( 3); av_fallthrough;
99 302673210 case 2: LPC1( 2); av_fallthrough;
100 302689594 case 1: LPC1( 1)
101 }
102 }
103 314136182 res[i ] = smp[i ] - CLIP(p0 >> shift);
104 314136182 res[i+1] = smp[i+1] - CLIP(p1 >> shift);
105 }
106 171002 }
107
108 171002 static void FUNC(flac_lpc_encode_c)(int32_t *res, const int32_t *smp, int len,
109 int order, const int32_t *coefs, int shift)
110 {
111 int i;
112
2/2
✓ Branch 0 taken 671769 times.
✓ Branch 1 taken 85501 times.
1514540 for (i = 0; i < order; i++)
113 1343538 res[i] = smp[i];
114 #if CONFIG_SMALL
115 for (i = order; i < len; i += 2) {
116 int j;
117 int s = smp[i];
118 sum_type p0 = 0, p1 = 0;
119 for (j = 0; j < order; j++) {
120 int c = coefs[j];
121 p1 += MUL(c, s);
122 s = smp[i-j-1];
123 p0 += MUL(c, s);
124 }
125 res[i ] = smp[i ] - CLIP(p0 >> shift);
126 res[i+1] = smp[i+1] - CLIP(p1 >> shift);
127 }
128 #else
129
9/9
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 335 times.
✓ Branch 4 taken 130 times.
✓ Branch 5 taken 1591 times.
✓ Branch 6 taken 9397 times.
✓ Branch 7 taken 73311 times.
✓ Branch 8 taken 704 times.
171002 switch (order) {
130 8 case 1: FUNC(lpc_encode_unrolled)(res, smp, len, 1, coefs, shift, 0); break;
131 2 case 2: FUNC(lpc_encode_unrolled)(res, smp, len, 2, coefs, shift, 0); break;
132 56 case 3: FUNC(lpc_encode_unrolled)(res, smp, len, 3, coefs, shift, 0); break;
133 670 case 4: FUNC(lpc_encode_unrolled)(res, smp, len, 4, coefs, shift, 0); break;
134 260 case 5: FUNC(lpc_encode_unrolled)(res, smp, len, 5, coefs, shift, 0); break;
135 3182 case 6: FUNC(lpc_encode_unrolled)(res, smp, len, 6, coefs, shift, 0); break;
136 18794 case 7: FUNC(lpc_encode_unrolled)(res, smp, len, 7, coefs, shift, 0); break;
137 146622 case 8: FUNC(lpc_encode_unrolled)(res, smp, len, 8, coefs, shift, 0); break;
138 1408 default: FUNC(lpc_encode_unrolled)(res, smp, len, order, coefs, shift, 1); break;
139 }
140 #endif
141 171002 }
142
143 /* Comment for clarity/de-obfuscation.
144 *
145 * for (int i = order; i < len; i++) {
146 * int32_t p = 0;
147 * for (int j = 0; j < order; j++) {
148 * int c = coefs[j];
149 * int s = smp[(i-1)-j];
150 * p += c*s;
151 * }
152 * res[i] = smp[i] - (p >> shift);
153 * }
154 *
155 * The CONFIG_SMALL code above simplifies to this, in the case of SAMPLE_SIZE
156 * not being equal to 32 (at the present time that means for 16-bit audio). The
157 * code above does 2 samples per iteration. Commit bfdd5bc (made all the way
158 * back in 2007) says that way is faster.
159 */
160