14#include "../common/allocations.h"
15#include "../common/zstd_deps.h"
16#include "../common/mem.h"
18#define FSE_STATIC_LINKING_ONLY
19#include "../common/fse.h"
20#include "../common/huf.h"
30#include "../common/bits.h"
41#ifndef ZSTD_COMPRESS_HEAPMODE
42# define ZSTD_COMPRESS_HEAPMODE 0
54#ifndef ZSTD_HASHLOG3_MAX
55# define ZSTD_HASHLOG3_MAX 17
71 if (r==0)
return ERROR(srcSize_wrong);
101static void ZSTD_initCCtx(
ZSTD_CCtx* cctx, ZSTD_customMem memManager)
117 if ((!customMem.customAlloc) ^ (!customMem.customFree))
return NULL;
119 if (!cctx)
return NULL;
120 ZSTD_initCCtx(cctx, customMem);
129 if (workspaceSize <=
sizeof(
ZSTD_CCtx))
return NULL;
130 if ((
size_t)workspace & 7)
return NULL;
134 if (cctx == NULL)
return NULL;
152static void ZSTD_clearAllDicts(
ZSTD_CCtx* cctx)
165 return bufferSize + cdictSize;
168static void ZSTD_freeCCtxContent(
ZSTD_CCtx* cctx)
172 ZSTD_clearAllDicts(cctx);
173#ifdef ZSTD_MULTITHREAD
181 DEBUGLOG(3,
"ZSTD_freeCCtx (address: %p)", (
void*)cctx);
182 if (cctx==NULL)
return 0;
184 "not compatible with static CCtx");
186 ZSTD_freeCCtxContent(cctx);
193static size_t ZSTD_sizeof_mtctx(
const ZSTD_CCtx* cctx)
195#ifdef ZSTD_MULTITHREAD
206 if (cctx==NULL)
return 0;
211 + ZSTD_sizeof_mtctx(cctx);
223static int ZSTD_rowMatchFinderSupported(
const ZSTD_strategy strategy) {
230static int ZSTD_rowMatchFinderUsed(
const ZSTD_strategy strategy,
const ZSTD_paramSwitch_e mode) {
231 assert(mode != ZSTD_ps_auto);
232 return ZSTD_rowMatchFinderSupported(strategy) && (
mode == ZSTD_ps_enable);
236static ZSTD_paramSwitch_e ZSTD_resolveRowMatchFinderMode(ZSTD_paramSwitch_e mode,
237 const ZSTD_compressionParameters*
const cParams) {
238#if defined(ZSTD_ARCH_X86_SSE2) || defined(ZSTD_ARCH_ARM_NEON)
239 int const kHasSIMD128 = 1;
241 int const kHasSIMD128 = 0;
243 if (mode != ZSTD_ps_auto)
return mode;
244 mode = ZSTD_ps_disable;
245 if (!ZSTD_rowMatchFinderSupported(cParams->strategy))
return mode;
247 if (cParams->windowLog > 14)
mode = ZSTD_ps_enable;
249 if (cParams->windowLog > 17)
mode = ZSTD_ps_enable;
255static ZSTD_paramSwitch_e ZSTD_resolveBlockSplitterMode(ZSTD_paramSwitch_e mode,
256 const ZSTD_compressionParameters*
const cParams) {
257 if (mode != ZSTD_ps_auto)
return mode;
258 return (cParams->strategy >=
ZSTD_btopt && cParams->windowLog >= 17) ? ZSTD_ps_enable : ZSTD_ps_disable;
262static int ZSTD_allocateChainTable(
const ZSTD_strategy strategy,
263 const ZSTD_paramSwitch_e useRowMatchFinder,
264 const U32 forDDSDict) {
265 assert(useRowMatchFinder != ZSTD_ps_auto);
269 return forDDSDict || ((strategy !=
ZSTD_fast) && !ZSTD_rowMatchFinderUsed(strategy, useRowMatchFinder));
276static ZSTD_paramSwitch_e ZSTD_resolveEnableLdm(ZSTD_paramSwitch_e mode,
277 const ZSTD_compressionParameters*
const cParams) {
278 if (mode != ZSTD_ps_auto)
return mode;
279 return (cParams->strategy >=
ZSTD_btopt && cParams->windowLog >= 27) ? ZSTD_ps_enable : ZSTD_ps_disable;
282static int ZSTD_resolveExternalSequenceValidation(
int mode) {
287static size_t ZSTD_resolveMaxBlockSize(
size_t maxBlockSize) {
288 if (maxBlockSize == 0) {
295static ZSTD_paramSwitch_e ZSTD_resolveExternalRepcodeSearch(ZSTD_paramSwitch_e value,
int cLevel) {
296 if (value != ZSTD_ps_auto)
return value;
298 return ZSTD_ps_disable;
300 return ZSTD_ps_enable;
306static int ZSTD_CDictIndicesAreTagged(
const ZSTD_compressionParameters*
const cParams) {
310static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
311 ZSTD_compressionParameters cParams)
313 ZSTD_CCtx_params cctxParams;
316 cctxParams.cParams = cParams;
319 cctxParams.ldmParams.enableLdm = ZSTD_resolveEnableLdm(cctxParams.ldmParams.enableLdm, &cParams);
320 if (cctxParams.ldmParams.enableLdm == ZSTD_ps_enable) {
322 assert(cctxParams.ldmParams.hashLog >= cctxParams.ldmParams.bucketSizeLog);
323 assert(cctxParams.ldmParams.hashRateLog < 32);
325 cctxParams.useBlockSplitter = ZSTD_resolveBlockSplitterMode(cctxParams.useBlockSplitter, &cParams);
326 cctxParams.useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(cctxParams.useRowMatchFinder, &cParams);
327 cctxParams.validateSequences = ZSTD_resolveExternalSequenceValidation(cctxParams.validateSequences);
328 cctxParams.maxBlockSize = ZSTD_resolveMaxBlockSize(cctxParams.maxBlockSize);
329 cctxParams.searchForExternalRepcodes = ZSTD_resolveExternalRepcodeSearch(cctxParams.searchForExternalRepcodes,
330 cctxParams.compressionLevel);
335static ZSTD_CCtx_params* ZSTD_createCCtxParams_advanced(
336 ZSTD_customMem customMem)
338 ZSTD_CCtx_params* params;
339 if ((!customMem.customAlloc) ^ (!customMem.customFree))
return NULL;
341 sizeof(ZSTD_CCtx_params), customMem);
342 if (!params) {
return NULL; }
344 params->customMem = customMem;
350 return ZSTD_createCCtxParams_advanced(ZSTD_defaultCMem);
355 if (params == NULL) {
return 0; }
368 cctxParams->compressionLevel = compressionLevel;
369 cctxParams->fParams.contentSizeFlag = 1;
373#define ZSTD_NO_CLEVEL 0
380ZSTD_CCtxParams_init_internal(ZSTD_CCtx_params* cctxParams,
381 const ZSTD_parameters* params,
382 int compressionLevel)
386 cctxParams->cParams = params->cParams;
387 cctxParams->fParams = params->fParams;
391 cctxParams->compressionLevel = compressionLevel;
392 cctxParams->useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(cctxParams->useRowMatchFinder, ¶ms->cParams);
393 cctxParams->useBlockSplitter = ZSTD_resolveBlockSplitterMode(cctxParams->useBlockSplitter, ¶ms->cParams);
394 cctxParams->ldmParams.enableLdm = ZSTD_resolveEnableLdm(cctxParams->ldmParams.enableLdm, ¶ms->cParams);
395 cctxParams->validateSequences = ZSTD_resolveExternalSequenceValidation(cctxParams->validateSequences);
396 cctxParams->maxBlockSize = ZSTD_resolveMaxBlockSize(cctxParams->maxBlockSize);
397 cctxParams->searchForExternalRepcodes = ZSTD_resolveExternalRepcodeSearch(cctxParams->searchForExternalRepcodes, compressionLevel);
398 DEBUGLOG(4,
"ZSTD_CCtxParams_init_internal: useRowMatchFinder=%d, useBlockSplitter=%d ldm=%d",
399 cctxParams->useRowMatchFinder, cctxParams->useBlockSplitter, cctxParams->ldmParams.enableLdm);
406 ZSTD_CCtxParams_init_internal(cctxParams, ¶ms,
ZSTD_NO_CLEVEL);
414static void ZSTD_CCtxParams_setZstdParams(
415 ZSTD_CCtx_params* cctxParams,
const ZSTD_parameters* params)
418 cctxParams->cParams = params->cParams;
419 cctxParams->fParams = params->fParams;
489#ifdef ZSTD_MULTITHREAD
498#ifdef ZSTD_MULTITHREAD
506#ifdef ZSTD_MULTITHREAD
515 case ZSTD_c_enableDedicatedDictSearch:
536 bounds.
lowerBound = ZSTD_LDM_BUCKETSIZELOG_MIN;
537 bounds.
upperBound = ZSTD_LDM_BUCKETSIZELOG_MAX;
546 case ZSTD_c_rsyncable:
551 case ZSTD_c_forceMaxWindow :
562 case ZSTD_c_forceAttachDict:
568 case ZSTD_c_literalCompressionMode:
569 ZSTD_STATIC_ASSERT(ZSTD_ps_auto < ZSTD_ps_enable && ZSTD_ps_enable < ZSTD_ps_disable);
575 bounds.
lowerBound = ZSTD_TARGETCBLOCKSIZE_MIN;
576 bounds.
upperBound = ZSTD_TARGETCBLOCKSIZE_MAX;
579 case ZSTD_c_srcSizeHint:
584 case ZSTD_c_stableInBuffer:
585 case ZSTD_c_stableOutBuffer:
590 case ZSTD_c_blockDelimiters:
591 bounds.
lowerBound = (int)ZSTD_sf_noBlockDelimiters;
592 bounds.
upperBound = (int)ZSTD_sf_explicitBlockDelimiters;
595 case ZSTD_c_validateSequences:
600 case ZSTD_c_useBlockSplitter:
605 case ZSTD_c_useRowMatchFinder:
610 case ZSTD_c_deterministicRefPrefix:
615 case ZSTD_c_prefetchCDictTables:
620 case ZSTD_c_enableSeqProducerFallback:
625 case ZSTD_c_maxBlockSize:
630 case ZSTD_c_searchForExternalRepcodes:
644static size_t ZSTD_cParam_clampBounds(
ZSTD_cParameter cParam,
int* value)
653#define BOUNDCHECK(cParam, val) \
655 RETURN_ERROR_IF(!ZSTD_cParam_withinBounds(cParam,val), \
656 parameter_outOfBound, "Param out of bounds"); \
678 case ZSTD_c_forceMaxWindow :
682 case ZSTD_c_rsyncable:
683 case ZSTD_c_enableDedicatedDictSearch:
689 case ZSTD_c_forceAttachDict:
690 case ZSTD_c_literalCompressionMode:
692 case ZSTD_c_srcSizeHint:
693 case ZSTD_c_stableInBuffer:
694 case ZSTD_c_stableOutBuffer:
695 case ZSTD_c_blockDelimiters:
696 case ZSTD_c_validateSequences:
697 case ZSTD_c_useBlockSplitter:
698 case ZSTD_c_useRowMatchFinder:
699 case ZSTD_c_deterministicRefPrefix:
700 case ZSTD_c_prefetchCDictTables:
701 case ZSTD_c_enableSeqProducerFallback:
702 case ZSTD_c_maxBlockSize:
703 case ZSTD_c_searchForExternalRepcodes:
711 DEBUGLOG(4,
"ZSTD_CCtx_setParameter (%i, %i)", (
int)param, value);
713 if (ZSTD_isUpdateAuthorized(param)) {
716 RETURN_ERROR(stage_wrong,
"can only set params in cctx init stage");
723 "MT not compatible with static alloc");
739 case ZSTD_c_forceMaxWindow:
740 case ZSTD_c_forceAttachDict:
741 case ZSTD_c_literalCompressionMode:
744 case ZSTD_c_rsyncable:
745 case ZSTD_c_enableDedicatedDictSearch:
751 case ZSTD_c_srcSizeHint:
752 case ZSTD_c_stableInBuffer:
753 case ZSTD_c_stableOutBuffer:
754 case ZSTD_c_blockDelimiters:
755 case ZSTD_c_validateSequences:
756 case ZSTD_c_useBlockSplitter:
757 case ZSTD_c_useRowMatchFinder:
758 case ZSTD_c_deterministicRefPrefix:
759 case ZSTD_c_prefetchCDictTables:
760 case ZSTD_c_enableSeqProducerFallback:
761 case ZSTD_c_maxBlockSize:
762 case ZSTD_c_searchForExternalRepcodes:
765 default:
RETURN_ERROR(parameter_unsupported,
"unknown parameter");
773 DEBUGLOG(4,
"ZSTD_CCtxParams_setParameter (%i, %i)", (
int)param, value);
778 CCtxParams->format = (ZSTD_format_e)value;
779 return (
size_t)CCtxParams->format;
786 CCtxParams->compressionLevel = value;
787 if (CCtxParams->compressionLevel >= 0)
return (
size_t)CCtxParams->compressionLevel;
794 CCtxParams->cParams.windowLog = (
U32)value;
795 return CCtxParams->cParams.windowLog;
800 CCtxParams->cParams.hashLog = (
U32)value;
801 return CCtxParams->cParams.hashLog;
806 CCtxParams->cParams.chainLog = (
U32)value;
807 return CCtxParams->cParams.chainLog;
812 CCtxParams->cParams.searchLog = (
U32)value;
813 return (
size_t)value;
818 CCtxParams->cParams.minMatch = (
U32)value;
819 return CCtxParams->cParams.minMatch;
823 CCtxParams->cParams.targetLength = (
U32)value;
824 return CCtxParams->cParams.targetLength;
830 return (
size_t)CCtxParams->cParams.strategy;
834 DEBUGLOG(4,
"set content size flag = %u", (value!=0));
835 CCtxParams->fParams.contentSizeFlag = value != 0;
836 return (
size_t)CCtxParams->fParams.contentSizeFlag;
840 CCtxParams->fParams.checksumFlag = value != 0;
841 return (
size_t)CCtxParams->fParams.checksumFlag;
844 DEBUGLOG(4,
"set dictIDFlag = %u", (value!=0));
845 CCtxParams->fParams.noDictIDFlag = !value;
846 return !CCtxParams->fParams.noDictIDFlag;
848 case ZSTD_c_forceMaxWindow :
849 CCtxParams->forceWindow = (value != 0);
850 return (
size_t)CCtxParams->forceWindow;
852 case ZSTD_c_forceAttachDict : {
853 const ZSTD_dictAttachPref_e pref = (ZSTD_dictAttachPref_e)value;
854 BOUNDCHECK(ZSTD_c_forceAttachDict, (
int)pref);
855 CCtxParams->attachDictPref = pref;
856 return CCtxParams->attachDictPref;
859 case ZSTD_c_literalCompressionMode : {
860 const ZSTD_paramSwitch_e lcm = (ZSTD_paramSwitch_e)value;
861 BOUNDCHECK(ZSTD_c_literalCompressionMode, (
int)lcm);
862 CCtxParams->literalCompressionMode = lcm;
863 return CCtxParams->literalCompressionMode;
867#ifndef ZSTD_MULTITHREAD
868 RETURN_ERROR_IF(value!=0, parameter_unsupported,
"not compiled with multithreading");
872 CCtxParams->nbWorkers = value;
873 return (
size_t)(CCtxParams->nbWorkers);
877#ifndef ZSTD_MULTITHREAD
878 RETURN_ERROR_IF(value!=0, parameter_unsupported,
"not compiled with multithreading");
886 CCtxParams->jobSize = value;
887 return CCtxParams->jobSize;
891#ifndef ZSTD_MULTITHREAD
892 RETURN_ERROR_IF(value!=0, parameter_unsupported,
"not compiled with multithreading");
896 CCtxParams->overlapLog = value;
897 return (
size_t)CCtxParams->overlapLog;
900 case ZSTD_c_rsyncable :
901#ifndef ZSTD_MULTITHREAD
902 RETURN_ERROR_IF(value!=0, parameter_unsupported,
"not compiled with multithreading");
906 CCtxParams->rsyncable = value;
907 return (
size_t)CCtxParams->rsyncable;
910 case ZSTD_c_enableDedicatedDictSearch :
911 CCtxParams->enableDedicatedDictSearch = (value!=0);
912 return (
size_t)CCtxParams->enableDedicatedDictSearch;
916 CCtxParams->ldmParams.enableLdm = (ZSTD_paramSwitch_e)value;
917 return CCtxParams->ldmParams.enableLdm;
922 CCtxParams->ldmParams.hashLog = (
U32)value;
923 return CCtxParams->ldmParams.hashLog;
928 CCtxParams->ldmParams.minMatchLength = (
U32)value;
929 return CCtxParams->ldmParams.minMatchLength;
934 CCtxParams->ldmParams.bucketSizeLog = (
U32)value;
935 return CCtxParams->ldmParams.bucketSizeLog;
940 CCtxParams->ldmParams.hashRateLog = (
U32)value;
941 return CCtxParams->ldmParams.hashRateLog;
945 value =
MAX(value, ZSTD_TARGETCBLOCKSIZE_MIN);
948 CCtxParams->targetCBlockSize = (
U32)value;
949 return CCtxParams->targetCBlockSize;
951 case ZSTD_c_srcSizeHint :
954 CCtxParams->srcSizeHint = value;
955 return (
size_t)CCtxParams->srcSizeHint;
957 case ZSTD_c_stableInBuffer:
960 return CCtxParams->inBufferMode;
962 case ZSTD_c_stableOutBuffer:
965 return CCtxParams->outBufferMode;
967 case ZSTD_c_blockDelimiters:
969 CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value;
970 return CCtxParams->blockDelimiters;
972 case ZSTD_c_validateSequences:
974 CCtxParams->validateSequences = value;
975 return (
size_t)CCtxParams->validateSequences;
977 case ZSTD_c_useBlockSplitter:
979 CCtxParams->useBlockSplitter = (ZSTD_paramSwitch_e)value;
980 return CCtxParams->useBlockSplitter;
982 case ZSTD_c_useRowMatchFinder:
984 CCtxParams->useRowMatchFinder = (ZSTD_paramSwitch_e)value;
985 return CCtxParams->useRowMatchFinder;
987 case ZSTD_c_deterministicRefPrefix:
988 BOUNDCHECK(ZSTD_c_deterministicRefPrefix, value);
989 CCtxParams->deterministicRefPrefix = !!value;
990 return (
size_t)CCtxParams->deterministicRefPrefix;
992 case ZSTD_c_prefetchCDictTables:
993 BOUNDCHECK(ZSTD_c_prefetchCDictTables, value);
994 CCtxParams->prefetchCDictTables = (ZSTD_paramSwitch_e)value;
995 return CCtxParams->prefetchCDictTables;
997 case ZSTD_c_enableSeqProducerFallback:
998 BOUNDCHECK(ZSTD_c_enableSeqProducerFallback, value);
999 CCtxParams->enableMatchFinderFallback = value;
1000 return (
size_t)CCtxParams->enableMatchFinderFallback;
1002 case ZSTD_c_maxBlockSize:
1005 CCtxParams->maxBlockSize = value;
1006 return CCtxParams->maxBlockSize;
1008 case ZSTD_c_searchForExternalRepcodes:
1009 BOUNDCHECK(ZSTD_c_searchForExternalRepcodes, value);
1010 CCtxParams->searchForExternalRepcodes = (ZSTD_paramSwitch_e)value;
1011 return CCtxParams->searchForExternalRepcodes;
1013 default:
RETURN_ERROR(parameter_unsupported,
"unknown parameter");
1023 ZSTD_CCtx_params
const* CCtxParams,
ZSTD_cParameter param,
int* value)
1027 case ZSTD_c_format :
1028 *value = CCtxParams->format;
1031 *value = CCtxParams->compressionLevel;
1034 *value = (int)CCtxParams->cParams.windowLog;
1037 *value = (
int)CCtxParams->cParams.hashLog;
1040 *value = (int)CCtxParams->cParams.chainLog;
1043 *value = CCtxParams->cParams.searchLog;
1046 *value = CCtxParams->cParams.minMatch;
1049 *value = CCtxParams->cParams.targetLength;
1052 *value = (
unsigned)CCtxParams->cParams.strategy;
1055 *value = CCtxParams->fParams.contentSizeFlag;
1058 *value = CCtxParams->fParams.checksumFlag;
1061 *value = !CCtxParams->fParams.noDictIDFlag;
1063 case ZSTD_c_forceMaxWindow :
1064 *value = CCtxParams->forceWindow;
1066 case ZSTD_c_forceAttachDict :
1067 *value = CCtxParams->attachDictPref;
1069 case ZSTD_c_literalCompressionMode :
1070 *value = CCtxParams->literalCompressionMode;
1073#ifndef ZSTD_MULTITHREAD
1074 assert(CCtxParams->nbWorkers == 0);
1076 *value = CCtxParams->nbWorkers;
1079#ifndef ZSTD_MULTITHREAD
1080 RETURN_ERROR(parameter_unsupported,
"not compiled with multithreading");
1082 assert(CCtxParams->jobSize <= INT_MAX);
1083 *value = (int)CCtxParams->jobSize;
1087#ifndef ZSTD_MULTITHREAD
1088 RETURN_ERROR(parameter_unsupported,
"not compiled with multithreading");
1090 *value = CCtxParams->overlapLog;
1093 case ZSTD_c_rsyncable :
1094#ifndef ZSTD_MULTITHREAD
1095 RETURN_ERROR(parameter_unsupported,
"not compiled with multithreading");
1097 *value = CCtxParams->rsyncable;
1100 case ZSTD_c_enableDedicatedDictSearch :
1101 *value = CCtxParams->enableDedicatedDictSearch;
1104 *value = CCtxParams->ldmParams.enableLdm;
1107 *value = CCtxParams->ldmParams.hashLog;
1110 *value = CCtxParams->ldmParams.minMatchLength;
1113 *value = CCtxParams->ldmParams.bucketSizeLog;
1116 *value = CCtxParams->ldmParams.hashRateLog;
1119 *value = (int)CCtxParams->targetCBlockSize;
1121 case ZSTD_c_srcSizeHint :
1122 *value = (
int)CCtxParams->srcSizeHint;
1124 case ZSTD_c_stableInBuffer :
1125 *value = (int)CCtxParams->inBufferMode;
1127 case ZSTD_c_stableOutBuffer :
1128 *value = (
int)CCtxParams->outBufferMode;
1130 case ZSTD_c_blockDelimiters :
1131 *value = (int)CCtxParams->blockDelimiters;
1133 case ZSTD_c_validateSequences :
1134 *value = (
int)CCtxParams->validateSequences;
1136 case ZSTD_c_useBlockSplitter :
1137 *value = (int)CCtxParams->useBlockSplitter;
1139 case ZSTD_c_useRowMatchFinder :
1140 *value = (
int)CCtxParams->useRowMatchFinder;
1142 case ZSTD_c_deterministicRefPrefix:
1143 *value = (int)CCtxParams->deterministicRefPrefix;
1145 case ZSTD_c_prefetchCDictTables:
1146 *value = (
int)CCtxParams->prefetchCDictTables;
1148 case ZSTD_c_enableSeqProducerFallback:
1149 *value = CCtxParams->enableMatchFinderFallback;
1151 case ZSTD_c_maxBlockSize:
1152 *value = (int)CCtxParams->maxBlockSize;
1154 case ZSTD_c_searchForExternalRepcodes:
1155 *value = (
int)CCtxParams->searchForExternalRepcodes;
1157 default:
RETURN_ERROR(parameter_unsupported,
"unknown parameter");
1170 ZSTD_CCtx* cctx,
const ZSTD_CCtx_params* params)
1172 DEBUGLOG(4,
"ZSTD_CCtx_setParametersUsingCCtxParams");
1174 "The context is in the wrong stage!");
1176 "Can't override parameters with cdict attached (some must "
1177 "be inherited from the cdict).");
1186 DEBUGLOG(4,
"ZSTD_CCtx_setCParams");
1202 DEBUGLOG(4,
"ZSTD_CCtx_setFParams");
1211 DEBUGLOG(4,
"ZSTD_CCtx_setParams");
1223 DEBUGLOG(4,
"ZSTD_CCtx_setPledgedSrcSize to %llu bytes", pledgedSrcSize);
1225 "Can't set pledgedSrcSize when not in init stage.");
1230static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(
1231 int const compressionLevel,
1232 size_t const dictSize);
1233static int ZSTD_dedicatedDictSearch_isSupported(
1234 const ZSTD_compressionParameters* cParams);
1235static void ZSTD_dedicatedDictSearch_revertCParams(
1236 ZSTD_compressionParameters* cParams);
1243static size_t ZSTD_initLocalDict(
ZSTD_CCtx* cctx)
1246 if (dl->
dict == NULL) {
1253 if (dl->
cdict != NULL) {
1276 const void* dict,
size_t dictSize,
1277 ZSTD_dictLoadMethod_e dictLoadMethod,
1278 ZSTD_dictContentType_e dictContentType)
1280 DEBUGLOG(4,
"ZSTD_CCtx_loadDictionary_advanced (size: %u)", (
U32)dictSize);
1282 "Can't load a dictionary when cctx is not in init stage.");
1283 ZSTD_clearAllDicts(cctx);
1284 if (dict == NULL || dictSize == 0)
1286 if (dictLoadMethod == ZSTD_dlm_byRef) {
1292 "static CCtx can't allocate for an internal copy of dictionary");
1295 "allocation failed for dictionary content");
1306 ZSTD_CCtx* cctx,
const void* dict,
size_t dictSize)
1309 cctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto);
1315 cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto);
1322 "Can't ref a dict when ctx not in init stage.");
1324 ZSTD_clearAllDicts(cctx);
1325 cctx->
cdict = cdict;
1332 "Can't ref a pool when ctx not in init stage.");
1343 ZSTD_CCtx* cctx,
const void* prefix,
size_t prefixSize, ZSTD_dictContentType_e dictContentType)
1346 "Can't ref a prefix when ctx not in init stage.");
1347 ZSTD_clearAllDicts(cctx);
1348 if (prefix != NULL && prefixSize > 0) {
1368 "Reset parameters is only possible during init stage.");
1369 ZSTD_clearAllDicts(cctx);
1394static ZSTD_compressionParameters
1395ZSTD_clampCParams(ZSTD_compressionParameters cParams)
1397# define CLAMP_TYPE(cParam, val, type) \
1399 ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
1400 if ((int)val<bounds.lowerBound) val=(type)bounds.lowerBound; \
1401 else if ((int)val>bounds.upperBound) val=(type)bounds.upperBound; \
1403# define CLAMP(cParam, val) CLAMP_TYPE(cParam, val, unsigned)
1419 return hashLog - btScale;
1430static U32 ZSTD_dictAndWindowLog(
U32 windowLog,
U64 srcSize,
U64 dictSize)
1432 const U64 maxWindowSize = 1ULL << ZSTD_WINDOWLOG_MAX;
1434 if (dictSize == 0) {
1437 assert(windowLog <= ZSTD_WINDOWLOG_MAX);
1440 U64 const windowSize = 1ULL << windowLog;
1441 U64 const dictAndWindowSize = dictSize + windowSize;
1446 if (windowSize >= dictSize + srcSize) {
1448 }
else if (dictAndWindowSize >= maxWindowSize) {
1449 return ZSTD_WINDOWLOG_MAX;
1463static ZSTD_compressionParameters
1464ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
1465 unsigned long long srcSize,
1468 ZSTD_paramSwitch_e useRowMatchFinder)
1470 const U64 minSrcSize = 513;
1471 const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
1476#ifdef ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR
1484#ifdef ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR
1489#ifdef ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR
1494#ifdef ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR
1499#ifdef ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR
1504#ifdef ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR
1509#ifdef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
1512 cPar.targetLength = 0;
1529 srcSize = minSrcSize;
1544 if ( (srcSize <= maxWindowResize)
1545 && (dictSize <= maxWindowResize) ) {
1546 U32 const tSize = (
U32)(srcSize + dictSize);
1547 static U32 const hashSizeMin = 1 << ZSTD_HASHLOG_MIN;
1548 U32 const srcLog = (tSize < hashSizeMin) ? ZSTD_HASHLOG_MIN :
1550 if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
1553 U32 const dictAndWindowLog = ZSTD_dictAndWindowLog(cPar.windowLog, (
U64)srcSize, (
U64)dictSize);
1555 if (cPar.hashLog > dictAndWindowLog+1) cPar.hashLog = dictAndWindowLog+1;
1556 if (cycleLog > dictAndWindowLog)
1557 cPar.chainLog -= (cycleLog - dictAndWindowLog);
1568 if (cPar.hashLog > maxShortCacheHashLog) {
1569 cPar.hashLog = maxShortCacheHashLog;
1571 if (cPar.chainLog > maxShortCacheHashLog) {
1572 cPar.chainLog = maxShortCacheHashLog;
1582 if (useRowMatchFinder == ZSTD_ps_auto)
1583 useRowMatchFinder = ZSTD_ps_enable;
1588 if (ZSTD_rowMatchFinderUsed(cPar.strategy, useRowMatchFinder)) {
1590 U32 const rowLog =
BOUNDED(4, cPar.searchLog, 6);
1592 U32 const maxHashLog = maxRowHashLog + rowLog;
1593 assert(cPar.hashLog >= rowLog);
1594 if (cPar.hashLog > maxHashLog) {
1595 cPar.hashLog = maxHashLog;
1602ZSTD_compressionParameters
1604 unsigned long long srcSize,
1607 cPar = ZSTD_clampCParams(cPar);
1609 return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize,
ZSTD_cpm_unknown, ZSTD_ps_auto);
1612static ZSTD_compressionParameters ZSTD_getCParams_internal(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize,
ZSTD_cParamMode_e mode);
1613static ZSTD_parameters ZSTD_getParams_internal(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize,
ZSTD_cParamMode_e mode);
1615static void ZSTD_overrideCParams(
1616 ZSTD_compressionParameters* cParams,
1617 const ZSTD_compressionParameters* overrides)
1619 if (overrides->windowLog) cParams->windowLog = overrides->windowLog;
1620 if (overrides->hashLog) cParams->hashLog = overrides->hashLog;
1621 if (overrides->chainLog) cParams->chainLog = overrides->chainLog;
1622 if (overrides->searchLog) cParams->searchLog = overrides->searchLog;
1623 if (overrides->minMatch) cParams->minMatch = overrides->minMatch;
1624 if (overrides->targetLength) cParams->targetLength = overrides->targetLength;
1625 if (overrides->strategy) cParams->strategy = overrides->strategy;
1631 ZSTD_compressionParameters cParams;
1633 srcSizeHint = CCtxParams->srcSizeHint;
1635 cParams = ZSTD_getCParams_internal(CCtxParams->compressionLevel, srcSizeHint, dictSize, mode);
1637 ZSTD_overrideCParams(&cParams, &CCtxParams->cParams);
1640 return ZSTD_adjustCParams_internal(cParams, srcSizeHint, dictSize, mode, CCtxParams->useRowMatchFinder);
1644ZSTD_sizeof_matchState(
const ZSTD_compressionParameters*
const cParams,
1645 const ZSTD_paramSwitch_e useRowMatchFinder,
1646 const U32 enableDedicatedDictSearch,
1650 size_t const chainSize = ZSTD_allocateChainTable(cParams->strategy, useRowMatchFinder, enableDedicatedDictSearch && !forCCtx)
1651 ? ((size_t)1 << cParams->chainLog)
1653 size_t const hSize = ((size_t)1) << cParams->hashLog;
1655 size_t const h3Size = hashLog3 ? ((size_t)1) << hashLog3 : 0;
1658 size_t const tableSpace = chainSize *
sizeof(
U32)
1659 + hSize *
sizeof(
U32)
1660 + h3Size *
sizeof(
U32);
1661 size_t const optPotentialSpace =
1668 size_t const lazyAdditionalSpace = ZSTD_rowMatchFinderUsed(cParams->strategy, useRowMatchFinder)
1671 size_t const optSpace = (forCCtx && (cParams->strategy >=
ZSTD_btopt))
1677 ZSTD_STATIC_ASSERT(ZSTD_HASHLOG_MIN >= 4 && ZSTD_WINDOWLOG_MIN >= 4 && ZSTD_CHAINLOG_MIN >= 4);
1678 assert(useRowMatchFinder != ZSTD_ps_auto);
1680 DEBUGLOG(4,
"chainSize: %u - hSize: %u - h3Size: %u",
1681 (
U32)chainSize, (
U32)hSize, (
U32)h3Size);
1682 return tableSpace + optSpace + slackSpace + lazyAdditionalSpace;
1687static size_t ZSTD_maxNbSeq(
size_t blockSize,
unsigned minMatch,
int useSequenceProducer) {
1688 U32 const divider = (minMatch==3 || useSequenceProducer) ? 3 : 4;
1689 return blockSize / divider;
1692static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal(
1693 const ZSTD_compressionParameters* cParams,
1696 const ZSTD_paramSwitch_e useRowMatchFinder,
1697 const size_t buffInSize,
1698 const size_t buffOutSize,
1699 const U64 pledgedSrcSize,
1700 int useSequenceProducer,
1701 size_t maxBlockSize)
1703 size_t const windowSize = (size_t)
BOUNDED(1ULL, 1ULL << cParams->windowLog, pledgedSrcSize);
1704 size_t const blockSize =
MIN(ZSTD_resolveMaxBlockSize(maxBlockSize), windowSize);
1705 size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, cParams->minMatch, useSequenceProducer);
1711 size_t const matchStateSize = ZSTD_sizeof_matchState(cParams, useRowMatchFinder, 0, 1);
1715 size_t const ldmSeqSpace = ldmParams->
enableLdm == ZSTD_ps_enable ?
1725 size_t const externalSeqSpace = useSequenceProducer
1729 size_t const neededSpace =
1740 DEBUGLOG(5,
"estimate workspace : %u", (
U32)neededSpace);
1746 ZSTD_compressionParameters
const cParams =
1748 ZSTD_paramSwitch_e
const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFinder,
1751 RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC,
"Estimate CCtx size is supported for single-threaded compression only.");
1755 return ZSTD_estimateCCtxSize_usingCCtxParams_internal(
1761 ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(cParams);
1762 if (ZSTD_rowMatchFinderSupported(cParams.strategy)) {
1764 size_t noRowCCtxSize;
1766 initialParams.useRowMatchFinder = ZSTD_ps_disable;
1768 initialParams.useRowMatchFinder = ZSTD_ps_enable;
1770 return MAX(noRowCCtxSize, rowCCtxSize);
1776static size_t ZSTD_estimateCCtxSize_internal(
int compressionLevel)
1779 size_t largestSize = 0;
1781 for (; tier < 4; ++tier) {
1783 ZSTD_compressionParameters
const cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeTiers[tier], 0,
ZSTD_cpm_noAttachDict);
1792 size_t memBudget = 0;
1793 for (level=
MIN(compressionLevel, 1); level<=compressionLevel; level++) {
1795 size_t const newMB = ZSTD_estimateCCtxSize_internal(level);
1796 if (newMB > memBudget) memBudget = newMB;
1803 RETURN_ERROR_IF(params->nbWorkers > 0, GENERIC,
"Estimate CCtx size is supported for single-threaded compression only.");
1804 { ZSTD_compressionParameters
const cParams =
1806 size_t const blockSize =
MIN(ZSTD_resolveMaxBlockSize(params->maxBlockSize), (
size_t)1 << cParams.windowLog);
1808 ? ((
size_t)1 << cParams.windowLog) + blockSize
1813 ZSTD_paramSwitch_e
const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params->useRowMatchFinder, ¶ms->cParams);
1815 return ZSTD_estimateCCtxSize_usingCCtxParams_internal(
1816 &cParams, ¶ms->ldmParams, 1, useRowMatchFinder, inBuffSize, outBuffSize,
1823 ZSTD_CCtx_params initialParams = ZSTD_makeCCtxParamsFromCParams(cParams);
1824 if (ZSTD_rowMatchFinderSupported(cParams.strategy)) {
1826 size_t noRowCCtxSize;
1828 initialParams.useRowMatchFinder = ZSTD_ps_disable;
1830 initialParams.useRowMatchFinder = ZSTD_ps_enable;
1832 return MAX(noRowCCtxSize, rowCCtxSize);
1838static size_t ZSTD_estimateCStreamSize_internal(
int compressionLevel)
1847 size_t memBudget = 0;
1848 for (level=
MIN(compressionLevel, 1); level<=compressionLevel; level++) {
1849 size_t const newMB = ZSTD_estimateCStreamSize_internal(level);
1850 if (newMB > memBudget) memBudget = newMB;
1861#ifdef ZSTD_MULTITHREAD
1866 { ZSTD_frameProgression fp;
1867 size_t const buffered = (cctx->
inBuff == NULL) ? 0 :
1875 fp.currentJobID = 0;
1876 fp.nbActiveWorkers = 0;
1885#ifdef ZSTD_MULTITHREAD
1894static void ZSTD_assertEqualCParams(ZSTD_compressionParameters cParams1,
1895 ZSTD_compressionParameters cParams2)
1899 assert(cParams1.windowLog == cParams2.windowLog);
1900 assert(cParams1.chainLog == cParams2.chainLog);
1901 assert(cParams1.hashLog == cParams2.hashLog);
1902 assert(cParams1.searchLog == cParams2.searchLog);
1903 assert(cParams1.minMatch == cParams2.minMatch);
1904 assert(cParams1.targetLength == cParams2.targetLength);
1905 assert(cParams1.strategy == cParams2.strategy);
1912 bs->
rep[i] = repStartValue[i];
1961static U64 ZSTD_bitmix(
U64 val,
U64 len) {
1963 val *= 0x9FB21C651E98DF25ULL;
1964 val ^= (
val >> 35) + len ;
1965 val *= 0x9FB21C651E98DF25ULL;
1966 return val ^ (
val >> 28);
1977 const ZSTD_compressionParameters* cParams,
1978 const ZSTD_paramSwitch_e useRowMatchFinder,
1984 size_t const chainSize = ZSTD_allocateChainTable(cParams->strategy, useRowMatchFinder,
1986 ? ((size_t)1 << cParams->chainLog)
1988 size_t const hSize = ((size_t)1) << cParams->hashLog;
1990 size_t const h3Size = hashLog3 ? ((size_t)1) << hashLog3 : 0;
1993 assert(useRowMatchFinder != ZSTD_ps_auto);
2002 ZSTD_invalidateMatchState(ms);
2008 DEBUGLOG(5,
"reserving table space");
2014 "failed a workspace allocation in ZSTD_reset_matchState");
2022 if (ZSTD_rowMatchFinderUsed(cParams->strategy, useRowMatchFinder)) {
2024 size_t const tagTableSize = hSize;
2029 ZSTD_advanceHashSalt(ms);
2037 U32 const rowLog =
BOUNDED(4, cParams->searchLog, 6);
2038 assert(cParams->hashLog >= rowLog);
2045 DEBUGLOG(4,
"reserving optimal parser space");
2057 "failed a workspace allocation in ZSTD_reset_matchState");
2068#define ZSTD_INDEXOVERFLOW_MARGIN (16 MB)
2079static int ZSTD_dictTooBig(
size_t const loadedDictSize)
2090static size_t ZSTD_resetCCtx_internal(
ZSTD_CCtx* zc,
2091 ZSTD_CCtx_params
const* params,
2092 U64 const pledgedSrcSize,
2093 size_t const loadedDictSize,
2098 DEBUGLOG(4,
"ZSTD_resetCCtx_internal: pledgedSrcSize=%u, wlog=%u, useRowMatchFinder=%d useBlockSplitter=%d",
2099 (
U32)pledgedSrcSize, params->cParams.windowLog, (
int)params->useRowMatchFinder, (
int)params->useBlockSplitter);
2110 assert(params->useRowMatchFinder != ZSTD_ps_auto);
2111 assert(params->useBlockSplitter != ZSTD_ps_auto);
2112 assert(params->ldmParams.enableLdm != ZSTD_ps_auto);
2113 assert(params->maxBlockSize != 0);
2114 if (params->ldmParams.enableLdm == ZSTD_ps_enable) {
2117 assert(params->ldmParams.hashLog >= params->ldmParams.bucketSizeLog);
2118 assert(params->ldmParams.hashRateLog < 32);
2121 {
size_t const windowSize =
MAX(1, (
size_t)
MIN(((
U64)1 << params->cParams.windowLog), pledgedSrcSize));
2122 size_t const blockSize =
MIN(params->maxBlockSize, windowSize);
2123 size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, params->cParams.minMatch,
ZSTD_hasExtSeqProd(params));
2128 ? windowSize + blockSize
2133 int const dictTooBig = ZSTD_dictTooBig(loadedDictSize);
2137 size_t const neededSpace =
2138 ZSTD_estimateCCtxSize_usingCCtxParams_internal(
2139 ¶ms->cParams, ¶ms->ldmParams, zc->
staticSize != 0, params->useRowMatchFinder,
2140 buffInSize, buffOutSize, pledgedSrcSize,
ZSTD_hasExtSeqProd(params), params->maxBlockSize);
2149 int resizeWorkspace = workspaceTooSmall || workspaceWasteful;
2150 DEBUGLOG(4,
"Need %zu B workspace", neededSpace);
2151 DEBUGLOG(4,
"windowSize: %zu - blockSize: %zu", windowSize, blockSize);
2153 if (resizeWorkspace) {
2154 DEBUGLOG(4,
"Resize workspaceSize from %zuKB to %zuKB",
2165 DEBUGLOG(5,
"reserving object space");
2188 DEBUGLOG(4,
"pledged content size : %u ; flag : %u",
2189 (
unsigned)pledgedSrcSize, zc->
appliedParams.fParams.contentSizeFlag);
2203 params->useRowMatchFinder,
2211 if (params->ldmParams.enableLdm == ZSTD_ps_enable) {
2213 size_t const ldmHSize = ((size_t)1) << params->ldmParams.hashLog;
2246 if (params->ldmParams.enableLdm == ZSTD_ps_enable) {
2248 size_t const numBuckets =
2249 ((size_t)1) << (params->ldmParams.hashLog -
2250 params->ldmParams.bucketSizeLog);
2285static const size_t attachDictSizeCutoffs[ZSTD_STRATEGY_MAX+1] = {
2298static int ZSTD_shouldAttachDict(
const ZSTD_CDict* cdict,
2299 const ZSTD_CCtx_params* params,
2304 return dedicatedDictSearch
2305 || ( ( pledgedSrcSize <= cutoff
2307 || params->attachDictPref == ZSTD_dictForceAttach )
2308 && params->attachDictPref != ZSTD_dictForceCopy
2309 && !params->forceWindow );
2314ZSTD_resetCCtx_byAttachingCDict(
ZSTD_CCtx* cctx,
2316 ZSTD_CCtx_params params,
2320 DEBUGLOG(4,
"ZSTD_resetCCtx_byAttachingCDict() pledgedSrcSize=%llu",
2321 (
unsigned long long)pledgedSrcSize);
2324 unsigned const windowLog = params.cParams.windowLog;
2331 ZSTD_dedicatedDictSearch_revertCParams(&adjusted_cdict_cParams);
2334 params.cParams = ZSTD_adjustCParams_internal(adjusted_cdict_cParams, pledgedSrcSize,
2336 params.useRowMatchFinder);
2337 params.cParams.windowLog = windowLog;
2348 if (cdictLen == 0) {
2350 DEBUGLOG(4,
"skipping attaching empty dictionary");
2352 DEBUGLOG(4,
"attaching dictionary into context");
2375static void ZSTD_copyCDictTableIntoCCtx(
U32* dst,
U32 const* src,
size_t tableSize,
2376 ZSTD_compressionParameters
const* cParams) {
2377 if (ZSTD_CDictIndicesAreTagged(cParams)){
2381 for (i = 0; i < tableSize; i++) {
2382 U32 const taggedIndex = src[i];
2391static size_t ZSTD_resetCCtx_byCopyingCDict(
ZSTD_CCtx* cctx,
2393 ZSTD_CCtx_params params,
2400 DEBUGLOG(4,
"ZSTD_resetCCtx_byCopyingCDict() pledgedSrcSize=%llu",
2401 (
unsigned long long)pledgedSrcSize);
2403 {
unsigned const windowLog = params.cParams.windowLog;
2406 params.cParams = *cdict_cParams;
2407 params.cParams.windowLog = windowLog;
2418 assert(params.useRowMatchFinder != ZSTD_ps_auto);
2421 {
size_t const chainSize = ZSTD_allocateChainTable(cdict_cParams->strategy, cdict->
useRowMatchFinder, 0 )
2422 ? ((size_t)1 << cdict_cParams->chainLog)
2424 size_t const hSize = (size_t)1 << cdict_cParams->hashLog;
2428 hSize, cdict_cParams);
2434 chainSize, cdict_cParams);
2437 if (ZSTD_rowMatchFinderUsed(cdict_cParams->strategy, cdict->
useRowMatchFinder)) {
2438 size_t const tagTableSize = hSize;
2448 size_t const h3Size = h3log ? ((size_t)1 << h3log) : 0;
2475static size_t ZSTD_resetCCtx_usingCDict(
ZSTD_CCtx* cctx,
2477 const ZSTD_CCtx_params* params,
2482 DEBUGLOG(4,
"ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)",
2483 (
unsigned)pledgedSrcSize);
2485 if (ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize)) {
2486 return ZSTD_resetCCtx_byAttachingCDict(
2487 cctx, cdict, *params, pledgedSrcSize, zbuff);
2489 return ZSTD_resetCCtx_byCopyingCDict(
2490 cctx, cdict, *params, pledgedSrcSize, zbuff);
2501static size_t ZSTD_copyCCtx_internal(
ZSTD_CCtx* dstCCtx,
2503 ZSTD_frameParameters fParams,
2508 "Can't copy a ctx that's not in init stage.");
2509 DEBUGLOG(5,
"ZSTD_copyCCtx_internal");
2517 params.useRowMatchFinder = srcCCtx->
appliedParams.useRowMatchFinder;
2518 params.useBlockSplitter = srcCCtx->
appliedParams.useBlockSplitter;
2520 params.fParams = fParams;
2522 ZSTD_resetCCtx_internal(dstCCtx, ¶ms, pledgedSrcSize,
2535 {
size_t const chainSize = ZSTD_allocateChainTable(srcCCtx->
appliedParams.cParams.strategy,
2540 size_t const hSize = (size_t)1 << srcCCtx->
appliedParams.cParams.hashLog;
2542 size_t const h3Size = h3log ? ((
size_t)1 << h3log) : 0;
2546 hSize *
sizeof(
U32));
2549 chainSize *
sizeof(
U32));
2552 h3Size *
sizeof(
U32));
2581 ZSTD_frameParameters fParams = { 1 , 0 , 0 };
2587 return ZSTD_copyCCtx_internal(dstCCtx, srcCCtx,
2588 fParams, pledgedSrcSize,
2593#define ZSTD_ROWSIZE 16
2611#if ZSTD_MEMORY_SANITIZER && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
2621 __msan_unpoison(
table, size *
sizeof(
U32));
2624 for (rowNb=0 ; rowNb < nbRows ; rowNb++) {
2632 }
else if (
table[cellNb] < reducerThreshold) {
2635 newVal =
table[cellNb] - reducerValue;
2637 table[cellNb] = newVal;
2642static void ZSTD_reduceTable(
U32*
const table,
U32 const size,
U32 const reducerValue)
2647static void ZSTD_reduceTable_btlazy2(
U32*
const table,
U32 const size,
U32 const reducerValue)
2654static void ZSTD_reduceIndex (
ZSTD_matchState_t* ms, ZSTD_CCtx_params
const* params,
const U32 reducerValue)
2656 {
U32 const hSize = (
U32)1 << params->cParams.hashLog;
2657 ZSTD_reduceTable(ms->
hashTable, hSize, reducerValue);
2660 if (ZSTD_allocateChainTable(params->cParams.strategy, params->useRowMatchFinder, (
U32)ms->
dedicatedDictSearch)) {
2661 U32 const chainSize = (
U32)1 << params->cParams.chainLog;
2663 ZSTD_reduceTable_btlazy2(ms->
chainTable, chainSize, reducerValue);
2665 ZSTD_reduceTable(ms->
chainTable, chainSize, reducerValue);
2670 ZSTD_reduceTable(ms->
hashTable3, h3Size, reducerValue);
2684 BYTE*
const llCodeTable = seqStorePtr->
llCode;
2685 BYTE*
const ofCodeTable = seqStorePtr->
ofCode;
2686 BYTE*
const mlCodeTable = seqStorePtr->
mlCode;
2689 int longOffsets = 0;
2690 assert(nbSeq <= seqStorePtr->maxNbSeq);
2691 for (u=0; u<nbSeq; u++) {
2696 ofCodeTable[u] = (
BYTE)ofCode;
2713static int ZSTD_useTargetCBlockSize(
const ZSTD_CCtx_params* cctxParams)
2715 DEBUGLOG(5,
"ZSTD_useTargetCBlockSize (targetCBlockSize=%zu)", cctxParams->targetCBlockSize);
2716 return (cctxParams->targetCBlockSize != 0);
2724static int ZSTD_blockSplitterEnabled(ZSTD_CCtx_params* cctxParams)
2726 DEBUGLOG(5,
"ZSTD_blockSplitterEnabled (useBlockSplitter=%d)", cctxParams->useBlockSplitter);
2727 assert(cctxParams->useBlockSplitter != ZSTD_ps_auto);
2728 return (cctxParams->useBlockSplitter == ZSTD_ps_enable);
2751ZSTD_buildSequencesStatistics(
2754 BYTE* dst,
const BYTE*
const dstEnd,
2756 void* entropyWorkspace,
size_t entropyWkspSize)
2758 BYTE*
const ostart = dst;
2759 const BYTE*
const oend = dstEnd;
2764 const BYTE*
const ofCodeTable = seqStorePtr->
ofCode;
2765 const BYTE*
const llCodeTable = seqStorePtr->
llCode;
2766 const BYTE*
const mlCodeTable = seqStorePtr->
mlCode;
2775 {
unsigned max =
MaxLL;
2776 size_t const mostFrequent =
HIST_countFast_wksp(countWorkspace, &max, llCodeTable, nbSeq, entropyWorkspace, entropyWkspSize);
2780 countWorkspace, max, mostFrequent, nbSeq,
2782 LL_defaultNorm, LL_defaultNormLog,
2787 op, (
size_t)(oend - op),
2789 countWorkspace, max, llCodeTable, nbSeq,
2790 LL_defaultNorm, LL_defaultNormLog,
MaxLL,
2793 entropyWorkspace, entropyWkspSize);
2795 DEBUGLOG(3,
"ZSTD_buildCTable for LitLens failed");
2796 stats.
size = countSize;
2807 countWorkspace, &max, ofCodeTable, nbSeq, entropyWorkspace, entropyWkspSize);
2813 countWorkspace, max, mostFrequent, nbSeq,
2815 OF_defaultNorm, OF_defaultNormLog,
2816 defaultPolicy, strategy);
2819 op, (
size_t)(oend - op),
2821 countWorkspace, max, ofCodeTable, nbSeq,
2825 entropyWorkspace, entropyWkspSize);
2827 DEBUGLOG(3,
"ZSTD_buildCTable for Offsets failed");
2828 stats.
size = countSize;
2839 countWorkspace, &max, mlCodeTable, nbSeq, entropyWorkspace, entropyWkspSize);
2840 DEBUGLOG(5,
"Building ML table (remaining space : %i)", (
int)(oend-op));
2843 countWorkspace, max, mostFrequent, nbSeq,
2845 ML_defaultNorm, ML_defaultNormLog,
2849 op, (
size_t)(oend - op),
2851 countWorkspace, max, mlCodeTable, nbSeq,
2852 ML_defaultNorm, ML_defaultNormLog,
MaxML,
2855 entropyWorkspace, entropyWkspSize);
2857 DEBUGLOG(3,
"ZSTD_buildCTable for MatchLengths failed");
2858 stats.
size = countSize;
2866 stats.
size = (size_t)(op-ostart);
2874#define SUSPECT_UNCOMPRESSIBLE_LITERAL_RATIO 20
2880 const ZSTD_CCtx_params* cctxParams,
2881 void* dst,
size_t dstCapacity,
2882 void* entropyWorkspace,
size_t entropyWkspSize,
2885 ZSTD_strategy const strategy = cctxParams->cParams.strategy;
2886 unsigned* count = (
unsigned*)entropyWorkspace;
2892 const BYTE*
const ofCodeTable = seqStorePtr->
ofCode;
2893 const BYTE*
const llCodeTable = seqStorePtr->
llCode;
2894 const BYTE*
const mlCodeTable = seqStorePtr->
mlCode;
2896 BYTE*
const oend = ostart + dstCapacity;
2898 size_t lastCountSize;
2899 int longOffsets = 0;
2901 entropyWorkspace = count + (
MaxSeq + 1);
2902 entropyWkspSize -= (
MaxSeq + 1) *
sizeof(*count);
2904 DEBUGLOG(5,
"ZSTD_entropyCompressSeqStore_internal (nbSeq=%zu, dstCapacity=%zu)", nbSeq, dstCapacity);
2911 size_t const numLiterals = (size_t)(seqStorePtr->
lit - seqStorePtr->
litStart);
2914 size_t const litSize = (size_t)(seqStorePtr->
lit - literals);
2919 entropyWorkspace, entropyWkspSize,
2920 &prevEntropy->
huf, &nextEntropy->
huf,
2921 cctxParams->cParams.strategy,
2923 suspectUncompressible, bmi2);
2925 assert(cSize <= dstCapacity);
2931 dstSize_tooSmall,
"Can't fit seq hdr in output buf!");
2933 *op++ = (
BYTE)nbSeq;
2935 op[0] = (
BYTE)((nbSeq>>8) + 0x80);
2936 op[1] = (
BYTE)nbSeq;
2947 return (
size_t)(op - ostart);
2949 {
BYTE*
const seqHead = op++;
2952 ZSTD_buildSequencesStatistics(seqStorePtr, nbSeq,
2953 &prevEntropy->
fse, &nextEntropy->
fse,
2956 entropyWorkspace, entropyWkspSize);
2965 op, (
size_t)(oend - op),
2966 CTable_MatchLength, mlCodeTable,
2967 CTable_OffsetBits, ofCodeTable,
2968 CTable_LitLength, llCodeTable,
2972 op += bitstreamSize;
2982 if (lastCountSize && (lastCountSize + bitstreamSize) < 4) {
2984 assert(lastCountSize + bitstreamSize == 3);
2985 DEBUGLOG(5,
"Avoiding bug in zstd decoder in versions <= 1.3.4 by "
2986 "emitting an uncompressed block.");
2991 DEBUGLOG(5,
"compressed block size : %u", (
unsigned)(op - ostart));
2992 return (
size_t)(op - ostart);
3000 const ZSTD_CCtx_params* cctxParams,
3001 void* dst,
size_t dstCapacity,
3003 void* entropyWorkspace,
size_t entropyWkspSize,
3007 seqStorePtr, prevEntropy, nextEntropy, cctxParams,
3009 entropyWorkspace, entropyWkspSize, bmi2);
3010 if (cSize == 0)
return 0;
3014 if ((cSize ==
ERROR(dstSize_tooSmall)) & (srcSize <= dstCapacity)) {
3015 DEBUGLOG(4,
"not enough dstCapacity (%zu) for ZSTD_entropyCompressSeqStore_internal()=> do not compress block", dstCapacity);
3021 {
size_t const maxCSize = srcSize -
ZSTD_minGain(srcSize, cctxParams->cParams.strategy);
3022 if (cSize >= maxCSize)
return 0;
3024 DEBUGLOG(5,
"ZSTD_entropyCompressSeqStore() cSize: %zu", cSize);
3086 DEBUGLOG(4,
"Selected block compressor: dictMode=%d strat=%d rowMatchfinder=%d", (
int)dictMode, (
int)strat, (
int)useRowMatchFinder);
3087 if (ZSTD_rowMatchFinderUsed(strat, useRowMatchFinder)) {
3110 DEBUGLOG(4,
"Selecting a row-based matchfinder");
3111 assert(useRowMatchFinder != ZSTD_ps_auto);
3112 selectedCompressor = rowBasedBlockCompressors[(int)dictMode][(
int)strat - (int)
ZSTD_greedy];
3114 selectedCompressor = blockCompressor[(int)dictMode][(
int)strat];
3116 assert(selectedCompressor != NULL);
3117 return selectedCompressor;
3120static void ZSTD_storeLastLiterals(
seqStore_t* seqStorePtr,
3121 const BYTE* anchor,
size_t lastLLSize)
3124 seqStorePtr->
lit += lastLLSize;
3140static size_t ZSTD_postProcessSequenceProducerResult(
3141 ZSTD_Sequence* outSeqs,
size_t nbExternalSeqs,
size_t outSeqsCapacity,
size_t srcSize
3144 nbExternalSeqs > outSeqsCapacity,
3145 sequenceProducer_failed,
3146 "External sequence producer returned error code %lu",
3147 (
unsigned long)nbExternalSeqs
3151 nbExternalSeqs == 0 && srcSize > 0,
3152 sequenceProducer_failed,
3153 "Got zero sequences from external sequence producer for a non-empty src buffer!"
3157 ZSTD_memset(&outSeqs[0], 0,
sizeof(ZSTD_Sequence));
3162 ZSTD_Sequence
const lastSeq = outSeqs[nbExternalSeqs - 1];
3165 if (lastSeq.offset == 0 && lastSeq.matchLength == 0) {
3166 return nbExternalSeqs;
3172 nbExternalSeqs == outSeqsCapacity,
3173 sequenceProducer_failed,
3174 "nbExternalSeqs == outSeqsCapacity but lastSeq is not a block delimiter!"
3178 ZSTD_memset(&outSeqs[nbExternalSeqs], 0,
sizeof(ZSTD_Sequence));
3179 return nbExternalSeqs + 1;
3189static size_t ZSTD_fastSequenceLengthSum(ZSTD_Sequence
const* seqBuf,
size_t seqBufSize) {
3190 size_t matchLenSum, litLenSum, i;
3193 for (i = 0; i < seqBufSize; i++) {
3194 litLenSum += seqBuf[i].litLength;
3195 matchLenSum += seqBuf[i].matchLength;
3197 return litLenSum + matchLenSum;
3202static size_t ZSTD_buildSeqStore(
ZSTD_CCtx* zc,
const void* src,
size_t srcSize)
3205 DEBUGLOG(5,
"ZSTD_buildSeqStore (srcSize=%zu)", srcSize);
3231 const BYTE*
const istart = (
const BYTE*)src;
3233 if (
sizeof(ptrdiff_t)==8)
assert(istart - base < (ptrdiff_t)(
U32)(-1));
3252 parameter_combination_unsupported,
3253 "Long-distance matching with external sequence producer enabled is not currently supported."
3264 }
else if (zc->
appliedParams.ldmParams.enableLdm == ZSTD_ps_enable) {
3271 parameter_combination_unsupported,
3272 "Long-distance matching with external sequence producer enabled is not currently supported."
3297 size_t const nbExternalSeqs = (zc->
appliedParams.extSeqProdFunc)(
3307 size_t const nbPostProcessedSeqs = ZSTD_postProcessSequenceProducerResult(
3317 size_t const seqLenSum = ZSTD_fastSequenceLengthSum(zc->
extSeqBuf, nbPostProcessedSeqs);
3318 RETURN_ERROR_IF(seqLenSum > srcSize, externalSequences_invalid,
"External sequences imply too large a block!");
3326 "Failed to copy external sequences to seqStore!"
3329 DEBUGLOG(5,
"Copied %lu sequences from external sequence producer to internal seqStore.", (
unsigned long)nbExternalSeqs);
3335 return nbPostProcessedSeqs;
3347 "External sequence producer returned error code %lu. Falling back to internal parser.",
3348 (
unsigned long)nbExternalSeqs
3360 {
const BYTE*
const lastLiterals = (
const BYTE*)src + srcSize - lastLLSize;
3361 ZSTD_storeLastLiterals(&zc->
seqStore, lastLiterals, lastLLSize);
3369 const size_t nbInSequences = seqStore->
sequences - inSeqs;
3370 const size_t nbInLiterals = (size_t)(seqStore->
lit - seqStore->
litStart);
3373 const size_t nbOutSequences = nbInSequences + 1;
3374 size_t nbOutLiterals = 0;
3385 "Not enough space to copy sequences");
3387 ZSTD_memcpy(&repcodes, prevRepcodes,
sizeof(repcodes));
3388 for (i = 0; i < nbInSequences; ++i) {
3390 outSeqs[i].litLength = inSeqs[i].
litLength;
3400 outSeqs[i].litLength += 0x10000;
3402 outSeqs[i].matchLength += 0x10000;
3410 outSeqs[i].rep = repcode;
3411 if (outSeqs[i].litLength != 0) {
3412 rawOffset = repcodes.
rep[repcode - 1];
3416 rawOffset = repcodes.
rep[0] - 1;
3418 rawOffset = repcodes.
rep[repcode];
3424 outSeqs[i].offset = rawOffset;
3429 inSeqs[i].litLength == 0);
3431 nbOutLiterals += outSeqs[i].litLength;
3437 assert(nbInLiterals >= nbOutLiterals);
3439 const size_t lastLLSize = nbInLiterals - nbOutLiterals;
3440 outSeqs[nbInSequences].litLength = (
U32)lastLLSize;
3441 outSeqs[nbInSequences].matchLength = 0;
3442 outSeqs[nbInSequences].offset = 0;
3443 assert(nbOutSequences == nbInSequences + 1);
3445 seqCollector->
seqIndex += nbOutSequences;
3452 const size_t maxNbSeq = (srcSize / ZSTD_MINMATCH_MIN) + 1;
3453 const size_t maxNbDelims = (srcSize / ZSTD_BLOCKSIZE_MAX_MIN) + 1;
3454 return maxNbSeq + maxNbDelims;
3458 size_t outSeqsSize,
const void* src,
size_t srcSize)
3464 int targetCBlockSize;
3466 RETURN_ERROR_IF(targetCBlockSize != 0, parameter_unsupported,
"targetCBlockSize != 0");
3471 RETURN_ERROR_IF(nbWorkers != 0, parameter_unsupported,
"nbWorkers != 0");
3483 const size_t ret =
ZSTD_compress2(zc, dst, dstCapacity, src, srcSize);
3494 for (; in < seqsSize; ++in) {
3495 if (sequences[in].offset == 0 && sequences[in].matchLength == 0) {
3496 if (in != seqsSize - 1) {
3497 sequences[in+1].litLength += sequences[in].litLength;
3500 sequences[out] = sequences[in];
3508static int ZSTD_isRLE(
const BYTE* src,
size_t length) {
3509 const BYTE* ip = src;
3511 const size_t valueST = (size_t)((
U64)
value * 0x0101010101010101ULL);
3512 const size_t unrollSize =
sizeof(size_t) * 4;
3513 const size_t unrollMask = unrollSize - 1;
3514 const size_t prefixLength = length & unrollMask;
3516 if (length == 1)
return 1;
3518 if (prefixLength &&
ZSTD_count(ip+1, ip, ip+prefixLength) != prefixLength-1) {
3521 for (i = prefixLength; i != length; i += unrollSize) {
3523 for (u = 0; u < unrollSize; u +=
sizeof(size_t)) {
3534static int ZSTD_maybeRLE(
seqStore_t const* seqStore)
3537 size_t const nbLits = (size_t)(seqStore->
lit - seqStore->
litStart);
3539 return nbSeqs < 4 && nbLits < 10;
3552writeBlockHeader(
void* op,
size_t cSize,
size_t blockSize,
U32 lastBlock)
3554 U32 const cBlockHeader = cSize == 1 ?
3555 lastBlock + (((
U32)
bt_rle)<<1) + (
U32)(blockSize << 3) :
3558 DEBUGLOG(3,
"writeBlockHeader: cSize: %zu blockSize: %zu lastBlock: %u", cSize, blockSize, lastBlock);
3569ZSTD_buildBlockEntropyStats_literals(
void*
const src,
size_t srcSize,
3573 const int literalsCompressionIsDisabled,
3574 void* workspace,
size_t wkspSize,
3577 BYTE*
const wkspStart = (
BYTE*)workspace;
3578 BYTE*
const wkspEnd = wkspStart + wkspSize;
3579 BYTE*
const countWkspStart = wkspStart;
3580 unsigned*
const countWksp = (
unsigned*)workspace;
3582 BYTE*
const nodeWksp = countWkspStart + countWkspSize;
3583 const size_t nodeWkspSize = (size_t)(wkspEnd - nodeWksp);
3587 DEBUGLOG(5,
"ZSTD_buildBlockEntropyStats_literals (srcSize=%zu)", srcSize);
3592 if (literalsCompressionIsDisabled) {
3593 DEBUGLOG(5,
"set_basic - disabled");
3599#ifndef COMPRESS_LITERALS_SIZE_MIN
3600# define COMPRESS_LITERALS_SIZE_MIN 63
3603 if (srcSize <= minLitSize) {
3604 DEBUGLOG(5,
"set_basic - too small");
3610 {
size_t const largest =
3612 (
const BYTE*)src, srcSize,
3613 workspace, wkspSize);
3615 if (largest == srcSize) {
3621 if (largest <= (srcSize >> 7)+4) {
3623 DEBUGLOG(5,
"set_basic - no gain");
3636 huffLog =
HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue, nodeWksp, nodeWkspSize, nextHuf->
CTable, countWksp, hufFlags);
3639 maxSymbolValue, huffLog,
3640 nodeWksp, nodeWkspSize);
3642 huffLog = (
U32)maxBits;
3650 nodeWksp, nodeWkspSize);
3655 if (oldCSize < srcSize && (oldCSize <= hSize + newCSize || hSize + 12 >= srcSize)) {
3656 DEBUGLOG(5,
"set_repeat - smaller");
3661 if (newCSize + hSize >= srcSize) {
3662 DEBUGLOG(5,
"set_basic - no gains");
3667 DEBUGLOG(5,
"set_compressed (hSize=%u)", (
U32)hSize);
3695ZSTD_buildBlockEntropyStats_sequences(
3699 const ZSTD_CCtx_params* cctxParams,
3701 void* workspace,
size_t wkspSize)
3703 ZSTD_strategy const strategy = cctxParams->cParams.strategy;
3708 unsigned* countWorkspace = (
unsigned*)workspace;
3709 unsigned* entropyWorkspace = countWorkspace + (
MaxSeq + 1);
3710 size_t entropyWorkspaceSize = wkspSize - (
MaxSeq + 1) *
sizeof(*countWorkspace);
3713 DEBUGLOG(5,
"ZSTD_buildBlockEntropyStats_sequences (nbSeq=%zu)", nbSeq);
3714 stats = nbSeq != 0 ? ZSTD_buildSequencesStatistics(seqStorePtr, nbSeq,
3715 prevEntropy, nextEntropy, op, oend,
3716 strategy, countWorkspace,
3717 entropyWorkspace, entropyWorkspaceSize)
3718 : ZSTD_buildDummySequencesStatistics(nextEntropy);
3738 const ZSTD_CCtx_params* cctxParams,
3740 void* workspace,
size_t wkspSize)
3742 size_t const litSize = (size_t)(seqStorePtr->
lit - seqStorePtr->
litStart);
3747 ZSTD_buildBlockEntropyStats_literals(seqStorePtr->
litStart, litSize,
3748 &prevEntropy->
huf, &nextEntropy->
huf,
3751 workspace, wkspSize, hufFlags);
3755 ZSTD_buildBlockEntropyStats_sequences(seqStorePtr,
3756 &prevEntropy->
fse, &nextEntropy->
fse,
3759 workspace, wkspSize);
3766ZSTD_estimateBlockSize_literal(
const BYTE* literals,
size_t litSize,
3769 void* workspace,
size_t wkspSize,
3772 unsigned*
const countWksp = (
unsigned*)workspace;
3774 size_t literalSectionHeaderSize = 3 + (litSize >= 1
KB) + (litSize >= 16
KB);
3775 U32 singleStream = litSize < 256;
3780 size_t const largest =
HIST_count_wksp (countWksp, &maxSymbolValue, (
const BYTE*)literals, litSize, workspace, wkspSize);
3783 if (writeEntropy) cLitSizeEstimate += hufMetadata->
hufDesSize;
3784 if (!singleStream) cLitSizeEstimate += 6;
3785 return cLitSizeEstimate + literalSectionHeaderSize;
3794 const BYTE* codeTable,
size_t nbSeq,
unsigned maxCode,
3796 const U8* additionalBits,
3797 short const* defaultNorm,
U32 defaultNormLog,
U32 defaultMax,
3798 void* workspace,
size_t wkspSize)
3800 unsigned*
const countWksp = (
unsigned*)workspace;
3801 const BYTE* ctp = codeTable;
3802 const BYTE*
const ctStart = ctp;
3803 const BYTE*
const ctEnd = ctStart + nbSeq;
3804 size_t cSymbolTypeSizeEstimateInBits = 0;
3805 unsigned max = maxCode;
3810 assert(max <= defaultMax);
3814 cSymbolTypeSizeEstimateInBits = 0;
3816 cSymbolTypeSizeEstimateInBits =
ZSTD_fseBitCost(fseCTable, countWksp, max);
3821 while (ctp < ctEnd) {
3822 if (additionalBits) cSymbolTypeSizeEstimateInBits += additionalBits[*ctp];
3823 else cSymbolTypeSizeEstimateInBits += *ctp;
3826 return cSymbolTypeSizeEstimateInBits >> 3;
3831ZSTD_estimateBlockSize_sequences(
const BYTE* ofCodeTable,
3832 const BYTE* llCodeTable,
3833 const BYTE* mlCodeTable,
3837 void* workspace,
size_t wkspSize,
3840 size_t sequencesSectionHeaderSize = 1 + 1 + (nbSeq >= 128) + (nbSeq >=
LONGNBSEQ);
3841 size_t cSeqSizeEstimate = 0;
3842 cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->
ofType, ofCodeTable, nbSeq,
MaxOff,
3845 workspace, wkspSize);
3846 cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->
llType, llCodeTable, nbSeq,
MaxLL,
3848 LL_defaultNorm, LL_defaultNormLog,
MaxLL,
3849 workspace, wkspSize);
3850 cSeqSizeEstimate += ZSTD_estimateBlockSize_symbolType(fseMetadata->
mlType, mlCodeTable, nbSeq,
MaxML,
3852 ML_defaultNorm, ML_defaultNormLog,
MaxML,
3853 workspace, wkspSize);
3854 if (writeEntropy) cSeqSizeEstimate += fseMetadata->
fseTablesSize;
3855 return cSeqSizeEstimate + sequencesSectionHeaderSize;
3860ZSTD_estimateBlockSize(
const BYTE* literals,
size_t litSize,
3861 const BYTE* ofCodeTable,
3862 const BYTE* llCodeTable,
3863 const BYTE* mlCodeTable,
3867 void* workspace,
size_t wkspSize,
3868 int writeLitEntropy,
int writeSeqEntropy)
3870 size_t const literalsSize = ZSTD_estimateBlockSize_literal(literals, litSize,
3872 workspace, wkspSize, writeLitEntropy);
3873 size_t const seqSize = ZSTD_estimateBlockSize_sequences(ofCodeTable, llCodeTable, mlCodeTable,
3875 workspace, wkspSize, writeSeqEntropy);
3876 return seqSize + literalsSize + ZSTD_blockHeaderSize;
3887 DEBUGLOG(6,
"ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize()");
3894 return ZSTD_estimateBlockSize(
3905static size_t ZSTD_countSeqStoreLiteralsBytes(
const seqStore_t*
const seqStore)
3907 size_t literalsBytes = 0;
3910 for (i = 0; i < nbSeqs; ++i) {
3914 literalsBytes += 0x10000;
3916 return literalsBytes;
3920static size_t ZSTD_countSeqStoreMatchBytes(
const seqStore_t*
const seqStore)
3922 size_t matchBytes = 0;
3925 for (i = 0; i < nbSeqs; ++i) {
3929 matchBytes += 0x10000;
3937static void ZSTD_deriveSeqStoreChunk(
seqStore_t* resultSeqStore,
3939 size_t startIdx,
size_t endIdx)
3941 *resultSeqStore = *originalSeqStore;
3944 resultSeqStore->
litStart += ZSTD_countSeqStoreLiteralsBytes(resultSeqStore);
3961 size_t const literalsBytes = ZSTD_countSeqStoreLiteralsBytes(resultSeqStore);
3962 resultSeqStore->
lit = resultSeqStore->
litStart + literalsBytes;
3964 resultSeqStore->
llCode += startIdx;
3965 resultSeqStore->
mlCode += startIdx;
3966 resultSeqStore->
ofCode += startIdx;
3989 return rep[adjustedRepCode];
4011 for (; idx < nbSeq; ++idx) {
4013 U32 const ll0 = (seq->
litLength == 0) && (idx != longLitLenIdx);
4017 U32 const dRawOffset = ZSTD_resolveRepcodeToRawOffset(dRepcodes->
rep, offBase, ll0);
4018 U32 const cRawOffset = ZSTD_resolveRepcodeToRawOffset(cRepcodes->
rep, offBase, ll0);
4023 if (dRawOffset != cRawOffset) {
4041ZSTD_compressSeqStore_singleBlock(
ZSTD_CCtx* zc,
4044 void* dst,
size_t dstCapacity,
4045 const void* src,
size_t srcSize,
4046 U32 lastBlock,
U32 isPartition)
4048 const U32 rleMaxLength = 25;
4056 DEBUGLOG(5,
"ZSTD_compressSeqStore_singleBlock");
4060 RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize, dstSize_tooSmall,
"Block header doesn't fit");
4064 op + ZSTD_blockHeaderSize, dstCapacity - ZSTD_blockHeaderSize,
4071 cSeqsSize < rleMaxLength &&
4072 ZSTD_isRLE((
BYTE const*)src, srcSize)) {
4083 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->
blockState);
4087 if (cSeqsSize == 0) {
4090 DEBUGLOG(4,
"Writing out nocompress block, size: %zu", cSize);
4091 *dRep = dRepOriginal;
4092 }
else if (cSeqsSize == 1) {
4095 DEBUGLOG(4,
"Writing out RLE block, size: %zu", cSize);
4096 *dRep = dRepOriginal;
4098 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->
blockState);
4099 writeBlockHeader(op, cSeqsSize, srcSize, lastBlock);
4100 cSize = ZSTD_blockHeaderSize + cSeqsSize;
4101 DEBUGLOG(4,
"Writing out compressed block, size: %zu", cSize);
4116#define MIN_SEQUENCES_BLOCK_SPLITTING 300
4133ZSTD_deriveBlockSplitsHelper(
seqStoreSplits* splits,
size_t startIdx,
size_t endIdx,
4139 size_t estimatedOriginalSize;
4140 size_t estimatedFirstHalfSize;
4141 size_t estimatedSecondHalfSize;
4142 size_t midIdx = (startIdx + endIdx)/2;
4144 DEBUGLOG(5,
"ZSTD_deriveBlockSplitsHelper: startIdx=%zu endIdx=%zu", startIdx, endIdx);
4145 assert(endIdx >= startIdx);
4147 DEBUGLOG(6,
"ZSTD_deriveBlockSplitsHelper: Too few sequences (%zu)", endIdx - startIdx);
4150 ZSTD_deriveSeqStoreChunk(fullSeqStoreChunk, origSeqStore, startIdx, endIdx);
4151 ZSTD_deriveSeqStoreChunk(firstHalfSeqStore, origSeqStore, startIdx, midIdx);
4152 ZSTD_deriveSeqStoreChunk(secondHalfSeqStore, origSeqStore, midIdx, endIdx);
4153 estimatedOriginalSize = ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize(fullSeqStoreChunk, zc);
4154 estimatedFirstHalfSize = ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize(firstHalfSeqStore, zc);
4155 estimatedSecondHalfSize = ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize(secondHalfSeqStore, zc);
4156 DEBUGLOG(5,
"Estimated original block size: %zu -- First half split: %zu -- Second half split: %zu",
4157 estimatedOriginalSize, estimatedFirstHalfSize, estimatedSecondHalfSize);
4161 if (estimatedFirstHalfSize + estimatedSecondHalfSize < estimatedOriginalSize) {
4162 DEBUGLOG(5,
"split decided at seqNb:%zu", midIdx);
4163 ZSTD_deriveBlockSplitsHelper(splits, startIdx, midIdx, zc, origSeqStore);
4166 ZSTD_deriveBlockSplitsHelper(splits, midIdx, endIdx, zc, origSeqStore);
4175static size_t ZSTD_deriveBlockSplits(
ZSTD_CCtx* zc,
U32 partitions[],
U32 nbSeq)
4181 DEBUGLOG(5,
"ZSTD_deriveBlockSplits: Too few sequences to split (%u <= 4)", nbSeq);
4185 ZSTD_deriveBlockSplitsHelper(&splits, 0, nbSeq, zc, &zc->
seqStore);
4187 DEBUGLOG(5,
"ZSTD_deriveBlockSplits: final nb partitions: %zu", splits.
idx+1);
4197ZSTD_compressBlock_splitBlock_internal(
ZSTD_CCtx* zc,
4198 void* dst,
size_t dstCapacity,
4199 const void* src,
size_t blockSize,
4200 U32 lastBlock,
U32 nbSeq)
4206 size_t srcBytesTotal = 0;
4210 size_t const numSplits = ZSTD_deriveBlockSplits(zc, partitions, nbSeq);
4232 DEBUGLOG(5,
"ZSTD_compressBlock_splitBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
4236 if (numSplits == 0) {
4237 size_t cSizeSingleBlock =
4238 ZSTD_compressSeqStore_singleBlock(zc, &zc->
seqStore,
4243 FORWARD_IF_ERROR(cSizeSingleBlock,
"Compressing single block from splitBlock_internal() failed!");
4244 DEBUGLOG(5,
"ZSTD_compressBlock_splitBlock_internal: No splits");
4246 assert(cSizeSingleBlock <= zc->blockSize + ZSTD_blockHeaderSize);
4247 return cSizeSingleBlock;
4250 ZSTD_deriveSeqStoreChunk(currSeqStore, &zc->
seqStore, 0, partitions[0]);
4251 for (i = 0; i <= numSplits; ++i) {
4253 U32 const lastPartition = (i == numSplits);
4254 U32 lastBlockEntireSrc = 0;
4256 size_t srcBytes = ZSTD_countSeqStoreLiteralsBytes(currSeqStore) + ZSTD_countSeqStoreMatchBytes(currSeqStore);
4257 srcBytesTotal += srcBytes;
4258 if (lastPartition) {
4260 srcBytes += blockSize - srcBytesTotal;
4261 lastBlockEntireSrc = lastBlock;
4263 ZSTD_deriveSeqStoreChunk(nextSeqStore, &zc->
seqStore, partitions[i], partitions[i+1]);
4266 cSizeChunk = ZSTD_compressSeqStore_singleBlock(zc, currSeqStore,
4270 lastBlockEntireSrc, 1 );
4271 DEBUGLOG(5,
"Estimated size: %zu vs %zu : actual size",
4272 ZSTD_buildEntropyStatisticsAndEstimateSubBlockSize(currSeqStore, zc), cSizeChunk);
4277 dstCapacity -= cSizeChunk;
4278 cSize += cSizeChunk;
4279 *currSeqStore = *nextSeqStore;
4280 assert(cSizeChunk <= zc->blockSize + ZSTD_blockHeaderSize);
4290ZSTD_compressBlock_splitBlock(
ZSTD_CCtx* zc,
4291 void* dst,
size_t dstCapacity,
4292 const void* src,
size_t srcSize,
U32 lastBlock)
4296 DEBUGLOG(4,
"ZSTD_compressBlock_splitBlock");
4299 {
const size_t bss = ZSTD_buildSeqStore(zc, src, srcSize);
4307 DEBUGLOG(4,
"ZSTD_compressBlock_splitBlock: Nocompress block");
4313 cSize = ZSTD_compressBlock_splitBlock_internal(zc, dst, dstCapacity, src, srcSize, lastBlock, nbSeq);
4319ZSTD_compressBlock_internal(
ZSTD_CCtx* zc,
4320 void* dst,
size_t dstCapacity,
4321 const void* src,
size_t srcSize,
U32 frame)
4327 const U32 rleMaxLength = 25;
4331 DEBUGLOG(5,
"ZSTD_compressBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
4335 {
const size_t bss = ZSTD_buildSeqStore(zc, src, srcSize);
4346 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->
blockState);
4365 cSize < rleMaxLength &&
4366 ZSTD_isRLE(ip, srcSize))
4374 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->
blockState);
4386static size_t ZSTD_compressBlock_targetCBlockSize_body(
ZSTD_CCtx* zc,
4387 void* dst,
size_t dstCapacity,
4388 const void* src,
size_t srcSize,
4389 const size_t bss,
U32 lastBlock)
4391 DEBUGLOG(6,
"Attempting ZSTD_compressSuperBlock()");
4399 ZSTD_isRLE((
BYTE const*)src, srcSize))
4421 {
size_t const cSize =
4423 if (cSize !=
ERROR(dstSize_tooSmall)) {
4424 size_t const maxCSize =
4427 if (cSize != 0 && cSize < maxCSize + ZSTD_blockHeaderSize) {
4428 ZSTD_blockState_confirmRepcodesAndEntropyTables(&zc->
blockState);
4435 DEBUGLOG(6,
"Resorting to ZSTD_noCompressBlock()");
4442static size_t ZSTD_compressBlock_targetCBlockSize(
ZSTD_CCtx* zc,
4443 void* dst,
size_t dstCapacity,
4444 const void* src,
size_t srcSize,
4448 const size_t bss = ZSTD_buildSeqStore(zc, src, srcSize);
4449 DEBUGLOG(5,
"ZSTD_compressBlock_targetCBlockSize (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u, srcSize=%zu)",
4453 cSize = ZSTD_compressBlock_targetCBlockSize_body(zc, dst, dstCapacity, src, srcSize, bss, lastBlock);
4454 FORWARD_IF_ERROR(cSize,
"ZSTD_compressBlock_targetCBlockSize_body failed");
4464 ZSTD_CCtx_params
const* params,
4468 U32 const cycleLog =
ZSTD_cycleLog(params->cParams.chainLog, params->cParams.strategy);
4469 U32 const maxDist = (
U32)1 << params->cParams.windowLog;
4476 ZSTD_reduceIndex(ms, params, correction);
4493static size_t ZSTD_compress_frameChunk(
ZSTD_CCtx* cctx,
4494 void* dst,
size_t dstCapacity,
4495 const void* src,
size_t srcSize,
4499 size_t remaining = srcSize;
4507 DEBUGLOG(4,
"ZSTD_compress_frameChunk (blockSize=%u)", (
unsigned)blockSize);
4513 U32 const lastBlock = lastFrameChunk & (blockSize >= remaining);
4519 "not enough space to store compressed block");
4520 if (remaining < blockSize) blockSize = remaining;
4522 ZSTD_overflowCorrectIfNeeded(
4532 cSize = ZSTD_compressBlock_targetCBlockSize(cctx, op, dstCapacity, ip, blockSize, lastBlock);
4535 assert(cSize <= blockSize + ZSTD_blockHeaderSize);
4536 }
else if (ZSTD_blockSplitterEnabled(&cctx->
appliedParams)) {
4537 cSize = ZSTD_compressBlock_splitBlock(cctx, op, dstCapacity, ip, blockSize, lastBlock);
4541 cSize = ZSTD_compressBlock_internal(cctx,
4542 op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize,
4550 U32 const cBlockHeader = cSize == 1 ?
4551 lastBlock + (((
U32)
bt_rle)<<1) + (
U32)(blockSize << 3) :
4554 cSize += ZSTD_blockHeaderSize;
4560 assert(remaining >= blockSize);
4561 remaining -= blockSize;
4563 assert(dstCapacity >= cSize);
4564 dstCapacity -= cSize;
4566 DEBUGLOG(5,
"ZSTD_compress_frameChunk: adding a block of size %u",
4571 return (
size_t)(op-ostart);
4575static size_t ZSTD_writeFrameHeader(
void* dst,
size_t dstCapacity,
4576 const ZSTD_CCtx_params* params,
U64 pledgedSrcSize,
U32 dictID)
4578 U32 const dictIDSizeCodeLength = (dictID>0) + (dictID>=256) + (dictID>=65536);
4579 U32 const dictIDSizeCode = params->fParams.noDictIDFlag ? 0 : dictIDSizeCodeLength;
4580 U32 const checksumFlag = params->fParams.checksumFlag>0;
4581 U32 const windowSize = (
U32)1 << params->cParams.windowLog;
4582 U32 const singleSegment = params->fParams.contentSizeFlag && (windowSize >= pledgedSrcSize);
4584 U32 const fcsCode = params->fParams.contentSizeFlag ?
4585 (pledgedSrcSize>=256) + (pledgedSrcSize>=65536+256) + (pledgedSrcSize>=0xFFFFFFFFU) : 0;
4586 BYTE const frameHeaderDescriptionByte = (
BYTE)(dictIDSizeCode + (checksumFlag<<2) + (singleSegment<<5) + (fcsCode<<6) );
4590 RETURN_ERROR_IF(dstCapacity < ZSTD_FRAMEHEADERSIZE_MAX, dstSize_tooSmall,
4591 "dst buf is too small to fit worst-case frame header size.");
4592 DEBUGLOG(4,
"ZSTD_writeFrameHeader : dictIDFlag : %u ; dictID : %u ; dictIDSizeCode : %u",
4593 !params->fParams.noDictIDFlag, (
unsigned)dictID, (
unsigned)dictIDSizeCode);
4594 if (params->format == ZSTD_f_zstd1) {
4598 op[pos++] = frameHeaderDescriptionByte;
4599 if (!singleSegment) op[pos++] = windowLogByte;
4600 switch(dictIDSizeCode)
4606 case 1 : op[pos] = (
BYTE)(dictID); pos++;
break;
4615 case 0 :
if (singleSegment) op[pos++] = (
BYTE)(pledgedSrcSize);
break;
4630 const void* src,
size_t srcSize,
unsigned magicVariant) {
4633 dstSize_tooSmall,
"Not enough room for skippable frame");
4634 RETURN_ERROR_IF(srcSize > (
unsigned)0xFFFFFFFF, srcSize_wrong,
"Src size too large for skippable frame");
4635 RETURN_ERROR_IF(magicVariant > 15, parameter_outOfBound,
"Skippable frame magic number variant not supported");
4640 return srcSize + ZSTD_SKIPPABLEHEADERSIZE;
4651 "dst buf is too small to write frame trailer empty block.");
4654 return ZSTD_blockHeaderSize;
4670static size_t ZSTD_compressContinue_internal (
ZSTD_CCtx* cctx,
4671 void* dst,
size_t dstCapacity,
4672 const void* src,
size_t srcSize,
4673 U32 frame,
U32 lastFrameChunk)
4678 DEBUGLOG(5,
"ZSTD_compressContinue_internal, stage: %u, srcSize: %u",
4679 cctx->
stage, (
unsigned)srcSize);
4681 "missing init (ZSTD_compressBegin)");
4684 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->
appliedParams,
4687 assert(fhSize <= dstCapacity);
4688 dstCapacity -= fhSize;
4689 dst = (
char*)dst + fhSize;
4693 if (!srcSize)
return fhSize;
4699 if (cctx->
appliedParams.ldmParams.enableLdm == ZSTD_ps_enable) {
4705 ZSTD_overflowCorrectIfNeeded(
4707 src, (
BYTE const*)src + srcSize);
4710 DEBUGLOG(5,
"ZSTD_compressContinue_internal (blockSize=%u)", (
unsigned)cctx->
blockSize);
4711 {
size_t const cSize = frame ?
4712 ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) :
4713 ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize, 0 );
4714 FORWARD_IF_ERROR(cSize,
"%s", frame ?
"ZSTD_compress_frameChunk failed" :
"ZSTD_compressBlock_internal failed");
4723 "error : pledgedSrcSize = %u, while realSrcSize >= %u",
4727 return cSize + fhSize;
4732 void* dst,
size_t dstCapacity,
4733 const void* src,
size_t srcSize)
4735 DEBUGLOG(5,
"ZSTD_compressContinue (srcSize=%u)", (
unsigned)srcSize);
4736 return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1 , 0 );
4741 void* dst,
size_t dstCapacity,
4742 const void* src,
size_t srcSize)
4747static size_t ZSTD_getBlockSize_deprecated(
const ZSTD_CCtx* cctx)
4749 ZSTD_compressionParameters
const cParams = cctx->
appliedParams.cParams;
4751 return MIN(cctx->
appliedParams.maxBlockSize, (
size_t)1 << cParams.windowLog);
4757 return ZSTD_getBlockSize_deprecated(cctx);
4763 DEBUGLOG(5,
"ZSTD_compressBlock: srcSize = %u", (
unsigned)srcSize);
4764 {
size_t const blockSizeMax = ZSTD_getBlockSize_deprecated(cctx);
4765 RETURN_ERROR_IF(srcSize > blockSizeMax, srcSize_wrong,
"input is larger than a block"); }
4767 return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 , 0 );
4782 ZSTD_CCtx_params
const* params,
4783 const void* src,
size_t srcSize,
4787 const BYTE* ip = (
const BYTE*) src;
4788 const BYTE*
const iend = ip + srcSize;
4789 int const loadLdmDict = params->ldmParams.enableLdm == ZSTD_ps_enable && ls != NULL;
4792 ZSTD_assertEqualCParams(params->cParams, ms->
cParams);
4802 int const CDictTaggedIndices = ZSTD_CDictIndicesAreTagged(¶ms->cParams);
4810 maxDictSize =
MIN(maxDictSize, shortCacheMaxDictSize);
4815 if (srcSize > maxDictSize) {
4816 ip = iend - maxDictSize;
4818 srcSize = maxDictSize;
4829 DEBUGLOG(4,
"ZSTD_loadDictionaryContent(): useRowMatchFinder=%d", (
int)params->useRowMatchFinder);
4839 U32 maxDictSize = 8U <<
MIN(
MAX(params->cParams.hashLog, params->cParams.chainLog), 28);
4840 if (srcSize > maxDictSize) {
4841 ip = iend - maxDictSize;
4843 srcSize = maxDictSize;
4853 ZSTD_overflowCorrectIfNeeded(ms, ws, params, ip, iend);
4855 switch(params->cParams.strategy)
4861#ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
4871#if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \
4872 || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \
4873 || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR)
4879 assert(params->useRowMatchFinder != ZSTD_ps_auto);
4880 if (params->useRowMatchFinder == ZSTD_ps_enable) {
4881 size_t const tagTableSize = ((size_t)1 << params->cParams.hashLog);
4884 DEBUGLOG(4,
"Using row-based hash table for lazy dict");
4887 DEBUGLOG(4,
"Using chain-based hash table for lazy dict");
4899#if !defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR) \
4900 || !defined(ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR) \
4901 || !defined(ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR)
4922static FSE_repeat ZSTD_dictNCountRepeat(
short* normalizedCounter,
unsigned dictMaxSymbolValue,
unsigned maxSymbolValue)
4925 if (dictMaxSymbolValue < maxSymbolValue) {
4926 return FSE_repeat_check;
4928 for (s = 0; s <= maxSymbolValue; ++s) {
4929 if (normalizedCounter[s] == 0) {
4930 return FSE_repeat_check;
4933 return FSE_repeat_valid;
4937 const void*
const dict,
size_t dictSize)
4939 short offcodeNCount[
MaxOff+1];
4940 unsigned offcodeMaxValue =
MaxOff;
4941 const BYTE* dictPtr = (
const BYTE*)dict;
4942 const BYTE*
const dictEnd = dictPtr + dictSize;
4946 {
unsigned maxSymbolValue = 255;
4947 unsigned hasZeroWeights = 1;
4949 dictEnd-dictPtr, &hasZeroWeights);
4953 if (!hasZeroWeights && maxSymbolValue == 255)
4957 dictPtr += hufHeaderSize;
4960 {
unsigned offcodeLog;
4961 size_t const offcodeHeaderSize =
FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
4967 offcodeNCount,
MaxOff, offcodeLog,
4969 dictionary_corrupted,
"");
4971 dictPtr += offcodeHeaderSize;
4974 {
short matchlengthNCount[
MaxML+1];
4975 unsigned matchlengthMaxValue =
MaxML, matchlengthLog;
4976 size_t const matchlengthHeaderSize =
FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
4981 matchlengthNCount, matchlengthMaxValue, matchlengthLog,
4983 dictionary_corrupted,
"");
4985 dictPtr += matchlengthHeaderSize;
4988 {
short litlengthNCount[
MaxLL+1];
4989 unsigned litlengthMaxValue =
MaxLL, litlengthLog;
4990 size_t const litlengthHeaderSize =
FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
4995 litlengthNCount, litlengthMaxValue, litlengthLog,
4997 dictionary_corrupted,
"");
4999 dictPtr += litlengthHeaderSize;
5008 {
size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
5010 if (dictContentSize <= ((
U32)-1) - 128
KB) {
5011 U32 const maxOffset = (
U32)dictContentSize + 128
KB;
5019 for (u=0; u<3; u++) {
5024 return dictPtr - (
const BYTE*)dict;
5039 ZSTD_CCtx_params
const* params,
5040 const void* dict,
size_t dictSize,
5045 const BYTE* dictPtr = (
const BYTE*)dict;
5046 const BYTE*
const dictEnd = dictPtr + dictSize;
5053 dictID = params->fParams.noDictIDFlag ? 0 :
MEM_readLE32(dictPtr + 4 );
5059 size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
5061 ms, NULL, ws, params, dictPtr, dictContentSize, dtlm, tfp),
"");
5073 const ZSTD_CCtx_params* params,
5074 const void* dict,
size_t dictSize,
5075 ZSTD_dictContentType_e dictContentType,
5080 DEBUGLOG(4,
"ZSTD_compress_insertDictionary (dictSize=%u)", (
U32)dictSize);
5081 if ((dict==NULL) || (dictSize<8)) {
5082 RETURN_ERROR_IF(dictContentType == ZSTD_dct_fullDict, dictionary_wrong,
"");
5089 if (dictContentType == ZSTD_dct_rawContent)
5090 return ZSTD_loadDictionaryContent(ms, ls, ws, params, dict, dictSize, dtlm, tfp);
5093 if (dictContentType == ZSTD_dct_auto) {
5094 DEBUGLOG(4,
"raw content dictionary detected");
5095 return ZSTD_loadDictionaryContent(
5096 ms, ls, ws, params, dict, dictSize, dtlm, tfp);
5098 RETURN_ERROR_IF(dictContentType == ZSTD_dct_fullDict, dictionary_wrong,
"");
5103 return ZSTD_loadZstdDictionary(
5104 bs, ms, ws, params, dict, dictSize, dtlm, tfp, workspace);
5107#define ZSTD_USE_CDICT_PARAMS_SRCSIZE_CUTOFF (128 KB)
5108#define ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER (6ULL)
5113static size_t ZSTD_compressBegin_internal(
ZSTD_CCtx* cctx,
5114 const void* dict,
size_t dictSize,
5115 ZSTD_dictContentType_e dictContentType,
5118 const ZSTD_CCtx_params* params,
U64 pledgedSrcSize,
5121 size_t const dictContentSize = cdict ? cdict->
dictContentSize : dictSize;
5123 cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0;
5125 DEBUGLOG(4,
"ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog);
5128 assert(!((dict) && (cdict)));
5135 && (params->attachDictPref != ZSTD_dictForceLoad) ) {
5136 return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
5142 {
size_t const dictID = cdict ?
5143 ZSTD_compress_insertDictionary(
5148 : ZSTD_compress_insertDictionary(
5153 assert(dictID <= UINT_MAX);
5161 const void* dict,
size_t dictSize,
5162 ZSTD_dictContentType_e dictContentType,
5165 const ZSTD_CCtx_params* params,
5166 unsigned long long pledgedSrcSize)
5168 DEBUGLOG(4,
"ZSTD_compressBegin_advanced_internal: wlog=%u", params->cParams.windowLog);
5171 return ZSTD_compressBegin_internal(cctx,
5172 dict, dictSize, dictContentType, dtlm,
5174 params, pledgedSrcSize,
5181 const void* dict,
size_t dictSize,
5182 ZSTD_parameters params,
unsigned long long pledgedSrcSize)
5184 ZSTD_CCtx_params cctxParams;
5185 ZSTD_CCtxParams_init_internal(&cctxParams, ¶ms,
ZSTD_NO_CLEVEL);
5189 &cctxParams, pledgedSrcSize);
5193ZSTD_compressBegin_usingDict_deprecated(
ZSTD_CCtx* cctx,
const void* dict,
size_t dictSize,
int compressionLevel)
5195 ZSTD_CCtx_params cctxParams;
5197 ZSTD_CCtxParams_init_internal(&cctxParams, ¶ms, (compressionLevel == 0) ?
ZSTD_CLEVEL_DEFAULT : compressionLevel);
5199 DEBUGLOG(4,
"ZSTD_compressBegin_usingDict (dictSize=%u)", (
unsigned)dictSize);
5200 return ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dct_auto,
ZSTD_dtlm_fast, NULL,
5207 return ZSTD_compressBegin_usingDict_deprecated(cctx, dict, dictSize, compressionLevel);
5212 return ZSTD_compressBegin_usingDict_deprecated(cctx, NULL, 0, compressionLevel);
5219static size_t ZSTD_writeEpilogue(
ZSTD_CCtx* cctx,
void* dst,
size_t dstCapacity)
5229 size_t fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->
appliedParams, 0, 0);
5231 dstCapacity -= fhSize;
5240 RETURN_ERROR_IF(dstCapacity<3, dstSize_tooSmall,
"no room for epilogue");
5242 op += ZSTD_blockHeaderSize;
5243 dstCapacity -= ZSTD_blockHeaderSize;
5248 RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall,
"no room for checksum");
5249 DEBUGLOG(4,
"ZSTD_writeEpilogue: write checksum : %08X", (
unsigned)checksum);
5261 if (cctx->traceCtx && ZSTD_trace_compress_end != NULL) {
5266 trace.streaming = streaming;
5267 trace.dictionaryID = cctx->
dictID;
5273 ZSTD_trace_compress_end(cctx->traceCtx, &trace);
5283 void* dst,
size_t dstCapacity,
5284 const void* src,
size_t srcSize)
5287 size_t const cSize = ZSTD_compressContinue_internal(cctx,
5288 dst, dstCapacity, src, srcSize,
5291 endResult = ZSTD_writeEpilogue(cctx, (
char*)dst + cSize, dstCapacity-cSize);
5296 DEBUGLOG(4,
"end of frame : controlling src size");
5300 "error : pledgedSrcSize = %u, while realSrcSize = %u",
5305 return cSize + endResult;
5310 void* dst,
size_t dstCapacity,
5311 const void* src,
size_t srcSize)
5317 void* dst,
size_t dstCapacity,
5318 const void* src,
size_t srcSize,
5319 const void* dict,
size_t dictSize,
5320 ZSTD_parameters params)
5322 DEBUGLOG(4,
"ZSTD_compress_advanced");
5335 void* dst,
size_t dstCapacity,
5336 const void* src,
size_t srcSize,
5337 const void* dict,
size_t dictSize,
5338 const ZSTD_CCtx_params* params)
5340 DEBUGLOG(4,
"ZSTD_compress_advanced_internal (srcSize:%u)", (
unsigned)srcSize);
5348 void* dst,
size_t dstCapacity,
5349 const void* src,
size_t srcSize,
5350 const void* dict,
size_t dictSize,
5351 int compressionLevel)
5354 ZSTD_parameters
const params = ZSTD_getParams_internal(compressionLevel, srcSize, dict ? dictSize : 0,
ZSTD_cpm_noAttachDict);
5355 assert(params.fParams.contentSizeFlag == 1);
5358 DEBUGLOG(4,
"ZSTD_compress_usingDict (srcSize=%u)", (
unsigned)srcSize);
5363 void* dst,
size_t dstCapacity,
5364 const void* src,
size_t srcSize,
5365 int compressionLevel)
5367 DEBUGLOG(4,
"ZSTD_compressCCtx (srcSize=%u)", (
unsigned)srcSize);
5373 const void* src,
size_t srcSize,
5374 int compressionLevel)
5377#if ZSTD_COMPRESS_HEAPMODE
5380 result =
ZSTD_compressCCtx(cctx, dst, dstCapacity, src, srcSize, compressionLevel);
5384 ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
5385 result =
ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
5386 ZSTD_freeCCtxContent(&ctxBody);
5397 size_t dictSize, ZSTD_compressionParameters cParams,
5398 ZSTD_dictLoadMethod_e dictLoadMethod)
5405 + ZSTD_sizeof_matchState(&cParams, ZSTD_resolveRowMatchFinderMode(ZSTD_ps_auto, &cParams),
5407 + (dictLoadMethod == ZSTD_dlm_byRef ? 0
5419 if (cdict==NULL)
return 0;
5420 DEBUGLOG(5,
"sizeof(*cdict) : %u", (
unsigned)
sizeof(*cdict));
5426static size_t ZSTD_initCDict_internal(
5428 const void* dictBuffer,
size_t dictSize,
5429 ZSTD_dictLoadMethod_e dictLoadMethod,
5430 ZSTD_dictContentType_e dictContentType,
5431 ZSTD_CCtx_params params)
5433 DEBUGLOG(3,
"ZSTD_initCDict_internal (dictContentType:%u)", (
unsigned)dictContentType);
5437 if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dictBuffer) || (!dictSize)) {
5443 ZSTD_memcpy(internalBuffer, dictBuffer, dictSize);
5457 params.useRowMatchFinder,
5465 params.fParams.contentSizeFlag = 1;
5466 {
size_t const dictID = ZSTD_compress_insertDictionary(
5479static ZSTD_CDict* ZSTD_createCDict_advanced_internal(
size_t dictSize,
5480 ZSTD_dictLoadMethod_e dictLoadMethod,
5481 ZSTD_compressionParameters cParams,
5482 ZSTD_paramSwitch_e useRowMatchFinder,
5483 U32 enableDedicatedDictSearch,
5484 ZSTD_customMem customMem)
5486 if ((!customMem.customAlloc) ^ (!customMem.customFree))
return NULL;
5488 {
size_t const workspaceSize =
5491 ZSTD_sizeof_matchState(&cParams, useRowMatchFinder, enableDedicatedDictSearch, 0) +
5492 (dictLoadMethod == ZSTD_dlm_byRef ? 0
5516 ZSTD_dictLoadMethod_e dictLoadMethod,
5517 ZSTD_dictContentType_e dictContentType,
5518 ZSTD_compressionParameters cParams,
5519 ZSTD_customMem customMem)
5521 ZSTD_CCtx_params cctxParams;
5524 cctxParams.cParams = cParams;
5525 cctxParams.customMem = customMem;
5527 dictBuffer, dictSize,
5528 dictLoadMethod, dictContentType,
5529 &cctxParams, customMem);
5533 const void* dict,
size_t dictSize,
5534 ZSTD_dictLoadMethod_e dictLoadMethod,
5535 ZSTD_dictContentType_e dictContentType,
5536 const ZSTD_CCtx_params* originalCctxParams,
5537 ZSTD_customMem customMem)
5539 ZSTD_CCtx_params cctxParams = *originalCctxParams;
5540 ZSTD_compressionParameters cParams;
5543 DEBUGLOG(3,
"ZSTD_createCDict_advanced2, mode %u", (
unsigned)dictContentType);
5544 if (!customMem.customAlloc ^ !customMem.customFree)
return NULL;
5546 if (cctxParams.enableDedicatedDictSearch) {
5547 cParams = ZSTD_dedicatedDictSearch_getCParams(
5548 cctxParams.compressionLevel, dictSize);
5549 ZSTD_overrideCParams(&cParams, &cctxParams.cParams);
5555 if (!ZSTD_dedicatedDictSearch_isSupported(&cParams)) {
5557 cctxParams.enableDedicatedDictSearch = 0;
5562 DEBUGLOG(3,
"ZSTD_createCDict_advanced2: DDS: %u", cctxParams.enableDedicatedDictSearch);
5563 cctxParams.cParams = cParams;
5564 cctxParams.useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(cctxParams.useRowMatchFinder, &cParams);
5566 cdict = ZSTD_createCDict_advanced_internal(dictSize,
5567 dictLoadMethod, cctxParams.cParams,
5568 cctxParams.useRowMatchFinder, cctxParams.enableDedicatedDictSearch,
5571 if (!cdict ||
ZSTD_isError( ZSTD_initCDict_internal(cdict,
5573 dictLoadMethod, dictContentType,
5586 ZSTD_dlm_byCopy, ZSTD_dct_auto,
5587 cParams, ZSTD_defaultCMem);
5597 ZSTD_dlm_byRef, ZSTD_dct_auto,
5598 cParams, ZSTD_defaultCMem);
5606 if (cdict==NULL)
return 0;
5607 { ZSTD_customMem
const cMem = cdict->
customMem;
5610 if (!cdictInWorkspace) {
5631 void* workspace,
size_t workspaceSize,
5632 const void* dict,
size_t dictSize,
5633 ZSTD_dictLoadMethod_e dictLoadMethod,
5634 ZSTD_dictContentType_e dictContentType,
5635 ZSTD_compressionParameters cParams)
5637 ZSTD_paramSwitch_e
const useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(ZSTD_ps_auto, &cParams);
5639 size_t const matchStateSize = ZSTD_sizeof_matchState(&cParams, useRowMatchFinder, 1, 0);
5641 + (dictLoadMethod == ZSTD_dlm_byRef ? 0
5646 ZSTD_CCtx_params params;
5648 if ((
size_t)workspace & 7)
return NULL;
5654 if (cdict == NULL)
return NULL;
5658 DEBUGLOG(4,
"(workspaceSize < neededSize) : (%u < %u) => %u",
5659 (
unsigned)workspaceSize, (
unsigned)neededSize, (
unsigned)(workspaceSize < neededSize));
5660 if (workspaceSize < neededSize)
return NULL;
5663 params.cParams = cParams;
5664 params.useRowMatchFinder = useRowMatchFinder;
5670 dictLoadMethod, dictContentType,
5689 if (cdict==NULL)
return 0;
5696static size_t ZSTD_compressBegin_usingCDict_internal(
5698 ZSTD_frameParameters
const fParams,
unsigned long long const pledgedSrcSize)
5700 ZSTD_CCtx_params cctxParams;
5701 DEBUGLOG(4,
"ZSTD_compressBegin_usingCDict_internal");
5705 ZSTD_parameters params;
5706 params.fParams = fParams;
5715 ZSTD_CCtxParams_init_internal(&cctxParams, ¶ms, cdict->
compressionLevel);
5722 U32 const limitedSrcSize = (
U32)
MIN(pledgedSrcSize, 1U << 19);
5723 U32 const limitedSrcLog = limitedSrcSize > 1 ?
ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1;
5724 cctxParams.cParams.windowLog =
MAX(cctxParams.cParams.windowLog, limitedSrcLog);
5726 return ZSTD_compressBegin_internal(cctx,
5729 &cctxParams, pledgedSrcSize,
5739 ZSTD_frameParameters
const fParams,
unsigned long long const pledgedSrcSize)
5741 return ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, pledgedSrcSize);
5748 ZSTD_frameParameters
const fParams = { 0 , 0 , 0 };
5760static size_t ZSTD_compress_usingCDict_internal(
ZSTD_CCtx* cctx,
5761 void* dst,
size_t dstCapacity,
5762 const void* src,
size_t srcSize,
5763 const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
5765 FORWARD_IF_ERROR(ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, srcSize),
"");
5773 void* dst,
size_t dstCapacity,
5774 const void* src,
size_t srcSize,
5775 const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
5777 return ZSTD_compress_usingCDict_internal(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
5786 void* dst,
size_t dstCapacity,
5787 const void* src,
size_t srcSize,
5790 ZSTD_frameParameters
const fParams = { 1 , 0 , 0 };
5791 return ZSTD_compress_usingCDict_internal(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
5834 if (cdict != NULL && ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize))
5849 DEBUGLOG(4,
"ZSTD_resetCStream: pledgedSrcSize = %u", (
unsigned)pledgedSrcSize);
5860 const void* dict,
size_t dictSize,
const ZSTD_CDict* cdict,
5861 const ZSTD_CCtx_params* params,
5862 unsigned long long pledgedSrcSize)
5864 DEBUGLOG(4,
"ZSTD_initCStream_internal");
5869 assert(!((dict) && (cdict)));
5883 ZSTD_frameParameters fParams,
5884 unsigned long long pledgedSrcSize)
5886 DEBUGLOG(4,
"ZSTD_initCStream_usingCDict_advanced");
5897 DEBUGLOG(4,
"ZSTD_initCStream_usingCDict");
5909 const void* dict,
size_t dictSize,
5910 ZSTD_parameters params,
unsigned long long pss)
5917 DEBUGLOG(4,
"ZSTD_initCStream_advanced");
5928 DEBUGLOG(4,
"ZSTD_initCStream_usingDict");
5942 DEBUGLOG(4,
"ZSTD_initCStream_srcSize");
5961static size_t ZSTD_nextInputSizeHint(
const ZSTD_CCtx* cctx)
5968 if (hintInSize==0) hintInSize = cctx->
blockSize;
5976static size_t ZSTD_compressStream_generic(
ZSTD_CStream* zcs,
5981 const char*
const istart = (
assert(input != NULL), (
const char*)
input->src);
5982 const char*
const iend = (istart != NULL) ? istart +
input->size : istart;
5983 const char* ip = (istart != NULL) ? istart +
input->pos : istart;
5984 char*
const ostart = (
assert(output != NULL), (
char*)
output->dst);
5985 char*
const oend = (ostart != NULL) ? ostart +
output->size : ostart;
5986 char* op = (ostart != NULL) ? ostart +
output->pos : ostart;
5987 U32 someMoreWork = 1;
5990 DEBUGLOG(5,
"ZSTD_compressStream_generic, flush=%i, srcSize = %zu", (
int)flushMode,
input->size -
input->pos);
6012 while (someMoreWork) {
6016 RETURN_ERROR(init_missing,
"call ZSTD_initCStream() first!");
6025 op, oend-op, ip, iend-ip);
6026 DEBUGLOG(4,
"ZSTD_compressEnd : cSize=%u", (
unsigned)cSize);
6032 someMoreWork = 0;
break;
6041 if (ip) ip += loaded;
6045 someMoreWork = 0;
break;
6050 someMoreWork = 0;
break;
6055 && ( (
size_t)(iend - ip) < zcs->
blockSize) ) {
6059 someMoreWork = 0;
break;
6064 someMoreWork = 0;
break;
6068 DEBUGLOG(5,
"stream compression stage (flushMode==%u)", flushMode);
6072 size_t oSize = oend-op;
6079 if (inputBuffered) {
6080 unsigned const lastBlock = (flushMode ==
ZSTD_e_end) && (ip==iend);
6085 zcs->inBuff + zcs->inToCompress, iSize);
6086 FORWARD_IF_ERROR(cSize,
"%s", lastBlock ?
"ZSTD_compressEnd failed" :
"ZSTD_compressContinue failed");
6092 DEBUGLOG(5,
"inBuffTarget:%u / inBuffSize:%u",
6098 unsigned const lastBlock = (flushMode ==
ZSTD_e_end) && (ip + iSize == iend);
6103 if (ip) ip += iSize;
6104 FORWARD_IF_ERROR(cSize,
"%s", lastBlock ?
"ZSTD_compressEnd failed" :
"ZSTD_compressContinue failed");
6106 if (lastBlock)
assert(ip == iend);
6111 DEBUGLOG(5,
"Frame completed directly in outBuffer");
6128 DEBUGLOG(5,
"toFlush: %u into %u ==> flushed: %u",
6129 (
unsigned)toFlush, (
unsigned)(oend-op), (
unsigned)flushed);
6133 if (toFlush!=flushed) {
6141 DEBUGLOG(5,
"Frame completed on flush");
6155 input->pos = ip - istart;
6156 output->pos = op - ostart;
6158 return ZSTD_nextInputSizeHint(zcs);
6161static size_t ZSTD_nextInputSizeHint_MTorST(
const ZSTD_CCtx* cctx)
6163#ifdef ZSTD_MULTITHREAD
6165 assert(cctx->mtctx != NULL);
6169 return ZSTD_nextInputSizeHint(cctx);
6176 return ZSTD_nextInputSizeHint_MTorST(zcs);
6185 DEBUGLOG(5,
"ZSTD_setBufferExpectations (for advanced stable in/out modes)");
6197static size_t ZSTD_checkBufferStability(
ZSTD_CCtx const* cctx,
6205 RETURN_ERROR(stabilityCondition_notRespected,
"ZSTD_c_stableInBuffer enabled but input differs!");
6209 size_t const outBufferSize =
output->size -
output->pos;
6211 RETURN_ERROR(stabilityCondition_notRespected,
"ZSTD_c_stableOutBuffer enabled but output size differs!");
6216static size_t ZSTD_CCtx_init_compressStream2(
ZSTD_CCtx* cctx,
6232 DEBUGLOG(4,
"ZSTD_compressStream2 : transparent init stage");
6235 {
size_t const dictSize = prefixDict.
dict
6244 params.useBlockSplitter = ZSTD_resolveBlockSplitterMode(params.useBlockSplitter, ¶ms.cParams);
6245 params.ldmParams.enableLdm = ZSTD_resolveEnableLdm(params.ldmParams.enableLdm, ¶ms.cParams);
6246 params.useRowMatchFinder = ZSTD_resolveRowMatchFinderMode(params.useRowMatchFinder, ¶ms.cParams);
6247 params.validateSequences = ZSTD_resolveExternalSequenceValidation(params.validateSequences);
6248 params.maxBlockSize = ZSTD_resolveMaxBlockSize(params.maxBlockSize);
6249 params.searchForExternalRepcodes = ZSTD_resolveExternalRepcodeSearch(params.searchForExternalRepcodes, params.compressionLevel);
6251#ifdef ZSTD_MULTITHREAD
6255 parameter_combination_unsupported,
6256 "External sequence producer isn't supported with nbWorkers >= 1"
6260 params.nbWorkers = 0;
6262 if (params.nbWorkers > 0) {
6264 cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0;
6267 if (cctx->mtctx == NULL) {
6268 DEBUGLOG(4,
"ZSTD_compressStream2: creating new mtctx for nbWorkers=%u",
6271 RETURN_ERROR_IF(cctx->mtctx == NULL, memory_allocation,
"NULL pointer!");
6274 DEBUGLOG(4,
"call ZSTDMT_initCStream_internal as nbWorkers=%u", params.nbWorkers);
6292 ¶ms, pledgedSrcSize,
6319 DEBUGLOG(5,
"ZSTD_compressStream2, endOp=%u ", (
unsigned)endOp);
6321 RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall,
"invalid output buffer");
6322 RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong,
"invalid input buffer");
6328 size_t const inputSize = input->size - input->pos;
6339 input->pos = input->size;
6347 FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, totalInputSize),
"compressStream2 initialization failed");
6348 ZSTD_setBufferExpectations(cctx, output, input);
6352 FORWARD_IF_ERROR(ZSTD_checkBufferStability(cctx, output, input, endOp),
"invalid buffers");
6354#ifdef ZSTD_MULTITHREAD
6369 size_t const ipos = input->pos;
6370 size_t const opos = output->pos;
6375 || (endOp ==
ZSTD_e_end && flushMin == 0) ) {
6387 if (input->pos != ipos || output->pos != opos || input->pos == input->size || output->pos == output->size)
6394 if (flushMin == 0 || output->pos == output->size)
6398 DEBUGLOG(5,
"completed ZSTD_compressStream2 delegating to ZSTDMT_compressStream_generic");
6403 ZSTD_setBufferExpectations(cctx, output, input);
6407 FORWARD_IF_ERROR( ZSTD_compressStream_generic(cctx, output, input, endOp) ,
"");
6408 DEBUGLOG(5,
"completed ZSTD_compressStream2");
6409 ZSTD_setBufferExpectations(cctx, output, input);
6415 void* dst,
size_t dstCapacity,
size_t* dstPos,
6416 const void* src,
size_t srcSize,
size_t* srcPos,
6422 output.size = dstCapacity;
6423 output.pos = *dstPos;
6425 input.size = srcSize;
6426 input.pos = *srcPos;
6429 *dstPos = output.pos;
6430 *srcPos = input.pos;
6436 void* dst,
size_t dstCapacity,
6437 const void* src,
size_t srcSize)
6441 DEBUGLOG(4,
"ZSTD_compress2 (srcSize=%u)", (
unsigned)srcSize);
6449 dst, dstCapacity, &oPos,
6450 src, srcSize, &iPos,
6458 assert(oPos == dstCapacity);
6471ZSTD_validateSequence(
U32 offCode,
U32 matchLength,
U32 minMatch,
6472 size_t posInSrc,
U32 windowLog,
size_t dictSize,
int useSequenceProducer)
6474 U32 const windowSize = 1u << windowLog;
6480 size_t const offsetBound = posInSrc > windowSize ? (size_t)windowSize : posInSrc + (
size_t)dictSize;
6481 size_t const matchLenLowerBound = (minMatch == 3 || useSequenceProducer) ? 3 : 4;
6484 RETURN_ERROR_IF(matchLength < matchLenLowerBound, externalSequences_invalid,
"Matchlength too small for the minMatch");
6493 if (!ll0 && rawOffset == rep[0]) {
6495 }
else if (rawOffset == rep[1]) {
6497 }
else if (rawOffset == rep[2]) {
6499 }
else if (ll0 && rawOffset == rep[0] - 1) {
6508 const ZSTD_Sequence*
const inSeqs,
size_t inSeqsSize,
6509 const void* src,
size_t blockSize,
6510 ZSTD_paramSwitch_e externalRepSearch)
6513 U32 const startIdx = idx;
6514 BYTE const* ip = (
BYTE const*)(src);
6515 const BYTE*
const iend = ip + blockSize;
6519 DEBUGLOG(5,
"ZSTD_copySequencesToSeqStoreExplicitBlockDelim (blockSize = %zu)", blockSize);
6529 for (; idx < inSeqsSize && (inSeqs[idx].matchLength != 0 || inSeqs[idx].offset != 0); ++idx) {
6530 U32 const litLength = inSeqs[idx].litLength;
6531 U32 const matchLength = inSeqs[idx].matchLength;
6534 if (externalRepSearch == ZSTD_ps_disable) {
6537 U32 const ll0 = (litLength == 0);
6538 offBase = ZSTD_finalizeOffBase(inSeqs[idx].offset, updatedRepcodes.
rep, ll0);
6542 DEBUGLOG(6,
"Storing sequence: (of: %u, ml: %u, ll: %u)", offBase, matchLength, litLength);
6544 seqPos->
posInSrc += litLength + matchLength;
6547 "Sequence validation failed");
6550 "Not enough memory allocated. Try adjusting ZSTD_c_minMatch.");
6552 ip += matchLength + litLength;
6556 assert(externalRepSearch != ZSTD_ps_auto);
6558 if (externalRepSearch == ZSTD_ps_disable && idx != startIdx) {
6559 U32*
const rep = updatedRepcodes.
rep;
6560 U32 lastSeqIdx = idx - 1;
6562 if (lastSeqIdx >= startIdx + 2) {
6563 rep[2] = inSeqs[lastSeqIdx - 2].offset;
6564 rep[1] = inSeqs[lastSeqIdx - 1].offset;
6565 rep[0] = inSeqs[lastSeqIdx].offset;
6566 }
else if (lastSeqIdx == startIdx + 1) {
6568 rep[1] = inSeqs[lastSeqIdx - 1].offset;
6569 rep[0] = inSeqs[lastSeqIdx].offset;
6571 assert(lastSeqIdx == startIdx);
6574 rep[0] = inSeqs[lastSeqIdx].offset;
6580 if (inSeqs[idx].litLength) {
6581 DEBUGLOG(6,
"Storing last literals of size: %u", inSeqs[idx].litLength);
6582 ZSTD_storeLastLiterals(&cctx->
seqStore, ip, inSeqs[idx].litLength);
6583 ip += inSeqs[idx].litLength;
6584 seqPos->
posInSrc += inSeqs[idx].litLength;
6586 RETURN_ERROR_IF(ip != iend, externalSequences_invalid,
"Blocksize doesn't agree with block delimiter!");
6587 seqPos->
idx = idx+1;
6593 const ZSTD_Sequence*
const inSeqs,
size_t inSeqsSize,
6594 const void* src,
size_t blockSize, ZSTD_paramSwitch_e externalRepSearch)
6600 BYTE const* ip = (
BYTE const*)(src);
6601 BYTE const* iend = ip + blockSize;
6603 U32 bytesAdjustment = 0;
6604 U32 finalMatchSplit = 0;
6607 (void)externalRepSearch;
6616 DEBUGLOG(5,
"ZSTD_copySequencesToSeqStoreNoBlockDelim: idx: %u PIS: %u blockSize: %zu", idx, startPosInSequence, blockSize);
6617 DEBUGLOG(5,
"Start seq: idx: %u (of: %u ml: %u ll: %u)", idx, inSeqs[idx].offset, inSeqs[idx].matchLength, inSeqs[idx].litLength);
6619 while (endPosInSequence && idx < inSeqsSize && !finalMatchSplit) {
6620 const ZSTD_Sequence currSeq = inSeqs[idx];
6621 U32 litLength = currSeq.litLength;
6622 U32 matchLength = currSeq.matchLength;
6623 U32 const rawOffset = currSeq.offset;
6627 if (endPosInSequence >= currSeq.litLength + currSeq.matchLength) {
6628 if (startPosInSequence >= litLength) {
6629 startPosInSequence -= litLength;
6631 matchLength -= startPosInSequence;
6633 litLength -= startPosInSequence;
6636 endPosInSequence -= currSeq.litLength + currSeq.matchLength;
6637 startPosInSequence = 0;
6641 DEBUGLOG(6,
"Require a split: diff: %u, idx: %u PIS: %u",
6642 currSeq.litLength + currSeq.matchLength - endPosInSequence, idx, endPosInSequence);
6643 if (endPosInSequence > litLength) {
6644 U32 firstHalfMatchLength;
6645 litLength = startPosInSequence >= litLength ? 0 : litLength - startPosInSequence;
6646 firstHalfMatchLength = endPosInSequence - startPosInSequence - litLength;
6647 if (matchLength > blockSize && firstHalfMatchLength >= cctx->
appliedParams.cParams.minMatch) {
6649 U32 secondHalfMatchLength = currSeq.matchLength + currSeq.litLength - endPosInSequence;
6650 if (secondHalfMatchLength < cctx->appliedParams.cParams.minMatch) {
6652 endPosInSequence -= cctx->
appliedParams.cParams.minMatch - secondHalfMatchLength;
6653 bytesAdjustment = cctx->
appliedParams.cParams.minMatch - secondHalfMatchLength;
6654 firstHalfMatchLength -= bytesAdjustment;
6656 matchLength = firstHalfMatchLength;
6659 finalMatchSplit = 1;
6666 bytesAdjustment = endPosInSequence - currSeq.litLength;
6667 endPosInSequence = currSeq.litLength;
6676 {
U32 const ll0 = (litLength == 0);
6677 offBase = ZSTD_finalizeOffBase(rawOffset, updatedRepcodes.
rep, ll0);
6682 seqPos->
posInSrc += litLength + matchLength;
6685 "Sequence validation failed");
6687 DEBUGLOG(6,
"Storing sequence: (of: %u, ml: %u, ll: %u)", offBase, matchLength, litLength);
6689 "Not enough memory allocated. Try adjusting ZSTD_c_minMatch.");
6691 ip += matchLength + litLength;
6692 if (!finalMatchSplit)
6695 DEBUGLOG(5,
"Ending seq: idx: %u (of: %u ml: %u ll: %u)", idx, inSeqs[idx].offset, inSeqs[idx].matchLength, inSeqs[idx].litLength);
6696 assert(idx == inSeqsSize || endPosInSequence <= inSeqs[idx].litLength + inSeqs[idx].matchLength);
6701 iend -= bytesAdjustment;
6704 U32 lastLLSize = (
U32)(iend - ip);
6706 DEBUGLOG(6,
"Storing last literals of size: %u", lastLLSize);
6707 ZSTD_storeLastLiterals(&cctx->
seqStore, ip, lastLLSize);
6711 return bytesAdjustment;
6715 const ZSTD_Sequence*
const inSeqs,
size_t inSeqsSize,
6716 const void* src,
size_t blockSize, ZSTD_paramSwitch_e externalRepSearch);
6721 if (mode == ZSTD_sf_explicitBlockDelimiters) {
6723 }
else if (mode == ZSTD_sf_noBlockDelimiters) {
6726 assert(sequenceCopier != NULL);
6727 return sequenceCopier;
6735blockSize_explicitDelimiter(
const ZSTD_Sequence* inSeqs,
size_t inSeqsSize,
ZSTD_sequencePosition seqPos)
6738 size_t blockSize = 0;
6739 size_t spos = seqPos.
idx;
6740 DEBUGLOG(6,
"blockSize_explicitDelimiter : seq %zu / %zu", spos, inSeqsSize);
6741 assert(spos <= inSeqsSize);
6742 while (spos < inSeqsSize) {
6743 end = (inSeqs[spos].offset == 0);
6744 blockSize += inSeqs[spos].litLength + inSeqs[spos].matchLength;
6746 if (inSeqs[spos].matchLength != 0)
6747 RETURN_ERROR(externalSequences_invalid,
"delimiter format error : both matchlength and offset must be == 0");
6753 RETURN_ERROR(externalSequences_invalid,
"Reached end of sequences without finding a block delimiter");
6758static size_t blockSize_noDelimiter(
size_t blockSize,
size_t remaining)
6760 int const lastBlock = (remaining <= blockSize);
6761 return lastBlock ? remaining : blockSize;
6764static size_t determine_blockSize(ZSTD_sequenceFormat_e mode,
6765 size_t blockSize,
size_t remaining,
6768 DEBUGLOG(6,
"determine_blockSize : remainingSize = %zu", remaining);
6769 if (mode == ZSTD_sf_noBlockDelimiters)
6770 return blockSize_noDelimiter(blockSize, remaining);
6771 {
size_t const explicitBlockSize = blockSize_explicitDelimiter(inSeqs, inSeqsSize, seqPos);
6772 FORWARD_IF_ERROR(explicitBlockSize,
"Error while determining block size with explicit delimiters");
6773 if (explicitBlockSize > blockSize)
6774 RETURN_ERROR(externalSequences_invalid,
"sequences incorrectly define a too large block");
6775 if (explicitBlockSize > remaining)
6776 RETURN_ERROR(externalSequences_invalid,
"sequences define a frame longer than source");
6777 return explicitBlockSize;
6787ZSTD_compressSequences_internal(
ZSTD_CCtx* cctx,
6788 void* dst,
size_t dstCapacity,
6789 const ZSTD_Sequence* inSeqs,
size_t inSeqsSize,
6790 const void* src,
size_t srcSize)
6793 size_t remaining = srcSize;
6800 DEBUGLOG(4,
"ZSTD_compressSequences_internal srcSize: %zu, inSeqsSize: %zu", srcSize, inSeqsSize);
6802 if (remaining == 0) {
6804 RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall,
"No room for empty frame block header");
6806 op += ZSTD_blockHeaderSize;
6807 dstCapacity -= ZSTD_blockHeaderSize;
6808 cSize += ZSTD_blockHeaderSize;
6812 size_t compressedSeqsSize;
6814 size_t additionalByteAdjustment;
6815 size_t blockSize = determine_blockSize(cctx->
appliedParams.blockDelimiters,
6817 inSeqs, inSeqsSize, seqPos);
6818 U32 const lastBlock = (blockSize == remaining);
6820 assert(blockSize <= remaining);
6822 DEBUGLOG(5,
"Working on new block. Blocksize: %zu (total:%zu)", blockSize, (ip - (
const BYTE*)src) + blockSize);
6824 additionalByteAdjustment = sequenceCopier(cctx, &seqPos, inSeqs, inSeqsSize, ip, blockSize, cctx->
appliedParams.searchForExternalRepcodes);
6826 blockSize -= additionalByteAdjustment;
6834 DEBUGLOG(5,
"Block too small, writing out nocompress block: cSize: %zu", cBlockSize);
6835 cSize += cBlockSize;
6838 remaining -= blockSize;
6839 dstCapacity -= cBlockSize;
6843 RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize, dstSize_tooSmall,
"not enough dstCapacity to write a new compressed block");
6847 op + ZSTD_blockHeaderSize , dstCapacity - ZSTD_blockHeaderSize,
6851 FORWARD_IF_ERROR(compressedSeqsSize,
"Compressing sequences of block failed");
6852 DEBUGLOG(5,
"Compressed sequences size: %zu", compressedSeqsSize);
6856 ZSTD_isRLE(ip, blockSize)) {
6861 compressedSeqsSize = 1;
6864 if (compressedSeqsSize == 0) {
6868 DEBUGLOG(5,
"Writing out nocompress block, size: %zu", cBlockSize);
6869 }
else if (compressedSeqsSize == 1) {
6872 DEBUGLOG(5,
"Writing out RLE block, size: %zu", cBlockSize);
6876 ZSTD_blockState_confirmRepcodesAndEntropyTables(&cctx->
blockState);
6883 cBlockSize = ZSTD_blockHeaderSize + compressedSeqsSize;
6884 DEBUGLOG(5,
"Writing out compressed block, size: %zu", cBlockSize);
6887 cSize += cBlockSize;
6894 remaining -= blockSize;
6895 dstCapacity -= cBlockSize;
6898 DEBUGLOG(5,
"cSize running total: %zu (remaining dstCapacity=%zu)", cSize, dstCapacity);
6901 DEBUGLOG(4,
"cSize final total: %zu", cSize);
6906 void* dst,
size_t dstCapacity,
6907 const ZSTD_Sequence* inSeqs,
size_t inSeqsSize,
6908 const void* src,
size_t srcSize)
6912 size_t compressedBlocksSize = 0;
6913 size_t frameHeaderSize = 0;
6916 DEBUGLOG(4,
"ZSTD_compressSequences (dstCapacity=%zu)", dstCapacity);
6920 frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->
appliedParams, srcSize, cctx->
dictID);
6921 op += frameHeaderSize;
6922 dstCapacity -= frameHeaderSize;
6923 cSize += frameHeaderSize;
6928 compressedBlocksSize = ZSTD_compressSequences_internal(cctx,
6933 cSize += compressedBlocksSize;
6934 dstCapacity -= compressedBlocksSize;
6938 RETURN_ERROR_IF(dstCapacity<4, dstSize_tooSmall,
"no room for checksum");
6939 DEBUGLOG(4,
"Write checksum : %08X", (
unsigned)checksum);
6944 DEBUGLOG(4,
"Final compressed size: %zu", cSize);
6962 input.size = input.pos;
6971 FORWARD_IF_ERROR(remainingToFlush ,
"ZSTD_compressStream2(,,ZSTD_e_end) failed");
6972 if (zcs->
appliedParams.nbWorkers > 0)
return remainingToFlush;
6976 size_t const toFlush = remainingToFlush + lastBlockSize + checksumSize;
6977 DEBUGLOG(4,
"ZSTD_endStream : remaining to flush : %u", (
unsigned)toFlush);
6990static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(
int const compressionLevel,
size_t const dictSize)
6992 ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, 0, dictSize,
ZSTD_cpm_createCDict);
6993 switch (cParams.strategy) {
7011static int ZSTD_dedicatedDictSearch_isSupported(
7012 ZSTD_compressionParameters
const* cParams)
7016 && (cParams->hashLog > cParams->chainLog)
7017 && (cParams->chainLog <= 24);
7025static void ZSTD_dedicatedDictSearch_revertCParams(
7026 ZSTD_compressionParameters* cParams) {
7027 switch (cParams->strategy) {
7035 if (cParams->hashLog < ZSTD_HASHLOG_MIN) {
7036 cParams->hashLog = ZSTD_HASHLOG_MIN;
7062 size_t const addedSize =
unknown && dictSize > 0 ? 500 : 0;
7072static ZSTD_compressionParameters ZSTD_getCParams_internal(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize,
ZSTD_cParamMode_e mode)
7074 U64 const rSize = ZSTD_getCParamRowSize(srcSizeHint, dictSize, mode);
7075 U32 const tableID = (rSize <= 256
KB) + (rSize <= 128
KB) + (rSize <= 16
KB);
7077 DEBUGLOG(5,
"ZSTD_getCParams_internal (cLevel=%i)", compressionLevel);
7081 else if (compressionLevel < 0) row = 0;
7083 else row = compressionLevel;
7085 { ZSTD_compressionParameters cp = ZSTD_defaultCParameters[tableID][row];
7086 DEBUGLOG(5,
"ZSTD_getCParams_internal selected tableID: %u row: %u strat: %u", tableID, row, (
U32)cp.strategy);
7088 if (compressionLevel < 0) {
7090 cp.targetLength = (unsigned)(-clampedCompressionLevel);
7093 return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize, mode, ZSTD_ps_auto);
7100ZSTD_compressionParameters
ZSTD_getCParams(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize)
7103 return ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize,
ZSTD_cpm_unknown);
7110static ZSTD_parameters ZSTD_getParams_internal(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize,
ZSTD_cParamMode_e mode) {
7111 ZSTD_parameters params;
7112 ZSTD_compressionParameters
const cParams = ZSTD_getCParams_internal(compressionLevel, srcSizeHint, dictSize, mode);
7113 DEBUGLOG(5,
"ZSTD_getParams (cLevel=%i)", compressionLevel);
7115 params.cParams = cParams;
7116 params.fParams.contentSizeFlag = 1;
7124ZSTD_parameters
ZSTD_getParams(
int compressionLevel,
unsigned long long srcSizeHint,
size_t dictSize) {
7126 return ZSTD_getParams_internal(compressionLevel, srcSizeHint, dictSize,
ZSTD_cpm_unknown);
7131 void* extSeqProdState,
7132 ZSTD_sequenceProducer_F extSeqProdFunc
7141 ZSTD_CCtx_params* params,
7142 void* extSeqProdState,
7143 ZSTD_sequenceProducer_F extSeqProdFunc
7146 if (extSeqProdFunc != NULL) {
7147 params->extSeqProdFunc = extSeqProdFunc;
7148 params->extSeqProdState = extSeqProdState;
7150 params->extSeqProdFunc = NULL;
7151 params->extSeqProdState = NULL;
MEM_STATIC void ZSTD_customFree(void *ptr, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC unsigned ZSTD_highbit32(U32 val)
MEM_STATIC U64 ZSTD_rotateRight_U64(U64 const value, U32 count)
#define STREAM_ACCUMULATOR_MIN
#define FORCE_INLINE_TEMPLATE
MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void)
#define assert(condition)
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
#define RETURN_ERROR(err,...)
#define FORWARD_IF_ERROR(err,...)
#define RETURN_ERROR_IF(cond, err,...)
size_t FSE_buildCTable_wksp(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize)
size_t HIST_count_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, void *workSpace, size_t workSpaceSize)
size_t HIST_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, void *workSpace, size_t workSpaceSize)
int HUF_validateCTable(const HUF_CElt *CTable, const unsigned *count, unsigned maxSymbolValue)
#define HUF_SYMBOLVALUE_MAX
size_t HUF_writeCTable_wksp(void *dst, size_t maxDstSize, const HUF_CElt *CTable, unsigned maxSymbolValue, unsigned huffLog, void *workspace, size_t workspaceSize)
#define HUF_WORKSPACE_SIZE
size_t HUF_estimateCompressedSize(const HUF_CElt *CTable, const unsigned *count, unsigned maxSymbolValue)
#define HUF_OPTIMAL_DEPTH_THRESHOLD
size_t HUF_buildCTable_wksp(HUF_CElt *tree, const unsigned *count, U32 maxSymbolValue, U32 maxNbBits, void *workSpace, size_t wkspSize)
size_t HUF_readCTable(HUF_CElt *CTable, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize, unsigned *hasZeroWeights)
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, void *workSpace, size_t wkspSize, HUF_CElt *table, const unsigned *count, int flags)
MEM_STATIC unsigned MEM_32bits(void)
MEM_STATIC size_t MEM_readST(const void *memPtr)
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
MEM_STATIC unsigned MEM_64bits(void)
MEM_STATIC void MEM_writeLE64(void *memPtr, U64 val64)
MEM_STATIC void MEM_writeLE24(void *memPtr, U32 val)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
ZSTD_buffered_policy_e bufferedPolicy
ZSTD_blockSplitCtx blockSplitCtx
ZSTD_CCtx_params appliedParams
ZSTD_prefixDict prefixDict
SeqCollector seqCollector
ZSTD_CCtx_params simpleApiParams
size_t expectedOutBufferSize
ZSTD_compressionStage_e stage
ZSTD_CCtx_params requestedParams
rawSeqStore_t externSeqStore
unsigned long long pledgedSrcSizePlusOne
ZSTD_blockState_t blockState
ZSTD_cStreamStage streamStage
unsigned long long consumedSrcSize
ZSTD_Sequence * extSeqBuf
size_t stableIn_notConsumed
unsigned long long producedCSize
ZSTD_inBuffer expectedInBuffer
size_t outBuffFlushedSize
size_t outBuffContentSize
ZSTD_compressedBlockState_t cBlockState
ZSTD_dictContentType_e dictContentType
ZSTD_paramSwitch_e useRowMatchFinder
ZSTD_matchState_t matchState
seqStore_t secondHalfSeqStore
U32 partitions[ZSTD_MAX_NB_BLOCK_SPLITS]
seqStore_t firstHalfSeqStore
seqStore_t fullSeqStoreChunk
ZSTD_entropyCTablesMetadata_t entropyMetadata
ZSTD_matchState_t matchState
ZSTD_compressedBlockState_t * prevCBlock
ZSTD_compressedBlockState_t * nextCBlock
ZSTD_entropyCTables_t entropy
FSE_repeat matchlength_repeatMode
FSE_CTable offcodeCTable[FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)]
FSE_repeat offcode_repeatMode
FSE_CTable litlengthCTable[FSE_CTABLE_SIZE_U32(LLFSELog, MaxLL)]
FSE_repeat litlength_repeatMode
FSE_CTable matchlengthCTable[FSE_CTABLE_SIZE_U32(MLFSELog, MaxML)]
HUF_CElt CTable[HUF_CTABLE_SIZE_ST(255)]
ZSTD_dictContentType_e dictContentType
const rawSeqStore_t * ldmSeqStore
ZSTD_compressionParameters cParams
const ZSTD_matchState_t * dictMatchState
ZSTD_dictContentType_e dictContentType
ZSTD_paramSwitch_e enableLdm
ZSTD_match_t * matchTable
ZSTD_optimal_t * priceTable
unsigned * matchLengthFreq
ZSTD_paramSwitch_e literalCompressionMode
const ZSTD_entropyCTables_t * symbolCosts
ZSTD_longLengthType_e longLengthType
@ ZSTD_c_targetCBlockSize
@ ZSTD_c_enableLongDistanceMatching
@ ZSTD_c_compressionLevel
@ ZSTD_c_ldmBucketSizeLog
#define ZSTD_VERSION_NUMBER
#define ZSTD_CONTENTSIZE_UNKNOWN
#define ZSTD_MAGIC_DICTIONARY
#define ZSTD_CLEVEL_DEFAULT
#define ZSTD_COMPRESSBOUND(srcSize)
@ ZSTD_reset_session_only
@ ZSTD_reset_session_and_parameters
#define ZSTD_BLOCKSIZE_MAX
#define ZSTD_MAGIC_SKIPPABLE_START
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, int compressionLevel)
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx *cctx, ZSTD_cParameter param, int value)
size_t ZSTD_compress_advanced_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_CCtx_params *params)
size_t ZSTD_compressBound(size_t srcSize)
size_t ZSTD_compressStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
#define ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER
size_t ZSTD_compressStream2_simpleArgs(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos, ZSTD_EndDirective endOp)
size_t ZSTD_initCStream_usingCDict(ZSTD_CStream *zcs, const ZSTD_CDict *cdict)
size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx *cctx)
void ZSTD_CCtxParams_registerSequenceProducer(ZSTD_CCtx_params *params, void *extSeqProdState, ZSTD_sequenceProducer_F extSeqProdFunc)
size_t ZSTD_endStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output)
size_t ZSTD_getBlockSize(const ZSTD_CCtx *cctx)
size_t ZSTD_writeSkippableFrame(void *dst, size_t dstCapacity, const void *src, size_t srcSize, unsigned magicVariant)
size_t ZSTD_copySequencesToSeqStoreNoBlockDelim(ZSTD_CCtx *cctx, ZSTD_sequencePosition *seqPos, const ZSTD_Sequence *const inSeqs, size_t inSeqsSize, const void *src, size_t blockSize, ZSTD_paramSwitch_e externalRepSearch)
ZSTD_CDict * ZSTD_createCDict(const void *dict, size_t dictSize, int compressionLevel)
size_t ZSTD_compressCCtx(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize)
ZSTD_CCtx * ZSTD_createCCtx(void)
ZSTD_CCtx * ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams)
FORCE_INLINE_TEMPLATE void ZSTD_reduceTable_internal(U32 *const table, U32 const size, U32 const reducerValue, int const preserveMark)
MEM_STATIC size_t ZSTD_entropyCompressSeqStore_internal(const seqStore_t *seqStorePtr, const ZSTD_entropyCTables_t *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, const ZSTD_CCtx_params *cctxParams, void *dst, size_t dstCapacity, void *entropyWorkspace, size_t entropyWkspSize, const int bmi2)
size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params *params)
size_t ZSTD_compressBegin(ZSTD_CCtx *cctx, int compressionLevel)
size_t ZSTD_compressBlock(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
void ZSTD_CCtx_trace(ZSTD_CCtx *cctx, size_t extraCSize)
size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
#define SUSPECT_UNCOMPRESSIBLE_LITERAL_RATIO
size_t ZSTD_compressEnd_public(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_CCtx_setFParams(ZSTD_CCtx *cctx, ZSTD_frameParameters fparams)
ZSTD_CStream * ZSTD_initStaticCStream(void *workspace, size_t workspaceSize)
size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params *params)
size_t ZSTD_compress_usingCDict(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict)
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(const ZSTD_CCtx_params *CCtxParams, U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode)
int ZSTD_seqToCodes(const seqStore_t *seqStorePtr)
size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence *sequences, size_t seqsSize)
size_t ZSTD_compressSequences(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const ZSTD_Sequence *inSeqs, size_t inSeqsSize, const void *src, size_t srcSize)
#define CLAMP_TYPE(cParam, val, type)
size_t ZSTD_freeCCtx(ZSTD_CCtx *cctx)
size_t ZSTD_compressBlock_deprecated(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
ZSTD_CDict * ZSTD_createCDict_byReference(const void *dict, size_t dictSize, int compressionLevel)
size_t ZSTD_estimateCCtxSize(int compressionLevel)
size_t ZSTD_compress2(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_CCtxParams_getParameter(ZSTD_CCtx_params const *CCtxParams, ZSTD_cParameter param, int *value)
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
size_t ZSTD_flushStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output)
ZSTD_CCtx * ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize)
MEM_STATIC size_t ZSTD_entropyCompressSeqStore(const seqStore_t *seqStorePtr, const ZSTD_entropyCTables_t *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, const ZSTD_CCtx_params *cctxParams, void *dst, size_t dstCapacity, size_t srcSize, void *entropyWorkspace, size_t entropyWkspSize, int bmi2)
size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream *zcs, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize)
size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod)
int ZSTD_defaultCLevel(void)
size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params *cctxParams, int compressionLevel)
size_t ZSTD_compressStream2(ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
ZSTD_CCtx_params * ZSTD_createCCtxParams(void)
size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
void ZSTD_registerSequenceProducer(ZSTD_CCtx *zc, void *extSeqProdState, ZSTD_sequenceProducer_F extSeqProdFunc)
size_t ZSTD_CCtx_reset(ZSTD_CCtx *cctx, ZSTD_ResetDirective reset)
size_t ZSTD_sequenceBound(size_t srcSize)
size_t ZSTD_toFlushNow(ZSTD_CCtx *cctx)
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t *bs, void *workspace, const void *const dict, size_t dictSize)
size_t ZSTD_CCtx_refCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
size_t ZSTD_initCStream(ZSTD_CStream *zcs, int compressionLevel)
size_t ZSTD_CStreamInSize(void)
unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict *cdict)
size_t ZSTD_compress_usingDict(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
size_t ZSTD_freeCDict(ZSTD_CDict *cdict)
ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
size_t ZSTD_compressEnd(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize)
#define COMPRESS_LITERALS_SIZE_MIN
void ZSTD_resetSeqStore(seqStore_t *ssPtr)
size_t ZSTD_copySequencesToSeqStoreExplicitBlockDelim(ZSTD_CCtx *cctx, ZSTD_sequencePosition *seqPos, const ZSTD_Sequence *const inSeqs, size_t inSeqsSize, const void *src, size_t blockSize, ZSTD_paramSwitch_e externalRepSearch)
size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx *cctx, unsigned long long pledgedSrcSize)
ZSTD_CStream * ZSTD_createCStream_advanced(ZSTD_customMem customMem)
size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, const ZSTD_CDict *cdict, const ZSTD_CCtx_params *params, unsigned long long pledgedSrcSize)
size_t ZSTD_sizeof_CDict(const ZSTD_CDict *cdict)
size_t ZSTD_initCStream_internal(ZSTD_CStream *zcs, const void *dict, size_t dictSize, const ZSTD_CDict *cdict, const ZSTD_CCtx_params *params, unsigned long long pledgedSrcSize)
size_t ZSTD_initCStream_usingDict(ZSTD_CStream *zcs, const void *dict, size_t dictSize, int compressionLevel)
size_t ZSTD_compressBegin_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize)
size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
size_t ZSTD_CCtx_setParametersUsingCCtxParams(ZSTD_CCtx *cctx, const ZSTD_CCtx_params *params)
size_t ZSTD_compressContinue(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_initCStream_srcSize(ZSTD_CStream *zcs, int compressionLevel, unsigned long long pss)
size_t ZSTD_freeCStream(ZSTD_CStream *zcs)
size_t ZSTD_compressBegin_usingCDict_deprecated(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx *cctx)
size_t ZSTD_sizeof_CStream(const ZSTD_CStream *zcs)
size_t ZSTD_generateSequences(ZSTD_CCtx *zc, ZSTD_Sequence *outSeqs, size_t outSeqsSize, const void *src, size_t srcSize)
size_t ZSTD_CCtx_setParams(ZSTD_CCtx *cctx, ZSTD_parameters params)
void ZSTD_referenceExternalSequences(ZSTD_CCtx *cctx, rawSeq *seq, size_t nbSeq)
size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams)
#define ZSTD_USE_CDICT_PARAMS_SRCSIZE_CUTOFF
size_t ZSTD_buildBlockEntropyStats(const seqStore_t *seqStorePtr, const ZSTD_entropyCTables_t *prevEntropy, ZSTD_entropyCTables_t *nextEntropy, const ZSTD_CCtx_params *cctxParams, ZSTD_entropyCTablesMetadata_t *entropyMetadata, void *workspace, size_t wkspSize)
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode)
size_t ZSTD_CStreamOutSize(void)
U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat)
size_t ZSTD_compress_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params)
size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, int value)
size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx *cctx, ZSTD_threadPool *pool)
size_t ZSTD_compress(void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
size_t ZSTD_copyCCtx(ZSTD_CCtx *dstCCtx, const ZSTD_CCtx *srcCCtx, unsigned long long pledgedSrcSize)
#define ZSTD_HASHLOG3_MAX
size_t ZSTD_estimateCStreamSize(int compressionLevel)
size_t ZSTD_writeLastEmptyBlock(void *dst, size_t dstCapacity)
#define ZSTD_INDEXOVERFLOW_MARGIN
size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params *params)
void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t *bs)
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)
#define CLAMP(cParam, val)
void ZSTD_invalidateRepCodes(ZSTD_CCtx *cctx)
ZSTD_CDict * ZSTD_createCDict_advanced2(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, const ZSTD_CCtx_params *originalCctxParams, ZSTD_customMem customMem)
size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params *params)
const seqStore_t * ZSTD_getSeqStore(const ZSTD_CCtx *ctx)
#define BOUNDCHECK(cParam, val)
size_t ZSTD_resetCStream(ZSTD_CStream *zcs, unsigned long long pss)
size_t ZSTD_CCtx_getParameter(ZSTD_CCtx const *cctx, ZSTD_cParameter param, int *value)
size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_compressContinue_public(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t(* ZSTD_sequenceCopier)(ZSTD_CCtx *cctx, ZSTD_sequencePosition *seqPos, const ZSTD_Sequence *const inSeqs, size_t inSeqsSize, const void *src, size_t blockSize, ZSTD_paramSwitch_e externalRepSearch)
size_t ZSTD_CCtx_setCParams(ZSTD_CCtx *cctx, ZSTD_compressionParameters cparams)
size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx *const cctx, const ZSTD_CDict *const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize)
const ZSTD_CDict * ZSTD_initStaticCDict(void *workspace, size_t workspaceSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams)
size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams)
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict *cdict)
size_t ZSTD_initCStream_advanced(ZSTD_CStream *zcs, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pss)
size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params *cctxParams, ZSTD_parameters params)
ZSTD_CStream * ZSTD_createCStream(void)
MEM_STATIC size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
MEM_STATIC U32 ZSTD_MLcode(U32 mlBase)
MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window, U32 cycleLog, U32 maxDist, U32 loadedDictEnd, void const *src, void const *srcEnd)
#define REPCODE3_TO_OFFBASE
MEM_STATIC void ZSTD_window_clear(ZSTD_window_t *window)
#define ZSTD_SHORT_CACHE_TAG_BITS
#define OFFBASE_TO_OFFSET(o)
#define OFFBASE_IS_REPCODE(o)
MEM_STATIC int ZSTD_literalsCompressionIsDisabled(const ZSTD_CCtx_params *cctxParams)
MEM_STATIC size_t ZSTD_noCompressBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize, U32 lastBlock)
#define ZSTD_CHUNKSIZE_MAX
#define OFFSET_TO_OFFBASE(o)
MEM_STATIC U32 ZSTD_window_isEmpty(ZSTD_window_t const window)
MEM_STATIC void ZSTD_updateRep(U32 rep[ZSTD_REP_NUM], U32 const offBase, U32 const ll0)
MEM_STATIC U32 ZSTD_window_hasExtDict(ZSTD_window_t const window)
MEM_STATIC U32 ZSTD_LLcode(U32 litLength)
#define ZSTD_MAX_NB_BLOCK_SPLITS
#define ZSTD_WINDOW_START_INDEX
#define ENTROPY_WORKSPACE_SIZE
MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR U32 ZSTD_window_update(ZSTD_window_t *window, void const *src, size_t srcSize, int forceNonContiguous)
MEM_STATIC void ZSTD_window_init(ZSTD_window_t *window)
MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR U32 ZSTD_window_correctOverflow(ZSTD_window_t *window, U32 cycleLog, U32 maxDist, void const *src)
MEM_STATIC size_t ZSTD_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *const pInLimit)
size_t(* ZSTD_blockCompressor)(ZSTD_matchState_t *bs, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
HINT_INLINE UNUSED_ATTR void ZSTD_storeSeq(seqStore_t *seqStorePtr, size_t litLength, const BYTE *literals, const BYTE *litLimit, U32 offBase, size_t matchLength)
MEM_STATIC size_t ZSTD_rleCompressBlock(void *dst, size_t dstCapacity, BYTE src, size_t srcSize, U32 lastBlock)
#define REPCODE1_TO_OFFBASE
MEM_STATIC int ZSTD_cParam_withinBounds(ZSTD_cParameter cParam, int value)
MEM_STATIC void ZSTD_checkDictValidity(const ZSTD_window_t *window, const void *blockEnd, U32 maxDist, U32 *loadedDictEndPtr, const ZSTD_matchState_t **dictMatchStatePtr)
MEM_STATIC void ZSTD_window_enforceMaxDist(ZSTD_window_t *window, const void *blockEnd, U32 maxDist, U32 *loadedDictEndPtr, const ZSTD_matchState_t **dictMatchStatePtr)
#define REPCODE_TO_OFFBASE(r)
ZSTD_dictTableLoadMethod_e
#define OFFBASE_TO_REPCODE(o)
#define ZSTD_DUBT_UNSORTED_MARK
MEM_STATIC int ZSTD_hasExtSeqProd(const ZSTD_CCtx_params *params)
size_t ZSTD_compressLiterals(void *dst, size_t dstCapacity, const void *src, size_t srcSize, void *entropyWorkspace, size_t entropyWorkspaceSize, const ZSTD_hufCTables_t *prevHuf, ZSTD_hufCTables_t *nextHuf, ZSTD_strategy strategy, int disableLiteralCompression, int suspectUncompressible, int bmi2)
size_t ZSTD_crossEntropyCost(short const *norm, unsigned accuracyLog, unsigned const *count, unsigned const max)
size_t ZSTD_fseBitCost(FSE_CTable const *ctable, unsigned const *count, unsigned const max)
size_t ZSTD_buildCTable(void *dst, size_t dstCapacity, FSE_CTable *nextCTable, U32 FSELog, symbolEncodingType_e type, unsigned *count, U32 max, const BYTE *codeTable, size_t nbSeq, const S16 *defaultNorm, U32 defaultNormLog, U32 defaultMax, const FSE_CTable *prevCTable, size_t prevCTableSize, void *entropyWorkspace, size_t entropyWorkspaceSize)
symbolEncodingType_e ZSTD_selectEncodingType(FSE_repeat *repeatMode, unsigned const *count, unsigned const max, size_t const mostFrequent, size_t nbSeq, unsigned const FSELog, FSE_CTable const *prevCTable, short const *defaultNorm, U32 defaultNormLog, ZSTD_defaultPolicy_e const isDefaultAllowed, ZSTD_strategy const strategy)
size_t ZSTD_encodeSequences(void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets, int bmi2)
size_t ZSTD_compressSuperBlock(ZSTD_CCtx *zc, void *dst, size_t dstCapacity, const void *src, size_t srcSize, unsigned lastBlock)
MEM_STATIC size_t ZSTD_cwksp_create(ZSTD_cwksp *ws, size_t size, ZSTD_customMem customMem)
MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t const align)
MEM_STATIC void ZSTD_cwksp_mark_tables_clean(ZSTD_cwksp *ws)
MEM_STATIC int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp *ws)
@ ZSTD_cwksp_dynamic_alloc
@ ZSTD_cwksp_static_alloc
MEM_STATIC void ZSTD_cwksp_move(ZSTD_cwksp *dst, ZSTD_cwksp *src)
MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_clear_tables(ZSTD_cwksp *ws)
MEM_STATIC int ZSTD_cwksp_owns_buffer(const ZSTD_cwksp *ws, const void *ptr)
MEM_STATIC int ZSTD_cwksp_check_wasteful(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC void * ZSTD_cwksp_reserve_aligned_init_once(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC size_t ZSTD_cwksp_slack_space_required(void)
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_free(ZSTD_cwksp *ws, ZSTD_customMem customMem)
MEM_STATIC BYTE * ZSTD_cwksp_reserve_buffer(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC int ZSTD_cwksp_estimated_space_within_bounds(const ZSTD_cwksp *const ws, size_t const estimatedSpace)
MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp *ws)
MEM_STATIC void * ZSTD_cwksp_reserve_object(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp *ws, void *start, size_t size, ZSTD_cwksp_static_alloc_e isStatic)
MEM_STATIC size_t ZSTD_cwksp_aligned_alloc_size(size_t size)
MEM_STATIC size_t ZSTD_cwksp_alloc_size(size_t size)
MEM_STATIC int ZSTD_cwksp_check_available(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC void * ZSTD_cwksp_reserve_table(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC void * ZSTD_cwksp_reserve_aligned(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp *ws)
#define ZSTD_memcpy(d, s, l)
#define ZSTD_memset(p, v, l)
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t *ms, const void *const end, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_tableFillPurpose_e tfp)
#define ZSTD_COMPRESSBLOCK_DOUBLEFAST_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_DOUBLEFAST_EXTDICT
#define ZSTD_COMPRESSBLOCK_DOUBLEFAST
size_t ZSTD_compressBlock_fast_dictMatchState(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
size_t ZSTD_compressBlock_fast(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
void ZSTD_fillHashTable(ZSTD_matchState_t *ms, const void *const end, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_tableFillPurpose_e tfp)
size_t ZSTD_compressBlock_fast_extDict(ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], void const *src, size_t srcSize)
#define ZSTD_BLOCKHEADERSIZE
#define WILDCOPY_OVERLENGTH
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define BOUNDED(min, val, max)
#define ZSTD_STATIC_ASSERT(c)
void ZSTD_row_update(ZSTD_matchState_t *const ms, const BYTE *ip)
void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t *ms, const BYTE *const ip)
U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t *ms, const BYTE *ip)
#define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH_ROW
#define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE_ROW
#define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT_ROW
#define ZSTD_COMPRESSBLOCK_LAZY_ROW
#define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH
#define ZSTD_COMPRESSBLOCK_BTLAZY2
#define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH
#define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT
#define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT_ROW
#define ZSTD_ROW_HASH_TAG_BITS
#define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH_ROW
#define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE_ROW
#define ZSTD_COMPRESSBLOCK_LAZY2_ROW
#define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_LAZY2
#define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT
#define ZSTD_COMPRESSBLOCK_LAZY
#define ZSTD_COMPRESSBLOCK_BTLAZY2_EXTDICT
#define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT_ROW
#define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_GREEDY_ROW
#define ZSTD_LAZY_DDSS_BUCKET_LOG
#define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH_ROW
#define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT
#define ZSTD_COMPRESSBLOCK_GREEDY
#define ZSTD_COMPRESSBLOCK_BTLAZY2_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE_ROW
#define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH
size_t ZSTD_ldm_generateSequences(ldmState_t *ldmState, rawSeqStore_t *sequences, ldmParams_t const *params, void const *src, size_t srcSize)
void ZSTD_ldm_skipSequences(rawSeqStore_t *rawSeqStore, size_t srcSize, U32 const minMatch)
void ZSTD_ldm_adjustParameters(ldmParams_t *params, ZSTD_compressionParameters const *cParams)
size_t ZSTD_ldm_blockCompress(rawSeqStore_t *rawSeqStore, ZSTD_matchState_t *ms, seqStore_t *seqStore, U32 rep[ZSTD_REP_NUM], ZSTD_paramSwitch_e useRowMatchFinder, void const *src, size_t srcSize)
void ZSTD_ldm_fillHashTable(ldmState_t *ldmState, const BYTE *ip, const BYTE *iend, ldmParams_t const *params)
size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize)
void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t *rawSeqStore, size_t nbBytes)
size_t ZSTD_ldm_getTableSize(ldmParams_t params)
#define ZSTD_LDM_DEFAULT_WINDOW_LOG
void ZSTD_updateTree(ZSTD_matchState_t *ms, const BYTE *ip, const BYTE *iend)
#define ZSTD_COMPRESSBLOCK_BTULTRA
#define ZSTD_COMPRESSBLOCK_BTULTRA_EXTDICT
#define ZSTD_COMPRESSBLOCK_BTOPT_EXTDICT
#define ZSTD_COMPRESSBLOCK_BTOPT_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_BTULTRA2
#define ZSTD_COMPRESSBLOCK_BTULTRA_DICTMATCHSTATE
#define ZSTD_COMPRESSBLOCK_BTOPT
size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx *mtctx)
size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx *mtctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx *mtctx)
void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx *mtctx, const ZSTD_CCtx_params *cctxParams)
size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx *mtctx)
size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx *mtctx)
size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx *mtctx)
size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx *mtctx, const void *dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, const ZSTD_CDict *cdict, ZSTD_CCtx_params params, unsigned long long pledgedSrcSize)
ZSTDMT_CCtx * ZSTDMT_createCCtx_advanced(unsigned nbWorkers, ZSTD_customMem cMem, ZSTD_threadPool *pool)
#define ZSTDMT_JOBSIZE_MAX
#define ZSTDMT_JOBSIZE_MIN
#define ZSTDMT_NBWORKERS_MAX