diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-09-27 19:09:21 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-09-27 19:09:21 +0300 |
commit | 1dcecfb09b55157b8653d747963069c8bed74f04 (patch) | |
tree | 81fa1f1e8bf6871981970ca826d897db6f33527b /src/liblzma/lz | |
parent | Added 7z2lzma.bash. (diff) | |
download | xz-1dcecfb09b55157b8653d747963069c8bed74f04.tar.xz |
Some API changes, bug fixes, cleanups etc.
Diffstat (limited to '')
-rw-r--r-- | src/liblzma/lz/lz_encoder.c | 30 | ||||
-rw-r--r-- | src/liblzma/lz/lz_encoder.h | 26 | ||||
-rw-r--r-- | src/liblzma/lz/lz_encoder_mf.c | 30 | ||||
-rw-r--r-- | src/liblzma/lzma/Makefile.am | 4 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma2_decoder.c | 10 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma2_encoder.c | 27 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_common.h | 26 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_decoder.c | 37 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_encoder.c | 51 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_encoder_optimum_fast.c | 10 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_encoder_optimum_normal.c | 20 | ||||
-rw-r--r-- | src/liblzma/lzma/lzma_encoder_presets.c | 50 |
12 files changed, 154 insertions, 167 deletions
diff --git a/src/liblzma/lz/lz_encoder.c b/src/liblzma/lz/lz_encoder.c index 159080ee..d598f71a 100644 --- a/src/liblzma/lz/lz_encoder.c +++ b/src/liblzma/lz/lz_encoder.c @@ -189,15 +189,13 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, // For now, the dictionary size is limited to 1.5 GiB. This may grow // in the future if needed, but it needs a little more work than just // changing this check. - if (lz_options->dictionary_size < LZMA_DICTIONARY_SIZE_MIN - || lz_options->dictionary_size + if (lz_options->dict_size < LZMA_DICT_SIZE_MIN + || lz_options->dict_size > (UINT32_C(1) << 30) + (UINT32_C(1) << 29) - || lz_options->find_len_max - > lz_options->match_len_max) + || lz_options->nice_len > lz_options->match_len_max) return true; - mf->keep_size_before = lz_options->before_size - + lz_options->dictionary_size; + mf->keep_size_before = lz_options->before_size + lz_options->dict_size; mf->keep_size_after = lz_options->after_size + lz_options->match_len_max; @@ -213,7 +211,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, // to size_t. // - Memory usage calculation needs something too, e.g. use uint64_t // for mf->size. - uint32_t reserve = lz_options->dictionary_size / 2; + uint32_t reserve = lz_options->dict_size / 2; if (reserve > (UINT32_C(1) << 30)) reserve /= 2; @@ -232,7 +230,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, // Match finder options mf->match_len_max = lz_options->match_len_max; - mf->find_len_max = lz_options->find_len_max; + mf->nice_len = lz_options->nice_len; // cyclic_size has to stay smaller than 2 Gi. Note that this doesn't // mean limitting dictionary size to less than 2 GiB. With a match @@ -249,7 +247,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, // memory to keep the code simpler. The current way is simple and // still allows pretty big dictionaries, so I don't expect these // limits to change. - mf->cyclic_size = lz_options->dictionary_size + 1; + mf->cyclic_size = lz_options->dict_size + 1; // Validate the match finder ID and setup the function pointers. switch (lz_options->match_finder) { @@ -289,9 +287,9 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, } // Calculate the sizes of mf->hash and mf->son and check that - // find_len_max is big enough for the selected match finder. + // nice_len is big enough for the selected match finder. const uint32_t hash_bytes = lz_options->match_finder & 0x0F; - if (hash_bytes > mf->find_len_max) + if (hash_bytes > mf->nice_len) return true; const bool is_bt = (lz_options->match_finder & 0x10) != 0; @@ -302,7 +300,7 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, } else { // Round dictionary size up to the next 2^n - 1 so it can // be used as a hash mask. - hs = lz_options->dictionary_size - 1; + hs = lz_options->dict_size - 1; hs |= hs >> 1; hs |= hs >> 2; hs |= hs >> 4; @@ -353,11 +351,11 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator, } // Maximum number of match finder cycles - mf->loops = lz_options->match_finder_cycles; - if (mf->loops == 0) { - mf->loops = 16 + (mf->find_len_max / 2); + mf->depth = lz_options->depth; + if (mf->depth == 0) { + mf->depth = 16 + (mf->nice_len / 2); if (!is_bt) - mf->loops /= 2; + mf->depth /= 2; } return false; diff --git a/src/liblzma/lz/lz_encoder.h b/src/liblzma/lz/lz_encoder.h index 373cc01b..44880d77 100644 --- a/src/liblzma/lz/lz_encoder.h +++ b/src/liblzma/lz/lz_encoder.h @@ -110,13 +110,13 @@ struct lzma_mf_s { uint32_t hash_mask; /// Maximum number of loops in the match finder - uint32_t loops; + uint32_t depth; /// Maximum length of a match that the match finder will try to find. - uint32_t find_len_max; + uint32_t nice_len; /// Maximum length of a match supported by the LZ-based encoder. - /// If the longest match found by the match finder is find_len_max, + /// If the longest match found by the match finder is nice_len, /// mf_find() tries to expand it up to match_len_max bytes. uint32_t match_len_max; @@ -139,40 +139,40 @@ typedef struct { size_t before_size; /// Size of the history buffer - size_t dictionary_size; + size_t dict_size; /// Extra amount of data to keep available after the "actual" /// dictionary. size_t after_size; /// Maximum length of a match that the LZ-based encoder can accept. - /// This is used to extend matches of length find_len_max to the + /// This is used to extend matches of length nice_len to the /// maximum possible length. size_t match_len_max; /// Match finder will search matches of at maximum of this length. /// This must be less than or equal to match_len_max. - size_t find_len_max; + size_t nice_len; /// Type of the match finder to use lzma_match_finder match_finder; - /// TODO: Comment - uint32_t match_finder_cycles; + /// Maximum search depth + uint32_t depth; /// TODO: Comment - const uint8_t *preset_dictionary; + const uint8_t *preset_dict; - uint32_t preset_dictionary_size; + uint32_t preset_dict_size; } lzma_lz_options; // The total usable buffer space at any moment outside the match finder: -// before_size + dictionary_size + after_size + match_len_max +// before_size + dict_size + after_size + match_len_max // // In reality, there's some extra space allocated to prevent the number of -// memmove() calls reasonable. The bigger the dictionary_size is, the bigger +// memmove() calls reasonable. The bigger the dict_size is, the bigger // this extra buffer will be since with bigger dictionaries memmove() would // also take longer. // @@ -181,7 +181,7 @@ typedef struct { // In other words, a single encoder loop may advance lzma_mf.read_pos at // maximum of after_size times. Since matches are looked up to // lzma_mf.buffer[lzma_mf.read_pos + match_len_max - 1], the total -// amount of extra buffer needed after dictionary_size becomes +// amount of extra buffer needed after dict_size becomes // after_size + match_len_max. // // before_size has two uses. The first one is to keep literals available diff --git a/src/liblzma/lz/lz_encoder_mf.c b/src/liblzma/lz/lz_encoder_mf.c index d82681b3..9d50e91d 100644 --- a/src/liblzma/lz/lz_encoder_mf.c +++ b/src/liblzma/lz/lz_encoder_mf.c @@ -42,7 +42,7 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) #ifndef NDEBUG // Validate the matches. for (uint32_t i = 0; i < count; ++i) { - assert(matches[i].len <= mf->find_len_max); + assert(matches[i].len <= mf->nice_len); assert(matches[i].dist < mf->read_pos); assert(memcmp(mf_ptr(mf) - 1, mf_ptr(mf) - matches[i].dist - 2, @@ -56,7 +56,7 @@ 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->find_len_max) { + if (len_best == mf->nice_len) { // 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 @@ -90,7 +90,7 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) /// Hash value to indicate unused element in the hash. Since we start the -/// positions from dictionary_size + 1, zero is always too far to qualify +/// positions from dict_size + 1, zero is always too far to qualify /// as usable match position. #define EMPTY_HASH_VALUE 0 @@ -166,7 +166,7 @@ move_pos(lzma_mf *mf) } -/// When flushing, we cannot run the match finder unless there is find_len_max +/// When flushing, we cannot run the match finder unless there is nice_len /// bytes available in the dictionary. Instead, we skip running the match /// finder (indicating that no match was found), and count how many bytes we /// have ignored this way. @@ -196,8 +196,8 @@ move_pending(lzma_mf *mf) /// in them. #define header(is_bt, len_min, ret_op) \ uint32_t len_limit = mf_avail(mf); \ - if (mf->find_len_max <= len_limit) { \ - len_limit = mf->find_len_max; \ + if (mf->nice_len <= len_limit) { \ + len_limit = mf->nice_len; \ } else if (len_limit < (len_min) \ || (is_bt && mf->action == LZMA_SYNC_FLUSH)) { \ assert(mf->action != LZMA_RUN); \ @@ -226,7 +226,7 @@ move_pending(lzma_mf *mf) /// of matches found. #define call_find(func, len_best) \ do { \ - matches_count = func(len_limit, pos, cur, cur_match, mf->loops, \ + matches_count = func(len_limit, pos, cur, cur_match, mf->depth, \ mf->son, mf->cyclic_pos, mf->cyclic_size, \ matches + matches_count, len_best) \ - matches; \ @@ -246,7 +246,7 @@ do { \ /// \param pos lzma_mf.read_pos + lzma_mf.offset /// \param cur Pointer to current byte (mf_ptr(mf)) /// \param cur_match Start position of the current match candidate -/// \param loops Maximum length of the hash chain +/// \param depth Maximum length of the hash chain /// \param son lzma_mf.son (contains the hash chain) /// \param cyclic_pos /// \param cyclic_size @@ -258,7 +258,7 @@ hc_find_func( const uint32_t pos, const uint8_t *const cur, uint32_t cur_match, - uint32_t loops, + uint32_t depth, uint32_t *const son, const uint32_t cyclic_pos, const uint32_t cyclic_size, @@ -269,7 +269,7 @@ hc_find_func( while (true) { const uint32_t delta = pos - cur_match; - if (loops-- == 0 || delta >= cyclic_size) + if (depth-- == 0 || delta >= cyclic_size) return matches; const uint8_t *const pb = cur - delta; @@ -463,7 +463,7 @@ bt_find_func( const uint32_t pos, const uint8_t *const cur, uint32_t cur_match, - uint32_t loops, + uint32_t depth, uint32_t *const son, const uint32_t cyclic_pos, const uint32_t cyclic_size, @@ -478,7 +478,7 @@ bt_find_func( while (true) { const uint32_t delta = pos - cur_match; - if (loops-- == 0 || delta >= cyclic_size) { + if (depth-- == 0 || delta >= cyclic_size) { *ptr0 = EMPTY_HASH_VALUE; *ptr1 = EMPTY_HASH_VALUE; return matches; @@ -531,7 +531,7 @@ bt_skip_func( const uint32_t pos, const uint8_t *const cur, uint32_t cur_match, - uint32_t loops, + uint32_t depth, uint32_t *const son, const uint32_t cyclic_pos, const uint32_t cyclic_size) @@ -544,7 +544,7 @@ bt_skip_func( while (true) { const uint32_t delta = pos - cur_match; - if (loops-- == 0 || delta >= cyclic_size) { + if (depth-- == 0 || delta >= cyclic_size) { *ptr0 = EMPTY_HASH_VALUE; *ptr1 = EMPTY_HASH_VALUE; return; @@ -588,7 +588,7 @@ bt_skip_func( #define bt_skip() \ do { \ - bt_skip_func(len_limit, pos, cur, cur_match, mf->loops, \ + bt_skip_func(len_limit, pos, cur, cur_match, mf->depth, \ mf->son, mf->cyclic_pos, \ mf->cyclic_size); \ move_pos(mf); \ diff --git a/src/liblzma/lzma/Makefile.am b/src/liblzma/lzma/Makefile.am index bcc1fdc6..ec6b7b27 100644 --- a/src/liblzma/lzma/Makefile.am +++ b/src/liblzma/lzma/Makefile.am @@ -24,7 +24,7 @@ liblzma2_la_CPPFLAGS = \ liblzma2_la_SOURCES = lzma_common.h -if COND_ENCODER_LZMA +if COND_ENCODER_LZMA1 liblzma2_la_SOURCES += \ fastpos.h \ lzma_encoder.h \ @@ -39,7 +39,7 @@ liblzma2_la_SOURCES += fastpos_table.c endif endif -if COND_DECODER_LZMA +if COND_DECODER_LZMA1 liblzma2_la_SOURCES += \ lzma_decoder.c \ lzma_decoder.h diff --git a/src/liblzma/lzma/lzma2_decoder.c b/src/liblzma/lzma/lzma2_decoder.c index 88e73fb6..af1da746 100644 --- a/src/liblzma/lzma/lzma2_decoder.c +++ b/src/liblzma/lzma/lzma2_decoder.c @@ -303,14 +303,14 @@ lzma_lzma2_props_decode(void **options, lzma_allocator *allocator, return LZMA_MEM_ERROR; if (props[0] == 40) { - opt->dictionary_size = UINT32_MAX; + opt->dict_size = UINT32_MAX; } else { - opt->dictionary_size = 2 | (props[0] & 1); - opt->dictionary_size <<= props[0] / 2 + 11; + opt->dict_size = 2 | (props[0] & 1); + opt->dict_size <<= props[0] / 2 + 11; } - opt->preset_dictionary = NULL; - opt->preset_dictionary_size = 0; + opt->preset_dict = NULL; + opt->preset_dict_size = 0; *options = opt; diff --git a/src/liblzma/lzma/lzma2_encoder.c b/src/liblzma/lzma/lzma2_encoder.c index b2cd176b..757b871d 100644 --- a/src/liblzma/lzma/lzma2_encoder.c +++ b/src/liblzma/lzma/lzma2_encoder.c @@ -178,19 +178,13 @@ lzma2_encode(lzma_coder *restrict coder, lzma_mf *restrict mf, // Look if there are new options. At least for now, // only lc/lp/pb can be changed. if (coder->opt_new != NULL - && (coder->opt_cur.literal_context_bits - != coder->opt_new->literal_context_bits - || coder->opt_cur.literal_pos_bits - != coder->opt_new->literal_pos_bits - || coder->opt_cur.pos_bits - != coder->opt_new->pos_bits)) { + && (coder->opt_cur.lc != coder->opt_new->lc + || coder->opt_cur.lp != coder->opt_new->lp + || coder->opt_cur.pb != coder->opt_new->pb)) { // Options have been changed, copy them to opt_cur. - coder->opt_cur.literal_context_bits - = coder->opt_new->literal_context_bits; - coder->opt_cur.literal_pos_bits - = coder->opt_new->literal_pos_bits; - coder->opt_cur.pos_bits - = coder->opt_new->pos_bits; + coder->opt_cur.lc = coder->opt_new->lc; + coder->opt_cur.lp = coder->opt_new->lp; + coder->opt_cur.pb = coder->opt_new->pb; // We need to write the new options and reset // the encoder state. @@ -352,10 +346,9 @@ lzma2_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator, // compressed size of a chunk is not smaller than the uncompressed // size, so we need to have at least LZMA2_COMPRESSED_MAX bytes // history available. - if (lz_options->before_size + lz_options->dictionary_size - < LZMA2_CHUNK_MAX) - lz_options->before_size = LZMA2_CHUNK_MAX - - lz_options->dictionary_size; + if (lz_options->before_size + lz_options->dict_size < LZMA2_CHUNK_MAX) + lz_options->before_size + = LZMA2_CHUNK_MAX - lz_options->dict_size; return LZMA_OK; } @@ -385,7 +378,7 @@ extern lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out) { const lzma_options_lzma *const opt = options; - uint32_t d = MAX(opt->dictionary_size, LZMA_DICTIONARY_SIZE_MIN); + uint32_t d = MAX(opt->dict_size, LZMA_DICT_SIZE_MIN); // Round up to to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending // on which one is the next: diff --git a/src/liblzma/lzma/lzma_common.h b/src/liblzma/lzma/lzma_common.h index 6909969b..546bf89e 100644 --- a/src/liblzma/lzma/lzma_common.h +++ b/src/liblzma/lzma/lzma_common.h @@ -32,20 +32,16 @@ /// Maximum number of position states. A position state is the lowest pos bits /// number of bits of the current uncompressed offset. In some places there /// are different sets of probabilities for different pos states. -#define POS_STATES_MAX (1 << LZMA_POS_BITS_MAX) +#define POS_STATES_MAX (1 << LZMA_PB_MAX) -/// Validates literal_context_bits, literal_pos_bits, and pos_bits. +/// Validates lc, lp, and pb. static inline bool is_lclppb_valid(const lzma_options_lzma *options) { - return options->literal_context_bits <= LZMA_LITERAL_CONTEXT_BITS_MAX - && options->literal_pos_bits - <= LZMA_LITERAL_POS_BITS_MAX - && options->literal_context_bits - + options->literal_pos_bits - <= LZMA_LITERAL_BITS_MAX - && options->pos_bits <= LZMA_POS_BITS_MAX; + return options->lc <= LZMA_LCLP_MAX && options->lp <= LZMA_LCLP_MAX + && options->lc + options->lp <= LZMA_LCLP_MAX + && options->pb <= LZMA_PB_MAX; } @@ -126,7 +122,7 @@ typedef enum { #define LITERAL_CODER_SIZE 0x300 /// Maximum number of literal coders -#define LITERAL_CODERS_MAX (1 << LZMA_LITERAL_BITS_MAX) +#define LITERAL_CODERS_MAX (1 << LZMA_LCLP_MAX) /// Locate the literal coder for the next literal byte. The choice depends on /// - the lowest literal_pos_bits bits of the position of the current @@ -138,13 +134,11 @@ typedef enum { static inline void literal_init(probability (*probs)[LITERAL_CODER_SIZE], - uint32_t literal_context_bits, uint32_t literal_pos_bits) + uint32_t lc, uint32_t lp) { - assert(literal_context_bits + literal_pos_bits - <= LZMA_LITERAL_BITS_MAX); + assert(lc + lp <= LZMA_LCLP_MAX); - const uint32_t coders - = 1U << (literal_context_bits + literal_pos_bits); + const uint32_t coders = 1U << (lc + lp); for (uint32_t i = 0; i < coders; ++i) for (uint32_t j = 0; j < LITERAL_CODER_SIZE; ++j) @@ -219,7 +213,7 @@ literal_init(probability (*probs)[LITERAL_CODER_SIZE], // fastpos.h to understand why). #define END_POS_MODEL_INDEX 14 -// Seven-bit distances use the full FIXME +// Pos slots that indicate a distance <= 127. #define FULL_DISTANCES_BITS (END_POS_MODEL_INDEX / 2) #define FULL_DISTANCES (1 << FULL_DISTANCES_BITS) diff --git a/src/liblzma/lzma/lzma_decoder.c b/src/liblzma/lzma/lzma_decoder.c index 0fa62c66..df3371e2 100644 --- a/src/liblzma/lzma/lzma_decoder.c +++ b/src/liblzma/lzma/lzma_decoder.c @@ -231,7 +231,7 @@ struct lzma_coder_s { uint32_t rep2; ///< Distance of third latest match uint32_t rep3; ///< Distance of fourth latest match - uint32_t pos_mask; // (1U << pos_bits) - 1 + uint32_t pos_mask; // (1U << pb) - 1 uint32_t literal_context_bits; uint32_t literal_pos_mask; @@ -866,14 +866,13 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt) // FIXME? // Calculate pos_mask. We don't need pos_bits as is for anything. - coder->pos_mask = (1U << options->pos_bits) - 1; + coder->pos_mask = (1U << options->pb) - 1; // Initialize the literal decoder. - literal_init(coder->literal, options->literal_context_bits, - options->literal_pos_bits); + literal_init(coder->literal, options->lc, options->lp); - coder->literal_context_bits = options->literal_context_bits; - coder->literal_pos_mask = (1 << options->literal_pos_bits) - 1; + coder->literal_context_bits = options->lc; + coder->literal_pos_mask = (1U << options->lp) - 1; // State coder->state = STATE_LIT_LIT; @@ -881,7 +880,7 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt) coder->rep1 = 0; coder->rep2 = 0; coder->rep3 = 0; - coder->pos_mask = (1 << options->pos_bits) - 1; + coder->pos_mask = (1U << options->pb) - 1; // Range decoder rc_reset(coder->rc); @@ -908,7 +907,7 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt) bittree_reset(coder->pos_align, ALIGN_BITS); // Len decoders (also bit/bittree) - const uint32_t num_pos_states = 1 << options->pos_bits; + const uint32_t 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); @@ -957,7 +956,7 @@ 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; - *dict_size = options->dictionary_size; + *dict_size = options->dict_size; return LZMA_OK; } @@ -1003,13 +1002,12 @@ lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte) return true; // See the file format specification to understand this. - options->pos_bits = byte / (9 * 5); - byte -= options->pos_bits * 9 * 5; - options->literal_pos_bits = byte / 9; - options->literal_context_bits = byte - options->literal_pos_bits * 9; + options->pb = byte / (9 * 5); + byte -= options->pb * 9 * 5; + options->lp = byte / 9; + options->lc = byte - options->lp * 9; - return options->literal_context_bits + options->literal_pos_bits - > LZMA_LITERAL_BITS_MAX; + return options->lc + options->lp > LZMA_LCLP_MAX; } @@ -1017,8 +1015,7 @@ extern uint64_t lzma_lzma_decoder_memusage(const void *options) { const lzma_options_lzma *const opt = options; - const uint64_t lz_memusage - = lzma_lz_decoder_memusage(opt->dictionary_size); + const uint64_t lz_memusage = lzma_lz_decoder_memusage(opt->dict_size); if (lz_memusage == UINT64_MAX) return UINT64_MAX; @@ -1044,10 +1041,10 @@ lzma_lzma_props_decode(void **options, lzma_allocator *allocator, // All dictionary sizes are accepted, including zero. LZ decoder // will automatically use a dictionary at least a few KiB even if // a smaller dictionary is requested. - opt->dictionary_size = integer_read_32(props + 1); + opt->dict_size = integer_read_32(props + 1); - opt->preset_dictionary = NULL; - opt->preset_dictionary_size = 0; + opt->preset_dict = NULL; + opt->preset_dict_size = 0; *options = opt; diff --git a/src/liblzma/lzma/lzma_encoder.c b/src/liblzma/lzma/lzma_encoder.c index 02b7d19a..2f81bedc 100644 --- a/src/liblzma/lzma/lzma_encoder.c +++ b/src/liblzma/lzma/lzma_encoder.c @@ -428,14 +428,14 @@ set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options) // LZ encoder initialization does the validation, also when just // calculating memory usage, so we don't need to validate here. lz_options->before_size = OPTS; - lz_options->dictionary_size = options->dictionary_size; + lz_options->dict_size = options->dict_size; lz_options->after_size = LOOP_INPUT_MAX; lz_options->match_len_max = MATCH_LEN_MAX; - lz_options->find_len_max = options->fast_bytes; - lz_options->match_finder = options->match_finder; - lz_options->match_finder_cycles = options->match_finder_cycles; - lz_options->preset_dictionary = options->preset_dictionary; - lz_options->preset_dictionary_size = options->preset_dictionary_size; + lz_options->nice_len = options->nice_len; + lz_options->match_finder = options->mf; + lz_options->depth = options->depth; + lz_options->preset_dict = options->preset_dict; + lz_options->preset_dict_size = options->preset_dict_size; } @@ -467,9 +467,9 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options) { assert(!coder->is_flushed); - coder->pos_mask = (1U << options->pos_bits) - 1; - coder->literal_context_bits = options->literal_context_bits; - coder->literal_pos_mask = (1U << options->literal_pos_bits) - 1; + coder->pos_mask = (1U << options->pb) - 1; + coder->literal_context_bits = options->lc; + coder->literal_pos_mask = (1U << options->lp) - 1; // Range coder rc_reset(&coder->rc); @@ -479,8 +479,7 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options) for (size_t i = 0; i < REP_DISTANCES; ++i) coder->reps[i] = 0; - literal_init(coder->literal, options->literal_context_bits, - options->literal_pos_bits); + literal_init(coder->literal, options->lc, options->lp); // Bit encoders for (size_t i = 0; i < STATES; ++i) { @@ -506,10 +505,10 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options) // Length encoders length_encoder_reset(&coder->match_len_encoder, - 1U << options->pos_bits, coder->fast_mode); + 1U << options->pb, coder->fast_mode); length_encoder_reset(&coder->rep_len_encoder, - 1U << options->pos_bits, coder->fast_mode); + 1U << options->pb, coder->fast_mode); // Price counts are incremented every time appropriate probabilities // are changed. price counts are set to zero when the price tables @@ -546,8 +545,8 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator, // Validate some of the options. LZ encoder validates fast_bytes too // but we need a valid value here earlier. - if (!is_lclppb_valid(options) || options->fast_bytes < MATCH_LEN_MIN - || options->fast_bytes > MATCH_LEN_MAX) + if (!is_lclppb_valid(options) || options->nice_len < MATCH_LEN_MIN + || options->nice_len > MATCH_LEN_MAX) return LZMA_OPTIONS_ERROR; // Set compression mode. @@ -562,17 +561,16 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator, // Set dist_table_size. // Round the dictionary size up to next 2^n. uint32_t log_size = 0; - while ((UINT32_C(1) << log_size) - < options->dictionary_size) + while ((UINT32_C(1) << log_size) < options->dict_size) ++log_size; coder->dist_table_size = log_size * 2; // Length encoders' price table size coder->match_len_encoder.table_size - = options->fast_bytes + 1 - MATCH_LEN_MIN; + = options->nice_len + 1 - MATCH_LEN_MIN; coder->rep_len_encoder.table_size - = options->fast_bytes + 1 - MATCH_LEN_MIN; + = options->nice_len + 1 - MATCH_LEN_MIN; break; } @@ -627,24 +625,17 @@ lzma_lzma_encoder_memusage(const void *options) extern bool lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte) { - if (options->literal_context_bits > LZMA_LITERAL_CONTEXT_BITS_MAX - || options->literal_pos_bits - > LZMA_LITERAL_POS_BITS_MAX - || options->pos_bits > LZMA_POS_BITS_MAX - || options->literal_context_bits - + options->literal_pos_bits - > LZMA_LITERAL_BITS_MAX) + if (!is_lclppb_valid(options)) return true; - *byte = (options->pos_bits * 5 + options->literal_pos_bits) * 9 - + options->literal_context_bits; + *byte = (options->pb * 5 + options->lp) * 9 + options->lc; assert(*byte <= (4 * 5 + 4) * 9 + 8); return false; } -#ifdef HAVE_ENCODER_LZMA +#ifdef HAVE_ENCODER_LZMA1 extern lzma_ret lzma_lzma_props_encode(const void *options, uint8_t *out) { @@ -653,7 +644,7 @@ lzma_lzma_props_encode(const void *options, uint8_t *out) if (lzma_lzma_lclppb_encode(opt, out)) return LZMA_PROG_ERROR; - integer_write_32(out + 1, opt->dictionary_size); + integer_write_32(out + 1, opt->dict_size); return LZMA_OK; } diff --git a/src/liblzma/lzma/lzma_encoder_optimum_fast.c b/src/liblzma/lzma/lzma_encoder_optimum_fast.c index 9da7e79e..4e8e26a2 100644 --- a/src/liblzma/lzma/lzma_encoder_optimum_fast.c +++ b/src/liblzma/lzma/lzma_encoder_optimum_fast.c @@ -38,7 +38,7 @@ extern void lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf, uint32_t *restrict back_res, uint32_t *restrict len_res) { - const uint32_t fast_bytes = mf->find_len_max; + const uint32_t nice_len = mf->nice_len; uint32_t len_main; uint32_t matches_count; @@ -79,8 +79,8 @@ lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf, && buf[len] == buf_back[len]; ++len) ; // If we have found a repeated match that is at least - // fast_bytes long, return it immediatelly. - if (len >= fast_bytes) { + // nice_len long, return it immediatelly. + if (len >= nice_len) { *back_res = i; *len_res = len; mf_skip(mf, len - 1); @@ -94,8 +94,8 @@ lzma_lzma_optimum_fast(lzma_coder *restrict coder, lzma_mf *restrict mf, } // We didn't find a long enough repeated match. Encode it as a normal - // match if the match length is at least fast_bytes. - if (len_main >= fast_bytes) { + // match if the match length is at least nice_len. + if (len_main >= nice_len) { *back_res = coder->matches[matches_count - 1].dist + REP_DISTANCES; *len_res = len_main; diff --git a/src/liblzma/lzma/lzma_encoder_optimum_normal.c b/src/liblzma/lzma/lzma_encoder_optimum_normal.c index f0dd92c9..7071a433 100644 --- a/src/liblzma/lzma/lzma_encoder_optimum_normal.c +++ b/src/liblzma/lzma/lzma_encoder_optimum_normal.c @@ -281,7 +281,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf, uint32_t *restrict back_res, uint32_t *restrict len_res, uint32_t position) { - const uint32_t fast_bytes = mf->find_len_max; + const uint32_t nice_len = mf->nice_len; uint32_t len_main; uint32_t matches_count; @@ -324,7 +324,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf, rep_max_index = i; } - if (rep_lens[rep_max_index] >= fast_bytes) { + if (rep_lens[rep_max_index] >= nice_len) { *back_res = rep_max_index; *len_res = rep_lens[rep_max_index]; mf_skip(mf, *len_res - 1); @@ -332,7 +332,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf, } - if (len_main >= fast_bytes) { + if (len_main >= nice_len) { *back_res = coder->matches[matches_count - 1].dist + REP_DISTANCES; *len_res = len_main; @@ -457,7 +457,7 @@ helper1(lzma_coder *restrict coder, lzma_mf *restrict mf, static inline uint32_t helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf, uint32_t len_end, uint32_t position, const uint32_t cur, - const uint32_t fast_bytes, const uint32_t buf_avail_full) + const uint32_t nice_len, const uint32_t buf_avail_full) { uint32_t matches_count = coder->matches_count; uint32_t new_len = coder->longest_match_length; @@ -572,12 +572,12 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf, if (buf_avail_full < 2) return len_end; - const uint32_t buf_avail = MIN(buf_avail_full, fast_bytes); + const uint32_t buf_avail = MIN(buf_avail_full, nice_len); if (!next_is_literal && match_byte != current_byte) { // speed optimization // try literal + rep0 const uint8_t *const buf_back = buf - reps[0] - 1; - const uint32_t limit = MIN(buf_avail_full, fast_bytes + 1); + const uint32_t limit = MIN(buf_avail_full, nice_len + 1); uint32_t len_test = 1; while (len_test < limit && buf[len_test] == buf_back[len_test]) @@ -656,7 +656,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf, uint32_t len_test_2 = len_test + 1; const uint32_t limit = MIN(buf_avail_full, - len_test_2 + fast_bytes); + len_test_2 + nice_len); for (; len_test_2 < limit && buf[len_test_2] == buf_back[len_test_2]; ++len_test_2) ; @@ -751,7 +751,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf, const uint8_t *const buf_back = buf - cur_back - 1; uint32_t len_test_2 = len_test + 1; const uint32_t limit = MIN(buf_avail_full, - len_test_2 + fast_bytes); + len_test_2 + nice_len); for (; len_test_2 < limit && buf[len_test_2] == buf_back[len_test_2]; @@ -862,11 +862,11 @@ lzma_lzma_optimum_normal(lzma_coder *restrict coder, lzma_mf *restrict mf, coder->longest_match_length = mf_find( mf, &coder->matches_count, coder->matches); - if (coder->longest_match_length >= mf->find_len_max) + if (coder->longest_match_length >= mf->nice_len) break; len_end = helper2(coder, reps, mf_ptr(mf) - 1, len_end, - position + cur, cur, mf->find_len_max, + position + cur, cur, mf->nice_len, MIN(mf_avail(mf) + 1, OPTS - 1 - cur)); } diff --git a/src/liblzma/lzma/lzma_encoder_presets.c b/src/liblzma/lzma/lzma_encoder_presets.c index 08f339e9..7ef3509e 100644 --- a/src/liblzma/lzma/lzma_encoder_presets.c +++ b/src/liblzma/lzma/lzma_encoder_presets.c @@ -20,10 +20,11 @@ #include "common.h" +/* #define pow2(e) (UINT32_C(1) << (e)) -LZMA_API const lzma_options_lzma lzma_preset_lzma[9] = { +static const lzma_options_lzma presets[9] = { // dict lc lp pb mode fb mf mfc { pow2(16), NULL, 0, 3, 0, 2, false, LZMA_MODE_FAST, 64, LZMA_MF_HC3, 0, 0, 0, 0, 0, NULL, NULL }, { pow2(20), NULL, 0, 3, 0, 0, false, LZMA_MODE_FAST, 64, LZMA_MF_HC4, 0, 0, 0, 0, 0, NULL, NULL }, @@ -37,30 +38,43 @@ LZMA_API const lzma_options_lzma lzma_preset_lzma[9] = { }; -/* extern LZMA_API lzma_bool -lzma_preset_lzma(lzma_options_lzma *options, uint32_t level) +lzma_lzma_preset(lzma_options_lzma *options, uint32_t level) { - *options = (lzma_options_lzma){ + if (level >= ARRAY_SIZE(presetes)) + return true; - }; + *options = presets[level]; + return false; +} +*/ - options->literal_context_bits = LZMA_LITERAL_CONTEXT_BITS_DEFAULT - options->literal_pos_bits = LZMA_LITERAL_POS_BITS_DEFAULT; - options->pos_bits = LZMA_POS_BITS_DEFAULT; - options->preset_dictionary = NULL; - options->preset_dictionary_size = 0; - options->persistent = false; - options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL; - options->fast_bytes = level <= +extern LZMA_API lzma_bool +lzma_lzma_preset(lzma_options_lzma *options, uint32_t level) +{ + if (level >= 9) + return true; + + memzero(options, sizeof(*options)); - options->match_finder = level == 1 ? LZMA_MF_HC3 - : (level == 2 ? LZMA_MF_HC4 : LZMA_MF_BT4); - options->match_finder_cycles = 0; + static const uint8_t shift[9] = { 16, 20, 19, 20, 21, 22, 23, 24, 25 }; + options->dict_size = UINT32_C(1) << shift[level]; + options->preset_dict = NULL; + options->preset_dict_size = 0; + options->lc = LZMA_LC_DEFAULT; + options->lp = LZMA_LP_DEFAULT; + options->pb = LZMA_PB_DEFAULT; - options->dictionary_size = + options->persistent = false; + options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL; + + options->nice_len = level <= 5 ? 32 : 64; + options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4 + : LZMA_MF_BT4; + options->depth = 0; + + return false; } -*/ |