]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/rangecoder/range_common.h
Added precomputed range coder probability price table.
[icculus/xz.git] / src / liblzma / rangecoder / range_common.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       range_common.h
4 /// \brief      Common things for range encoder and decoder
5 //
6 //  Copyright (C) 1999-2006 Igor Pavlov
7 //  Copyright (C) 2006 Lasse Collin
8 //
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Lesser General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2.1 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Lesser General Public License for more details.
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 #ifndef LZMA_RANGE_COMMON_H
22 #define LZMA_RANGE_COMMON_H
23
24 #ifdef HAVE_CONFIG_H
25 #       include "common.h"
26 #endif
27
28
29 ///////////////
30 // Constants //
31 ///////////////
32
33 #define SHIFT_BITS 8
34 #define TOP_BITS 24
35 #define TOP_VALUE (UINT32_C(1) << TOP_BITS)
36 #define BIT_MODEL_TOTAL_BITS 11
37 #define BIT_MODEL_TOTAL (UINT32_C(1) << BIT_MODEL_TOTAL_BITS)
38 #define MOVE_BITS 5
39
40 #define MOVE_REDUCING_BITS 2
41 #define BIT_PRICE_SHIFT_BITS 6
42
43
44 ////////////
45 // Macros //
46 ////////////
47
48 // Resets the probability so that both 0 and 1 have probability of 50 %
49 #define bit_reset(prob) \
50         prob = BIT_MODEL_TOTAL >> 1
51
52 // This does the same for a complete bit tree.
53 // (A tree represented as an array.)
54 #define bittree_reset(probs, bit_levels) \
55         for (uint32_t bt_i = 0; bt_i < (1 << (bit_levels)); ++bt_i) \
56                 bit_reset((probs)[bt_i])
57
58
59 //////////////////////
60 // Type definitions //
61 //////////////////////
62
63 // Bit coder speed optimization
64 // uint16_t is enough for probability, but usually uint32_t is faster and it
65 // doesn't waste too much memory. If uint64_t is fastest on 64-bit CPU, you
66 // probably want to use that instead of uint32_t. With uint64_t you will
67 // waste RAM _at maximum_ of 4.5 MiB (same for both encoding and decoding).
68 typedef uint32_t probability;
69
70 #endif