24 # ifndef DYNAMIC_CRC_TABLE
25 # define DYNAMIC_CRC_TABLE
38 # if (UINT_MAX == 0xffffffffUL)
39 typedef unsigned int u4;
41 # if (ULONG_MAX == 0xffffffffUL)
42 typedef unsigned long u4;
44 # if (USHRT_MAX == 0xffffffffUL)
45 typedef unsigned short u4;
56 # define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
57 (((w)&0xff00)<<8)+(((w)&0xff)<<24))
58 local unsigned long crc32_little
OF((
unsigned long,
59 const unsigned char FAR *,
unsigned));
60 local unsigned long crc32_big
OF((
unsigned long,
61 const unsigned char FAR *,
unsigned));
74 #ifdef DYNAMIC_CRC_TABLE
76 local volatile int crc_table_empty = 1;
78 local void make_crc_table
OF((
void));
80 local void write_table
OF((FILE *,
const unsigned long FAR *));
108 local void make_crc_table()
114 static volatile int first = 1;
115 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
125 for (n = 0; n <
sizeof(
p)/
sizeof(
unsigned char); n++)
126 poly |= 1UL << (31 - p[n]);
129 for (n = 0; n < 256; n++) {
130 c = (
unsigned long)n;
131 for (k = 0; k < 8; k++)
132 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
139 for (n = 0; n < 256; n++) {
141 crc_table[4][
n] = REV(c);
142 for (k = 1; k < 4; k++) {
143 c = crc_table[0][c & 0xff] ^ (c >> 8);
145 crc_table[k + 4][
n] = REV(c);
154 while (crc_table_empty)
163 out = fopen(
"crc32.h",
"w");
164 if (out ==
NULL)
return;
165 fprintf(out,
"/* crc32.h -- tables for rapid CRC calculation\n");
166 fprintf(out,
" * Generated automatically by crc32.c\n */\n\n");
167 fprintf(out,
"local const unsigned long FAR ");
168 fprintf(out,
"crc_table[TBLS][256] =\n{\n {\n");
169 write_table(out, crc_table[0]);
171 fprintf(out,
"#ifdef BYFOUR\n");
172 for (k = 1; k < 8; k++) {
173 fprintf(out,
" },\n {\n");
174 write_table(out, crc_table[k]);
176 fprintf(out,
"#endif\n");
178 fprintf(out,
" }\n};\n");
191 for (n = 0; n < 256; n++)
192 fprintf(out,
"%s0x%08lxUL%s", n % 5 ?
"" :
" ", table[n],
193 n == 255 ?
"\n" : (n % 5 == 4 ?
",\n" :
", "));
209 #ifdef DYNAMIC_CRC_TABLE
217 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
218 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
226 if (buf ==
Z_NULL)
return 0UL;
228 #ifdef DYNAMIC_CRC_TABLE
234 if (
sizeof(
void *) ==
sizeof(ptrdiff_t)) {
238 if (*((
unsigned char *)(&endian)))
239 return crc32_little(crc, buf, len);
241 return crc32_big(crc, buf, len);
244 crc = crc ^ 0xffffffffUL;
252 return crc ^ 0xffffffffUL;
258 #define DOLIT4 c ^= *buf4++; \
259 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
260 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
261 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
270 register const u4
FAR *buf4;
274 while (len && ((ptrdiff_t)buf & 3)) {
275 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
279 buf4 = (
const u4
FAR *)(
const void FAR *)
buf;
288 buf = (
const unsigned char FAR *)buf4;
291 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
294 return (
unsigned long)
c;
298 #define DOBIG4 c ^= *++buf4; \
299 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
300 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
301 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
304 local unsigned long crc32_big(crc, buf, len)
310 register const u4
FAR *buf4;
314 while (len && ((ptrdiff_t)buf & 3)) {
315 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
319 buf4 = (
const u4
FAR *)(
const void FAR *)
buf;
330 buf = (
const unsigned char FAR *)buf4;
333 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
336 return (
unsigned long)(REV(c));
362 unsigned
long *square;
387 odd[0] = 0xedb88320UL;
389 for (n = 1; n <
GF2_DIM; n++) {
local void gf2_matrix_square(unsigned long *square, unsigned long *mat)
GLenum GLsizei GLenum GLenum const GLvoid * table
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
local unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
const unsigned long FAR *ZEXPORT get_crc_table()
GLenum GLenum GLvoid * row
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
local const unsigned long FAR crc_table[TBLS][256]
GLenum GLuint GLsizei const GLchar * buf