1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file range_common.h
4 /// \brief Common things for range encoder and decoder
6 // Copyright (C) 1999-2006 Igor Pavlov
7 // Copyright (C) 2006 Lasse Collin
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.
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.
19 ///////////////////////////////////////////////////////////////////////////////
21 #ifndef LZMA_RANGE_COMMON_H
22 #define LZMA_RANGE_COMMON_H
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)
38 #define MOVE_REDUCING_BITS 2
39 #define BIT_PRICE_SHIFT_BITS 6
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
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])
57 //////////////////////
58 // Type definitions //
59 //////////////////////
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;