OLD | NEW |
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 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 */ | 20 */ |
21 | 21 |
22 #ifdef MAKECRCH | 22 #ifdef MAKECRCH |
23 # include <stdio.h> | 23 # include <stdio.h> |
24 # ifndef DYNAMIC_CRC_TABLE | 24 # ifndef DYNAMIC_CRC_TABLE |
25 # define DYNAMIC_CRC_TABLE | 25 # define DYNAMIC_CRC_TABLE |
26 # endif /* !DYNAMIC_CRC_TABLE */ | 26 # endif /* !DYNAMIC_CRC_TABLE */ |
27 #endif /* MAKECRCH */ | 27 #endif /* MAKECRCH */ |
28 | 28 |
| 29 #include "deflate.h" |
| 30 #include "x86.h" |
29 #include "zutil.h" /* for STDC and FAR definitions */ | 31 #include "zutil.h" /* for STDC and FAR definitions */ |
30 | 32 |
31 #define local static | 33 #define local static |
32 | 34 |
33 /* Find a four-byte integer type for crc32_little() and crc32_big(). */ | 35 /* Find a four-byte integer type for crc32_little() and crc32_big(). */ |
34 #ifndef NOBYFOUR | 36 #ifndef NOBYFOUR |
35 # ifdef STDC /* need ANSI C limits.h to determine sizes */ | 37 # ifdef STDC /* need ANSI C limits.h to determine sizes */ |
36 # include <limits.h> | 38 # include <limits.h> |
37 # define BYFOUR | 39 # define BYFOUR |
38 # if (UINT_MAX == 0xffffffffUL) | 40 # if (UINT_MAX == 0xffffffffUL) |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 return crc32_combine_(crc1, crc2, len2); | 435 return crc32_combine_(crc1, crc2, len2); |
434 } | 436 } |
435 | 437 |
436 uLong ZEXPORT crc32_combine64(crc1, crc2, len2) | 438 uLong ZEXPORT crc32_combine64(crc1, crc2, len2) |
437 uLong crc1; | 439 uLong crc1; |
438 uLong crc2; | 440 uLong crc2; |
439 z_off64_t len2; | 441 z_off64_t len2; |
440 { | 442 { |
441 return crc32_combine_(crc1, crc2, len2); | 443 return crc32_combine_(crc1, crc2, len2); |
442 } | 444 } |
| 445 |
| 446 ZLIB_INTERNAL void crc_reset(deflate_state *const s) |
| 447 { |
| 448 if (x86_cpu_enable_simd) { |
| 449 crc_fold_init(s); |
| 450 return; |
| 451 } |
| 452 s->strm->adler = crc32(0L, Z_NULL, 0); |
| 453 } |
| 454 |
| 455 ZLIB_INTERNAL void crc_finalize(deflate_state *const s) |
| 456 { |
| 457 if (x86_cpu_enable_simd) |
| 458 s->strm->adler = crc_fold_512to32(s); |
| 459 } |
| 460 |
| 461 ZLIB_INTERNAL void copy_with_crc(z_streamp strm, Bytef *dst, long size) |
| 462 { |
| 463 if (x86_cpu_enable_simd) { |
| 464 crc_fold_copy(strm->state, dst, strm->next_in, size); |
| 465 return; |
| 466 } |
| 467 zmemcpy(dst, strm->next_in, size); |
| 468 strm->adler = crc32(strm->adler, dst, size); |
| 469 } |
OLD | NEW |