TESTING: no len3 matches

This commit is contained in:
Eric Biggers 2020-10-18 22:53:50 -07:00
parent 48e5ceb816
commit 17b11efffe
2 changed files with 5 additions and 32 deletions

View File

@ -2107,7 +2107,7 @@ deflate_compress_lazy(struct libdeflate_compressor * restrict c,
cur_len = hc_matchfinder_longest_match(&c->p.g.hc_mf, cur_len = hc_matchfinder_longest_match(&c->p.g.hc_mf,
&in_cur_base, &in_cur_base,
in_next, in_next,
DEFLATE_MIN_MATCH_LEN - 1, DEFLATE_MIN_MATCH_LEN,
max_len, max_len,
nice_len, nice_len,
c->max_search_depth, c->max_search_depth,
@ -2115,7 +2115,7 @@ deflate_compress_lazy(struct libdeflate_compressor * restrict c,
&cur_offset); &cur_offset);
in_next += 1; in_next += 1;
if (cur_len < DEFLATE_MIN_MATCH_LEN) { if (cur_len < DEFLATE_MIN_MATCH_LEN + 1) {
/* No match found. Choose a literal. */ /* No match found. Choose a literal. */
deflate_choose_literal(c, *(in_next - 1), &litrunlen); deflate_choose_literal(c, *(in_next - 1), &litrunlen);
observe_literal(&c->split_stats, *(in_next - 1)); observe_literal(&c->split_stats, *(in_next - 1));

View File

@ -117,9 +117,6 @@
struct hc_matchfinder { struct hc_matchfinder {
/* The hash table for finding length 3 matches */
mf_pos_t hash3_tab[1UL << HC_MATCHFINDER_HASH3_ORDER];
/* The hash table which contains the first nodes of the linked lists for /* The hash table which contains the first nodes of the linked lists for
* finding length 4+ matches */ * finding length 4+ matches */
mf_pos_t hash4_tab[1UL << HC_MATCHFINDER_HASH4_ORDER]; mf_pos_t hash4_tab[1UL << HC_MATCHFINDER_HASH4_ORDER];
@ -196,8 +193,8 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
{ {
u32 depth_remaining = max_search_depth; u32 depth_remaining = max_search_depth;
const u8 *best_matchptr = in_next; const u8 *best_matchptr = in_next;
mf_pos_t cur_node3, cur_node4; mf_pos_t cur_node4;
u32 hash3, hash4; u32 hash4;
u32 next_hashseq; u32 next_hashseq;
u32 seq4; u32 seq4;
const u8 *matchptr; const u8 *matchptr;
@ -219,17 +216,11 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
goto out; goto out;
/* Get the precomputed hash codes. */ /* Get the precomputed hash codes. */
hash3 = next_hashes[0];
hash4 = next_hashes[1]; hash4 = next_hashes[1];
/* From the hash buckets, get the first node of each linked list. */ /* From the hash buckets, get the first node of each linked list. */
cur_node3 = mf->hash3_tab[hash3];
cur_node4 = mf->hash4_tab[hash4]; cur_node4 = mf->hash4_tab[hash4];
/* Update for length 3 matches. This replaces the singleton node in the
* 'hash3' bucket with the node for the current sequence. */
mf->hash3_tab[hash3] = cur_pos;
/* Update for length 4 matches. This prepends the node for the current /* Update for length 4 matches. This prepends the node for the current
* sequence to the linked list in the 'hash4' bucket. */ * sequence to the linked list in the 'hash4' bucket. */
mf->hash4_tab[hash4] = cur_pos; mf->hash4_tab[hash4] = cur_pos;
@ -237,28 +228,15 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
/* Compute the next hash codes. */ /* Compute the next hash codes. */
next_hashseq = get_unaligned_le32(in_next + 1); next_hashseq = get_unaligned_le32(in_next + 1);
next_hashes[0] = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER);
next_hashes[1] = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); next_hashes[1] = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER);
prefetchw(&mf->hash3_tab[next_hashes[0]]);
prefetchw(&mf->hash4_tab[next_hashes[1]]); prefetchw(&mf->hash4_tab[next_hashes[1]]);
if (best_len < 4) { /* No match of length >= 4 found yet? */ if (best_len < 4) { /* No match of length >= 4 found yet? */
/* Check for a length 3 match if needed. */ /* Check for a length 3 match if needed. */
if (cur_node3 <= cutoff)
goto out;
seq4 = load_u32_unaligned(in_next); seq4 = load_u32_unaligned(in_next);
if (best_len < 3) {
matchptr = &in_base[cur_node3];
if (load_u24_unaligned(matchptr) == loaded_u32_to_u24(seq4)) {
best_len = 3;
best_matchptr = matchptr;
}
}
/* Check for a length 4 match. */ /* Check for a length 4 match. */
if (cur_node4 <= cutoff) if (cur_node4 <= cutoff)
@ -372,7 +350,7 @@ hc_matchfinder_skip_positions(struct hc_matchfinder * const restrict mf,
u32 * const restrict next_hashes) u32 * const restrict next_hashes)
{ {
u32 cur_pos; u32 cur_pos;
u32 hash3, hash4; u32 hash4;
u32 next_hashseq; u32 next_hashseq;
u32 remaining = count; u32 remaining = count;
@ -380,7 +358,6 @@ hc_matchfinder_skip_positions(struct hc_matchfinder * const restrict mf,
return &in_next[count]; return &in_next[count];
cur_pos = in_next - *in_base_p; cur_pos = in_next - *in_base_p;
hash3 = next_hashes[0];
hash4 = next_hashes[1]; hash4 = next_hashes[1];
do { do {
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { if (cur_pos == MATCHFINDER_WINDOW_SIZE) {
@ -388,19 +365,15 @@ hc_matchfinder_skip_positions(struct hc_matchfinder * const restrict mf,
*in_base_p += MATCHFINDER_WINDOW_SIZE; *in_base_p += MATCHFINDER_WINDOW_SIZE;
cur_pos = 0; cur_pos = 0;
} }
mf->hash3_tab[hash3] = cur_pos;
mf->next_tab[cur_pos] = mf->hash4_tab[hash4]; mf->next_tab[cur_pos] = mf->hash4_tab[hash4];
mf->hash4_tab[hash4] = cur_pos; mf->hash4_tab[hash4] = cur_pos;
next_hashseq = get_unaligned_le32(++in_next); next_hashseq = get_unaligned_le32(++in_next);
hash3 = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER);
hash4 = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); hash4 = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER);
cur_pos++; cur_pos++;
} while (--remaining); } while (--remaining);
prefetchw(&mf->hash3_tab[hash3]);
prefetchw(&mf->hash4_tab[hash4]); prefetchw(&mf->hash4_tab[hash4]);
next_hashes[0] = hash3;
next_hashes[1] = hash4; next_hashes[1] = hash4;
return in_next; return in_next;