diff options
author | Bob Pearson <rpearson@systemfabricworks.com> | 2012-03-23 18:02:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 19:58:37 -0400 |
commit | 9a1dbf6a29694c9d81b498019f103aee0f8b5b6c (patch) | |
tree | 1f331fa108ea29ccf06a7b5816da4dbcaa12bf2d /lib/gen_crc32table.c | |
parent | ce4320ddda4c2520fe77194d3c801ad4e8a8aa11 (diff) |
crc32: make CRC_*_BITS definition correspond to actual bit counts
crc32.c provides a choice of one of several algorithms for computing the
LSB and LSB versions of the CRC32 checksum based on the parameters
CRC_LE_BITS and CRC_BE_BITS.
In the original version the values 1, 2, 4 and 8 respectively selected
versions of the alrogithm that computed the crc 1, 2, 4 and 32 bits as a
time.
This patch series adds a new version that computes the CRC 64 bits at a
time. To make things easier to understand the parameter has been
reinterpreted to actually stand for the number of bits processed in each
step of the algorithm so that the old value 8 has been replaced with the
value 32.
This also allows us to add in a widely used crc algorithm that computes
the crc 8 bits at a time called the Sarwate algorithm.
[djwong@us.ibm.com: Minor changelog tweaks]
Signed-off-by: Bob Pearson <rpearson@systemfabricworks.com>
Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
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.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c index eced7696eb7c..99ac744848fb 100644 --- a/lib/gen_crc32table.c +++ b/lib/gen_crc32table.c | |||
@@ -4,8 +4,17 @@ | |||
4 | 4 | ||
5 | #define ENTRIES_PER_LINE 4 | 5 | #define ENTRIES_PER_LINE 4 |
6 | 6 | ||
7 | #if CRC_LE_BITS <= 8 | ||
7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) | 8 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) |
9 | #else | ||
10 | #define LE_TABLE_SIZE 256 | ||
11 | #endif | ||
12 | |||
13 | #if CRC_BE_BITS <= 8 | ||
8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) | 14 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) |
15 | #else | ||
16 | #define BE_TABLE_SIZE 256 | ||
17 | #endif | ||
9 | 18 | ||
10 | static uint32_t crc32table_le[4][256]; | 19 | static uint32_t crc32table_le[4][256]; |
11 | static uint32_t crc32table_be[4][256]; | 20 | static uint32_t crc32table_be[4][256]; |
@@ -24,7 +33,7 @@ static void crc32init_le(void) | |||
24 | 33 | ||
25 | crc32table_le[0][0] = 0; | 34 | crc32table_le[0][0] = 0; |
26 | 35 | ||
27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { | 36 | for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) { |
28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); | 37 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) | 38 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) |
30 | crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; | 39 | crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; |