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.
11 /*-*************************************
43 /*-*************************************
48 * full-block strategy.
58 /*-*************************************
81 assert(cctx != NULL); in ZSTD_initCCtx()
83 cctx->customMem = memManager; in ZSTD_initCCtx()
84 cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); in ZSTD_initCCtx()
86 assert(!ZSTD_isError(err)); in ZSTD_initCCtx()
94 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN==(0ULL - 1)); in ZSTD_createCCtx_advanced()
108 if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */ in ZSTD_initStaticCCtx()
115 ZSTD_cwksp_move(&cctx->workspace, &ws); in ZSTD_initStaticCCtx()
116 cctx->staticSize = workspaceSize; in ZSTD_initStaticCCtx()
119 …if (!ZSTD_cwksp_check_available(&cctx->workspace, ENTROPY_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compres… in ZSTD_initStaticCCtx()
120 …cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
121 …cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
122 …cctx->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cctx->workspace, ENTROPY_WORKSPACE_SIZE); in ZSTD_initStaticCCtx()
123 cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); in ZSTD_initStaticCCtx()
132 ZSTD_customFree(cctx->localDict.dictBuffer, cctx->customMem); in ZSTD_clearAllDicts()
133 ZSTD_freeCDict(cctx->localDict.cdict); in ZSTD_clearAllDicts()
134 ZSTD_memset(&cctx->localDict, 0, sizeof(cctx->localDict)); in ZSTD_clearAllDicts()
135 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); in ZSTD_clearAllDicts()
136 cctx->cdict = NULL; in ZSTD_clearAllDicts()
148 assert(cctx != NULL); in ZSTD_freeCCtxContent()
149 assert(cctx->staticSize == 0); in ZSTD_freeCCtxContent()
151 ZSTD_cwksp_free(&cctx->workspace, cctx->customMem); in ZSTD_freeCCtxContent()
157 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_freeCCtx()
160 int cctxInWorkspace = ZSTD_cwksp_owns_buffer(&cctx->workspace, cctx); in ZSTD_freeCCtx()
163 ZSTD_customFree(cctx, cctx->customMem); in ZSTD_freeCCtx()
181 return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx)) in ZSTD_sizeof_CCtx()
182 + ZSTD_cwksp_sizeof(&cctx->workspace) in ZSTD_sizeof_CCtx()
183 + ZSTD_sizeof_localDict(cctx->localDict) in ZSTD_sizeof_CCtx()
193 const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); } in ZSTD_getSeqStore()
200 return cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 27; in ZSTD_CParams_shouldEnableLdm()
216 assert(cctxParams.ldmParams.hashLog >= cctxParams.ldmParams.bucketSizeLog); in ZSTD_makeCCtxParamsFromCParams()
217 assert(cctxParams.ldmParams.hashRateLog < 32); in ZSTD_makeCCtxParamsFromCParams()
220 assert(!ZSTD_checkCParams(cParams)); in ZSTD_makeCCtxParamsFromCParams()
233 params->customMem = customMem; in ZSTD_createCCtxParams_advanced()
245 ZSTD_customFree(params, params->customMem); in ZSTD_freeCCtxParams()
257 cctxParams->compressionLevel = compressionLevel; in ZSTD_CCtxParams_init()
258 cctxParams->fParams.contentSizeFlag = 1; in ZSTD_CCtxParams_init()
270 assert(!ZSTD_checkCParams(params->cParams)); in ZSTD_CCtxParams_init_internal()
272 cctxParams->cParams = params->cParams; in ZSTD_CCtxParams_init_internal()
273 cctxParams->fParams = params->fParams; in ZSTD_CCtxParams_init_internal()
277 cctxParams->compressionLevel = compressionLevel; in ZSTD_CCtxParams_init_internal()
295 assert(!ZSTD_checkCParams(params->cParams)); in ZSTD_CCtxParams_setZstdParams()
296 cctxParams->cParams = params->cParams; in ZSTD_CCtxParams_setZstdParams()
297 cctxParams->fParams = params->fParams; in ZSTD_CCtxParams_setZstdParams()
301 cctxParams->compressionLevel = ZSTD_NO_CLEVEL; in ZSTD_CCtxParams_setZstdParams()
534 if (cctx->streamStage != zcss_init) { in ZSTD_CCtx_setParameter()
536 cctx->cParamsChanged = 1; in ZSTD_CCtx_setParameter()
544 RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported, in ZSTD_CCtx_setParameter()
582 return ZSTD_CCtxParams_setParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_setParameter()
593 CCtxParams->format = (ZSTD_format_e)value; in ZSTD_CCtxParams_setParameter()
594 return (size_t)CCtxParams->format; in ZSTD_CCtxParams_setParameter()
599 CCtxParams->compressionLevel = ZSTD_CLEVEL_DEFAULT; /* 0 == default */ in ZSTD_CCtxParams_setParameter()
601 CCtxParams->compressionLevel = value; in ZSTD_CCtxParams_setParameter()
602 if (CCtxParams->compressionLevel >= 0) return (size_t)CCtxParams->compressionLevel; in ZSTD_CCtxParams_setParameter()
609 CCtxParams->cParams.windowLog = (U32)value; in ZSTD_CCtxParams_setParameter()
610 return CCtxParams->cParams.windowLog; in ZSTD_CCtxParams_setParameter()
615 CCtxParams->cParams.hashLog = (U32)value; in ZSTD_CCtxParams_setParameter()
616 return CCtxParams->cParams.hashLog; in ZSTD_CCtxParams_setParameter()
621 CCtxParams->cParams.chainLog = (U32)value; in ZSTD_CCtxParams_setParameter()
622 return CCtxParams->cParams.chainLog; in ZSTD_CCtxParams_setParameter()
627 CCtxParams->cParams.searchLog = (U32)value; in ZSTD_CCtxParams_setParameter()
633 CCtxParams->cParams.minMatch = value; in ZSTD_CCtxParams_setParameter()
634 return CCtxParams->cParams.minMatch; in ZSTD_CCtxParams_setParameter()
638 CCtxParams->cParams.targetLength = value; in ZSTD_CCtxParams_setParameter()
639 return CCtxParams->cParams.targetLength; in ZSTD_CCtxParams_setParameter()
644 CCtxParams->cParams.strategy = (ZSTD_strategy)value; in ZSTD_CCtxParams_setParameter()
645 return (size_t)CCtxParams->cParams.strategy; in ZSTD_CCtxParams_setParameter()
650 CCtxParams->fParams.contentSizeFlag = value != 0; in ZSTD_CCtxParams_setParameter()
651 return CCtxParams->fParams.contentSizeFlag; in ZSTD_CCtxParams_setParameter()
654 /* A 32-bits content checksum will be calculated and written at end of frame (default:0) */ in ZSTD_CCtxParams_setParameter()
655 CCtxParams->fParams.checksumFlag = value != 0; in ZSTD_CCtxParams_setParameter()
656 return CCtxParams->fParams.checksumFlag; in ZSTD_CCtxParams_setParameter()
660 CCtxParams->fParams.noDictIDFlag = !value; in ZSTD_CCtxParams_setParameter()
661 return !CCtxParams->fParams.noDictIDFlag; in ZSTD_CCtxParams_setParameter()
664 CCtxParams->forceWindow = (value != 0); in ZSTD_CCtxParams_setParameter()
665 return CCtxParams->forceWindow; in ZSTD_CCtxParams_setParameter()
670 CCtxParams->attachDictPref = pref; in ZSTD_CCtxParams_setParameter()
671 return CCtxParams->attachDictPref; in ZSTD_CCtxParams_setParameter()
677 CCtxParams->literalCompressionMode = lcm; in ZSTD_CCtxParams_setParameter()
678 return CCtxParams->literalCompressionMode; in ZSTD_CCtxParams_setParameter()
698 CCtxParams->enableDedicatedDictSearch = (value!=0); in ZSTD_CCtxParams_setParameter()
699 return CCtxParams->enableDedicatedDictSearch; in ZSTD_CCtxParams_setParameter()
702 CCtxParams->ldmParams.enableLdm = (value!=0); in ZSTD_CCtxParams_setParameter()
703 return CCtxParams->ldmParams.enableLdm; in ZSTD_CCtxParams_setParameter()
708 CCtxParams->ldmParams.hashLog = value; in ZSTD_CCtxParams_setParameter()
709 return CCtxParams->ldmParams.hashLog; in ZSTD_CCtxParams_setParameter()
714 CCtxParams->ldmParams.minMatchLength = value; in ZSTD_CCtxParams_setParameter()
715 return CCtxParams->ldmParams.minMatchLength; in ZSTD_CCtxParams_setParameter()
720 CCtxParams->ldmParams.bucketSizeLog = value; in ZSTD_CCtxParams_setParameter()
721 return CCtxParams->ldmParams.bucketSizeLog; in ZSTD_CCtxParams_setParameter()
726 CCtxParams->ldmParams.hashRateLog = value; in ZSTD_CCtxParams_setParameter()
727 return CCtxParams->ldmParams.hashRateLog; in ZSTD_CCtxParams_setParameter()
732 CCtxParams->targetCBlockSize = value; in ZSTD_CCtxParams_setParameter()
733 return CCtxParams->targetCBlockSize; in ZSTD_CCtxParams_setParameter()
738 CCtxParams->srcSizeHint = value; in ZSTD_CCtxParams_setParameter()
739 return CCtxParams->srcSizeHint; in ZSTD_CCtxParams_setParameter()
743 CCtxParams->inBufferMode = (ZSTD_bufferMode_e)value; in ZSTD_CCtxParams_setParameter()
744 return CCtxParams->inBufferMode; in ZSTD_CCtxParams_setParameter()
748 CCtxParams->outBufferMode = (ZSTD_bufferMode_e)value; in ZSTD_CCtxParams_setParameter()
749 return CCtxParams->outBufferMode; in ZSTD_CCtxParams_setParameter()
753 CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value; in ZSTD_CCtxParams_setParameter()
754 return CCtxParams->blockDelimiters; in ZSTD_CCtxParams_setParameter()
758 CCtxParams->validateSequences = value; in ZSTD_CCtxParams_setParameter()
759 return CCtxParams->validateSequences; in ZSTD_CCtxParams_setParameter()
767 return ZSTD_CCtxParams_getParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_getParameter()
776 *value = CCtxParams->format; in ZSTD_CCtxParams_getParameter()
779 *value = CCtxParams->compressionLevel; in ZSTD_CCtxParams_getParameter()
782 *value = (int)CCtxParams->cParams.windowLog; in ZSTD_CCtxParams_getParameter()
785 *value = (int)CCtxParams->cParams.hashLog; in ZSTD_CCtxParams_getParameter()
788 *value = (int)CCtxParams->cParams.chainLog; in ZSTD_CCtxParams_getParameter()
791 *value = CCtxParams->cParams.searchLog; in ZSTD_CCtxParams_getParameter()
794 *value = CCtxParams->cParams.minMatch; in ZSTD_CCtxParams_getParameter()
797 *value = CCtxParams->cParams.targetLength; in ZSTD_CCtxParams_getParameter()
800 *value = (unsigned)CCtxParams->cParams.strategy; in ZSTD_CCtxParams_getParameter()
803 *value = CCtxParams->fParams.contentSizeFlag; in ZSTD_CCtxParams_getParameter()
806 *value = CCtxParams->fParams.checksumFlag; in ZSTD_CCtxParams_getParameter()
809 *value = !CCtxParams->fParams.noDictIDFlag; in ZSTD_CCtxParams_getParameter()
812 *value = CCtxParams->forceWindow; in ZSTD_CCtxParams_getParameter()
815 *value = CCtxParams->attachDictPref; in ZSTD_CCtxParams_getParameter()
818 *value = CCtxParams->literalCompressionMode; in ZSTD_CCtxParams_getParameter()
821 assert(CCtxParams->nbWorkers == 0); in ZSTD_CCtxParams_getParameter()
822 *value = CCtxParams->nbWorkers; in ZSTD_CCtxParams_getParameter()
831 *value = CCtxParams->enableDedicatedDictSearch; in ZSTD_CCtxParams_getParameter()
834 *value = CCtxParams->ldmParams.enableLdm; in ZSTD_CCtxParams_getParameter()
837 *value = CCtxParams->ldmParams.hashLog; in ZSTD_CCtxParams_getParameter()
840 *value = CCtxParams->ldmParams.minMatchLength; in ZSTD_CCtxParams_getParameter()
843 *value = CCtxParams->ldmParams.bucketSizeLog; in ZSTD_CCtxParams_getParameter()
846 *value = CCtxParams->ldmParams.hashRateLog; in ZSTD_CCtxParams_getParameter()
849 *value = (int)CCtxParams->targetCBlockSize; in ZSTD_CCtxParams_getParameter()
852 *value = (int)CCtxParams->srcSizeHint; in ZSTD_CCtxParams_getParameter()
855 *value = (int)CCtxParams->inBufferMode; in ZSTD_CCtxParams_getParameter()
858 *value = (int)CCtxParams->outBufferMode; in ZSTD_CCtxParams_getParameter()
861 *value = (int)CCtxParams->blockDelimiters; in ZSTD_CCtxParams_getParameter()
864 *value = (int)CCtxParams->validateSequences; in ZSTD_CCtxParams_getParameter()
874 * If ZSTDMT is enabled, parameters are pushed to cctx->mtctx.
882 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
884 RETURN_ERROR_IF(cctx->cdict, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
888 cctx->requestedParams = *params; in ZSTD_CCtx_setParametersUsingCCtxParams()
895 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setPledgedSrcSize()
897 cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1; in ZSTD_CCtx_setPledgedSrcSize()
916 ZSTD_localDict* const dl = &cctx->localDict; in ZSTD_initLocalDict()
917 if (dl->dict == NULL) { in ZSTD_initLocalDict()
919 assert(dl->dictBuffer == NULL); in ZSTD_initLocalDict()
920 assert(dl->cdict == NULL); in ZSTD_initLocalDict()
921 assert(dl->dictSize == 0); in ZSTD_initLocalDict()
924 if (dl->cdict != NULL) { in ZSTD_initLocalDict()
925 assert(cctx->cdict == dl->cdict); in ZSTD_initLocalDict()
929 assert(dl->dictSize > 0); in ZSTD_initLocalDict()
930 assert(cctx->cdict == NULL); in ZSTD_initLocalDict()
931 assert(cctx->prefixDict.dict == NULL); in ZSTD_initLocalDict()
933 dl->cdict = ZSTD_createCDict_advanced2( in ZSTD_initLocalDict()
934 dl->dict, in ZSTD_initLocalDict()
935 dl->dictSize, in ZSTD_initLocalDict()
937 dl->dictContentType, in ZSTD_initLocalDict()
938 &cctx->requestedParams, in ZSTD_initLocalDict()
939 cctx->customMem); in ZSTD_initLocalDict()
940 RETURN_ERROR_IF(!dl->cdict, memory_allocation, "ZSTD_createCDict_advanced failed"); in ZSTD_initLocalDict()
941 cctx->cdict = dl->cdict; in ZSTD_initLocalDict()
949 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_loadDictionary_advanced()
956 cctx->localDict.dict = dict; in ZSTD_CCtx_loadDictionary_advanced()
959 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_CCtx_loadDictionary_advanced()
961 dictBuffer = ZSTD_customMalloc(dictSize, cctx->customMem); in ZSTD_CCtx_loadDictionary_advanced()
964 cctx->localDict.dictBuffer = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
965 cctx->localDict.dict = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
967 cctx->localDict.dictSize = dictSize; in ZSTD_CCtx_loadDictionary_advanced()
968 cctx->localDict.dictContentType = dictContentType; in ZSTD_CCtx_loadDictionary_advanced()
988 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refCDict()
992 cctx->cdict = cdict; in ZSTD_CCtx_refCDict()
998 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refThreadPool()
1000 cctx->pool = pool; in ZSTD_CCtx_refThreadPool()
1012 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refPrefix_advanced()
1016 cctx->prefixDict.dict = prefix; in ZSTD_CCtx_refPrefix_advanced()
1017 cctx->prefixDict.dictSize = prefixSize; in ZSTD_CCtx_refPrefix_advanced()
1018 cctx->prefixDict.dictContentType = dictContentType; in ZSTD_CCtx_refPrefix_advanced()
1025 size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset) in ZSTD_CCtx_reset() argument
1027 if ( (reset == ZSTD_reset_session_only) in ZSTD_CCtx_reset()
1028 || (reset == ZSTD_reset_session_and_parameters) ) { in ZSTD_CCtx_reset()
1029 cctx->streamStage = zcss_init; in ZSTD_CCtx_reset()
1030 cctx->pledgedSrcSizePlusOne = 0; in ZSTD_CCtx_reset()
1032 if ( (reset == ZSTD_reset_parameters) in ZSTD_CCtx_reset()
1033 || (reset == ZSTD_reset_session_and_parameters) ) { in ZSTD_CCtx_reset()
1034 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_reset()
1035 "Can't reset parameters only when not in init stage."); in ZSTD_CCtx_reset()
1037 return ZSTD_CCtxParams_reset(&cctx->requestedParams); in ZSTD_CCtx_reset()
1085 return hashLog - btScale; in ZSTD_cycleLog()
1103 assert(windowLog <= ZSTD_WINDOWLOG_MAX); in ZSTD_dictAndWindowLog()
1104 assert(srcSize != ZSTD_CONTENTSIZE_UNKNOWN); /* Handled in ZSTD_adjustCParams_internal() */ in ZSTD_dictAndWindowLog()
1117 return ZSTD_highbit32((U32)dictAndWindowSize - 1) + 1; in ZSTD_dictAndWindowLog()
1136 const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1); in ZSTD_adjustCParams_internal()
1137 assert(ZSTD_checkCParams(cPar)==0); in ZSTD_adjustCParams_internal()
1162 assert(0); in ZSTD_adjustCParams_internal()
1172 ZSTD_highbit32(tSize-1) + 1; in ZSTD_adjustCParams_internal()
1180 cPar.chainLog -= (cycleLog - dictAndWindowLog); in ZSTD_adjustCParams_internal()
1206 if (overrides->windowLog) cParams->windowLog = overrides->windowLog; in ZSTD_overrideCParams()
1207 if (overrides->hashLog) cParams->hashLog = overrides->hashLog; in ZSTD_overrideCParams()
1208 if (overrides->chainLog) cParams->chainLog = overrides->chainLog; in ZSTD_overrideCParams()
1209 if (overrides->searchLog) cParams->searchLog = overrides->searchLog; in ZSTD_overrideCParams()
1210 if (overrides->minMatch) cParams->minMatch = overrides->minMatch; in ZSTD_overrideCParams()
1211 if (overrides->targetLength) cParams->targetLength = overrides->targetLength; in ZSTD_overrideCParams()
1212 if (overrides->strategy) cParams->strategy = overrides->strategy; in ZSTD_overrideCParams()
1219 if (srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN && CCtxParams->srcSizeHint > 0) { in ZSTD_getCParamsFromCCtxParams()
1220 srcSizeHint = CCtxParams->srcSizeHint; in ZSTD_getCParamsFromCCtxParams()
1222 cParams = ZSTD_getCParams_internal(CCtxParams->compressionLevel, srcSizeHint, dictSize, mode); in ZSTD_getCParamsFromCCtxParams()
1223 if (CCtxParams->ldmParams.enableLdm) cParams.windowLog = ZSTD_LDM_DEFAULT_WINDOW_LOG; in ZSTD_getCParamsFromCCtxParams()
1224 ZSTD_overrideCParams(&cParams, &CCtxParams->cParams); in ZSTD_getCParamsFromCCtxParams()
1225 assert(!ZSTD_checkCParams(cParams)); in ZSTD_getCParamsFromCCtxParams()
1234 … size_t const chainSize = (cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams->chainLog); in ZSTD_sizeof_matchState()
1235 size_t const hSize = ((size_t)1) << cParams->hashLog; in ZSTD_sizeof_matchState()
1236 …U32 const hashLog3 = (forCCtx && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->window… in ZSTD_sizeof_matchState()
1250 size_t const optSpace = (forCCtx && (cParams->strategy >= ZSTD_btopt)) in ZSTD_sizeof_matchState()
1253 DEBUGLOG(4, "chainSize: %u - hSize: %u - h3Size: %u", in ZSTD_sizeof_matchState()
1266 size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << cParams->windowLog), pledgedSrcSize)); in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1268 U32 const divider = (cParams->minMatch==3) ? 3 : 4; in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1279 size_t const ldmSeqSpace = ldmParams->enableLdm ? in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1307 …RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-thread… in ZSTD_estimateCCtxSize_usingCCtxParams()
1308 /* estimateCCtxSize is for one-shot compression. So no buffers should in ZSTD_estimateCCtxSize_usingCCtxParams()
1309 * be needed. However, we still allocate two 0-sized buffers, which can in ZSTD_estimateCCtxSize_usingCCtxParams()
1312 &cParams, &params->ldmParams, 1, 0, 0, ZSTD_CONTENTSIZE_UNKNOWN); in ZSTD_estimateCCtxSize_usingCCtxParams()
1348 …RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-thread… in ZSTD_estimateCStreamSize_usingCCtxParams()
1352 size_t const inBuffSize = (params->inBufferMode == ZSTD_bm_buffered) in ZSTD_estimateCStreamSize_usingCCtxParams()
1355 size_t const outBuffSize = (params->outBufferMode == ZSTD_bm_buffered) in ZSTD_estimateCStreamSize_usingCCtxParams()
1360 &cParams, &params->ldmParams, 1, inBuffSize, outBuffSize, in ZSTD_estimateCStreamSize_usingCCtxParams()
1390 * able to count progression inside worker threads (non-blocking mode).
1395 size_t const buffered = (cctx->inBuff == NULL) ? 0 : in ZSTD_getFrameProgression()
1396 cctx->inBuffPos - cctx->inToCompress; in ZSTD_getFrameProgression()
1397 if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress); in ZSTD_getFrameProgression()
1398 assert(buffered <= ZSTD_BLOCKSIZE_MAX); in ZSTD_getFrameProgression()
1399 fp.ingested = cctx->consumedSrcSize + buffered; in ZSTD_getFrameProgression()
1400 fp.consumed = cctx->consumedSrcSize; in ZSTD_getFrameProgression()
1401 fp.produced = cctx->producedCSize; in ZSTD_getFrameProgression()
1402 …fp.flushed = cctx->producedCSize; /* simplified; some data might still be left within streaming… in ZSTD_getFrameProgression()
1414 …return 0; /* over-simplification; could also check if context is currently running in streaming … in ZSTD_toFlushNow()
1422 assert(cParams1.windowLog == cParams2.windowLog); in ZSTD_assertEqualCParams()
1423 assert(cParams1.chainLog == cParams2.chainLog); in ZSTD_assertEqualCParams()
1424 assert(cParams1.hashLog == cParams2.hashLog); in ZSTD_assertEqualCParams()
1425 assert(cParams1.searchLog == cParams2.searchLog); in ZSTD_assertEqualCParams()
1426 assert(cParams1.minMatch == cParams2.minMatch); in ZSTD_assertEqualCParams()
1427 assert(cParams1.targetLength == cParams2.targetLength); in ZSTD_assertEqualCParams()
1428 assert(cParams1.strategy == cParams2.strategy); in ZSTD_assertEqualCParams()
1435 bs->rep[i] = repStartValue[i]; in ZSTD_reset_compressedBlockState()
1436 bs->entropy.huf.repeatMode = HUF_repeat_none; in ZSTD_reset_compressedBlockState()
1437 bs->entropy.fse.offcode_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1438 bs->entropy.fse.matchlength_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1439 bs->entropy.fse.litlength_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1446 static void ZSTD_invalidateMatchState(ZSTD_matchState_t* ms) in ZSTD_invalidateMatchState() argument
1448 ZSTD_window_clear(&ms->window); in ZSTD_invalidateMatchState()
1450 ms->nextToUpdate = ms->window.dictLimit; in ZSTD_invalidateMatchState()
1451 ms->loadedDictEnd = 0; in ZSTD_invalidateMatchState()
1452 ms->opt.litLengthSum = 0; /* force reset of btopt stats */ in ZSTD_invalidateMatchState()
1453 ms->dictMatchState = NULL; in ZSTD_invalidateMatchState()
1457 * Controls, for this matchState reset, whether the tables need to be cleared /
1469 * Controls, for this matchState reset, whether indexing can continue where it
1484 ZSTD_reset_matchState(ZSTD_matchState_t* ms, in ZSTD_reset_matchState() argument
1491 … size_t const chainSize = (cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams->chainLog); in ZSTD_reset_matchState()
1492 size_t const hSize = ((size_t)1) << cParams->hashLog; in ZSTD_reset_matchState()
1493 …Log3 = ((forWho == ZSTD_resetTarget_CCtx) && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParam… in ZSTD_reset_matchState()
1496 DEBUGLOG(4, "reset indices : %u", forceResetIndex == ZSTDirp_reset); in ZSTD_reset_matchState()
1498 ZSTD_window_init(&ms->window); in ZSTD_reset_matchState()
1502 ms->hashLog3 = hashLog3; in ZSTD_reset_matchState()
1504 ZSTD_invalidateMatchState(ms); in ZSTD_reset_matchState()
1506 assert(!ZSTD_cwksp_reserve_failed(ws)); /* check that allocation hasn't already failed */ in ZSTD_reset_matchState()
1512 ms->hashTable = (U32*)ZSTD_cwksp_reserve_table(ws, hSize * sizeof(U32)); in ZSTD_reset_matchState()
1513 ms->chainTable = (U32*)ZSTD_cwksp_reserve_table(ws, chainSize * sizeof(U32)); in ZSTD_reset_matchState()
1514 ms->hashTable3 = (U32*)ZSTD_cwksp_reserve_table(ws, h3Size * sizeof(U32)); in ZSTD_reset_matchState()
1518 DEBUGLOG(4, "reset table : %u", crp!=ZSTDcrp_leaveDirty); in ZSTD_reset_matchState()
1520 /* reset tables only */ in ZSTD_reset_matchState()
1525 if ((forWho == ZSTD_resetTarget_CCtx) && (cParams->strategy >= ZSTD_btopt)) { in ZSTD_reset_matchState()
1527ms->opt.litFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (1<<Litbits) * sizeof(unsigned)); in ZSTD_reset_matchState()
1528ms->opt.litLengthFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxLL+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1529ms->opt.matchLengthFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxML+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1530ms->opt.offCodeFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxOff+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1531ms->opt.matchTable = (ZSTD_match_t*)ZSTD_cwksp_reserve_aligned(ws, (ZSTD_OPT_NUM+1) * sizeof(ZSTD_… in ZSTD_reset_matchState()
1532ms->opt.priceTable = (ZSTD_optimal_t*)ZSTD_cwksp_reserve_aligned(ws, (ZSTD_OPT_NUM+1) * sizeof(ZST… in ZSTD_reset_matchState()
1535 ms->cParams = *cParams; in ZSTD_reset_matchState()
1546 * Works when re-using a context for a lot of smallish inputs :
1553 return (size_t)(w.nextSrc - w.base) > (ZSTD_CURRENT_MAX - ZSTD_INDEXOVERFLOW_MARGIN); in ZSTD_indexTooCloseToMax()
1564 ZSTD_cwksp* const ws = &zc->workspace; in ZSTD_resetCCtx_internal()
1567 assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); in ZSTD_resetCCtx_internal()
1569 zc->isFirstBlock = 1; in ZSTD_resetCCtx_internal()
1574 assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog); in ZSTD_resetCCtx_internal()
1575 assert(params.ldmParams.hashRateLog < 32); in ZSTD_resetCCtx_internal()
1590 int const indexTooClose = ZSTD_indexTooCloseToMax(zc->blockState.matchState.window); in ZSTD_resetCCtx_internal()
1592 (!indexTooClose && zc->initialized) ? ZSTDirp_continue : ZSTDirp_reset; in ZSTD_resetCCtx_internal()
1596 &params.cParams, &params.ldmParams, zc->staticSize != 0, in ZSTD_resetCCtx_internal()
1600 if (!zc->staticSize) ZSTD_cwksp_bump_oversized_duration(ws, 0); in ZSTD_resetCCtx_internal()
1608 DEBUGLOG(4, "windowSize: %zu - blockSize: %zu", windowSize, blockSize); in ZSTD_resetCCtx_internal()
1615 RETURN_ERROR_IF(zc->staticSize, memory_allocation, "static cctx : no resize"); in ZSTD_resetCCtx_internal()
1619 ZSTD_cwksp_free(ws, zc->customMem); in ZSTD_resetCCtx_internal()
1620 FORWARD_IF_ERROR(ZSTD_cwksp_create(ws, neededSpace, zc->customMem), ""); in ZSTD_resetCCtx_internal()
1626 assert(ZSTD_cwksp_check_available(ws, 2 * sizeof(ZSTD_compressedBlockState_t))); in ZSTD_resetCCtx_internal()
1627 …zc->blockState.prevCBlock = (ZSTD_compressedBlockState_t*) ZSTD_cwksp_reserve_object(ws, sizeof(ZS… in ZSTD_resetCCtx_internal()
1628 …RETURN_ERROR_IF(zc->blockState.prevCBlock == NULL, memory_allocation, "couldn't allocate prevCBloc… in ZSTD_resetCCtx_internal()
1629 …zc->blockState.nextCBlock = (ZSTD_compressedBlockState_t*) ZSTD_cwksp_reserve_object(ws, sizeof(ZS… in ZSTD_resetCCtx_internal()
1630 …RETURN_ERROR_IF(zc->blockState.nextCBlock == NULL, memory_allocation, "couldn't allocate nextCBloc… in ZSTD_resetCCtx_internal()
1631 zc->entropyWorkspace = (U32*) ZSTD_cwksp_reserve_object(ws, ENTROPY_WORKSPACE_SIZE); in ZSTD_resetCCtx_internal()
1632 …RETURN_ERROR_IF(zc->blockState.nextCBlock == NULL, memory_allocation, "couldn't allocate entropyWo… in ZSTD_resetCCtx_internal()
1638 zc->appliedParams = params; in ZSTD_resetCCtx_internal()
1639 zc->blockState.matchState.cParams = params.cParams; in ZSTD_resetCCtx_internal()
1640 zc->pledgedSrcSizePlusOne = pledgedSrcSize+1; in ZSTD_resetCCtx_internal()
1641 zc->consumedSrcSize = 0; in ZSTD_resetCCtx_internal()
1642 zc->producedCSize = 0; in ZSTD_resetCCtx_internal()
1644 zc->appliedParams.fParams.contentSizeFlag = 0; in ZSTD_resetCCtx_internal()
1646 (unsigned)pledgedSrcSize, zc->appliedParams.fParams.contentSizeFlag); in ZSTD_resetCCtx_internal()
1647 zc->blockSize = blockSize; in ZSTD_resetCCtx_internal()
1649 xxh64_reset(&zc->xxhState, 0); in ZSTD_resetCCtx_internal()
1650 zc->stage = ZSTDcs_init; in ZSTD_resetCCtx_internal()
1651 zc->dictID = 0; in ZSTD_resetCCtx_internal()
1652 zc->dictContentSize = 0; in ZSTD_resetCCtx_internal()
1654 ZSTD_reset_compressedBlockState(zc->blockState.prevCBlock); in ZSTD_resetCCtx_internal()
1659 zc->seqStore.litStart = ZSTD_cwksp_reserve_buffer(ws, blockSize + WILDCOPY_OVERLENGTH); in ZSTD_resetCCtx_internal()
1660 zc->seqStore.maxNbLit = blockSize; in ZSTD_resetCCtx_internal()
1663 zc->bufferedPolicy = zbuff; in ZSTD_resetCCtx_internal()
1664 zc->inBuffSize = buffInSize; in ZSTD_resetCCtx_internal()
1665 zc->inBuff = (char*)ZSTD_cwksp_reserve_buffer(ws, buffInSize); in ZSTD_resetCCtx_internal()
1666 zc->outBuffSize = buffOutSize; in ZSTD_resetCCtx_internal()
1667 zc->outBuff = (char*)ZSTD_cwksp_reserve_buffer(ws, buffOutSize); in ZSTD_resetCCtx_internal()
1673 ((size_t)1) << (params.ldmParams.hashLog - in ZSTD_resetCCtx_internal()
1675 zc->ldmState.bucketOffsets = ZSTD_cwksp_reserve_buffer(ws, numBuckets); in ZSTD_resetCCtx_internal()
1676 ZSTD_memset(zc->ldmState.bucketOffsets, 0, numBuckets); in ZSTD_resetCCtx_internal()
1681 zc->seqStore.maxNbSeq = maxNbSeq; in ZSTD_resetCCtx_internal()
1682 zc->seqStore.llCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1683 zc->seqStore.mlCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1684 zc->seqStore.ofCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1685 … zc->seqStore.sequencesStart = (seqDef*)ZSTD_cwksp_reserve_aligned(ws, maxNbSeq * sizeof(seqDef)); in ZSTD_resetCCtx_internal()
1688 &zc->blockState.matchState, in ZSTD_resetCCtx_internal()
1699 …zc->ldmState.hashTable = (ldmEntry_t*)ZSTD_cwksp_reserve_aligned(ws, ldmHSize * sizeof(ldmEntry_t)… in ZSTD_resetCCtx_internal()
1700 ZSTD_memset(zc->ldmState.hashTable, 0, ldmHSize * sizeof(ldmEntry_t)); in ZSTD_resetCCtx_internal()
1701 … zc->ldmSequences = (rawSeq*)ZSTD_cwksp_reserve_aligned(ws, maxNbLdmSeq * sizeof(rawSeq)); in ZSTD_resetCCtx_internal()
1702 zc->maxNbLdmSequences = maxNbLdmSeq; in ZSTD_resetCCtx_internal()
1704 ZSTD_window_init(&zc->ldmState.window); in ZSTD_resetCCtx_internal()
1705 ZSTD_window_clear(&zc->ldmState.window); in ZSTD_resetCCtx_internal()
1706 zc->ldmState.loadedDictEnd = 0; in ZSTD_resetCCtx_internal()
1712 assert(ZSTD_cwksp_used(ws) >= neededSpace && in ZSTD_resetCCtx_internal()
1716 zc->initialized = 1; in ZSTD_resetCCtx_internal()
1728 for (i=0; i<ZSTD_REP_NUM; i++) cctx->blockState.prevCBlock->rep[i] = 0; in ZSTD_invalidateRepCodes()
1729 assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window)); in ZSTD_invalidateRepCodes()
1734 * in-place.
1753 size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy]; in ZSTD_shouldAttachDict()
1754 int const dedicatedDictSearch = cdict->matchState.dedicatedDictSearch; in ZSTD_shouldAttachDict()
1758 || params->attachDictPref == ZSTD_dictForceAttach ) in ZSTD_shouldAttachDict()
1759 && params->attachDictPref != ZSTD_dictForceCopy in ZSTD_shouldAttachDict()
1760 && !params->forceWindow ); /* dictMatchState isn't correctly in ZSTD_shouldAttachDict()
1772 ZSTD_compressionParameters adjusted_cdict_cParams = cdict->matchState.cParams; in ZSTD_resetCCtx_byAttachingCDict()
1774 assert(windowLog != 0); in ZSTD_resetCCtx_byAttachingCDict()
1779 if (cdict->matchState.dedicatedDictSearch) { in ZSTD_resetCCtx_byAttachingCDict()
1784 cdict->dictContentSize, ZSTD_cpm_attachDict); in ZSTD_resetCCtx_byAttachingCDict()
1788 assert(cctx->appliedParams.cParams.strategy == adjusted_cdict_cParams.strategy); in ZSTD_resetCCtx_byAttachingCDict()
1791 { const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc in ZSTD_resetCCtx_byAttachingCDict()
1792 - cdict->matchState.window.base); in ZSTD_resetCCtx_byAttachingCDict()
1793 const U32 cdictLen = cdictEnd - cdict->matchState.window.dictLimit; in ZSTD_resetCCtx_byAttachingCDict()
1799 cctx->blockState.matchState.dictMatchState = &cdict->matchState; in ZSTD_resetCCtx_byAttachingCDict()
1803 if (cctx->blockState.matchState.window.dictLimit < cdictEnd) { in ZSTD_resetCCtx_byAttachingCDict()
1804 cctx->blockState.matchState.window.nextSrc = in ZSTD_resetCCtx_byAttachingCDict()
1805 cctx->blockState.matchState.window.base + cdictEnd; in ZSTD_resetCCtx_byAttachingCDict()
1806 ZSTD_window_clear(&cctx->blockState.matchState.window); in ZSTD_resetCCtx_byAttachingCDict()
1809 … cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit; in ZSTD_resetCCtx_byAttachingCDict()
1812 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byAttachingCDict()
1813 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byAttachingCDict()
1816 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byAttachingCDict()
1827 const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams; in ZSTD_resetCCtx_byCopyingCDict()
1829 assert(!cdict->matchState.dedicatedDictSearch); in ZSTD_resetCCtx_byCopyingCDict()
1834 assert(windowLog != 0); in ZSTD_resetCCtx_byCopyingCDict()
1840 assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy); in ZSTD_resetCCtx_byCopyingCDict()
1841 assert(cctx->appliedParams.cParams.hashLog == cdict_cParams->hashLog); in ZSTD_resetCCtx_byCopyingCDict()
1842 assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog); in ZSTD_resetCCtx_byCopyingCDict()
1845 ZSTD_cwksp_mark_tables_dirty(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
1848 …{ size_t const chainSize = (cdict_cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cdict_cPar… in ZSTD_resetCCtx_byCopyingCDict()
1849 size_t const hSize = (size_t)1 << cdict_cParams->hashLog; in ZSTD_resetCCtx_byCopyingCDict()
1851 ZSTD_memcpy(cctx->blockState.matchState.hashTable, in ZSTD_resetCCtx_byCopyingCDict()
1852 cdict->matchState.hashTable, in ZSTD_resetCCtx_byCopyingCDict()
1854 ZSTD_memcpy(cctx->blockState.matchState.chainTable, in ZSTD_resetCCtx_byCopyingCDict()
1855 cdict->matchState.chainTable, in ZSTD_resetCCtx_byCopyingCDict()
1860 { int const h3log = cctx->blockState.matchState.hashLog3; in ZSTD_resetCCtx_byCopyingCDict()
1862 assert(cdict->matchState.hashLog3 == 0); in ZSTD_resetCCtx_byCopyingCDict()
1863 ZSTD_memset(cctx->blockState.matchState.hashTable3, 0, h3Size * sizeof(U32)); in ZSTD_resetCCtx_byCopyingCDict()
1866 ZSTD_cwksp_mark_tables_clean(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
1869 { ZSTD_matchState_t const* srcMatchState = &cdict->matchState; in ZSTD_resetCCtx_byCopyingCDict()
1870 ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState; in ZSTD_resetCCtx_byCopyingCDict()
1871 dstMatchState->window = srcMatchState->window; in ZSTD_resetCCtx_byCopyingCDict()
1872 dstMatchState->nextToUpdate = srcMatchState->nextToUpdate; in ZSTD_resetCCtx_byCopyingCDict()
1873 dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd; in ZSTD_resetCCtx_byCopyingCDict()
1876 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byCopyingCDict()
1877 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byCopyingCDict()
1880 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byCopyingCDict()
1887 * in-place. We decide here which strategy to use. */
1921 RETURN_ERROR_IF(srcCCtx->stage!=ZSTDcs_init, stage_wrong, in ZSTD_copyCCtx_internal()
1924 ZSTD_memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); in ZSTD_copyCCtx_internal()
1925 { ZSTD_CCtx_params params = dstCCtx->requestedParams; in ZSTD_copyCCtx_internal()
1927 params.cParams = srcCCtx->appliedParams.cParams; in ZSTD_copyCCtx_internal()
1931assert(dstCCtx->appliedParams.cParams.windowLog == srcCCtx->appliedParams.cParams.windowLog); in ZSTD_copyCCtx_internal()
1932 assert(dstCCtx->appliedParams.cParams.strategy == srcCCtx->appliedParams.cParams.strategy); in ZSTD_copyCCtx_internal()
1933 assert(dstCCtx->appliedParams.cParams.hashLog == srcCCtx->appliedParams.cParams.hashLog); in ZSTD_copyCCtx_internal()
1934 assert(dstCCtx->appliedParams.cParams.chainLog == srcCCtx->appliedParams.cParams.chainLog); in ZSTD_copyCCtx_internal()
1935 assert(dstCCtx->blockState.matchState.hashLog3 == srcCCtx->blockState.matchState.hashLog3); in ZSTD_copyCCtx_internal()
1938 ZSTD_cwksp_mark_tables_dirty(&dstCCtx->workspace); in ZSTD_copyCCtx_internal()
1941 …{ size_t const chainSize = (srcCCtx->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((size_t… in ZSTD_copyCCtx_internal()
1942 size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog; in ZSTD_copyCCtx_internal()
1943 int const h3log = srcCCtx->blockState.matchState.hashLog3; in ZSTD_copyCCtx_internal()
1946 ZSTD_memcpy(dstCCtx->blockState.matchState.hashTable, in ZSTD_copyCCtx_internal()
1947 srcCCtx->blockState.matchState.hashTable, in ZSTD_copyCCtx_internal()
1949 ZSTD_memcpy(dstCCtx->blockState.matchState.chainTable, in ZSTD_copyCCtx_internal()
1950 srcCCtx->blockState.matchState.chainTable, in ZSTD_copyCCtx_internal()
1952 ZSTD_memcpy(dstCCtx->blockState.matchState.hashTable3, in ZSTD_copyCCtx_internal()
1953 srcCCtx->blockState.matchState.hashTable3, in ZSTD_copyCCtx_internal()
1957 ZSTD_cwksp_mark_tables_clean(&dstCCtx->workspace); in ZSTD_copyCCtx_internal()
1961 const ZSTD_matchState_t* srcMatchState = &srcCCtx->blockState.matchState; in ZSTD_copyCCtx_internal()
1962 ZSTD_matchState_t* dstMatchState = &dstCCtx->blockState.matchState; in ZSTD_copyCCtx_internal()
1963 dstMatchState->window = srcMatchState->window; in ZSTD_copyCCtx_internal()
1964 dstMatchState->nextToUpdate = srcMatchState->nextToUpdate; in ZSTD_copyCCtx_internal()
1965 dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd; in ZSTD_copyCCtx_internal()
1967 dstCCtx->dictID = srcCCtx->dictID; in ZSTD_copyCCtx_internal()
1968 dstCCtx->dictContentSize = srcCCtx->dictContentSize; in ZSTD_copyCCtx_internal()
1971 …ZSTD_memcpy(dstCCtx->blockState.prevCBlock, srcCCtx->blockState.prevCBlock, sizeof(*srcCCtx->block… in ZSTD_copyCCtx_internal()
1984 ZSTD_buffered_policy_e const zbuff = srcCCtx->bufferedPolicy; in ZSTD_copyCCtx()
2001 * to help auto-vectorization */
2008 assert((size & (ZSTD_ROWSIZE-1)) == 0); /* multiple of ZSTD_ROWSIZE */ in ZSTD_reduceTable_internal()
2009 assert(size < (1U<<31)); /* can be casted to int */ in ZSTD_reduceTable_internal()
2020 else table[cellNb] -= reducerValue; in ZSTD_reduceTable_internal()
2037 static void ZSTD_reduceIndex (ZSTD_matchState_t* ms, ZSTD_CCtx_params const* params, const U32 redu… in ZSTD_reduceIndex() argument
2039 { U32 const hSize = (U32)1 << params->cParams.hashLog; in ZSTD_reduceIndex()
2040 ZSTD_reduceTable(ms->hashTable, hSize, reducerValue); in ZSTD_reduceIndex()
2043 if (params->cParams.strategy != ZSTD_fast) { in ZSTD_reduceIndex()
2044 U32 const chainSize = (U32)1 << params->cParams.chainLog; in ZSTD_reduceIndex()
2045 if (params->cParams.strategy == ZSTD_btlazy2) in ZSTD_reduceIndex()
2046 ZSTD_reduceTable_btlazy2(ms->chainTable, chainSize, reducerValue); in ZSTD_reduceIndex()
2048 ZSTD_reduceTable(ms->chainTable, chainSize, reducerValue); in ZSTD_reduceIndex()
2051 if (ms->hashLog3) { in ZSTD_reduceIndex()
2052 U32 const h3Size = (U32)1 << ms->hashLog3; in ZSTD_reduceIndex()
2053 ZSTD_reduceTable(ms->hashTable3, h3Size, reducerValue); in ZSTD_reduceIndex()
2058 /*-*******************************************************
2066 const seqDef* const sequences = seqStorePtr->sequencesStart; in ZSTD_seqToCodes()
2067 BYTE* const llCodeTable = seqStorePtr->llCode; in ZSTD_seqToCodes()
2068 BYTE* const ofCodeTable = seqStorePtr->ofCode; in ZSTD_seqToCodes()
2069 BYTE* const mlCodeTable = seqStorePtr->mlCode; in ZSTD_seqToCodes()
2070 U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_seqToCodes()
2072 assert(nbSeq <= seqStorePtr->maxNbSeq); in ZSTD_seqToCodes()
2080 if (seqStorePtr->longLengthID==1) in ZSTD_seqToCodes()
2081 llCodeTable[seqStorePtr->longLengthPos] = MaxLL; in ZSTD_seqToCodes()
2082 if (seqStorePtr->longLengthID==2) in ZSTD_seqToCodes()
2083 mlCodeTable[seqStorePtr->longLengthPos] = MaxML; in ZSTD_seqToCodes()
2092 DEBUGLOG(5, "ZSTD_useTargetCBlockSize (targetCBlockSize=%zu)", cctxParams->targetCBlockSize); in ZSTD_useTargetCBlockSize()
2093 return (cctxParams->targetCBlockSize != 0); in ZSTD_useTargetCBlockSize()
2107 const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN; in ZSTD_entropyCompressSequences_internal()
2108 ZSTD_strategy const strategy = cctxParams->cParams.strategy; in ZSTD_entropyCompressSequences_internal()
2110 FSE_CTable* CTable_LitLength = nextEntropy->fse.litlengthCTable; in ZSTD_entropyCompressSequences_internal()
2111 FSE_CTable* CTable_OffsetBits = nextEntropy->fse.offcodeCTable; in ZSTD_entropyCompressSequences_internal()
2112 FSE_CTable* CTable_MatchLength = nextEntropy->fse.matchlengthCTable; in ZSTD_entropyCompressSequences_internal()
2114 const seqDef* const sequences = seqStorePtr->sequencesStart; in ZSTD_entropyCompressSequences_internal()
2115 const BYTE* const ofCodeTable = seqStorePtr->ofCode; in ZSTD_entropyCompressSequences_internal()
2116 const BYTE* const llCodeTable = seqStorePtr->llCode; in ZSTD_entropyCompressSequences_internal()
2117 const BYTE* const mlCodeTable = seqStorePtr->mlCode; in ZSTD_entropyCompressSequences_internal()
2121 size_t const nbSeq = (size_t)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_entropyCompressSequences_internal()
2126 entropyWkspSize -= (MaxSeq + 1) * sizeof(*count); in ZSTD_entropyCompressSequences_internal()
2130 assert(entropyWkspSize >= HUF_WORKSPACE_SIZE); in ZSTD_entropyCompressSequences_internal()
2133 { const BYTE* const literals = seqStorePtr->litStart; in ZSTD_entropyCompressSequences_internal()
2134 size_t const litSize = (size_t)(seqStorePtr->lit - literals); in ZSTD_entropyCompressSequences_internal()
2136 &prevEntropy->huf, &nextEntropy->huf, in ZSTD_entropyCompressSequences_internal()
2137 cctxParams->cParams.strategy, in ZSTD_entropyCompressSequences_internal()
2144 assert(cSize <= dstCapacity); in ZSTD_entropyCompressSequences_internal()
2149 RETURN_ERROR_IF((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/, in ZSTD_entropyCompressSequences_internal()
2159 MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)); in ZSTD_entropyCompressSequences_internal()
2162 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2165 ZSTD_memcpy(&nextEntropy->fse, &prevEntropy->fse, sizeof(prevEntropy->fse)); in ZSTD_entropyCompressSequences_internal()
2166 return (size_t)(op - ostart); in ZSTD_entropyCompressSequences_internal()
2171 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2179 nextEntropy->fse.litlength_repeatMode = prevEntropy->fse.litlength_repeatMode; in ZSTD_entropyCompressSequences_internal()
2180 LLtype = ZSTD_selectEncodingType(&nextEntropy->fse.litlength_repeatMode, in ZSTD_entropyCompressSequences_internal()
2182 LLFSELog, prevEntropy->fse.litlengthCTable, in ZSTD_entropyCompressSequences_internal()
2185 assert(set_basic < set_compressed && set_rle < set_compressed); in ZSTD_entropyCompressSequences_internal()
2186assert(!(LLtype < set_compressed && nextEntropy->fse.litlength_repeatMode != FSE_repeat_none)); /*… in ZSTD_entropyCompressSequences_internal()
2188 op, (size_t)(oend - op), in ZSTD_entropyCompressSequences_internal()
2192 prevEntropy->fse.litlengthCTable, in ZSTD_entropyCompressSequences_internal()
2193 sizeof(prevEntropy->fse.litlengthCTable), in ZSTD_entropyCompressSequences_internal()
2199 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2208 nextEntropy->fse.offcode_repeatMode = prevEntropy->fse.offcode_repeatMode; in ZSTD_entropyCompressSequences_internal()
2209 Offtype = ZSTD_selectEncodingType(&nextEntropy->fse.offcode_repeatMode, in ZSTD_entropyCompressSequences_internal()
2211 OffFSELog, prevEntropy->fse.offcodeCTable, in ZSTD_entropyCompressSequences_internal()
2214assert(!(Offtype < set_compressed && nextEntropy->fse.offcode_repeatMode != FSE_repeat_none)); /* … in ZSTD_entropyCompressSequences_internal()
2216 op, (size_t)(oend - op), in ZSTD_entropyCompressSequences_internal()
2220 prevEntropy->fse.offcodeCTable, in ZSTD_entropyCompressSequences_internal()
2221 sizeof(prevEntropy->fse.offcodeCTable), in ZSTD_entropyCompressSequences_internal()
2227 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2233 DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op)); in ZSTD_entropyCompressSequences_internal()
2234 nextEntropy->fse.matchlength_repeatMode = prevEntropy->fse.matchlength_repeatMode; in ZSTD_entropyCompressSequences_internal()
2235 MLtype = ZSTD_selectEncodingType(&nextEntropy->fse.matchlength_repeatMode, in ZSTD_entropyCompressSequences_internal()
2237 MLFSELog, prevEntropy->fse.matchlengthCTable, in ZSTD_entropyCompressSequences_internal()
2240assert(!(MLtype < set_compressed && nextEntropy->fse.matchlength_repeatMode != FSE_repeat_none)); … in ZSTD_entropyCompressSequences_internal()
2242 op, (size_t)(oend - op), in ZSTD_entropyCompressSequences_internal()
2246 prevEntropy->fse.matchlengthCTable, in ZSTD_entropyCompressSequences_internal()
2247 sizeof(prevEntropy->fse.matchlengthCTable), in ZSTD_entropyCompressSequences_internal()
2253 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2259 op, (size_t)(oend - op), in ZSTD_entropyCompressSequences_internal()
2267 assert(op <= oend); in ZSTD_entropyCompressSequences_internal()
2276 if (lastNCount && (op - lastNCount) < 4) { in ZSTD_entropyCompressSequences_internal()
2278 assert(op - lastNCount == 3); in ZSTD_entropyCompressSequences_internal()
2285 DEBUGLOG(5, "compressed block size : %u", (unsigned)(op - ostart)); in ZSTD_entropyCompressSequences_internal()
2286 return (size_t)(op - ostart); in ZSTD_entropyCompressSequences_internal()
2312 { size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, cctxParams->cParams.strategy); in ZSTD_entropyCompressSequences()
2369 assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat)); in ZSTD_selectBlockCompressor()
2371 assert(selectedCompressor != NULL); in ZSTD_selectBlockCompressor()
2378 ZSTD_memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_storeLastLiterals()
2379 seqStorePtr->lit += lastLLSize; in ZSTD_storeLastLiterals()
2384 ssPtr->lit = ssPtr->litStart; in ZSTD_resetSeqStore()
2385 ssPtr->sequences = ssPtr->sequencesStart; in ZSTD_resetSeqStore()
2386 ssPtr->longLengthID = 0; in ZSTD_resetSeqStore()
2393 ZSTD_matchState_t* const ms = &zc->blockState.matchState; in ZSTD_buildSeqStore() local
2395 assert(srcSize <= ZSTD_BLOCKSIZE_MAX); in ZSTD_buildSeqStore()
2396 /* Assert that we have correctly flushed the ctx params into the ms's copy */ in ZSTD_buildSeqStore()
2397 ZSTD_assertEqualCParams(zc->appliedParams.cParams, ms->cParams); in ZSTD_buildSeqStore()
2399 if (zc->appliedParams.cParams.strategy >= ZSTD_btopt) { in ZSTD_buildSeqStore()
2400 ZSTD_ldm_skipRawSeqStoreBytes(&zc->externSeqStore, srcSize); in ZSTD_buildSeqStore()
2402 … ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.minMatch); in ZSTD_buildSeqStore()
2406 ZSTD_resetSeqStore(&(zc->seqStore)); in ZSTD_buildSeqStore()
2408 ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; in ZSTD_buildSeqStore()
2410 ms->opt.literalCompressionMode = zc->appliedParams.literalCompressionMode; in ZSTD_buildSeqStore()
2414 assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit); in ZSTD_buildSeqStore()
2417 { const BYTE* const base = ms->window.base; in ZSTD_buildSeqStore()
2419 const U32 curr = (U32)(istart-base); in ZSTD_buildSeqStore()
2420 … if (sizeof(ptrdiff_t)==8) assert(istart - base < (ptrdiff_t)(U32)(-1)); /* ensure no overflow */ in ZSTD_buildSeqStore()
2421 if (curr > ms->nextToUpdate + 384) in ZSTD_buildSeqStore()
2422 ms->nextToUpdate = curr - MIN(192, (U32)(curr - ms->nextToUpdate - 384)); in ZSTD_buildSeqStore()
2426 { ZSTD_dictMode_e const dictMode = ZSTD_matchState_dictMode(ms); in ZSTD_buildSeqStore()
2430 zc->blockState.nextCBlock->rep[i] = zc->blockState.prevCBlock->rep[i]; in ZSTD_buildSeqStore()
2432 if (zc->externSeqStore.pos < zc->externSeqStore.size) { in ZSTD_buildSeqStore()
2433 assert(!zc->appliedParams.ldmParams.enableLdm); in ZSTD_buildSeqStore()
2436 ZSTD_ldm_blockCompress(&zc->externSeqStore, in ZSTD_buildSeqStore()
2437 ms, &zc->seqStore, in ZSTD_buildSeqStore()
2438 zc->blockState.nextCBlock->rep, in ZSTD_buildSeqStore()
2440 assert(zc->externSeqStore.pos <= zc->externSeqStore.size); in ZSTD_buildSeqStore()
2441 } else if (zc->appliedParams.ldmParams.enableLdm) { in ZSTD_buildSeqStore()
2444 ldmSeqStore.seq = zc->ldmSequences; in ZSTD_buildSeqStore()
2445 ldmSeqStore.capacity = zc->maxNbLdmSequences; in ZSTD_buildSeqStore()
2447 FORWARD_IF_ERROR(ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore, in ZSTD_buildSeqStore()
2448 &zc->appliedParams.ldmParams, in ZSTD_buildSeqStore()
2453 ms, &zc->seqStore, in ZSTD_buildSeqStore()
2454 zc->blockState.nextCBlock->rep, in ZSTD_buildSeqStore()
2456 assert(ldmSeqStore.pos == ldmSeqStore.size); in ZSTD_buildSeqStore()
2458 …ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.… in ZSTD_buildSeqStore()
2459 ms->ldmSeqStore = NULL; in ZSTD_buildSeqStore()
2460 … lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize); in ZSTD_buildSeqStore()
2462 { const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize; in ZSTD_buildSeqStore()
2463 ZSTD_storeLastLiterals(&zc->seqStore, lastLiterals, lastLLSize); in ZSTD_buildSeqStore()
2471 const seqDef* seqStoreSeqs = seqStore->sequencesStart; in ZSTD_copyBlockSequences()
2472 size_t seqStoreSeqSize = seqStore->sequences - seqStoreSeqs; in ZSTD_copyBlockSequences()
2473 size_t seqStoreLiteralsSize = (size_t)(seqStore->lit - seqStore->litStart); in ZSTD_copyBlockSequences()
2477 ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex]; in ZSTD_copyBlockSequences()
2481 assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences); in ZSTD_copyBlockSequences()
2483 assert(zc->seqCollector.maxSequences >= seqStoreSeqSize + 1); in ZSTD_copyBlockSequences()
2484 ZSTD_memcpy(updatedRepcodes.rep, zc->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copyBlockSequences()
2486 U32 rawOffset = seqStoreSeqs[i].offset - ZSTD_REP_NUM; in ZSTD_copyBlockSequences()
2491 if (i == seqStore->longLengthPos) { in ZSTD_copyBlockSequences()
2492 if (seqStore->longLengthID == 1) { in ZSTD_copyBlockSequences()
2494 } else if (seqStore->longLengthID == 2) { in ZSTD_copyBlockSequences()
2503 rawOffset = updatedRepcodes.rep[outSeqs[i].rep - 1]; in ZSTD_copyBlockSequences()
2506 rawOffset = updatedRepcodes.rep[0] - 1; in ZSTD_copyBlockSequences()
2514 so we provide seqStoreSeqs[i].offset - 1 */ in ZSTD_copyBlockSequences()
2516 seqStoreSeqs[i].offset - 1, in ZSTD_copyBlockSequences()
2524 assert(seqStoreLiteralsSize >= literalsRead); in ZSTD_copyBlockSequences()
2525 lastLLSize = seqStoreLiteralsSize - literalsRead; in ZSTD_copyBlockSequences()
2529 zc->seqCollector.seqIndex += seqStoreSeqSize; in ZSTD_copyBlockSequences()
2545 zc->seqCollector = seqCollector; in ZSTD_generateSequences()
2549 return zc->seqCollector.seqIndex; in ZSTD_generateSequences()
2557 if (in != seqsSize - 1) { in ZSTD_mergeBlockDelimiters()
2574 const size_t unrollMask = unrollSize - 1; in ZSTD_isRLE()
2580 if (prefixLength && ZSTD_count(ip+1, ip, ip+prefixLength) != prefixLength-1) { in ZSTD_isRLE()
2599 size_t const nbSeqs = (size_t)(seqStore->sequences - seqStore->sequencesStart); in ZSTD_maybeRLE()
2600 size_t const nbLits = (size_t)(seqStore->lit - seqStore->litStart); in ZSTD_maybeRLE()
2607 ZSTD_compressedBlockState_t* const tmp = zc->blockState.prevCBlock; in ZSTD_confirmRepcodesAndEntropyTables()
2608 zc->blockState.prevCBlock = zc->blockState.nextCBlock; in ZSTD_confirmRepcodesAndEntropyTables()
2609 zc->blockState.nextCBlock = tmp; in ZSTD_confirmRepcodesAndEntropyTables()
2625 (unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, in ZSTD_compressBlock_internal()
2626 (unsigned)zc->blockState.matchState.nextToUpdate); in ZSTD_compressBlock_internal()
2633 if (zc->seqCollector.collectSequences) { in ZSTD_compressBlock_internal()
2640 cSize = ZSTD_entropyCompressSequences(&zc->seqStore, in ZSTD_compressBlock_internal()
2641 &zc->blockState.prevCBlock->entropy, &zc->blockState.nextCBlock->entropy, in ZSTD_compressBlock_internal()
2642 &zc->appliedParams, in ZSTD_compressBlock_internal()
2645 zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressBlock_internal()
2646 zc->bmi2); in ZSTD_compressBlock_internal()
2648 if (zc->seqCollector.collectSequences) { in ZSTD_compressBlock_internal()
2659 !zc->isFirstBlock && in ZSTD_compressBlock_internal()
2675 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressBlock_internal()
2676 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressBlock_internal()
2692 !zc->isFirstBlock && in ZSTD_compressBlock_targetCBlockSize_body()
2693 ZSTD_maybeRLE(&zc->seqStore) && in ZSTD_compressBlock_targetCBlockSize_body()
2719 … size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, zc->appliedParams.cParams.strategy); in ZSTD_compressBlock_targetCBlockSize_body()
2744 …(unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, (unsigned)zc->blockSt… in ZSTD_compressBlock_targetCBlockSize()
2750 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressBlock_targetCBlockSize()
2751 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressBlock_targetCBlockSize()
2756 static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms, in ZSTD_overflowCorrectIfNeeded() argument
2762 if (ZSTD_window_needOverflowCorrection(ms->window, iend)) { in ZSTD_overflowCorrectIfNeeded()
2763 U32 const maxDist = (U32)1 << params->cParams.windowLog; in ZSTD_overflowCorrectIfNeeded()
2764 U32 const cycleLog = ZSTD_cycleLog(params->cParams.chainLog, params->cParams.strategy); in ZSTD_overflowCorrectIfNeeded()
2765 U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip); in ZSTD_overflowCorrectIfNeeded()
2770 ZSTD_reduceIndex(ms, params, correction); in ZSTD_overflowCorrectIfNeeded()
2772 if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; in ZSTD_overflowCorrectIfNeeded()
2773 else ms->nextToUpdate -= correction; in ZSTD_overflowCorrectIfNeeded()
2775 ms->loadedDictEnd = 0; in ZSTD_overflowCorrectIfNeeded()
2776 ms->dictMatchState = NULL; in ZSTD_overflowCorrectIfNeeded()
2792 size_t blockSize = cctx->blockSize; in ZSTD_compress_frameChunk()
2797 U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog; in ZSTD_compress_frameChunk()
2799 assert(cctx->appliedParams.cParams.windowLog <= ZSTD_WINDOWLOG_MAX); in ZSTD_compress_frameChunk()
2802 if (cctx->appliedParams.fParams.checksumFlag && srcSize) in ZSTD_compress_frameChunk()
2803 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compress_frameChunk()
2806 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compress_frameChunk() local
2815 ms, &cctx->workspace, &cctx->appliedParams, ip, ip + blockSize); in ZSTD_compress_frameChunk()
2816 …ZSTD_checkDictValidity(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchSta… in ZSTD_compress_frameChunk()
2819 if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit; in ZSTD_compress_frameChunk()
2822 if (ZSTD_useTargetCBlockSize(&cctx->appliedParams)) { in ZSTD_compress_frameChunk()
2825 assert(cSize > 0); in ZSTD_compress_frameChunk()
2826 assert(cSize <= blockSize + ZSTD_blockHeaderSize); in ZSTD_compress_frameChunk()
2829 op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, in ZSTD_compress_frameChunk()
2847 assert(remaining >= blockSize); in ZSTD_compress_frameChunk()
2848 remaining -= blockSize; in ZSTD_compress_frameChunk()
2850 assert(dstCapacity >= cSize); in ZSTD_compress_frameChunk()
2851 dstCapacity -= cSize; in ZSTD_compress_frameChunk()
2852 cctx->isFirstBlock = 0; in ZSTD_compress_frameChunk()
2857 if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending; in ZSTD_compress_frameChunk()
2858 return (size_t)(op-ostart); in ZSTD_compress_frameChunk()
2865 U32 const dictIDSizeCodeLength = (dictID>0) + (dictID>=256) + (dictID>=65536); /* 0-3 */ in ZSTD_writeFrameHeader()
2866 … U32 const dictIDSizeCode = params->fParams.noDictIDFlag ? 0 : dictIDSizeCodeLength; /* 0-3 */ in ZSTD_writeFrameHeader()
2867 U32 const checksumFlag = params->fParams.checksumFlag>0; in ZSTD_writeFrameHeader()
2868 U32 const windowSize = (U32)1 << params->cParams.windowLog; in ZSTD_writeFrameHeader()
2869 U32 const singleSegment = params->fParams.contentSizeFlag && (windowSize >= pledgedSrcSize); in ZSTD_writeFrameHeader()
2870 … BYTE const windowLogByte = (BYTE)((params->cParams.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN) << 3); in ZSTD_writeFrameHeader()
2871 U32 const fcsCode = params->fParams.contentSizeFlag ? in ZSTD_writeFrameHeader()
2872 …(pledgedSrcSize>=256) + (pledgedSrcSize>=65536+256) + (pledgedSrcSize>=0xFFFFFFFFU) : 0; /* 0-3 */ in ZSTD_writeFrameHeader()
2876 assert(!(params->fParams.contentSizeFlag && pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN)); in ZSTD_writeFrameHeader()
2878 "dst buf is too small to fit worst-case frame header size."); in ZSTD_writeFrameHeader()
2880 !params->fParams.noDictIDFlag, (unsigned)dictID, (unsigned)dictIDSizeCode); in ZSTD_writeFrameHeader()
2881 if (params->format == ZSTD_f_zstd1) { in ZSTD_writeFrameHeader()
2890 assert(0); /* impossible */ in ZSTD_writeFrameHeader()
2900 assert(0); /* impossible */ in ZSTD_writeFrameHeader()
2903 case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break; in ZSTD_writeFrameHeader()
2931 * output an empty Block with end-of-frame mark to complete a frame
2947 RETURN_ERROR_IF(cctx->stage != ZSTDcs_init, stage_wrong, in ZSTD_referenceExternalSequences()
2949 RETURN_ERROR_IF(cctx->appliedParams.ldmParams.enableLdm, in ZSTD_referenceExternalSequences()
2952 cctx->externSeqStore.seq = seq; in ZSTD_referenceExternalSequences()
2953 cctx->externSeqStore.size = nbSeq; in ZSTD_referenceExternalSequences()
2954 cctx->externSeqStore.capacity = nbSeq; in ZSTD_referenceExternalSequences()
2955 cctx->externSeqStore.pos = 0; in ZSTD_referenceExternalSequences()
2956 cctx->externSeqStore.posInSequence = 0; in ZSTD_referenceExternalSequences()
2966 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compressContinue_internal() local
2970 cctx->stage, (unsigned)srcSize); in ZSTD_compressContinue_internal()
2971 RETURN_ERROR_IF(cctx->stage==ZSTDcs_created, stage_wrong, in ZSTD_compressContinue_internal()
2974 if (frame && (cctx->stage==ZSTDcs_init)) { in ZSTD_compressContinue_internal()
2975 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, in ZSTD_compressContinue_internal()
2976 cctx->pledgedSrcSizePlusOne-1, cctx->dictID); in ZSTD_compressContinue_internal()
2978 assert(fhSize <= dstCapacity); in ZSTD_compressContinue_internal()
2979 dstCapacity -= fhSize; in ZSTD_compressContinue_internal()
2981 cctx->stage = ZSTDcs_ongoing; in ZSTD_compressContinue_internal()
2986 if (!ZSTD_window_update(&ms->window, src, srcSize)) { in ZSTD_compressContinue_internal()
2987 ms->nextToUpdate = ms->window.dictLimit; in ZSTD_compressContinue_internal()
2989 if (cctx->appliedParams.ldmParams.enableLdm) { in ZSTD_compressContinue_internal()
2990 ZSTD_window_update(&cctx->ldmState.window, src, srcSize); in ZSTD_compressContinue_internal()
2996 ms, &cctx->workspace, &cctx->appliedParams, in ZSTD_compressContinue_internal()
3000 DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (unsigned)cctx->blockSize); in ZSTD_compressContinue_internal()
3005 cctx->consumedSrcSize += srcSize; in ZSTD_compressContinue_internal()
3006 cctx->producedCSize += (cSize + fhSize); in ZSTD_compressContinue_internal()
3007 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressContinue_internal()
3008 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressContinue_internal()
3009 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1); in ZSTD_compressContinue_internal()
3011 cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne, in ZSTD_compressContinue_internal()
3014 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressContinue_internal()
3015 (unsigned)cctx->consumedSrcSize); in ZSTD_compressContinue_internal()
3032 ZSTD_compressionParameters const cParams = cctx->appliedParams.cParams; in ZSTD_getBlockSize()
3033 assert(!ZSTD_checkCParams(cParams)); in ZSTD_getBlockSize()
3049 static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms, in ZSTD_loadDictionaryContent() argument
3059 ZSTD_window_update(&ms->window, src, srcSize); in ZSTD_loadDictionaryContent()
3060 ms->loadedDictEnd = params->forceWindow ? 0 : (U32)(iend - ms->window.base); in ZSTD_loadDictionaryContent()
3062 if (params->ldmParams.enableLdm && ls != NULL) { in ZSTD_loadDictionaryContent()
3063 ZSTD_window_update(&ls->window, src, srcSize); in ZSTD_loadDictionaryContent()
3064 ls->loadedDictEnd = params->forceWindow ? 0 : (U32)(iend - ls->window.base); in ZSTD_loadDictionaryContent()
3067 /* Assert that we the ms params match the params we're being given */ in ZSTD_loadDictionaryContent()
3068 ZSTD_assertEqualCParams(params->cParams, ms->cParams); in ZSTD_loadDictionaryContent()
3072 while (iend - ip > HASH_READ_SIZE) { in ZSTD_loadDictionaryContent()
3073 size_t const remaining = (size_t)(iend - ip); in ZSTD_loadDictionaryContent()
3077 ZSTD_overflowCorrectIfNeeded(ms, ws, params, ip, ichunk); in ZSTD_loadDictionaryContent()
3079 if (params->ldmParams.enableLdm && ls != NULL) in ZSTD_loadDictionaryContent()
3080 … ZSTD_ldm_fillHashTable(ls, (const BYTE*)src, (const BYTE*)src + srcSize, &params->ldmParams); in ZSTD_loadDictionaryContent()
3082 switch(params->cParams.strategy) in ZSTD_loadDictionaryContent()
3085 ZSTD_fillHashTable(ms, ichunk, dtlm); in ZSTD_loadDictionaryContent()
3088 ZSTD_fillDoubleHashTable(ms, ichunk, dtlm); in ZSTD_loadDictionaryContent()
3094 if (chunk >= HASH_READ_SIZE && ms->dedicatedDictSearch) { in ZSTD_loadDictionaryContent()
3095 assert(chunk == remaining); /* must load everything in one go */ in ZSTD_loadDictionaryContent()
3096 ZSTD_dedicatedDictSearch_lazy_loadDictionary(ms, ichunk-HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
3098 ZSTD_insertAndFindFirstIndex(ms, ichunk-HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
3107 ZSTD_updateTree(ms, ichunk-HASH_READ_SIZE, ichunk); in ZSTD_loadDictionaryContent()
3111 assert(0); /* not possible : not a valid strategy id */ in ZSTD_loadDictionaryContent()
3117 ms->nextToUpdate = (U32)(iend - ms->window.base); in ZSTD_loadDictionaryContent()
3148 bs->entropy.huf.repeatMode = HUF_repeat_check; in ZSTD_loadCEntropy()
3152 …size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, di… in ZSTD_loadCEntropy()
3153 dictEnd-dictPtr, &hasZeroWeights); in ZSTD_loadCEntropy()
3155 /* We only set the loaded table as valid if it contains all non-zero in ZSTD_loadCEntropy()
3158 bs->entropy.huf.repeatMode = HUF_repeat_valid; in ZSTD_loadCEntropy()
3166 …eaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
3171 bs->entropy.fse.offcodeCTable, in ZSTD_loadCEntropy()
3181 …FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
3185 bs->entropy.fse.matchlengthCTable, in ZSTD_loadCEntropy()
3189 …bs->entropy.fse.matchlength_repeatMode = ZSTD_dictNCountRepeat(matchlengthNCount, matchlengthMaxVa… in ZSTD_loadCEntropy()
3195 …ize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
3199 bs->entropy.fse.litlengthCTable, in ZSTD_loadCEntropy()
3203 …bs->entropy.fse.litlength_repeatMode = ZSTD_dictNCountRepeat(litlengthNCount, litlengthMaxValue, M… in ZSTD_loadCEntropy()
3208 bs->rep[0] = MEM_readLE32(dictPtr+0); in ZSTD_loadCEntropy()
3209 bs->rep[1] = MEM_readLE32(dictPtr+4); in ZSTD_loadCEntropy()
3210 bs->rep[2] = MEM_readLE32(dictPtr+8); in ZSTD_loadCEntropy()
3213 { size_t const dictContentSize = (size_t)(dictEnd - dictPtr); in ZSTD_loadCEntropy()
3215 if (dictContentSize <= ((U32)-1) - 128 KB) { in ZSTD_loadCEntropy()
3220 …bs->entropy.fse.offcode_repeatMode = ZSTD_dictNCountRepeat(offcodeNCount, offcodeMaxValue, MIN(off… in ZSTD_loadCEntropy()
3225 RETURN_ERROR_IF(bs->rep[u] == 0, dictionary_corrupted, ""); in ZSTD_loadCEntropy()
3226 RETURN_ERROR_IF(bs->rep[u] > dictContentSize, dictionary_corrupted, ""); in ZSTD_loadCEntropy()
3229 return dictPtr - (const BYTE*)dict; in ZSTD_loadCEntropy()
3234 * https://github.com/facebook/zstd/blob/release/doc/zstd_compression_format.md#dictionary-format
3242 ZSTD_matchState_t* ms, in ZSTD_loadZstdDictionary() argument
3255 assert(dictSize >= 8); in ZSTD_loadZstdDictionary()
3256 assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY); in ZSTD_loadZstdDictionary()
3258 dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr + 4 /* skip magic number */ ); in ZSTD_loadZstdDictionary()
3264 size_t const dictContentSize = (size_t)(dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
3266 ms, NULL, ws, params, dictPtr, dictContentSize, dtlm), ""); in ZSTD_loadZstdDictionary()
3275 ZSTD_matchState_t* ms, in ZSTD_compress_insertDictionary() argument
3294 return ZSTD_loadDictionaryContent(ms, ls, ws, params, dict, dictSize, dtlm); in ZSTD_compress_insertDictionary()
3300 ms, ls, ws, params, dict, dictSize, dtlm); in ZSTD_compress_insertDictionary()
3303 assert(0); /* impossible */ in ZSTD_compress_insertDictionary()
3308 bs, ms, ws, params, dict, dictSize, dtlm, workspace); in ZSTD_compress_insertDictionary()
3324 DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog); in ZSTD_compressBegin_internal()
3326 assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); in ZSTD_compressBegin_internal()
3327 assert(!((dict) && (cdict))); /* either dict or cdict, not both */ in ZSTD_compressBegin_internal()
3329 && (cdict->dictContentSize > 0) in ZSTD_compressBegin_internal()
3331 || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER in ZSTD_compressBegin_internal()
3333 || cdict->compressionLevel == 0) in ZSTD_compressBegin_internal()
3334 && (params->attachDictPref != ZSTD_dictForceLoad) ) { in ZSTD_compressBegin_internal()
3342 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
3343 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent, in ZSTD_compressBegin_internal()
3344 cdict->dictContentSize, cdict->dictContentType, dtlm, in ZSTD_compressBegin_internal()
3345 cctx->entropyWorkspace) in ZSTD_compressBegin_internal()
3347 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
3348 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, dict, dictSize, in ZSTD_compressBegin_internal()
3349 dictContentType, dtlm, cctx->entropyWorkspace); in ZSTD_compressBegin_internal()
3351 assert(dictID <= UINT_MAX); in ZSTD_compressBegin_internal()
3352 cctx->dictID = (U32)dictID; in ZSTD_compressBegin_internal()
3353 cctx->dictContentSize = cdict ? cdict->dictContentSize : dictSize; in ZSTD_compressBegin_internal()
3366 DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params->cParams.windowLog); in ZSTD_compressBegin_advanced_internal()
3368 FORWARD_IF_ERROR( ZSTD_checkCParams(params->cParams) , ""); in ZSTD_compressBegin_advanced_internal()
3418 RETURN_ERROR_IF(cctx->stage == ZSTDcs_created, stage_wrong, "init missing"); in ZSTD_writeEpilogue()
3421 if (cctx->stage == ZSTDcs_init) { in ZSTD_writeEpilogue()
3422 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, 0, 0); in ZSTD_writeEpilogue()
3424 dstCapacity -= fhSize; in ZSTD_writeEpilogue()
3426 cctx->stage = ZSTDcs_ongoing; in ZSTD_writeEpilogue()
3429 if (cctx->stage != ZSTDcs_ending) { in ZSTD_writeEpilogue()
3435 dstCapacity -= ZSTD_blockHeaderSize; in ZSTD_writeEpilogue()
3438 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_writeEpilogue()
3439 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_writeEpilogue()
3446 cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ in ZSTD_writeEpilogue()
3447 return op-ostart; in ZSTD_writeEpilogue()
3465 endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize); in ZSTD_compressEnd()
3467 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressEnd()
3468 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressEnd()
3469 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1); in ZSTD_compressEnd()
3472 cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1, in ZSTD_compressEnd()
3475 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressEnd()
3476 (unsigned)cctx->consumedSrcSize); in ZSTD_compressEnd()
3523 assert(params.fParams.contentSizeFlag == 1); in ZSTD_compress_usingDict()
3536 assert(cctx != NULL); in ZSTD_compressCCtx()
3580 return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict)) in ZSTD_sizeof_CDict()
3581 + ZSTD_cwksp_sizeof(&cdict->workspace); in ZSTD_sizeof_CDict()
3592 assert(!ZSTD_checkCParams(params.cParams)); in ZSTD_initCDict_internal()
3593 cdict->matchState.cParams = params.cParams; in ZSTD_initCDict_internal()
3594 cdict->matchState.dedicatedDictSearch = params.enableDedicatedDictSearch; in ZSTD_initCDict_internal()
3595 if (cdict->matchState.dedicatedDictSearch && dictSize > ZSTD_CHUNKSIZE_MAX) { in ZSTD_initCDict_internal()
3596 cdict->matchState.dedicatedDictSearch = 0; in ZSTD_initCDict_internal()
3599 cdict->dictContent = dictBuffer; in ZSTD_initCDict_internal()
3601 …void *internalBuffer = ZSTD_cwksp_reserve_object(&cdict->workspace, ZSTD_cwksp_align(dictSize, siz… in ZSTD_initCDict_internal()
3603 cdict->dictContent = internalBuffer; in ZSTD_initCDict_internal()
3606 cdict->dictContentSize = dictSize; in ZSTD_initCDict_internal()
3607 cdict->dictContentType = dictContentType; in ZSTD_initCDict_internal()
3609 … cdict->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE); in ZSTD_initCDict_internal()
3612 /* Reset the state to no dictionary */ in ZSTD_initCDict_internal()
3613 ZSTD_reset_compressedBlockState(&cdict->cBlockState); in ZSTD_initCDict_internal()
3615 &cdict->matchState, in ZSTD_initCDict_internal()
3616 &cdict->workspace, in ZSTD_initCDict_internal()
3627 &cdict->cBlockState, &cdict->matchState, NULL, &cdict->workspace, in ZSTD_initCDict_internal()
3628 &params, cdict->dictContent, cdict->dictContentSize, in ZSTD_initCDict_internal()
3629 dictContentType, ZSTD_dtlm_full, cdict->entropyWorkspace); in ZSTD_initCDict_internal()
3631 assert(dictID <= (size_t)(U32)-1); in ZSTD_initCDict_internal()
3632 cdict->dictID = (U32)dictID; in ZSTD_initCDict_internal()
3663 assert(cdict != NULL); in ZSTD_createCDict_advanced_internal()
3664 ZSTD_cwksp_move(&cdict->workspace, &ws); in ZSTD_createCDict_advanced_internal()
3665 cdict->customMem = customMem; in ZSTD_createCDict_advanced_internal()
3666 cdict->compressionLevel = ZSTD_NO_CLEVEL; /* signals advanced API usage */ in ZSTD_createCDict_advanced_internal()
3713 /* Fall back to non-DDSS params */ in ZSTD_createCDict_advanced2()
3743 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel; in ZSTD_createCDict()
3754 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel; in ZSTD_createCDict_byReference()
3761 { ZSTD_customMem const cMem = cdict->customMem; in ZSTD_freeCDict()
3762 int cdictInWorkspace = ZSTD_cwksp_owns_buffer(&cdict->workspace, cdict); in ZSTD_freeCDict()
3763 ZSTD_cwksp_free(&cdict->workspace, cMem); in ZSTD_freeCDict()
3774 * Provided pointer must 8-bytes aligned.
3800 if ((size_t)workspace & 7) return NULL; /* 8-aligned */ in ZSTD_initStaticCDict()
3807 ZSTD_cwksp_move(&cdict->workspace, &ws); in ZSTD_initStaticCDict()
3828 assert(cdict != NULL); in ZSTD_getCParamsFromCDict()
3829 return cdict->matchState.cParams; in ZSTD_getCParamsFromCDict()
3835 * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
3839 return cdict->dictID; in ZSTD_getDictID_fromCDict()
3857 … || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER in ZSTD_compressBegin_usingCDict_advanced()
3859 || cdict->compressionLevel == 0 ) ? in ZSTD_compressBegin_usingCDict_advanced()
3861 : ZSTD_getCParams(cdict->compressionLevel, in ZSTD_compressBegin_usingCDict_advanced()
3863 cdict->dictContentSize); in ZSTD_compressBegin_usingCDict_advanced()
3864 ZSTD_CCtxParams_init_internal(&cctxParams, &params, cdict->compressionLevel); in ZSTD_compressBegin_usingCDict_advanced()
3872 U32 const limitedSrcLog = limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1; in ZSTD_compressBegin_usingCDict_advanced()
3950 return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ; in ZSTD_CStreamOutSize()
3988 assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); in ZSTD_initCStream_internal()
3989 zcs->requestedParams = *params; in ZSTD_initCStream_internal()
3990 assert(!((dict) && (cdict))); /* either dict or cdict, not both */ in ZSTD_initCStream_internal()
4010 zcs->requestedParams.fParams = fParams; in ZSTD_initCStream_usingCDict_advanced()
4042 ZSTD_CCtxParams_setZstdParams(&zcs->requestedParams, &params); in ZSTD_initCStream_advanced()
4084 size_t hintInSize = cctx->inBuffTarget - cctx->inBuffPos; in ZSTD_nextInputSizeHint()
4085 if (hintInSize==0) hintInSize = cctx->blockSize; in ZSTD_nextInputSizeHint()
4091 * non-static, because can be called from zstdmt_compress.c
4098 const char* const istart = (const char*)input->src; in ZSTD_compressStream_generic()
4099 const char* const iend = input->size != 0 ? istart + input->size : istart; in ZSTD_compressStream_generic()
4100 const char* ip = input->pos != 0 ? istart + input->pos : istart; in ZSTD_compressStream_generic()
4101 char* const ostart = (char*)output->dst; in ZSTD_compressStream_generic()
4102 char* const oend = output->size != 0 ? ostart + output->size : ostart; in ZSTD_compressStream_generic()
4103 char* op = output->pos != 0 ? ostart + output->pos : ostart; in ZSTD_compressStream_generic()
4108 if (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
4109 assert(zcs->inBuff != NULL); in ZSTD_compressStream_generic()
4110 assert(zcs->inBuffSize > 0); in ZSTD_compressStream_generic()
4112 if (zcs->appliedParams.outBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
4113 assert(zcs->outBuff != NULL); in ZSTD_compressStream_generic()
4114 assert(zcs->outBuffSize > 0); in ZSTD_compressStream_generic()
4116 assert(output->pos <= output->size); in ZSTD_compressStream_generic()
4117 assert(input->pos <= input->size); in ZSTD_compressStream_generic()
4118 assert((U32)flushMode <= (U32)ZSTD_e_end); in ZSTD_compressStream_generic()
4121 switch(zcs->streamStage) in ZSTD_compressStream_generic()
4128 && ( (size_t)(oend-op) >= ZSTD_compressBound(iend-ip) /* Enough output space */ in ZSTD_compressStream_generic()
4129 …|| zcs->appliedParams.outBufferMode == ZSTD_bm_stable) /* OR we are allowed to return dstSizeTooS… in ZSTD_compressStream_generic()
4130 && (zcs->inBuffPos == 0) ) { in ZSTD_compressStream_generic()
4133 op, oend-op, ip, iend-ip); in ZSTD_compressStream_generic()
4138 zcs->frameEnded = 1; in ZSTD_compressStream_generic()
4143 if (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
4144 size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos; in ZSTD_compressStream_generic()
4146 zcs->inBuff + zcs->inBuffPos, toLoad, in ZSTD_compressStream_generic()
4147 ip, iend-ip); in ZSTD_compressStream_generic()
4148 zcs->inBuffPos += loaded; in ZSTD_compressStream_generic()
4152 && (zcs->inBuffPos < zcs->inBuffTarget) ) { in ZSTD_compressStream_generic()
4157 && (zcs->inBuffPos == zcs->inToCompress) ) { in ZSTD_compressStream_generic()
4164 { int const inputBuffered = (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered); in ZSTD_compressStream_generic()
4167 size_t oSize = oend-op; in ZSTD_compressStream_generic()
4169 ? zcs->inBuffPos - zcs->inToCompress in ZSTD_compressStream_generic()
4170 : MIN((size_t)(iend - ip), zcs->blockSize); in ZSTD_compressStream_generic()
4171 … if (oSize >= ZSTD_compressBound(iSize) || zcs->appliedParams.outBufferMode == ZSTD_bm_stable) in ZSTD_compressStream_generic()
4174 cDst = zcs->outBuff, oSize = zcs->outBuffSize; in ZSTD_compressStream_generic()
4179 zcs->inBuff + zcs->inToCompress, iSize) : in ZSTD_compressStream_generic()
4181 zcs->inBuff + zcs->inToCompress, iSize); in ZSTD_compressStream_generic()
4183 zcs->frameEnded = lastBlock; in ZSTD_compressStream_generic()
4185 zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize; in ZSTD_compressStream_generic()
4186 if (zcs->inBuffTarget > zcs->inBuffSize) in ZSTD_compressStream_generic()
4187 zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize; in ZSTD_compressStream_generic()
4189 (unsigned)zcs->inBuffTarget, (unsigned)zcs->inBuffSize); in ZSTD_compressStream_generic()
4191 assert(zcs->inBuffTarget <= zcs->inBuffSize); in ZSTD_compressStream_generic()
4192 zcs->inToCompress = zcs->inBuffPos; in ZSTD_compressStream_generic()
4195 assert(flushMode == ZSTD_e_end /* Already validated */); in ZSTD_compressStream_generic()
4203 zcs->frameEnded = lastBlock; in ZSTD_compressStream_generic()
4205 assert(ip == iend); in ZSTD_compressStream_generic()
4209 if (zcs->frameEnded) { in ZSTD_compressStream_generic()
4216 zcs->outBuffContentSize = cSize; in ZSTD_compressStream_generic()
4217 zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
4218 zcs->streamStage = zcss_flush; /* pass-through to flush stage */ in ZSTD_compressStream_generic()
4223 assert(zcs->appliedParams.outBufferMode == ZSTD_bm_buffered); in ZSTD_compressStream_generic()
4224 { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; in ZSTD_compressStream_generic()
4225 size_t const flushed = ZSTD_limitCopy(op, (size_t)(oend-op), in ZSTD_compressStream_generic()
4226 zcs->outBuff + zcs->outBuffFlushedSize, toFlush); in ZSTD_compressStream_generic()
4228 (unsigned)toFlush, (unsigned)(oend-op), (unsigned)flushed); in ZSTD_compressStream_generic()
4231 zcs->outBuffFlushedSize += flushed; in ZSTD_compressStream_generic()
4234 assert(op==oend); in ZSTD_compressStream_generic()
4238 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
4239 if (zcs->frameEnded) { in ZSTD_compressStream_generic()
4245 zcs->streamStage = zcss_load; in ZSTD_compressStream_generic()
4250 assert(0); in ZSTD_compressStream_generic()
4254 input->pos = ip - istart; in ZSTD_compressStream_generic()
4255 output->pos = op - ostart; in ZSTD_compressStream_generic()
4256 if (zcs->frameEnded) return 0; in ZSTD_compressStream_generic()
4277 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
4278 cctx->expectedInBuffer = *input; in ZSTD_setBufferExpectations()
4280 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
4281 cctx->expectedOutBufferSize = output->size - output->pos; in ZSTD_setBufferExpectations()
4293 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
4294 ZSTD_inBuffer const expect = cctx->expectedInBuffer; in ZSTD_checkBufferStability()
4295 if (expect.src != input->src || expect.pos != input->pos || expect.size != input->size) in ZSTD_checkBufferStability()
4300 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
4301 size_t const outBufferSize = output->size - output->pos; in ZSTD_checkBufferStability()
4302 if (cctx->expectedOutBufferSize != outBufferSize) in ZSTD_checkBufferStability()
4311 ZSTD_CCtx_params params = cctx->requestedParams; in ZSTD_CCtx_init_compressStream2()
4312 ZSTD_prefixDict const prefixDict = cctx->prefixDict; in ZSTD_CCtx_init_compressStream2()
4314 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */ in ZSTD_CCtx_init_compressStream2()
4315 assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */ in ZSTD_CCtx_init_compressStream2()
4316 if (cctx->cdict) in ZSTD_CCtx_init_compressStream2()
4317 …params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of co… in ZSTD_CCtx_init_compressStream2()
4319 … if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = inSize + 1; /* auto-fix pledgedSrcSize */ in ZSTD_CCtx_init_compressStream2()
4323 : (cctx->cdict ? cctx->cdict->dictContentSize : 0); in ZSTD_CCtx_init_compressStream2()
4324 …STD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, &params, cctx->pledgedSrcSizePlusOne… in ZSTD_CCtx_init_compressStream2()
4326 &params, cctx->pledgedSrcSizePlusOne-1, in ZSTD_CCtx_init_compressStream2()
4336 { U64 const pledgedSrcSize = cctx->pledgedSrcSizePlusOne - 1; in ZSTD_CCtx_init_compressStream2()
4337 assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); in ZSTD_CCtx_init_compressStream2()
4340 cctx->cdict, in ZSTD_CCtx_init_compressStream2()
4343 assert(cctx->appliedParams.nbWorkers == 0); in ZSTD_CCtx_init_compressStream2()
4344 cctx->inToCompress = 0; in ZSTD_CCtx_init_compressStream2()
4345 cctx->inBuffPos = 0; in ZSTD_CCtx_init_compressStream2()
4346 if (cctx->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_CCtx_init_compressStream2()
4348 * it would require to add a 3-bytes null block to end frame in ZSTD_CCtx_init_compressStream2()
4350 cctx->inBuffTarget = cctx->blockSize + (cctx->blockSize == pledgedSrcSize); in ZSTD_CCtx_init_compressStream2()
4352 cctx->inBuffTarget = 0; in ZSTD_CCtx_init_compressStream2()
4354 cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0; in ZSTD_CCtx_init_compressStream2()
4355 cctx->streamStage = zcss_load; in ZSTD_CCtx_init_compressStream2()
4356 cctx->frameEnded = 0; in ZSTD_CCtx_init_compressStream2()
4368 RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer"); in ZSTD_compressStream2()
4369 RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer"); in ZSTD_compressStream2()
4371 assert(cctx != NULL); in ZSTD_compressStream2()
4374 if (cctx->streamStage == zcss_init) { in ZSTD_compressStream2()
4375 …FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size), "CompressStream2 initia… in ZSTD_compressStream2()
4385 return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */ in ZSTD_compressStream2()
4407 ZSTD_bufferMode_e const originalInBufferMode = cctx->requestedParams.inBufferMode; in ZSTD_compress2()
4408 ZSTD_bufferMode_e const originalOutBufferMode = cctx->requestedParams.outBufferMode; in ZSTD_compress2()
4412 cctx->requestedParams.inBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
4413 cctx->requestedParams.outBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
4420 /* Reset to the original values. */ in ZSTD_compress2()
4421 cctx->requestedParams.inBufferMode = originalInBufferMode; in ZSTD_compress2()
4422 cctx->requestedParams.outBufferMode = originalOutBufferMode; in ZSTD_compress2()
4425 assert(oPos == dstCapacity); in ZSTD_compress2()
4428 assert(iPos == srcSize); /* all input is expected consumed */ in ZSTD_compress2()
4463 repCode = 2 - ll0; in ZSTD_finalizeOffCode()
4465 repCode = 3 - ll0; in ZSTD_finalizeOffCode()
4466 } else if (ll0 && rawOffset == rep[0] - 1) { in ZSTD_finalizeOffCode()
4471 offCode = repCode - 1; in ZSTD_finalizeOffCode()
4482 U32 idx = seqPos->idx; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4492 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4493 dictSize = (U32)cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4494 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4495 dictSize = (U32)cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4499 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4508 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4509 seqPos->posInSrc += litLength + matchLength; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4510 FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4511 cctx->appliedParams.cParams.windowLog, dictSize, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4512 cctx->appliedParams.cParams.minMatch), in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4515 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4517 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4520 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4524 ZSTD_storeLastLiterals(&cctx->seqStore, ip, inSeqs[idx].litLength); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4526 seqPos->posInSrc += inSeqs[idx].litLength; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4529 seqPos->idx = idx+1; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4533 /* Returns the number of bytes to move the current read position back by. Only non-zero
4547 U32 idx = seqPos->idx; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4548 U32 startPosInSequence = seqPos->posInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4549 U32 endPosInSequence = seqPos->posInSequence + (U32)blockSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4561 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4562 dictSize = cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4563 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4564 dictSize = cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4570 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4580 startPosInSequence -= litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4582 matchLength -= startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4584 litLength -= startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4587 endPosInSequence -= currSeq.litLength + currSeq.matchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4594 … currSeq.litLength + currSeq.matchLength - endPosInSequence, idx, endPosInSequence); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4597 litLength = startPosInSequence >= litLength ? 0 : litLength - startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4598 firstHalfMatchLength = endPosInSequence - startPosInSequence - litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4599 … if (matchLength > blockSize && firstHalfMatchLength >= cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4601 … U32 secondHalfMatchLength = currSeq.matchLength + currSeq.litLength - endPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4602 if (secondHalfMatchLength < cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4604 … endPosInSequence -= cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4605 … bytesAdjustment = cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4606 firstHalfMatchLength -= bytesAdjustment; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4609 … /* Flag that we split the last match - after storing the sequence, exit the loop, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4618 bytesAdjustment = endPosInSequence - currSeq.litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4633 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4634 seqPos->posInSrc += litLength + matchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4635 FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4636 cctx->appliedParams.cParams.windowLog, dictSize, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4637 cctx->appliedParams.cParams.minMatch), in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4641 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4643 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4647assert(idx == inSeqsSize || endPosInSequence <= inSeqs[idx].litLength + inSeqs[idx].matchLength); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4648 seqPos->idx = idx; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4649 seqPos->posInSequence = endPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4650 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4652 iend -= bytesAdjustment; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4655 U32 lastLLSize = (U32)(iend - ip); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4656 assert(ip <= iend); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4658 ZSTD_storeLastLiterals(&cctx->seqStore, ip, lastLLSize); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4659 seqPos->posInSrc += lastLLSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4670 assert(ZSTD_cParam_withinBounds(ZSTD_c_blockDelimiters, mode)); in ZSTD_selectSequenceCopier()
4676 assert(sequenceCopier != NULL); in ZSTD_selectSequenceCopier()
4680 /* Compress, block-by-block, all of the sequences given.
4697 …ZSTD_sequenceCopier sequenceCopier = ZSTD_selectSequenceCopier(cctx->appliedParams.blockDelimiters… in ZSTD_compressSequences_internal()
4706 dstCapacity -= ZSTD_blockHeaderSize; in ZSTD_compressSequences_internal()
4713 lastBlock = remaining <= cctx->blockSize; in ZSTD_compressSequences_internal()
4714 blockSize = lastBlock ? (U32)remaining : (U32)cctx->blockSize; in ZSTD_compressSequences_internal()
4715 ZSTD_resetSeqStore(&cctx->seqStore); in ZSTD_compressSequences_internal()
4720 blockSize -= additionalByteAdjustment; in ZSTD_compressSequences_internal()
4730 remaining -= blockSize; in ZSTD_compressSequences_internal()
4731 dstCapacity -= cBlockSize; in ZSTD_compressSequences_internal()
4735 compressedSeqsSize = ZSTD_entropyCompressSequences(&cctx->seqStore, in ZSTD_compressSequences_internal()
4736 … &cctx->blockState.prevCBlock->entropy, &cctx->blockState.nextCBlock->entropy, in ZSTD_compressSequences_internal()
4737 &cctx->appliedParams, in ZSTD_compressSequences_internal()
4738 … op + ZSTD_blockHeaderSize /* Leave space for block header */, dstCapacity - ZSTD_blockHeaderSize, in ZSTD_compressSequences_internal()
4740 … cctx->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressSequences_internal()
4741 cctx->bmi2); in ZSTD_compressSequences_internal()
4745 if (!cctx->isFirstBlock && in ZSTD_compressSequences_internal()
4746 ZSTD_maybeRLE(&cctx->seqStore) && in ZSTD_compressSequences_internal()
4768 if (cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressSequences_internal()
4769 cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressSequences_internal()
4786 remaining -= blockSize; in ZSTD_compressSequences_internal()
4787 dstCapacity -= cBlockSize; in ZSTD_compressSequences_internal()
4788 cctx->isFirstBlock = 0; in ZSTD_compressSequences_internal()
4805 assert(cctx != NULL); in ZSTD_compressSequences()
4808 …frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->appliedParams, srcSize, cctx->dict… in ZSTD_compressSequences()
4810 dstCapacity -= frameHeaderSize; in ZSTD_compressSequences()
4812 if (cctx->appliedParams.fParams.checksumFlag && srcSize) { in ZSTD_compressSequences()
4813 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compressSequences()
4822 dstCapacity -= compressedBlocksSize; in ZSTD_compressSequences()
4824 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_compressSequences()
4825 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_compressSequences()
4852 if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */ in ZSTD_endStream()
4854 { size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE; in ZSTD_endStream()
4855 …size_t const checksumSize = (size_t)(zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag… in ZSTD_endStream()
4863 /*-===== Pre-defined compression levels =====-*/
4867 int ZSTD_minCLevel(void) { return (int)-ZSTD_TARGETLENGTH_MAX; } in ZSTD_minCLevel()
4870 { /* "default" - for any srcSize > 256 KB */
5000 return (cParams->strategy >= ZSTD_greedy) in ZSTD_dedicatedDictSearch_isSupported()
5001 && (cParams->strategy <= ZSTD_lazy2) in ZSTD_dedicatedDictSearch_isSupported()
5002 && (cParams->hashLog >= cParams->chainLog) in ZSTD_dedicatedDictSearch_isSupported()
5003 && (cParams->chainLog <= 24); in ZSTD_dedicatedDictSearch_isSupported()
5013 switch (cParams->strategy) { in ZSTD_dedicatedDictSearch_revertCParams()
5020 cParams->hashLog -= ZSTD_LAZY_DDSS_BUCKET_LOG; in ZSTD_dedicatedDictSearch_revertCParams()
5041 assert(0); in ZSTD_getCParamRowSize()
5072 cp.targetLength = (unsigned)(-clampedCompressionLevel); in ZSTD_getCParams_internal()