diff options
Diffstat (limited to 'Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c')
-rw-r--r-- | Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c | 167 |
1 files changed, 114 insertions, 53 deletions
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c index f82a1c1..50c3459 100644 --- a/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c +++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c @@ -32,8 +32,9 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) if (count > 0) { #ifndef NDEBUG + uint32_t i; // Validate the matches. - for (uint32_t i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) { assert(matches[i].len <= mf->nice_len); assert(matches[i].dist < mf->read_pos); assert(memcmp(mf_ptr(mf) - 1, @@ -49,6 +50,9 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) // If a match of maximum search length was found, try to // extend the match to maximum possible length. if (len_best == mf->nice_len) { + uint8_t *p1; + uint8_t *p2; + // The limit for the match length is either the // maximum match length supported by the LZ-based // encoder or the number of bytes left in the @@ -59,11 +63,11 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) // Pointer to the byte we just ran through // the match finder. - const uint8_t *p1 = mf_ptr(mf) - 1; + p1 = mf_ptr(mf) - 1; // Pointer to the beginning of the match. We need -1 // here because the match distances are zero based. - const uint8_t *p2 = p1 - matches[count - 1].dist - 1; + p2 = p1 - matches[count - 1].dist - 1; while (len_best < limit && p1[len_best] == p2[len_best]) @@ -108,18 +112,22 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) static void normalize(lzma_mf *mf) { + uint32_t i; + uint32_t subvalue; + uint32_t count; + uint32_t *hash; + assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS); // In future we may not want to touch the lowest bits, because there // may be match finders that use larger resolution than one byte. - const uint32_t subvalue - = (MUST_NORMALIZE_POS - mf->cyclic_size); + subvalue = (MUST_NORMALIZE_POS - mf->cyclic_size); // & (~(UINT32_C(1) << 10) - 1); - const uint32_t count = mf->hash_size_sum + mf->sons_count; - uint32_t *hash = mf->hash; + count = mf->hash_size_sum + mf->sons_count; + hash = mf->hash; - for (uint32_t i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) { // If the distance is greater than the dictionary size, // we can simply mark the hash element as empty. // @@ -196,15 +204,14 @@ move_pending(lzma_mf *mf) move_pending(mf); \ ret_op; \ } \ - const uint8_t *cur = mf_ptr(mf); \ - const uint32_t pos = mf->read_pos + mf->offset + cur = mf_ptr(mf); \ + pos = mf->read_pos + mf->offset /// Header for find functions. "return 0" indicates that zero matches /// were found. #define header_find(is_bt, len_min) \ - header(is_bt, len_min, return 0); \ - uint32_t matches_count = 0 + header(is_bt, len_min, return 0) /// Header for a loop in a skip function. "continue" tells to skip the rest @@ -261,10 +268,11 @@ hc_find_func( while (true) { const uint32_t delta = pos - cur_match; + const uint8_t *pb; if (depth-- == 0 || delta >= cyclic_size) return matches; - const uint8_t *const pb = cur - delta; + pb = cur - delta; cur_match = son[cyclic_pos - delta + (delta > cyclic_pos ? cyclic_size : 0)]; @@ -305,18 +313,23 @@ do { \ extern uint32_t lzma_mf_hc3_find(lzma_mf *mf, lzma_match *matches) { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */ + uint32_t delta2, cur_match; + uint32_t len_best = 2; + uint32_t matches_count = 0; + header_find(false, 3); hash_3_calc(); - const uint32_t delta2 = pos - mf->hash[hash_2_value]; - const uint32_t cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; + delta2 = pos - mf->hash[hash_2_value]; + cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_value] = pos; - uint32_t len_best = 2; - if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { for ( ; len_best != len_limit; ++len_best) if (*(cur + len_best - delta2) != cur[len_best]) @@ -340,18 +353,22 @@ extern void lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount) { do { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */ + uint32_t cur_match; + if (mf_avail(mf) < 3) { move_pending(mf); continue; } - const uint8_t *cur = mf_ptr(mf); - const uint32_t pos = mf->read_pos + mf->offset; + cur = mf_ptr(mf); + pos = mf->read_pos + mf->offset; hash_3_calc(); - const uint32_t cur_match - = mf->hash[FIX_3_HASH_SIZE + hash_value]; + cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_value] = pos; @@ -367,21 +384,25 @@ lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount) extern uint32_t lzma_mf_hc4_find(lzma_mf *mf, lzma_match *matches) { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */ + uint32_t delta2, delta3, cur_match; + uint32_t len_best = 1; + uint32_t matches_count = 0; + header_find(false, 4); hash_4_calc(); - uint32_t delta2 = pos - mf->hash[hash_2_value]; - const uint32_t delta3 - = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value]; - const uint32_t cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; + delta2 = pos - mf->hash[hash_2_value]; + delta3 = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value]; + cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; mf->hash[hash_2_value ] = pos; mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos; mf->hash[FIX_4_HASH_SIZE + hash_value] = pos; - uint32_t len_best = 1; - if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { len_best = 2; matches[0].len = 2; @@ -420,18 +441,22 @@ extern void lzma_mf_hc4_skip(lzma_mf *mf, uint32_t amount) { do { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */ + uint32_t cur_match; + if (mf_avail(mf) < 4) { move_pending(mf); continue; } - const uint8_t *cur = mf_ptr(mf); - const uint32_t pos = mf->read_pos + mf->offset; + cur = mf_ptr(mf); + pos = mf->read_pos + mf->offset; hash_4_calc(); - const uint32_t cur_match - = mf->hash[FIX_4_HASH_SIZE + hash_value]; + cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos; @@ -469,6 +494,10 @@ bt_find_func( uint32_t len1 = 0; while (true) { + uint32_t *pair; + const uint8_t *pb; + uint32_t len; + const uint32_t delta = pos - cur_match; if (depth-- == 0 || delta >= cyclic_size) { *ptr0 = EMPTY_HASH_VALUE; @@ -476,12 +505,12 @@ bt_find_func( return matches; } - uint32_t *const pair = son + ((cyclic_pos - delta + pair = son + ((cyclic_pos - delta + (delta > cyclic_pos ? cyclic_size : 0)) << 1); - const uint8_t *const pb = cur - delta; - uint32_t len = my_min(len0, len1); + pb = cur - delta; + len = my_min(len0, len1); if (pb[len] == cur[len]) { while (++len != len_limit) @@ -535,6 +564,10 @@ bt_skip_func( uint32_t len1 = 0; while (true) { + uint32_t *pair; + const uint8_t *pb; + uint32_t len; + const uint32_t delta = pos - cur_match; if (depth-- == 0 || delta >= cyclic_size) { *ptr0 = EMPTY_HASH_VALUE; @@ -542,11 +575,11 @@ bt_skip_func( return; } - uint32_t *pair = son + ((cyclic_pos - delta + pair = son + ((cyclic_pos - delta + (delta > cyclic_pos ? cyclic_size : 0)) << 1); - const uint8_t *pb = cur - delta; - uint32_t len = my_min(len0, len1); + pb = cur - delta; + len = my_min(len0, len1); if (pb[len] == cur[len]) { while (++len != len_limit) @@ -593,11 +626,17 @@ do { \ extern uint32_t lzma_mf_bt2_find(lzma_mf *mf, lzma_match *matches) { + const uint8_t *cur; + uint32_t pos; + uint32_t hash_value; /* hash_2_calc */ + uint32_t cur_match; + uint32_t matches_count = 0; + header_find(true, 2); hash_2_calc(); - const uint32_t cur_match = mf->hash[hash_value]; + cur_match = mf->hash[hash_value]; mf->hash[hash_value] = pos; bt_find(1); @@ -608,11 +647,16 @@ extern void lzma_mf_bt2_skip(lzma_mf *mf, uint32_t amount) { do { + const uint8_t *cur; + uint32_t pos; + uint32_t hash_value; /* hash_2_calc */ + uint32_t cur_match; + header_skip(true, 2); hash_2_calc(); - const uint32_t cur_match = mf->hash[hash_value]; + cur_match = mf->hash[hash_value]; mf->hash[hash_value] = pos; bt_skip(); @@ -626,18 +670,23 @@ lzma_mf_bt2_skip(lzma_mf *mf, uint32_t amount) extern uint32_t lzma_mf_bt3_find(lzma_mf *mf, lzma_match *matches) { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */ + uint32_t delta2, cur_match; + uint32_t len_best = 2; + uint32_t matches_count = 0; + header_find(true, 3); hash_3_calc(); - const uint32_t delta2 = pos - mf->hash[hash_2_value]; - const uint32_t cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; + delta2 = pos - mf->hash[hash_2_value]; + cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_value] = pos; - uint32_t len_best = 2; - if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { for ( ; len_best != len_limit; ++len_best) if (*(cur + len_best - delta2) != cur[len_best]) @@ -661,12 +710,16 @@ extern void lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount) { do { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value; /* hash_3_calc */ + uint32_t cur_match; + header_skip(true, 3); hash_3_calc(); - const uint32_t cur_match - = mf->hash[FIX_3_HASH_SIZE + hash_value]; + cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_value] = pos; @@ -682,21 +735,25 @@ lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount) extern uint32_t lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches) { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */ + uint32_t delta2, delta3, cur_match; + uint32_t len_best = 1; + uint32_t matches_count = 0; + header_find(true, 4); hash_4_calc(); - uint32_t delta2 = pos - mf->hash[hash_2_value]; - const uint32_t delta3 - = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value]; - const uint32_t cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; + delta2 = pos - mf->hash[hash_2_value]; + delta3 = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value]; + cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos; mf->hash[FIX_4_HASH_SIZE + hash_value] = pos; - uint32_t len_best = 1; - if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { len_best = 2; matches[0].len = 2; @@ -735,12 +792,16 @@ extern void lzma_mf_bt4_skip(lzma_mf *mf, uint32_t amount) { do { + const uint8_t *cur; + uint32_t pos; + uint32_t temp, hash_value, hash_2_value, hash_3_value; /* hash_4_calc */ + uint32_t cur_match; + header_skip(true, 4); hash_4_calc(); - const uint32_t cur_match - = mf->hash[FIX_4_HASH_SIZE + hash_value]; + cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos; |