FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/crc_internal.h
Date: 2026-09-26 05:01:43
Exec Total Coverage
Lines: 25 28 89.3%
Functions: 2 2 100.0%
Branches: 8 10 80.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 #ifndef AVUTIL_CRC_INTERNAL_H
20 #define AVUTIL_CRC_INTERNAL_H
21
22 #include <stdint.h>
23 #include "libavutil/attributes.h"
24 #include "libavutil/reverse.h"
25
26 48 static uint64_t reverse(uint64_t p, unsigned int deg)
27 {
28 48 uint64_t ret = 0;
29 int i;
30
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 48 times.
188 for (i = 0; i < (deg / 8); i += 1) {
31 140 ret = (ret << 8) | (ff_reverse[p & 0xff]);
32 140 p >>= 8;
33 }
34 48 int rem = (deg + 1) - 8 * i;
35 48 ret = (ret << rem) | (ff_reverse[p & 0xff] >> (8 - rem));
36 48 return ret;
37 }
38
39 20 av_unused static uint64_t xnmodp(unsigned n, uint64_t poly, unsigned deg,
40 uint64_t *div, int bitreverse)
41 {
42 uint64_t mod, mask, high;
43
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (n < deg) {
45 ✗ *div = 0;
46 ✗ return poly;
47 }
48 20 mask = ((uint64_t)1 << deg) - 1;
49 20 poly &= mask;
50 20 mod = poly;
51 20 *div = 1;
52 20 deg--;
53
2/2
✓ Branch 0 taken 4736 times.
✓ Branch 1 taken 20 times.
4756 while (--n > deg) {
54 4736 high = (mod >> deg) & 1;
55 4736 *div = (*div << 1) | high;
56 4736 mod <<= 1;
57
2/2
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 2344 times.
4736 if (high)
58 2392 mod ^= poly;
59 }
60 20 uint64_t ret = mod & mask;
61
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (bitreverse) {
62 20 *div = reverse(*div, deg) << 1;
63 20 return reverse(ret, deg) << 1;
64 }
65 ✗ return ret;
66 }
67
68 #endif /* AVUTIL_CRC_INTERNAL_H */
69