Rizin
unix-like reverse engineering framework and cli tools
price.h
Go to the documentation of this file.
1 //
5 //
6 // Author: Igor Pavlov
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #ifndef LZMA_PRICE_H
14 #define LZMA_PRICE_H
15 
16 
17 #define RC_MOVE_REDUCING_BITS 4
18 #define RC_BIT_PRICE_SHIFT_BITS 4
19 #define RC_PRICE_TABLE_SIZE (RC_BIT_MODEL_TOTAL >> RC_MOVE_REDUCING_BITS)
20 
21 #define RC_INFINITY_PRICE (UINT32_C(1) << 30)
22 
23 
26 
27 
28 static inline uint32_t
30 {
31  return lzma_rc_prices[(prob ^ ((UINT32_C(0) - bit)
33 }
34 
35 
36 static inline uint32_t
38 {
39  return lzma_rc_prices[prob >> RC_MOVE_REDUCING_BITS];
40 }
41 
42 
43 static inline uint32_t
45 {
46  return lzma_rc_prices[(prob ^ (RC_BIT_MODEL_TOTAL - 1))
48 }
49 
50 
51 static inline uint32_t
52 rc_bittree_price(const probability *const probs,
53  const uint32_t bit_levels, uint32_t symbol)
54 {
55  uint32_t price = 0;
56  symbol += UINT32_C(1) << bit_levels;
57 
58  do {
59  const uint32_t bit = symbol & 1;
60  symbol >>= 1;
61  price += rc_bit_price(probs[symbol], bit);
62  } while (symbol != 1);
63 
64  return price;
65 }
66 
67 
68 static inline uint32_t
70  uint32_t bit_levels, uint32_t symbol)
71 {
72  uint32_t price = 0;
73  uint32_t model_index = 1;
74 
75  do {
76  const uint32_t bit = symbol & 1;
77  symbol >>= 1;
78  price += rc_bit_price(probs[model_index], bit);
79  model_index = (model_index << 1) + bit;
80  } while (--bit_levels != 0);
81 
82  return price;
83 }
84 
85 
86 static inline uint32_t
88 {
89  return bits << RC_BIT_PRICE_SHIFT_BITS;
90 }
91 
92 #endif
int bits(struct state *s, int need)
Definition: blast.c:72
RzCryptoSelector bit
Definition: crypto.c:16
static uint32_t rc_bit_price(const probability prob, const uint32_t bit)
Definition: price.h:29
#define RC_MOVE_REDUCING_BITS
Definition: price.h:17
static uint32_t rc_bittree_price(const probability *const probs, const uint32_t bit_levels, uint32_t symbol)
Definition: price.h:52
#define RC_PRICE_TABLE_SIZE
Definition: price.h:19
static uint32_t rc_bittree_reverse_price(const probability *const probs, uint32_t bit_levels, uint32_t symbol)
Definition: price.h:69
static uint32_t rc_bit_0_price(const probability prob)
Definition: price.h:37
static uint32_t rc_bit_1_price(const probability prob)
Definition: price.h:44
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
static uint32_t rc_direct_price(const uint32_t bits)
Definition: price.h:87
#define RC_BIT_PRICE_SHIFT_BITS
Definition: price.h:18
uint16_t probability
Type of probabilities used with range coder.
Definition: range_common.h:69
#define RC_BIT_MODEL_TOTAL
Definition: range_common.h:28
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define UINT32_C(val)