FFmpeg
Loading...
Searching...
No Matches
crc_internal.h
Go to the documentation of this file.
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>
24#include "libavutil/reverse.h"
25
26static 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
39av_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 if (n < deg) {
45 *div = 0;
46 return poly;
47 }
48 mask = ((uint64_t)1 << deg) - 1;
49 poly &= mask;
50 mod = poly;
51 *div = 1;
52 deg--;
53 while (--n > deg) {
54 high = (mod >> deg) & 1;
55 *div = (*div << 1) | high;
56 mod <<= 1;
57 if (high)
58 mod ^= poly;
59 }
60 uint64_t ret = mod & mask;
61 if (bitreverse) {
62 *div = reverse(*div, deg) << 1;
63 return reverse(ret, deg) << 1;
64 }
65 return ret;
66}
67
68#endif /* AVUTIL_CRC_INTERNAL_H */
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static av_unused uint64_t xnmodp(unsigned n, uint64_t poly, unsigned deg, uint64_t *div, int bitreverse)
static uint64_t reverse(uint64_t p, unsigned int deg)
int high
Definition dovi_rpuenc.c:39
Macro definitions for various function/variable attributes.
#define av_unused
Definition attributes.h:164
const uint8_t ff_reverse[256]
Definition reverse.c:23
static const uint16_t mask[17]
Definition lzw.c:38
static int mod(int a, int b)
Modulo operation with only positive remainders.
Definition vf_v360.c:755