25 # ifndef DYNAMIC_CRC_TABLE
26 # define DYNAMIC_CRC_TABLE
33 #if !defined(NOBYFOUR) && defined(Z_U4)
37 local unsigned long crc32_little
OF((
unsigned long,
38 const unsigned char FAR *, z_size_t));
39 local unsigned long crc32_big
OF((
unsigned long,
40 const unsigned char FAR *, z_size_t));
53 #ifdef DYNAMIC_CRC_TABLE
55 local volatile int crc_table_empty = 1;
57 local void make_crc_table
OF((
void));
59 local void write_table
OF((FILE *,
const z_crc_t FAR *));
87 local void make_crc_table()
93 static volatile int first = 1;
94 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
104 for (n = 0; n < (
int)(
sizeof(p)/
sizeof(
unsigned char)); n++)
105 poly |= (z_crc_t)1 << (31 - p[
n]);
108 for (n = 0; n < 256; n++) {
110 for (k = 0; k < 8; k++)
111 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
118 for (n = 0; n < 256; n++) {
121 for (k = 1; k < 4; k++) {
122 c = crc_table[0][c & 0xff] ^ (c >> 8);
133 while (crc_table_empty)
142 out = fopen(
"crc32.h",
"w");
143 if (out == NULL)
return;
144 fprintf(out,
"/* crc32.h -- tables for rapid CRC calculation\n");
145 fprintf(out,
" * Generated automatically by crc32.c\n */\n\n");
146 fprintf(out,
"local const z_crc_t FAR ");
147 fprintf(out,
"crc_table[TBLS][256] =\n{\n {\n");
148 write_table(out, crc_table[0]);
150 fprintf(out,
"#ifdef BYFOUR\n");
151 for (k = 1; k < 8; k++) {
152 fprintf(out,
" },\n {\n");
153 write_table(out, crc_table[k]);
155 fprintf(out,
"#endif\n");
157 fprintf(out,
" }\n};\n");
164 local void write_table(out, table)
166 const z_crc_t FAR *table;
170 for (n = 0; n < 256; n++)
171 fprintf(out,
"%s0x%08lxUL%s", n % 5 ?
"" :
" ",
172 (
unsigned long)(table[n]),
173 n == 255 ?
"\n" : (n % 5 == 4 ?
",\n" :
", "));
189 #ifdef DYNAMIC_CRC_TABLE
197 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
198 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
203 const
unsigned char FAR *buf;
206 if (buf ==
Z_NULL)
return 0UL;
208 #ifdef DYNAMIC_CRC_TABLE
214 if (
sizeof(
void *) ==
sizeof(ptrdiff_t)) {
218 if (*((
unsigned char *)(&endian)))
219 return crc32_little(crc, buf, len);
221 return crc32_big(crc, buf, len);
224 crc = crc ^ 0xffffffffUL;
232 return crc ^ 0xffffffffUL;
238 const
unsigned char FAR *buf;
259 #define DOLIT4 c ^= *buf4++; \
260 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
261 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
262 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
265 local unsigned long crc32_little(crc, buf,
len)
267 const
unsigned char FAR *buf;
271 register const z_crc_t FAR *buf4;
275 while (len && ((ptrdiff_t)buf & 3)) {
276 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
280 buf4 = (
const z_crc_t FAR *)(
const void FAR *)buf;
289 buf = (
const unsigned char FAR *)buf4;
292 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
295 return (
unsigned long)
c;
299 #define DOBIG4 c ^= *buf4++; \
300 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
301 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
302 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
305 local unsigned long crc32_big(crc, buf, len)
307 const
unsigned char FAR *buf;
311 register const z_crc_t FAR *buf4;
315 while (len && ((ptrdiff_t)buf & 3)) {
316 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
320 buf4 = (
const z_crc_t FAR *)(
const void FAR *)buf;
329 buf = (
const unsigned char FAR *)buf4;
332 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
335 return (
unsigned long)(
ZSWAP32(c));
386 odd[0] = 0xedb88320UL;
388 for (n = 1; n <
GF2_DIM; n++) {