26 template <
size_t Polynomial,
size_t NumTables>
29 std::array<uint32_t, 256 * NumTables>
table = {};
33 for (uint32_t i = 0; i < 256; i++) {
35 r = ((r & 1) * Polynomial) ^ (r >> 1);
36 r = ((r & 1) * Polynomial) ^ (r >> 1);
37 r = ((r & 1) * Polynomial) ^ (r >> 1);
38 r = ((r & 1) * Polynomial) ^ (r >> 1);
39 r = ((r & 1) * Polynomial) ^ (r >> 1);
40 r = ((r & 1) * Polynomial) ^ (r >> 1);
41 r = ((r & 1) * Polynomial) ^ (r >> 1);
42 r = ((r & 1) * Polynomial) ^ (r >> 1);
45 for (
size_t i = 256; i <
table.size(); i++) {
46 uint32_t value =
table[i - 256];
57 return (uint32_t(
data[0]) << 0) | (uint32_t(
data[1]) << 8) | (uint32_t(
data[2]) << 16) |
58 (uint32_t(
data[3]) << 24);
74 inline uint32_t
crc32Update(
const uint32_t prev,
const std::byte*
const data,
const size_t length) {
78 for (; (
uintptr_t(
data + offset) &
alignof(uint32_t)) != 0 && offset < length; offset++) {
81 if (offset == length) {
86 size_t remainingBytes = length - offset;
87 for (; remainingBytes >= 8; offset += 8, remainingBytes -= 8) {
97 for (; offset < length; offset++) {
105 return crc ^ 0xffffffff;