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 * Maximum size of the hash table dedicated to find 3-bytes matches,
54 /*-*************************************
59 * full-block strategy.
69 /*-*************************************
84 … * row-based matchfinder. Unless the cdict is reloaded, we will use
96 assert(cctx != NULL); in ZSTD_initCCtx()
98 cctx->customMem = memManager; in ZSTD_initCCtx()
99 cctx->bmi2 = ZSTD_cpuSupportsBmi2(); in ZSTD_initCCtx()
101 assert(!ZSTD_isError(err)); in ZSTD_initCCtx()
109 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN==(0ULL - 1)); in ZSTD_createCCtx_advanced()
123 if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */ in ZSTD_initStaticCCtx()
130 ZSTD_cwksp_move(&cctx->workspace, &ws); in ZSTD_initStaticCCtx()
131 cctx->staticSize = workspaceSize; in ZSTD_initStaticCCtx()
134 …if (!ZSTD_cwksp_check_available(&cctx->workspace, ENTROPY_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compres… in ZSTD_initStaticCCtx()
135 …cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
136 …cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
137 …cctx->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cctx->workspace, ENTROPY_WORKSPACE_SIZE); in ZSTD_initStaticCCtx()
138 cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); in ZSTD_initStaticCCtx()
147 ZSTD_customFree(cctx->localDict.dictBuffer, cctx->customMem); in ZSTD_clearAllDicts()
148 ZSTD_freeCDict(cctx->localDict.cdict); in ZSTD_clearAllDicts()
149 ZSTD_memset(&cctx->localDict, 0, sizeof(cctx->localDict)); in ZSTD_clearAllDicts()
150 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); in ZSTD_clearAllDicts()
151 cctx->cdict = NULL; in ZSTD_clearAllDicts()
163 assert(cctx != NULL); in ZSTD_freeCCtxContent()
164 assert(cctx->staticSize == 0); in ZSTD_freeCCtxContent()
166 ZSTD_cwksp_free(&cctx->workspace, cctx->customMem); in ZSTD_freeCCtxContent()
172 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_freeCCtx()
175 int cctxInWorkspace = ZSTD_cwksp_owns_buffer(&cctx->workspace, cctx); in ZSTD_freeCCtx()
178 ZSTD_customFree(cctx, cctx->customMem); in ZSTD_freeCCtx()
196 return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx)) in ZSTD_sizeof_CCtx()
197 + ZSTD_cwksp_sizeof(&cctx->workspace) in ZSTD_sizeof_CCtx()
198 + ZSTD_sizeof_localDict(cctx->localDict) in ZSTD_sizeof_CCtx()
208 const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); } in ZSTD_getSeqStore()
219 assert(mode != ZSTD_ps_auto); in ZSTD_rowMatchFinderUsed()
233 if (!ZSTD_rowMatchFinderSupported(cParams->strategy)) return mode; in ZSTD_resolveRowMatchFinderMode()
235 if (cParams->windowLog > 14) mode = ZSTD_ps_enable; in ZSTD_resolveRowMatchFinderMode()
237 if (cParams->windowLog > 17) mode = ZSTD_ps_enable; in ZSTD_resolveRowMatchFinderMode()
246 …return (cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 17) ? ZSTD_ps_enable : ZSTD_ps_di… in ZSTD_resolveBlockSplitterMode()
253 assert(useRowMatchFinder != ZSTD_ps_auto); in ZSTD_allocateChainTable()
255 …* We do not allocate a chaintable if we are using ZSTD_fast, or are using the row-based matchfinde… in ZSTD_allocateChainTable()
267 …return (cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 27) ? ZSTD_ps_enable : ZSTD_ps_di… in ZSTD_resolveEnableLdm()
282 assert(cctxParams.ldmParams.hashLog >= cctxParams.ldmParams.bucketSizeLog); in ZSTD_makeCCtxParamsFromCParams()
283 assert(cctxParams.ldmParams.hashRateLog < 32); in ZSTD_makeCCtxParamsFromCParams()
287 assert(!ZSTD_checkCParams(cParams)); in ZSTD_makeCCtxParamsFromCParams()
300 params->customMem = customMem; in ZSTD_createCCtxParams_advanced()
312 ZSTD_customFree(params, params->customMem); in ZSTD_freeCCtxParams()
324 cctxParams->compressionLevel = compressionLevel; in ZSTD_CCtxParams_init()
325 cctxParams->fParams.contentSizeFlag = 1; in ZSTD_CCtxParams_init()
337 assert(!ZSTD_checkCParams(params->cParams)); in ZSTD_CCtxParams_init_internal()
339 cctxParams->cParams = params->cParams; in ZSTD_CCtxParams_init_internal()
340 cctxParams->fParams = params->fParams; in ZSTD_CCtxParams_init_internal()
344 cctxParams->compressionLevel = compressionLevel; in ZSTD_CCtxParams_init_internal()
345 …cctxParams->useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(cctxParams->useRowMatchFinder, &par… in ZSTD_CCtxParams_init_internal()
346 …cctxParams->useBlockSplitter = ZSTD_resolveBlockSplitterMode(cctxParams->useBlockSplitter, ¶ms… in ZSTD_CCtxParams_init_internal()
347 …cctxParams->ldmParams.enableLdm = ZSTD_resolveEnableLdm(cctxParams->ldmParams.enableLdm, ¶ms->… in ZSTD_CCtxParams_init_internal()
349 … cctxParams->useRowMatchFinder, cctxParams->useBlockSplitter, cctxParams->ldmParams.enableLdm); in ZSTD_CCtxParams_init_internal()
367 assert(!ZSTD_checkCParams(params->cParams)); in ZSTD_CCtxParams_setZstdParams()
368 cctxParams->cParams = params->cParams; in ZSTD_CCtxParams_setZstdParams()
369 cctxParams->fParams = params->fParams; in ZSTD_CCtxParams_setZstdParams()
373 cctxParams->compressionLevel = ZSTD_NO_CLEVEL; in ZSTD_CCtxParams_setZstdParams()
624 if (cctx->streamStage != zcss_init) { in ZSTD_CCtx_setParameter()
626 cctx->cParamsChanged = 1; in ZSTD_CCtx_setParameter()
634 RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported, in ZSTD_CCtx_setParameter()
675 return ZSTD_CCtxParams_setParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_setParameter()
686 CCtxParams->format = (ZSTD_format_e)value; in ZSTD_CCtxParams_setParameter()
687 return (size_t)CCtxParams->format; in ZSTD_CCtxParams_setParameter()
692 CCtxParams->compressionLevel = ZSTD_CLEVEL_DEFAULT; /* 0 == default */ in ZSTD_CCtxParams_setParameter()
694 CCtxParams->compressionLevel = value; in ZSTD_CCtxParams_setParameter()
695 if (CCtxParams->compressionLevel >= 0) return (size_t)CCtxParams->compressionLevel; in ZSTD_CCtxParams_setParameter()
702 CCtxParams->cParams.windowLog = (U32)value; in ZSTD_CCtxParams_setParameter()
703 return CCtxParams->cParams.windowLog; in ZSTD_CCtxParams_setParameter()
708 CCtxParams->cParams.hashLog = (U32)value; in ZSTD_CCtxParams_setParameter()
709 return CCtxParams->cParams.hashLog; in ZSTD_CCtxParams_setParameter()
714 CCtxParams->cParams.chainLog = (U32)value; in ZSTD_CCtxParams_setParameter()
715 return CCtxParams->cParams.chainLog; in ZSTD_CCtxParams_setParameter()
720 CCtxParams->cParams.searchLog = (U32)value; in ZSTD_CCtxParams_setParameter()
726 CCtxParams->cParams.minMatch = value; in ZSTD_CCtxParams_setParameter()
727 return CCtxParams->cParams.minMatch; in ZSTD_CCtxParams_setParameter()
731 CCtxParams->cParams.targetLength = value; in ZSTD_CCtxParams_setParameter()
732 return CCtxParams->cParams.targetLength; in ZSTD_CCtxParams_setParameter()
737 CCtxParams->cParams.strategy = (ZSTD_strategy)value; in ZSTD_CCtxParams_setParameter()
738 return (size_t)CCtxParams->cParams.strategy; in ZSTD_CCtxParams_setParameter()
743 CCtxParams->fParams.contentSizeFlag = value != 0; in ZSTD_CCtxParams_setParameter()
744 return CCtxParams->fParams.contentSizeFlag; in ZSTD_CCtxParams_setParameter()
747 /* A 32-bits content checksum will be calculated and written at end of frame (default:0) */ in ZSTD_CCtxParams_setParameter()
748 CCtxParams->fParams.checksumFlag = value != 0; in ZSTD_CCtxParams_setParameter()
749 return CCtxParams->fParams.checksumFlag; in ZSTD_CCtxParams_setParameter()
753 CCtxParams->fParams.noDictIDFlag = !value; in ZSTD_CCtxParams_setParameter()
754 return !CCtxParams->fParams.noDictIDFlag; in ZSTD_CCtxParams_setParameter()
757 CCtxParams->forceWindow = (value != 0); in ZSTD_CCtxParams_setParameter()
758 return CCtxParams->forceWindow; in ZSTD_CCtxParams_setParameter()
763 CCtxParams->attachDictPref = pref; in ZSTD_CCtxParams_setParameter()
764 return CCtxParams->attachDictPref; in ZSTD_CCtxParams_setParameter()
770 CCtxParams->literalCompressionMode = lcm; in ZSTD_CCtxParams_setParameter()
771 return CCtxParams->literalCompressionMode; in ZSTD_CCtxParams_setParameter()
791 CCtxParams->enableDedicatedDictSearch = (value!=0); in ZSTD_CCtxParams_setParameter()
792 return CCtxParams->enableDedicatedDictSearch; in ZSTD_CCtxParams_setParameter()
795 CCtxParams->ldmParams.enableLdm = (ZSTD_paramSwitch_e)value; in ZSTD_CCtxParams_setParameter()
796 return CCtxParams->ldmParams.enableLdm; in ZSTD_CCtxParams_setParameter()
801 CCtxParams->ldmParams.hashLog = value; in ZSTD_CCtxParams_setParameter()
802 return CCtxParams->ldmParams.hashLog; in ZSTD_CCtxParams_setParameter()
807 CCtxParams->ldmParams.minMatchLength = value; in ZSTD_CCtxParams_setParameter()
808 return CCtxParams->ldmParams.minMatchLength; in ZSTD_CCtxParams_setParameter()
813 CCtxParams->ldmParams.bucketSizeLog = value; in ZSTD_CCtxParams_setParameter()
814 return CCtxParams->ldmParams.bucketSizeLog; in ZSTD_CCtxParams_setParameter()
819 CCtxParams->ldmParams.hashRateLog = value; in ZSTD_CCtxParams_setParameter()
820 return CCtxParams->ldmParams.hashRateLog; in ZSTD_CCtxParams_setParameter()
825 CCtxParams->targetCBlockSize = value; in ZSTD_CCtxParams_setParameter()
826 return CCtxParams->targetCBlockSize; in ZSTD_CCtxParams_setParameter()
831 CCtxParams->srcSizeHint = value; in ZSTD_CCtxParams_setParameter()
832 return CCtxParams->srcSizeHint; in ZSTD_CCtxParams_setParameter()
836 CCtxParams->inBufferMode = (ZSTD_bufferMode_e)value; in ZSTD_CCtxParams_setParameter()
837 return CCtxParams->inBufferMode; in ZSTD_CCtxParams_setParameter()
841 CCtxParams->outBufferMode = (ZSTD_bufferMode_e)value; in ZSTD_CCtxParams_setParameter()
842 return CCtxParams->outBufferMode; in ZSTD_CCtxParams_setParameter()
846 CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value; in ZSTD_CCtxParams_setParameter()
847 return CCtxParams->blockDelimiters; in ZSTD_CCtxParams_setParameter()
851 CCtxParams->validateSequences = value; in ZSTD_CCtxParams_setParameter()
852 return CCtxParams->validateSequences; in ZSTD_CCtxParams_setParameter()
856 CCtxParams->useBlockSplitter = (ZSTD_paramSwitch_e)value; in ZSTD_CCtxParams_setParameter()
857 return CCtxParams->useBlockSplitter; in ZSTD_CCtxParams_setParameter()
861 CCtxParams->useRowMatchFinder = (ZSTD_paramSwitch_e)value; in ZSTD_CCtxParams_setParameter()
862 return CCtxParams->useRowMatchFinder; in ZSTD_CCtxParams_setParameter()
866 CCtxParams->deterministicRefPrefix = !!value; in ZSTD_CCtxParams_setParameter()
867 return CCtxParams->deterministicRefPrefix; in ZSTD_CCtxParams_setParameter()
875 return ZSTD_CCtxParams_getParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_getParameter()
884 *value = CCtxParams->format; in ZSTD_CCtxParams_getParameter()
887 *value = CCtxParams->compressionLevel; in ZSTD_CCtxParams_getParameter()
890 *value = (int)CCtxParams->cParams.windowLog; in ZSTD_CCtxParams_getParameter()
893 *value = (int)CCtxParams->cParams.hashLog; in ZSTD_CCtxParams_getParameter()
896 *value = (int)CCtxParams->cParams.chainLog; in ZSTD_CCtxParams_getParameter()
899 *value = CCtxParams->cParams.searchLog; in ZSTD_CCtxParams_getParameter()
902 *value = CCtxParams->cParams.minMatch; in ZSTD_CCtxParams_getParameter()
905 *value = CCtxParams->cParams.targetLength; in ZSTD_CCtxParams_getParameter()
908 *value = (unsigned)CCtxParams->cParams.strategy; in ZSTD_CCtxParams_getParameter()
911 *value = CCtxParams->fParams.contentSizeFlag; in ZSTD_CCtxParams_getParameter()
914 *value = CCtxParams->fParams.checksumFlag; in ZSTD_CCtxParams_getParameter()
917 *value = !CCtxParams->fParams.noDictIDFlag; in ZSTD_CCtxParams_getParameter()
920 *value = CCtxParams->forceWindow; in ZSTD_CCtxParams_getParameter()
923 *value = CCtxParams->attachDictPref; in ZSTD_CCtxParams_getParameter()
926 *value = CCtxParams->literalCompressionMode; in ZSTD_CCtxParams_getParameter()
929 assert(CCtxParams->nbWorkers == 0); in ZSTD_CCtxParams_getParameter()
930 *value = CCtxParams->nbWorkers; in ZSTD_CCtxParams_getParameter()
939 *value = CCtxParams->enableDedicatedDictSearch; in ZSTD_CCtxParams_getParameter()
942 *value = CCtxParams->ldmParams.enableLdm; in ZSTD_CCtxParams_getParameter()
945 *value = CCtxParams->ldmParams.hashLog; in ZSTD_CCtxParams_getParameter()
948 *value = CCtxParams->ldmParams.minMatchLength; in ZSTD_CCtxParams_getParameter()
951 *value = CCtxParams->ldmParams.bucketSizeLog; in ZSTD_CCtxParams_getParameter()
954 *value = CCtxParams->ldmParams.hashRateLog; in ZSTD_CCtxParams_getParameter()
957 *value = (int)CCtxParams->targetCBlockSize; in ZSTD_CCtxParams_getParameter()
960 *value = (int)CCtxParams->srcSizeHint; in ZSTD_CCtxParams_getParameter()
963 *value = (int)CCtxParams->inBufferMode; in ZSTD_CCtxParams_getParameter()
966 *value = (int)CCtxParams->outBufferMode; in ZSTD_CCtxParams_getParameter()
969 *value = (int)CCtxParams->blockDelimiters; in ZSTD_CCtxParams_getParameter()
972 *value = (int)CCtxParams->validateSequences; in ZSTD_CCtxParams_getParameter()
975 *value = (int)CCtxParams->useBlockSplitter; in ZSTD_CCtxParams_getParameter()
978 *value = (int)CCtxParams->useRowMatchFinder; in ZSTD_CCtxParams_getParameter()
981 *value = (int)CCtxParams->deterministicRefPrefix; in ZSTD_CCtxParams_getParameter()
991 * If ZSTDMT is enabled, parameters are pushed to cctx->mtctx.
999 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
1001 RETURN_ERROR_IF(cctx->cdict, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
1005 cctx->requestedParams = *params; in ZSTD_CCtx_setParametersUsingCCtxParams()
1012 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setPledgedSrcSize()
1014 cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1; in ZSTD_CCtx_setPledgedSrcSize()
1033 ZSTD_localDict* const dl = &cctx->localDict; in ZSTD_initLocalDict()
1034 if (dl->dict == NULL) { in ZSTD_initLocalDict()
1036 assert(dl->dictBuffer == NULL); in ZSTD_initLocalDict()
1037 assert(dl->cdict == NULL); in ZSTD_initLocalDict()
1038 assert(dl->dictSize == 0); in ZSTD_initLocalDict()
1041 if (dl->cdict != NULL) { in ZSTD_initLocalDict()
1042 assert(cctx->cdict == dl->cdict); in ZSTD_initLocalDict()
1046 assert(dl->dictSize > 0); in ZSTD_initLocalDict()
1047 assert(cctx->cdict == NULL); in ZSTD_initLocalDict()
1048 assert(cctx->prefixDict.dict == NULL); in ZSTD_initLocalDict()
1050 dl->cdict = ZSTD_createCDict_advanced2( in ZSTD_initLocalDict()
1051 dl->dict, in ZSTD_initLocalDict()
1052 dl->dictSize, in ZSTD_initLocalDict()
1054 dl->dictContentType, in ZSTD_initLocalDict()
1055 &cctx->requestedParams, in ZSTD_initLocalDict()
1056 cctx->customMem); in ZSTD_initLocalDict()
1057 RETURN_ERROR_IF(!dl->cdict, memory_allocation, "ZSTD_createCDict_advanced failed"); in ZSTD_initLocalDict()
1058 cctx->cdict = dl->cdict; in ZSTD_initLocalDict()
1066 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_loadDictionary_advanced()
1073 cctx->localDict.dict = dict; in ZSTD_CCtx_loadDictionary_advanced()
1076 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_CCtx_loadDictionary_advanced()
1078 dictBuffer = ZSTD_customMalloc(dictSize, cctx->customMem); in ZSTD_CCtx_loadDictionary_advanced()
1081 cctx->localDict.dictBuffer = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
1082 cctx->localDict.dict = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
1084 cctx->localDict.dictSize = dictSize; in ZSTD_CCtx_loadDictionary_advanced()
1085 cctx->localDict.dictContentType = dictContentType; in ZSTD_CCtx_loadDictionary_advanced()
1105 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refCDict()
1109 cctx->cdict = cdict; in ZSTD_CCtx_refCDict()
1115 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refThreadPool()
1117 cctx->pool = pool; in ZSTD_CCtx_refThreadPool()
1129 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refPrefix_advanced()
1133 cctx->prefixDict.dict = prefix; in ZSTD_CCtx_refPrefix_advanced()
1134 cctx->prefixDict.dictSize = prefixSize; in ZSTD_CCtx_refPrefix_advanced()
1135 cctx->prefixDict.dictContentType = dictContentType; in ZSTD_CCtx_refPrefix_advanced()
1142 size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset) in ZSTD_CCtx_reset() argument
1144 if ( (reset == ZSTD_reset_session_only) in ZSTD_CCtx_reset()
1145 || (reset == ZSTD_reset_session_and_parameters) ) { in ZSTD_CCtx_reset()
1146 cctx->streamStage = zcss_init; in ZSTD_CCtx_reset()
1147 cctx->pledgedSrcSizePlusOne = 0; in ZSTD_CCtx_reset()
1149 if ( (reset == ZSTD_reset_parameters) in ZSTD_CCtx_reset()
1150 || (reset == ZSTD_reset_session_and_parameters) ) { in ZSTD_CCtx_reset()
1151 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_reset()
1152 "Can't reset parameters only when not in init stage."); in ZSTD_CCtx_reset()
1154 return ZSTD_CCtxParams_reset(&cctx->requestedParams); in ZSTD_CCtx_reset()
1202 return hashLog - btScale; in ZSTD_cycleLog()
1220 assert(windowLog <= ZSTD_WINDOWLOG_MAX); in ZSTD_dictAndWindowLog()
1221 assert(srcSize != ZSTD_CONTENTSIZE_UNKNOWN); /* Handled in ZSTD_adjustCParams_internal() */ in ZSTD_dictAndWindowLog()
1234 return ZSTD_highbit32((U32)dictAndWindowSize - 1) + 1; in ZSTD_dictAndWindowLog()
1253 const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1); in ZSTD_adjustCParams_internal()
1254 assert(ZSTD_checkCParams(cPar)==0); in ZSTD_adjustCParams_internal()
1279 assert(0); in ZSTD_adjustCParams_internal()
1289 ZSTD_highbit32(tSize-1) + 1; in ZSTD_adjustCParams_internal()
1297 cPar.chainLog -= (cycleLog - dictAndWindowLog); in ZSTD_adjustCParams_internal()
1323 if (overrides->windowLog) cParams->windowLog = overrides->windowLog; in ZSTD_overrideCParams()
1324 if (overrides->hashLog) cParams->hashLog = overrides->hashLog; in ZSTD_overrideCParams()
1325 if (overrides->chainLog) cParams->chainLog = overrides->chainLog; in ZSTD_overrideCParams()
1326 if (overrides->searchLog) cParams->searchLog = overrides->searchLog; in ZSTD_overrideCParams()
1327 if (overrides->minMatch) cParams->minMatch = overrides->minMatch; in ZSTD_overrideCParams()
1328 if (overrides->targetLength) cParams->targetLength = overrides->targetLength; in ZSTD_overrideCParams()
1329 if (overrides->strategy) cParams->strategy = overrides->strategy; in ZSTD_overrideCParams()
1336 if (srcSizeHint == ZSTD_CONTENTSIZE_UNKNOWN && CCtxParams->srcSizeHint > 0) { in ZSTD_getCParamsFromCCtxParams()
1337 srcSizeHint = CCtxParams->srcSizeHint; in ZSTD_getCParamsFromCCtxParams()
1339 cParams = ZSTD_getCParams_internal(CCtxParams->compressionLevel, srcSizeHint, dictSize, mode); in ZSTD_getCParamsFromCCtxParams()
1340 …if (CCtxParams->ldmParams.enableLdm == ZSTD_ps_enable) cParams.windowLog = ZSTD_LDM_DEFAULT_WINDOW… in ZSTD_getCParamsFromCCtxParams()
1341 ZSTD_overrideCParams(&cParams, &CCtxParams->cParams); in ZSTD_getCParamsFromCCtxParams()
1342 assert(!ZSTD_checkCParams(cParams)); in ZSTD_getCParamsFromCCtxParams()
1353 /* chain table size should be 0 for fast or row-hash strategies */ in ZSTD_sizeof_matchState()
1354 …size_t const chainSize = ZSTD_allocateChainTable(cParams->strategy, useRowMatchFinder, enableDedic… in ZSTD_sizeof_matchState()
1355 ? ((size_t)1 << cParams->chainLog) in ZSTD_sizeof_matchState()
1357 size_t const hSize = ((size_t)1) << cParams->hashLog; in ZSTD_sizeof_matchState()
1358 …U32 const hashLog3 = (forCCtx && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->window… in ZSTD_sizeof_matchState()
1372 size_t const lazyAdditionalSpace = ZSTD_rowMatchFinderUsed(cParams->strategy, useRowMatchFinder) in ZSTD_sizeof_matchState()
1375 size_t const optSpace = (forCCtx && (cParams->strategy >= ZSTD_btopt)) in ZSTD_sizeof_matchState()
1382 assert(useRowMatchFinder != ZSTD_ps_auto); in ZSTD_sizeof_matchState()
1384 DEBUGLOG(4, "chainSize: %u - hSize: %u - h3Size: %u", in ZSTD_sizeof_matchState()
1398 size_t const windowSize = (size_t) BOUNDED(1ULL, 1ULL << cParams->windowLog, pledgedSrcSize); in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1400 U32 const divider = (cParams->minMatch==3) ? 3 : 4; in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1411 size_t const ldmSeqSpace = ldmParams->enableLdm == ZSTD_ps_enable ? in ZSTD_estimateCCtxSize_usingCCtxParams_internal()
1438 …ZSTD_paramSwitch_e const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFin… in ZSTD_estimateCCtxSize_usingCCtxParams()
1441 …RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-thread… in ZSTD_estimateCCtxSize_usingCCtxParams()
1442 /* estimateCCtxSize is for one-shot compression. So no buffers should in ZSTD_estimateCCtxSize_usingCCtxParams()
1443 * be needed. However, we still allocate two 0-sized buffers, which can in ZSTD_estimateCCtxSize_usingCCtxParams()
1446 &cParams, ¶ms->ldmParams, 1, useRowMatchFinder, 0, 0, ZSTD_CONTENTSIZE_UNKNOWN); in ZSTD_estimateCCtxSize_usingCCtxParams()
1453 … /* Pick bigger of not using and using row-based matchfinder for greedy and lazy strategies */ in ZSTD_estimateCCtxSize_usingCParams()
1493 …RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC, "Estimate CCtx size is supported for single-thread… in ZSTD_estimateCStreamSize_usingCCtxParams()
1497 size_t const inBuffSize = (params->inBufferMode == ZSTD_bm_buffered) in ZSTD_estimateCStreamSize_usingCCtxParams()
1500 size_t const outBuffSize = (params->outBufferMode == ZSTD_bm_buffered) in ZSTD_estimateCStreamSize_usingCCtxParams()
1503 …onst useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFinder, ¶ms->cParam… in ZSTD_estimateCStreamSize_usingCCtxParams()
1506 &cParams, ¶ms->ldmParams, 1, useRowMatchFinder, inBuffSize, outBuffSize, in ZSTD_estimateCStreamSize_usingCCtxParams()
1515 … /* Pick bigger of not using and using row-based matchfinder for greedy and lazy strategies */ in ZSTD_estimateCStreamSize_usingCParams()
1547 * able to count progression inside worker threads (non-blocking mode).
1552 size_t const buffered = (cctx->inBuff == NULL) ? 0 : in ZSTD_getFrameProgression()
1553 cctx->inBuffPos - cctx->inToCompress; in ZSTD_getFrameProgression()
1554 if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress); in ZSTD_getFrameProgression()
1555 assert(buffered <= ZSTD_BLOCKSIZE_MAX); in ZSTD_getFrameProgression()
1556 fp.ingested = cctx->consumedSrcSize + buffered; in ZSTD_getFrameProgression()
1557 fp.consumed = cctx->consumedSrcSize; in ZSTD_getFrameProgression()
1558 fp.produced = cctx->producedCSize; in ZSTD_getFrameProgression()
1559 …fp.flushed = cctx->producedCSize; /* simplified; some data might still be left within streaming… in ZSTD_getFrameProgression()
1571 …return 0; /* over-simplification; could also check if context is currently running in streaming … in ZSTD_toFlushNow()
1579 assert(cParams1.windowLog == cParams2.windowLog); in ZSTD_assertEqualCParams()
1580 assert(cParams1.chainLog == cParams2.chainLog); in ZSTD_assertEqualCParams()
1581 assert(cParams1.hashLog == cParams2.hashLog); in ZSTD_assertEqualCParams()
1582 assert(cParams1.searchLog == cParams2.searchLog); in ZSTD_assertEqualCParams()
1583 assert(cParams1.minMatch == cParams2.minMatch); in ZSTD_assertEqualCParams()
1584 assert(cParams1.targetLength == cParams2.targetLength); in ZSTD_assertEqualCParams()
1585 assert(cParams1.strategy == cParams2.strategy); in ZSTD_assertEqualCParams()
1592 bs->rep[i] = repStartValue[i]; in ZSTD_reset_compressedBlockState()
1593 bs->entropy.huf.repeatMode = HUF_repeat_none; in ZSTD_reset_compressedBlockState()
1594 bs->entropy.fse.offcode_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1595 bs->entropy.fse.matchlength_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1596 bs->entropy.fse.litlength_repeatMode = FSE_repeat_none; in ZSTD_reset_compressedBlockState()
1603 static void ZSTD_invalidateMatchState(ZSTD_matchState_t* ms) in ZSTD_invalidateMatchState() argument
1605 ZSTD_window_clear(&ms->window); in ZSTD_invalidateMatchState()
1607 ms->nextToUpdate = ms->window.dictLimit; in ZSTD_invalidateMatchState()
1608 ms->loadedDictEnd = 0; in ZSTD_invalidateMatchState()
1609 ms->opt.litLengthSum = 0; /* force reset of btopt stats */ in ZSTD_invalidateMatchState()
1610 ms->dictMatchState = NULL; in ZSTD_invalidateMatchState()
1614 * Controls, for this matchState reset, whether the tables need to be cleared /
1626 * Controls, for this matchState reset, whether indexing can continue where it
1642 ZSTD_reset_matchState(ZSTD_matchState_t* ms, in ZSTD_reset_matchState() argument
1650 /* disable chain table allocation for fast or row-based strategies */ in ZSTD_reset_matchState()
1651 size_t const chainSize = ZSTD_allocateChainTable(cParams->strategy, useRowMatchFinder, in ZSTD_reset_matchState()
1652 … ms->dedicatedDictSearch && (forWho == ZSTD_resetTarget_CDict)) in ZSTD_reset_matchState()
1653 ? ((size_t)1 << cParams->chainLog) in ZSTD_reset_matchState()
1655 size_t const hSize = ((size_t)1) << cParams->hashLog; in ZSTD_reset_matchState()
1656 …Log3 = ((forWho == ZSTD_resetTarget_CCtx) && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParam… in ZSTD_reset_matchState()
1659 DEBUGLOG(4, "reset indices : %u", forceResetIndex == ZSTDirp_reset); in ZSTD_reset_matchState()
1660 assert(useRowMatchFinder != ZSTD_ps_auto); in ZSTD_reset_matchState()
1662 ZSTD_window_init(&ms->window); in ZSTD_reset_matchState()
1666 ms->hashLog3 = hashLog3; in ZSTD_reset_matchState()
1668 ZSTD_invalidateMatchState(ms); in ZSTD_reset_matchState()
1670 assert(!ZSTD_cwksp_reserve_failed(ws)); /* check that allocation hasn't already failed */ in ZSTD_reset_matchState()
1676 ms->hashTable = (U32*)ZSTD_cwksp_reserve_table(ws, hSize * sizeof(U32)); in ZSTD_reset_matchState()
1677 ms->chainTable = (U32*)ZSTD_cwksp_reserve_table(ws, chainSize * sizeof(U32)); in ZSTD_reset_matchState()
1678 ms->hashTable3 = (U32*)ZSTD_cwksp_reserve_table(ws, h3Size * sizeof(U32)); in ZSTD_reset_matchState()
1682 DEBUGLOG(4, "reset table : %u", crp!=ZSTDcrp_leaveDirty); in ZSTD_reset_matchState()
1684 /* reset tables only */ in ZSTD_reset_matchState()
1689 if ((forWho == ZSTD_resetTarget_CCtx) && (cParams->strategy >= ZSTD_btopt)) { in ZSTD_reset_matchState()
1691 … ms->opt.litFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (1<<Litbits) * sizeof(unsigned)); in ZSTD_reset_matchState()
1692 … ms->opt.litLengthFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxLL+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1693 … ms->opt.matchLengthFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxML+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1694 … ms->opt.offCodeFreq = (unsigned*)ZSTD_cwksp_reserve_aligned(ws, (MaxOff+1) * sizeof(unsigned)); in ZSTD_reset_matchState()
1695 …ms->opt.matchTable = (ZSTD_match_t*)ZSTD_cwksp_reserve_aligned(ws, (ZSTD_OPT_NUM+1) * sizeof(ZSTD_… in ZSTD_reset_matchState()
1696 …ms->opt.priceTable = (ZSTD_optimal_t*)ZSTD_cwksp_reserve_aligned(ws, (ZSTD_OPT_NUM+1) * sizeof(ZST… in ZSTD_reset_matchState()
1699 if (ZSTD_rowMatchFinderUsed(cParams->strategy, useRowMatchFinder)) { in ZSTD_reset_matchState()
1702 ms->tagTable = (U16*)ZSTD_cwksp_reserve_aligned(ws, tagTableSize); in ZSTD_reset_matchState()
1703 if (ms->tagTable) ZSTD_memset(ms->tagTable, 0, tagTableSize); in ZSTD_reset_matchState()
1705 { /* Switch to 32-entry rows if searchLog is 5 (or more) */ in ZSTD_reset_matchState()
1706 U32 const rowLog = BOUNDED(4, cParams->searchLog, 6); in ZSTD_reset_matchState()
1707 assert(cParams->hashLog >= rowLog); in ZSTD_reset_matchState()
1708 ms->rowHashLog = cParams->hashLog - rowLog; in ZSTD_reset_matchState()
1712 ms->cParams = *cParams; in ZSTD_reset_matchState()
1722 * Works when re-using a context for a lot of smallish inputs :
1729 return (size_t)(w.nextSrc - w.base) > (ZSTD_CURRENT_MAX - ZSTD_INDEXOVERFLOW_MARGIN); in ZSTD_indexTooCloseToMax()
1734 * one go generically. So we ensure that in that case we reset the tables to zero,
1755 ZSTD_cwksp* const ws = &zc->workspace; in ZSTD_resetCCtx_internal()
1757 …(U32)pledgedSrcSize, params->cParams.windowLog, (int)params->useRowMatchFinder, (int)params->useBl… in ZSTD_resetCCtx_internal()
1758 assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); in ZSTD_resetCCtx_internal()
1760 zc->isFirstBlock = 1; in ZSTD_resetCCtx_internal()
1765 zc->appliedParams = *params; in ZSTD_resetCCtx_internal()
1766 params = &zc->appliedParams; in ZSTD_resetCCtx_internal()
1768 assert(params->useRowMatchFinder != ZSTD_ps_auto); in ZSTD_resetCCtx_internal()
1769 assert(params->useBlockSplitter != ZSTD_ps_auto); in ZSTD_resetCCtx_internal()
1770 assert(params->ldmParams.enableLdm != ZSTD_ps_auto); in ZSTD_resetCCtx_internal()
1771 if (params->ldmParams.enableLdm == ZSTD_ps_enable) { in ZSTD_resetCCtx_internal()
1773 ZSTD_ldm_adjustParameters(&zc->appliedParams.ldmParams, ¶ms->cParams); in ZSTD_resetCCtx_internal()
1774 assert(params->ldmParams.hashLog >= params->ldmParams.bucketSizeLog); in ZSTD_resetCCtx_internal()
1775 assert(params->ldmParams.hashRateLog < 32); in ZSTD_resetCCtx_internal()
1778 …{ size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params->cParams.windowLog), pledgedSrc… in ZSTD_resetCCtx_internal()
1780 U32 const divider = (params->cParams.minMatch==3) ? 3 : 4; in ZSTD_resetCCtx_internal()
1782 … size_t const buffOutSize = (zbuff == ZSTDb_buffered && params->outBufferMode == ZSTD_bm_buffered) in ZSTD_resetCCtx_internal()
1785 … size_t const buffInSize = (zbuff == ZSTDb_buffered && params->inBufferMode == ZSTD_bm_buffered) in ZSTD_resetCCtx_internal()
1788 size_t const maxNbLdmSeq = ZSTD_ldm_getMaxNbSeq(params->ldmParams, blockSize); in ZSTD_resetCCtx_internal()
1790 int const indexTooClose = ZSTD_indexTooCloseToMax(zc->blockState.matchState.window); in ZSTD_resetCCtx_internal()
1793 (indexTooClose || dictTooBig || !zc->initialized) ? ZSTDirp_reset : ZSTDirp_continue; in ZSTD_resetCCtx_internal()
1797 … ¶ms->cParams, ¶ms->ldmParams, zc->staticSize != 0, params->useRowMatchFinder, in ZSTD_resetCCtx_internal()
1803 if (!zc->staticSize) ZSTD_cwksp_bump_oversized_duration(ws, 0); in ZSTD_resetCCtx_internal()
1810 DEBUGLOG(4, "windowSize: %zu - blockSize: %zu", windowSize, blockSize); in ZSTD_resetCCtx_internal()
1817 RETURN_ERROR_IF(zc->staticSize, memory_allocation, "static cctx : no resize"); in ZSTD_resetCCtx_internal()
1821 ZSTD_cwksp_free(ws, zc->customMem); in ZSTD_resetCCtx_internal()
1822 FORWARD_IF_ERROR(ZSTD_cwksp_create(ws, neededSpace, zc->customMem), ""); in ZSTD_resetCCtx_internal()
1828 assert(ZSTD_cwksp_check_available(ws, 2 * sizeof(ZSTD_compressedBlockState_t))); in ZSTD_resetCCtx_internal()
1829 …zc->blockState.prevCBlock = (ZSTD_compressedBlockState_t*) ZSTD_cwksp_reserve_object(ws, sizeof(ZS… in ZSTD_resetCCtx_internal()
1830 …RETURN_ERROR_IF(zc->blockState.prevCBlock == NULL, memory_allocation, "couldn't allocate prevCBloc… in ZSTD_resetCCtx_internal()
1831 …zc->blockState.nextCBlock = (ZSTD_compressedBlockState_t*) ZSTD_cwksp_reserve_object(ws, sizeof(ZS… in ZSTD_resetCCtx_internal()
1832 …RETURN_ERROR_IF(zc->blockState.nextCBlock == NULL, memory_allocation, "couldn't allocate nextCBloc… in ZSTD_resetCCtx_internal()
1833 zc->entropyWorkspace = (U32*) ZSTD_cwksp_reserve_object(ws, ENTROPY_WORKSPACE_SIZE); in ZSTD_resetCCtx_internal()
1834 …RETURN_ERROR_IF(zc->entropyWorkspace == NULL, memory_allocation, "couldn't allocate entropyWorkspa… in ZSTD_resetCCtx_internal()
1840 zc->blockState.matchState.cParams = params->cParams; in ZSTD_resetCCtx_internal()
1841 zc->pledgedSrcSizePlusOne = pledgedSrcSize+1; in ZSTD_resetCCtx_internal()
1842 zc->consumedSrcSize = 0; in ZSTD_resetCCtx_internal()
1843 zc->producedCSize = 0; in ZSTD_resetCCtx_internal()
1845 zc->appliedParams.fParams.contentSizeFlag = 0; in ZSTD_resetCCtx_internal()
1847 (unsigned)pledgedSrcSize, zc->appliedParams.fParams.contentSizeFlag); in ZSTD_resetCCtx_internal()
1848 zc->blockSize = blockSize; in ZSTD_resetCCtx_internal()
1850 xxh64_reset(&zc->xxhState, 0); in ZSTD_resetCCtx_internal()
1851 zc->stage = ZSTDcs_init; in ZSTD_resetCCtx_internal()
1852 zc->dictID = 0; in ZSTD_resetCCtx_internal()
1853 zc->dictContentSize = 0; in ZSTD_resetCCtx_internal()
1855 ZSTD_reset_compressedBlockState(zc->blockState.prevCBlock); in ZSTD_resetCCtx_internal()
1860 zc->seqStore.litStart = ZSTD_cwksp_reserve_buffer(ws, blockSize + WILDCOPY_OVERLENGTH); in ZSTD_resetCCtx_internal()
1861 zc->seqStore.maxNbLit = blockSize; in ZSTD_resetCCtx_internal()
1864 zc->bufferedPolicy = zbuff; in ZSTD_resetCCtx_internal()
1865 zc->inBuffSize = buffInSize; in ZSTD_resetCCtx_internal()
1866 zc->inBuff = (char*)ZSTD_cwksp_reserve_buffer(ws, buffInSize); in ZSTD_resetCCtx_internal()
1867 zc->outBuffSize = buffOutSize; in ZSTD_resetCCtx_internal()
1868 zc->outBuff = (char*)ZSTD_cwksp_reserve_buffer(ws, buffOutSize); in ZSTD_resetCCtx_internal()
1871 if (params->ldmParams.enableLdm == ZSTD_ps_enable) { in ZSTD_resetCCtx_internal()
1874 ((size_t)1) << (params->ldmParams.hashLog - in ZSTD_resetCCtx_internal()
1875 params->ldmParams.bucketSizeLog); in ZSTD_resetCCtx_internal()
1876 zc->ldmState.bucketOffsets = ZSTD_cwksp_reserve_buffer(ws, numBuckets); in ZSTD_resetCCtx_internal()
1877 ZSTD_memset(zc->ldmState.bucketOffsets, 0, numBuckets); in ZSTD_resetCCtx_internal()
1882 zc->seqStore.maxNbSeq = maxNbSeq; in ZSTD_resetCCtx_internal()
1883 zc->seqStore.llCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1884 zc->seqStore.mlCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1885 zc->seqStore.ofCode = ZSTD_cwksp_reserve_buffer(ws, maxNbSeq * sizeof(BYTE)); in ZSTD_resetCCtx_internal()
1886 … zc->seqStore.sequencesStart = (seqDef*)ZSTD_cwksp_reserve_aligned(ws, maxNbSeq * sizeof(seqDef)); in ZSTD_resetCCtx_internal()
1889 &zc->blockState.matchState, in ZSTD_resetCCtx_internal()
1891 ¶ms->cParams, in ZSTD_resetCCtx_internal()
1892 params->useRowMatchFinder, in ZSTD_resetCCtx_internal()
1898 if (params->ldmParams.enableLdm == ZSTD_ps_enable) { in ZSTD_resetCCtx_internal()
1900 size_t const ldmHSize = ((size_t)1) << params->ldmParams.hashLog; in ZSTD_resetCCtx_internal()
1901 …zc->ldmState.hashTable = (ldmEntry_t*)ZSTD_cwksp_reserve_aligned(ws, ldmHSize * sizeof(ldmEntry_t)… in ZSTD_resetCCtx_internal()
1902 ZSTD_memset(zc->ldmState.hashTable, 0, ldmHSize * sizeof(ldmEntry_t)); in ZSTD_resetCCtx_internal()
1903 … zc->ldmSequences = (rawSeq*)ZSTD_cwksp_reserve_aligned(ws, maxNbLdmSeq * sizeof(rawSeq)); in ZSTD_resetCCtx_internal()
1904 zc->maxNbLdmSequences = maxNbLdmSeq; in ZSTD_resetCCtx_internal()
1906 ZSTD_window_init(&zc->ldmState.window); in ZSTD_resetCCtx_internal()
1907 zc->ldmState.loadedDictEnd = 0; in ZSTD_resetCCtx_internal()
1911 assert(ZSTD_cwksp_estimated_space_within_bounds(ws, neededSpace, resizeWorkspace)); in ZSTD_resetCCtx_internal()
1913 zc->initialized = 1; in ZSTD_resetCCtx_internal()
1925 for (i=0; i<ZSTD_REP_NUM; i++) cctx->blockState.prevCBlock->rep[i] = 0; in ZSTD_invalidateRepCodes()
1926 assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window)); in ZSTD_invalidateRepCodes()
1931 * in-place.
1950 size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy]; in ZSTD_shouldAttachDict()
1951 int const dedicatedDictSearch = cdict->matchState.dedicatedDictSearch; in ZSTD_shouldAttachDict()
1955 || params->attachDictPref == ZSTD_dictForceAttach ) in ZSTD_shouldAttachDict()
1956 && params->attachDictPref != ZSTD_dictForceCopy in ZSTD_shouldAttachDict()
1957 && !params->forceWindow ); /* dictMatchState isn't correctly in ZSTD_shouldAttachDict()
1971 ZSTD_compressionParameters adjusted_cdict_cParams = cdict->matchState.cParams; in ZSTD_resetCCtx_byAttachingCDict()
1973 assert(windowLog != 0); in ZSTD_resetCCtx_byAttachingCDict()
1978 if (cdict->matchState.dedicatedDictSearch) { in ZSTD_resetCCtx_byAttachingCDict()
1983 cdict->dictContentSize, ZSTD_cpm_attachDict); in ZSTD_resetCCtx_byAttachingCDict()
1985 params.useRowMatchFinder = cdict->useRowMatchFinder; /* cdict overrides */ in ZSTD_resetCCtx_byAttachingCDict()
1989 assert(cctx->appliedParams.cParams.strategy == adjusted_cdict_cParams.strategy); in ZSTD_resetCCtx_byAttachingCDict()
1992 { const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc in ZSTD_resetCCtx_byAttachingCDict()
1993 - cdict->matchState.window.base); in ZSTD_resetCCtx_byAttachingCDict()
1994 const U32 cdictLen = cdictEnd - cdict->matchState.window.dictLimit; in ZSTD_resetCCtx_byAttachingCDict()
2000 cctx->blockState.matchState.dictMatchState = &cdict->matchState; in ZSTD_resetCCtx_byAttachingCDict()
2004 if (cctx->blockState.matchState.window.dictLimit < cdictEnd) { in ZSTD_resetCCtx_byAttachingCDict()
2005 cctx->blockState.matchState.window.nextSrc = in ZSTD_resetCCtx_byAttachingCDict()
2006 cctx->blockState.matchState.window.base + cdictEnd; in ZSTD_resetCCtx_byAttachingCDict()
2007 ZSTD_window_clear(&cctx->blockState.matchState.window); in ZSTD_resetCCtx_byAttachingCDict()
2010 … cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit; in ZSTD_resetCCtx_byAttachingCDict()
2013 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byAttachingCDict()
2014 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byAttachingCDict()
2017 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byAttachingCDict()
2028 const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams; in ZSTD_resetCCtx_byCopyingCDict()
2030 assert(!cdict->matchState.dedicatedDictSearch); in ZSTD_resetCCtx_byCopyingCDict()
2035 assert(windowLog != 0); in ZSTD_resetCCtx_byCopyingCDict()
2039 params.useRowMatchFinder = cdict->useRowMatchFinder; in ZSTD_resetCCtx_byCopyingCDict()
2043 assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy); in ZSTD_resetCCtx_byCopyingCDict()
2044 assert(cctx->appliedParams.cParams.hashLog == cdict_cParams->hashLog); in ZSTD_resetCCtx_byCopyingCDict()
2045 assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog); in ZSTD_resetCCtx_byCopyingCDict()
2048 ZSTD_cwksp_mark_tables_dirty(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
2049 assert(params.useRowMatchFinder != ZSTD_ps_auto); in ZSTD_resetCCtx_byCopyingCDict()
2052 …{ size_t const chainSize = ZSTD_allocateChainTable(cdict_cParams->strategy, cdict->useRowMatchFi… in ZSTD_resetCCtx_byCopyingCDict()
2053 ? ((size_t)1 << cdict_cParams->chainLog) in ZSTD_resetCCtx_byCopyingCDict()
2055 size_t const hSize = (size_t)1 << cdict_cParams->hashLog; in ZSTD_resetCCtx_byCopyingCDict()
2057 ZSTD_memcpy(cctx->blockState.matchState.hashTable, in ZSTD_resetCCtx_byCopyingCDict()
2058 cdict->matchState.hashTable, in ZSTD_resetCCtx_byCopyingCDict()
2061 …if (ZSTD_allocateChainTable(cctx->appliedParams.cParams.strategy, cctx->appliedParams.useRowMatchF… in ZSTD_resetCCtx_byCopyingCDict()
2062 ZSTD_memcpy(cctx->blockState.matchState.chainTable, in ZSTD_resetCCtx_byCopyingCDict()
2063 cdict->matchState.chainTable, in ZSTD_resetCCtx_byCopyingCDict()
2067 if (ZSTD_rowMatchFinderUsed(cdict_cParams->strategy, cdict->useRowMatchFinder)) { in ZSTD_resetCCtx_byCopyingCDict()
2069 ZSTD_memcpy(cctx->blockState.matchState.tagTable, in ZSTD_resetCCtx_byCopyingCDict()
2070 cdict->matchState.tagTable, in ZSTD_resetCCtx_byCopyingCDict()
2076 { int const h3log = cctx->blockState.matchState.hashLog3; in ZSTD_resetCCtx_byCopyingCDict()
2078 assert(cdict->matchState.hashLog3 == 0); in ZSTD_resetCCtx_byCopyingCDict()
2079 ZSTD_memset(cctx->blockState.matchState.hashTable3, 0, h3Size * sizeof(U32)); in ZSTD_resetCCtx_byCopyingCDict()
2082 ZSTD_cwksp_mark_tables_clean(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
2085 { ZSTD_matchState_t const* srcMatchState = &cdict->matchState; in ZSTD_resetCCtx_byCopyingCDict()
2086 ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState; in ZSTD_resetCCtx_byCopyingCDict()
2087 dstMatchState->window = srcMatchState->window; in ZSTD_resetCCtx_byCopyingCDict()
2088 dstMatchState->nextToUpdate = srcMatchState->nextToUpdate; in ZSTD_resetCCtx_byCopyingCDict()
2089 dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd; in ZSTD_resetCCtx_byCopyingCDict()
2092 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byCopyingCDict()
2093 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byCopyingCDict()
2096 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byCopyingCDict()
2103 * in-place. We decide here which strategy to use. */
2136 RETURN_ERROR_IF(srcCCtx->stage!=ZSTDcs_init, stage_wrong, in ZSTD_copyCCtx_internal()
2139 ZSTD_memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); in ZSTD_copyCCtx_internal()
2140 { ZSTD_CCtx_params params = dstCCtx->requestedParams; in ZSTD_copyCCtx_internal()
2142 params.cParams = srcCCtx->appliedParams.cParams; in ZSTD_copyCCtx_internal()
2143 assert(srcCCtx->appliedParams.useRowMatchFinder != ZSTD_ps_auto); in ZSTD_copyCCtx_internal()
2144 assert(srcCCtx->appliedParams.useBlockSplitter != ZSTD_ps_auto); in ZSTD_copyCCtx_internal()
2145 assert(srcCCtx->appliedParams.ldmParams.enableLdm != ZSTD_ps_auto); in ZSTD_copyCCtx_internal()
2146 params.useRowMatchFinder = srcCCtx->appliedParams.useRowMatchFinder; in ZSTD_copyCCtx_internal()
2147 params.useBlockSplitter = srcCCtx->appliedParams.useBlockSplitter; in ZSTD_copyCCtx_internal()
2148 params.ldmParams = srcCCtx->appliedParams.ldmParams; in ZSTD_copyCCtx_internal()
2153 … assert(dstCCtx->appliedParams.cParams.windowLog == srcCCtx->appliedParams.cParams.windowLog); in ZSTD_copyCCtx_internal()
2154 assert(dstCCtx->appliedParams.cParams.strategy == srcCCtx->appliedParams.cParams.strategy); in ZSTD_copyCCtx_internal()
2155 assert(dstCCtx->appliedParams.cParams.hashLog == srcCCtx->appliedParams.cParams.hashLog); in ZSTD_copyCCtx_internal()
2156 assert(dstCCtx->appliedParams.cParams.chainLog == srcCCtx->appliedParams.cParams.chainLog); in ZSTD_copyCCtx_internal()
2157 assert(dstCCtx->blockState.matchState.hashLog3 == srcCCtx->blockState.matchState.hashLog3); in ZSTD_copyCCtx_internal()
2160 ZSTD_cwksp_mark_tables_dirty(&dstCCtx->workspace); in ZSTD_copyCCtx_internal()
2163 { size_t const chainSize = ZSTD_allocateChainTable(srcCCtx->appliedParams.cParams.strategy, in ZSTD_copyCCtx_internal()
2164 srcCCtx->appliedParams.useRowMatchFinder, in ZSTD_copyCCtx_internal()
2166 ? ((size_t)1 << srcCCtx->appliedParams.cParams.chainLog) in ZSTD_copyCCtx_internal()
2168 size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog; in ZSTD_copyCCtx_internal()
2169 int const h3log = srcCCtx->blockState.matchState.hashLog3; in ZSTD_copyCCtx_internal()
2172 ZSTD_memcpy(dstCCtx->blockState.matchState.hashTable, in ZSTD_copyCCtx_internal()
2173 srcCCtx->blockState.matchState.hashTable, in ZSTD_copyCCtx_internal()
2175 ZSTD_memcpy(dstCCtx->blockState.matchState.chainTable, in ZSTD_copyCCtx_internal()
2176 srcCCtx->blockState.matchState.chainTable, in ZSTD_copyCCtx_internal()
2178 ZSTD_memcpy(dstCCtx->blockState.matchState.hashTable3, in ZSTD_copyCCtx_internal()
2179 srcCCtx->blockState.matchState.hashTable3, in ZSTD_copyCCtx_internal()
2183 ZSTD_cwksp_mark_tables_clean(&dstCCtx->workspace); in ZSTD_copyCCtx_internal()
2187 const ZSTD_matchState_t* srcMatchState = &srcCCtx->blockState.matchState; in ZSTD_copyCCtx_internal()
2188 ZSTD_matchState_t* dstMatchState = &dstCCtx->blockState.matchState; in ZSTD_copyCCtx_internal()
2189 dstMatchState->window = srcMatchState->window; in ZSTD_copyCCtx_internal()
2190 dstMatchState->nextToUpdate = srcMatchState->nextToUpdate; in ZSTD_copyCCtx_internal()
2191 dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd; in ZSTD_copyCCtx_internal()
2193 dstCCtx->dictID = srcCCtx->dictID; in ZSTD_copyCCtx_internal()
2194 dstCCtx->dictContentSize = srcCCtx->dictContentSize; in ZSTD_copyCCtx_internal()
2197 …ZSTD_memcpy(dstCCtx->blockState.prevCBlock, srcCCtx->blockState.prevCBlock, sizeof(*srcCCtx->block… in ZSTD_copyCCtx_internal()
2210 ZSTD_buffered_policy_e const zbuff = srcCCtx->bufferedPolicy; in ZSTD_copyCCtx()
2227 * to help auto-vectorization */
2236 assert((size & (ZSTD_ROWSIZE-1)) == 0); /* multiple of ZSTD_ROWSIZE */ in ZSTD_reduceTable_internal()
2237 assert(size < (1U<<31)); /* can be casted to int */ in ZSTD_reduceTable_internal()
2246 * to auto-vectorize the loop. */ in ZSTD_reduceTable_internal()
2251 newVal = table[cellNb] - reducerValue; in ZSTD_reduceTable_internal()
2270 static void ZSTD_reduceIndex (ZSTD_matchState_t* ms, ZSTD_CCtx_params const* params, const U32 redu… in ZSTD_reduceIndex() argument
2272 { U32 const hSize = (U32)1 << params->cParams.hashLog; in ZSTD_reduceIndex()
2273 ZSTD_reduceTable(ms->hashTable, hSize, reducerValue); in ZSTD_reduceIndex()
2276 …if (ZSTD_allocateChainTable(params->cParams.strategy, params->useRowMatchFinder, (U32)ms->dedicate… in ZSTD_reduceIndex()
2277 U32 const chainSize = (U32)1 << params->cParams.chainLog; in ZSTD_reduceIndex()
2278 if (params->cParams.strategy == ZSTD_btlazy2) in ZSTD_reduceIndex()
2279 ZSTD_reduceTable_btlazy2(ms->chainTable, chainSize, reducerValue); in ZSTD_reduceIndex()
2281 ZSTD_reduceTable(ms->chainTable, chainSize, reducerValue); in ZSTD_reduceIndex()
2284 if (ms->hashLog3) { in ZSTD_reduceIndex()
2285 U32 const h3Size = (U32)1 << ms->hashLog3; in ZSTD_reduceIndex()
2286 ZSTD_reduceTable(ms->hashTable3, h3Size, reducerValue); in ZSTD_reduceIndex()
2291 /*-*******************************************************
2299 const seqDef* const sequences = seqStorePtr->sequencesStart; in ZSTD_seqToCodes()
2300 BYTE* const llCodeTable = seqStorePtr->llCode; in ZSTD_seqToCodes()
2301 BYTE* const ofCodeTable = seqStorePtr->ofCode; in ZSTD_seqToCodes()
2302 BYTE* const mlCodeTable = seqStorePtr->mlCode; in ZSTD_seqToCodes()
2303 U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_seqToCodes()
2305 assert(nbSeq <= seqStorePtr->maxNbSeq); in ZSTD_seqToCodes()
2313 if (seqStorePtr->longLengthType==ZSTD_llt_literalLength) in ZSTD_seqToCodes()
2314 llCodeTable[seqStorePtr->longLengthPos] = MaxLL; in ZSTD_seqToCodes()
2315 if (seqStorePtr->longLengthType==ZSTD_llt_matchLength) in ZSTD_seqToCodes()
2316 mlCodeTable[seqStorePtr->longLengthPos] = MaxML; in ZSTD_seqToCodes()
2325 DEBUGLOG(5, "ZSTD_useTargetCBlockSize (targetCBlockSize=%zu)", cctxParams->targetCBlockSize); in ZSTD_useTargetCBlockSize()
2326 return (cctxParams->targetCBlockSize != 0); in ZSTD_useTargetCBlockSize()
2336 DEBUGLOG(5, "ZSTD_blockSplitterEnabled (useBlockSplitter=%d)", cctxParams->useBlockSplitter); in ZSTD_blockSplitterEnabled()
2337 assert(cctxParams->useBlockSplitter != ZSTD_ps_auto); in ZSTD_blockSplitterEnabled()
2338 return (cctxParams->useBlockSplitter == ZSTD_ps_enable); in ZSTD_blockSplitterEnabled()
2357 * entropyWkspSize must be of size at least ENTROPY_WORKSPACE_SIZE - (MaxSeq + 1)*sizeof(U32)
2368 FSE_CTable* CTable_LitLength = nextEntropy->litlengthCTable; in ZSTD_buildSequencesStatistics()
2369 FSE_CTable* CTable_OffsetBits = nextEntropy->offcodeCTable; in ZSTD_buildSequencesStatistics()
2370 FSE_CTable* CTable_MatchLength = nextEntropy->matchlengthCTable; in ZSTD_buildSequencesStatistics()
2371 const BYTE* const ofCodeTable = seqStorePtr->ofCode; in ZSTD_buildSequencesStatistics()
2372 const BYTE* const llCodeTable = seqStorePtr->llCode; in ZSTD_buildSequencesStatistics()
2373 const BYTE* const mlCodeTable = seqStorePtr->mlCode; in ZSTD_buildSequencesStatistics()
2379 assert(op <= oend); in ZSTD_buildSequencesStatistics()
2380 assert(nbSeq != 0); /* ZSTD_selectEncodingType() divides by nbSeq */ in ZSTD_buildSequencesStatistics()
2385 nextEntropy->litlength_repeatMode = prevEntropy->litlength_repeatMode; in ZSTD_buildSequencesStatistics()
2386 stats.LLtype = ZSTD_selectEncodingType(&nextEntropy->litlength_repeatMode, in ZSTD_buildSequencesStatistics()
2388 LLFSELog, prevEntropy->litlengthCTable, in ZSTD_buildSequencesStatistics()
2391 assert(set_basic < set_compressed && set_rle < set_compressed); in ZSTD_buildSequencesStatistics()
2392 …assert(!(stats.LLtype < set_compressed && nextEntropy->litlength_repeatMode != FSE_repeat_none)); … in ZSTD_buildSequencesStatistics()
2394 op, (size_t)(oend - op), in ZSTD_buildSequencesStatistics()
2398 prevEntropy->litlengthCTable, in ZSTD_buildSequencesStatistics()
2399 sizeof(prevEntropy->litlengthCTable), in ZSTD_buildSequencesStatistics()
2409 assert(op <= oend); in ZSTD_buildSequencesStatistics()
2418 nextEntropy->offcode_repeatMode = prevEntropy->offcode_repeatMode; in ZSTD_buildSequencesStatistics()
2419 stats.Offtype = ZSTD_selectEncodingType(&nextEntropy->offcode_repeatMode, in ZSTD_buildSequencesStatistics()
2421 OffFSELog, prevEntropy->offcodeCTable, in ZSTD_buildSequencesStatistics()
2424 …assert(!(stats.Offtype < set_compressed && nextEntropy->offcode_repeatMode != FSE_repeat_none)); /… in ZSTD_buildSequencesStatistics()
2426 op, (size_t)(oend - op), in ZSTD_buildSequencesStatistics()
2430 prevEntropy->offcodeCTable, in ZSTD_buildSequencesStatistics()
2431 sizeof(prevEntropy->offcodeCTable), in ZSTD_buildSequencesStatistics()
2441 assert(op <= oend); in ZSTD_buildSequencesStatistics()
2447 DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op)); in ZSTD_buildSequencesStatistics()
2448 nextEntropy->matchlength_repeatMode = prevEntropy->matchlength_repeatMode; in ZSTD_buildSequencesStatistics()
2449 stats.MLtype = ZSTD_selectEncodingType(&nextEntropy->matchlength_repeatMode, in ZSTD_buildSequencesStatistics()
2451 MLFSELog, prevEntropy->matchlengthCTable, in ZSTD_buildSequencesStatistics()
2454 …assert(!(stats.MLtype < set_compressed && nextEntropy->matchlength_repeatMode != FSE_repeat_none))… in ZSTD_buildSequencesStatistics()
2456 op, (size_t)(oend - op), in ZSTD_buildSequencesStatistics()
2460 prevEntropy->matchlengthCTable, in ZSTD_buildSequencesStatistics()
2461 sizeof(prevEntropy->matchlengthCTable), in ZSTD_buildSequencesStatistics()
2471 assert(op <= oend); in ZSTD_buildSequencesStatistics()
2473 stats.size = (size_t)(op-ostart); in ZSTD_buildSequencesStatistics()
2491 const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN; in ZSTD_entropyCompressSeqStore_internal()
2492 ZSTD_strategy const strategy = cctxParams->cParams.strategy; in ZSTD_entropyCompressSeqStore_internal()
2494 FSE_CTable* CTable_LitLength = nextEntropy->fse.litlengthCTable; in ZSTD_entropyCompressSeqStore_internal()
2495 FSE_CTable* CTable_OffsetBits = nextEntropy->fse.offcodeCTable; in ZSTD_entropyCompressSeqStore_internal()
2496 FSE_CTable* CTable_MatchLength = nextEntropy->fse.matchlengthCTable; in ZSTD_entropyCompressSeqStore_internal()
2497 const seqDef* const sequences = seqStorePtr->sequencesStart; in ZSTD_entropyCompressSeqStore_internal()
2498 const size_t nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; in ZSTD_entropyCompressSeqStore_internal()
2499 const BYTE* const ofCodeTable = seqStorePtr->ofCode; in ZSTD_entropyCompressSeqStore_internal()
2500 const BYTE* const llCodeTable = seqStorePtr->llCode; in ZSTD_entropyCompressSeqStore_internal()
2501 const BYTE* const mlCodeTable = seqStorePtr->mlCode; in ZSTD_entropyCompressSeqStore_internal()
2508 entropyWkspSize -= (MaxSeq + 1) * sizeof(*count); in ZSTD_entropyCompressSeqStore_internal()
2512 assert(entropyWkspSize >= HUF_WORKSPACE_SIZE); in ZSTD_entropyCompressSeqStore_internal()
2515 { const BYTE* const literals = seqStorePtr->litStart; in ZSTD_entropyCompressSeqStore_internal()
2516 size_t const numSequences = seqStorePtr->sequences - seqStorePtr->sequencesStart; in ZSTD_entropyCompressSeqStore_internal()
2517 size_t const numLiterals = seqStorePtr->lit - seqStorePtr->litStart; in ZSTD_entropyCompressSeqStore_internal()
2520 size_t const litSize = (size_t)(seqStorePtr->lit - literals); in ZSTD_entropyCompressSeqStore_internal()
2522 &prevEntropy->huf, &nextEntropy->huf, in ZSTD_entropyCompressSeqStore_internal()
2523 cctxParams->cParams.strategy, in ZSTD_entropyCompressSeqStore_internal()
2530 assert(cSize <= dstCapacity); in ZSTD_entropyCompressSeqStore_internal()
2535 RETURN_ERROR_IF((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/, in ZSTD_entropyCompressSeqStore_internal()
2545 MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)); in ZSTD_entropyCompressSeqStore_internal()
2548 assert(op <= oend); in ZSTD_entropyCompressSeqStore_internal()
2551 ZSTD_memcpy(&nextEntropy->fse, &prevEntropy->fse, sizeof(prevEntropy->fse)); in ZSTD_entropyCompressSeqStore_internal()
2552 return (size_t)(op - ostart); in ZSTD_entropyCompressSeqStore_internal()
2559 &prevEntropy->fse, &nextEntropy->fse, in ZSTD_entropyCompressSeqStore_internal()
2570 op, (size_t)(oend - op), in ZSTD_entropyCompressSeqStore_internal()
2578 assert(op <= oend); in ZSTD_entropyCompressSeqStore_internal()
2589 assert(lastCountSize + bitstreamSize == 3); in ZSTD_entropyCompressSeqStore_internal()
2596 DEBUGLOG(5, "compressed block size : %u", (unsigned)(op - ostart)); in ZSTD_entropyCompressSeqStore_internal()
2597 return (size_t)(op - ostart); in ZSTD_entropyCompressSeqStore_internal()
2623 { size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, cctxParams->cParams.strategy); in ZSTD_entropyCompressSeqStore()
2680 assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat)); in ZSTD_selectBlockCompressor()
2697 DEBUGLOG(4, "Selecting a row-based matchfinder"); in ZSTD_selectBlockCompressor()
2698 assert(useRowMatchFinder != ZSTD_ps_auto); in ZSTD_selectBlockCompressor()
2699 selectedCompressor = rowBasedBlockCompressors[(int)dictMode][(int)strat - (int)ZSTD_greedy]; in ZSTD_selectBlockCompressor()
2703 assert(selectedCompressor != NULL); in ZSTD_selectBlockCompressor()
2710 ZSTD_memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_storeLastLiterals()
2711 seqStorePtr->lit += lastLLSize; in ZSTD_storeLastLiterals()
2716 ssPtr->lit = ssPtr->litStart; in ZSTD_resetSeqStore()
2717 ssPtr->sequences = ssPtr->sequencesStart; in ZSTD_resetSeqStore()
2718 ssPtr->longLengthType = ZSTD_llt_none; in ZSTD_resetSeqStore()
2725 ZSTD_matchState_t* const ms = &zc->blockState.matchState; in ZSTD_buildSeqStore() local
2727 assert(srcSize <= ZSTD_BLOCKSIZE_MAX); in ZSTD_buildSeqStore()
2728 /* Assert that we have correctly flushed the ctx params into the ms's copy */ in ZSTD_buildSeqStore()
2729 ZSTD_assertEqualCParams(zc->appliedParams.cParams, ms->cParams); in ZSTD_buildSeqStore()
2731 if (zc->appliedParams.cParams.strategy >= ZSTD_btopt) { in ZSTD_buildSeqStore()
2732 ZSTD_ldm_skipRawSeqStoreBytes(&zc->externSeqStore, srcSize); in ZSTD_buildSeqStore()
2734 … ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.minMatch); in ZSTD_buildSeqStore()
2738 ZSTD_resetSeqStore(&(zc->seqStore)); in ZSTD_buildSeqStore()
2740 ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; in ZSTD_buildSeqStore()
2742 ms->opt.literalCompressionMode = zc->appliedParams.literalCompressionMode; in ZSTD_buildSeqStore()
2746 assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit); in ZSTD_buildSeqStore()
2749 { const BYTE* const base = ms->window.base; in ZSTD_buildSeqStore()
2751 const U32 curr = (U32)(istart-base); in ZSTD_buildSeqStore()
2752 … if (sizeof(ptrdiff_t)==8) assert(istart - base < (ptrdiff_t)(U32)(-1)); /* ensure no overflow */ in ZSTD_buildSeqStore()
2753 if (curr > ms->nextToUpdate + 384) in ZSTD_buildSeqStore()
2754 ms->nextToUpdate = curr - MIN(192, (U32)(curr - ms->nextToUpdate - 384)); in ZSTD_buildSeqStore()
2758 { ZSTD_dictMode_e const dictMode = ZSTD_matchState_dictMode(ms); in ZSTD_buildSeqStore()
2762 zc->blockState.nextCBlock->rep[i] = zc->blockState.prevCBlock->rep[i]; in ZSTD_buildSeqStore()
2764 if (zc->externSeqStore.pos < zc->externSeqStore.size) { in ZSTD_buildSeqStore()
2765 assert(zc->appliedParams.ldmParams.enableLdm == ZSTD_ps_disable); in ZSTD_buildSeqStore()
2768 ZSTD_ldm_blockCompress(&zc->externSeqStore, in ZSTD_buildSeqStore()
2769 ms, &zc->seqStore, in ZSTD_buildSeqStore()
2770 zc->blockState.nextCBlock->rep, in ZSTD_buildSeqStore()
2771 zc->appliedParams.useRowMatchFinder, in ZSTD_buildSeqStore()
2773 assert(zc->externSeqStore.pos <= zc->externSeqStore.size); in ZSTD_buildSeqStore()
2774 } else if (zc->appliedParams.ldmParams.enableLdm == ZSTD_ps_enable) { in ZSTD_buildSeqStore()
2777 ldmSeqStore.seq = zc->ldmSequences; in ZSTD_buildSeqStore()
2778 ldmSeqStore.capacity = zc->maxNbLdmSequences; in ZSTD_buildSeqStore()
2780 FORWARD_IF_ERROR(ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore, in ZSTD_buildSeqStore()
2781 &zc->appliedParams.ldmParams, in ZSTD_buildSeqStore()
2786 ms, &zc->seqStore, in ZSTD_buildSeqStore()
2787 zc->blockState.nextCBlock->rep, in ZSTD_buildSeqStore()
2788 zc->appliedParams.useRowMatchFinder, in ZSTD_buildSeqStore()
2790 assert(ldmSeqStore.pos == ldmSeqStore.size); in ZSTD_buildSeqStore()
2792 …ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.… in ZSTD_buildSeqStore()
2793 … zc->appliedParams.useRowMatchFinder, in ZSTD_buildSeqStore()
2795 ms->ldmSeqStore = NULL; in ZSTD_buildSeqStore()
2796 … lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize); in ZSTD_buildSeqStore()
2798 { const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize; in ZSTD_buildSeqStore()
2799 ZSTD_storeLastLiterals(&zc->seqStore, lastLiterals, lastLLSize); in ZSTD_buildSeqStore()
2807 const seqDef* seqStoreSeqs = seqStore->sequencesStart; in ZSTD_copyBlockSequences()
2808 size_t seqStoreSeqSize = seqStore->sequences - seqStoreSeqs; in ZSTD_copyBlockSequences()
2809 size_t seqStoreLiteralsSize = (size_t)(seqStore->lit - seqStore->litStart); in ZSTD_copyBlockSequences()
2813 ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex]; in ZSTD_copyBlockSequences()
2817 assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences); in ZSTD_copyBlockSequences()
2819 assert(zc->seqCollector.maxSequences >= seqStoreSeqSize + 1); in ZSTD_copyBlockSequences()
2820 ZSTD_memcpy(updatedRepcodes.rep, zc->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copyBlockSequences()
2822 U32 rawOffset = seqStoreSeqs[i].offBase - ZSTD_REP_NUM; in ZSTD_copyBlockSequences()
2827 if (i == seqStore->longLengthPos) { in ZSTD_copyBlockSequences()
2828 if (seqStore->longLengthType == ZSTD_llt_literalLength) { in ZSTD_copyBlockSequences()
2830 } else if (seqStore->longLengthType == ZSTD_llt_matchLength) { in ZSTD_copyBlockSequences()
2839 rawOffset = updatedRepcodes.rep[outSeqs[i].rep - 1]; in ZSTD_copyBlockSequences()
2842 rawOffset = updatedRepcodes.rep[0] - 1; in ZSTD_copyBlockSequences()
2850 so we provide seqStoreSeqs[i].offset - 1 */ in ZSTD_copyBlockSequences()
2852 seqStoreSeqs[i].offBase - 1, in ZSTD_copyBlockSequences()
2860 assert(seqStoreLiteralsSize >= literalsRead); in ZSTD_copyBlockSequences()
2861 lastLLSize = seqStoreLiteralsSize - literalsRead; in ZSTD_copyBlockSequences()
2865 zc->seqCollector.seqIndex += seqStoreSeqSize; in ZSTD_copyBlockSequences()
2881 zc->seqCollector = seqCollector; in ZSTD_generateSequences()
2885 return zc->seqCollector.seqIndex; in ZSTD_generateSequences()
2893 if (in != seqsSize - 1) { in ZSTD_mergeBlockDelimiters()
2910 const size_t unrollMask = unrollSize - 1; in ZSTD_isRLE()
2916 if (prefixLength && ZSTD_count(ip+1, ip, ip+prefixLength) != prefixLength-1) { in ZSTD_isRLE()
2935 size_t const nbSeqs = (size_t)(seqStore->sequences - seqStore->sequencesStart); in ZSTD_maybeRLE()
2936 size_t const nbLits = (size_t)(seqStore->lit - seqStore->litStart); in ZSTD_maybeRLE()
2943 ZSTD_compressedBlockState_t* const tmp = bs->prevCBlock; in ZSTD_blockState_confirmRepcodesAndEntropyTables()
2944 bs->prevCBlock = bs->nextCBlock; in ZSTD_blockState_confirmRepcodesAndEntropyTables()
2945 bs->nextCBlock = tmp; in ZSTD_blockState_confirmRepcodesAndEntropyTables()
2976 const size_t nodeWkspSize = wkspEnd-nodeWksp; in ZSTD_buildBlockEntropyStats_literals()
2979 HUF_repeat repeat = prevHuf->repeatMode; in ZSTD_buildBlockEntropyStats_literals()
2986 DEBUGLOG(5, "set_basic - disabled"); in ZSTD_buildBlockEntropyStats_literals()
2987 hufMetadata->hType = set_basic; in ZSTD_buildBlockEntropyStats_literals()
2995 …{ size_t const minLitSize = (prevHuf->repeatMode == HUF_repeat_valid) ? 6 : COMPRESS_LITERALS_SI… in ZSTD_buildBlockEntropyStats_literals()
2997 DEBUGLOG(5, "set_basic - too small"); in ZSTD_buildBlockEntropyStats_literals()
2998 hufMetadata->hType = set_basic; in ZSTD_buildBlockEntropyStats_literals()
3008 hufMetadata->hType = set_rle; in ZSTD_buildBlockEntropyStats_literals()
3012 DEBUGLOG(5, "set_basic - no gain"); in ZSTD_buildBlockEntropyStats_literals()
3013 hufMetadata->hType = set_basic; in ZSTD_buildBlockEntropyStats_literals()
3019 …if (repeat == HUF_repeat_check && !HUF_validateCTable((HUF_CElt const*)prevHuf->CTable, countWksp,… in ZSTD_buildBlockEntropyStats_literals()
3024 ZSTD_memset(nextHuf->CTable, 0, sizeof(nextHuf->CTable)); in ZSTD_buildBlockEntropyStats_literals()
3026 { size_t const maxBits = HUF_buildCTable_wksp((HUF_CElt*)nextHuf->CTable, countWksp, in ZSTD_buildBlockEntropyStats_literals()
3033 (HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue); in ZSTD_buildBlockEntropyStats_literals()
3035 hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer), in ZSTD_buildBlockEntropyStats_literals()
3036 (HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog, in ZSTD_buildBlockEntropyStats_literals()
3041 (HUF_CElt const*)prevHuf->CTable, countWksp, maxSymbolValue); in ZSTD_buildBlockEntropyStats_literals()
3043 DEBUGLOG(5, "set_repeat - smaller"); in ZSTD_buildBlockEntropyStats_literals()
3045 hufMetadata->hType = set_repeat; in ZSTD_buildBlockEntropyStats_literals()
3050 DEBUGLOG(5, "set_basic - no gains"); in ZSTD_buildBlockEntropyStats_literals()
3052 hufMetadata->hType = set_basic; in ZSTD_buildBlockEntropyStats_literals()
3056 hufMetadata->hType = set_compressed; in ZSTD_buildBlockEntropyStats_literals()
3057 nextHuf->repeatMode = HUF_repeat_check; in ZSTD_buildBlockEntropyStats_literals()
3071 nextEntropy->litlength_repeatMode = FSE_repeat_none; in ZSTD_buildDummySequencesStatistics()
3072 nextEntropy->offcode_repeatMode = FSE_repeat_none; in ZSTD_buildDummySequencesStatistics()
3073 nextEntropy->matchlength_repeatMode = FSE_repeat_none; in ZSTD_buildDummySequencesStatistics()
3089 ZSTD_strategy const strategy = cctxParams->cParams.strategy; in ZSTD_buildBlockEntropyStats_sequences()
3090 size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; in ZSTD_buildBlockEntropyStats_sequences()
3091 BYTE* const ostart = fseMetadata->fseTablesBuffer; in ZSTD_buildBlockEntropyStats_sequences()
3092 BYTE* const oend = ostart + sizeof(fseMetadata->fseTablesBuffer); in ZSTD_buildBlockEntropyStats_sequences()
3096 size_t entropyWorkspaceSize = wkspSize - (MaxSeq + 1) * sizeof(*countWorkspace); in ZSTD_buildBlockEntropyStats_sequences()
3106 fseMetadata->llType = (symbolEncodingType_e) stats.LLtype; in ZSTD_buildBlockEntropyStats_sequences()
3107 fseMetadata->ofType = (symbolEncodingType_e) stats.Offtype; in ZSTD_buildBlockEntropyStats_sequences()
3108 fseMetadata->mlType = (symbolEncodingType_e) stats.MLtype; in ZSTD_buildBlockEntropyStats_sequences()
3109 fseMetadata->lastCountSize = stats.lastCountSize; in ZSTD_buildBlockEntropyStats_sequences()
3127 size_t const litSize = seqStorePtr->lit - seqStorePtr->litStart; in ZSTD_buildBlockEntropyStats()
3128 entropyMetadata->hufMetadata.hufDesSize = in ZSTD_buildBlockEntropyStats()
3129 ZSTD_buildBlockEntropyStats_literals(seqStorePtr->litStart, litSize, in ZSTD_buildBlockEntropyStats()
3130 &prevEntropy->huf, &nextEntropy->huf, in ZSTD_buildBlockEntropyStats()
3131 &entropyMetadata->hufMetadata, in ZSTD_buildBlockEntropyStats()
3134 …FORWARD_IF_ERROR(entropyMetadata->hufMetadata.hufDesSize, "ZSTD_buildBlockEntropyStats_literals fa… in ZSTD_buildBlockEntropyStats()
3135 entropyMetadata->fseMetadata.fseTablesSize = in ZSTD_buildBlockEntropyStats()
3137 &prevEntropy->fse, &nextEntropy->fse, in ZSTD_buildBlockEntropyStats()
3139 &entropyMetadata->fseMetadata, in ZSTD_buildBlockEntropyStats()
3141 …FORWARD_IF_ERROR(entropyMetadata->fseMetadata.fseTablesSize, "ZSTD_buildBlockEntropyStats_sequence… in ZSTD_buildBlockEntropyStats()
3157 if (hufMetadata->hType == set_basic) return litSize; in ZSTD_estimateBlockSize_literal()
3158 else if (hufMetadata->hType == set_rle) return 1; in ZSTD_estimateBlockSize_literal()
3159 else if (hufMetadata->hType == set_compressed || hufMetadata->hType == set_repeat) { in ZSTD_estimateBlockSize_literal()
3162 …{ size_t cLitSizeEstimate = HUF_estimateCompressedSize((const HUF_CElt*)huf->CTable, countWksp, … in ZSTD_estimateBlockSize_literal()
3163 if (writeEntropy) cLitSizeEstimate += hufMetadata->hufDesSize; in ZSTD_estimateBlockSize_literal()
3164 … if (!singleStream) cLitSizeEstimate += 6; /* multi-stream huffman uses 6-byte jump table */ in ZSTD_estimateBlockSize_literal()
3167 assert(0); /* impossible */ in ZSTD_estimateBlockSize_literal()
3171 /* Returns the size estimate for the FSE-compressed symbols (of, ml, ll) of a block */
3189 assert(max <= defaultMax); in ZSTD_estimateBlockSize_symbolType()
3220 …cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->ofType, ofCodeTable, nbSeq, Max… in ZSTD_estimateBlockSize_sequences()
3221 fseTables->offcodeCTable, NULL, in ZSTD_estimateBlockSize_sequences()
3224 …cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->llType, llCodeTable, nbSeq, Max… in ZSTD_estimateBlockSize_sequences()
3225 fseTables->litlengthCTable, LL_bits, in ZSTD_estimateBlockSize_sequences()
3228 …cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->mlType, mlCodeTable, nbSeq, Max… in ZSTD_estimateBlockSize_sequences()
3229 fseTables->matchlengthCTable, ML_bits, in ZSTD_estimateBlockSize_sequences()
3232 if (writeEntropy) cSeqSizeEstimate += fseMetadata->fseTablesSize; in ZSTD_estimateBlockSize_sequences()
3247 … &entropy->huf, &entropyMetadata->hufMetadata, in ZSTD_estimateBlockSize()
3250 … nbSeq, &entropy->fse, &entropyMetadata->fseMetadata, in ZSTD_estimateBlockSize()
3260 ZSTD_entropyCTablesMetadata_t* entropyMetadata = &zc->blockSplitCtx.entropyMetadata; in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3263 &zc->blockState.prevCBlock->entropy, in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3264 &zc->blockState.nextCBlock->entropy, in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3265 &zc->appliedParams, in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3267 … zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */), ""); in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3268 return ZSTD_estimateBlockSize(seqStore->litStart, (size_t)(seqStore->lit - seqStore->litStart), in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3269 seqStore->ofCode, seqStore->llCode, seqStore->mlCode, in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3270 (size_t)(seqStore->sequences - seqStore->sequencesStart), in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3271 …&zc->blockState.nextCBlock->entropy, entropyMetadata, zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE, in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3272 (int)(entropyMetadata->hufMetadata.hType == set_compressed), 1); in ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()
3278 size_t const nbSeqs = seqStore->sequences - seqStore->sequencesStart; in ZSTD_countSeqStoreLiteralsBytes()
3281 seqDef seq = seqStore->sequencesStart[i]; in ZSTD_countSeqStoreLiteralsBytes()
3283 if (i == seqStore->longLengthPos && seqStore->longLengthType == ZSTD_llt_literalLength) { in ZSTD_countSeqStoreLiteralsBytes()
3293 size_t const nbSeqs = seqStore->sequences - seqStore->sequencesStart; in ZSTD_countSeqStoreMatchBytes()
3296 seqDef seq = seqStore->sequencesStart[i]; in ZSTD_countSeqStoreMatchBytes()
3298 if (i == seqStore->longLengthPos && seqStore->longLengthType == ZSTD_llt_matchLength) { in ZSTD_countSeqStoreMatchBytes()
3311 BYTE* const litEnd = originalSeqStore->lit; in ZSTD_deriveSeqStoreChunk()
3317 resultSeqStore->sequences = originalSeqStore->sequencesStart + startIdx; in ZSTD_deriveSeqStoreChunk()
3322 if (originalSeqStore->longLengthType != ZSTD_llt_none) { in ZSTD_deriveSeqStoreChunk()
3323 … if (originalSeqStore->longLengthPos < startIdx || originalSeqStore->longLengthPos > endIdx) { in ZSTD_deriveSeqStoreChunk()
3324 resultSeqStore->longLengthType = ZSTD_llt_none; in ZSTD_deriveSeqStoreChunk()
3326 resultSeqStore->longLengthPos -= (U32)startIdx; in ZSTD_deriveSeqStoreChunk()
3329 resultSeqStore->sequencesStart = originalSeqStore->sequencesStart + startIdx; in ZSTD_deriveSeqStoreChunk()
3330 resultSeqStore->sequences = originalSeqStore->sequencesStart + endIdx; in ZSTD_deriveSeqStoreChunk()
3332 resultSeqStore->litStart += literalsBytesPreceding; in ZSTD_deriveSeqStoreChunk()
3333 if (endIdx == (size_t)(originalSeqStore->sequences - originalSeqStore->sequencesStart)) { in ZSTD_deriveSeqStoreChunk()
3335 resultSeqStore->lit = litEnd; in ZSTD_deriveSeqStoreChunk()
3337 resultSeqStore->lit = resultSeqStore->litStart+literalsBytes; in ZSTD_deriveSeqStoreChunk()
3339 resultSeqStore->llCode += startIdx; in ZSTD_deriveSeqStoreChunk()
3340 resultSeqStore->mlCode += startIdx; in ZSTD_deriveSeqStoreChunk()
3341 resultSeqStore->ofCode += startIdx; in ZSTD_deriveSeqStoreChunk()
3351 U32 const adjustedOffCode = STORED_REPCODE(offCode) - 1 + ll0; /* [ 0 - 3 ] */ in ZSTD_resolveRepcodeToRawOffset()
3352 assert(STORED_IS_REPCODE(offCode)); in ZSTD_resolveRepcodeToRawOffset()
3354 /* litlength == 0 and offCode == 2 implies selection of first repcode - 1 */ in ZSTD_resolveRepcodeToRawOffset()
3355 assert(rep[0] > 0); in ZSTD_resolveRepcodeToRawOffset()
3356 return rep[0] - 1; in ZSTD_resolveRepcodeToRawOffset()
3369 * Note : this function assumes seq->offBase respects the following numbering scheme :
3371 * 1-3 : repcode 1-3
3378 seqDef* const seq = seqStore->sequencesStart + idx; in ZSTD_seqStore_resolveOffCodes()
3379 U32 const ll0 = (seq->litLength == 0); in ZSTD_seqStore_resolveOffCodes()
3380 U32 const offCode = OFFBASE_TO_STORED(seq->offBase); in ZSTD_seqStore_resolveOffCodes()
3381 assert(seq->offBase > 0); in ZSTD_seqStore_resolveOffCodes()
3383 U32 const dRawOffset = ZSTD_resolveRepcodeToRawOffset(dRepcodes->rep, offCode, ll0); in ZSTD_seqStore_resolveOffCodes()
3384 U32 const cRawOffset = ZSTD_resolveRepcodeToRawOffset(cRepcodes->rep, offCode, ll0); in ZSTD_seqStore_resolveOffCodes()
3390 seq->offBase = cRawOffset + ZSTD_REP_NUM; in ZSTD_seqStore_resolveOffCodes()
3394 …* Decompression repcode history may use modified seq->offset value taken from compression repcode … in ZSTD_seqStore_resolveOffCodes()
3396 ZSTD_updateRep(dRepcodes->rep, OFFBASE_TO_STORED(seq->offBase), ll0); in ZSTD_seqStore_resolveOffCodes()
3397 ZSTD_updateRep(cRepcodes->rep, offCode, ll0); in ZSTD_seqStore_resolveOffCodes()
3419 /* In case of an RLE or raw block, the simulated decompression repcode history must be reset */ in ZSTD_compressSeqStore_singleBlock()
3423 …ZSTD_seqStore_resolveOffCodes(dRep, cRep, seqStore, (U32)(seqStore->sequences - seqStore->sequence… in ZSTD_compressSeqStore_singleBlock()
3427 &zc->blockState.prevCBlock->entropy, &zc->blockState.nextCBlock->entropy, in ZSTD_compressSeqStore_singleBlock()
3428 &zc->appliedParams, in ZSTD_compressSeqStore_singleBlock()
3429 op + ZSTD_blockHeaderSize, dstCapacity - ZSTD_blockHeaderSize, in ZSTD_compressSeqStore_singleBlock()
3431 … zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressSeqStore_singleBlock()
3432 zc->bmi2); in ZSTD_compressSeqStore_singleBlock()
3435 if (!zc->isFirstBlock && in ZSTD_compressSeqStore_singleBlock()
3445 if (zc->seqCollector.collectSequences) { in ZSTD_compressSeqStore_singleBlock()
3447 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->blockState); in ZSTD_compressSeqStore_singleBlock()
3455 *dRep = dRepOriginal; /* reset simulated decompression repcode history */ in ZSTD_compressSeqStore_singleBlock()
3460 *dRep = dRepOriginal; /* reset simulated decompression repcode history */ in ZSTD_compressSeqStore_singleBlock()
3462 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->blockState); in ZSTD_compressSeqStore_singleBlock()
3468 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressSeqStore_singleBlock()
3469 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressSeqStore_singleBlock()
3484 …* If advantageous to split, then we recurse down the two sub-blocks. If not, or if an error occurr…
3498 seqStore_t* fullSeqStoreChunk = &zc->blockSplitCtx.fullSeqStoreChunk; in ZSTD_deriveBlockSplitsHelper()
3499 seqStore_t* firstHalfSeqStore = &zc->blockSplitCtx.firstHalfSeqStore; in ZSTD_deriveBlockSplitsHelper()
3500 seqStore_t* secondHalfSeqStore = &zc->blockSplitCtx.secondHalfSeqStore; in ZSTD_deriveBlockSplitsHelper()
3506 …if (endIdx - startIdx < MIN_SEQUENCES_BLOCK_SPLITTING || splits->idx >= ZSTD_MAX_NB_BLOCK_SPLITS) { in ZSTD_deriveBlockSplitsHelper()
3517 …DEBUGLOG(4, "Estimated original block size: %zu -- First half split: %zu -- Second half split: %zu… in ZSTD_deriveBlockSplitsHelper()
3524 splits->splitLocations[splits->idx] = (U32)midIdx; in ZSTD_deriveBlockSplitsHelper()
3525 splits->idx++; in ZSTD_deriveBlockSplitsHelper()
3530 /* Base recursive function. Populates a table with intra-block partition indices that can improve c…
3532 * Returns the number of splits made (which equals the size of the partition table - 1).
3541 ZSTD_deriveBlockSplitsHelper(&splits, 0, nbSeq, zc, &zc->seqStore); in ZSTD_deriveBlockSplits()
3561 U32* partitions = zc->blockSplitCtx.partitions; /* size == ZSTD_MAX_NB_BLOCK_SPLITS */ in ZSTD_compressBlock_splitBlock_internal()
3562 seqStore_t* nextSeqStore = &zc->blockSplitCtx.nextSeqStore; in ZSTD_compressBlock_splitBlock_internal()
3563 seqStore_t* currSeqStore = &zc->blockSplitCtx.currSeqStore; in ZSTD_compressBlock_splitBlock_internal()
3582 ZSTD_memcpy(dRep.rep, zc->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_compressBlock_splitBlock_internal()
3583 ZSTD_memcpy(cRep.rep, zc->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_compressBlock_splitBlock_internal()
3587 (unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, in ZSTD_compressBlock_splitBlock_internal()
3588 (unsigned)zc->blockState.matchState.nextToUpdate); in ZSTD_compressBlock_splitBlock_internal()
3591 size_t cSizeSingleBlock = ZSTD_compressSeqStore_singleBlock(zc, &zc->seqStore, in ZSTD_compressBlock_splitBlock_internal()
3598 assert(cSizeSingleBlock <= ZSTD_BLOCKSIZE_MAX + ZSTD_blockHeaderSize); in ZSTD_compressBlock_splitBlock_internal()
3602 ZSTD_deriveSeqStoreChunk(currSeqStore, &zc->seqStore, 0, partitions[0]); in ZSTD_compressBlock_splitBlock_internal()
3613 srcBytes += blockSize - srcBytesTotal; in ZSTD_compressBlock_splitBlock_internal()
3616 ZSTD_deriveSeqStoreChunk(nextSeqStore, &zc->seqStore, partitions[i], partitions[i+1]); in ZSTD_compressBlock_splitBlock_internal()
3629 dstCapacity -= cSizeChunk; in ZSTD_compressBlock_splitBlock_internal()
3632 assert(cSizeChunk <= ZSTD_BLOCKSIZE_MAX + ZSTD_blockHeaderSize); in ZSTD_compressBlock_splitBlock_internal()
3637 ZSTD_memcpy(zc->blockState.prevCBlock->rep, dRep.rep, sizeof(repcodes_t)); in ZSTD_compressBlock_splitBlock_internal()
3651 assert(zc->appliedParams.useBlockSplitter == ZSTD_ps_enable); in ZSTD_compressBlock_splitBlock()
3656 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressBlock_splitBlock()
3657 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressBlock_splitBlock()
3663 nbSeq = (U32)(zc->seqStore.sequences - zc->seqStore.sequencesStart); in ZSTD_compressBlock_splitBlock()
3685 (unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, in ZSTD_compressBlock_internal()
3686 (unsigned)zc->blockState.matchState.nextToUpdate); in ZSTD_compressBlock_internal()
3693 if (zc->seqCollector.collectSequences) { in ZSTD_compressBlock_internal()
3695 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->blockState); in ZSTD_compressBlock_internal()
3700 cSize = ZSTD_entropyCompressSeqStore(&zc->seqStore, in ZSTD_compressBlock_internal()
3701 &zc->blockState.prevCBlock->entropy, &zc->blockState.nextCBlock->entropy, in ZSTD_compressBlock_internal()
3702 &zc->appliedParams, in ZSTD_compressBlock_internal()
3705 zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressBlock_internal()
3706 zc->bmi2); in ZSTD_compressBlock_internal()
3713 !zc->isFirstBlock && in ZSTD_compressBlock_internal()
3723 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->blockState); in ZSTD_compressBlock_internal()
3729 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressBlock_internal()
3730 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressBlock_internal()
3746 !zc->isFirstBlock && in ZSTD_compressBlock_targetCBlockSize_body()
3747 ZSTD_maybeRLE(&zc->seqStore) && in ZSTD_compressBlock_targetCBlockSize_body()
3773 … size_t const maxCSize = srcSize - ZSTD_minGain(srcSize, zc->appliedParams.cParams.strategy); in ZSTD_compressBlock_targetCBlockSize_body()
3776 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->blockState); in ZSTD_compressBlock_targetCBlockSize_body()
3798 …(unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, (unsigned)zc->blockSt… in ZSTD_compressBlock_targetCBlockSize()
3804 if (zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressBlock_targetCBlockSize()
3805 zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressBlock_targetCBlockSize()
3810 static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms, in ZSTD_overflowCorrectIfNeeded() argument
3816 U32 const cycleLog = ZSTD_cycleLog(params->cParams.chainLog, params->cParams.strategy); in ZSTD_overflowCorrectIfNeeded()
3817 U32 const maxDist = (U32)1 << params->cParams.windowLog; in ZSTD_overflowCorrectIfNeeded()
3818 …if (ZSTD_window_needOverflowCorrection(ms->window, cycleLog, maxDist, ms->loadedDictEnd, ip, iend)… in ZSTD_overflowCorrectIfNeeded()
3819 U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip); in ZSTD_overflowCorrectIfNeeded()
3824 ZSTD_reduceIndex(ms, params, correction); in ZSTD_overflowCorrectIfNeeded()
3826 if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; in ZSTD_overflowCorrectIfNeeded()
3827 else ms->nextToUpdate -= correction; in ZSTD_overflowCorrectIfNeeded()
3829 ms->loadedDictEnd = 0; in ZSTD_overflowCorrectIfNeeded()
3830 ms->dictMatchState = NULL; in ZSTD_overflowCorrectIfNeeded()
3846 size_t blockSize = cctx->blockSize; in ZSTD_compress_frameChunk()
3851 U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog; in ZSTD_compress_frameChunk()
3853 assert(cctx->appliedParams.cParams.windowLog <= ZSTD_WINDOWLOG_MAX); in ZSTD_compress_frameChunk()
3856 if (cctx->appliedParams.fParams.checksumFlag && srcSize) in ZSTD_compress_frameChunk()
3857 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compress_frameChunk()
3860 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compress_frameChunk() local
3869 ms, &cctx->workspace, &cctx->appliedParams, ip, ip + blockSize); in ZSTD_compress_frameChunk()
3870 …ZSTD_checkDictValidity(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchSta… in ZSTD_compress_frameChunk()
3871 … ZSTD_window_enforceMaxDist(&ms->window, ip, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); in ZSTD_compress_frameChunk()
3874 if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit; in ZSTD_compress_frameChunk()
3877 if (ZSTD_useTargetCBlockSize(&cctx->appliedParams)) { in ZSTD_compress_frameChunk()
3880 assert(cSize > 0); in ZSTD_compress_frameChunk()
3881 assert(cSize <= blockSize + ZSTD_blockHeaderSize); in ZSTD_compress_frameChunk()
3882 } else if (ZSTD_blockSplitterEnabled(&cctx->appliedParams)) { in ZSTD_compress_frameChunk()
3885 assert(cSize > 0 || cctx->seqCollector.collectSequences == 1); in ZSTD_compress_frameChunk()
3888 op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, in ZSTD_compress_frameChunk()
3906 assert(remaining >= blockSize); in ZSTD_compress_frameChunk()
3907 remaining -= blockSize; in ZSTD_compress_frameChunk()
3909 assert(dstCapacity >= cSize); in ZSTD_compress_frameChunk()
3910 dstCapacity -= cSize; in ZSTD_compress_frameChunk()
3911 cctx->isFirstBlock = 0; in ZSTD_compress_frameChunk()
3916 if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending; in ZSTD_compress_frameChunk()
3917 return (size_t)(op-ostart); in ZSTD_compress_frameChunk()
3924 U32 const dictIDSizeCodeLength = (dictID>0) + (dictID>=256) + (dictID>=65536); /* 0-3 */ in ZSTD_writeFrameHeader()
3925 … U32 const dictIDSizeCode = params->fParams.noDictIDFlag ? 0 : dictIDSizeCodeLength; /* 0-3 */ in ZSTD_writeFrameHeader()
3926 U32 const checksumFlag = params->fParams.checksumFlag>0; in ZSTD_writeFrameHeader()
3927 U32 const windowSize = (U32)1 << params->cParams.windowLog; in ZSTD_writeFrameHeader()
3928 U32 const singleSegment = params->fParams.contentSizeFlag && (windowSize >= pledgedSrcSize); in ZSTD_writeFrameHeader()
3929 … BYTE const windowLogByte = (BYTE)((params->cParams.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN) << 3); in ZSTD_writeFrameHeader()
3930 U32 const fcsCode = params->fParams.contentSizeFlag ? in ZSTD_writeFrameHeader()
3931 …(pledgedSrcSize>=256) + (pledgedSrcSize>=65536+256) + (pledgedSrcSize>=0xFFFFFFFFU) : 0; /* 0-3 */ in ZSTD_writeFrameHeader()
3935 assert(!(params->fParams.contentSizeFlag && pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN)); in ZSTD_writeFrameHeader()
3937 "dst buf is too small to fit worst-case frame header size."); in ZSTD_writeFrameHeader()
3939 !params->fParams.noDictIDFlag, (unsigned)dictID, (unsigned)dictIDSizeCode); in ZSTD_writeFrameHeader()
3940 if (params->format == ZSTD_f_zstd1) { in ZSTD_writeFrameHeader()
3949 assert(0); /* impossible */ in ZSTD_writeFrameHeader()
3959 assert(0); /* impossible */ in ZSTD_writeFrameHeader()
3962 case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break; in ZSTD_writeFrameHeader()
3990 * output an empty Block with end-of-frame mark to complete a frame
4006 RETURN_ERROR_IF(cctx->stage != ZSTDcs_init, stage_wrong, in ZSTD_referenceExternalSequences()
4008 RETURN_ERROR_IF(cctx->appliedParams.ldmParams.enableLdm == ZSTD_ps_enable, in ZSTD_referenceExternalSequences()
4011 cctx->externSeqStore.seq = seq; in ZSTD_referenceExternalSequences()
4012 cctx->externSeqStore.size = nbSeq; in ZSTD_referenceExternalSequences()
4013 cctx->externSeqStore.capacity = nbSeq; in ZSTD_referenceExternalSequences()
4014 cctx->externSeqStore.pos = 0; in ZSTD_referenceExternalSequences()
4015 cctx->externSeqStore.posInSequence = 0; in ZSTD_referenceExternalSequences()
4025 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compressContinue_internal() local
4029 cctx->stage, (unsigned)srcSize); in ZSTD_compressContinue_internal()
4030 RETURN_ERROR_IF(cctx->stage==ZSTDcs_created, stage_wrong, in ZSTD_compressContinue_internal()
4033 if (frame && (cctx->stage==ZSTDcs_init)) { in ZSTD_compressContinue_internal()
4034 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, in ZSTD_compressContinue_internal()
4035 cctx->pledgedSrcSizePlusOne-1, cctx->dictID); in ZSTD_compressContinue_internal()
4037 assert(fhSize <= dstCapacity); in ZSTD_compressContinue_internal()
4038 dstCapacity -= fhSize; in ZSTD_compressContinue_internal()
4040 cctx->stage = ZSTDcs_ongoing; in ZSTD_compressContinue_internal()
4045 if (!ZSTD_window_update(&ms->window, src, srcSize, ms->forceNonContiguous)) { in ZSTD_compressContinue_internal()
4046 ms->forceNonContiguous = 0; in ZSTD_compressContinue_internal()
4047 ms->nextToUpdate = ms->window.dictLimit; in ZSTD_compressContinue_internal()
4049 if (cctx->appliedParams.ldmParams.enableLdm == ZSTD_ps_enable) { in ZSTD_compressContinue_internal()
4050 ZSTD_window_update(&cctx->ldmState.window, src, srcSize, /* forceNonContiguous */ 0); in ZSTD_compressContinue_internal()
4056 ms, &cctx->workspace, &cctx->appliedParams, in ZSTD_compressContinue_internal()
4060 DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (unsigned)cctx->blockSize); in ZSTD_compressContinue_internal()
4065 cctx->consumedSrcSize += srcSize; in ZSTD_compressContinue_internal()
4066 cctx->producedCSize += (cSize + fhSize); in ZSTD_compressContinue_internal()
4067 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressContinue_internal()
4068 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressContinue_internal()
4069 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1); in ZSTD_compressContinue_internal()
4071 cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne, in ZSTD_compressContinue_internal()
4074 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressContinue_internal()
4075 (unsigned)cctx->consumedSrcSize); in ZSTD_compressContinue_internal()
4092 ZSTD_compressionParameters const cParams = cctx->appliedParams.cParams; in ZSTD_getBlockSize()
4093 assert(!ZSTD_checkCParams(cParams)); in ZSTD_getBlockSize()
4109 static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms, in ZSTD_loadDictionaryContent() argument
4118 int const loadLdmDict = params->ldmParams.enableLdm == ZSTD_ps_enable && ls != NULL; in ZSTD_loadDictionaryContent()
4120 /* Assert that we the ms params match the params we're being given */ in ZSTD_loadDictionaryContent()
4121 ZSTD_assertEqualCParams(params->cParams, ms->cParams); in ZSTD_loadDictionaryContent()
4128 U32 const maxDictSize = ZSTD_CURRENT_MAX - 1; in ZSTD_loadDictionaryContent()
4130 assert(ZSTD_window_isEmpty(ms->window)); in ZSTD_loadDictionaryContent()
4132 assert(ZSTD_window_isEmpty(ls->window)); in ZSTD_loadDictionaryContent()
4135 ip = iend - maxDictSize; in ZSTD_loadDictionaryContent()
4141 … DEBUGLOG(4, "ZSTD_loadDictionaryContent(): useRowMatchFinder=%d", (int)params->useRowMatchFinder); in ZSTD_loadDictionaryContent()
4142 ZSTD_window_update(&ms->window, src, srcSize, /* forceNonContiguous */ 0); in ZSTD_loadDictionaryContent()
4143 ms->loadedDictEnd = params->forceWindow ? 0 : (U32)(iend - ms->window.base); in ZSTD_loadDictionaryContent()
4144 ms->forceNonContiguous = params->deterministicRefPrefix; in ZSTD_loadDictionaryContent()
4147 ZSTD_window_update(&ls->window, src, srcSize, /* forceNonContiguous */ 0); in ZSTD_loadDictionaryContent()
4148 ls->loadedDictEnd = params->forceWindow ? 0 : (U32)(iend - ls->window.base); in ZSTD_loadDictionaryContent()
4153 ZSTD_overflowCorrectIfNeeded(ms, ws, params, ip, iend); in ZSTD_loadDictionaryContent()
4156 ZSTD_ldm_fillHashTable(ls, ip, iend, ¶ms->ldmParams); in ZSTD_loadDictionaryContent()
4158 switch(params->cParams.strategy) in ZSTD_loadDictionaryContent()
4161 ZSTD_fillHashTable(ms, iend, dtlm); in ZSTD_loadDictionaryContent()
4164 ZSTD_fillDoubleHashTable(ms, iend, dtlm); in ZSTD_loadDictionaryContent()
4170 assert(srcSize >= HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
4171 if (ms->dedicatedDictSearch) { in ZSTD_loadDictionaryContent()
4172 assert(ms->chainTable != NULL); in ZSTD_loadDictionaryContent()
4173 ZSTD_dedicatedDictSearch_lazy_loadDictionary(ms, iend-HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
4175 assert(params->useRowMatchFinder != ZSTD_ps_auto); in ZSTD_loadDictionaryContent()
4176 if (params->useRowMatchFinder == ZSTD_ps_enable) { in ZSTD_loadDictionaryContent()
4177 size_t const tagTableSize = ((size_t)1 << params->cParams.hashLog) * sizeof(U16); in ZSTD_loadDictionaryContent()
4178 ZSTD_memset(ms->tagTable, 0, tagTableSize); in ZSTD_loadDictionaryContent()
4179 ZSTD_row_update(ms, iend-HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
4180 DEBUGLOG(4, "Using row-based hash table for lazy dict"); in ZSTD_loadDictionaryContent()
4182 ZSTD_insertAndFindFirstIndex(ms, iend-HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
4183 DEBUGLOG(4, "Using chain-based hash table for lazy dict"); in ZSTD_loadDictionaryContent()
4192 assert(srcSize >= HASH_READ_SIZE); in ZSTD_loadDictionaryContent()
4193 ZSTD_updateTree(ms, iend-HASH_READ_SIZE, iend); in ZSTD_loadDictionaryContent()
4197 assert(0); /* not possible : not a valid strategy id */ in ZSTD_loadDictionaryContent()
4200 ms->nextToUpdate = (U32)(iend - ms->window.base); in ZSTD_loadDictionaryContent()
4231 bs->entropy.huf.repeatMode = HUF_repeat_check; in ZSTD_loadCEntropy()
4235 …size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, di… in ZSTD_loadCEntropy()
4236 dictEnd-dictPtr, &hasZeroWeights); in ZSTD_loadCEntropy()
4238 /* We only set the loaded table as valid if it contains all non-zero in ZSTD_loadCEntropy()
4241 bs->entropy.huf.repeatMode = HUF_repeat_valid; in ZSTD_loadCEntropy()
4249 …eaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
4254 bs->entropy.fse.offcodeCTable, in ZSTD_loadCEntropy()
4264 …FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
4268 bs->entropy.fse.matchlengthCTable, in ZSTD_loadCEntropy()
4272 …bs->entropy.fse.matchlength_repeatMode = ZSTD_dictNCountRepeat(matchlengthNCount, matchlengthMaxVa… in ZSTD_loadCEntropy()
4278 …ize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); in ZSTD_loadCEntropy()
4282 bs->entropy.fse.litlengthCTable, in ZSTD_loadCEntropy()
4286 …bs->entropy.fse.litlength_repeatMode = ZSTD_dictNCountRepeat(litlengthNCount, litlengthMaxValue, M… in ZSTD_loadCEntropy()
4291 bs->rep[0] = MEM_readLE32(dictPtr+0); in ZSTD_loadCEntropy()
4292 bs->rep[1] = MEM_readLE32(dictPtr+4); in ZSTD_loadCEntropy()
4293 bs->rep[2] = MEM_readLE32(dictPtr+8); in ZSTD_loadCEntropy()
4296 { size_t const dictContentSize = (size_t)(dictEnd - dictPtr); in ZSTD_loadCEntropy()
4298 if (dictContentSize <= ((U32)-1) - 128 KB) { in ZSTD_loadCEntropy()
4303 …bs->entropy.fse.offcode_repeatMode = ZSTD_dictNCountRepeat(offcodeNCount, offcodeMaxValue, MIN(off… in ZSTD_loadCEntropy()
4308 RETURN_ERROR_IF(bs->rep[u] == 0, dictionary_corrupted, ""); in ZSTD_loadCEntropy()
4309 RETURN_ERROR_IF(bs->rep[u] > dictContentSize, dictionary_corrupted, ""); in ZSTD_loadCEntropy()
4312 return dictPtr - (const BYTE*)dict; in ZSTD_loadCEntropy()
4317 * https://github.com/facebook/zstd/blob/release/doc/zstd_compression_format.md#dictionary-format
4325 ZSTD_matchState_t* ms, in ZSTD_loadZstdDictionary() argument
4337 assert(dictSize >= 8); in ZSTD_loadZstdDictionary()
4338 assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY); in ZSTD_loadZstdDictionary()
4340 dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr + 4 /* skip magic number */ ); in ZSTD_loadZstdDictionary()
4346 size_t const dictContentSize = (size_t)(dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
4348 ms, NULL, ws, params, dictPtr, dictContentSize, dtlm), ""); in ZSTD_loadZstdDictionary()
4357 ZSTD_matchState_t* ms, in ZSTD_compress_insertDictionary() argument
4376 return ZSTD_loadDictionaryContent(ms, ls, ws, params, dict, dictSize, dtlm); in ZSTD_compress_insertDictionary()
4382 ms, ls, ws, params, dict, dictSize, dtlm); in ZSTD_compress_insertDictionary()
4385 assert(0); /* impossible */ in ZSTD_compress_insertDictionary()
4390 bs, ms, ws, params, dict, dictSize, dtlm, workspace); in ZSTD_compress_insertDictionary()
4406 size_t const dictContentSize = cdict ? cdict->dictContentSize : dictSize; in ZSTD_compressBegin_internal()
4407 DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog); in ZSTD_compressBegin_internal()
4409 assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); in ZSTD_compressBegin_internal()
4410 assert(!((dict) && (cdict))); /* either dict or cdict, not both */ in ZSTD_compressBegin_internal()
4412 && (cdict->dictContentSize > 0) in ZSTD_compressBegin_internal()
4414 || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER in ZSTD_compressBegin_internal()
4416 || cdict->compressionLevel == 0) in ZSTD_compressBegin_internal()
4417 && (params->attachDictPref != ZSTD_dictForceLoad) ) { in ZSTD_compressBegin_internal()
4426 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
4427 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent, in ZSTD_compressBegin_internal()
4428 cdict->dictContentSize, cdict->dictContentType, dtlm, in ZSTD_compressBegin_internal()
4429 cctx->entropyWorkspace) in ZSTD_compressBegin_internal()
4431 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
4432 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, dict, dictSize, in ZSTD_compressBegin_internal()
4433 dictContentType, dtlm, cctx->entropyWorkspace); in ZSTD_compressBegin_internal()
4435 assert(dictID <= UINT_MAX); in ZSTD_compressBegin_internal()
4436 cctx->dictID = (U32)dictID; in ZSTD_compressBegin_internal()
4437 cctx->dictContentSize = dictContentSize; in ZSTD_compressBegin_internal()
4450 DEBUGLOG(4, "ZSTD_compressBegin_advanced_internal: wlog=%u", params->cParams.windowLog); in ZSTD_compressBegin_advanced_internal()
4452 FORWARD_IF_ERROR( ZSTD_checkCParams(params->cParams) , ""); in ZSTD_compressBegin_advanced_internal()
4502 RETURN_ERROR_IF(cctx->stage == ZSTDcs_created, stage_wrong, "init missing"); in ZSTD_writeEpilogue()
4505 if (cctx->stage == ZSTDcs_init) { in ZSTD_writeEpilogue()
4506 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, 0, 0); in ZSTD_writeEpilogue()
4508 dstCapacity -= fhSize; in ZSTD_writeEpilogue()
4510 cctx->stage = ZSTDcs_ongoing; in ZSTD_writeEpilogue()
4513 if (cctx->stage != ZSTDcs_ending) { in ZSTD_writeEpilogue()
4519 dstCapacity -= ZSTD_blockHeaderSize; in ZSTD_writeEpilogue()
4522 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_writeEpilogue()
4523 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_writeEpilogue()
4530 cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ in ZSTD_writeEpilogue()
4531 return op-ostart; in ZSTD_writeEpilogue()
4549 endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize); in ZSTD_compressEnd()
4551 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressEnd()
4552 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressEnd()
4553 ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1); in ZSTD_compressEnd()
4556 cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1, in ZSTD_compressEnd()
4559 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressEnd()
4560 (unsigned)cctx->consumedSrcSize); in ZSTD_compressEnd()
4574 ZSTD_CCtxParams_init_internal(&cctx->simpleApiParams, ¶ms, ZSTD_NO_CLEVEL); in ZSTD_compress_advanced()
4579 &cctx->simpleApiParams); in ZSTD_compress_advanced()
4605 assert(params.fParams.contentSizeFlag == 1); in ZSTD_compress_usingDict()
4606 …ZSTD_CCtxParams_init_internal(&cctx->simpleApiParams, ¶ms, (compressionLevel == 0) ? ZSTD_CLEV… in ZSTD_compress_usingDict()
4609 …ss_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, &cctx->simpleApiParams); in ZSTD_compress_usingDict()
4618 assert(cctx != NULL); in ZSTD_compressCCtx()
4647 * in case we are using DDS with row-hash. */ in ZSTD_estimateCDictSize_advanced()
4665 return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict)) in ZSTD_sizeof_CDict()
4666 + ZSTD_cwksp_sizeof(&cdict->workspace); in ZSTD_sizeof_CDict()
4677 assert(!ZSTD_checkCParams(params.cParams)); in ZSTD_initCDict_internal()
4678 cdict->matchState.cParams = params.cParams; in ZSTD_initCDict_internal()
4679 cdict->matchState.dedicatedDictSearch = params.enableDedicatedDictSearch; in ZSTD_initCDict_internal()
4681 cdict->dictContent = dictBuffer; in ZSTD_initCDict_internal()
4683 …void *internalBuffer = ZSTD_cwksp_reserve_object(&cdict->workspace, ZSTD_cwksp_align(dictSize, siz… in ZSTD_initCDict_internal()
4685 cdict->dictContent = internalBuffer; in ZSTD_initCDict_internal()
4688 cdict->dictContentSize = dictSize; in ZSTD_initCDict_internal()
4689 cdict->dictContentType = dictContentType; in ZSTD_initCDict_internal()
4691 … cdict->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE); in ZSTD_initCDict_internal()
4694 /* Reset the state to no dictionary */ in ZSTD_initCDict_internal()
4695 ZSTD_reset_compressedBlockState(&cdict->cBlockState); in ZSTD_initCDict_internal()
4697 &cdict->matchState, in ZSTD_initCDict_internal()
4698 &cdict->workspace, in ZSTD_initCDict_internal()
4710 &cdict->cBlockState, &cdict->matchState, NULL, &cdict->workspace, in ZSTD_initCDict_internal()
4711 ¶ms, cdict->dictContent, cdict->dictContentSize, in ZSTD_initCDict_internal()
4712 dictContentType, ZSTD_dtlm_full, cdict->entropyWorkspace); in ZSTD_initCDict_internal()
4714 assert(dictID <= (size_t)(U32)-1); in ZSTD_initCDict_internal()
4715 cdict->dictID = (U32)dictID; in ZSTD_initCDict_internal()
4749 assert(cdict != NULL); in ZSTD_createCDict_advanced_internal()
4750 ZSTD_cwksp_move(&cdict->workspace, &ws); in ZSTD_createCDict_advanced_internal()
4751 cdict->customMem = customMem; in ZSTD_createCDict_advanced_internal()
4752 cdict->compressionLevel = ZSTD_NO_CLEVEL; /* signals advanced API usage */ in ZSTD_createCDict_advanced_internal()
4753 cdict->useRowMatchFinder = useRowMatchFinder; in ZSTD_createCDict_advanced_internal()
4799 /* Fall back to non-DDSS params */ in ZSTD_createCDict_advanced2()
4834 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel; in ZSTD_createCDict()
4845 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel; in ZSTD_createCDict_byReference()
4852 { ZSTD_customMem const cMem = cdict->customMem; in ZSTD_freeCDict()
4853 int cdictInWorkspace = ZSTD_cwksp_owns_buffer(&cdict->workspace, cdict); in ZSTD_freeCDict()
4854 ZSTD_cwksp_free(&cdict->workspace, cMem); in ZSTD_freeCDict()
4865 * Provided pointer must 8-bytes aligned.
4893 if ((size_t)workspace & 7) return NULL; /* 8-aligned */ in ZSTD_initStaticCDict()
4900 ZSTD_cwksp_move(&cdict->workspace, &ws); in ZSTD_initStaticCDict()
4910 cdict->useRowMatchFinder = useRowMatchFinder; in ZSTD_initStaticCDict()
4923 assert(cdict != NULL); in ZSTD_getCParamsFromCDict()
4924 return cdict->matchState.cParams; in ZSTD_getCParamsFromCDict()
4930 * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
4934 return cdict->dictID; in ZSTD_getDictID_fromCDict()
4952 … || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER in ZSTD_compressBegin_usingCDict_internal()
4954 || cdict->compressionLevel == 0 ) ? in ZSTD_compressBegin_usingCDict_internal()
4956 : ZSTD_getCParams(cdict->compressionLevel, in ZSTD_compressBegin_usingCDict_internal()
4958 cdict->dictContentSize); in ZSTD_compressBegin_usingCDict_internal()
4959 ZSTD_CCtxParams_init_internal(&cctxParams, ¶ms, cdict->compressionLevel); in ZSTD_compressBegin_usingCDict_internal()
4967 U32 const limitedSrcLog = limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1; in ZSTD_compressBegin_usingCDict_internal()
5068 return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ; in ZSTD_CStreamOutSize()
5106 assert(!ZSTD_isError(ZSTD_checkCParams(params->cParams))); in ZSTD_initCStream_internal()
5107 zcs->requestedParams = *params; in ZSTD_initCStream_internal()
5108 assert(!((dict) && (cdict))); /* either dict or cdict, not both */ in ZSTD_initCStream_internal()
5128 zcs->requestedParams.fParams = fParams; in ZSTD_initCStream_usingCDict_advanced()
5160 ZSTD_CCtxParams_setZstdParams(&zcs->requestedParams, ¶ms); in ZSTD_initCStream_advanced()
5202 size_t hintInSize = cctx->inBuffTarget - cctx->inBuffPos; in ZSTD_nextInputSizeHint()
5203 if (hintInSize==0) hintInSize = cctx->blockSize; in ZSTD_nextInputSizeHint()
5209 * non-static, because can be called from zstdmt_compress.c
5216 const char* const istart = (const char*)input->src; in ZSTD_compressStream_generic()
5217 const char* const iend = input->size != 0 ? istart + input->size : istart; in ZSTD_compressStream_generic()
5218 const char* ip = input->pos != 0 ? istart + input->pos : istart; in ZSTD_compressStream_generic()
5219 char* const ostart = (char*)output->dst; in ZSTD_compressStream_generic()
5220 char* const oend = output->size != 0 ? ostart + output->size : ostart; in ZSTD_compressStream_generic()
5221 char* op = output->pos != 0 ? ostart + output->pos : ostart; in ZSTD_compressStream_generic()
5226 if (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
5227 assert(zcs->inBuff != NULL); in ZSTD_compressStream_generic()
5228 assert(zcs->inBuffSize > 0); in ZSTD_compressStream_generic()
5230 if (zcs->appliedParams.outBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
5231 assert(zcs->outBuff != NULL); in ZSTD_compressStream_generic()
5232 assert(zcs->outBuffSize > 0); in ZSTD_compressStream_generic()
5234 assert(output->pos <= output->size); in ZSTD_compressStream_generic()
5235 assert(input->pos <= input->size); in ZSTD_compressStream_generic()
5236 assert((U32)flushMode <= (U32)ZSTD_e_end); in ZSTD_compressStream_generic()
5239 switch(zcs->streamStage) in ZSTD_compressStream_generic()
5246 && ( (size_t)(oend-op) >= ZSTD_compressBound(iend-ip) /* Enough output space */ in ZSTD_compressStream_generic()
5247 …|| zcs->appliedParams.outBufferMode == ZSTD_bm_stable) /* OR we are allowed to return dstSizeTooS… in ZSTD_compressStream_generic()
5248 && (zcs->inBuffPos == 0) ) { in ZSTD_compressStream_generic()
5251 op, oend-op, ip, iend-ip); in ZSTD_compressStream_generic()
5256 zcs->frameEnded = 1; in ZSTD_compressStream_generic()
5261 if (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_compressStream_generic()
5262 size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos; in ZSTD_compressStream_generic()
5264 zcs->inBuff + zcs->inBuffPos, toLoad, in ZSTD_compressStream_generic()
5265 ip, iend-ip); in ZSTD_compressStream_generic()
5266 zcs->inBuffPos += loaded; in ZSTD_compressStream_generic()
5270 && (zcs->inBuffPos < zcs->inBuffTarget) ) { in ZSTD_compressStream_generic()
5275 && (zcs->inBuffPos == zcs->inToCompress) ) { in ZSTD_compressStream_generic()
5282 { int const inputBuffered = (zcs->appliedParams.inBufferMode == ZSTD_bm_buffered); in ZSTD_compressStream_generic()
5285 size_t oSize = oend-op; in ZSTD_compressStream_generic()
5287 ? zcs->inBuffPos - zcs->inToCompress in ZSTD_compressStream_generic()
5288 : MIN((size_t)(iend - ip), zcs->blockSize); in ZSTD_compressStream_generic()
5289 … if (oSize >= ZSTD_compressBound(iSize) || zcs->appliedParams.outBufferMode == ZSTD_bm_stable) in ZSTD_compressStream_generic()
5292 cDst = zcs->outBuff, oSize = zcs->outBuffSize; in ZSTD_compressStream_generic()
5297 zcs->inBuff + zcs->inToCompress, iSize) : in ZSTD_compressStream_generic()
5299 zcs->inBuff + zcs->inToCompress, iSize); in ZSTD_compressStream_generic()
5301 zcs->frameEnded = lastBlock; in ZSTD_compressStream_generic()
5303 zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize; in ZSTD_compressStream_generic()
5304 if (zcs->inBuffTarget > zcs->inBuffSize) in ZSTD_compressStream_generic()
5305 zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize; in ZSTD_compressStream_generic()
5307 (unsigned)zcs->inBuffTarget, (unsigned)zcs->inBuffSize); in ZSTD_compressStream_generic()
5309 assert(zcs->inBuffTarget <= zcs->inBuffSize); in ZSTD_compressStream_generic()
5310 zcs->inToCompress = zcs->inBuffPos; in ZSTD_compressStream_generic()
5313 assert(flushMode == ZSTD_e_end /* Already validated */); in ZSTD_compressStream_generic()
5321 zcs->frameEnded = lastBlock; in ZSTD_compressStream_generic()
5323 assert(ip == iend); in ZSTD_compressStream_generic()
5327 if (zcs->frameEnded) { in ZSTD_compressStream_generic()
5334 zcs->outBuffContentSize = cSize; in ZSTD_compressStream_generic()
5335 zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
5336 zcs->streamStage = zcss_flush; /* pass-through to flush stage */ in ZSTD_compressStream_generic()
5341 assert(zcs->appliedParams.outBufferMode == ZSTD_bm_buffered); in ZSTD_compressStream_generic()
5342 { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; in ZSTD_compressStream_generic()
5343 size_t const flushed = ZSTD_limitCopy(op, (size_t)(oend-op), in ZSTD_compressStream_generic()
5344 zcs->outBuff + zcs->outBuffFlushedSize, toFlush); in ZSTD_compressStream_generic()
5346 (unsigned)toFlush, (unsigned)(oend-op), (unsigned)flushed); in ZSTD_compressStream_generic()
5349 zcs->outBuffFlushedSize += flushed; in ZSTD_compressStream_generic()
5352 assert(op==oend); in ZSTD_compressStream_generic()
5356 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
5357 if (zcs->frameEnded) { in ZSTD_compressStream_generic()
5363 zcs->streamStage = zcss_load; in ZSTD_compressStream_generic()
5368 assert(0); in ZSTD_compressStream_generic()
5372 input->pos = ip - istart; in ZSTD_compressStream_generic()
5373 output->pos = op - ostart; in ZSTD_compressStream_generic()
5374 if (zcs->frameEnded) return 0; in ZSTD_compressStream_generic()
5395 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
5396 cctx->expectedInBuffer = *input; in ZSTD_setBufferExpectations()
5398 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
5399 cctx->expectedOutBufferSize = output->size - output->pos; in ZSTD_setBufferExpectations()
5411 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
5412 ZSTD_inBuffer const expect = cctx->expectedInBuffer; in ZSTD_checkBufferStability()
5413 if (expect.src != input->src || expect.pos != input->pos || expect.size != input->size) in ZSTD_checkBufferStability()
5418 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
5419 size_t const outBufferSize = output->size - output->pos; in ZSTD_checkBufferStability()
5420 if (cctx->expectedOutBufferSize != outBufferSize) in ZSTD_checkBufferStability()
5429 ZSTD_CCtx_params params = cctx->requestedParams; in ZSTD_CCtx_init_compressStream2()
5430 ZSTD_prefixDict const prefixDict = cctx->prefixDict; in ZSTD_CCtx_init_compressStream2()
5432 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */ in ZSTD_CCtx_init_compressStream2()
5433 assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */ in ZSTD_CCtx_init_compressStream2()
5434 if (cctx->cdict && !cctx->localDict.cdict) { in ZSTD_CCtx_init_compressStream2()
5439 params.compressionLevel = cctx->cdict->compressionLevel; in ZSTD_CCtx_init_compressStream2()
5442 … if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = inSize + 1; /* auto-fix pledgedSrcSize */ in ZSTD_CCtx_init_compressStream2()
5446 : (cctx->cdict ? cctx->cdict->dictContentSize : 0); in ZSTD_CCtx_init_compressStream2()
5447 …STD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, ¶ms, cctx->pledgedSrcSizePlusOne… in ZSTD_CCtx_init_compressStream2()
5449 ¶ms, cctx->pledgedSrcSizePlusOne-1, in ZSTD_CCtx_init_compressStream2()
5457 { U64 const pledgedSrcSize = cctx->pledgedSrcSizePlusOne - 1; in ZSTD_CCtx_init_compressStream2()
5458 assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); in ZSTD_CCtx_init_compressStream2()
5461 cctx->cdict, in ZSTD_CCtx_init_compressStream2()
5464 assert(cctx->appliedParams.nbWorkers == 0); in ZSTD_CCtx_init_compressStream2()
5465 cctx->inToCompress = 0; in ZSTD_CCtx_init_compressStream2()
5466 cctx->inBuffPos = 0; in ZSTD_CCtx_init_compressStream2()
5467 if (cctx->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_CCtx_init_compressStream2()
5469 * it would require to add a 3-bytes null block to end frame in ZSTD_CCtx_init_compressStream2()
5471 cctx->inBuffTarget = cctx->blockSize + (cctx->blockSize == pledgedSrcSize); in ZSTD_CCtx_init_compressStream2()
5473 cctx->inBuffTarget = 0; in ZSTD_CCtx_init_compressStream2()
5475 cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0; in ZSTD_CCtx_init_compressStream2()
5476 cctx->streamStage = zcss_load; in ZSTD_CCtx_init_compressStream2()
5477 cctx->frameEnded = 0; in ZSTD_CCtx_init_compressStream2()
5489 RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer"); in ZSTD_compressStream2()
5490 RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer"); in ZSTD_compressStream2()
5492 assert(cctx != NULL); in ZSTD_compressStream2()
5495 if (cctx->streamStage == zcss_init) { in ZSTD_compressStream2()
5496 …FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size), "CompressStream2 initia… in ZSTD_compressStream2()
5506 return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */ in ZSTD_compressStream2()
5528 ZSTD_bufferMode_e const originalInBufferMode = cctx->requestedParams.inBufferMode; in ZSTD_compress2()
5529 ZSTD_bufferMode_e const originalOutBufferMode = cctx->requestedParams.outBufferMode; in ZSTD_compress2()
5533 cctx->requestedParams.inBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
5534 cctx->requestedParams.outBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
5541 /* Reset to the original values. */ in ZSTD_compress2()
5542 cctx->requestedParams.inBufferMode = originalInBufferMode; in ZSTD_compress2()
5543 cctx->requestedParams.outBufferMode = originalOutBufferMode; in ZSTD_compress2()
5546 assert(oPos == dstCapacity); in ZSTD_compress2()
5549 assert(iPos == srcSize); /* all input is expected consumed */ in ZSTD_compress2()
5588 offCode = STORE_REPCODE(2 - ll0); in ZSTD_finalizeOffCode()
5590 offCode = STORE_REPCODE(3 - ll0); in ZSTD_finalizeOffCode()
5591 } else if (ll0 && rawOffset == rep[0] - 1) { in ZSTD_finalizeOffCode()
5606 U32 idx = seqPos->idx; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5612 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5613 dictSize = (U32)cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5614 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5615 dictSize = (U32)cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5619 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5628 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5629 seqPos->posInSrc += litLength + matchLength; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5630 FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5631 cctx->appliedParams.cParams.windowLog, dictSize), in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5634 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5636 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5639 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5643 ZSTD_storeLastLiterals(&cctx->seqStore, ip, inSeqs[idx].litLength); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5645 seqPos->posInSrc += inSeqs[idx].litLength; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5648 seqPos->idx = idx+1; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
5652 /* Returns the number of bytes to move the current read position back by. Only non-zero
5668 U32 idx = seqPos->idx; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5669 U32 startPosInSequence = seqPos->posInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5670 U32 endPosInSequence = seqPos->posInSequence + (U32)blockSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5678 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5679 dictSize = cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5680 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5681 dictSize = cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5687 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5698 startPosInSequence -= litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5700 matchLength -= startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5702 litLength -= startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5705 endPosInSequence -= currSeq.litLength + currSeq.matchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5712 … currSeq.litLength + currSeq.matchLength - endPosInSequence, idx, endPosInSequence); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5715 litLength = startPosInSequence >= litLength ? 0 : litLength - startPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5716 firstHalfMatchLength = endPosInSequence - startPosInSequence - litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5717 … if (matchLength > blockSize && firstHalfMatchLength >= cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5719 … U32 secondHalfMatchLength = currSeq.matchLength + currSeq.litLength - endPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5720 if (secondHalfMatchLength < cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5722 … endPosInSequence -= cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5723 … bytesAdjustment = cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5724 firstHalfMatchLength -= bytesAdjustment; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5727 … /* Flag that we split the last match - after storing the sequence, exit the loop, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5736 bytesAdjustment = endPosInSequence - currSeq.litLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5751 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5752 seqPos->posInSrc += litLength + matchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5753 FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5754 cctx->appliedParams.cParams.windowLog, dictSize), in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5758 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5760 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5764 … assert(idx == inSeqsSize || endPosInSequence <= inSeqs[idx].litLength + inSeqs[idx].matchLength); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5765 seqPos->idx = idx; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5766 seqPos->posInSequence = endPosInSequence; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5767 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5769 iend -= bytesAdjustment; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5772 U32 lastLLSize = (U32)(iend - ip); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5773 assert(ip <= iend); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5775 ZSTD_storeLastLiterals(&cctx->seqStore, ip, lastLLSize); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5776 seqPos->posInSrc += lastLLSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
5788 assert(ZSTD_cParam_withinBounds(ZSTD_c_blockDelimiters, mode)); in ZSTD_selectSequenceCopier()
5794 assert(sequenceCopier != NULL); in ZSTD_selectSequenceCopier()
5798 /* Compress, block-by-block, all of the sequences given.
5818 …ZSTD_sequenceCopier const sequenceCopier = ZSTD_selectSequenceCopier(cctx->appliedParams.blockDeli… in ZSTD_compressSequences_internal()
5827 dstCapacity -= ZSTD_blockHeaderSize; in ZSTD_compressSequences_internal()
5834 lastBlock = remaining <= cctx->blockSize; in ZSTD_compressSequences_internal()
5835 blockSize = lastBlock ? (U32)remaining : (U32)cctx->blockSize; in ZSTD_compressSequences_internal()
5836 ZSTD_resetSeqStore(&cctx->seqStore); in ZSTD_compressSequences_internal()
5841 blockSize -= additionalByteAdjustment; in ZSTD_compressSequences_internal()
5851 remaining -= blockSize; in ZSTD_compressSequences_internal()
5852 dstCapacity -= cBlockSize; in ZSTD_compressSequences_internal()
5856 compressedSeqsSize = ZSTD_entropyCompressSeqStore(&cctx->seqStore, in ZSTD_compressSequences_internal()
5857 … &cctx->blockState.prevCBlock->entropy, &cctx->blockState.nextCBlock->entropy, in ZSTD_compressSequences_internal()
5858 &cctx->appliedParams, in ZSTD_compressSequences_internal()
5859 … op + ZSTD_blockHeaderSize /* Leave space for block header */, dstCapacity - ZSTD_blockHeaderSize, in ZSTD_compressSequences_internal()
5861 … cctx->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressSequences_internal()
5862 cctx->bmi2); in ZSTD_compressSequences_internal()
5866 if (!cctx->isFirstBlock && in ZSTD_compressSequences_internal()
5867 ZSTD_maybeRLE(&cctx->seqStore) && in ZSTD_compressSequences_internal()
5888 ZSTD_blockState_confirmRepcodesAndEntropyTables(&cctx->blockState); in ZSTD_compressSequences_internal()
5889 if (cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressSequences_internal()
5890 cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressSequences_internal()
5907 remaining -= blockSize; in ZSTD_compressSequences_internal()
5908 dstCapacity -= cBlockSize; in ZSTD_compressSequences_internal()
5909 cctx->isFirstBlock = 0; in ZSTD_compressSequences_internal()
5927 assert(cctx != NULL); in ZSTD_compressSequences()
5930 …frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->appliedParams, srcSize, cctx->dict… in ZSTD_compressSequences()
5932 dstCapacity -= frameHeaderSize; in ZSTD_compressSequences()
5934 if (cctx->appliedParams.fParams.checksumFlag && srcSize) { in ZSTD_compressSequences()
5935 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compressSequences()
5944 dstCapacity -= compressedBlocksSize; in ZSTD_compressSequences()
5946 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_compressSequences()
5947 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_compressSequences()
5974 if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */ in ZSTD_endStream()
5976 { size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE; in ZSTD_endStream()
5977 …size_t const checksumSize = (size_t)(zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag… in ZSTD_endStream()
5985 /*-===== Pre-defined compression levels =====-*/
5989 int ZSTD_minCLevel(void) { return (int)-ZSTD_TARGETLENGTH_MAX; } in ZSTD_minCLevel()
6016 return (cParams->strategy >= ZSTD_greedy) in ZSTD_dedicatedDictSearch_isSupported()
6017 && (cParams->strategy <= ZSTD_lazy2) in ZSTD_dedicatedDictSearch_isSupported()
6018 && (cParams->hashLog > cParams->chainLog) in ZSTD_dedicatedDictSearch_isSupported()
6019 && (cParams->chainLog <= 24); in ZSTD_dedicatedDictSearch_isSupported()
6029 switch (cParams->strategy) { in ZSTD_dedicatedDictSearch_revertCParams()
6036 cParams->hashLog -= ZSTD_LAZY_DDSS_BUCKET_LOG; in ZSTD_dedicatedDictSearch_revertCParams()
6037 if (cParams->hashLog < ZSTD_HASHLOG_MIN) { in ZSTD_dedicatedDictSearch_revertCParams()
6038 cParams->hashLog = ZSTD_HASHLOG_MIN; in ZSTD_dedicatedDictSearch_revertCParams()
6060 assert(0); in ZSTD_getCParamRowSize()
6092 cp.targetLength = (unsigned)(-clampedCompressionLevel); in ZSTD_getCParams_internal()