]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_common.h
Added support for flush marker, which will be in files
[icculus/xz.git] / src / liblzma / lzma / lzma_common.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       lzma_common.h
4 /// \brief      Private definitions common to LZMA encoder and decoder
5 //
6 //  Copyright (C) 1999-2006 Igor Pavlov
7 //  Copyright (C) 2007 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_LZMA_COMMON_H
22 #define LZMA_LZMA_COMMON_H
23
24 #include "common.h"
25 #include "lzma_literal.h"
26 #include "range_common.h"
27
28
29 ///////////////
30 // Constants //
31 ///////////////
32
33 #define REP_DISTANCES 4
34 #define STATES 12
35 #define LIT_STATES 7
36
37 #define POS_SLOT_BITS 6
38 #define DICT_LOG_SIZE_MAX 30
39 #define DIST_TABLE_SIZE_MAX (DICT_LOG_SIZE_MAX * 2)
40 #if (UINT32_C(1) << DICT_LOG_SIZE_MAX) != LZMA_DICTIONARY_SIZE_MAX
41 #       error DICT_LOG_SIZE_MAX is inconsistent with LZMA_DICTIONARY_SIZE_MAX
42 #endif
43
44 // 2 is for speed optimization
45 #define LEN_TO_POS_STATES_BITS 2
46 #define LEN_TO_POS_STATES (1 << LEN_TO_POS_STATES_BITS)
47
48 #define MATCH_MIN_LEN 2
49
50 #define ALIGN_BITS 4
51 #define ALIGN_TABLE_SIZE (1 << ALIGN_BITS)
52 #define ALIGN_MASK (ALIGN_TABLE_SIZE - 1)
53
54 #define START_POS_MODEL_INDEX 4
55 #define END_POS_MODEL_INDEX 14
56 #define POS_MODELS (END_POS_MODEL_INDEX - START_POS_MODEL_INDEX)
57
58 #define FULL_DISTANCES (1 << (END_POS_MODEL_INDEX / 2))
59
60 #define LIT_POS_STATES_BITS_MAX LZMA_LITERAL_POS_BITS_MAX
61 #define LIT_CONTEXT_BITS_MAX LZMA_LITERAL_CONTEXT_BITS_MAX
62
63 #define POS_STATES_BITS_MAX LZMA_POS_BITS_MAX
64 #define POS_STATES_MAX (1 << POS_STATES_BITS_MAX)
65
66
67 // Length coder & Length price table encoder
68 #define LEN_LOW_BITS 3
69 #define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
70 #define LEN_MID_BITS 3
71 #define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
72 #define LEN_HIGH_BITS 8
73 #define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
74 #define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
75 #define LEN_SPEC_SYMBOLS (LOW_LOW_SYMBOLS + LEN_MID_LEN_SYMBOLS)
76 #define MATCH_MAX_LEN (MATCH_MIN_LEN + LEN_SYMBOLS - 1)
77
78 // Total number of probs in a Len Encoder
79 #define LEN_CODER_TOTAL_PROBS (LEN_HIGH_CODER + LEN_HIGH_SYMBOLS)
80
81 // Price table size of Len Encoder
82 #define LEN_PRICES (LEN_SYMBOLS << POS_STATES_BITS_MAX)
83
84 // Special lengths used together with distance == UINT32_MAX
85 #define LEN_SPECIAL_EOPM MATCH_MIN_LEN
86 #define LEN_SPECIAL_FLUSH (LEN_SPECIAL_EOPM + 1)
87
88
89 // Optimal - Number of entries in the optimum array.
90 #define OPTS (1 << 12)
91
92
93 // Miscellaneous
94 #define INFINITY_PRICE 0x0FFFFFFF
95
96
97 ////////////
98 // Macros //
99 ////////////
100
101 #define get_len_to_pos_state(len) \
102         ((len) < LEN_TO_POS_STATES + MATCH_MIN_LEN \
103                 ? (len) - MATCH_MIN_LEN \
104                 : LEN_TO_POS_STATES - 1)
105
106
107 ///////////
108 // State //
109 ///////////
110
111 // Used for updating strm->data->state in both encoder and decoder.
112
113 #define update_char(index) \
114         index = ((index) < 4 \
115                         ? 0 \
116                         : ((index) < 10 \
117                                 ? (index) - 3 \
118                                 : (index) - 6))
119
120 #define update_match(index) \
121         index = ((index) < LIT_STATES ? 7 : 10)
122
123 #define update_rep(index) \
124         index = ((index) < LIT_STATES ? 8 : 11)
125
126 #define update_short_rep(index) \
127         index = ((index) < LIT_STATES ? 9 : 11)
128
129 #define is_char_state(index) \
130         ((index) < LIT_STATES)
131
132 #endif