2 #include "../include/generated/autoconf.h"
6 #define ENTRIES_PER_LINE 4
9 # define LE_TABLE_ROWS (CRC_LE_BITS/8)
10 # define LE_TABLE_SIZE 256
12 # define LE_TABLE_ROWS 1
13 # define LE_TABLE_SIZE (1 << CRC_LE_BITS)
17 # define BE_TABLE_ROWS (CRC_BE_BITS/8)
18 # define BE_TABLE_SIZE 256
20 # define BE_TABLE_ROWS 1
21 # define BE_TABLE_SIZE (1 << CRC_BE_BITS)
24 static uint32_t crc32table_le[LE_TABLE_ROWS][256];
25 static uint32_t crc32table_be[BE_TABLE_ROWS][256];
28 * crc32init_le() - allocate and initialize LE table data
30 * crc is the crc of the byte i; other entries are filled in based on the
31 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
34 static void crc32init_le(void)
39 crc32table_le[0][0] = 0;
41 for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
42 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
43 for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
44 crc32table_le[0][i + j] = crc ^ crc32table_le[0][j];
46 for (i = 0; i < LE_TABLE_SIZE; i++) {
47 crc = crc32table_le[0][i];
48 for (j = 1; j < LE_TABLE_ROWS; j++) {
49 crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8);
50 crc32table_le[j][i] = crc;
56 * crc32init_be() - allocate and initialize BE table data
58 static void crc32init_be(void)
61 uint32_t crc = 0x80000000;
63 crc32table_be[0][0] = 0;
65 for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
66 crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
67 for (j = 0; j < i; j++)
68 crc32table_be[0][i + j] = crc ^ crc32table_be[0][j];
70 for (i = 0; i < BE_TABLE_SIZE; i++) {
71 crc = crc32table_be[0][i];
72 for (j = 1; j < BE_TABLE_ROWS; j++) {
73 crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
74 crc32table_be[j][i] = crc;
79 static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
83 for (j = 0 ; j < rows; j++) {
85 for (i = 0; i < len - 1; i++) {
86 if (i % ENTRIES_PER_LINE == 0)
88 printf("%s(0x%8.8xL), ", trans, table[j][i]);
90 printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]);
94 int main(int argc, char** argv)
96 printf("/* this file is generated - do not edit */\n\n");
98 if (CRC_LE_BITS > 1) {
100 printf("static const u32 __cacheline_aligned "
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");
108 if (CRC_BE_BITS > 1) {
110 printf("static const u32 __cacheline_aligned "
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");