1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file crc64_tablegen.c
4 /// \brief Generate crc64_table_le.h and crc64_table_be.h
6 /// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c
7 /// Add -DWORDS_BIGENDIAN to generate big endian table.
9 // Author: Lasse Collin
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
14 ///////////////////////////////////////////////////////////////////////////////
17 #include "../../common/tuklib_integer.h"
20 static uint64_t crc64_table
[4][256];
24 init_crc64_table(void)
26 static const uint64_t poly64
= UINT64_C(0xC96C5795D7870F42);
28 for (size_t s
= 0; s
< 4; ++s
) {
29 for (size_t b
= 0; b
< 256; ++b
) {
30 uint64_t r
= s
== 0 ? b
: crc64_table
[s
- 1][b
];
32 for (size_t i
= 0; i
< 8; ++i
) {
34 r
= (r
>> 1) ^ poly64
;
39 crc64_table
[s
][b
] = r
;
43 #ifdef WORDS_BIGENDIAN
44 for (size_t s
= 0; s
< 4; ++s
)
45 for (size_t b
= 0; b
< 256; ++b
)
46 crc64_table
[s
][b
] = bswap64(crc64_table
[s
][b
]);
54 print_crc64_table(void)
56 printf("/* This file has been automatically generated by "
57 "crc64_tablegen.c. */\n\n"
58 "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
60 for (size_t s
= 0; s
< 4; ++s
) {
61 for (size_t b
= 0; b
< 256; ++b
) {
65 printf("UINT64_C(0x%016" PRIX64
")",
69 printf(",%s", (b
+1) % 2 == 0 ? "" : " ");
73 printf("\n\t}\n};\n");