aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gen_crc32table.c
diff options
context:
space:
mode:
authorBob Pearson <rpearson@systemfabricworks.com>2012-03-23 18:02:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 19:58:37 -0400
commit324eb0f17d9dcead3c60c133aa244f6b3631fec9 (patch)
tree657c564269a0fc1921f4252dbf0184725f5c85fa /lib/gen_crc32table.c
parent9a1dbf6a29694c9d81b498019f103aee0f8b5b6c (diff)
crc32: add slice-by-8 algorithm to existing code
Add slicing-by-8 algorithm to the existing slicing-by-4 algorithm. This consists of: - extend largest BITS size from 32 to 64 - extend tables from tab[4][256] to up to tab[8][256] - Add code for inner loop. [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.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c
index 99ac744848fb..0d9edd17ee13 100644
--- a/lib/gen_crc32table.c
+++ b/lib/gen_crc32table.c
@@ -1,23 +1,28 @@
1#include <stdio.h> 1#include <stdio.h>
2#include "../include/generated/autoconf.h"
2#include "crc32defs.h" 3#include "crc32defs.h"
3#include <inttypes.h> 4#include <inttypes.h>
4 5
5#define ENTRIES_PER_LINE 4 6#define ENTRIES_PER_LINE 4
6 7
7#if CRC_LE_BITS <= 8 8#if CRC_LE_BITS > 8
8#define LE_TABLE_SIZE (1 << CRC_LE_BITS) 9# define LE_TABLE_ROWS (CRC_LE_BITS/8)
10# define LE_TABLE_SIZE 256
9#else 11#else
10#define LE_TABLE_SIZE 256 12# define LE_TABLE_ROWS 1
13# define LE_TABLE_SIZE (1 << CRC_LE_BITS)
11#endif 14#endif
12 15
13#if CRC_BE_BITS <= 8 16#if CRC_BE_BITS > 8
14#define BE_TABLE_SIZE (1 << CRC_BE_BITS) 17# define BE_TABLE_ROWS (CRC_BE_BITS/8)
18# define BE_TABLE_SIZE 256
15#else 19#else
16#define BE_TABLE_SIZE 256 20# define BE_TABLE_ROWS 1
21# define BE_TABLE_SIZE (1 << CRC_BE_BITS)
17#endif 22#endif
18 23
19static uint32_t crc32table_le[4][256]; 24static uint32_t crc32table_le[LE_TABLE_ROWS][256];
20static uint32_t crc32table_be[4][256]; 25static uint32_t crc32table_be[BE_TABLE_ROWS][256];
21 26
22/** 27/**
23 * crc32init_le() - allocate and initialize LE table data 28 * crc32init_le() - allocate and initialize LE table data
@@ -40,7 +45,7 @@ static void crc32init_le(void)
40 } 45 }
41 for (i = 0; i < LE_TABLE_SIZE; i++) { 46 for (i = 0; i < LE_TABLE_SIZE; i++) {
42 crc = crc32table_le[0][i]; 47 crc = crc32table_le[0][i];
43 for (j = 1; j < 4; j++) { 48 for (j = 1; j < LE_TABLE_ROWS; j++) {
44 crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8); 49 crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8);
45 crc32table_le[j][i] = crc; 50 crc32table_le[j][i] = crc;
46 } 51 }
@@ -64,18 +69,18 @@ static void crc32init_be(void)
64 } 69 }
65 for (i = 0; i < BE_TABLE_SIZE; i++) { 70 for (i = 0; i < BE_TABLE_SIZE; i++) {
66 crc = crc32table_be[0][i]; 71 crc = crc32table_be[0][i];
67 for (j = 1; j < 4; j++) { 72 for (j = 1; j < BE_TABLE_ROWS; j++) {
68 crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8); 73 crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
69 crc32table_be[j][i] = crc; 74 crc32table_be[j][i] = crc;
70 } 75 }
71 } 76 }
72} 77}
73 78
74static void output_table(uint32_t (*table)[256], int len, char *trans) 79static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
75{ 80{
76 int i, j; 81 int i, j;
77 82
78 for (j = 0 ; j < 4; j++) { 83 for (j = 0 ; j < rows; j++) {
79 printf("{"); 84 printf("{");
80 for (i = 0; i < len - 1; i++) { 85 for (i = 0; i < len - 1; i++) {
81 if (i % ENTRIES_PER_LINE == 0) 86 if (i % ENTRIES_PER_LINE == 0)
@@ -92,15 +97,21 @@ int main(int argc, char** argv)
92 97
93 if (CRC_LE_BITS > 1) { 98 if (CRC_LE_BITS > 1) {
94 crc32init_le(); 99 crc32init_le();
95 printf("static const u32 crc32table_le[4][256] = {"); 100 printf("static const u32 __cacheline_aligned "
96 output_table(crc32table_le, LE_TABLE_SIZE, "tole"); 101 "crc32table_le[%d][%d] = {",
102 LE_TABLE_ROWS, LE_TABLE_SIZE);
103 output_table(crc32table_le, LE_TABLE_ROWS,
104 LE_TABLE_SIZE, "tole");
97 printf("};\n"); 105 printf("};\n");
98 } 106 }
99 107
100 if (CRC_BE_BITS > 1) { 108 if (CRC_BE_BITS > 1) {
101 crc32init_be(); 109 crc32init_be();
102 printf("static const u32 crc32table_be[4][256] = {"); 110 printf("static const u32 __cacheline_aligned "
103 output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); 111 "crc32table_be[%d][%d] = {",
112 BE_TABLE_ROWS, BE_TABLE_SIZE);
113 output_table(crc32table_be, LE_TABLE_ROWS,
114 BE_TABLE_SIZE, "tobe");
104 printf("};\n"); 115 printf("};\n");
105 } 116 }
106 117