Lines Matching +full:reset +full:- +full:assert +full:- +full:ms
5 * This source code is licensed under both the BSD-style license (found in the
8 * You may select, at your option, one of the above-listed licenses.
18 /*-*************************************
25 /*-*************************************
35 … benefit is that ZSTD_DUBT_UNSORTED_MARK cannot be mishandled after table re-use with a different …
39 /*-*************************************
111 /* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
127 …ZSTD_OptPrice_e priceType; /* prices can be determined dynamically, or follow a pre-defined cost…
128 const ZSTD_entropyCTables_t* symbolCosts; /* pre-calculated dictionary statistics */
220 int forceWindow; /* force back-references to respect limit of
260 * Indicates whether this compression proceeds directly from user-provided
261 * source buffer to user-provided destination buffer (ZSTDb_not_buffered), or
271 …n requestedParams. Triggers transmission of new params to ZSTDMT (if available) then reset to 0. */
322 ZSTD_prefixDict prefixDict; /* single-usage dictionary */
324 /* Multi-threading */
379 * note : mlBase = matchLength - MINMATCH;
380 * because it's the format it's stored in seqStore->sequences */
405 newReps.rep[0] = offset - ZSTD_REP_MOVE; in ZSTD_updateRep()
409 U32 const currentOffset = (repCode==ZSTD_REP_NUM) ? (rep[0] - 1) : rep[repCode]; in ZSTD_updateRep()
462 U32 const minlog = (strat>=ZSTD_btultra) ? (U32)(strat) - 1 : 6; in ZSTD_minGain()
464 assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat)); in ZSTD_minGain()
470 switch (cctxParams->literalCompressionMode) { in ZSTD_disableLiteralsCompression()
476 assert(0 /* impossible: pre-validated */); in ZSTD_disableLiteralsCompression()
479 … return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0); in ZSTD_disableLiteralsCompression()
489 assert(iend > ilimit_w); in ZSTD_safecopyLiterals()
491 ZSTD_wildcopy(op, ip, ilimit_w - ip, ZSTD_no_overlap); in ZSTD_safecopyLiterals()
492 op += ilimit_w - ip; in ZSTD_safecopyLiterals()
501 * `mlBase` : matchLength - MINMATCH
507 BYTE const* const litLimit_w = litLimit - WILDCOPY_OVERLENGTH; in ZSTD_storeSeq()
512 { U32 const pos = (U32)((const BYTE*)literals - g_start); in ZSTD_storeSeq()
517 assert((size_t)(seqStorePtr->sequences - seqStorePtr->sequencesStart) < seqStorePtr->maxNbSeq); in ZSTD_storeSeq()
519 assert(seqStorePtr->maxNbLit <= 128 KB); in ZSTD_storeSeq()
520 assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + seqStorePtr->maxNbLit); in ZSTD_storeSeq()
521 assert(literals + litLength <= litLimit); in ZSTD_storeSeq()
526 assert(WILDCOPY_OVERLENGTH >= 16); in ZSTD_storeSeq()
527 ZSTD_copy16(seqStorePtr->lit, literals); in ZSTD_storeSeq()
529 … ZSTD_wildcopy(seqStorePtr->lit+16, literals+16, (ptrdiff_t)litLength-16, ZSTD_no_overlap); in ZSTD_storeSeq()
532 ZSTD_safecopyLiterals(seqStorePtr->lit, literals, litEnd, litLimit_w); in ZSTD_storeSeq()
534 seqStorePtr->lit += litLength; in ZSTD_storeSeq()
538 assert(seqStorePtr->longLengthID == 0); /* there can only be a single long length */ in ZSTD_storeSeq()
539 seqStorePtr->longLengthID = 1; in ZSTD_storeSeq()
540 seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_storeSeq()
542 seqStorePtr->sequences[0].litLength = (U16)litLength; in ZSTD_storeSeq()
545 seqStorePtr->sequences[0].offset = offCode + 1; in ZSTD_storeSeq()
549 assert(seqStorePtr->longLengthID == 0); /* there can only be a single long length */ in ZSTD_storeSeq()
550 seqStorePtr->longLengthID = 2; in ZSTD_storeSeq()
551 seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_storeSeq()
553 seqStorePtr->sequences[0].matchLength = (U16)mlBase; in ZSTD_storeSeq()
555 seqStorePtr->sequences++; in ZSTD_storeSeq()
559 /*-*************************************
577 return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; in ZSTD_NbCommonBytes()
587 return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; in ZSTD_NbCommonBytes()
596 …gned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */ in ZSTD_NbCommonBytes()
618 const BYTE* const pInLoopLimit = pInLimit - (sizeof(size_t)-1); in ZSTD_count()
628 return (size_t)(pIn - pStart); in ZSTD_count()
630 …if (MEM_64bits() && (pIn<(pInLimit-3)) && (MEM_read32(pMatch) == MEM_read32(pIn))) { pIn+=4; pMatc… in ZSTD_count()
631 if ((pIn<(pInLimit-1)) && (MEM_read16(pMatch) == MEM_read16(pIn))) { pIn+=2; pMatch+=2; } in ZSTD_count()
633 return (size_t)(pIn - pStart); in ZSTD_count()
644 const BYTE* const vEnd = MIN( ip + (mEnd - match), iEnd); in ZSTD_count_2segments()
647 DEBUGLOG(7, "ZSTD_count_2segments: found a 2-parts match (current length==%zu)", matchLength); in ZSTD_count_2segments()
648 DEBUGLOG(7, "distance from match beginning to end dictionary = %zi", mEnd - match); in ZSTD_count_2segments()
649 DEBUGLOG(7, "distance from current pos to end buffer = %zi", iEnd - ip); in ZSTD_count_2segments()
656 /*-*************************************
660 static U32 ZSTD_hash3(U32 u, U32 h) { return ((u << (32-24)) * prime3bytes) >> (32-h) ; } in ZSTD_hash3()
664 static U32 ZSTD_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32-h) ; } in ZSTD_hash4()
668 static size_t ZSTD_hash5(U64 u, U32 h) { return (size_t)(((u << (64-40)) * prime5bytes) >> (64-h))… in ZSTD_hash5()
672 static size_t ZSTD_hash6(U64 u, U32 h) { return (size_t)(((u << (64-48)) * prime6bytes) >> (64-h))… in ZSTD_hash6()
676 static size_t ZSTD_hash7(U64 u, U32 h) { return (size_t)(((u << (64-56)) * prime7bytes) >> (64-h))… in ZSTD_hash7()
680 static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; } in ZSTD_hash8()
741 return ZSTD_ipow(prime8bytes, length - 1); in ZSTD_rollingHash_primePower()
749 hash -= (toRemove + ZSTD_ROLL_HASH_CHAR_OFFSET) * primePower; in ZSTD_rollingHash_rotate()
755 /*-*************************************
765 ( ((U32)-1) /* Maximum ending current index */ \
766 - ZSTD_CURRENT_MAX) /* Maximum beginning lowLimit */
774 size_t const endT = (size_t)(window->nextSrc - window->base); in ZSTD_window_clear()
777 window->lowLimit = end; in ZSTD_window_clear()
778 window->dictLimit = end; in ZSTD_window_clear()
783 * Returns non-zero if the window has a non-empty extDict.
795 MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms) in ZSTD_matchState_dictMode() argument
797 return ZSTD_window_hasExtDict(ms->window) ? in ZSTD_matchState_dictMode()
799 ms->dictMatchState != NULL ? in ZSTD_matchState_dictMode()
800 … (ms->dictMatchState->dedicatedDictSearch ? ZSTD_dedicatedDictSearch : ZSTD_dictMatchState) : in ZSTD_matchState_dictMode()
806 * Returns non-zero if the indices are getting too large and need overflow
812 U32 const curr = (U32)((BYTE const*)srcEnd - window.base); in ZSTD_window_needOverflowCorrection()
834 * current - newCurrent in ZSTD_window_correctOverflow()
835 * > (3<<29 + 1<<windowLog) - (1<<windowLog + 1<<chainLog) in ZSTD_window_correctOverflow()
836 * > (3<<29) - (1<<chainLog) in ZSTD_window_correctOverflow()
837 * > (3<<29) - (1<<30) (NOTE: chainLog <= 30) in ZSTD_window_correctOverflow()
840 * 2. (ip+ZSTD_CHUNKSIZE_MAX - cctx->base) doesn't overflow: in ZSTD_window_correctOverflow()
842 * In 64-bit mode we are safe, because we have 64-bit ptrdiff_t. in ZSTD_window_correctOverflow()
843 * In 32-bit mode we are safe, because (chainLog <= 29), so in ZSTD_window_correctOverflow()
844 * ip+ZSTD_CHUNKSIZE_MAX - cctx->base < 1<<32. in ZSTD_window_correctOverflow()
845 * 3. (cctx->lowLimit + 1<<windowLog) < 1<<32: in ZSTD_window_correctOverflow()
848 U32 const cycleMask = (1U << cycleLog) - 1; in ZSTD_window_correctOverflow()
849 U32 const curr = (U32)((BYTE const*)src - window->base); in ZSTD_window_correctOverflow()
851 /* Exclude zero so that newCurrent - maxDist >= 1. */ in ZSTD_window_correctOverflow()
854 U32 const correction = curr - newCurrent; in ZSTD_window_correctOverflow()
855 assert((maxDist & cycleMask) == 0); in ZSTD_window_correctOverflow()
856 assert(curr > newCurrent); in ZSTD_window_correctOverflow()
858 assert(correction > 1<<28); in ZSTD_window_correctOverflow()
860 window->base += correction; in ZSTD_window_correctOverflow()
861 window->dictBase += correction; in ZSTD_window_correctOverflow()
862 if (window->lowLimit <= correction) window->lowLimit = 1; in ZSTD_window_correctOverflow()
863 else window->lowLimit -= correction; in ZSTD_window_correctOverflow()
864 if (window->dictLimit <= correction) window->dictLimit = 1; in ZSTD_window_correctOverflow()
865 else window->dictLimit -= correction; in ZSTD_window_correctOverflow()
868 assert(newCurrent >= maxDist); in ZSTD_window_correctOverflow()
869 assert(newCurrent - maxDist >= 1); in ZSTD_window_correctOverflow()
871 assert(window->lowLimit <= newCurrent); in ZSTD_window_correctOverflow()
872 assert(window->dictLimit <= newCurrent); in ZSTD_window_correctOverflow()
875 window->lowLimit); in ZSTD_window_correctOverflow()
882 * (srcEnd - base) - lowLimit == maxDist + loadedDictEnd
909 U32 const blockEndIdx = (U32)((BYTE const*)blockEnd - window->base); in ZSTD_window_enforceMaxDist()
914 /* - When there is no dictionary : loadedDictEnd == 0. in ZSTD_window_enforceMaxDist()
916 overflowing next operation `newLowLimit = blockEndIdx - maxDist`. in ZSTD_window_enforceMaxDist()
917 - When there is a standard dictionary : in ZSTD_window_enforceMaxDist()
923 - When there is an attached dictionary : in ZSTD_window_enforceMaxDist()
928 U32 const newLowLimit = blockEndIdx - maxDist; in ZSTD_window_enforceMaxDist()
929 if (window->lowLimit < newLowLimit) window->lowLimit = newLowLimit; in ZSTD_window_enforceMaxDist()
930 if (window->dictLimit < window->lowLimit) { in ZSTD_window_enforceMaxDist()
932 (unsigned)window->dictLimit, (unsigned)window->lowLimit); in ZSTD_window_enforceMaxDist()
933 window->dictLimit = window->lowLimit; in ZSTD_window_enforceMaxDist()
945 * loadedDictEnd uses same referential as window->base
954 assert(loadedDictEndPtr != NULL); in ZSTD_checkDictValidity()
955 assert(dictMatchStatePtr != NULL); in ZSTD_checkDictValidity()
956 { U32 const blockEndIdx = (U32)((BYTE const*)blockEnd - window->base); in ZSTD_checkDictValidity()
960 assert(blockEndIdx >= loadedDictEnd); in ZSTD_checkDictValidity()
978 window->base = (BYTE const*)""; in ZSTD_window_init()
979 window->dictBase = (BYTE const*)""; in ZSTD_window_init()
980 window->dictLimit = 1; /* start from 1, so that 1st position is valid */ in ZSTD_window_init()
981 window->lowLimit = 1; /* it ensures first and later CCtx usages compress the same */ in ZSTD_window_init()
982 window->nextSrc = window->base + 1; /* see issue #1241 */ in ZSTD_window_init()
990 * Returns non-zero if the segment is contiguous.
1000 assert(window->base != NULL); in ZSTD_window_update()
1001 assert(window->dictBase != NULL); in ZSTD_window_update()
1003 if (src != window->nextSrc) { in ZSTD_window_update()
1005 size_t const distanceFromBase = (size_t)(window->nextSrc - window->base); in ZSTD_window_update()
1006 DEBUGLOG(5, "Non contiguous blocks, new segment starts at %u", window->dictLimit); in ZSTD_window_update()
1007 window->lowLimit = window->dictLimit; in ZSTD_window_update()
1008 assert(distanceFromBase == (size_t)(U32)distanceFromBase); /* should never overflow */ in ZSTD_window_update()
1009 window->dictLimit = (U32)distanceFromBase; in ZSTD_window_update()
1010 window->dictBase = window->base; in ZSTD_window_update()
1011 window->base = ip - distanceFromBase; in ZSTD_window_update()
1012 /* ms->nextToUpdate = window->dictLimit; */ in ZSTD_window_update()
1013 …if (window->dictLimit - window->lowLimit < HASH_READ_SIZE) window->lowLimit = window->dictLimit; … in ZSTD_window_update()
1016 window->nextSrc = ip + srcSize; in ZSTD_window_update()
1018 if ( (ip+srcSize > window->dictBase + window->lowLimit) in ZSTD_window_update()
1019 & (ip < window->dictBase + window->dictLimit)) { in ZSTD_window_update()
1020 ptrdiff_t const highInputIdx = (ip + srcSize) - window->dictBase; in ZSTD_window_update()
1021 …U32 const lowLimitMax = (highInputIdx > (ptrdiff_t)window->dictLimit) ? window->dictLimit : (U32)h… in ZSTD_window_update()
1022 window->lowLimit = lowLimitMax; in ZSTD_window_update()
1023 DEBUGLOG(5, "Overlapping extDict and input : new lowLimit = %u", window->lowLimit); in ZSTD_window_update()
1029 * Returns the lowest allowed match index. It may either be in the ext-dict or the prefix.
1031 MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog) in ZSTD_getLowestMatchIndex() argument
1034 U32 const lowestValid = ms->window.lowLimit; in ZSTD_getLowestMatchIndex()
1035 … U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid; in ZSTD_getLowestMatchIndex()
1036 U32 const isDictionary = (ms->loadedDictEnd != 0); in ZSTD_getLowestMatchIndex()
1048 MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog) in ZSTD_getLowestPrefixIndex() argument
1051 U32 const lowestValid = ms->window.dictLimit; in ZSTD_getLowestPrefixIndex()
1052 … U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid; in ZSTD_getLowestPrefixIndex()
1053 U32 const isDictionary = (ms->loadedDictEnd != 0); in ZSTD_getLowestPrefixIndex()
1075 assert(hb + fp_accuracy < 31); in ZSTD_fWeight()
1088 u, table[u], ZSTD_fWeight(sum) - ZSTD_fWeight(table[u]) ); in ZSTD_debugTable()
1160 * output an empty Block with end-of-frame mark to complete a frame
1174 * NOTE: seqs are not verified! Invalid sequences can cause out-of-bounds memory