fixed msan warning

on btlazy2 strategy with dictAttach
This commit is contained in:
Yann Collet 2018-10-02 18:20:20 -07:00
parent c9843ec232
commit 22ddf3523a

View File

@ -16,8 +16,8 @@
* Binary Tree search * Binary Tree search
***************************************/ ***************************************/
static void ZSTD_updateDUBT( static void
ZSTD_matchState_t* ms, ZSTD_updateDUBT(ZSTD_matchState_t* ms,
const BYTE* ip, const BYTE* iend, const BYTE* ip, const BYTE* iend,
U32 mls) U32 mls)
{ {
@ -60,8 +60,8 @@ static void ZSTD_updateDUBT(
* sort one already inserted but unsorted position * sort one already inserted but unsorted position
* assumption : current >= btlow == (current - btmask) * assumption : current >= btlow == (current - btmask)
* doesn't fail */ * doesn't fail */
static void ZSTD_insertDUBT1( static void
ZSTD_matchState_t* ms, ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
U32 current, const BYTE* inputEnd, U32 current, const BYTE* inputEnd,
U32 nbCompares, U32 btLow, const ZSTD_dictMode_e dictMode) U32 nbCompares, U32 btLow, const ZSTD_dictMode_e dictMode)
{ {
@ -142,14 +142,15 @@ static void ZSTD_insertDUBT1(
} }
static size_t ZSTD_DUBT_findBetterDictMatch ( static size_t
ZSTD_DUBT_findBetterDictMatch (
ZSTD_matchState_t* ms, ZSTD_matchState_t* ms,
const BYTE* const ip, const BYTE* const iend, const BYTE* const ip, const BYTE* const iend,
size_t* offsetPtr, size_t* offsetPtr,
size_t bestLength,
U32 nbCompares, U32 nbCompares,
U32 const mls, U32 const mls,
const ZSTD_dictMode_e dictMode) { const ZSTD_dictMode_e dictMode)
{
const ZSTD_matchState_t * const dms = ms->dictMatchState; const ZSTD_matchState_t * const dms = ms->dictMatchState;
const ZSTD_compressionParameters* const dmsCParams = &dms->cParams; const ZSTD_compressionParameters* const dmsCParams = &dms->cParams;
const U32 * const dictHashTable = dms->hashTable; const U32 * const dictHashTable = dms->hashTable;
@ -171,7 +172,7 @@ static size_t ZSTD_DUBT_findBetterDictMatch (
U32 const btMask = (1 << btLog) - 1; U32 const btMask = (1 << btLog) - 1;
U32 const btLow = (btMask >= dictHighLimit - dictLowLimit) ? dictLowLimit : dictHighLimit - btMask; U32 const btLow = (btMask >= dictHighLimit - dictLowLimit) ? dictLowLimit : dictHighLimit - btMask;
size_t commonLengthSmaller=0, commonLengthLarger=0; size_t commonLengthSmaller=0, commonLengthLarger=0, bestLength=0;
U32 matchEndIdx = current+8+1; U32 matchEndIdx = current+8+1;
(void)dictMode; (void)dictMode;
@ -190,15 +191,16 @@ static size_t ZSTD_DUBT_findBetterDictMatch (
if (matchLength > matchEndIdx - matchIndex) if (matchLength > matchEndIdx - matchIndex)
matchEndIdx = matchIndex + (U32)matchLength; matchEndIdx = matchIndex + (U32)matchLength;
if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit32(current-matchIndex+1) - ZSTD_highbit32((U32)offsetPtr[0]+1)) ) { if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit32(current-matchIndex+1) - ZSTD_highbit32((U32)offsetPtr[0]+1)) ) {
DEBUGLOG(9, "ZSTD_DUBT_findBestDictMatch(%u) : found better match length %u -> %u and offsetCode %u -> %u (dictMatchIndex %u, matchIndex %u)", DEBUGLOG(2, "ZSTD_DUBT_findBestDictMatch(%u) : found better match length %u -> %u and offsetCode %u -> %u (dictMatchIndex %u, matchIndex %u)",
current, (U32)bestLength, (U32)matchLength, (U32)*offsetPtr, ZSTD_REP_MOVE + current - matchIndex, dictMatchIndex, matchIndex); current, (U32)bestLength, (U32)matchLength, (U32)*offsetPtr, ZSTD_REP_MOVE + current - matchIndex, dictMatchIndex, matchIndex);
bestLength = matchLength, *offsetPtr = ZSTD_REP_MOVE + current - matchIndex; bestLength = matchLength, *offsetPtr = ZSTD_REP_MOVE + current - matchIndex;
} }
if (ip+matchLength == iend) { /* equal : no way to know if inf or sup */ if (ip+matchLength == iend) { /* reached end of input : ip[matchLength] is not valid, no way to know if it's larger or smaller than match */
break; /* drop, to guarantee consistency (miss a little bit of compression) */ break; /* drop, to guarantee consistency (miss a little bit of compression) */
} }
} }
DEBUGLOG(2, "matchLength:%6zu, match:%p, prefixStart:%p, ip:%p", matchLength, match, prefixStart, ip);
if (match[matchLength] < ip[matchLength]) { if (match[matchLength] < ip[matchLength]) {
if (dictMatchIndex <= btLow) { break; } /* beyond tree size, stop the search */ if (dictMatchIndex <= btLow) { break; } /* beyond tree size, stop the search */
commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */ commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */
@ -213,7 +215,7 @@ static size_t ZSTD_DUBT_findBetterDictMatch (
if (bestLength >= MINMATCH) { if (bestLength >= MINMATCH) {
U32 const mIndex = current - ((U32)*offsetPtr - ZSTD_REP_MOVE); (void)mIndex; U32 const mIndex = current - ((U32)*offsetPtr - ZSTD_REP_MOVE); (void)mIndex;
DEBUGLOG(8, "ZSTD_DUBT_findBestDictMatch(%u) : found match of length %u and offsetCode %u (pos %u)", DEBUGLOG(2, "ZSTD_DUBT_findBestDictMatch(%u) : found match of length %u and offsetCode %u (pos %u)",
current, (U32)bestLength, (U32)*offsetPtr, mIndex); current, (U32)bestLength, (U32)*offsetPtr, mIndex);
} }
return bestLength; return bestLength;
@ -221,12 +223,12 @@ static size_t ZSTD_DUBT_findBetterDictMatch (
} }
static size_t ZSTD_DUBT_findBestMatch ( static size_t
ZSTD_matchState_t* ms, ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
const BYTE* const ip, const BYTE* const iend, const BYTE* const ip, const BYTE* const iend,
size_t* offsetPtr, size_t* offsetPtr,
U32 const mls, U32 const mls,
const ZSTD_dictMode_e dictMode) const ZSTD_dictMode_e dictMode)
{ {
const ZSTD_compressionParameters* const cParams = &ms->cParams; const ZSTD_compressionParameters* const cParams = &ms->cParams;
U32* const hashTable = ms->hashTable; U32* const hashTable = ms->hashTable;
@ -344,7 +346,7 @@ static size_t ZSTD_DUBT_findBestMatch (
*smallerPtr = *largerPtr = 0; *smallerPtr = *largerPtr = 0;
if (dictMode == ZSTD_dictMatchState && nbCompares) { if (dictMode == ZSTD_dictMatchState && nbCompares) {
bestLength = ZSTD_DUBT_findBetterDictMatch(ms, ip, iend, offsetPtr, bestLength, nbCompares, mls, dictMode); bestLength = ZSTD_DUBT_findBetterDictMatch(ms, ip, iend, offsetPtr, nbCompares, mls, dictMode);
} }
assert(matchEndIdx > current+8); /* ensure nextToUpdate is increased */ assert(matchEndIdx > current+8); /* ensure nextToUpdate is increased */
@ -360,12 +362,12 @@ static size_t ZSTD_DUBT_findBestMatch (
/** ZSTD_BtFindBestMatch() : Tree updater, providing best match */ /** ZSTD_BtFindBestMatch() : Tree updater, providing best match */
FORCE_INLINE_TEMPLATE size_t ZSTD_BtFindBestMatch ( FORCE_INLINE_TEMPLATE size_t
ZSTD_matchState_t* ms, ZSTD_BtFindBestMatch( ZSTD_matchState_t* ms,
const BYTE* const ip, const BYTE* const iLimit, const BYTE* const ip, const BYTE* const iLimit,
size_t* offsetPtr, size_t* offsetPtr,
const U32 mls /* template */, const U32 mls /* template */,
const ZSTD_dictMode_e dictMode) const ZSTD_dictMode_e dictMode)
{ {
DEBUGLOG(7, "ZSTD_BtFindBestMatch"); DEBUGLOG(7, "ZSTD_BtFindBestMatch");
if (ip < ms->window.base + ms->nextToUpdate) return 0; /* skipped area */ if (ip < ms->window.base + ms->nextToUpdate) return 0; /* skipped area */
@ -374,10 +376,10 @@ FORCE_INLINE_TEMPLATE size_t ZSTD_BtFindBestMatch (
} }
static size_t ZSTD_BtFindBestMatch_selectMLS ( static size_t
ZSTD_matchState_t* ms, ZSTD_BtFindBestMatch_selectMLS ( ZSTD_matchState_t* ms,
const BYTE* ip, const BYTE* const iLimit, const BYTE* ip, const BYTE* const iLimit,
size_t* offsetPtr) size_t* offsetPtr)
{ {
switch(ms->cParams.searchLength) switch(ms->cParams.searchLength)
{ {
@ -679,7 +681,7 @@ size_t ZSTD_compressBlock_lazy_generic(
} }
/* first search (depth 0) */ /* first search (depth 0) */
{ size_t offsetFound = 99999999; { size_t offsetFound = 999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offsetFound); size_t const ml2 = searchMax(ms, ip, iend, &offsetFound);
if (ml2 > matchLength) if (ml2 > matchLength)
matchLength = ml2, start = ip, offset=offsetFound; matchLength = ml2, start = ip, offset=offsetFound;
@ -717,7 +719,7 @@ size_t ZSTD_compressBlock_lazy_generic(
matchLength = mlRep, offset = 0, start = ip; matchLength = mlRep, offset = 0, start = ip;
} }
} }
{ size_t offset2=99999999; { size_t offset2=999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offset2); size_t const ml2 = searchMax(ms, ip, iend, &offset2);
int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */
int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4); int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4);
@ -752,7 +754,7 @@ size_t ZSTD_compressBlock_lazy_generic(
matchLength = mlRep, offset = 0, start = ip; matchLength = mlRep, offset = 0, start = ip;
} }
} }
{ size_t offset2=99999999; { size_t offset2=999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offset2); size_t const ml2 = searchMax(ms, ip, iend, &offset2);
int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */
int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7); int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7);
@ -942,7 +944,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
} } } }
/* first search (depth 0) */ /* first search (depth 0) */
{ size_t offsetFound = 99999999; { size_t offsetFound = 999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offsetFound); size_t const ml2 = searchMax(ms, ip, iend, &offsetFound);
if (ml2 > matchLength) if (ml2 > matchLength)
matchLength = ml2, start = ip, offset=offsetFound; matchLength = ml2, start = ip, offset=offsetFound;
@ -975,7 +977,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
} } } }
/* search match, depth 1 */ /* search match, depth 1 */
{ size_t offset2=99999999; { size_t offset2=999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offset2); size_t const ml2 = searchMax(ms, ip, iend, &offset2);
int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */
int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4); int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4);
@ -1005,7 +1007,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
} } } }
/* search match, depth 2 */ /* search match, depth 2 */
{ size_t offset2=99999999; { size_t offset2=999999999;
size_t const ml2 = searchMax(ms, ip, iend, &offset2); size_t const ml2 = searchMax(ms, ip, iend, &offset2);
int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */
int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7); int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7);