relocate large arrays from the stack to ldmState_t

This commit is contained in:
Quentin Carbonneaux
2021-02-10 16:16:54 +01:00
parent e2ad174d73
commit 552efcac2d
4 changed files with 17 additions and 17 deletions
-1
View File
@@ -1627,7 +1627,6 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
ZSTD_ldm_adjustParameters(&params.ldmParams, &params.cParams); ZSTD_ldm_adjustParameters(&params.ldmParams, &params.cParams);
assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog); assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog);
assert(params.ldmParams.hashRateLog < 32); assert(params.ldmParams.hashRateLog < 32);
zc->ldmState.hashPower = ZSTD_rollingHash_primePower(params.ldmParams.minMatchLength);
} }
{ size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params.cParams.windowLog), pledgedSrcSize)); { size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params.cParams.windowLog), pledgedSrcSize));
+11 -2
View File
@@ -183,13 +183,22 @@ typedef struct {
U32 checksum; U32 checksum;
} ldmEntry_t; } ldmEntry_t;
typedef struct {
BYTE const* split;
U32 hash;
U32 checksum;
ldmEntry_t* bucket;
} ldmMatchCandidate_t;
#define LDM_BATCH_SIZE 64
typedef struct { typedef struct {
ZSTD_window_t window; /* State for the window round buffer management */ ZSTD_window_t window; /* State for the window round buffer management */
ldmEntry_t* hashTable; ldmEntry_t* hashTable;
U32 loadedDictEnd; U32 loadedDictEnd;
BYTE* bucketOffsets; /* Next position in bucket to insert entry */ BYTE* bucketOffsets; /* Next position in bucket to insert entry */
U64 hashPower; /* Used to compute the rolling hash. size_t splitIndices[LDM_BATCH_SIZE];
* Depends on ldmParams.minMatchLength */ ldmMatchCandidate_t matchCandidates[LDM_BATCH_SIZE];
} ldmState_t; } ldmState_t;
typedef struct { typedef struct {
+6 -12
View File
@@ -19,7 +19,6 @@
#define LDM_BUCKET_SIZE_LOG 3 #define LDM_BUCKET_SIZE_LOG 3
#define LDM_MIN_MATCH_LENGTH 64 #define LDM_MIN_MATCH_LENGTH 64
#define LDM_HASH_RLOG 7 #define LDM_HASH_RLOG 7
#define LDM_LOOKAHEAD_SPLITS 64
typedef struct { typedef struct {
U64 rolling; U64 rolling;
@@ -62,8 +61,8 @@ static void ZSTD_ldm_gear_init(ldmRollingHashState_t* state, ldmParams_t const*
* *
* Registers in the splits array all the split points found in the first * Registers in the splits array all the split points found in the first
* size bytes following the data pointer. This function terminates when * size bytes following the data pointer. This function terminates when
* either all the data has been processed or LDM_LOOKAHEAD_SPLITS splits * either all the data has been processed or LDM_BATCH_SIZE splits are
* are present in the splits array. * present in the splits array.
* *
* Precondition: The splits array must not be full. * Precondition: The splits array must not be full.
* Returns: The number of bytes processed. */ * Returns: The number of bytes processed. */
@@ -84,7 +83,7 @@ static size_t ZSTD_ldm_gear_feed(ldmRollingHashState_t* state,
if (UNLIKELY((hash & mask) == 0)) { \ if (UNLIKELY((hash & mask) == 0)) { \
splits[*numSplits] = n; \ splits[*numSplits] = n; \
*numSplits += 1; \ *numSplits += 1; \
if (*numSplits == LDM_LOOKAHEAD_SPLITS) \ if (*numSplits == LDM_BATCH_SIZE) \
goto done; \ goto done; \
} \ } \
} while (0) } while (0)
@@ -247,7 +246,7 @@ void ZSTD_ldm_fillHashTable(
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;
size_t splits[LDM_LOOKAHEAD_SPLITS]; size_t* const splits = ldmState->splitIndices;
unsigned numSplits; unsigned numSplits;
DEBUGLOG(5, "ZSTD_ldm_fillHashTable"); DEBUGLOG(5, "ZSTD_ldm_fillHashTable");
@@ -319,13 +318,8 @@ static size_t ZSTD_ldm_generateSequences_internal(
/* Rolling hash state */ /* Rolling hash state */
ldmRollingHashState_t hashState; ldmRollingHashState_t hashState;
/* Arrays for staged-processing */ /* Arrays for staged-processing */
size_t splits[LDM_LOOKAHEAD_SPLITS]; size_t* const splits = ldmState->splitIndices;
struct { ldmMatchCandidate_t* const candidates = ldmState->matchCandidates;
BYTE const* split;
U32 hash;
U32 checksum;
ldmEntry_t* bucket;
} candidates[LDM_LOOKAHEAD_SPLITS];
unsigned numSplits; unsigned numSplits;
if (srcSize < minMatchLength) if (srcSize < minMatchLength)
-2
View File
@@ -472,8 +472,6 @@ ZSTDMT_serialState_reset(serialState_t* serialState,
ZSTD_ldm_adjustParameters(&params.ldmParams, &params.cParams); ZSTD_ldm_adjustParameters(&params.ldmParams, &params.cParams);
assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog); assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog);
assert(params.ldmParams.hashRateLog < 32); assert(params.ldmParams.hashRateLog < 32);
serialState->ldmState.hashPower =
ZSTD_rollingHash_primePower(params.ldmParams.minMatchLength);
} else { } else {
ZSTD_memset(&params.ldmParams, 0, sizeof(params.ldmParams)); ZSTD_memset(&params.ldmParams, 0, sizeof(params.ldmParams));
} }