Crc32C Class Reference

#include <crc32c.h>

Detailed Description

This class implements a CRC32C generator which is based on the generator polynom x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+x^8+x^6+1 0x11EDC6F41 (the iSCSI CRC). If available the SSE4.2 instructions are used, otherwise it will be calculated by software. The returned CRC value is equal for all machines. All these examples should deliver the same result per line (0xcdee067a) on all systems: UpdateUInt64(0x1234567890abcdef) UpdateUInt32(0x90abcdef) UpdateUInt32(0x12345678) UpdateUInt16(0xcdef) UpdateUInt32(0x567890ab) UpdateUInt16(0x1234) UpdateUChar(0xef) UpdateUChar(0xcd) UpdateUInt32(0x567890ab) UpdateUChar(0x34) UpdateUChar(0x12) UInt64 val = 0x1234567890abcdef Update(&val, 8) see http://drdobbs.com/cpp/229401411 and http://download.intel.com/design/intarch/papers/323405.pdf for a parallelized CRC

Public Member Functions

 Crc32C ()
 
 Crc32C (UInt32 u)
 
UInt32 GetCrc () const
 
void Reset ()
 
void Set (UInt32 u)
 
const Crc32Coperator= (const Crc32C &other)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt64 (UInt64 u)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt32 (UInt32 u)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt16 (UInt16 u)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUChar (UChar u)
 
MAXON_ATTRIBUTE_FORCE_INLINE void Update (const Block< const Byte > &mem)
 
template<Int ALIGNMENT>
MAXON_ATTRIBUTE_FORCE_INLINE void Update (const Block< const Byte > &mem)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt (UInt u)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt64 (Int64 i)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt32 (Int32 i)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt16 (Int16 i)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt (Int i)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateChar (Char i)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateBool (Bool b)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat32 (Float32 r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat64 (Float64 r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat (Float r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d32 (const Vector2d32 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector32 (const Vector32 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d32 (const Vector4d32 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d64 (const Vector2d64 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector64 (const Vector64 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d64 (const Vector4d64 &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d (const Vector2d &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector (const Vector &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d (const Vector4d &r)
 
MAXON_ATTRIBUTE_FORCE_INLINE void UpdatePointer (const void *p)
 

Static Public Member Functions

static constexpr UInt32 GetResetValue ()
 

Static Public Attributes

static const UInt32 UNSET_VALUE
 

Protected Attributes

UInt32 _crc
 

Static Protected Attributes

static const UInt32 crc32tab_o32 [256]
 
static const UInt32 crc32tab_o40 [256]
 
static const UInt32 crc32tab_o48 [256]
 
static const UInt32 crc32tab_o56 [256]
 
static const UInt32 crc32tab_o64 [256]
 
static const UInt32 crc32tab_o72 [256]
 
static const UInt32 crc32tab_o80 [256]
 
static const UInt32 crc32tab_o88 [256]
 
static const UInt32 RESET_VALUE
 

Friends

Bool operator== (const Crc32C &a, const Crc32C &b)
 
Bool operator!= (const Crc32C &a, const Crc32C &b)
 

Constructor & Destructor Documentation

◆ Crc32C() [1/2]

Crc32C ( )

Constructs the object and resets its state.

◆ Crc32C() [2/2]

Crc32C ( UInt32  u)
explicit

Constructs the object and sets its state to a certain value.

Parameters
[in]uThe initial value.

Member Function Documentation

◆ GetCrc()

UInt32 GetCrc ( ) const

Gets the CRC value.

Returns
The CRC value.

◆ Reset()

void Reset ( void  )

Resets the state of this instance.

◆ Set()

void Set ( UInt32  u)

Constructs the objects and resets its state.

Parameters
[in]uThe new state value.

◆ operator=()

const Crc32C& operator= ( const Crc32C other)

Assigns another value.

Parameters
[in]otherThe new value.
Returns
A reference to itself.

◆ GetResetValue()

static constexpr UInt32 GetResetValue ( )
staticconstexpr

Gets the internal value of a reset class.

Returns
The reset value.

◆ UpdateUInt64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt64 ( UInt64  u)

Accumulates the CRC value.

Parameters
[in]uThe value used to accumulate the CRC value.

◆ UpdateUInt32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt32 ( UInt32  u)

Accumulates the CRC value.

Parameters
[in]uThe value used to accumulate the CRC value.

◆ UpdateUInt16()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt16 ( UInt16  u)

Accumulates the CRC value.

Parameters
[in]uThe value used to accumulate the CRC value.

◆ UpdateUChar()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUChar ( UChar  u)

Accumulates the CRC value.

Parameters
[in]uThe value used to accumulate the CRC value.

◆ Update() [1/2]

MAXON_ATTRIBUTE_FORCE_INLINE void Update ( const Block< const Byte > &  mem)

Accumulates the CRC value.

Parameters
[in]memA raw memory buffer.

◆ Update() [2/2]

MAXON_ATTRIBUTE_FORCE_INLINE void Update ( const Block< const Byte > &  mem)

Accumulates the CRC value.

Template Parameters
ALIGNMENTAlignment hint. Must be a power of 2.
Parameters
[in]memA raw memory buffer.

◆ UpdateUInt()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateUInt ( UInt  u)

Accumulates the CRC value.

Parameters
[in]uThe value used to accumulate the CRC value.

◆ UpdateInt64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt64 ( Int64  i)

Accumulates the CRC value.

Parameters
[in]iThe value used to accumulate the CRC value.

◆ UpdateInt32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt32 ( Int32  i)

Accumulates the CRC value.

Parameters
[in]iThe value used to accumulate the CRC value.

◆ UpdateInt16()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt16 ( Int16  i)

Accumulates the CRC value.

Parameters
[in]iThe value used to accumulate the CRC value.

◆ UpdateInt()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateInt ( Int  i)

Accumulates the CRC value.

Parameters
[in]iThe value used to accumulate the CRC value.

◆ UpdateChar()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateChar ( Char  i)

Accumulates the CRC value.

Parameters
[in]iThe value used to accumulate the CRC value.

◆ UpdateBool()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateBool ( Bool  b)

Accumulates the CRC value.

Parameters
[in]bThe value used to accumulate the CRC value.

◆ UpdateFloat32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat32 ( Float32  r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateFloat64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat64 ( Float64  r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateFloat()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateFloat ( Float  r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector2d32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d32 ( const Vector2d32 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector32 ( const Vector32 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector4d32()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d32 ( const Vector4d32 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector2d64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d64 ( const Vector2d64 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector64 ( const Vector64 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector4d64()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d64 ( const Vector4d64 r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector2d()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector2d ( const Vector2d r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector ( const Vector r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdateVector4d()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdateVector4d ( const Vector4d r)

Accumulates the CRC value.

Parameters
[in]rThe value used to accumulate the CRC value.

◆ UpdatePointer()

MAXON_ATTRIBUTE_FORCE_INLINE void UpdatePointer ( const void *  p)

Accumulates the CRC value.

Parameters
[in]pThe value used to accumulate the CRC value.

Friends And Related Function Documentation

◆ operator==

Bool operator== ( const Crc32C a,
const Crc32C b 
)
friend

Checks for equality.

Parameters
[in]aFirst operand.
[in]bSecond operand.
Returns
True, if both are equal.

◆ operator!=

Bool operator!= ( const Crc32C a,
const Crc32C b 
)
friend

Checks for inequality.

Parameters
[in]aFirst operand.
[in]bSecond operand.
Returns
True, if both are equal.

Member Data Documentation

◆ _crc

UInt32 _crc
protected

The CRC value that is accumulated.

◆ crc32tab_o32

const UInt32 crc32tab_o32[256]
staticprotected

A helper table for the software CRC.

◆ crc32tab_o40

const UInt32 crc32tab_o40[256]
staticprotected

◆ crc32tab_o48

const UInt32 crc32tab_o48[256]
staticprotected

◆ crc32tab_o56

const UInt32 crc32tab_o56[256]
staticprotected

◆ crc32tab_o64

const UInt32 crc32tab_o64[256]
staticprotected

◆ crc32tab_o72

const UInt32 crc32tab_o72[256]
staticprotected

◆ crc32tab_o80

const UInt32 crc32tab_o80[256]
staticprotected

◆ crc32tab_o88

const UInt32 crc32tab_o88[256]
staticprotected

◆ RESET_VALUE

const UInt32 RESET_VALUE
staticprotected

◆ UNSET_VALUE

const UInt32 UNSET_VALUE
static

Crc is most liekly unset if GetCrc returns UNSET_VALUE.