summaryrefslogtreecommitdiffstats
path: root/lib/gen_crc32table.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2012-03-23 15:02:25 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 16:58:38 -0700
commit46c5801eaf86e83cb3a4142ad35188db5011fff0 (patch)
tree2b8a8f7709aa7dadafdf13f823488cf51e2e2fed /lib/gen_crc32table.c
parent78dff4189708d07cdcaf7bfd1b04ebe78ac9c041 (diff)
downloadlinux-46c5801eaf86e83cb3a4142ad35188db5011fff0.tar.gz
linux-46c5801eaf86e83cb3a4142ad35188db5011fff0.tar.bz2
linux-46c5801eaf86e83cb3a4142ad35188db5011fff0.zip
crc32: bolt on crc32c
Reuse the existing crc32 code to stamp out a crc32c implementation. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Bob Pearson <rpearson@systemfabricworks.com> Cc: Randy Dunlap <rdunlap@xenotime.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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 0d9edd17ee13..8f8d5439e2d9 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;
}