]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - lib/gen_crc32table.c
5 #define ENTRIES_PER_LINE 4
7 #define LE_TABLE_SIZE (1 << CRC_LE_BITS)
8 #define BE_TABLE_SIZE (1 << CRC_BE_BITS)
10 static uint32_t crc32table_le
[4][LE_TABLE_SIZE
];
11 static uint32_t crc32table_be
[4][BE_TABLE_SIZE
];
14 * crc32init_le() - allocate and initialize LE table data
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].
20 static void crc32init_le(void)
25 crc32table_le
[0][0] = 0;
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
[0][i
+ j
] = crc
^ crc32table_le
[0][j
];
32 for (i
= 0; i
< LE_TABLE_SIZE
; i
++) {
33 crc
= crc32table_le
[0][i
];
34 for (j
= 1; j
< 4; j
++) {
35 crc
= crc32table_le
[0][crc
& 0xff] ^ (crc
>> 8);
36 crc32table_le
[j
][i
] = crc
;
42 * crc32init_be() - allocate and initialize BE table data
44 static void crc32init_be(void)
47 uint32_t crc
= 0x80000000;
49 crc32table_be
[0][0] = 0;
51 for (i
= 1; i
< BE_TABLE_SIZE
; i
<<= 1) {
52 crc
= (crc
<< 1) ^ ((crc
& 0x80000000) ? CRCPOLY_BE
: 0);
53 for (j
= 0; j
< i
; j
++)
54 crc32table_be
[0][i
+ j
] = crc
^ crc32table_be
[0][j
];
56 for (i
= 0; i
< BE_TABLE_SIZE
; i
++) {
57 crc
= crc32table_be
[0][i
];
58 for (j
= 1; j
< 4; j
++) {
59 crc
= crc32table_be
[0][(crc
>> 24) & 0xff] ^ (crc
<< 8);
60 crc32table_be
[j
][i
] = crc
;
65 static void output_table(uint32_t table
[4][256], int len
, char *trans
)
69 for (j
= 0 ; j
< 4; j
++) {
71 for (i
= 0; i
< len
- 1; i
++) {
72 if (i
% ENTRIES_PER_LINE
== 0)
74 printf("%s(0x%8.8xL), ", trans
, table
[j
][i
]);
76 printf("%s(0x%8.8xL)},\n", trans
, table
[j
][len
- 1]);
80 int main(int argc
, char** argv
)
82 printf("/* this file is generated - do not edit */\n\n");
84 if (CRC_LE_BITS
> 1) {
86 printf("static const u32 crc32table_le[4][256] = {");
87 output_table(crc32table_le
, LE_TABLE_SIZE
, "tole");
91 if (CRC_BE_BITS
> 1) {
93 printf("static const u32 crc32table_be[4][256] = {");
94 output_table(crc32table_be
, BE_TABLE_SIZE
, "tobe");