source: trunk/essentials/dev-lang/python/Modules/zlib/crc32.c

Last change on this file was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 12.9 KB
Line 
1/* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2005 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 *
5 * Thanks to Rodney Brown <[email protected]> for his contribution of faster
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
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.
10 */
11
12/* @(#) $Id$ */
13
14/*
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
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
19 one thread to use crc32().
20 */
21
22#ifdef MAKECRCH
23# include <stdio.h>
24# ifndef DYNAMIC_CRC_TABLE
25# define DYNAMIC_CRC_TABLE
26# endif /* !DYNAMIC_CRC_TABLE */
27#endif /* MAKECRCH */
28
29#include "zutil.h" /* for STDC and FAR definitions */
30
31#define local static
32
33/* Find a four-byte integer type for crc32_little() and crc32_big(). */
34#ifndef NOBYFOUR
35# ifdef STDC /* need ANSI C limits.h to determine sizes */
36# include <limits.h>
37# define BYFOUR
38# if (UINT_MAX == 0xffffffffUL)
39 typedef unsigned int u4;
40# else
41# if (ULONG_MAX == 0xffffffffUL)