]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/gen_crc32table.c
1 // SPDX-License-Identifier: GPL-2.0
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)
16 static uint32_t crc32ctable_le
[LE_TABLE_ROWS
][256];
19 * crc32init_le() - allocate and initialize LE table data
21 * crc is the crc of the byte i; other entries are filled in based on the
22 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
25 static void crc32init_le_generic(const uint32_t polynomial
,
33 for (i
= LE_TABLE_SIZE
>> 1; i
; i
>>= 1) {
34 crc
= (crc
>> 1) ^ ((crc
& 1) ? polynomial
: 0);
35 for (j
= 0; j
< LE_TABLE_SIZE
; j
+= 2 * i
)
36 tab
[0][i
+ j
] = crc
^ tab
[0][j
];
38 for (i
= 0; i
< LE_TABLE_SIZE
; i
++) {
40 for (j
= 1; j
< LE_TABLE_ROWS
; j
++) {
41 crc
= tab
[0][crc
& 0xff] ^ (crc
>> 8);
47 static void crc32cinit_le(void)
49 crc32init_le_generic(CRC32C_POLY_LE
, crc32ctable_le
);
52 static void output_table(uint32_t (*table
)[256], int rows
, int len
, char *trans
)
56 for (j
= 0 ; j
< rows
; j
++) {
58 for (i
= 0; i
< len
- 1; i
++) {
59 if (i
% ENTRIES_PER_LINE
== 0)
61 printf("%s(0x%8.8xL), ", trans
, table
[j
][i
]);
63 printf("%s(0x%8.8xL)},\n", trans
, table
[j
][len
- 1]);
67 int main(int argc
, char** argv
)
69 printf("/* this file is generated - do not edit */\n\n");
71 if (CRC_LE_BITS
> 1) {
73 printf("static u32 crc32ctable_le[%d][%d] = {",
74 LE_TABLE_ROWS
, LE_TABLE_SIZE
);
75 output_table(crc32ctable_le
, LE_TABLE_ROWS
,
76 LE_TABLE_SIZE
, "tole");