Skip to content

Commit

Permalink
Merge pull request #3129 from felixhandte/zstd-fast-nodict-unconditio…
Browse files Browse the repository at this point in the history
…nal-ip1-table-write

ZSTD_fast_noDict: Avoid Safety Check When Writing `ip1` into Table
  • Loading branch information
felixhandte authored May 11, 2022
2 parents 8bf32de + 1bc8019 commit 8af64f4
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 95 deletions.
32 changes: 27 additions & 5 deletions lib/compress/zstd_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ ZSTD_compressBlock_fast_noDict_generic(
match0 -= mLength;
offcode = REPCODE1_TO_OFFBASE;
mLength += 4;

/* First write next hash table entry; we've already calculated it.
* This write is known to be safe because the ip1 is before the
* repcode (ip2). */
hashTable[hash1] = (U32)(ip1 - base);

goto _match;
}

Expand All @@ -195,6 +201,12 @@ ZSTD_compressBlock_fast_noDict_generic(
/* check match at ip[0] */
if (MEM_read32(ip0) == mval) {
/* found a match! */

/* First write next hash table entry; we've already calculated it.
* This write is known to be safe because the ip1 == ip0 + 1, so
* we know we will resume searching after ip1 */
hashTable[hash1] = (U32)(ip1 - base);

goto _offset;
}

Expand Down Expand Up @@ -224,6 +236,21 @@ ZSTD_compressBlock_fast_noDict_generic(
/* check match at ip[0] */
if (MEM_read32(ip0) == mval) {
/* found a match! */

/* first write next hash table entry; we've already calculated it */
if (step <= 4) {
/* We need to avoid writing an index into the hash table >= the
* position at which we will pick up our searching after we've
* taken this match.
*
* The minimum possible match has length 4, so the earliest ip0
* can be after we take this match will be the current ip0 + 4.
* ip1 is ip0 + step - 1. If ip1 is >= ip0 + 4, we can't safely
* write this position.
*/
hashTable[hash1] = (U32)(ip1 - base);
}

goto _offset;
}

Expand Down Expand Up @@ -287,11 +314,6 @@ ZSTD_compressBlock_fast_noDict_generic(
ip0 += mLength;
anchor = ip0;

/* write next hash table entry */
if (ip1 < ip0) {
hashTable[hash1] = (U32)(ip1 - base);
}

/* Fill table and check for immediate repcode. */
if (ip0 <= ilimit) {
/* Fill Table */
Expand Down
Loading

0 comments on commit 8af64f4

Please sign in to comment.