Changeset 133 for smplayer/vendor/current/zlib/crc32.c
- Timestamp:
- Oct 24, 2012, 7:56:20 PM (13 years ago)
- Location:
- smplayer/vendor/current/zlib
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
smplayer/vendor/current/zlib/crc32.c
r121 r133 1 1 /* crc32.c -- compute the CRC-32 of a data stream 2 * Copyright (C) 1995-2006, 2010, 2011 Mark Adler2 * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler 3 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 4 * … … 33 33 #define local static 34 34 35 /* Find a four-byte integer type for crc32_little() and crc32_big(). */36 #ifndef NOBYFOUR37 # ifdef STDC /* need ANSI C limits.h to determine sizes */38 # include <limits.h>39 # define BYFOUR40 # if (UINT_MAX == 0xffffffffUL)41 typedef unsigned int u4;42 # else43 # if (ULONG_MAX == 0xffffffffUL)44 typedef unsigned long u4;45 # else46 # if (USHRT_MAX == 0xffffffffUL)47 typedef unsigned short u4;48 # else49 # undef BYFOUR /* can't find a four-byte integer type! */50 # endif51 # endif52 # endif53 # endif /* STDC */54 #endif /* !NOBYFOUR */55 56 35 /* Definitions for doing the crc four data bytes at a time. */ 36 #if !defined(NOBYFOUR) && defined(Z_U4) 37 # define BYFOUR 38 #endif 57 39 #ifdef BYFOUR 58 typedef u4 crc_table_t;59 # define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \60 (((w)&0xff00)<<8)+(((w)&0xff)<<24))61 40 local unsigned long crc32_little OF((unsigned long, 62 41 const unsigned char FAR *, unsigned)); … … 65 44 # define TBLS 8 66 45 #else 67 typedef unsigned long crc_table_t;68 46 # define TBLS 1 69 47 #endif /* BYFOUR */ … … 79 57 80 58 local volatile int crc_table_empty = 1; 81 local crc_table_t FAR crc_table[TBLS][256];59 local z_crc_t FAR crc_table[TBLS][256]; 82 60 local void make_crc_table OF((void)); 83 61 #ifdef MAKECRCH 84 local void write_table OF((FILE *, const crc_table_t FAR *));62 local void write_table OF((FILE *, const z_crc_t FAR *)); 85 63 #endif /* MAKECRCH */ 86 64 /* … … 112 90 local void make_crc_table() 113 91 { 114 crc_table_t c;92 z_crc_t c; 115 93 int n, k; 116 crc_table_t poly;/* polynomial exclusive-or pattern */94 z_crc_t poly; /* polynomial exclusive-or pattern */ 117 95 /* terms of polynomial defining this crc (except x^32): */ 118 96 static volatile int first = 1; /* flag to limit concurrent making */ … … 128 106 poly = 0; 129 107 for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) 130 poly |= ( crc_table_t)1 << (31 - p[n]);108 poly |= (z_crc_t)1 << (31 - p[n]); 131 109 132 110 /* generate a crc for every 8-bit value */ 133 111 for (n = 0; n < 256; n++) { 134 c = ( crc_table_t)n;112 c = (z_crc_t)n; 135 113 for (k = 0; k < 8; k++) 136 114 c = c & 1 ? poly ^ (c >> 1) : c >> 1; … … 143 121 for (n = 0; n < 256; n++) { 144 122 c = crc_table[0][n]; 145 crc_table[4][n] = REV(c);123 crc_table[4][n] = ZSWAP32(c); 146 124 for (k = 1; k < 4; k++) { 147 125 c = crc_table[0][c & 0xff] ^ (c >> 8); 148 126 crc_table[k][n] = c; 149 crc_table[k + 4][n] = REV(c);127 crc_table[k + 4][n] = ZSWAP32(c); 150 128 } 151 129 } … … 169 147 fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 170 148 fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 171 fprintf(out, "local const crc_table_t FAR ");149 fprintf(out, "local const z_crc_t FAR "); 172 150 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 173 151 write_table(out, crc_table[0]); … … 189 167 local void write_table(out, table) 190 168 FILE *out; 191 const crc_table_t FAR *table;169 const z_crc_t FAR *table; 192 170 { 193 171 int n; … … 210 188 * This function can be used by asm versions of crc32() 211 189 */ 212 const unsigned longFAR * ZEXPORT get_crc_table()190 const z_crc_t FAR * ZEXPORT get_crc_table() 213 191 { 214 192 #ifdef DYNAMIC_CRC_TABLE … … 216 194 make_crc_table(); 217 195 #endif /* DYNAMIC_CRC_TABLE */ 218 return (const unsigned longFAR *)crc_table;196 return (const z_crc_t FAR *)crc_table; 219 197 } 220 198 … … 238 216 #ifdef BYFOUR 239 217 if (sizeof(void *) == sizeof(ptrdiff_t)) { 240 u4endian;218 z_crc_t endian; 241 219 242 220 endian = 1; … … 272 250 unsigned len; 273 251 { 274 register u4c;275 register const u4FAR *buf4;276 277 c = ( u4)crc;252 register z_crc_t c; 253 register const z_crc_t FAR *buf4; 254 255 c = (z_crc_t)crc; 278 256 c = ~c; 279 257 while (len && ((ptrdiff_t)buf & 3)) { … … 282 260 } 283 261 284 buf4 = (const u4FAR *)(const void FAR *)buf;262 buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 285 263 while (len >= 32) { 286 264 DOLIT32; … … 312 290 unsigned len; 313 291 { 314 register u4c;315 register const u4FAR *buf4;316 317 c = REV((u4)crc);292 register z_crc_t c; 293 register const z_crc_t FAR *buf4; 294 295 c = ZSWAP32((z_crc_t)crc); 318 296 c = ~c; 319 297 while (len && ((ptrdiff_t)buf & 3)) { … … 322 300 } 323 301 324 buf4 = (const u4FAR *)(const void FAR *)buf;302 buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 325 303 buf4--; 326 304 while (len >= 32) { … … 339 317 } while (--len); 340 318 c = ~c; 341 return (unsigned long)( REV(c));319 return (unsigned long)(ZSWAP32(c)); 342 320 } 343 321
Note:
See TracChangeset
for help on using the changeset viewer.