 Does anyone know where I could find efficient source code for a 32bit CRC
 subprogram?

 My company spends about $250,000 in CPU time each year on a very
 inefficient 150line COBOL program that simply computes a 32bit CRC from
 a 500byte buffer.

 I already converted it to assembly language, but I'm not sure it's as
 efficient as it should be (of course, I've probably already reduced the
 cost to $10,000 per year, but I'd like to shoot for something less than
 $5,000 as well as to learn more about CRC algorithms). Thanks for any
 help!
I found this short one in C in my archive:
_FILE VERIFICATION USING CRC_
by Mark R. Nelson
[LISTING ONE]
*/
/* Instead of performing a straightforward calculation of the 32bit CRC usin
* a series of logical operations, program uses faster table lookup method. */
#include <stdio.h>
unsigned long CalculateBufferCRC(unsigned int count,unsigned long crc,void
*buffer);
unsigned long CRCTable[256];
#define CRC32_POLYNOMIAL 0xEDB88320L
void BuildCRCTable()
{
int i;
int j;
unsigned long crc;
for ( i = 0; i <= 255 ; i++ ) {
crc = i;
for ( j = 8 ; j > 0; j ) {
if ( crc & 1 )
crc = ( crc >> 1 ) ^ CRC32_POLYNOMIAL;
else
crc >>= 1;
}
CRCTable[ i ] = crc;
}
Quote:
}
/* This routine is responsible for actually performing the calculation of the
* 32bit CRC for the entire file. We precondition the CRC value with all 1's
* then invert every bit after the entire file has been done. This gives us a
* CRC value that corresponds with the values calculated by PKZIP and ARJ. */
void main()
{
unsigned long crc;
BuildCRCTable();
crc = 0xFFFFFFFFL;
crc = CalculateBufferCRC( 15, crc, "Dit is een test" );
crc ^= 0xFFFFFFFFL;
printf("CRC32=%8.8X\n",crc);
Quote:
}
/* Routine calculates the CRC for a block of data using table lookup method.
* It accepts an original value for the crc, and returns the updated value. */
unsigned long CalculateBufferCRC( count, crc, buffer )
unsigned int count;
unsigned long crc;
void *buffer;
{
unsigned char *p;
unsigned long temp1;
unsigned long temp2;
p = (unsigned char*) buffer;
while ( count != 0 ) {
temp1 = ( crc >> 8 ) & 0x00FFFFFFL;
temp2 = CRCTable[ ( (int) crc ^ *p++ ) & 0xff ];
crc = temp1 ^ temp2;
}
return( crc );
Quote:
}
Ron van Wier

