Rizin
unix-like reverse engineering framework and cli tools
price_tablegen.c File Reference

Probability price table generator. More...

#include <inttypes.h>
#include <stdio.h>
#include "range_common.h"
#include "price.h"

Go to the source code of this file.

Functions

static void init_price_table (void)
 
static void print_price_table (void)
 
int main (void)
 

Variables

static uint32_t rc_prices [RC_PRICE_TABLE_SIZE]
 

Detailed Description

Probability price table generator.

Compiling: gcc -std=c99 -o price_tablegen price_tablegen.c

Definition in file price_tablegen.c.

Function Documentation

◆ init_price_table()

static void init_price_table ( void  )
static

Definition at line 26 of file price_tablegen.c.

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 }
lzma_index ** i
Definition: index.h:629
#define w
Definition: crypto_rc6.c:13
#define RC_MOVE_REDUCING_BITS
Definition: price.h:17
#define RC_BIT_PRICE_SHIFT_BITS
Definition: price.h:18
static uint32_t rc_prices[RC_PRICE_TABLE_SIZE]
#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)

References i, RC_BIT_MODEL_TOTAL, RC_BIT_MODEL_TOTAL_BITS, RC_BIT_PRICE_SHIFT_BITS, RC_MOVE_REDUCING_BITS, rc_prices, UINT32_C, and w.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 82 of file price_tablegen.c.

83 {
86  return 0;
87 }
static void print_price_table(void)
static void init_price_table(void)

References init_price_table(), and print_price_table().

◆ print_price_table()

static void print_price_table ( void  )
static

Definition at line 55 of file price_tablegen.c.

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 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define PRIu32
Definition: macros.h:20
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

References i, lzma_rc_prices, printf(), PRIu32, and rc_prices.

Referenced by main().

Variable Documentation

◆ rc_prices

uint32_t rc_prices[RC_PRICE_TABLE_SIZE]
static

Definition at line 22 of file price_tablegen.c.

Referenced by init_price_table(), and print_price_table().