diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /lib/gen_crc32table.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'lib/gen_crc32table.c')
-rw-r--r-- | lib/gen_crc32table.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c new file mode 100644 index 000000000000..bea5d97df991 --- /dev/null +++ b/lib/gen_crc32table.c | |||
@@ -0,0 +1,82 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "crc32defs.h" | ||
3 | #include <inttypes.h> | ||
4 | |||
5 | #define ENTRIES_PER_LINE 4 | ||
6 | |||
7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) | ||
8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) | ||
9 | |||
10 | static uint32_t crc32table_le[LE_TABLE_SIZE]; | ||
11 | static uint32_t crc32table_be[BE_TABLE_SIZE]; | ||
12 | |||
13 | /** | ||
14 | * crc32init_le() - allocate and initialize LE table data | ||
15 | * | ||
16 | * crc is the crc of the byte i; other entries are filled in based on the | ||
17 | * fact that crctable[i^j] = crctable[i] ^ crctable[j]. | ||
18 | * | ||
19 | */ | ||
20 | static void crc32init_le(void) | ||
21 | { | ||
22 | unsigned i, j; | ||
23 | uint32_t crc = 1; | ||
24 | |||
25 | crc32table_le[0] = 0; | ||
26 | |||
27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { | ||
28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); | ||
29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) | ||
30 | crc32table_le[i + j] = crc ^ crc32table_le[j]; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * crc32init_be() - allocate and initialize BE table data | ||
36 | */ | ||
37 | static void crc32init_be(void) | ||
38 | { | ||
39 | unsigned i, j; | ||
40 | uint32_t crc = 0x80000000; | ||
41 | |||
42 | crc32table_be[0] = 0; | ||
43 | |||
44 | for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { | ||
45 | crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); | ||
46 | for (j = 0; j < i; j++) | ||
47 | crc32table_be[i + j] = crc ^ crc32table_be[j]; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static void output_table(uint32_t table[], int len, char *trans) | ||
52 | { | ||
53 | int i; | ||
54 | |||
55 | for (i = 0; i < len - 1; i++) { | ||
56 | if (i % ENTRIES_PER_LINE == 0) | ||
57 | printf("\n"); | ||
58 | printf("%s(0x%8.8xL), ", trans, table[i]); | ||
59 | } | ||
60 | printf("%s(0x%8.8xL)\n", trans, table[len - 1]); | ||
61 | } | ||
62 | |||
63 | int main(int argc, char** argv) | ||
64 | { | ||
65 | printf("/* this file is generated - do not edit */\n\n"); | ||
66 | |||
67 | if (CRC_LE_BITS > 1) { | ||
68 | crc32init_le(); | ||
69 | printf("static const u32 crc32table_le[] = {"); | ||
70 | output_table(crc32table_le, LE_TABLE_SIZE, "tole"); | ||
71 | printf("};\n"); | ||
72 | } | ||
73 | |||
74 | if (CRC_BE_BITS > 1) { | ||
75 | crc32init_be(); | ||
76 | printf("static const u32 crc32table_be[] = {"); | ||
77 | output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); | ||
78 | printf("};\n"); | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||