source: project/release/2/z3/z3crc32.h @ 8742

Last change on this file since 8742 was 8742, checked in by felix winkelmann, 12 years ago

moved eggs partially to rrb2

File size: 2.1 KB
Line 
1/*
2 * cyclic redundancy check 32 bit
3 * Copyright (C) 1999 Christian Wolff, 2004,2005 Oskar Schirmer
4 * for Convergence Integrated Media GmbH (http://www.convergence.de)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#ifndef __Z3CRC32_H__
22#define __Z3CRC32_H__
23
24#include <sys/types.h>
25
26#define LSBFCOEFF(x) | ((1UL << 31) >> x)
27
28#define POLYNOMIAL_32_LSBF 0 \
29    LSBFCOEFF(0)  \
30    LSBFCOEFF(1)  \
31    LSBFCOEFF(2)  \
32    LSBFCOEFF(4)  \
33    LSBFCOEFF(5)  \
34    LSBFCOEFF(7)  \
35    LSBFCOEFF(8)  \
36    LSBFCOEFF(10) \
37    LSBFCOEFF(11) \
38    LSBFCOEFF(12) \
39    LSBFCOEFF(16) \
40    LSBFCOEFF(22) \
41    LSBFCOEFF(23) \
42    LSBFCOEFF(26)
43
44#define CRC_INIT_32   ((__u32)(-1))
45
46#define update_crc_32(crc, data) \
47    (((crc) >> 8) ^ crc_32_table[(unsigned char)((crc) ^ (data))])
48
49// generate the tables of CRC-32 remainders for all possible bytes
50static inline void gen_crc32_table(__u32 *table) {
51  register int i,j;
52  register __u32 crc32;
53  for (i=0; i<256; i++) {
54    crc32=(__u32)i;
55    for (j=0; j<8; j++) {
56      crc32 = (crc32 >> 1) ^ ((crc32 & 1) ? POLYNOMIAL_32_LSBF : 0);
57    }
58    table[i] = crc32;
59  }
60}
61
62// update the CRC on the data block one byte at a time
63static inline __u32 update_crc_32_block(__u32 *table, __u32 crc,
64                char *data_block_ptr, int data_block_size)
65{
66  register int i;
67  for (i=data_block_size; i>0; i--) {
68    crc = (crc >> 8) ^ table[(unsigned char)(crc ^ (*data_block_ptr++))];
69  }
70  return crc;
71}
72
73#endif /* __Z3CRC32_H__ */
Note: See TracBrowser for help on using the repository browser.