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 // This code has been put into the public domain.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 ///////////////////////////////////////////////////////////////////////////////
20 #ifdef WORDS_BIGENDIAN
21 # include "../../common/bswap.h"
25 static uint64_t crc64_table[4][256];
29 init_crc64_table(void)
31 static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
33 for (size_t s = 0; s < 4; ++s) {
34 for (size_t b = 0; b < 256; ++b) {
35 uint64_t r = s == 0 ? b : crc64_table[s - 1][b];
37 for (size_t i = 0; i < 8; ++i) {
39 r = (r >> 1) ^ poly64;
44 crc64_table[s][b] = r;
48 #ifdef WORDS_BIGENDIAN
49 for (size_t s = 0; s < 4; ++s)
50 for (size_t b = 0; b < 256; ++b)
51 crc64_table[s][b] = bswap_64(crc64_table[s][b]);
59 print_crc64_table(void)
61 printf("/* This file has been automatically generated by "
62 "crc64_tablegen.c. */\n\n"
63 "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
65 for (size_t s = 0; s < 4; ++s) {
66 for (size_t b = 0; b < 256; ++b) {
70 printf("UINT64_C(0x%016" PRIX64 ")",
74 printf(",%s", (b+1) % 2 == 0 ? "" : " ");
78 printf("\n\t}\n};\n");