1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
5 /// \file price_tablegen.c
6 /// \brief Probability price table generator
8 /// Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c
10 // Authors: Igor Pavlov
13 ///////////////////////////////////////////////////////////////////////////////
18 // Make it compile without common.h.
19 #define BUILDING_PRICE_TABLEGEN
20 #define lzma_attr_visibility_hidden
22 #include "range_common.h"
26 static uint32_t rc_prices
[RC_PRICE_TABLE_SIZE
];
30 init_price_table(void)
32 for (uint32_t i
= (UINT32_C(1) << RC_MOVE_REDUCING_BITS
) / 2;
33 i
< RC_BIT_MODEL_TOTAL
;
34 i
+= (UINT32_C(1) << RC_MOVE_REDUCING_BITS
)) {
35 const uint32_t cycles_bits
= RC_BIT_PRICE_SHIFT_BITS
;
37 uint32_t bit_count
= 0;
39 for (uint32_t j
= 0; j
< cycles_bits
; ++j
) {
43 while (w
>= (UINT32_C(1) << 16)) {
49 rc_prices
[i
>> RC_MOVE_REDUCING_BITS
]
50 = (RC_BIT_MODEL_TOTAL_BITS
<< cycles_bits
)
59 print_price_table(void)
61 // Split the SPDX string so that it won't accidentally match
62 // when tools search for the string.
63 printf("// SPDX" "-License-Identifier" ": 0BSD\n\n"
64 "// This file has been generated by price_tablegen.c.\n\n"
65 "#include \"range_encoder.h\"\n\n"
66 "const uint8_t lzma_rc_prices["
67 "RC_PRICE_TABLE_SIZE] = {");
69 const size_t array_size
= sizeof(lzma_rc_prices
)
70 / sizeof(lzma_rc_prices
[0]);
71 for (size_t i
= 0; i
< array_size
; ++i
) {
75 printf("%4" PRIu32
, rc_prices
[i
]);
77 if (i
!= array_size
- 1)