Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: third_party/zlib/crc32.c

Issue 2084863002: Update Zlib to version 1.2.8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/crc32.h ('k') | third_party/zlib/deflate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crc32.c -- compute the CRC-32 of a data stream 1 /* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2006, 2010 Mark Adler 2 * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * 4 *
5 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster 5 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
6 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 6 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
7 * tables for updating the shift register in one step with three exclusive-ors 7 * tables for updating the shift register in one step with three exclusive-ors
8 * instead of four steps with four exclusive-ors. This results in about a 8 * instead of four steps with four exclusive-ors. This results in about a
9 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 9 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
10 */ 10 */
11 11
12 /* @(#) $Id$ */ 12 /* @(#) $Id$ */
13 13
14 /* 14 /*
15 Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 15 Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
16 protection on the static variables used to control the first-use generation 16 protection on the static variables used to control the first-use generation
17 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 17 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
18 first call get_crc_table() to initialize the tables before allowing more than 18 first call get_crc_table() to initialize the tables before allowing more than
19 one thread to use crc32(). 19 one thread to use crc32().
20
21 DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
20 */ 22 */
21 23
22 #ifdef MAKECRCH 24 #ifdef MAKECRCH
23 # include <stdio.h> 25 # include <stdio.h>
24 # ifndef DYNAMIC_CRC_TABLE 26 # ifndef DYNAMIC_CRC_TABLE
25 # define DYNAMIC_CRC_TABLE 27 # define DYNAMIC_CRC_TABLE
26 # endif /* !DYNAMIC_CRC_TABLE */ 28 # endif /* !DYNAMIC_CRC_TABLE */
27 #endif /* MAKECRCH */ 29 #endif /* MAKECRCH */
28 30
29 #include "deflate.h" 31 #include "deflate.h"
30 #include "x86.h" 32 #include "x86.h"
31 #include "zutil.h" /* for STDC and FAR definitions */ 33 #include "zutil.h" /* for STDC and FAR definitions */
32 34
33 #define local static 35 #define local static
34 36
35 /* Find a four-byte integer type for crc32_little() and crc32_big(). */
36 #ifndef NOBYFOUR
37 # ifdef STDC /* need ANSI C limits.h to determine sizes */
38 # include <limits.h>
39 # define BYFOUR
40 # if (UINT_MAX == 0xffffffffUL)
41 typedef unsigned int u4;
42 # else
43 # if (ULONG_MAX == 0xffffffffUL)
44 typedef unsigned long u4;
45 # else
46 # if (USHRT_MAX == 0xffffffffUL)
47 typedef unsigned short u4;
48 # else
49 # undef BYFOUR /* can't find a four-byte integer type! */
50 # endif
51 # endif
52 # endif
53 # endif /* STDC */
54 #endif /* !NOBYFOUR */
55
56 /* Definitions for doing the crc four data bytes at a time. */ 37 /* Definitions for doing the crc four data bytes at a time. */
38 #if !defined(NOBYFOUR) && defined(Z_U4)
39 # define BYFOUR
40 #endif
57 #ifdef BYFOUR 41 #ifdef BYFOUR
58 # define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
59 (((w)&0xff00)<<8)+(((w)&0xff)<<24))
60 local unsigned long crc32_little OF((unsigned long, 42 local unsigned long crc32_little OF((unsigned long,
61 const unsigned char FAR *, unsigned)); 43 const unsigned char FAR *, unsigned));
62 local unsigned long crc32_big OF((unsigned long, 44 local unsigned long crc32_big OF((unsigned long,
63 const unsigned char FAR *, unsigned)); 45 const unsigned char FAR *, unsigned));
64 # define TBLS 8 46 # define TBLS 8
65 #else 47 #else
66 # define TBLS 1 48 # define TBLS 1
67 #endif /* BYFOUR */ 49 #endif /* BYFOUR */
68 50
69 /* Local functions for crc concatenation */ 51 /* Local functions for crc concatenation */
70 local unsigned long gf2_matrix_times OF((unsigned long *mat, 52 local unsigned long gf2_matrix_times OF((unsigned long *mat,
71 unsigned long vec)); 53 unsigned long vec));
72 local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 54 local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
73 local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2); 55 local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
74 56
75 57
76 #ifdef DYNAMIC_CRC_TABLE 58 #ifdef DYNAMIC_CRC_TABLE
77 59
78 local volatile int crc_table_empty = 1; 60 local volatile int crc_table_empty = 1;
79 local unsigned long FAR crc_table[TBLS][256]; 61 local z_crc_t FAR crc_table[TBLS][256];
80 local void make_crc_table OF((void)); 62 local void make_crc_table OF((void));
81 #ifdef MAKECRCH 63 #ifdef MAKECRCH
82 local void write_table OF((FILE *, const unsigned long FAR *)); 64 local void write_table OF((FILE *, const z_crc_t FAR *));
83 #endif /* MAKECRCH */ 65 #endif /* MAKECRCH */
84 /* 66 /*
85 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 67 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
86 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 68 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
87 69
88 Polynomials over GF(2) are represented in binary, one bit per coefficient, 70 Polynomials over GF(2) are represented in binary, one bit per coefficient,
89 with the lowest powers in the most significant bit. Then adding polynomials 71 with the lowest powers in the most significant bit. Then adding polynomials
90 is just exclusive-or, and multiplying a polynomial by x is a right shift by 72 is just exclusive-or, and multiplying a polynomial by x is a right shift by
91 one. If we call the above polynomial p, and represent a byte as the 73 one. If we call the above polynomial p, and represent a byte as the
92 polynomial q, also with the lowest power in the most significant bit (so the 74 polynomial q, also with the lowest power in the most significant bit (so the
93 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 75 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
94 where a mod b means the remainder after dividing a by b. 76 where a mod b means the remainder after dividing a by b.
95 77
96 This calculation is done using the shift-register method of multiplying and 78 This calculation is done using the shift-register method of multiplying and
97 taking the remainder. The register is initialized to zero, and for each 79 taking the remainder. The register is initialized to zero, and for each
98 incoming bit, x^32 is added mod p to the register if the bit is a one (where 80 incoming bit, x^32 is added mod p to the register if the bit is a one (where
99 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 81 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
100 x (which is shifting right by one and adding x^32 mod p if the bit shifted 82 x (which is shifting right by one and adding x^32 mod p if the bit shifted
101 out is a one). We start with the highest power (least significant bit) of 83 out is a one). We start with the highest power (least significant bit) of
102 q and repeat for all eight bits of q. 84 q and repeat for all eight bits of q.
103 85
104 The first table is simply the CRC of all possible eight bit values. This is 86 The first table is simply the CRC of all possible eight bit values. This is
105 all the information needed to generate CRCs on data a byte at a time for all 87 all the information needed to generate CRCs on data a byte at a time for all
106 combinations of CRC register values and incoming bytes. The remaining tables 88 combinations of CRC register values and incoming bytes. The remaining tables
107 allow for word-at-a-time CRC calculation for both big-endian and little- 89 allow for word-at-a-time CRC calculation for both big-endian and little-
108 endian machines, where a word is four bytes. 90 endian machines, where a word is four bytes.
109 */ 91 */
110 local void make_crc_table() 92 local void make_crc_table()
111 { 93 {
112 unsigned long c; 94 z_crc_t c;
113 int n, k; 95 int n, k;
114 unsigned long poly; /* polynomial exclusive-or pattern */ 96 z_crc_t poly; /* polynomial exclusive-or pattern */
115 /* terms of polynomial defining this crc (except x^32): */ 97 /* terms of polynomial defining this crc (except x^32): */
116 static volatile int first = 1; /* flag to limit concurrent making */ 98 static volatile int first = 1; /* flag to limit concurrent making */
117 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 99 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
118 100
119 /* See if another task is already doing this (not thread-safe, but better 101 /* See if another task is already doing this (not thread-safe, but better
120 than nothing -- significantly reduces duration of vulnerability in 102 than nothing -- significantly reduces duration of vulnerability in
121 case the advice about DYNAMIC_CRC_TABLE is ignored) */ 103 case the advice about DYNAMIC_CRC_TABLE is ignored) */
122 if (first) { 104 if (first) {
123 first = 0; 105 first = 0;
124 106
125 /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 107 /* make exclusive-or pattern from polynomial (0xedb88320UL) */
126 poly = 0UL; 108 poly = 0;
127 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) 109 for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
128 poly |= 1UL << (31 - p[n]); 110 poly |= (z_crc_t)1 << (31 - p[n]);
129 111
130 /* generate a crc for every 8-bit value */ 112 /* generate a crc for every 8-bit value */
131 for (n = 0; n < 256; n++) { 113 for (n = 0; n < 256; n++) {
132 c = (unsigned long)n; 114 c = (z_crc_t)n;
133 for (k = 0; k < 8; k++) 115 for (k = 0; k < 8; k++)
134 c = c & 1 ? poly ^ (c >> 1) : c >> 1; 116 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
135 crc_table[0][n] = c; 117 crc_table[0][n] = c;
136 } 118 }
137 119
138 #ifdef BYFOUR 120 #ifdef BYFOUR
139 /* generate crc for each value followed by one, two, and three zeros, 121 /* generate crc for each value followed by one, two, and three zeros,
140 and then the byte reversal of those as well as the first table */ 122 and then the byte reversal of those as well as the first table */
141 for (n = 0; n < 256; n++) { 123 for (n = 0; n < 256; n++) {
142 c = crc_table[0][n]; 124 c = crc_table[0][n];
143 crc_table[4][n] = REV(c); 125 crc_table[4][n] = ZSWAP32(c);
144 for (k = 1; k < 4; k++) { 126 for (k = 1; k < 4; k++) {
145 c = crc_table[0][c & 0xff] ^ (c >> 8); 127 c = crc_table[0][c & 0xff] ^ (c >> 8);
146 crc_table[k][n] = c; 128 crc_table[k][n] = c;
147 crc_table[k + 4][n] = REV(c); 129 crc_table[k + 4][n] = ZSWAP32(c);
148 } 130 }
149 } 131 }
150 #endif /* BYFOUR */ 132 #endif /* BYFOUR */
151 133
152 crc_table_empty = 0; 134 crc_table_empty = 0;
153 } 135 }
154 else { /* not first */ 136 else { /* not first */
155 /* wait for the other guy to finish (not efficient, but rare) */ 137 /* wait for the other guy to finish (not efficient, but rare) */
156 while (crc_table_empty) 138 while (crc_table_empty)
157 ; 139 ;
158 } 140 }
159 141
160 #ifdef MAKECRCH 142 #ifdef MAKECRCH
161 /* write out CRC tables to crc32.h */ 143 /* write out CRC tables to crc32.h */
162 { 144 {
163 FILE *out; 145 FILE *out;
164 146
165 out = fopen("crc32.h", "w"); 147 out = fopen("crc32.h", "w");
166 if (out == NULL) return; 148 if (out == NULL) return;
167 fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 149 fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
168 fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 150 fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
169 fprintf(out, "local const unsigned long FAR "); 151 fprintf(out, "local const z_crc_t FAR ");
170 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 152 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
171 write_table(out, crc_table[0]); 153 write_table(out, crc_table[0]);
172 # ifdef BYFOUR 154 # ifdef BYFOUR
173 fprintf(out, "#ifdef BYFOUR\n"); 155 fprintf(out, "#ifdef BYFOUR\n");
174 for (k = 1; k < 8; k++) { 156 for (k = 1; k < 8; k++) {
175 fprintf(out, " },\n {\n"); 157 fprintf(out, " },\n {\n");
176 write_table(out, crc_table[k]); 158 write_table(out, crc_table[k]);
177 } 159 }
178 fprintf(out, "#endif\n"); 160 fprintf(out, "#endif\n");
179 # endif /* BYFOUR */ 161 # endif /* BYFOUR */
180 fprintf(out, " }\n};\n"); 162 fprintf(out, " }\n};\n");
181 fclose(out); 163 fclose(out);
182 } 164 }
183 #endif /* MAKECRCH */ 165 #endif /* MAKECRCH */
184 } 166 }
185 167
186 #ifdef MAKECRCH 168 #ifdef MAKECRCH
187 local void write_table(out, table) 169 local void write_table(out, table)
188 FILE *out; 170 FILE *out;
189 const unsigned long FAR *table; 171 const z_crc_t FAR *table;
190 { 172 {
191 int n; 173 int n;
192 174
193 for (n = 0; n < 256; n++) 175 for (n = 0; n < 256; n++)
194 fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], 176 fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
177 (unsigned long)(table[n]),
195 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 178 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
196 } 179 }
197 #endif /* MAKECRCH */ 180 #endif /* MAKECRCH */
198 181
199 #else /* !DYNAMIC_CRC_TABLE */ 182 #else /* !DYNAMIC_CRC_TABLE */
200 /* ======================================================================== 183 /* ========================================================================
201 * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 184 * Tables of CRC-32s of all single-byte values, made by make_crc_table().
202 */ 185 */
203 #include "crc32.h" 186 #include "crc32.h"
204 #endif /* DYNAMIC_CRC_TABLE */ 187 #endif /* DYNAMIC_CRC_TABLE */
205 188
206 /* ========================================================================= 189 /* =========================================================================
207 * This function can be used by asm versions of crc32() 190 * This function can be used by asm versions of crc32()
208 */ 191 */
209 const unsigned long FAR * ZEXPORT get_crc_table() 192 const z_crc_t FAR * ZEXPORT get_crc_table()
210 { 193 {
211 #ifdef DYNAMIC_CRC_TABLE 194 #ifdef DYNAMIC_CRC_TABLE
212 if (crc_table_empty) 195 if (crc_table_empty)
213 make_crc_table(); 196 make_crc_table();
214 #endif /* DYNAMIC_CRC_TABLE */ 197 #endif /* DYNAMIC_CRC_TABLE */
215 return (const unsigned long FAR *)crc_table; 198 return (const z_crc_t FAR *)crc_table;
216 } 199 }
217 200
218 /* ========================================================================= */ 201 /* ========================================================================= */
219 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 202 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
220 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 203 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
221 204
222 /* ========================================================================= */ 205 /* ========================================================================= */
223 unsigned long ZEXPORT crc32(crc, buf, len) 206 unsigned long ZEXPORT crc32(crc, buf, len)
224 unsigned long crc; 207 unsigned long crc;
225 const unsigned char FAR *buf; 208 const unsigned char FAR *buf;
226 uInt len; 209 uInt len;
227 { 210 {
228 if (buf == Z_NULL) return 0UL; 211 if (buf == Z_NULL) return 0UL;
229 212
230 #ifdef DYNAMIC_CRC_TABLE 213 #ifdef DYNAMIC_CRC_TABLE
231 if (crc_table_empty) 214 if (crc_table_empty)
232 make_crc_table(); 215 make_crc_table();
233 #endif /* DYNAMIC_CRC_TABLE */ 216 #endif /* DYNAMIC_CRC_TABLE */
234 217
235 #ifdef BYFOUR 218 #ifdef BYFOUR
236 if (sizeof(void *) == sizeof(ptrdiff_t)) { 219 if (sizeof(void *) == sizeof(ptrdiff_t)) {
237 u4 endian; 220 z_crc_t endian;
238 221
239 endian = 1; 222 endian = 1;
240 if (*((unsigned char *)(&endian))) 223 if (*((unsigned char *)(&endian)))
241 return crc32_little(crc, buf, len); 224 return crc32_little(crc, buf, len);
242 else 225 else
243 return crc32_big(crc, buf, len); 226 return crc32_big(crc, buf, len);
244 } 227 }
245 #endif /* BYFOUR */ 228 #endif /* BYFOUR */
246 crc = crc ^ 0xffffffffUL; 229 crc = crc ^ 0xffffffffUL;
247 while (len >= 8) { 230 while (len >= 8) {
(...skipping 13 matching lines...) Expand all
261 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 244 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
262 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 245 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
263 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 246 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
264 247
265 /* ========================================================================= */ 248 /* ========================================================================= */
266 local unsigned long crc32_little(crc, buf, len) 249 local unsigned long crc32_little(crc, buf, len)
267 unsigned long crc; 250 unsigned long crc;
268 const unsigned char FAR *buf; 251 const unsigned char FAR *buf;
269 unsigned len; 252 unsigned len;
270 { 253 {
271 register u4 c; 254 register z_crc_t c;
272 register const u4 FAR *buf4; 255 register const z_crc_t FAR *buf4;
273 256
274 c = (u4)crc; 257 c = (z_crc_t)crc;
275 c = ~c; 258 c = ~c;
276 while (len && ((ptrdiff_t)buf & 3)) { 259 while (len && ((ptrdiff_t)buf & 3)) {
277 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 260 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
278 len--; 261 len--;
279 } 262 }
280 263
281 buf4 = (const u4 FAR *)(const void FAR *)buf; 264 buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
282 while (len >= 32) { 265 while (len >= 32) {
283 DOLIT32; 266 DOLIT32;
284 len -= 32; 267 len -= 32;
285 } 268 }
286 while (len >= 4) { 269 while (len >= 4) {
287 DOLIT4; 270 DOLIT4;
288 len -= 4; 271 len -= 4;
289 } 272 }
290 buf = (const unsigned char FAR *)buf4; 273 buf = (const unsigned char FAR *)buf4;
291 274
292 if (len) do { 275 if (len) do {
293 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 276 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
294 } while (--len); 277 } while (--len);
295 c = ~c; 278 c = ~c;
296 return (unsigned long)c; 279 return (unsigned long)c;
297 } 280 }
298 281
299 /* ========================================================================= */ 282 /* ========================================================================= */
300 #define DOBIG4 c ^= *++buf4; \ 283 #define DOBIG4 c ^= *++buf4; \
301 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 284 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
302 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 285 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
303 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 286 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
304 287
305 /* ========================================================================= */ 288 /* ========================================================================= */
306 local unsigned long crc32_big(crc, buf, len) 289 local unsigned long crc32_big(crc, buf, len)
307 unsigned long crc; 290 unsigned long crc;
308 const unsigned char FAR *buf; 291 const unsigned char FAR *buf;
309 unsigned len; 292 unsigned len;
310 { 293 {
311 register u4 c; 294 register z_crc_t c;
312 register const u4 FAR *buf4; 295 register const z_crc_t FAR *buf4;
313 296
314 c = REV((u4)crc); 297 c = ZSWAP32((z_crc_t)crc);
315 c = ~c; 298 c = ~c;
316 while (len && ((ptrdiff_t)buf & 3)) { 299 while (len && ((ptrdiff_t)buf & 3)) {
317 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 300 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
318 len--; 301 len--;
319 } 302 }
320 303
321 buf4 = (const u4 FAR *)(const void FAR *)buf; 304 buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
322 buf4--; 305 buf4--;
323 while (len >= 32) { 306 while (len >= 32) {
324 DOBIG32; 307 DOBIG32;
325 len -= 32; 308 len -= 32;
326 } 309 }
327 while (len >= 4) { 310 while (len >= 4) {
328 DOBIG4; 311 DOBIG4;
329 len -= 4; 312 len -= 4;
330 } 313 }
331 buf4++; 314 buf4++;
332 buf = (const unsigned char FAR *)buf4; 315 buf = (const unsigned char FAR *)buf4;
333 316
334 if (len) do { 317 if (len) do {
335 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 318 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
336 } while (--len); 319 } while (--len);
337 c = ~c; 320 c = ~c;
338 return (unsigned long)(REV(c)); 321 return (unsigned long)(ZSWAP32(c));
339 } 322 }
340 323
341 #endif /* BYFOUR */ 324 #endif /* BYFOUR */
342 325
343 #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 326 #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
344 327
345 /* ========================================================================= */ 328 /* ========================================================================= */
346 local unsigned long gf2_matrix_times(mat, vec) 329 local unsigned long gf2_matrix_times(mat, vec)
347 unsigned long *mat; 330 unsigned long *mat;
348 unsigned long vec; 331 unsigned long vec;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 443
461 ZLIB_INTERNAL void copy_with_crc(z_streamp strm, Bytef *dst, long size) 444 ZLIB_INTERNAL void copy_with_crc(z_streamp strm, Bytef *dst, long size)
462 { 445 {
463 if (x86_cpu_enable_simd) { 446 if (x86_cpu_enable_simd) {
464 crc_fold_copy(strm->state, dst, strm->next_in, size); 447 crc_fold_copy(strm->state, dst, strm->next_in, size);
465 return; 448 return;
466 } 449 }
467 zmemcpy(dst, strm->next_in, size); 450 zmemcpy(dst, strm->next_in, size);
468 strm->adler = crc32(strm->adler, dst, size); 451 strm->adler = crc32(strm->adler, dst, size);
469 } 452 }
OLDNEW
« no previous file with comments | « third_party/zlib/crc32.h ('k') | third_party/zlib/deflate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698