Deleted Added
full compact
crc32.c (17651) crc32.c (33904)
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-1996 Mark Adler
2 * Copyright (C) 1995-1998 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* $Id: crc32.c,v 1.8 1996/01/30 21:59:10 me Exp $ */
6/* @(#) $Id$ */
7
8#include "zlib.h"
9
10#define local static
11
12#ifdef DYNAMIC_CRC_TABLE
13
14local int crc_table_empty = 1;

--- 25 unchanged lines hidden (view full) ---

40 combinations of CRC register values and incoming bytes.
41*/
42local void make_crc_table()
43{
44 uLong c;
45 int n, k;
46 uLong poly; /* polynomial exclusive-or pattern */
47 /* terms of polynomial defining this crc (except x^32): */
7
8#include "zlib.h"
9
10#define local static
11
12#ifdef DYNAMIC_CRC_TABLE
13
14local int crc_table_empty = 1;

--- 25 unchanged lines hidden (view full) ---

40 combinations of CRC register values and incoming bytes.
41*/
42local void make_crc_table()
43{
44 uLong c;
45 int n, k;
46 uLong poly; /* polynomial exclusive-or pattern */
47 /* terms of polynomial defining this crc (except x^32): */
48 static Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
48 static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
49
50 /* make exclusive-or pattern from polynomial (0xedb88320L) */
51 poly = 0L;
52 for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
53 poly |= 1L << (31 - p[n]);
54
55 for (n = 0; n < 256; n++)
56 {
57 c = (uLong)n;
58 for (k = 0; k < 8; k++)
59 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
60 crc_table[n] = c;
61 }
62 crc_table_empty = 0;
63}
64#else
65/* ========================================================================
66 * Table of CRC-32's of all single-byte values (made by make_crc_table)
67 */
49
50 /* make exclusive-or pattern from polynomial (0xedb88320L) */
51 poly = 0L;
52 for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
53 poly |= 1L << (31 - p[n]);
54
55 for (n = 0; n < 256; n++)
56 {
57 c = (uLong)n;
58 for (k = 0; k < 8; k++)
59 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
60 crc_table[n] = c;
61 }
62 crc_table_empty = 0;
63}
64#else
65/* ========================================================================
66 * Table of CRC-32's of all single-byte values (made by make_crc_table)
67 */
68local uLongf crc_table[256] = {
68local const uLongf crc_table[256] = {
69 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
70 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
71 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
72 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
73 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
74 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
75 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
76 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,

--- 42 unchanged lines hidden (view full) ---

119 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
120 0x2d02ef8dL
121};
122#endif
123
124/* =========================================================================
125 * This function can be used by asm versions of crc32()
126 */
69 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
70 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
71 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
72 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
73 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
74 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
75 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
76 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,

--- 42 unchanged lines hidden (view full) ---

119 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
120 0x2d02ef8dL
121};
122#endif
123
124/* =========================================================================
125 * This function can be used by asm versions of crc32()
126 */
127uLongf *get_crc_table()
127const uLongf * ZEXPORT get_crc_table()
128{
129#ifdef DYNAMIC_CRC_TABLE
130 if (crc_table_empty) make_crc_table();
131#endif
128{
129#ifdef DYNAMIC_CRC_TABLE
130 if (crc_table_empty) make_crc_table();
131#endif
132 return (uLongf *)crc_table;
132 return (const uLongf *)crc_table;
133}
134
135/* ========================================================================= */
136#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
137#define DO2(buf) DO1(buf); DO1(buf);
138#define DO4(buf) DO2(buf); DO2(buf);
139#define DO8(buf) DO4(buf); DO4(buf);
140
141/* ========================================================================= */
133}
134
135/* ========================================================================= */
136#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
137#define DO2(buf) DO1(buf); DO1(buf);
138#define DO4(buf) DO2(buf); DO2(buf);
139#define DO8(buf) DO4(buf); DO4(buf);
140
141/* ========================================================================= */
142uLong crc32(crc, buf, len)
142uLong ZEXPORT crc32(crc, buf, len)
143 uLong crc;
144 const Bytef *buf;
145 uInt len;
146{
147 if (buf == Z_NULL) return 0L;
148#ifdef DYNAMIC_CRC_TABLE
149 if (crc_table_empty)
150 make_crc_table();

--- 12 unchanged lines hidden ---
143 uLong crc;
144 const Bytef *buf;
145 uInt len;
146{
147 if (buf == Z_NULL) return 0L;
148#ifdef DYNAMIC_CRC_TABLE
149 if (crc_table_empty)
150 make_crc_table();

--- 12 unchanged lines hidden ---