Coverage Report

Created: 2026-08-11 07:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavutil/crc_internal.h
Line
Count
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
0
{
28
0
    uint64_t ret = 0;
29
0
    int i;
30
0
    for (i = 0; i < (deg / 8); i += 1) {
31
0
        ret = (ret << 8) | (ff_reverse[p & 0xff]);
32
0
        p >>= 8;
33
0
    }
34
0
    int rem = (deg + 1) - 8 * i;
35
0
    ret = (ret << rem) | (ff_reverse[p & 0xff] >> (8 - rem));
36
0
    return ret;
37
0
}
38
39
av_unused static uint64_t xnmodp(unsigned n, uint64_t poly, unsigned deg,
40
                                 uint64_t *div, int bitreverse)
41
0
{
42
0
    uint64_t mod, mask, high;
43
44
0
    if (n < deg) {
45
0
        *div = 0;
46
0
        return poly;
47
0
    }
48
0
    mask = ((uint64_t)1 << deg) - 1;
49
0
    poly &= mask;
50
0
    mod = poly;
51
0
    *div = 1;
52
0
    deg--;
53
0
    while (--n > deg) {
54
0
        high = (mod >> deg) & 1;
55
0
        *div = (*div << 1) | high;
56
0
        mod <<= 1;
57
0
        if (high)
58
0
            mod ^= poly;
59
0
    }
60
0
    uint64_t ret = mod & mask;
61
0
    if (bitreverse) {
62
0
        *div = reverse(*div, deg) << 1;
63
0
        return reverse(ret, deg) << 1;
64
0
    }
65
0
    return ret;
66
0
}
67
68
#endif /* AVUTIL_CRC_INTERNAL_H */