From: W. Felix Handte Date: Wed, 11 May 2022 15:27:34 +0000 (-0400) Subject: Hoist Hash Table Writes Up into Each Match Found Block X-Git-Tag: v1.5.4^2~213^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd1f5829432c6df1a47c26cf9be75495fb2fdb94;p=thirdparty%2Fzstd.git Hoist Hash Table Writes Up into Each Match Found Block 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! --- diff --git a/lib/compress/zstd_fast.c b/lib/compress/zstd_fast.c index f2028ef35..11c80af87 100644 --- a/lib/compress/zstd_fast.c +++ b/lib/compress/zstd_fast.c @@ -182,6 +182,10 @@ _start: /* Requires: ip0 */ 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; } @@ -195,6 +199,10 @@ _start: /* Requires: ip0 */ /* 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; } @@ -224,7 +232,9 @@ _start: /* Requires: ip0 */ /* 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. @@ -239,8 +249,9 @@ _start: /* Requires: ip0 */ * 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; } @@ -304,9 +315,6 @@ _match: /* Requires: ip0, match0, offcode */ 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 */