Garbage-collect the DYNAMIC_CRC_TABLE stuff. The table it computed
was incompatible with the new CRC code, and it is largely unnecessary now, since the static table is so much smaller. Fixes PR kern/20935.
This commit is contained in:
parent
bb218b78eb
commit
7a3fa51b7f
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile.gzboot,v 1.5 2002/04/25 22:30:38 thorpej Exp $
|
||||
# $NetBSD: Makefile.gzboot,v 1.6 2003/03/29 22:25:25 thorpej Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
@ -41,9 +41,6 @@ CPPFLAGS+= -DHEAP_SIZE=1048576 # 1M
|
||||
# libsa options
|
||||
CPPFLAGS+= -DHEAP_VARIABLE
|
||||
|
||||
# libz options
|
||||
CPPFLAGS+= -DDYNAMIC_CRC_TABLE
|
||||
|
||||
CPPFLAGS+= -DRELOC=${RELOC}
|
||||
CPPFLAGS+= -DMAXIMAGESIZE=${MAXIMAGESIZE}
|
||||
CPPFLAGS+= -DLOADADDR=${LOADADDR}
|
||||
|
@ -1,79 +1,22 @@
|
||||
/* $NetBSD: crc32.c,v 1.5 2003/03/25 22:48:44 mycroft Exp $ */
|
||||
/* $NetBSD: crc32.c,v 1.6 2003/03/29 22:25:26 thorpej Exp $ */
|
||||
|
||||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: crc32.c,v 1.5 2003/03/25 22:48:44 mycroft Exp $ */
|
||||
/* @(#) $Id: crc32.c,v 1.6 2003/03/29 22:25:26 thorpej Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#define local static
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
local int crc_table_empty = 1;
|
||||
local uLongf crc_table[256];
|
||||
local void make_crc_table __P((void));
|
||||
|
||||
/*
|
||||
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
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.
|
||||
|
||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||
with the lowest powers in the most significant bit. Then adding polynomials
|
||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||
one. If we call the above polynomial p, and represent a byte as the
|
||||
polynomial q, also with the lowest power in the most significant bit (so the
|
||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||
where a mod b means the remainder after dividing a by b.
|
||||
|
||||
This calculation is done using the shift-register method of multiplying and
|
||||
taking the remainder. The register is initialized to zero, and for each
|
||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||
out is a one). We start with the highest power (least significant bit) of
|
||||
q and repeat for all eight bits of q.
|
||||
|
||||
The table is simply the CRC of all possible eight bit values. This is all
|
||||
the information needed to generate CRC's on data a byte at a time for all
|
||||
combinations of CRC register values and incoming bytes.
|
||||
*/
|
||||
local void make_crc_table()
|
||||
{
|
||||
uLong c;
|
||||
int n, k;
|
||||
uLong poly; /* polynomial exclusive-or pattern */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||
|
||||
/* make exclusive-or pattern from polynomial (0xedb88320L) */
|
||||
poly = 0L;
|
||||
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
|
||||
poly |= 1L << (31 - p[n]);
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (uLong)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||
crc_table[n] = c;
|
||||
}
|
||||
crc_table_empty = 0;
|
||||
}
|
||||
#else
|
||||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by make_crc_table)
|
||||
*/
|
||||
local const uLongf crc_table[16] = {
|
||||
0x00000000L, 0x1db71064L, 0x3b6e20c8L, 0x26d930acL,
|
||||
0x76dc4190L, 0x6b6b51f4L, 0x4db26158L, 0x5005713cL,
|
||||
0xedb88320L, 0xf00f9344L, 0xd6d6a3e8L, 0xcb61b38cL,
|
||||
0x9b64c2b0L, 0x86d3d2d4L, 0xa00ae278L, 0xbdbdf21cL
|
||||
};
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DO1(buf) do { crc ^= *buf++; crc = (crc >> 4) ^ crc_table[crc & 0xf]; crc = (crc >> 4) ^ crc_table[crc & 0xf]; } while (0)
|
||||
@ -88,10 +31,6 @@ uLong ZEXPORT crc32(crc, buf, len)
|
||||
uInt len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0L;
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif
|
||||
crc = crc ^ 0xffffffffL;
|
||||
while (len >= 8)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user