]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/rangecoder/range_common.h
Imported to git.
[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 #include "common.h"
25
26
27 ///////////////
28 // Constants //
29 ///////////////
30
31 #define SHIFT_BITS 8
32 #define TOP_BITS 24
33 #define TOP_VALUE (UINT32_C(1) << TOP_BITS)
34 #define BIT_MODEL_TOTAL_BITS 11
35 #define BIT_MODEL_TOTAL (UINT32_C(1) << BIT_MODEL_TOTAL_BITS)
36 #define MOVE_BITS 5
37
38 #define MOVE_REDUCING_BITS 2
39 #define BIT_PRICE_SHIFT_BITS 6
40
41
42 ////////////
43 // Macros //
44 ////////////
45
46 // Resets the probability so that both 0 and 1 have probability of 50 %
47 #define bit_reset(prob) \
48         prob = BIT_MODEL_TOTAL >> 1
49
50 // This does the same for a complete bit tree.
51 // (A tree represented as an array.)
52 #define bittree_reset(probs, bit_levels) \
53         for (uint32_t bt_i = 0; bt_i < (1 << (bit_levels)); ++bt_i) \
54                 bit_reset((probs)[bt_i])
55
56
57 //////////////////////
58 // Type definitions //
59 //////////////////////
60
61 // Bit coder speed optimization
62 // uint16_t is enough for probability, but usually uint32_t is faster and it
63 // doesn't waste too much memory. If uint64_t is fastest on 64-bit CPU, you
64 // probably want to use that instead of uint32_t. With uint64_t you will
65 // waste RAM _at maximum_ of 4.5 MiB (same for both encoding and decoding).
66 typedef uint32_t probability;
67
68 #endif