Skip to content

Commit

Permalink
compress:check more bytes to reduce ZSTD_count call
Browse files Browse the repository at this point in the history
Signed-off-by: Jun He <jun.he@arm.com>
Change-Id: I3449ea423d5c8e8344f75341f19a2d1643c703f6
  • Loading branch information
JunHe77 committed Jul 18, 2022
1 parent 43f21a6 commit a222b32
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/compress/zstd_lazy.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ size_t ZSTD_HcFindBestMatch(
? ZSTD_hashPtr(ip, ddsHashLog, mls) << ZSTD_LAZY_DDSS_BUCKET_LOG : 0;

U32 matchIndex;
U32 ref = 0, lookup = 0, pr = 0;
if (dictMode != ZSTD_extDict) {
/* read initial refernence */
ref = MEM_read32(ip);
}

if (dictMode == ZSTD_dedicatedDictSearch) {
const U32* entry = &dms->hashTable[ddsIdx];
Expand All @@ -692,7 +697,8 @@ size_t ZSTD_HcFindBestMatch(
if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) {
const BYTE* const match = base + matchIndex;
assert(matchIndex >= dictLimit); /* ensures this is true if dictMode != ZSTD_extDict */
if (match[ml] == ip[ml]) /* potentially better */
lookup = MEM_read32(match + pr); /* read 4B starting from (match + ml + 1 - sizeof(U32)) */
if (ref == lookup) /* potentially better */
currentMl = ZSTD_count(ip, match, iLimit);
} else {
const BYTE* const match = dictBase + matchIndex;
Expand All @@ -706,6 +712,11 @@ size_t ZSTD_HcFindBestMatch(
ml = currentMl;
*offsetPtr = OFFSET_TO_OFFBASE(curr - matchIndex);
if (ip+currentMl == iLimit) break; /* best possible, avoids read overflow on next attempt */
if (dictMode != ZSTD_extDict) {
/* have a new longer ml, now advance one more byte and read new reference */
pr = ml - sizeof(ref) + 1;
ref = MEM_read32(ip + pr);
}
}

if (matchIndex <= minChain) break;
Expand Down Expand Up @@ -1210,6 +1221,11 @@ size_t ZSTD_RowFindBestMatch(
size_t numMatches = 0;
size_t currMatch = 0;
ZSTD_VecMask matches = ZSTD_row_getMatchMask(tagRow, (BYTE)tag, headGrouped, rowEntries);
U32 ref = 0, lookup = 0, pr = 0;
if (dictMode != ZSTD_extDict) {
/* read initial ref */
ref = MEM_read32(ip);
}

/* Cycle through the matches and prefetch */
for (; (matches > 0) && (nbAttempts > 0); --nbAttempts, matches &= (matches - 1)) {
Expand Down Expand Up @@ -1244,7 +1260,8 @@ size_t ZSTD_RowFindBestMatch(
if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) {
const BYTE* const match = base + matchIndex;
assert(matchIndex >= dictLimit); /* ensures this is true if dictMode != ZSTD_extDict */
if (match[ml] == ip[ml]) /* potentially better */
lookup = MEM_read32(match + pr); /* read 4B starting from (match + ml + 1 - sizeof(U32)) */
if (ref == lookup) /* potentially better */
currentMl = ZSTD_count(ip, match, iLimit);
} else {
const BYTE* const match = dictBase + matchIndex;
Expand All @@ -1258,6 +1275,11 @@ size_t ZSTD_RowFindBestMatch(
ml = currentMl;
*offsetPtr = OFFSET_TO_OFFBASE(curr - matchIndex);
if (ip+currentMl == iLimit) break; /* best possible, avoids read overflow on next attempt */
if (dictMode != ZSTD_extDict) {
/* have a new longer ml, now advance one more byte and read new reference */
pr = ml - sizeof(ref) + 1;
ref = MEM_read32(ip + pr);
}
}
}
}
Expand Down

0 comments on commit a222b32

Please sign in to comment.