Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PG_CRC_H
00023 #define PG_CRC_H
00024
00025
00026 #ifdef FRONTEND
00027 #define CRCDLLIMPORT
00028 #else
00029 #define CRCDLLIMPORT PGDLLIMPORT
00030 #endif
00031
00032 typedef uint32 pg_crc32;
00033
00034
00035 #define INIT_CRC32(crc) ((crc) = 0xFFFFFFFF)
00036
00037
00038 #define FIN_CRC32(crc) ((crc) ^= 0xFFFFFFFF)
00039
00040
00041 #define COMP_CRC32(crc, data, len) \
00042 do { \
00043 const unsigned char *__data = (const unsigned char *) (data); \
00044 uint32 __len = (len); \
00045 \
00046 while (__len-- > 0) \
00047 { \
00048 int __tab_index = ((int) ((crc) >> 24) ^ *__data++) & 0xFF; \
00049 (crc) = pg_crc32_table[__tab_index] ^ ((crc) << 8); \
00050 } \
00051 } while (0)
00052
00053
00054 #define EQ_CRC32(c1,c2) ((c1) == (c2))
00055
00056
00057 extern CRCDLLIMPORT const uint32 pg_crc32_table[];
00058
00059
00060 #ifdef PROVIDE_64BIT_CRC
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #if SIZEOF_VOID_P < 8
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 typedef struct pg_crc64
00081 {
00082 uint32 crc0;
00083 uint32 crc1;
00084 } pg_crc64;
00085
00086
00087 #define INIT_CRC64(crc) ((crc).crc0 = 0xffffffff, (crc).crc1 = 0xffffffff)
00088
00089
00090 #define FIN_CRC64(crc) ((crc).crc0 ^= 0xffffffff, (crc).crc1 ^= 0xffffffff)
00091
00092
00093 #define COMP_CRC64(crc, data, len) \
00094 do { \
00095 uint32 __crc0 = (crc).crc0; \
00096 uint32 __crc1 = (crc).crc1; \
00097 unsigned char *__data = (unsigned char *) (data); \
00098 uint32 __len = (len); \
00099 \
00100 while (__len-- > 0) \
00101 { \
00102 int __tab_index = ((int) (__crc1 >> 24) ^ *__data++) & 0xFF; \
00103 __crc1 = pg_crc64_table1[__tab_index] ^ ((__crc1 << 8) | (__crc0 >> 24)); \
00104 __crc0 = pg_crc64_table0[__tab_index] ^ (__crc0 << 8); \
00105 } \
00106 (crc).crc0 = __crc0; \
00107 (crc).crc1 = __crc1; \
00108 } while (0)
00109
00110
00111 #define EQ_CRC64(c1,c2) ((c1).crc0 == (c2).crc0 && (c1).crc1 == (c2).crc1)
00112
00113
00114 extern CRCDLLIMPORT const uint32 pg_crc64_table0[];
00115 extern CRCDLLIMPORT const uint32 pg_crc64_table1[];
00116 #else
00117
00118 typedef struct pg_crc64
00119 {
00120 uint64 crc0;
00121 } pg_crc64;
00122
00123
00124 #define INIT_CRC64(crc) ((crc).crc0 = UINT64CONST(0xffffffffffffffff))
00125
00126
00127 #define FIN_CRC64(crc) ((crc).crc0 ^= UINT64CONST(0xffffffffffffffff))
00128
00129
00130 #define COMP_CRC64(crc, data, len) \
00131 do { \
00132 uint64 __crc0 = (crc).crc0; \
00133 unsigned char *__data = (unsigned char *) (data); \
00134 uint32 __len = (len); \
00135 \
00136 while (__len-- > 0) \
00137 { \
00138 int __tab_index = ((int) (__crc0 >> 56) ^ *__data++) & 0xFF; \
00139 __crc0 = pg_crc64_table[__tab_index] ^ (__crc0 << 8); \
00140 } \
00141 (crc).crc0 = __crc0; \
00142 } while (0)
00143
00144
00145 #define EQ_CRC64(c1,c2) ((c1).crc0 == (c2).crc0)
00146
00147
00148 extern CRCDLLIMPORT const uint64 pg_crc64_table[];
00149 #endif
00150 #endif
00151
00152 #endif