1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file price_tablegen.c
4 /// \brief Probability price table generator
6 /// Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c
8 // Authors: Igor Pavlov
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
14 ///////////////////////////////////////////////////////////////////////////////
18 #include "range_common.h"
22 static uint32_t rc_prices
[RC_PRICE_TABLE_SIZE
];
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
;
33 uint32_t bit_count
= 0;
35 for (uint32_t j
= 0; j
< cycles_bits
; ++j
) {
39 while (w
>= (UINT32_C(1) << 16)) {
45 rc_prices
[i
>> RC_MOVE_REDUCING_BITS
]
46 = (RC_BIT_MODEL_TOTAL_BITS
<< cycles_bits
)
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
) {
69 printf("%4" PRIu32
, rc_prices
[i
]);
71 if (i
!= array_size
- 1)