I have the following code(manual version is from Adler's answer)
#include <iostream>
#include <nmmintrin.h>
#define POLY2 0x82f63b78
uint32_t crc32c2(uint32_t crc, const unsigned char *buf, size_t len)
{
int k;
crc = ~crc;
while (len--) {
crc ^= *buf++;
for (k = 0; k < 8; k++)
crc = crc & 1 ? (crc >> 1) ^ POLY2 : crc >> 1;
}
return ~crc;
}
int main(int argc, char **argv)
{
const unsigned int val = 5;
std::cout << std::hex << crc32c2(0,(const unsigned char*)&val,4) << std::endl;
std::cout << _mm_crc32_u32(0, 5) << std::endl;
}
Output is:
ee00d08c
a6679b4b
My question is why the manual version does not give the same answer as the intrisic.