aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gen_crc32table.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2012-03-23 18:02:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 19:58:38 -0400
commit46c5801eaf86e83cb3a4142ad35188db5011fff0 (patch)
tree2b8a8f7709aa7dadafdf13f823488cf51e2e2fed /lib/gen_crc32table.c
parent78dff4189708d07cdcaf7bfd1b04ebe78ac9c041 (diff)
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 @@
23 23
24static uint32_t crc32table_le[LE_TABLE_ROWS][256]; 24static uint32_t crc32table_le[LE_TABLE_ROWS][256];
25static uint32_t crc32table_be[BE_TABLE_ROWS][256]; 25static uint32_t crc32table_be[BE_TABLE_ROWS][256];
26static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
26 27
27/** 28/**
28 * crc32init_le() - allocate and initialize LE table data 29 * crc32init_le() - allocate and initialize LE table data
@@ -31,27 +32,38 @@ static uint32_t crc32table_be[BE_TABLE_ROWS][256];
31 * fact that crctable[i^j] = crctable[i] ^ crctable[j]. 32 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
32 * 33 *
33 */ 34 */
34static void crc32init_le(void) 35static void crc32init_le_generic(const uint32_t polynomial,
36 uint32_t (*tab)[256])
35{ 37{
36 unsigned i, j; 38 unsigned i, j;
37 uint32_t crc = 1; 39 uint32_t crc = 1;
38 40
39 crc32table_le[0][0] = 0; 41 tab[0][0] = 0;
40 42
41 for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) { 43 for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
42 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 44 crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
43 for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) 45 for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
44 crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; 46 tab[0][i + j] = crc ^ tab[0][j];
45 } 47 }
46 for (i = 0; i < LE_TABLE_SIZE; i++) { 48 for (i = 0; i < LE_TABLE_SIZE; i++) {
47 crc = crc32table_le[0][i]; 49 crc = tab[0][i];
48 for (j = 1; j < LE_TABLE_ROWS; j++) { 50 for (j = 1; j < LE_TABLE_ROWS; j++) {
49 crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8); 51 crc = tab[0][crc & 0xff] ^ (crc >> 8);
50 crc32table_le[j][i] = crc; 52 tab[j][i] = crc;
51 } 53 }
52 } 54 }
53} 55}
54 56
57static void crc32init_le(void)
58{
59 crc32init_le_generic(CRCPOLY_LE, crc32table_le);
60}
61
62static void crc32cinit_le(void)
63{
64 crc32init_le_generic(CRC32C_POLY_LE, crc32ctable_le);
65}
66
55/** 67/**
56 * crc32init_be() - allocate and initialize BE table data 68 * crc32init_be() - allocate and initialize BE table data
57 */ 69 */
@@ -114,6 +126,15 @@ int main(int argc, char** argv)
114 BE_TABLE_SIZE, "tobe"); 126 BE_TABLE_SIZE, "tobe");
115 printf("};\n"); 127 printf("};\n");
116 } 128 }
129 if (CRC_LE_BITS > 1) {
130 crc32cinit_le();
131 printf("static const u32 __cacheline_aligned "
132 "crc32ctable_le[%d][%d] = {",
133 LE_TABLE_ROWS, LE_TABLE_SIZE);
134 output_table(crc32ctable_le, LE_TABLE_ROWS,
135 LE_TABLE_SIZE, "tole");
136 printf("};\n");
137 }
117 138
118 return 0; 139 return 0;
119} 140}