1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file crc32_tablegen.c
4 /// \brief Generate crc32_table_le.h and crc32_table_be.h
6 /// Compiling: gcc -std=c99 -o crc32_tablegen crc32_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 ///////////////////////////////////////////////////////////////////////////////
19 #ifdef WORDS_BIGENDIAN
20 # include "../../common/bswap.h"
24 static uint32_t crc32_table[8][256];
28 init_crc32_table(void)
30 static const uint32_t poly32 = UINT32_C(0xEDB88320);
32 for (size_t s = 0; s < 8; ++s) {
33 for (size_t b = 0; b < 256; ++b) {
34 uint32_t r = s == 0 ? b : crc32_table[s - 1][b];
36 for (size_t i = 0; i < 8; ++i) {
38 r = (r >> 1) ^ poly32;
43 crc32_table[s][b] = r;
47 #ifdef WORDS_BIGENDIAN
48 for (size_t s = 0; s < 8; ++s)
49 for (size_t b = 0; b < 256; ++b)
50 crc32_table[s][b] = bswap_32(crc32_table[s][b]);
58 print_crc32_table(void)
60 printf("/* This file has been automatically generated by "
61 "crc32_tablegen.c. */\n\n"
62 "const uint32_t lzma_crc32_table[8][256] = {\n\t{");
64 for (size_t s = 0; s < 8; ++s) {
65 for (size_t b = 0; b < 256; ++b) {
69 printf("0x%08" PRIX32, crc32_table[s][b]);
72 printf(",%s", (b+1) % 4 == 0 ? "" : " ");
76 printf("\n\t}\n};\n");