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));
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++) {
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(out, table)
173 for (n = 0; n < 256; n++)
174 fprintf(out,
"%s0x%08lxUL%s", n % 5 ?
"" :
" ",
175 (
unsigned long)(table[n]),
176 n == 255 ?
"\n" : (n % 5 == 4 ?
",\n" :
", "));
192 #ifdef DYNAMIC_CRC_TABLE
200 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
201 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
209 if (buf ==
Z_NULL)
return 0UL;
211 #ifdef DYNAMIC_CRC_TABLE
217 if (
sizeof(
void *) ==
sizeof(ptrdiff_t)) {
221 if (*((
unsigned char *)(&endian)))
222 return crc32_little(crc, buf, len);
224 return crc32_big(crc, buf, len);
227 crc = crc ^ 0xffffffffUL;
235 return crc ^ 0xffffffffUL;
241 #define DOLIT4 c ^= *buf4++; \
242 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
243 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
244 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
247 local unsigned long crc32_little(
crc, buf, len)
257 while (len && ((ptrdiff_t)buf & 3)) {
258 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
271 buf = (
const unsigned char FAR *)buf4;
274 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
277 return (
unsigned long)c;
281 #define DOBIG4 c ^= *++buf4; \
282 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
283 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
284 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
287 local unsigned long crc32_big(crc, buf, len)
297 while (len && ((ptrdiff_t)buf & 3)) {
298 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
313 buf = (
const unsigned char FAR *)buf4;
316 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
319 return (
unsigned long)(
ZSWAP32(c));
345 unsigned
long *square;
370 odd[0] = 0xedb88320UL;
372 for (n = 1; n <
GF2_DIM; n++) {