aboutsummaryrefslogtreecommitdiff
path: root/lib/gen_crc32table.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gen_crc32table.c')
-rw-r--r--lib/gen_crc32table.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c
index 0d9edd17ee1..8f8d5439e2d 100644
--- a/lib/gen_crc32table.c
+++ b/lib/gen_crc32table.c
@@ -23,6 +23,7 @@
static uint32_t crc32table_le[LE_TABLE_ROWS][256];
static uint32_t crc32table_be[BE_TABLE_ROWS][256];
+static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
/**
* crc32init_le() - allocate and initialize LE table data
@@ -31,27 +32,38 @@ static uint32_t crc32table_be[BE_TABLE_ROWS][256];
* fact that crctable[i^j] = crctable[i] ^ crctable[j].
*
*/
-static void crc32init_le(void)
+static void crc32init_le_generic(const uint32_t polynomial,
+ uint32_t (*tab)[256])
{
unsigned i, j;
uint32_t crc = 1;
- crc32table_le[0][0] = 0;
+ tab[0][0] = 0;
for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
- crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
+ crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
- crc32table_le[0][i + j] = crc ^ crc32table_le[0][j];
+ tab[0][i + j] = crc ^ tab[0][j];
}
for (i = 0; i < LE_TABLE_SIZE; i++) {
- crc = crc32table_le[0][i];
+ crc = tab[0][i];
for (j = 1; j < LE_TABLE_ROWS; j++) {
- crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8);
- crc32table_le[j][i] = crc;
+ crc = tab[0][crc & 0xff] ^ (crc >> 8);
+ tab[j][i] = crc;
}
}
}
+static void crc32init_le(void)
+{
+ crc32init_le_generic(CRCPOLY_LE, crc32table_le);
+}
+
+static void crc32cinit_le(void)
+{
+ crc32init_le_generic(CRC32C_POLY_LE, crc32ctable_le);
+}
+
/**
* crc32init_be() - allocate and initialize BE table data
*/
@@ -114,6 +126,15 @@ int main(int argc, char** argv)
BE_TABLE_SIZE, "tobe");
printf("};\n");
}
+ if (CRC_LE_BITS > 1) {
+ crc32cinit_le();
+ printf("static const u32 __cacheline_aligned "
+ "crc32ctable_le[%d][%d] = {",
+ LE_TABLE_ROWS, LE_TABLE_SIZE);
+ output_table(crc32ctable_le, LE_TABLE_ROWS,
+ LE_TABLE_SIZE, "tole");
+ printf("};\n");
+ }
return 0;
}