[Coco] IP packets on my coco
Barry Nelson
barry.nelson at amobiledevice.com
Wed Jun 8 02:39:13 EDT 2016
Oops, open mouth, insert foot. Here is some code that uses a 256 byte table to accelerate a 32 bit CRC calculation.
/* This does table lookup to calulate a 32 bit CRC. First the CRC table itself
is calculated. Not counting the table setup when compiled to Cyclops with
GCC, this function executes in 7 + 13n instructions, where n is the number
of bytes in the input message. It should be doable in 4 + 9n instructions.
In any case, two of the 13 or 9 instrucions are load byte. */
static unsigned int crctable[256];
void setupcrc32c() {
unsigned int byte, crc, mask;
int j;
/* Set up the table. */
for (byte = 0; byte <= 255; byte++) {
crc = byte;
for (j = 7; j >= 0; j--) { // Do eight times.
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
/* 0xEDB88320 is 0x04C11DB7 reversed */
}
crctable[byte] = crc;
}
}
unsigned int crc32c(unsigned char *message) {
int i=0;
unsigned int byte, crc;
/* Calculate the CRC. */
crc = 0xFFFFFFFF;
while ((byte = message[i]) != 0) {
crc = (crc >> 8) ^ crctable[(crc ^ byte) & 0xFF];
i = i + 1;
}
return ~crc;
}
On Jun 8, 2016, at 1:57 AM, Barry Nelson <barry.nelson at amobiledevice.com> wrote:
> The problem with that approach is that an 8 bit CRC requires a 256 byte lookup table or 2^8 bytes. A 32 bit CRC would need a 2^32 byte table or 4294967296 bytes, that is a 4Gb lookup table.
More information about the Coco
mailing list