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

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

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