| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: crc32.c,v 1.4.4.4 2009/05/03 17:33:17 snj Exp $ */ | | 1 | /* $NetBSD: crc32.c,v 1.4.4.5 2009/05/03 22:25:25 snj Exp $ */ |
2 | | | 2 | |
3 | /* crc32.c -- compute the CRC-32 of a data stream | | 3 | /* crc32.c -- compute the CRC-32 of a data stream |
4 | * | | 4 | * |
5 | * Adapted from zlib's crc code. | | 5 | * Adapted from zlib's crc code. |
6 | * | | 6 | * |
7 | * Copyright (C) 1995-2005 Mark Adler | | 7 | * Copyright (C) 1995-2005 Mark Adler |
8 | * For conditions of distribution and use, see copyright notice in zlib.h | | 8 | * For conditions of distribution and use, see copyright notice in zlib.h |
9 | * | | 9 | * |
10 | * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster | | 10 | * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster |
11 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing | | 11 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing |
12 | * tables for updating the shift register in one step with three exclusive-ors | | 12 | * tables for updating the shift register in one step with three exclusive-ors |
13 | * instead of four steps with four exclusive-ors. This results in about a | | 13 | * instead of four steps with four exclusive-ors. This results in about a |
14 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. | | 14 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. |
| @@ -70,30 +70,27 @@ uint32_t crc32(uint32_t crc, const uint8 | | | @@ -70,30 +70,27 @@ uint32_t crc32(uint32_t crc, const uint8 |
70 | c = ~c; | | 70 | c = ~c; |
71 | return (uint32_t)c; | | 71 | return (uint32_t)c; |
72 | } | | 72 | } |
73 | | | 73 | |
74 | #else /* BIG_ENDIAN */ | | 74 | #else /* BIG_ENDIAN */ |
75 | | | 75 | |
76 | /* ========================================================================= */ | | 76 | /* ========================================================================= */ |
77 | #define DOBIG4 c ^= *++buf4; \ | | 77 | #define DOBIG4 c ^= *++buf4; \ |
78 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ | | 78 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ |
79 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] | | 79 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] |
80 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 | | 80 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 |
81 | | | 81 | |
82 | /* ========================================================================= */ | | 82 | /* ========================================================================= */ |
83 | uint32_t crc32( | | 83 | uint32_t crc32(uint32_t crc, const uint8_t *buf, size_t len) |
84 | uint32_t crc, | | | |
85 | const unsigned char *buf, | | | |
86 | unsigned len) | | | |
87 | { | | 84 | { |
88 | register u4 c; | | 85 | register u4 c; |
89 | register const u4 *buf4; | | 86 | register const u4 *buf4; |
90 | | | 87 | |
91 | if (buf == NULL) return 0UL; | | 88 | if (buf == NULL) return 0UL; |
92 | | | 89 | |
93 | c = REV((u4)crc); | | 90 | c = REV((u4)crc); |
94 | c = ~c; | | 91 | c = ~c; |
95 | while (len && ((uintptr_t)buf & 3)) { | | 92 | while (len && ((uintptr_t)buf & 3)) { |
96 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); | | 93 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); |
97 | len--; | | 94 | len--; |
98 | } | | 95 | } |
99 | | | 96 | |