1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file fastpos_tablegen.c
4 /// \brief Generates the lzma_fastpos[] lookup table
6 // Copyright (C) 1999-2007 Igor Pavlov
7 // Copyright (C) 2008 Lasse Collin
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 ///////////////////////////////////////////////////////////////////////////////
21 #include <sys/types.h>
30 uint8_t fastpos[1 << FASTPOS_BITS];
32 const uint8_t fast_slots = 2 * FASTPOS_BITS;
38 for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
39 const uint32_t k = 1 << ((slot_fast >> 1) - 1);
40 for (uint32_t j = 0; j < k; ++j, ++c)
41 fastpos[c] = slot_fast;
44 printf("/* This file has been automatically generated "
45 "by fastpos_tablegen.c. */\n\n"
46 "#include \"common.h\"\n"
47 "#include \"fastpos.h\"\n\n"
48 "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
50 for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
54 printf("%3u", (unsigned int)(fastpos[i]));
56 if (i != (1 << FASTPOS_BITS) - 1)