]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/fastpos_tablegen.c
Revised the fastpos code. It now uses the slightly faster
[icculus/xz.git] / src / liblzma / lzma / fastpos_tablegen.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       fastpos_tablegen.c
4 /// \brief      Generates the lzma_fastpos[] lookup table
5 //
6 //  Copyright (C) 1999-2007 Igor Pavlov
7 //  Copyright (C) 2008 Lasse Collin
8 //
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.
13 //
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.
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 #include <sys/types.h>
22 #include <inttypes.h>
23 #include <stdio.h>
24 #include "fastpos.h"
25
26
27 int
28 main(void)
29 {
30         uint8_t fastpos[1 << FASTPOS_BITS];
31
32         const uint8_t fast_slots = 2 * FASTPOS_BITS;
33         uint32_t c = 2;
34
35         fastpos[0] = 0;
36         fastpos[1] = 1;
37
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;
42         }
43
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] = {");
49
50         for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
51                 if (i % 16 == 0)
52                         printf("\n\t");
53
54                 printf("%3u", (unsigned int)(fastpos[i]));
55
56                 if (i != (1 << FASTPOS_BITS) - 1)
57                         printf(",");
58         }
59
60         printf("\n};\n");
61
62         return 0;
63 }