src/Message/CRC.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 /***************************************************************************
00027  *
00028  * Simple routine to calculate 32-bit CRC, assuming 32-bit integers.
00029  * 
00030  ***************************************************************************/
00031 
00032 // include files
00033 #include "Message/CRC.h"
00034 
00035 /* a table of values used in the calculation of the CRC for a buffer */
00036 static CRCTYPE crctab[256] = {
00037     0x00000000, 0x00007e00, 0x0000fc00, 0x00008200,
00038     0x000007ff, 0x000079ff, 0x0000fbff, 0x000085ff,
00039     0x00000fff, 0x000071ff, 0x0000f3ff, 0x00008dff,
00040     0x00000800, 0x00007600, 0x0000f400, 0x00008a00,
00041     0x00001fff, 0x000061ff, 0x0000e3ff, 0x00009dff,
00042     0x00001800, 0x00006600, 0x0000e400, 0x00009a00,
00043     0x00001000, 0x00006e00, 0x0000ec00, 0x00009200,
00044     0x000017ff, 0x000069ff, 0x0000ebff, 0x000095ff,
00045     0x00003fff, 0x000041ff, 0x0000c3ff, 0x0000bdff,
00046     0x00003800, 0x00004600, 0x0000c400, 0x0000ba00,
00047     0x00003000, 0x00004e00, 0x0000cc00, 0x0000b200,
00048     0x000037ff, 0x000049ff, 0x0000cbff, 0x0000b5ff,
00049     0x00002000, 0x00005e00, 0x0000dc00, 0x0000a200,
00050     0x000027ff, 0x000059ff, 0x0000dbff, 0x0000a5ff,
00051     0x00002fff, 0x000051ff, 0x0000d3ff, 0x0000adff,
00052     0x00002800, 0x00005600, 0x0000d400, 0x0000aa00,
00053     0x00007fff, 0x000001ff, 0x000083ff, 0x0000fdff,
00054     0x00007800, 0x00000600, 0x00008400, 0x0000fa00,
00055     0x00007000, 0x00000e00, 0x00008c00, 0x0000f200,
00056     0x000077ff, 0x000009ff, 0x00008bff, 0x0000f5ff,
00057     0x00006000, 0x00001e00, 0x00009c00, 0x0000e200,
00058     0x000067ff, 0x000019ff, 0x00009bff, 0x0000e5ff,
00059     0x00006fff, 0x000011ff, 0x000093ff, 0x0000edff,
00060     0x00006800, 0x00001600, 0x00009400, 0x0000ea00,
00061     0x00004000, 0x00003e00, 0x0000bc00, 0x0000c200,
00062     0x000047ff, 0x000039ff, 0x0000bbff, 0x0000c5ff,
00063     0x00004fff, 0x000031ff, 0x0000b3ff, 0x0000cdff,
00064     0x00004800, 0x00003600, 0x0000b400, 0x0000ca00,
00065     0x00005fff, 0x000021ff, 0x0000a3ff, 0x0000ddff,
00066     0x00005800, 0x00002600, 0x0000a400, 0x0000da00,
00067     0x00005000, 0x00002e00, 0x0000ac00, 0x0000d200,
00068     0x000057ff, 0x000029ff, 0x0000abff, 0x0000d5ff,
00069     0x0000ffff, 0x000081ff, 0x000003ff, 0x00007dff,
00070     0x0000f800, 0x00008600, 0x00000400, 0x00007a00,
00071     0x0000f000, 0x00008e00, 0x00000c00, 0x00007200,
00072     0x0000f7ff, 0x000089ff, 0x00000bff, 0x000075ff,
00073     0x0000e000, 0x00009e00, 0x00001c00, 0x00006200,
00074     0x0000e7ff, 0x000099ff, 0x00001bff, 0x000065ff,
00075     0x0000efff, 0x000091ff, 0x000013ff, 0x00006dff,
00076     0x0000e800, 0x00009600, 0x00001400, 0x00006a00,
00077     0x0000c000, 0x0000be00, 0x00003c00, 0x00004200,
00078     0x0000c7ff, 0x0000b9ff, 0x00003bff, 0x000045ff,
00079     0x0000cfff, 0x0000b1ff, 0x000033ff, 0x00004dff,
00080     0x0000c800, 0x0000b600, 0x00003400, 0x00004a00,
00081     0x0000dfff, 0x0000a1ff, 0x000023ff, 0x00005dff,
00082     0x0000d800, 0x0000a600, 0x00002400, 0x00005a00,
00083     0x0000d000, 0x0000ae00, 0x00002c00, 0x00005200,
00084     0x0000d7ff, 0x0000a9ff, 0x00002bff, 0x000055ff,
00085     0x00008000, 0x0000fe00, 0x00007c00, 0x00000200,
00086     0x000087ff, 0x0000f9ff, 0x00007bff, 0x000005ff,
00087     0x00008fff, 0x0000f1ff, 0x000073ff, 0x00000dff,
00088     0x00008800, 0x0000f600, 0x00007400, 0x00000a00,
00089     0x00009fff, 0x0000e1ff, 0x000063ff, 0x00001dff,
00090     0x00009800, 0x0000e600, 0x00006400, 0x00001a00,
00091     0x00009000, 0x0000ee00, 0x00006c00, 0x00001200,
00092     0x000097ff, 0x0000e9ff, 0x00006bff, 0x000015ff,
00093     0x0000bfff, 0x0000c1ff, 0x000043ff, 0x00003dff,
00094     0x0000b800, 0x0000c600, 0x00004400, 0x00003a00,
00095     0x0000b000, 0x0000ce00, 0x00004c00, 0x00003200,
00096     0x0000b7ff, 0x0000c9ff, 0x00004bff, 0x000035ff,
00097     0x0000a000, 0x0000de00, 0x00005c00, 0x00002200,
00098     0x0000a7ff, 0x0000d9ff, 0x00005bff, 0x000025ff,
00099     0x0000afff, 0x0000d1ff, 0x000053ff, 0x00002dff,
00100     0x0000a800, 0x0000d600, 0x00005400, 0x00002a00,
00101 };
00102 
00103 
00104 /* calculate the CRC for the given buffer of bytes, of length icnt */
00105 CRCTYPE crc(void *icp, int icnt) {
00106   register int initcrc = -1;
00107   register int cnt = icnt;
00108   register CRCTYPE crc = (CRCTYPE)initcrc;
00109   register unsigned char *cp = (unsigned char *)icp;
00110   while(cnt--)
00111     crc=((crc>>8)&0xffffff)^crctab[(crc&0xff)^*cp++];
00112 
00113   return(crc);
00114 }
00115 
00116 
00117 /***************************************************************************
00118  * $RCSfile: CRC.cpp,v $   $Author: adelmann $
00119  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:28 $
00120  * IPPL_VERSION_ID: $Id: CRC.cpp,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ 
00121  ***************************************************************************/
00122 

Generated on Mon Jan 16 13:23:52 2006 for IPPL by  doxygen 1.4.6