1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-04 09:18:36 +03:00

crc: move static table

Move static table upward in the code so it can be shared with
another 'crc' implementation.
This commit is contained in:
Zdenek Kabelac 2024-10-04 14:02:06 +02:00 committed by David Teigland
parent 8bfbb623d7
commit 6de4590cf9

View File

@ -18,14 +18,11 @@
#include "lib/misc/crc.h"
#include "lib/mm/xlate.h"
/* Calculate an endian-independent CRC of supplied buffer */
#ifndef DEBUG_CRC32
uint32_t calc_crc(uint32_t initial, const uint8_t *buf, uint32_t size)
#else
static uint32_t _calc_crc_new(uint32_t initial, const uint8_t *buf, uint32_t size)
#endif
{
/* CRC-32 byte lookup table generated by crc_gen.c */
/*
* CRC-32 byte lookup table generated by crc_gen.c
*
* Precomputed lookup table for CRC computed with 0xedb88320 polynomial.
*/
static const uint32_t _crctab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
@ -60,6 +57,14 @@ static uint32_t _calc_crc_new(uint32_t initial, const uint8_t *buf, uint32_t siz
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
/* Calculate an endian-independent CRC of supplied buffer */
#ifndef DEBUG_CRC32
uint32_t calc_crc(uint32_t initial, const uint8_t *buf, uint32_t size)
#else
static uint32_t _calc_crc_new(uint32_t initial, const uint8_t *buf, uint32_t size)
#endif
{
const uint32_t *start = (const uint32_t *) buf;
const uint32_t *end = (const uint32_t *) (buf + (size & 0xfffffffc));
uint32_t crc = initial;