text
stringlengths 0
2.2M
|
---|
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
|
const uint32_t* current = (const uint32_t*) data;
|
// process eight bytes at once (Slicing-by-8)
|
while (length >= 8)
|
{
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
uint32_t one = *current++ ^ swap(crc);
|
uint32_t two = *current++;
|
crc = Crc32Lookup[0][ two & 0xFF] ^
|
Crc32Lookup[1][(two>> 8) & 0xFF] ^
|
Crc32Lookup[2][(two>>16) & 0xFF] ^
|
Crc32Lookup[3][(two>>24) & 0xFF] ^
|
Crc32Lookup[4][ one & 0xFF] ^
|
Crc32Lookup[5][(one>> 8) & 0xFF] ^
|
Crc32Lookup[6][(one>>16) & 0xFF] ^
|
Crc32Lookup[7][(one>>24) & 0xFF];
|
#else
|
uint32_t one = *current++ ^ crc;
|
uint32_t two = *current++;
|
crc = Crc32Lookup[0][(two>>24) & 0xFF] ^
|
Crc32Lookup[1][(two>>16) & 0xFF] ^
|
Crc32Lookup[2][(two>> 8) & 0xFF] ^
|
Crc32Lookup[3][ two & 0xFF] ^
|
Crc32Lookup[4][(one>>24) & 0xFF] ^
|
Crc32Lookup[5][(one>>16) & 0xFF] ^
|
Crc32Lookup[6][(one>> 8) & 0xFF] ^
|
Crc32Lookup[7][ one & 0xFF];
|
#endif
|
length -= 8;
|
}
|
const uint8_t* currentChar = (const uint8_t*) current;
|
// remaining 1 to 7 bytes (standard algorithm)
|
while (length-- != 0)
|
crc = (crc >> 8) ^ Crc32Lookup[0][(crc & 0xFF) ^ *currentChar++];
|
return ~crc; // same as crc ^ 0xFFFFFFFF
|
}
|
/// compute CRC32 (Slicing-by-8 algorithm), unroll inner loop 4 times
|
uint32_t crc32_4x8bytes(const void* data, size_t length, uint32_t previousCrc32 = 0)
|
{
|
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
|
const uint32_t* current = (const uint32_t*) data;
|
// enabling optimization (at least -O2) automatically unrolls the inner for-loop
|
const size_t Unroll = 4;
|
const size_t BytesAtOnce = 8 * Unroll;
|
// process 4x eight bytes at once (Slicing-by-8)
|
while (length >= BytesAtOnce)
|
{
|
for (size_t unrolling = 0; unrolling < Unroll; unrolling++)
|
{
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
uint32_t one = *current++ ^ swap(crc);
|
uint32_t two = *current++;
|
crc = Crc32Lookup[0][ two & 0xFF] ^
|
Crc32Lookup[1][(two>> 8) & 0xFF] ^
|
Crc32Lookup[2][(two>>16) & 0xFF] ^
|
Crc32Lookup[3][(two>>24) & 0xFF] ^
|
Crc32Lookup[4][ one & 0xFF] ^
|
Crc32Lookup[5][(one>> 8) & 0xFF] ^
|
Crc32Lookup[6][(one>>16) & 0xFF] ^
|
Crc32Lookup[7][(one>>24) & 0xFF];
|
#else
|
uint32_t one = *current++ ^ crc;
|
uint32_t two = *current++;
|
crc = Crc32Lookup[0][(two>>24) & 0xFF] ^
|
Crc32Lookup[1][(two>>16) & 0xFF] ^
|
Crc32Lookup[2][(two>> 8) & 0xFF] ^
|
Crc32Lookup[3][ two & 0xFF] ^
|
Crc32Lookup[4][(one>>24) & 0xFF] ^
|
Crc32Lookup[5][(one>>16) & 0xFF] ^
|
Crc32Lookup[6][(one>> 8) & 0xFF] ^
|
Crc32Lookup[7][ one & 0xFF];
|
#endif
|
}
|
length -= BytesAtOnce;
|
}
|
const uint8_t* currentChar = (const uint8_t*) current;
|
// remaining 1 to 31 bytes (standard algorithm)
|
while (length-- != 0)
|
crc = (crc >> 8) ^ Crc32Lookup[0][(crc & 0xFF) ^ *currentChar++];
|
return ~crc; // same as crc ^ 0xFFFFFFFF
|
}
|
/// compute CRC32 (Slicing-by-16 algorithm)
|
uint32_t crc32_16bytes(const void* data, size_t length, uint32_t previousCrc32 = 0)
|
{
|
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
|
const uint32_t* current = (const uint32_t*) data;
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.