Dear Andy,
I've tried the CRC32 macro , but still not work
it must be my code mistake somehow.
Could you kindly show me the code that how you use with CRC32 macro ?
My invalid code.
========================================================
unsigned long crc32(unsigned long crc, const unsigned char *buf, int len)
{
#define CRC32_POLYNOMIAL 0x00400007
unsigned long crc_table[256];
unsigned long crc32;
int i, j;
for (i = 0; i < 256; i++) {
crc32 = i;
for (j = 8; j > 0; j--) {
if (crc32 & 1)
crc32 = (crc32 >> 1) ^ CRC32_POLYNOMIAL;
else
crc32 >>= 1;
}
crc_table = crc32;
}
if (buf == NULL) return 0L;
#define CRC32(c,crc) ( crc_table[((int)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8 ) &0x00FFFFFFL))
#define DO1(buf) crc = CRC32(crc, *buf++)
#define DO2(buf) DO1(buf); DO1(buf)
#define DO4(buf) DO2(buf); DO2(buf)
#define DO8(buf) DO4(buf); DO4(buf)
crc = crc ^ 0xffffffffL;
#ifndef NO_UNROLLED_LOOPS
while (len >= 8 ) {
DO8(buf);
len -= 8;
}
#endif
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}
I've tried the CRC32 macro , but still not work
it must be my code mistake somehow.
Could you kindly show me the code that how you use with CRC32 macro ?
My invalid code.
========================================================
unsigned long crc32(unsigned long crc, const unsigned char *buf, int len)
{
#define CRC32_POLYNOMIAL 0x00400007
unsigned long crc_table[256];
unsigned long crc32;
int i, j;
for (i = 0; i < 256; i++) {
crc32 = i;
for (j = 8; j > 0; j--) {
if (crc32 & 1)
crc32 = (crc32 >> 1) ^ CRC32_POLYNOMIAL;
else
crc32 >>= 1;
}
crc_table = crc32;
}
if (buf == NULL) return 0L;
#define CRC32(c,crc) ( crc_table[((int)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8 ) &0x00FFFFFFL))
#define DO1(buf) crc = CRC32(crc, *buf++)
#define DO2(buf) DO1(buf); DO1(buf)
#define DO4(buf) DO2(buf); DO2(buf)
#define DO8(buf) DO4(buf); DO4(buf)
crc = crc ^ 0xffffffffL;
#ifndef NO_UNROLLED_LOOPS
while (len >= 8 ) {
DO8(buf);
len -= 8;
}
#endif
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}