Path: blob/master/Utilities/cmliblzma/liblzma/check/crc64_tablegen.c
3153 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file crc64_tablegen.c5/// \brief Generate crc64_table_le.h and crc64_table_be.h6///7/// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c8/// Add -DWORDS_BIGENDIAN to generate big endian table.9//10// Author: Lasse Collin11//12///////////////////////////////////////////////////////////////////////////////1314#include <stdio.h>15#include "../../common/tuklib_integer.h"161718static uint64_t crc64_table[4][256];192021extern void22init_crc64_table(void)23{24static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);2526for (size_t s = 0; s < 4; ++s) {27for (size_t b = 0; b < 256; ++b) {28uint64_t r = s == 0 ? b : crc64_table[s - 1][b];2930for (size_t i = 0; i < 8; ++i) {31if (r & 1)32r = (r >> 1) ^ poly64;33else34r >>= 1;35}3637crc64_table[s][b] = r;38}39}4041#ifdef WORDS_BIGENDIAN42for (size_t s = 0; s < 4; ++s)43for (size_t b = 0; b < 256; ++b)44crc64_table[s][b] = byteswap64(crc64_table[s][b]);45#endif4647return;48}495051static void52print_crc64_table(void)53{54// Split the SPDX string so that it won't accidentally match55// when tools search for the string.56printf("// SPDX" "-License-Identifier" ": 0BSD\n\n"57"// This file has been generated by crc64_tablegen.c.\n\n"58"const uint64_t lzma_crc64_table[4][256] = {\n\t{");5960for (size_t s = 0; s < 4; ++s) {61for (size_t b = 0; b < 256; ++b) {62if ((b % 2) == 0)63printf("\n\t\t");6465printf("UINT64_C(0x%016" PRIX64 ")",66crc64_table[s][b]);6768if (b != 255)69printf(",%s", (b+1) % 2 == 0 ? "" : " ");70}7172if (s == 3)73printf("\n\t}\n};\n");74else75printf("\n\t}, {");76}7778return;79}808182int83main(void)84{85init_crc64_table();86print_crc64_table();87return 0;88}899091