1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       fastpos_tablegen.c
4 /// \brief      Generates the lzma_fastpos[] lookup table
5 ///
6 //  Authors:    Igor Pavlov
7 //              Lasse Collin
8 //
9 //  This file has been put into the public domain.
10 //  You can do whatever you want with this file.
11 //
12 ///////////////////////////////////////////////////////////////////////////////
13 
14 #include <inttypes.h>
15 #include <stdio.h>
16 
17 #define lzma_attr_visibility_hidden
18 #include "fastpos.h"
19 
20 
21 int
22 main(void)
23 {
24 	uint8_t fastpos[1 << FASTPOS_BITS];
25 
26 	const uint8_t fast_slots = 2 * FASTPOS_BITS;
27 	uint32_t c = 2;
28 
29 	fastpos[0] = 0;
30 	fastpos[1] = 1;
31 
32 	for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
33 		const uint32_t k = 1 << ((slot_fast >> 1) - 1);
34 		for (uint32_t j = 0; j < k; ++j, ++c)
35 			fastpos[c] = slot_fast;
36 	}
37 
38 	printf("/* This file has been automatically generated "
39 			"by fastpos_tablegen.c. */\n\n"
40 			"#include \"common.h\"\n"
41 			"#include \"fastpos.h\"\n\n"
42 			"const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
43 
44 	for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
45 		if (i % 16 == 0)
46 			printf("\n\t");
47 
48 		printf("%3u", (unsigned int)(fastpos[i]));
49 
50 		if (i != (1 << FASTPOS_BITS) - 1)
51 			printf(",");
52 	}
53 
54 	printf("\n};\n");
55 
56 	return 0;
57 }
58