1 /* 7zCrcOpt.c -- CRC32 calculation : optimized version
2 2009-11-23 : Igor Pavlov : Public domain */
3 
4 #if defined(_WIN32)
5 #include <WinSock2.h>
6 #include <Windows.h>
7 #endif
8 
9 #include "CpuArch.h"
10 
11 #ifdef MY_CPU_LE
12 
13 #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
14 
CrcUpdateT4(UInt32 v,const void * data,size_t size,const UInt32 * table)15 UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
16 {
17   const Byte *p = (const Byte *)data;
18   for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
19     v = CRC_UPDATE_BYTE_2(v, *p);
20   for (; size >= 4; size -= 4, p += 4)
21   {
22     v ^= *(const UInt32 *)p;
23     v =
24       table[0x300 + (v & 0xFF)] ^
25       table[0x200 + ((v >> 8) & 0xFF)] ^
26       table[0x100 + ((v >> 16) & 0xFF)] ^
27       table[0x000 + ((v >> 24))];
28   }
29   for (; size > 0; size--, p++)
30     v = CRC_UPDATE_BYTE_2(v, *p);
31   return v;
32 }
33 
CrcUpdateT8(UInt32 v,const void * data,size_t size,const UInt32 * table)34 UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)
35 {
36   return CrcUpdateT4(v, data, size, table);
37 }
38 
39 #endif
40