GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / tools / misc / xz / src / liblzma / rangecoder / price_tablegen.c
blobbf08ce39d7e5922a898e5909eca33c9ecca6acf2
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file price_tablegen.c
4 /// \brief Probability price table generator
5 ///
6 /// Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c
7 ///
8 // Authors: Igor Pavlov
9 // Lasse Collin
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
14 ///////////////////////////////////////////////////////////////////////////////
16 #include <inttypes.h>
17 #include <stdio.h>
18 #include "range_common.h"
19 #include "price.h"
22 static uint32_t rc_prices[RC_PRICE_TABLE_SIZE];
25 static void
26 init_price_table(void)
28 for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2;
29 i < RC_BIT_MODEL_TOTAL;
30 i += (UINT32_C(1) << RC_MOVE_REDUCING_BITS)) {
31 const uint32_t cycles_bits = RC_BIT_PRICE_SHIFT_BITS;
32 uint32_t w = i;
33 uint32_t bit_count = 0;
35 for (uint32_t j = 0; j < cycles_bits; ++j) {
36 w *= w;
37 bit_count <<= 1;
39 while (w >= (UINT32_C(1) << 16)) {
40 w >>= 1;
41 ++bit_count;
45 rc_prices[i >> RC_MOVE_REDUCING_BITS]
46 = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits)
47 - 15 - bit_count;
50 return;
54 static void
55 print_price_table(void)
57 printf("/* This file has been automatically generated by "
58 "price_tablegen.c. */\n\n"
59 "#include \"range_encoder.h\"\n\n"
60 "const uint8_t lzma_rc_prices["
61 "RC_PRICE_TABLE_SIZE] = {");
63 const size_t array_size = sizeof(lzma_rc_prices)
64 / sizeof(lzma_rc_prices[0]);
65 for (size_t i = 0; i < array_size; ++i) {
66 if (i % 8 == 0)
67 printf("\n\t");
69 printf("%4" PRIu32, rc_prices[i]);
71 if (i != array_size - 1)
72 printf(",");
75 printf("\n};\n");
77 return;
81 int
82 main(void)
84 init_price_table();
85 print_price_table();
86 return 0;