| 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/reverse.h" | ||
| 24 | |||
| 25 | ✗ | static uint64_t reverse(uint64_t p, unsigned int deg) | |
| 26 | { | ||
| 27 | ✗ | uint64_t ret = 0; | |
| 28 | int i; | ||
| 29 | ✗ | for (i = 0; i < (deg / 8); i += 1) { | |
| 30 | ✗ | ret = (ret << 8) | (ff_reverse[p & 0xff]); | |
| 31 | ✗ | p >>= 8; | |
| 32 | } | ||
| 33 | ✗ | int rem = (deg + 1) - 8 * i; | |
| 34 | ✗ | ret = (ret << rem) | (ff_reverse[p & 0xff] >> (8 - rem)); | |
| 35 | ✗ | return ret; | |
| 36 | } | ||
| 37 | |||
| 38 | 24 | static uint64_t xnmodp(unsigned n, uint64_t poly, unsigned deg, uint64_t *div, int bitreverse) | |
| 39 | { | ||
| 40 | uint64_t mod, mask, high; | ||
| 41 | |||
| 42 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (n < deg) { |
| 43 | ✗ | *div = 0; | |
| 44 | ✗ | return poly; | |
| 45 | } | ||
| 46 | 24 | mask = ((uint64_t)1 << deg) - 1; | |
| 47 | 24 | poly &= mask; | |
| 48 | 24 | mod = poly; | |
| 49 | 24 | *div = 1; | |
| 50 | 24 | deg--; | |
| 51 |
2/2✓ Branch 0 taken 5504 times.
✓ Branch 1 taken 24 times.
|
5528 | while (--n > deg) { |
| 52 | 5504 | high = (mod >> deg) & 1; | |
| 53 | 5504 | *div = (*div << 1) | high; | |
| 54 | 5504 | mod <<= 1; | |
| 55 |
2/2✓ Branch 0 taken 2428 times.
✓ Branch 1 taken 3076 times.
|
5504 | if (high) |
| 56 | 2428 | mod ^= poly; | |
| 57 | } | ||
| 58 | 24 | uint64_t ret = mod & mask; | |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (bitreverse) { |
| 60 | ✗ | *div = reverse(*div, deg) << 1; | |
| 61 | ✗ | return reverse(ret, deg) << 1; | |
| 62 | } | ||
| 63 | 24 | return ret; | |
| 64 | } | ||
| 65 | |||
| 66 | #endif /* AVUTIL_CRC_INTERNAL_H */ | ||
| 67 |