Skip to content

Commit

Permalink
Hoist Hash Table Writes Up into Each Match Found Block
Browse files Browse the repository at this point in the history
Refactoring this way avoids the bad write in the case that `step > 4`, and
is a bit more straightforward. It also seems to perform better!
  • Loading branch information
felixhandte committed May 11, 2022
1 parent 040986a commit cd1f582
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/compress/zstd_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ ZSTD_compressBlock_fast_noDict_generic(
match0 -= mLength;
offcode = REPCODE1_TO_OFFBASE;
mLength += 4;

/* first write next hash table entry; we've already calculated it */
hashTable[hash1] = (U32)(ip1 - base);

goto _match;
}

Expand All @@ -195,6 +199,10 @@ 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 */
hashTable[hash1] = (U32)(ip1 - base);

goto _offset;
}

Expand Down Expand Up @@ -224,7 +232,9 @@ ZSTD_compressBlock_fast_noDict_generic(
/* check match at ip[0] */
if (MEM_read32(ip0) == mval) {
/* found a match! */
if (step > 4) {

/* 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.
Expand All @@ -239,8 +249,9 @@ ZSTD_compressBlock_fast_noDict_generic(
* this is the only match path where this can occur. (In rep-
* code and the first match checks, ip1 == ip0 + 1.)
*/
ip1 = base;
hashTable[hash1] = (U32)(ip1 - base);
}

goto _offset;
}

Expand Down Expand Up @@ -304,9 +315,6 @@ ZSTD_compressBlock_fast_noDict_generic(
ip0 += mLength;
anchor = ip0;

/* write next hash table entry */
hashTable[hash1] = (U32)(ip1 - base);

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

0 comments on commit cd1f582

Please sign in to comment.