allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / C / Common / CRC.cpp
blob92bc009c2ffe20a58710bb7954d663dffeec4f6f
1 // Common/CRC.cpp
3 #include "StdAfx.h"
5 #include "CRC.h"
7 static const UInt32 kCRCPoly = 0xEDB88320;
9 UInt32 CCRC::Table[256];
11 void CCRC::InitTable()
13 for (UInt32 i = 0; i < 256; i++)
15 UInt32 r = i;
16 for (int j = 0; j < 8; j++)
17 if (r & 1)
18 r = (r >> 1) ^ kCRCPoly;
19 else
20 r >>= 1;
21 CCRC::Table[i] = r;
25 class CCRCTableInit
27 public:
28 CCRCTableInit() { CCRC::InitTable(); }
29 } g_CRCTableInit;
31 void CCRC::UpdateByte(Byte b)
33 _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
36 void CCRC::UpdateUInt16(UInt16 v)
38 UpdateByte(Byte(v));
39 UpdateByte(Byte(v >> 8));
42 void CCRC::UpdateUInt32(UInt32 v)
44 for (int i = 0; i < 4; i++)
45 UpdateByte((Byte)(v >> (8 * i)));
48 void CCRC::UpdateUInt64(UInt64 v)
50 for (int i = 0; i < 8; i++)
51 UpdateByte((Byte)(v >> (8 * i)));
54 void CCRC::Update(const void *data, size_t size)
56 UInt32 v = _value;
57 const Byte *p = (const Byte *)data;
58 for (; size > 0 ; size--, p++)
59 v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);
60 _value = v;