Merge pull request #4214 from facebook/ldm_bucketLog

minor: more accurate parameter for `ZSTD_ldm_insertEntry()`
This commit is contained in:
Yann Collet
2024-12-16 20:43:00 -08:00
committed by GitHub
+13 -12
View File
@@ -170,22 +170,22 @@ size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize)
/** ZSTD_ldm_getBucket() : /** ZSTD_ldm_getBucket() :
* Returns a pointer to the start of the bucket associated with hash. */ * Returns a pointer to the start of the bucket associated with hash. */
static ldmEntry_t* ZSTD_ldm_getBucket( static ldmEntry_t* ZSTD_ldm_getBucket(
ldmState_t* ldmState, size_t hash, ldmParams_t const ldmParams) const ldmState_t* ldmState, size_t hash, U32 const bucketSizeLog)
{ {
return ldmState->hashTable + (hash << ldmParams.bucketSizeLog); return ldmState->hashTable + (hash << bucketSizeLog);
} }
/** ZSTD_ldm_insertEntry() : /** ZSTD_ldm_insertEntry() :
* Insert the entry with corresponding hash into the hash table */ * Insert the entry with corresponding hash into the hash table */
static void ZSTD_ldm_insertEntry(ldmState_t* ldmState, static void ZSTD_ldm_insertEntry(ldmState_t* ldmState,
size_t const hash, const ldmEntry_t entry, size_t const hash, const ldmEntry_t entry,
ldmParams_t const ldmParams) U32 const bucketSizeLog)
{ {
BYTE* const pOffset = ldmState->bucketOffsets + hash; BYTE* const pOffset = ldmState->bucketOffsets + hash;
unsigned const offset = *pOffset; unsigned const offset = *pOffset;
*(ZSTD_ldm_getBucket(ldmState, hash, ldmParams) + offset) = entry; *(ZSTD_ldm_getBucket(ldmState, hash, bucketSizeLog) + offset) = entry;
*pOffset = (BYTE)((offset + 1) & ((1u << ldmParams.bucketSizeLog) - 1)); *pOffset = (BYTE)((offset + 1) & ((1u << bucketSizeLog) - 1));
} }
@@ -273,7 +273,8 @@ void ZSTD_ldm_fillHashTable(
const BYTE* iend, ldmParams_t const* params) const BYTE* iend, ldmParams_t const* params)
{ {
U32 const minMatchLength = params->minMatchLength; U32 const minMatchLength = params->minMatchLength;
U32 const hBits = params->hashLog - params->bucketSizeLog; U32 const bucketSizeLog = params->bucketSizeLog;
U32 const hBits = params->hashLog - bucketSizeLog;
BYTE const* const base = ldmState->window.base; BYTE const* const base = ldmState->window.base;
BYTE const* const istart = ip; BYTE const* const istart = ip;
ldmRollingHashState_t hashState; ldmRollingHashState_t hashState;
@@ -288,7 +289,7 @@ void ZSTD_ldm_fillHashTable(
unsigned n; unsigned n;
numSplits = 0; numSplits = 0;
hashed = ZSTD_ldm_gear_feed(&hashState, ip, iend - ip, splits, &numSplits); hashed = ZSTD_ldm_gear_feed(&hashState, ip, (size_t)(iend - ip), splits, &numSplits);
for (n = 0; n < numSplits; n++) { for (n = 0; n < numSplits; n++) {
if (ip + splits[n] >= istart + minMatchLength) { if (ip + splits[n] >= istart + minMatchLength) {
@@ -299,7 +300,7 @@ void ZSTD_ldm_fillHashTable(
entry.offset = (U32)(split - base); entry.offset = (U32)(split - base);
entry.checksum = (U32)(xxhash >> 32); entry.checksum = (U32)(xxhash >> 32);
ZSTD_ldm_insertEntry(ldmState, hash, entry, *params); ZSTD_ldm_insertEntry(ldmState, hash, entry, params->bucketSizeLog);
} }
} }
@@ -379,7 +380,7 @@ size_t ZSTD_ldm_generateSequences_internal(
candidates[n].split = split; candidates[n].split = split;
candidates[n].hash = hash; candidates[n].hash = hash;
candidates[n].checksum = (U32)(xxhash >> 32); candidates[n].checksum = (U32)(xxhash >> 32);
candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, *params); candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, params->bucketSizeLog);
PREFETCH_L1(candidates[n].bucket); PREFETCH_L1(candidates[n].bucket);
} }
@@ -402,7 +403,7 @@ size_t ZSTD_ldm_generateSequences_internal(
* the previous one, we merely register it in the hash table and * the previous one, we merely register it in the hash table and
* move on */ * move on */
if (split < anchor) { if (split < anchor) {
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params); ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
continue; continue;
} }
@@ -449,7 +450,7 @@ size_t ZSTD_ldm_generateSequences_internal(
/* No match found -- insert an entry into the hash table /* No match found -- insert an entry into the hash table
* and process the next candidate match */ * and process the next candidate match */
if (bestEntry == NULL) { if (bestEntry == NULL) {
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params); ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
continue; continue;
} }
@@ -470,7 +471,7 @@ size_t ZSTD_ldm_generateSequences_internal(
/* Insert the current entry into the hash table --- it must be /* Insert the current entry into the hash table --- it must be
* done after the previous block to avoid clobbering bestEntry */ * done after the previous block to avoid clobbering bestEntry */
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params); ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
anchor = split + forwardMatchLength; anchor = split + forwardMatchLength;