Rizin
unix-like reverse engineering framework and cli tools
|
Match finders. More...
Go to the source code of this file.
Macros | |
#define | EMPTY_HASH_VALUE 0 |
#define | MUST_NORMALIZE_POS UINT32_MAX |
#define | header(is_bt, len_min, ret_op) |
#define | header_find(is_bt, len_min) |
#define | header_skip(is_bt, len_min) header(is_bt, len_min, continue) |
#define | call_find(func, len_best) |
Functions | |
uint32_t | lzma_mf_find (lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches) |
Find matches starting from the current byte. More... | |
static void | normalize (lzma_mf *mf) |
Normalizes hash values. More... | |
static void | move_pos (lzma_mf *mf) |
Mark the current byte as processed from point of view of the match finder. More... | |
static void | move_pending (lzma_mf *mf) |
Match finders.
Definition in file lz_encoder_mf.c.
#define call_find | ( | func, | |
len_best | |||
) |
Calls hc_find_func() or bt_find_func() and calculates the total number of matches found. Updates the dictionary position and returns the number of matches found.
Definition at line 221 of file lz_encoder_mf.c.
#define EMPTY_HASH_VALUE 0 |
Hash value to indicate unused element in the hash. Since we start the positions from dict_size + 1, zero is always too far to qualify as usable match position.
Definition at line 86 of file lz_encoder_mf.c.
#define header | ( | is_bt, | |
len_min, | |||
ret_op | |||
) |
Calculate len_limit and determine if there is enough input to run the actual match finder code. Sets up "cur" and "pos". This macro is used by all find functions and binary tree skip functions. Hash chain skip function doesn't need len_limit so a simpler code is used in them.
Definition at line 191 of file lz_encoder_mf.c.
#define header_find | ( | is_bt, | |
len_min | |||
) |
Header for find functions. "return 0" indicates that zero matches were found.
Definition at line 207 of file lz_encoder_mf.c.
#define header_skip | ( | is_bt, | |
len_min | |||
) | header(is_bt, len_min, continue) |
Header for a loop in a skip function. "continue" tells to skip the rest of the code in the loop.
Definition at line 214 of file lz_encoder_mf.c.
#define MUST_NORMALIZE_POS UINT32_MAX |
Normalization must be done when lzma_mf.offset + lzma_mf.read_pos reaches MUST_NORMALIZE_POS.
Definition at line 91 of file lz_encoder_mf.c.
uint32_t lzma_mf_find | ( | lzma_mf * | mf, |
uint32_t * | count_ptr, | ||
lzma_match * | matches | ||
) |
Find matches starting from the current byte.
Definition at line 23 of file lz_encoder_mf.c.
References assert(), count, lzma_match::dist, lzma_mf_s::find, i, len, lzma_match::len, limit, lzma_mf_s::match_len_max, mf_avail(), mf_ptr(), lzma_mf_s::nice_len, and lzma_mf_s::read_ahead.
|
static |
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.
When new data is given after the flushing was completed, the match finder is restarted by rewinding mf->read_pos backwards by mf->pending. Then the missed bytes are added to the hash using the match finder's skip function (with small amount of input, it may start using mf->pending again if flushing).
Due to this rewinding, we don't touch cyclic_pos or test for normalization. It will be done when the match finder's skip function catches up after a flush.
Definition at line 178 of file lz_encoder_mf.c.
References assert(), lzma_mf_s::pending, lzma_mf_s::read_pos, and lzma_mf_s::write_pos.
|
static |
Mark the current byte as processed from point of view of the match finder.
Definition at line 150 of file lz_encoder_mf.c.
References assert(), lzma_mf_s::cyclic_pos, lzma_mf_s::cyclic_size, normalize(), lzma_mf_s::offset, lzma_mf_s::read_pos, UINT32_MAX, unlikely, and lzma_mf_s::write_pos.
|
static |
Normalizes hash values.
The hash arrays store positions of match candidates. The positions are relative to an arbitrary offset that is not the same as the absolute offset in the input stream. The relative position of the current byte is lzma_mf.offset + lzma_mf.read_pos. The distances of the matches are the differences of the current read position and the position found from the hash.
To prevent integer overflows of the offsets stored in the hash arrays, we need to "normalize" the stored values now and then. During the normalization, we drop values that indicate distance greater than the dictionary size, thus making space for new values.
Definition at line 108 of file lz_encoder_mf.c.
References assert(), lzma_mf_s::cyclic_size, EMPTY_HASH_VALUE, lzma_mf_s::hash, lzma_mf_s::hash_count, i, MUST_NORMALIZE_POS, lzma_mf_s::offset, lzma_mf_s::read_pos, lzma_mf_s::son, and lzma_mf_s::sons_count.
Referenced by move_pos(), and test_mc::run_mc().