Re: [patch v5 7/8] crc32-add-slicing-by-8.diff

From: George Spelvin
Date: Thu Aug 11 2011 - 11:34:10 EST


I don't know if you care, but here's some slightly more compact code for
creating the tables. It produces the same results, and I don't think
it's any slower.

I can explain it if anyone's confused, but it's hopefully fairly
easy to figure out assuming a backgriund in CRC math.

(Tested against existing code, not in kernel.)
Signed-off-by: George Spelvin <linux@xxxxxxxxxxx>

static void crc32init_le(void)
{
unsigned i, j, k;
uint32_t crc = 1;

for (i = 0; i < LE_TABLE_ROWS; i++) {
crc32table_le[i][0] = 0;
for (j = LE_TABLE_SIZE >> 1; j; j >>= 1) {
crc = (crc >> 1) ^ (crc & 1 ? CRCPOLY_LE : 0);
for (k = 0; k < LE_TABLE_SIZE; k += 2 * j)
crc32table_le[i][j + k] = crc ^ crc32table_le[i][k];
}
}
}

static void crc32init_be(void)
{
unsigned i, j, k;
uint32_t crc = 0x80000000;

for (i = 0; i < BE_TABLE_ROWS; i++) {
crc32table_be[i][0] = 0;
for (j = 1; j < BE_TABLE_SIZE; j <<= 1) {
crc = (crc << 1) ^ (crc & 0x80000000 ? CRCPOLY_BE : 0);
for (k = 0; k < j; k++)
crc32table_be[i][j + k] = crc ^ crc32table_be[i][k];
}
}
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/