OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
CRC.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 /***************************************************************************
27  *
28  * Simple routine to calculate 32-bit CRC, assuming 32-bit integers.
29  *
30  ***************************************************************************/
31 
32 // include files
33 #include "Message/CRC.h"
34 
35 /* a table of values used in the calculation of the CRC for a buffer */
36 static CRCTYPE crctab[256] =
37 {
38  0x00000000, 0x00007e00, 0x0000fc00, 0x00008200,
39  0x000007ff, 0x000079ff, 0x0000fbff, 0x000085ff,
40  0x00000fff, 0x000071ff, 0x0000f3ff, 0x00008dff,
41  0x00000800, 0x00007600, 0x0000f400, 0x00008a00,
42  0x00001fff, 0x000061ff, 0x0000e3ff, 0x00009dff,
43  0x00001800, 0x00006600, 0x0000e400, 0x00009a00,
44  0x00001000, 0x00006e00, 0x0000ec00, 0x00009200,
45  0x000017ff, 0x000069ff, 0x0000ebff, 0x000095ff,
46  0x00003fff, 0x000041ff, 0x0000c3ff, 0x0000bdff,
47  0x00003800, 0x00004600, 0x0000c400, 0x0000ba00,
48  0x00003000, 0x00004e00, 0x0000cc00, 0x0000b200,
49  0x000037ff, 0x000049ff, 0x0000cbff, 0x0000b5ff,
50  0x00002000, 0x00005e00, 0x0000dc00, 0x0000a200,
51  0x000027ff, 0x000059ff, 0x0000dbff, 0x0000a5ff,
52  0x00002fff, 0x000051ff, 0x0000d3ff, 0x0000adff,
53  0x00002800, 0x00005600, 0x0000d400, 0x0000aa00,
54  0x00007fff, 0x000001ff, 0x000083ff, 0x0000fdff,
55  0x00007800, 0x00000600, 0x00008400, 0x0000fa00,
56  0x00007000, 0x00000e00, 0x00008c00, 0x0000f200,
57  0x000077ff, 0x000009ff, 0x00008bff, 0x0000f5ff,
58  0x00006000, 0x00001e00, 0x00009c00, 0x0000e200,
59  0x000067ff, 0x000019ff, 0x00009bff, 0x0000e5ff,
60  0x00006fff, 0x000011ff, 0x000093ff, 0x0000edff,
61  0x00006800, 0x00001600, 0x00009400, 0x0000ea00,
62  0x00004000, 0x00003e00, 0x0000bc00, 0x0000c200,
63  0x000047ff, 0x000039ff, 0x0000bbff, 0x0000c5ff,
64  0x00004fff, 0x000031ff, 0x0000b3ff, 0x0000cdff,
65  0x00004800, 0x00003600, 0x0000b400, 0x0000ca00,
66  0x00005fff, 0x000021ff, 0x0000a3ff, 0x0000ddff,
67  0x00005800, 0x00002600, 0x0000a400, 0x0000da00,
68  0x00005000, 0x00002e00, 0x0000ac00, 0x0000d200,
69  0x000057ff, 0x000029ff, 0x0000abff, 0x0000d5ff,
70  0x0000ffff, 0x000081ff, 0x000003ff, 0x00007dff,
71  0x0000f800, 0x00008600, 0x00000400, 0x00007a00,
72  0x0000f000, 0x00008e00, 0x00000c00, 0x00007200,
73  0x0000f7ff, 0x000089ff, 0x00000bff, 0x000075ff,
74  0x0000e000, 0x00009e00, 0x00001c00, 0x00006200,
75  0x0000e7ff, 0x000099ff, 0x00001bff, 0x000065ff,
76  0x0000efff, 0x000091ff, 0x000013ff, 0x00006dff,
77  0x0000e800, 0x00009600, 0x00001400, 0x00006a00,
78  0x0000c000, 0x0000be00, 0x00003c00, 0x00004200,
79  0x0000c7ff, 0x0000b9ff, 0x00003bff, 0x000045ff,
80  0x0000cfff, 0x0000b1ff, 0x000033ff, 0x00004dff,
81  0x0000c800, 0x0000b600, 0x00003400, 0x00004a00,
82  0x0000dfff, 0x0000a1ff, 0x000023ff, 0x00005dff,
83  0x0000d800, 0x0000a600, 0x00002400, 0x00005a00,
84  0x0000d000, 0x0000ae00, 0x00002c00, 0x00005200,
85  0x0000d7ff, 0x0000a9ff, 0x00002bff, 0x000055ff,
86  0x00008000, 0x0000fe00, 0x00007c00, 0x00000200,
87  0x000087ff, 0x0000f9ff, 0x00007bff, 0x000005ff,
88  0x00008fff, 0x0000f1ff, 0x000073ff, 0x00000dff,
89  0x00008800, 0x0000f600, 0x00007400, 0x00000a00,
90  0x00009fff, 0x0000e1ff, 0x000063ff, 0x00001dff,
91  0x00009800, 0x0000e600, 0x00006400, 0x00001a00,
92  0x00009000, 0x0000ee00, 0x00006c00, 0x00001200,
93  0x000097ff, 0x0000e9ff, 0x00006bff, 0x000015ff,
94  0x0000bfff, 0x0000c1ff, 0x000043ff, 0x00003dff,
95  0x0000b800, 0x0000c600, 0x00004400, 0x00003a00,
96  0x0000b000, 0x0000ce00, 0x00004c00, 0x00003200,
97  0x0000b7ff, 0x0000c9ff, 0x00004bff, 0x000035ff,
98  0x0000a000, 0x0000de00, 0x00005c00, 0x00002200,
99  0x0000a7ff, 0x0000d9ff, 0x00005bff, 0x000025ff,
100  0x0000afff, 0x0000d1ff, 0x000053ff, 0x00002dff,
101  0x0000a800, 0x0000d600, 0x00005400, 0x00002a00,
102 };
103 
104 
105 /* calculate the CRC for the given buffer of bytes, of length icnt */
106 CRCTYPE crc(void *icp, int icnt)
107 {
108  int initcrc = -1;
109  int cnt = icnt;
110  CRCTYPE crc = (CRCTYPE)initcrc;
111  unsigned char *cp = (unsigned char *)icp;
112  while (cnt--)
113  crc=((crc>>8)&0xffffff)^crctab[(crc&0xff)^*cp++];
114 
115  return(crc);
116 }
CRCTYPE crc(void *icp, int icnt)
Definition: CRC.cpp:106
unsigned int CRCTYPE
Definition: CRC.h:25