summaryrefslogtreecommitdiff
path: root/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c')
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c162
1 files changed, 90 insertions, 72 deletions
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
index 9979bb4261..1bee2a9a39 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
@@ -114,33 +114,33 @@ do { \
case seq ## _CHOICE: \
rc_if_0(ld.choice, seq ## _CHOICE) { \
rc_update_0(ld.choice); \
- rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW0); \
- rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW1); \
- rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW2); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW0); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW1); \
+ rc_bit_case(ld.low[pos_state][symbol], 0, 0, seq ## _LOW2); \
target = symbol - LEN_LOW_SYMBOLS + MATCH_LEN_MIN; \
} else { \
rc_update_1(ld.choice); \
case seq ## _CHOICE2: \
rc_if_0(ld.choice2, seq ## _CHOICE2) { \
rc_update_0(ld.choice2); \
- rc_bit_case(ld.mid[pos_state][symbol], , , \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
seq ## _MID0); \
- rc_bit_case(ld.mid[pos_state][symbol], , , \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
seq ## _MID1); \
- rc_bit_case(ld.mid[pos_state][symbol], , , \
+ rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
seq ## _MID2); \
target = symbol - LEN_MID_SYMBOLS \
+ MATCH_LEN_MIN + LEN_LOW_SYMBOLS; \
} else { \
rc_update_1(ld.choice2); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH0); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH1); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH2); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH3); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH4); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH5); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH6); \
- rc_bit_case(ld.high[symbol], , , seq ## _HIGH7); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH0); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH1); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH2); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH3); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH4); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH5); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH6); \
+ rc_bit_case(ld.high[symbol], 0, 0, seq ## _HIGH7); \
target = symbol - LEN_HIGH_SYMBOLS \
+ MATCH_LEN_MIN \
+ LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; \
@@ -285,13 +285,6 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size)
{
- ////////////////////
- // Initialization //
- ////////////////////
-
- if (!rc_read_init(&coder->rc, in, in_pos, in_size))
- return LZMA_OK;
-
///////////////
// Variables //
///////////////
@@ -338,6 +331,16 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
if (no_eopm && coder->uncompressed_size < dict.limit - dict.pos)
dict.limit = dict.pos + (size_t)(coder->uncompressed_size);
+ ////////////////////
+ // Initialization //
+ ////////////////////
+
+ if (!rc_read_init(&coder->rc, in, in_pos, in_size))
+ return LZMA_OK;
+
+ rc = coder->rc;
+ rc_in_pos = *in_pos;
+
// The main decoder loop. The "switch" is used to restart the decoder at
// correct location. Once restarted, the "switch" is no longer used.
switch (coder->sequence)
@@ -353,6 +356,21 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
break;
rc_if_0(coder->is_match[state][pos_state], SEQ_IS_MATCH) {
+ static const lzma_lzma_state next_state[] = {
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_LIT_LIT,
+ STATE_MATCH_LIT_LIT,
+ STATE_REP_LIT_LIT,
+ STATE_SHORTREP_LIT_LIT,
+ STATE_MATCH_LIT,
+ STATE_REP_LIT,
+ STATE_SHORTREP_LIT,
+ STATE_MATCH_LIT,
+ STATE_REP_LIT
+ };
+
rc_update_0(coder->is_match[state][pos_state]);
// It's a literal i.e. a single 8-bit byte.
@@ -370,16 +388,21 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
rc_bit(probs[symbol], , , SEQ_LITERAL);
} while (symbol < (1 << 8));
#else
- rc_bit_case(probs[symbol], , , SEQ_LITERAL0);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL1);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL2);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL3);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL4);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL5);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL6);
- rc_bit_case(probs[symbol], , , SEQ_LITERAL7);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL0);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL1);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL2);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL3);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL4);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL5);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL6);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_LITERAL7);
#endif
} else {
+#ifndef HAVE_SMALL
+ uint32_t match_bit;
+ uint32_t subcoder_index;
+#endif
+
// Decode literal with match byte.
//
// We store the byte we compare against
@@ -418,8 +441,6 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
} while (symbol < (1 << 8));
#else
// Unroll the loop.
- uint32_t match_bit;
- uint32_t subcoder_index;
# define d(seq) \
case seq: \
@@ -453,20 +474,6 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
// Use a lookup table to update to literal state,
// since compared to other state updates, this would
// need two branches.
- static const lzma_lzma_state next_state[] = {
- STATE_LIT_LIT,
- STATE_LIT_LIT,
- STATE_LIT_LIT,
- STATE_LIT_LIT,
- STATE_MATCH_LIT_LIT,
- STATE_REP_LIT_LIT,
- STATE_SHORTREP_LIT_LIT,
- STATE_MATCH_LIT,
- STATE_REP_LIT,
- STATE_SHORTREP_LIT,
- STATE_MATCH_LIT,
- STATE_REP_LIT
- };
state = next_state[state];
case SEQ_LITERAL_WRITE:
@@ -511,12 +518,12 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
rc_bit(probs[symbol], , , SEQ_POS_SLOT);
} while (symbol < POS_SLOTS);
#else
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT0);
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT1);
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT2);
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT3);
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT4);
- rc_bit_case(probs[symbol], , , SEQ_POS_SLOT5);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT0);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT1);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT2);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT3);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT4);
+ rc_bit_case(probs[symbol], 0, 0, SEQ_POS_SLOT5);
#endif
// Get rid of the highest bit that was needed for
// indexing of the probability array.
@@ -564,25 +571,25 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
switch (limit) {
case 5:
assert(offset == 0);
- rc_bit(probs[symbol], ,
+ rc_bit(probs[symbol], 0,
rep0 += 1,
SEQ_POS_MODEL);
++offset;
--limit;
case 4:
- rc_bit(probs[symbol], ,
+ rc_bit(probs[symbol], 0,
rep0 += 1 << offset,
SEQ_POS_MODEL);
++offset;
--limit;
case 3:
- rc_bit(probs[symbol], ,
+ rc_bit(probs[symbol], 0,
rep0 += 1 << offset,
SEQ_POS_MODEL);
++offset;
--limit;
case 2:
- rc_bit(probs[symbol], ,
+ rc_bit(probs[symbol], 0,
rep0 += 1 << offset,
SEQ_POS_MODEL);
++offset;
@@ -594,7 +601,7 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
// rc_bit_last() here to omit
// the unneeded updating of
// "symbol".
- rc_bit_last(probs[symbol], ,
+ rc_bit_last(probs[symbol], 0,
rep0 += 1 << offset,
SEQ_POS_MODEL);
}
@@ -628,19 +635,19 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
} while (++offset < ALIGN_BITS);
#else
case SEQ_ALIGN0:
- rc_bit(coder->pos_align[symbol], ,
+ rc_bit(coder->pos_align[symbol], 0,
rep0 += 1, SEQ_ALIGN0);
case SEQ_ALIGN1:
- rc_bit(coder->pos_align[symbol], ,
+ rc_bit(coder->pos_align[symbol], 0,
rep0 += 2, SEQ_ALIGN1);
case SEQ_ALIGN2:
- rc_bit(coder->pos_align[symbol], ,
+ rc_bit(coder->pos_align[symbol], 0,
rep0 += 4, SEQ_ALIGN2);
case SEQ_ALIGN3:
// Like in SEQ_POS_MODEL, we don't
// need "symbol" for anything else
// than indexing the probability array.
- rc_bit_last(coder->pos_align[symbol], ,
+ rc_bit_last(coder->pos_align[symbol], 0,
rep0 += 8, SEQ_ALIGN3);
#endif
@@ -725,9 +732,11 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
// is stored to rep0 and rep1, rep2 and rep3
// are updated accordingly.
rc_if_0(coder->is_rep1[state], SEQ_IS_REP1) {
+ uint32_t distance;
+
rc_update_0(coder->is_rep1[state]);
- const uint32_t distance = rep1;
+ distance = rep1;
rep1 = rep0;
rep0 = distance;
@@ -736,19 +745,23 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
case SEQ_IS_REP2:
rc_if_0(coder->is_rep2[state],
SEQ_IS_REP2) {
+ uint32_t distance;
+
rc_update_0(coder->is_rep2[
state]);
- const uint32_t distance = rep2;
+ distance = rep2;
rep2 = rep1;
rep1 = rep0;
rep0 = distance;
} else {
+ uint32_t distance;
+
rc_update_1(coder->is_rep2[
state]);
- const uint32_t distance = rep3;
+ distance = rep3;
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
@@ -853,6 +866,9 @@ lzma_lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
static void
lzma_decoder_reset(lzma_coder *coder, const void *opt)
{
+ uint32_t i, j, pos_state;
+ uint32_t num_pos_states;
+
const lzma_options_lzma *options = opt;
// NOTE: We assume that lc/lp/pb are valid since they were
@@ -879,8 +895,8 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
rc_reset(coder->rc);
// Bit and bittree decoders
- for (uint32_t i = 0; i < STATES; ++i) {
- for (uint32_t j = 0; j <= coder->pos_mask; ++j) {
+ for (i = 0; i < STATES; ++i) {
+ for (j = 0; j <= coder->pos_mask; ++j) {
bit_reset(coder->is_match[i][j]);
bit_reset(coder->is_rep0_long[i][j]);
}
@@ -891,22 +907,22 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
bit_reset(coder->is_rep2[i]);
}
- for (uint32_t i = 0; i < LEN_TO_POS_STATES; ++i)
+ for (i = 0; i < LEN_TO_POS_STATES; ++i)
bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
- for (uint32_t i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
+ for (i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
bit_reset(coder->pos_special[i]);
bittree_reset(coder->pos_align, ALIGN_BITS);
// Len decoders (also bit/bittree)
- const uint32_t num_pos_states = 1U << options->pb;
+ num_pos_states = 1U << options->pb;
bit_reset(coder->match_len_decoder.choice);
bit_reset(coder->match_len_decoder.choice2);
bit_reset(coder->rep_len_decoder.choice);
bit_reset(coder->rep_len_decoder.choice2);
- for (uint32_t pos_state = 0; pos_state < num_pos_states; ++pos_state) {
+ for (pos_state = 0; pos_state < num_pos_states; ++pos_state) {
bittree_reset(coder->match_len_decoder.low[pos_state],
LEN_LOW_BITS);
bittree_reset(coder->match_len_decoder.mid[pos_state],
@@ -936,6 +952,8 @@ extern lzma_ret
lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
const void *opt, lzma_lz_options *lz_options)
{
+ const lzma_options_lzma *options = opt;
+
if (lz->coder == NULL) {
lz->coder = lzma_alloc(sizeof(lzma_coder), allocator);
if (lz->coder == NULL)
@@ -948,7 +966,6 @@ lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
// All dictionary sizes are OK here. LZ decoder will take care of
// the special cases.
- const lzma_options_lzma *options = opt;
lz_options->dict_size = options->dict_size;
lz_options->preset_dict = options->preset_dict;
lz_options->preset_dict_size = options->preset_dict_size;
@@ -1028,11 +1045,12 @@ extern lzma_ret
lzma_lzma_props_decode(void **options, lzma_allocator *allocator,
const uint8_t *props, size_t props_size)
{
+ lzma_options_lzma *opt;
+
if (props_size != 5)
return LZMA_OPTIONS_ERROR;
- lzma_options_lzma *opt
- = lzma_alloc(sizeof(lzma_options_lzma), allocator);
+ opt = lzma_alloc(sizeof(lzma_options_lzma), allocator);
if (opt == NULL)
return LZMA_MEM_ERROR;