FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/crc_internal.h
Date: 2026-09-27 12:50:02
Exec Total Coverage
Lines: 16 28 57.1%
Functions: 1 2 50.0%
Branches: 6 10 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
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 ✗ static uint64_t reverse(uint64_t p, unsigned int deg)
27 {
28 ✗ uint64_t ret = 0;
29 int i;
30 ✗ for (i = 0; i < (deg / 8); i += 1) {
31 ✗ ret = (ret << 8) | (ff_reverse[p & 0xff]);
32 ✗ p >>= 8;
33 }
34 ✗ int rem = (deg + 1) - 8 * i;
35 ✗ ret = (ret << rem) | (ff_reverse[p & 0xff] >> (8 - rem));
36 ✗ return ret;
37 }
38
39 24 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 24 times.
24 if (n < deg) {
45 ✗ *div = 0;
46 ✗ return poly;
47 }
48 24 mask = ((uint64_t)1 << deg) - 1;
49 24 poly &= mask;
50 24 mod = poly;
51 24 *div = 1;
52 24 deg--;
53
2/2
✓ Branch 0 taken 5504 times.
✓ Branch 1 taken 24 times.
5528 while (--n > deg) {
54 5504 high = (mod >> deg) & 1;
55 5504 *div = (*div << 1) | high;
56 5504 mod <<= 1;
57
2/2
✓ Branch 0 taken 2572 times.
✓ Branch 1 taken 2932 times.
5504 if (high)
58 2572 mod ^= poly;
59 }
60 24 uint64_t ret = mod & mask;
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (bitreverse) {
62 ✗ *div = reverse(*div, deg) << 1;
63 ✗ return reverse(ret, deg) << 1;
64 }
65 24 return ret;
66 }
67
68 #endif /* AVUTIL_CRC_INTERNAL_H */
69