1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file lzma_common.h
4 /// \brief Private definitions common to LZMA encoder and decoder
6 // Copyright (C) 1999-2006 Igor Pavlov
7 // Copyright (C) 2007 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_LZMA_COMMON_H
22 #define LZMA_LZMA_COMMON_H
25 #include "lzma_literal.h"
26 #include "range_common.h"
33 #define REP_DISTANCES 4
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
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)
48 #define MATCH_MIN_LEN 2
51 #define ALIGN_TABLE_SIZE (1 << ALIGN_BITS)
52 #define ALIGN_MASK (ALIGN_TABLE_SIZE - 1)
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)
58 #define FULL_DISTANCES (1 << (END_POS_MODEL_INDEX / 2))
60 #define LIT_POS_STATES_BITS_MAX LZMA_LITERAL_POS_BITS_MAX
61 #define LIT_CONTEXT_BITS_MAX LZMA_LITERAL_CONTEXT_BITS_MAX
63 #define POS_STATES_BITS_MAX LZMA_POS_BITS_MAX
64 #define POS_STATES_MAX (1 << POS_STATES_BITS_MAX)
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)
78 // Total number of probs in a Len Encoder
79 #define LEN_CODER_TOTAL_PROBS (LEN_HIGH_CODER + LEN_HIGH_SYMBOLS)
81 // Price table size of Len Encoder
82 #define LEN_PRICES (LEN_SYMBOLS << POS_STATES_BITS_MAX)
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)
89 // Optimal - Number of entries in the optimum array.
90 #define OPTS (1 << 12)
94 #define INFINITY_PRICE 0x0FFFFFFF
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)
111 // Used for updating strm->data->state in both encoder and decoder.
113 #define update_char(index) \
114 index = ((index) < 4 \
120 #define update_match(index) \
121 index = ((index) < LIT_STATES ? 7 : 10)
123 #define update_rep(index) \
124 index = ((index) < LIT_STATES ? 8 : 11)
126 #define update_short_rep(index) \
127 index = ((index) < LIT_STATES ? 9 : 11)
129 #define is_char_state(index) \
130 ((index) < LIT_STATES)