aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/rangecoder/price_tablegen.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/liblzma/rangecoder/price_tablegen.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/liblzma/rangecoder/price_tablegen.c b/src/liblzma/rangecoder/price_tablegen.c
index 68513635..4895ac76 100644
--- a/src/liblzma/rangecoder/price_tablegen.c
+++ b/src/liblzma/rangecoder/price_tablegen.c
@@ -19,23 +19,51 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include <stddef.h>
#include <inttypes.h>
#include <stdio.h>
#include "range_common.h"
#include "price.h"
-#include "price_table_init.c"
-int
-main(void)
+static uint32_t rc_prices[RC_PRICE_TABLE_SIZE];
+
+
+static void
+init_price_table(void)
{
- lzma_rc_init();
+ for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2;
+ i < RC_BIT_MODEL_TOTAL;
+ i += (UINT32_C(1) << RC_MOVE_REDUCING_BITS)) {
+ const uint32_t cycles_bits = RC_BIT_PRICE_SHIFT_BITS;
+ uint32_t w = i;
+ uint32_t bit_count = 0;
+
+ for (uint32_t j = 0; j < cycles_bits; ++j) {
+ w *= w;
+ bit_count <<= 1;
+
+ while (w >= (UINT32_C(1) << 16)) {
+ w >>= 1;
+ ++bit_count;
+ }
+ }
+
+ rc_prices[i >> RC_MOVE_REDUCING_BITS]
+ = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits)
+ - 15 - bit_count;
+ }
+
+ return;
+}
+
+static void
+print_price_table(void)
+{
printf("/* This file has been automatically generated by "
"price_tablegen.c. */\n\n"
"#include \"range_encoder.h\"\n\n"
- "const uint32_t lzma_rc_prices["
+ "const uint8_t lzma_rc_prices["
"RC_PRICE_TABLE_SIZE] = {");
const size_t array_size = sizeof(lzma_rc_prices)
@@ -44,7 +72,7 @@ main(void)
if (i % 8 == 0)
printf("\n\t");
- printf("%4" PRIu32, lzma_rc_prices[i]);
+ printf("%4" PRIu32, rc_prices[i]);
if (i != array_size - 1)
printf(",");
@@ -52,5 +80,14 @@ main(void)
printf("\n};\n");
+ return;
+}
+
+
+int
+main(void)
+{
+ init_price_table();
+ print_price_table();
return 0;
}