You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

#include <internal/crc.h>
static const uint32_t __h_crc_poly = 0xedb88320u;
static uint32_t __h_crc_table[_H_CRC_TABLE_SIZE];
static _Atomic volatile int __h_crc_initialised=0;
static _Atomic volatile int __initialising=0;
static uint32_t* __h_crc_create_table(uint32_t* table, uint32_t poly)
{
register int i=0;
for(;i<_H_CRC_TABLE_SIZE;i++)
{
register int j=0;
uint32_t e = (uint32_t)i;
for(;j<_H_CRC_ITERATIONS;j++)
{
if( (e&1) == 1)
e = (e>>1) ^ poly;
else e = e>>1;
}
table[i] = e;
}
return table;
}
static uint32_t __h_crc_calc(uint32_t* table, uint32_t seed, const unsigned char* buffer, int len)
{
uint32_t crc= seed;
register int i=0;
for(;i<len;i++)
{
crc = (crc>>8) ^ table[(buffer[i] ^ crc) & 0xff];
}
return crc;
}
unsigned long _h_crc32(unsigned long seed, const unsigned char* buffer,unsigned int len)
{
while(__initialising) (void)0;
if(!__h_crc_initialised)
{
__initialising=1;
__h_crc_create_table(__h_crc_table,__h_crc_poly);
__h_crc_initialised=1;
__initialising=0;
}
return ~__h_crc_calc(__h_crc_table, (uint32_t) seed, buffer, (int)len);
}