]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/gen_crc32table.c
5 #define ENTRIES_PER_LINE 4
8 # define LE_TABLE_ROWS (CRC_LE_BITS/8)
9 # define LE_TABLE_SIZE 256
11 # define LE_TABLE_ROWS 1
12 # define LE_TABLE_SIZE (1 << CRC_LE_BITS)
16 # define BE_TABLE_ROWS (CRC_BE_BITS/8)
17 # define BE_TABLE_SIZE 256
19 # define BE_TABLE_ROWS 1
20 # define BE_TABLE_SIZE (1 << CRC_BE_BITS)
23 static uint32_t crc32table_le
[LE_TABLE_ROWS
][256];
24 static uint32_t crc32ctable_le
[LE_TABLE_ROWS
][256];
27 * big endian ordered CRC not used by XFS.
28 static uint32_t crc32table_be[BE_TABLE_ROWS][256];
32 * crc32init_le() - allocate and initialize LE table data
34 * crc is the crc of the byte i; other entries are filled in based on the
35 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
38 static void crc32init_le_generic(const uint32_t polynomial
,
46 for (i
= LE_TABLE_SIZE
>> 1; i
; i
>>= 1) {
47 crc
= (crc
>> 1) ^ ((crc
& 1) ? polynomial
: 0);
48 for (j
= 0; j
< LE_TABLE_SIZE
; j
+= 2 * i
)
49 tab
[0][i
+ j
] = crc
^ tab
[0][j
];
51 for (i
= 0; i
< LE_TABLE_SIZE
; i
++) {
53 for (j
= 1; j
< LE_TABLE_ROWS
; j
++) {
54 crc
= tab
[0][crc
& 0xff] ^ (crc
>> 8);
60 static void crc32init_le(void)
62 crc32init_le_generic(CRCPOLY_LE
, crc32table_le
);
65 static void crc32cinit_le(void)
67 crc32init_le_generic(CRC32C_POLY_LE
, crc32ctable_le
);
71 * crc32init_be() - allocate and initialize BE table data
74 static void crc32init_be(void)
77 uint32_t crc
= 0x80000000;
79 crc32table_be
[0][0] = 0;
81 for (i
= 1; i
< BE_TABLE_SIZE
; i
<<= 1) {
82 crc
= (crc
<< 1) ^ ((crc
& 0x80000000) ? CRCPOLY_BE
: 0);
83 for (j
= 0; j
< i
; j
++)
84 crc32table_be
[0][i
+ j
] = crc
^ crc32table_be
[0][j
];
86 for (i
= 0; i
< BE_TABLE_SIZE
; i
++) {
87 crc
= crc32table_be
[0][i
];
88 for (j
= 1; j
< BE_TABLE_ROWS
; j
++) {
89 crc
= crc32table_be
[0][(crc
>> 24) & 0xff] ^ (crc
<< 8);
90 crc32table_be
[j
][i
] = crc
;
96 static void output_table(uint32_t (*table
)[256], int rows
, int len
, char *trans
)
100 for (j
= 0 ; j
< rows
; j
++) {
102 for (i
= 0; i
< len
- 1; i
++) {
103 if (i
% ENTRIES_PER_LINE
== 0)
105 printf("%s(0x%8.8xL), ", trans
, table
[j
][i
]);
107 printf("%s(0x%8.8xL)},\n", trans
, table
[j
][len
- 1]);
111 int main(int argc
, char** argv
)
113 printf("/* this file is generated - do not edit */\n\n");
115 if (CRC_LE_BITS
> 1) {
117 printf("static u32 crc32table_le[%d][%d] = {",
118 LE_TABLE_ROWS
, LE_TABLE_SIZE
);
119 output_table(crc32table_le
, LE_TABLE_ROWS
,
120 LE_TABLE_SIZE
, "tole");
124 #if 0 /* not used by xfsprogs */
125 if (CRC_BE_BITS
> 1) {
127 printf("static u32 crc32table_be[%d][%d] = {",
128 BE_TABLE_ROWS
, BE_TABLE_SIZE
);
129 output_table(crc32table_be
, LE_TABLE_ROWS
,
130 BE_TABLE_SIZE
, "tobe");
134 if (CRC_LE_BITS
> 1) {
136 printf("static u32 crc32ctable_le[%d][%d] = {",
137 LE_TABLE_ROWS
, LE_TABLE_SIZE
);
138 output_table(crc32ctable_le
, LE_TABLE_ROWS
,
139 LE_TABLE_SIZE
, "tole");