Rizin
unix-like reverse engineering framework and cli tools
price_tablegen.c
Go to the documentation of this file.
1 //
8 // Authors: Igor Pavlov
9 // Lasse Collin
10 //
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
13 //
15 
16 #include <inttypes.h>
17 #include <stdio.h>
18 #include "range_common.h"
19 #include "price.h"
20 
21 
23 
24 
25 static void
27 {
28  for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2;
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;
34 
35  for (uint32_t j = 0; j < cycles_bits; ++j) {
36  w *= w;
37  bit_count <<= 1;
38 
39  while (w >= (UINT32_C(1) << 16)) {
40  w >>= 1;
41  ++bit_count;
42  }
43  }
44 
46  = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits)
47  - 15 - bit_count;
48  }
49 
50  return;
51 }
52 
53 
54 static void
56 {
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] = {");
62 
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");
68 
69  printf("%4" PRIu32, rc_prices[i]);
70 
71  if (i != array_size - 1)
72  printf(",");
73  }
74 
75  printf("\n};\n");
76 
77  return;
78 }
79 
80 
81 int
82 main(void)
83 {
86  return 0;
87 }
lzma_index ** i
Definition: index.h:629
#define w
Definition: crypto_rc6.c:13
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define PRIu32
Definition: macros.h:20
Probability price calculation.
#define RC_MOVE_REDUCING_BITS
Definition: price.h:17
#define RC_PRICE_TABLE_SIZE
Definition: price.h:19
const uint8_t lzma_rc_prices[RC_PRICE_TABLE_SIZE]
Lookup table for the inline functions defined in this file.
Definition: price_table.c:5
#define RC_BIT_PRICE_SHIFT_BITS
Definition: price.h:18
int main(void)
static void print_price_table(void)
static uint32_t rc_prices[RC_PRICE_TABLE_SIZE]
static void init_price_table(void)
Common things for range encoder and decoder.
#define RC_BIT_MODEL_TOTAL_BITS
Definition: range_common.h:27
#define RC_BIT_MODEL_TOTAL
Definition: range_common.h:28
unsigned int uint32_t
Definition: sftypes.h:29
#define UINT32_C(val)