_mm_crc32_u8给出与参考代码不同的结果

我一直在努力与内在论。 特别是我使用标准CRC计算和所谓的等效intel内在函数得不到相同的结果。 我想转向使用_mm_crc32_u16_mm_crc32_u32但是如果我不能让8位操作工作就没有意义了。

 static UINT32 g_ui32CRC32Table[256] = { 0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL, 0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L, 0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L, .... // Your basic 32-bit CRC calculator // NOTE: this code cannot be changed UINT32 CalcCRC32(unsigned char *pucBuff, int iLen) { UINT32 crc = 0xFFFFFFFF; for (int x = 0; x > 8); } return crc ^ 0xFFFFFFFF; } UINT32 CalcCRC32_Intrinsic(unsigned char *pucBuff, int iLen) { UINT32 crc = 0xFFFFFFFF; for (int x = 0; x < iLen; x++) { crc = _mm_crc32_u8(crc, *pucBuff++); } return crc ^ 0xFFFFFFFF; } 

该表用于与英特尔指令使用的CRC多项式不同的CRC多项式。 该表适用于以太网/ ZIP /等。 CRC,通常称为CRC-32。 英特尔指令使用iSCSI(Castagnoli)多项式,用于CRC,通常称为CRC-32C。

这个简短的示例代码可以通过取消注释所需的多项式来计算:

 #include  #include  /* CRC-32 (Ethernet, ZIP, etc.) polynomial in reversed bit order. */ #define POLY 0xedb88320 /* CRC-32C (iSCSI) polynomial in reversed bit order. */ /* #define POLY 0x82f63b78 */ /* Compute CRC of buf[0..len-1] with initial CRC crc. This permits the computation of a CRC by feeding this routine a chunk of the input data at a time. The value of crc for the first chunk should be zero. */ uint32_t crc32c(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) ^ POLY : crc >> 1; } return ~crc; } 

您可以使用此代码通过简单地计算每个单字节消息0,1,2,…,255的CRC-32C来为您的代码生成替换表。