26 # ifndef DYNAMIC_CRC_TABLE
27 # define DYNAMIC_CRC_TABLE
36 #if !defined(NOBYFOUR) && defined(Z_U4)
40 local unsigned long crc32_little
OF((
unsigned long,
41 const unsigned char FAR *,
unsigned));
42 local unsigned long crc32_big
OF((
unsigned long,
43 const unsigned char FAR *,
unsigned));
56 #ifdef DYNAMIC_CRC_TABLE
58 local volatile int crc_table_empty = 1;
60 local void make_crc_table
OF((
void));
62 local void write_table
OF((FILE *,
const z_crc_t FAR *));
90 local void make_crc_table()
96 static volatile int first = 1;
97 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
107 for (n = 0; n < (
int)(
sizeof(p)/
sizeof(
unsigned char)); n++)
108 poly |= (z_crc_t)1 << (31 - p[
n]);
111 for (n = 0; n < 256; n++) {
113 for (k = 0; k < 8; k++)
114 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
121 for (n = 0; n < 256; n++) {
123 crc_table[4][
n] = ZSWAP32(c);
124 for (k = 1; k < 4; k++) {
125 c = crc_table[0][c & 0xff] ^ (c >> 8);
127 crc_table[k + 4][
n] = ZSWAP32(c);
136 while (crc_table_empty)
145 out = fopen(
"crc32.h",
"w");
146 if (out == NULL)
return;
147 fprintf(out,
"/* crc32.h -- tables for rapid CRC calculation\n");
148 fprintf(out,
" * Generated automatically by crc32.c\n */\n\n");
149 fprintf(out,
"local const z_crc_t FAR ");
150 fprintf(out,
"crc_table[TBLS][256] =\n{\n {\n");
151 write_table(out, crc_table[0]);
153 fprintf(out,
"#ifdef BYFOUR\n");
154 for (k = 1; k < 8; k++) {
155 fprintf(out,
" },\n {\n");
156 write_table(out, crc_table[k]);
158 fprintf(out,
"#endif\n");
160 fprintf(out,
" }\n};\n");
167 local void write_table(FILE *out,
const z_crc_t FAR * table)
171 for (n = 0; n < 256; n++)
172 fprintf(out,
"%s0x%08lxUL%s", n % 5 ?
"" :
" ",
173 (
unsigned long)(table[n]),
174 n == 255 ?
"\n" : (n % 5 == 4 ?
",\n" :
", "));
190 #ifdef DYNAMIC_CRC_TABLE
194 return (
const z_crc_t FAR *)crc_table;
198 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
199 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
202 unsigned long ZEXPORT
crc32(
unsigned long crc,
const unsigned char FAR *buf, uInt len)
204 if (buf == Z_NULL)
return 0UL;
206 #ifdef DYNAMIC_CRC_TABLE
212 if (
sizeof(
void *) ==
sizeof(ptrdiff_t)) {
216 if (*((
unsigned char *)(&endian)))
217 return crc32_little(crc, buf, len);
219 return crc32_big(crc, buf, len);
222 crc = crc ^ 0xffffffffUL;
230 return crc ^ 0xffffffffUL;
236 #define DOLIT4 c ^= *buf4++; \
237 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
238 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
239 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
242 local unsigned long crc32_little(
unsigned long crc,
const unsigned char FAR *buf,
unsigned len)
245 const z_crc_t FAR *buf4;
249 while (len && ((ptrdiff_t)buf & 3)) {
250 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
254 buf4 = (
const z_crc_t FAR *)(
const void FAR *)buf;
263 buf = (
const unsigned char FAR *)buf4;
266 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
269 return (
unsigned long)c;
273 #define DOBIG4 c ^= *++buf4; \
274 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
275 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
276 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
279 local unsigned long crc32_big(
unsigned long crc,
const unsigned char FAR *buf,
unsigned len)
282 const z_crc_t FAR *buf4;
284 c = ZSWAP32((z_crc_t)crc);
286 while (len && ((ptrdiff_t)buf & 3)) {
287 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
291 buf4 = (
const z_crc_t FAR *)(
const void FAR *)buf;
302 buf = (
const unsigned char FAR *)buf4;
305 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
308 return (
unsigned long)(ZSWAP32(c));
352 odd[0] = 0xedb88320UL;
354 for (n = 1; n <
GF2_DIM; n++) {
local unsigned long gf2_matrix_times OF((unsigned long *mat, unsigned long vec))
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
const z_crc_t FAR *ZEXPORT get_crc_table()
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
int(PTRFASTCALL *isName2)(const ENCODING *
local void gf2_matrix_square(unsigned long *square, unsigned long *mat)
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2)
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
local unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)