Coalesce hasDictMatchState and extDict Checks into One Enum and Rename Stuff

This commit is contained in:
W. Felix Handte
2018-05-23 17:53:03 -04:00
parent 265c2869d1
commit b67196f30d
6 changed files with 52 additions and 55 deletions
+9 -11
View File
@@ -2137,7 +2137,7 @@ MEM_STATIC size_t ZSTD_compressSequences(seqStore_t* seqStorePtr,
/* ZSTD_selectBlockCompressor() : /* ZSTD_selectBlockCompressor() :
* Not static, but internal use only (used by long distance matcher) * Not static, but internal use only (used by long distance matcher)
* assumption : strat is a valid strategy */ * assumption : strat is a valid strategy */
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict, ZSTD_hasDictMatchState_e hdms) ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e dictMode)
{ {
static const ZSTD_blockCompressor blockCompressor[3][(unsigned)ZSTD_btultra+1] = { static const ZSTD_blockCompressor blockCompressor[3][(unsigned)ZSTD_btultra+1] = {
{ ZSTD_compressBlock_fast /* default for 0 */, { ZSTD_compressBlock_fast /* default for 0 */,
@@ -2148,15 +2148,15 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict
ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict, ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict,
ZSTD_compressBlock_lazy_extDict,ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict, ZSTD_compressBlock_lazy_extDict,ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict,
ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btultra_extDict }, ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btultra_extDict },
{ ZSTD_compressBlock_fast_extDictMatchState /* default for 0 */, { ZSTD_compressBlock_fast_dictMatchState /* default for 0 */,
ZSTD_compressBlock_fast_extDictMatchState, ZSTD_compressBlock_fast_dictMatchState,
NULL, NULL, NULL, NULL, NULL, NULL, NULL } NULL, NULL, NULL, NULL, NULL, NULL, NULL /* unimplemented as of yet */ }
}; };
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1); ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1);
assert((U32)strat >= (U32)ZSTD_fast); assert((U32)strat >= (U32)ZSTD_fast);
assert((U32)strat <= (U32)ZSTD_btultra); assert((U32)strat <= (U32)ZSTD_btultra);
return blockCompressor[hdms == ZSTD_hasDictMatchState ? 2 : (extDict!=0)][(U32)strat]; return blockCompressor[(int)dictMode][(U32)strat];
} }
static void ZSTD_storeLastLiterals(seqStore_t* seqStorePtr, static void ZSTD_storeLastLiterals(seqStore_t* seqStorePtr,
@@ -2198,9 +2198,7 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
} }
/* select and store sequences */ /* select and store sequences */
{ U32 const extDict = ZSTD_window_hasExtDict(ms->window); { ZSTD_dictMode_e const dictMode = ZSTD_matchState_dictMode(ms);
ZSTD_hasDictMatchState_e const hdms =
ZSTD_matchState_hasDictMatchState(ms);
size_t lastLLSize; size_t lastLLSize;
{ int i; { int i;
for (i = 0; i < ZSTD_REP_NUM; ++i) for (i = 0; i < ZSTD_REP_NUM; ++i)
@@ -2214,7 +2212,7 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
ms, &zc->seqStore, ms, &zc->seqStore,
zc->blockState.nextCBlock->rep, zc->blockState.nextCBlock->rep,
&zc->appliedParams.cParams, &zc->appliedParams.cParams,
src, srcSize, extDict); src, srcSize);
assert(zc->externSeqStore.pos <= zc->externSeqStore.size); assert(zc->externSeqStore.pos <= zc->externSeqStore.size);
} else if (zc->appliedParams.ldmParams.enableLdm) { } else if (zc->appliedParams.ldmParams.enableLdm) {
rawSeqStore_t ldmSeqStore = {NULL, 0, 0, 0}; rawSeqStore_t ldmSeqStore = {NULL, 0, 0, 0};
@@ -2231,10 +2229,10 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
ms, &zc->seqStore, ms, &zc->seqStore,
zc->blockState.nextCBlock->rep, zc->blockState.nextCBlock->rep,
&zc->appliedParams.cParams, &zc->appliedParams.cParams,
src, srcSize, extDict); src, srcSize);
assert(ldmSeqStore.pos == ldmSeqStore.size); assert(ldmSeqStore.pos == ldmSeqStore.size);
} else { /* not long range mode */ } else { /* not long range mode */
ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, extDict, hdms); ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, dictMode);
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, &zc->appliedParams.cParams, src, srcSize); lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, &zc->appliedParams.cParams, src, srcSize);
} }
{ const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize; { const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize;
+11 -12
View File
@@ -250,22 +250,13 @@ struct ZSTD_CCtx_s {
typedef enum { ZSTD_dtlm_fast, ZSTD_dtlm_full } ZSTD_dictTableLoadMethod_e; typedef enum { ZSTD_dtlm_fast, ZSTD_dtlm_full } ZSTD_dictTableLoadMethod_e;
typedef enum { ZSTD_noDictMatchState, ZSTD_hasDictMatchState } ZSTD_hasDictMatchState_e; typedef enum { ZSTD_noDict = 0, ZSTD_extDict = 1, ZSTD_dictMatchState = 2 } ZSTD_dictMode_e;
/**
* ZSTD_matchState_hasDictMatchState():
* Does what the label says.
*/
MEM_STATIC ZSTD_hasDictMatchState_e ZSTD_matchState_hasDictMatchState(const ZSTD_matchState_t *ms)
{
return ms->dictMatchState != NULL ? ZSTD_hasDictMatchState : ZSTD_noDictMatchState;
}
typedef size_t (*ZSTD_blockCompressor) ( typedef size_t (*ZSTD_blockCompressor) (
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize); ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize);
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict, ZSTD_hasDictMatchState_e hdms); ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e hdms);
MEM_STATIC U32 ZSTD_LLcode(U32 litLength) MEM_STATIC U32 ZSTD_LLcode(U32 litLength)
@@ -522,7 +513,15 @@ MEM_STATIC U32 ZSTD_window_hasExtDict(ZSTD_window_t const window)
return window.lowLimit < window.dictLimit; return window.lowLimit < window.dictLimit;
} }
/**
* ZSTD_matchState_dictMode():
* Does what the label says.
*/
MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
{
return ms->dictMatchState != NULL ? ZSTD_dictMatchState :
ZSTD_window_hasExtDict(ms->window) ? ZSTD_extDict : ZSTD_noDict;
}
/** /**
* ZSTD_window_needOverflowCorrection(): * ZSTD_window_needOverflowCorrection():
+27 -25
View File
@@ -46,7 +46,7 @@ size_t ZSTD_compressBlock_fast_generic(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize, void const* src, size_t srcSize,
U32 const hlog, U32 const stepSize, U32 const mls, U32 const hlog, U32 const stepSize, U32 const mls,
ZSTD_hasDictMatchState_e const hasDict) ZSTD_dictMode_e const hasDict)
{ {
U32* const hashTable = ms->hashTable; U32* const hashTable = ms->hashTable;
const BYTE* const base = ms->window.base; const BYTE* const base = ms->window.base;
@@ -71,23 +71,25 @@ size_t ZSTD_compressBlock_fast_generic(
*/ */
const ZSTD_matchState_t* const dms = ms->dictMatchState; const ZSTD_matchState_t* const dms = ms->dictMatchState;
const U32* const dictHashTable = hasDict == ZSTD_hasDictMatchState ? const U32* const dictHashTable = hasDict == ZSTD_dictMatchState ?
dms->hashTable : NULL; dms->hashTable : NULL;
const U32 lowestDictIndex = hasDict == ZSTD_hasDictMatchState ? const U32 lowestDictIndex = hasDict == ZSTD_dictMatchState ?
dms->window.dictLimit : 0; dms->window.dictLimit : 0;
const BYTE* const dictBase = hasDict == ZSTD_hasDictMatchState ? const BYTE* const dictBase = hasDict == ZSTD_dictMatchState ?
dms->window.base : NULL; dms->window.base : NULL;
const BYTE* const dictLowest = hasDict == ZSTD_hasDictMatchState ? const BYTE* const dictLowest = hasDict == ZSTD_dictMatchState ?
dictBase + lowestDictIndex : NULL; dictBase + lowestDictIndex : NULL;
const BYTE* const dictEnd = hasDict == ZSTD_hasDictMatchState ? const BYTE* const dictEnd = hasDict == ZSTD_dictMatchState ?
dms->window.nextSrc : NULL; dms->window.nextSrc : NULL;
const U32 dictIndexDelta = hasDict == ZSTD_hasDictMatchState ? const U32 dictIndexDelta = hasDict == ZSTD_dictMatchState ?
lowestIndex - (dictEnd - dictBase) : lowestIndex - (dictEnd - dictBase) :
0; 0;
ptrdiff_t dictLowestIndex = hasDict == ZSTD_hasDictMatchState ? ptrdiff_t dictLowestIndex = hasDict == ZSTD_dictMatchState ?
lowestDictIndex + dictIndexDelta : lowestDictIndex + dictIndexDelta :
lowestIndex; lowestIndex;
assert(hasDict == ZSTD_noDict || hasDict == ZSTD_dictMatchState);
/* init */ /* init */
ip += (ip==lowest); ip += (ip==lowest);
{ U32 const maxRep = (U32)(ip-lowest); { U32 const maxRep = (U32)(ip-lowest);
@@ -103,18 +105,18 @@ size_t ZSTD_compressBlock_fast_generic(
U32 const matchIndex = hashTable[h]; U32 const matchIndex = hashTable[h];
const BYTE* match = base + matchIndex; const BYTE* match = base + matchIndex;
const ptrdiff_t repIndex = current + 1 - offset_1; const ptrdiff_t repIndex = current + 1 - offset_1;
const BYTE* repBase = hasDict == ZSTD_hasDictMatchState && repIndex < (ptrdiff_t)lowestIndex ? dictBase - dictIndexDelta : base; const BYTE* repBase = hasDict == ZSTD_dictMatchState && repIndex < (ptrdiff_t)lowestIndex ? dictBase - dictIndexDelta : base;
const BYTE* repMatch = repBase + repIndex; const BYTE* repMatch = repBase + repIndex;
hashTable[h] = current; /* update hash table */ hashTable[h] = current; /* update hash table */
if (hasDict == ZSTD_hasDictMatchState if (hasDict == ZSTD_dictMatchState
&& (((U32)((lowestIndex-1) - repIndex) >= 3) & (repIndex > dictLowestIndex) /* intentional underflow */) && (((U32)((lowestIndex-1) - repIndex) >= 3) & (repIndex > dictLowestIndex) /* intentional underflow */)
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
const BYTE* repMatchEnd = repIndex < (ptrdiff_t)lowestIndex ? dictEnd : iend; const BYTE* repMatchEnd = repIndex < (ptrdiff_t)lowestIndex ? dictEnd : iend;
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, istart) + 4; mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, istart) + 4;
ip++; ip++;
ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH); ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
} else if (hasDict == ZSTD_noDictMatchState } else if (hasDict == ZSTD_noDict
&& (offset_1 > 0) & (MEM_read32(repMatch) == MEM_read32(ip+1))) { && (offset_1 > 0) & (MEM_read32(repMatch) == MEM_read32(ip+1))) {
mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4; mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
ip++; ip++;
@@ -122,7 +124,7 @@ size_t ZSTD_compressBlock_fast_generic(
} else { } else {
if ( (matchIndex <= lowestIndex) if ( (matchIndex <= lowestIndex)
|| (MEM_read32(match) != MEM_read32(ip)) ) { || (MEM_read32(match) != MEM_read32(ip)) ) {
if (hasDict == ZSTD_hasDictMatchState) { if (hasDict == ZSTD_dictMatchState) {
U32 const dictMatchIndex = dictHashTable[h]; U32 const dictMatchIndex = dictHashTable[h];
const BYTE* dictMatch = dictBase + dictMatchIndex; const BYTE* dictMatch = dictBase + dictMatchIndex;
if (dictMatchIndex <= lowestDictIndex || if (dictMatchIndex <= lowestDictIndex ||
@@ -164,11 +166,11 @@ size_t ZSTD_compressBlock_fast_generic(
hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base); hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base);
/* check immediate repcode */ /* check immediate repcode */
if (hasDict == ZSTD_hasDictMatchState) { if (hasDict == ZSTD_dictMatchState) {
while (ip <= ilimit) { while (ip <= ilimit) {
U32 const current2 = (U32)(ip-base); U32 const current2 = (U32)(ip-base);
ptrdiff_t const repIndex2 = current2 - offset_2; ptrdiff_t const repIndex2 = current2 - offset_2;
const BYTE* repMatch2 = hasDict == ZSTD_hasDictMatchState const BYTE* repMatch2 = hasDict == ZSTD_dictMatchState
&& repIndex2 < (ptrdiff_t)lowestIndex ? && repIndex2 < (ptrdiff_t)lowestIndex ?
dictBase - dictIndexDelta + repIndex2 : dictBase - dictIndexDelta + repIndex2 :
base + repIndex2; base + repIndex2;
@@ -187,9 +189,9 @@ size_t ZSTD_compressBlock_fast_generic(
} }
} }
if (hasDict == ZSTD_noDictMatchState) { if (hasDict == ZSTD_noDict) {
while ( (ip <= ilimit) while ( (ip <= ilimit)
&& (hasDict != ZSTD_hasDictMatchState || ip - offset_2 >= istart) && (hasDict != ZSTD_dictMatchState || ip - offset_2 >= istart)
&& ( (offset_2>0) && ( (offset_2>0)
& (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) { & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
/* store sequence */ /* store sequence */
@@ -223,17 +225,17 @@ size_t ZSTD_compressBlock_fast(
{ {
default: /* includes case 3 */ default: /* includes case 3 */
case 4 : case 4 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 4, ZSTD_noDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 4, ZSTD_noDict);
case 5 : case 5 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 5, ZSTD_noDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 5, ZSTD_noDict);
case 6 : case 6 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 6, ZSTD_noDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 6, ZSTD_noDict);
case 7 : case 7 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 7, ZSTD_noDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 7, ZSTD_noDict);
} }
} }
size_t ZSTD_compressBlock_fast_extDictMatchState( size_t ZSTD_compressBlock_fast_dictMatchState(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize) ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize)
{ {
@@ -245,13 +247,13 @@ size_t ZSTD_compressBlock_fast_extDictMatchState(
{ {
default: /* includes case 3 */ default: /* includes case 3 */
case 4 : case 4 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 4, ZSTD_hasDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 4, ZSTD_dictMatchState);
case 5 : case 5 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 5, ZSTD_hasDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 5, ZSTD_dictMatchState);
case 6 : case 6 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 6, ZSTD_hasDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 6, ZSTD_dictMatchState);
case 7 : case 7 :
return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 7, ZSTD_hasDictMatchState); return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, hlog, stepSize, 7, ZSTD_dictMatchState);
} }
} }
+1 -1
View File
@@ -24,7 +24,7 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
size_t ZSTD_compressBlock_fast( size_t ZSTD_compressBlock_fast(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize); ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize);
size_t ZSTD_compressBlock_fast_extDictMatchState( size_t ZSTD_compressBlock_fast_dictMatchState(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize); ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize);
size_t ZSTD_compressBlock_fast_extDict( size_t ZSTD_compressBlock_fast_extDict(
+3 -4
View File
@@ -591,13 +591,12 @@ static rawSeq maybeSplitSequence(rawSeqStore_t* rawSeqStore,
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize, ZSTD_compressionParameters const* cParams, void const* src, size_t srcSize)
int const extDict)
{ {
unsigned const minMatch = cParams->searchLength; unsigned const minMatch = cParams->searchLength;
ZSTD_blockCompressor const blockCompressor = ZSTD_blockCompressor const blockCompressor =
ZSTD_selectBlockCompressor(cParams->strategy, extDict, ZSTD_selectBlockCompressor(cParams->strategy,
ZSTD_matchState_hasDictMatchState(ms)); ZSTD_matchState_dictMode(ms));
BYTE const* const base = ms->window.base; BYTE const* const base = ms->window.base;
/* Input bounds */ /* Input bounds */
BYTE const* const istart = (BYTE const*)src; BYTE const* const istart = (BYTE const*)src;
+1 -2
View File
@@ -62,8 +62,7 @@ size_t ZSTD_ldm_generateSequences(
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_compressionParameters const* cParams, ZSTD_compressionParameters const* cParams,
void const* src, size_t srcSize, void const* src, size_t srcSize);
int const extDict);
/** /**
* ZSTD_ldm_skipSequences(): * ZSTD_ldm_skipSequences():