]> pd.if.org Git - zpackage/blob - lzma/rangecoder/range_common.h
add needed headers to lzma files
[zpackage] / lzma / rangecoder / range_common.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       range_common.h
4 /// \brief      Common things for range encoder and decoder
5 ///
6 //  Authors:    Igor Pavlov
7 //              Lasse Collin
8 //
9 //  This file has been put into the public domain.
10 //  You can do whatever you want with this file.
11 //
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #ifndef LZMA_RANGE_COMMON_H
15 #define LZMA_RANGE_COMMON_H
16
17 #include <stdint.h>
18 #ifdef HAVE_CONFIG_H
19 #       include "common.h"
20 #endif
21
22
23 ///////////////
24 // Constants //
25 ///////////////
26
27 #define RC_SHIFT_BITS 8
28 #define RC_TOP_BITS 24
29 #define RC_TOP_VALUE (UINT32_C(1) << RC_TOP_BITS)
30 #define RC_BIT_MODEL_TOTAL_BITS 11
31 #define RC_BIT_MODEL_TOTAL (UINT32_C(1) << RC_BIT_MODEL_TOTAL_BITS)
32 #define RC_MOVE_BITS 5
33
34
35 ////////////
36 // Macros //
37 ////////////
38
39 // Resets the probability so that both 0 and 1 have probability of 50 %
40 #define bit_reset(prob) \
41         prob = RC_BIT_MODEL_TOTAL >> 1
42
43 // This does the same for a complete bit tree.
44 // (A tree represented as an array.)
45 #define bittree_reset(probs, bit_levels) \
46         for (uint32_t bt_i = 0; bt_i < (1 << (bit_levels)); ++bt_i) \
47                 bit_reset((probs)[bt_i])
48
49
50 //////////////////////
51 // Type definitions //
52 //////////////////////
53
54 /// \brief      Type of probabilities used with range coder
55 ///
56 /// This needs to be at least 12-bit integer, so uint16_t is a logical choice.
57 /// However, on some architecture and compiler combinations, a bigger type
58 /// may give better speed, because the probability variables are accessed
59 /// a lot. On the other hand, bigger probability type increases cache
60 /// footprint, since there are 2 to 14 thousand probability variables in
61 /// LZMA (assuming the limit of lc + lp <= 4; with lc + lp <= 12 there
62 /// would be about 1.5 million variables).
63 ///
64 /// With malicious files, the initialization speed of the LZMA decoder can
65 /// become important. In that case, smaller probability variables mean that
66 /// there is less bytes to write to RAM, which makes initialization faster.
67 /// With big probability type, the initialization can become so slow that it
68 /// can be a problem e.g. for email servers doing virus scanning.
69 ///
70 /// I will be sticking to uint16_t unless some specific architectures
71 /// are *much* faster (20-50 %) with uint32_t.
72 typedef uint16_t probability;
73
74 #endif