mirror of
https://github.com/Pecusx/libretro-atari800.git
synced 2026-05-20 22:33:22 +02:00
55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
/* crc32.c -- compute the CRC-32 of a data stream
|
|
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
*
|
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
|
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
|
* tables for updating the shift register in one step with three exclusive-ors
|
|
* instead of four steps with four exclusive-ors. This results in about a
|
|
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
|
*/
|
|
|
|
/* @(#) $Id$ */
|
|
|
|
#include "zutil.h" /* for STDC and FAR definitions */
|
|
|
|
#define local static
|
|
|
|
#define TBLS 1
|
|
|
|
/* ========================================================================
|
|
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
|
*/
|
|
#include "crc32.h"
|
|
|
|
/* =========================================================================
|
|
* This function can be used by asm versions of crc32()
|
|
*/
|
|
const z_crc_t FAR * ZEXPORT get_crc_table()
|
|
{
|
|
return (const z_crc_t FAR *)crc_table;
|
|
}
|
|
|
|
/* ========================================================================= */
|
|
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
|
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
|
|
|
/* ========================================================================= */
|
|
unsigned long ZEXPORT crc32(crc, buf, len)
|
|
unsigned long crc;
|
|
const unsigned char FAR *buf;
|
|
uInt len;
|
|
{
|
|
if (buf == Z_NULL) return 0UL;
|
|
|
|
crc = crc ^ 0xffffffffUL;
|
|
while (len >= 8) {
|
|
DO8;
|
|
len -= 8;
|
|
}
|
|
if (len) do {
|
|
DO1;
|
|
} while (--len);
|
|
return crc ^ 0xffffffffUL;
|
|
}
|