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