Lines Matching refs:cctx

79 static void ZSTD_initCCtx(ZSTD_CCtx* cctx, ZSTD_customMem memManager)  in ZSTD_initCCtx()  argument
81 assert(cctx != NULL); in ZSTD_initCCtx()
82 ZSTD_memset(cctx, 0, sizeof(*cctx)); in ZSTD_initCCtx()
83 cctx->customMem = memManager; in ZSTD_initCCtx()
84 cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); in ZSTD_initCCtx()
85 { size_t const err = ZSTD_CCtx_reset(cctx, ZSTD_reset_parameters); in ZSTD_initCCtx()
96 { ZSTD_CCtx* const cctx = (ZSTD_CCtx*)ZSTD_customMalloc(sizeof(ZSTD_CCtx), customMem); in ZSTD_createCCtx_advanced() local
97 if (!cctx) return NULL; in ZSTD_createCCtx_advanced()
98 ZSTD_initCCtx(cctx, customMem); in ZSTD_createCCtx_advanced()
99 return cctx; in ZSTD_createCCtx_advanced()
106 ZSTD_CCtx* cctx; in ZSTD_initStaticCCtx() local
111 cctx = (ZSTD_CCtx*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CCtx)); in ZSTD_initStaticCCtx()
112 if (cctx == NULL) return NULL; in ZSTD_initStaticCCtx()
114 ZSTD_memset(cctx, 0, sizeof(ZSTD_CCtx)); in ZSTD_initStaticCCtx()
115 ZSTD_cwksp_move(&cctx->workspace, &ws); in ZSTD_initStaticCCtx()
116 cctx->staticSize = workspaceSize; in ZSTD_initStaticCCtx()
119 …if (!ZSTD_cwksp_check_available(&cctx->workspace, ENTROPY_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compres… in ZSTD_initStaticCCtx()
120cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
121cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->works… in ZSTD_initStaticCCtx()
122cctx->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cctx->workspace, ENTROPY_WORKSPACE_SIZE); in ZSTD_initStaticCCtx()
123 cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); in ZSTD_initStaticCCtx()
124 return cctx; in ZSTD_initStaticCCtx()
130 static void ZSTD_clearAllDicts(ZSTD_CCtx* cctx) in ZSTD_clearAllDicts() argument
132 ZSTD_customFree(cctx->localDict.dictBuffer, cctx->customMem); in ZSTD_clearAllDicts()
133 ZSTD_freeCDict(cctx->localDict.cdict); in ZSTD_clearAllDicts()
134 ZSTD_memset(&cctx->localDict, 0, sizeof(cctx->localDict)); in ZSTD_clearAllDicts()
135 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); in ZSTD_clearAllDicts()
136 cctx->cdict = NULL; in ZSTD_clearAllDicts()
146 static void ZSTD_freeCCtxContent(ZSTD_CCtx* cctx) in ZSTD_freeCCtxContent() argument
148 assert(cctx != NULL); in ZSTD_freeCCtxContent()
149 assert(cctx->staticSize == 0); in ZSTD_freeCCtxContent()
150 ZSTD_clearAllDicts(cctx); in ZSTD_freeCCtxContent()
151 ZSTD_cwksp_free(&cctx->workspace, cctx->customMem); in ZSTD_freeCCtxContent()
154 size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx) in ZSTD_freeCCtx() argument
156 if (cctx==NULL) return 0; /* support free on NULL */ in ZSTD_freeCCtx()
157 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_freeCCtx()
160 int cctxInWorkspace = ZSTD_cwksp_owns_buffer(&cctx->workspace, cctx); in ZSTD_freeCCtx()
161 ZSTD_freeCCtxContent(cctx); in ZSTD_freeCCtx()
163 ZSTD_customFree(cctx, cctx->customMem); in ZSTD_freeCCtx()
170 static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx) in ZSTD_sizeof_mtctx() argument
172 (void)cctx; in ZSTD_sizeof_mtctx()
177 size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) in ZSTD_sizeof_CCtx() argument
179 if (cctx==NULL) return 0; /* support sizeof on NULL */ in ZSTD_sizeof_CCtx()
181 return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx)) in ZSTD_sizeof_CCtx()
182 + ZSTD_cwksp_sizeof(&cctx->workspace) in ZSTD_sizeof_CCtx()
183 + ZSTD_sizeof_localDict(cctx->localDict) in ZSTD_sizeof_CCtx()
184 + ZSTD_sizeof_mtctx(cctx); in ZSTD_sizeof_CCtx()
531 size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value) in ZSTD_CCtx_setParameter() argument
534 if (cctx->streamStage != zcss_init) { in ZSTD_CCtx_setParameter()
536 cctx->cParamsChanged = 1; in ZSTD_CCtx_setParameter()
544 RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported, in ZSTD_CCtx_setParameter()
582 return ZSTD_CCtxParams_setParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_setParameter()
765 size_t ZSTD_CCtx_getParameter(ZSTD_CCtx const* cctx, ZSTD_cParameter param, int* value) in ZSTD_CCtx_getParameter() argument
767 return ZSTD_CCtxParams_getParameter(&cctx->requestedParams, param, value); in ZSTD_CCtx_getParameter()
879 ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params) in ZSTD_CCtx_setParametersUsingCCtxParams() argument
882 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
884 RETURN_ERROR_IF(cctx->cdict, stage_wrong, in ZSTD_CCtx_setParametersUsingCCtxParams()
888 cctx->requestedParams = *params; in ZSTD_CCtx_setParametersUsingCCtxParams()
892 ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize) in ZSTD_CCtx_setPledgedSrcSize() argument
895 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_setPledgedSrcSize()
897 cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1; in ZSTD_CCtx_setPledgedSrcSize()
914 static size_t ZSTD_initLocalDict(ZSTD_CCtx* cctx) in ZSTD_initLocalDict() argument
916 ZSTD_localDict* const dl = &cctx->localDict; in ZSTD_initLocalDict()
925 assert(cctx->cdict == dl->cdict); in ZSTD_initLocalDict()
930 assert(cctx->cdict == NULL); in ZSTD_initLocalDict()
931 assert(cctx->prefixDict.dict == NULL); in ZSTD_initLocalDict()
938 &cctx->requestedParams, in ZSTD_initLocalDict()
939 cctx->customMem); in ZSTD_initLocalDict()
941 cctx->cdict = dl->cdict; in ZSTD_initLocalDict()
946 ZSTD_CCtx* cctx, const void* dict, size_t dictSize, in ZSTD_CCtx_loadDictionary_advanced() argument
949 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_loadDictionary_advanced()
952 ZSTD_clearAllDicts(cctx); /* in case one already exists */ in ZSTD_CCtx_loadDictionary_advanced()
956 cctx->localDict.dict = dict; in ZSTD_CCtx_loadDictionary_advanced()
959 RETURN_ERROR_IF(cctx->staticSize, memory_allocation, in ZSTD_CCtx_loadDictionary_advanced()
961 dictBuffer = ZSTD_customMalloc(dictSize, cctx->customMem); in ZSTD_CCtx_loadDictionary_advanced()
964 cctx->localDict.dictBuffer = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
965 cctx->localDict.dict = dictBuffer; in ZSTD_CCtx_loadDictionary_advanced()
967 cctx->localDict.dictSize = dictSize; in ZSTD_CCtx_loadDictionary_advanced()
968 cctx->localDict.dictContentType = dictContentType; in ZSTD_CCtx_loadDictionary_advanced()
973 ZSTD_CCtx* cctx, const void* dict, size_t dictSize) in ZSTD_CCtx_loadDictionary_byReference() argument
976 cctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto); in ZSTD_CCtx_loadDictionary_byReference()
979 ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) in ZSTD_CCtx_loadDictionary() argument
982 cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto); in ZSTD_CCtx_loadDictionary()
986 size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) in ZSTD_CCtx_refCDict() argument
988 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refCDict()
991 ZSTD_clearAllDicts(cctx); in ZSTD_CCtx_refCDict()
992 cctx->cdict = cdict; in ZSTD_CCtx_refCDict()
996 size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool) in ZSTD_CCtx_refThreadPool() argument
998 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refThreadPool()
1000 cctx->pool = pool; in ZSTD_CCtx_refThreadPool()
1004 size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize) in ZSTD_CCtx_refPrefix() argument
1006 return ZSTD_CCtx_refPrefix_advanced(cctx, prefix, prefixSize, ZSTD_dct_rawContent); in ZSTD_CCtx_refPrefix()
1010 … ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType) in ZSTD_CCtx_refPrefix_advanced() argument
1012 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_refPrefix_advanced()
1014 ZSTD_clearAllDicts(cctx); in ZSTD_CCtx_refPrefix_advanced()
1016 cctx->prefixDict.dict = prefix; in ZSTD_CCtx_refPrefix_advanced()
1017 cctx->prefixDict.dictSize = prefixSize; in ZSTD_CCtx_refPrefix_advanced()
1018 cctx->prefixDict.dictContentType = dictContentType; in ZSTD_CCtx_refPrefix_advanced()
1025 size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset) in ZSTD_CCtx_reset() argument
1029 cctx->streamStage = zcss_init; in ZSTD_CCtx_reset()
1030 cctx->pledgedSrcSizePlusOne = 0; in ZSTD_CCtx_reset()
1034 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong, in ZSTD_CCtx_reset()
1036 ZSTD_clearAllDicts(cctx); in ZSTD_CCtx_reset()
1037 return ZSTD_CCtxParams_reset(&cctx->requestedParams); in ZSTD_CCtx_reset()
1392 ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx) in ZSTD_getFrameProgression() argument
1395 size_t const buffered = (cctx->inBuff == NULL) ? 0 : in ZSTD_getFrameProgression()
1396 cctx->inBuffPos - cctx->inToCompress; in ZSTD_getFrameProgression()
1397 if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress); in ZSTD_getFrameProgression()
1399 fp.ingested = cctx->consumedSrcSize + buffered; in ZSTD_getFrameProgression()
1400 fp.consumed = cctx->consumedSrcSize; in ZSTD_getFrameProgression()
1401 fp.produced = cctx->producedCSize; in ZSTD_getFrameProgression()
1402 …fp.flushed = cctx->producedCSize; /* simplified; some data might still be left within streaming… in ZSTD_getFrameProgression()
1411 size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx) in ZSTD_toFlushNow() argument
1413 (void)cctx; in ZSTD_toFlushNow()
1726 void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) { in ZSTD_invalidateRepCodes() argument
1728 for (i=0; i<ZSTD_REP_NUM; i++) cctx->blockState.prevCBlock->rep[i] = 0; in ZSTD_invalidateRepCodes()
1729 assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window)); in ZSTD_invalidateRepCodes()
1765 ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx, in ZSTD_resetCCtx_byAttachingCDict() argument
1786 FORWARD_IF_ERROR(ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize, in ZSTD_resetCCtx_byAttachingCDict()
1788 assert(cctx->appliedParams.cParams.strategy == adjusted_cdict_cParams.strategy); in ZSTD_resetCCtx_byAttachingCDict()
1799 cctx->blockState.matchState.dictMatchState = &cdict->matchState; in ZSTD_resetCCtx_byAttachingCDict()
1803 if (cctx->blockState.matchState.window.dictLimit < cdictEnd) { in ZSTD_resetCCtx_byAttachingCDict()
1804 cctx->blockState.matchState.window.nextSrc = in ZSTD_resetCCtx_byAttachingCDict()
1805 cctx->blockState.matchState.window.base + cdictEnd; in ZSTD_resetCCtx_byAttachingCDict()
1806 ZSTD_window_clear(&cctx->blockState.matchState.window); in ZSTD_resetCCtx_byAttachingCDict()
1809cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit; in ZSTD_resetCCtx_byAttachingCDict()
1812 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byAttachingCDict()
1813 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byAttachingCDict()
1816 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byAttachingCDict()
1821 static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx, in ZSTD_resetCCtx_byCopyingCDict() argument
1838 FORWARD_IF_ERROR(ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize, in ZSTD_resetCCtx_byCopyingCDict()
1840 assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy); in ZSTD_resetCCtx_byCopyingCDict()
1841 assert(cctx->appliedParams.cParams.hashLog == cdict_cParams->hashLog); in ZSTD_resetCCtx_byCopyingCDict()
1842 assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog); in ZSTD_resetCCtx_byCopyingCDict()
1845 ZSTD_cwksp_mark_tables_dirty(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
1851 ZSTD_memcpy(cctx->blockState.matchState.hashTable, in ZSTD_resetCCtx_byCopyingCDict()
1854 ZSTD_memcpy(cctx->blockState.matchState.chainTable, in ZSTD_resetCCtx_byCopyingCDict()
1860 { int const h3log = cctx->blockState.matchState.hashLog3; in ZSTD_resetCCtx_byCopyingCDict()
1863 ZSTD_memset(cctx->blockState.matchState.hashTable3, 0, h3Size * sizeof(U32)); in ZSTD_resetCCtx_byCopyingCDict()
1866 ZSTD_cwksp_mark_tables_clean(&cctx->workspace); in ZSTD_resetCCtx_byCopyingCDict()
1870 ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState; in ZSTD_resetCCtx_byCopyingCDict()
1876 cctx->dictID = cdict->dictID; in ZSTD_resetCCtx_byCopyingCDict()
1877 cctx->dictContentSize = cdict->dictContentSize; in ZSTD_resetCCtx_byCopyingCDict()
1880 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState)); in ZSTD_resetCCtx_byCopyingCDict()
1888 static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx, in ZSTD_resetCCtx_usingCDict() argument
1900 cctx, cdict, *params, pledgedSrcSize, zbuff); in ZSTD_resetCCtx_usingCDict()
1903 cctx, cdict, *params, pledgedSrcSize, zbuff); in ZSTD_resetCCtx_usingCDict()
2787 static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, in ZSTD_compress_frameChunk() argument
2792 size_t blockSize = cctx->blockSize; in ZSTD_compress_frameChunk()
2797 U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog; in ZSTD_compress_frameChunk()
2799 assert(cctx->appliedParams.cParams.windowLog <= ZSTD_WINDOWLOG_MAX); in ZSTD_compress_frameChunk()
2802 if (cctx->appliedParams.fParams.checksumFlag && srcSize) in ZSTD_compress_frameChunk()
2803 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compress_frameChunk()
2806 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compress_frameChunk()
2815 ms, &cctx->workspace, &cctx->appliedParams, ip, ip + blockSize); in ZSTD_compress_frameChunk()
2822 if (ZSTD_useTargetCBlockSize(&cctx->appliedParams)) { in ZSTD_compress_frameChunk()
2823 … cSize = ZSTD_compressBlock_targetCBlockSize(cctx, op, dstCapacity, ip, blockSize, lastBlock); in ZSTD_compress_frameChunk()
2828 cSize = ZSTD_compressBlock_internal(cctx, in ZSTD_compress_frameChunk()
2852 cctx->isFirstBlock = 0; in ZSTD_compress_frameChunk()
2857 if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending; in ZSTD_compress_frameChunk()
2945 size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSeq) in ZSTD_referenceExternalSequences() argument
2947 RETURN_ERROR_IF(cctx->stage != ZSTDcs_init, stage_wrong, in ZSTD_referenceExternalSequences()
2949 RETURN_ERROR_IF(cctx->appliedParams.ldmParams.enableLdm, in ZSTD_referenceExternalSequences()
2952 cctx->externSeqStore.seq = seq; in ZSTD_referenceExternalSequences()
2953 cctx->externSeqStore.size = nbSeq; in ZSTD_referenceExternalSequences()
2954 cctx->externSeqStore.capacity = nbSeq; in ZSTD_referenceExternalSequences()
2955 cctx->externSeqStore.pos = 0; in ZSTD_referenceExternalSequences()
2956 cctx->externSeqStore.posInSequence = 0; in ZSTD_referenceExternalSequences()
2961 static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, in ZSTD_compressContinue_internal() argument
2966 ZSTD_matchState_t* const ms = &cctx->blockState.matchState; in ZSTD_compressContinue_internal()
2970 cctx->stage, (unsigned)srcSize); in ZSTD_compressContinue_internal()
2971 RETURN_ERROR_IF(cctx->stage==ZSTDcs_created, stage_wrong, in ZSTD_compressContinue_internal()
2974 if (frame && (cctx->stage==ZSTDcs_init)) { in ZSTD_compressContinue_internal()
2975 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, in ZSTD_compressContinue_internal()
2976 cctx->pledgedSrcSizePlusOne-1, cctx->dictID); in ZSTD_compressContinue_internal()
2981 cctx->stage = ZSTDcs_ongoing; in ZSTD_compressContinue_internal()
2989 if (cctx->appliedParams.ldmParams.enableLdm) { in ZSTD_compressContinue_internal()
2990 ZSTD_window_update(&cctx->ldmState.window, src, srcSize); in ZSTD_compressContinue_internal()
2996 ms, &cctx->workspace, &cctx->appliedParams, in ZSTD_compressContinue_internal()
3000 DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (unsigned)cctx->blockSize); in ZSTD_compressContinue_internal()
3002 … ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : in ZSTD_compressContinue_internal()
3003 … ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize, 0 /* frame */); in ZSTD_compressContinue_internal()
3005 cctx->consumedSrcSize += srcSize; in ZSTD_compressContinue_internal()
3006 cctx->producedCSize += (cSize + fhSize); in ZSTD_compressContinue_internal()
3007 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressContinue_internal()
3008 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressContinue_internal()
3011 cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne, in ZSTD_compressContinue_internal()
3014 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressContinue_internal()
3015 (unsigned)cctx->consumedSrcSize); in ZSTD_compressContinue_internal()
3021 size_t ZSTD_compressContinue (ZSTD_CCtx* cctx, in ZSTD_compressContinue() argument
3026 …return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1 /* frame mode */, 0 … in ZSTD_compressContinue()
3030 size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx) in ZSTD_getBlockSize() argument
3032 ZSTD_compressionParameters const cParams = cctx->appliedParams.cParams; in ZSTD_getBlockSize()
3037 size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t s… in ZSTD_compressBlock() argument
3040 { size_t const blockSizeMax = ZSTD_getBlockSize(cctx); in ZSTD_compressBlock()
3043 …return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 … in ZSTD_compressBlock()
3316 static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, in ZSTD_compressBegin_internal() argument
3335 return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff); in ZSTD_compressBegin_internal()
3338 FORWARD_IF_ERROR( ZSTD_resetCCtx_internal(cctx, *params, pledgedSrcSize, in ZSTD_compressBegin_internal()
3342 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
3343 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent, in ZSTD_compressBegin_internal()
3345 cctx->entropyWorkspace) in ZSTD_compressBegin_internal()
3347 cctx->blockState.prevCBlock, &cctx->blockState.matchState, in ZSTD_compressBegin_internal()
3348 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, dict, dictSize, in ZSTD_compressBegin_internal()
3349 dictContentType, dtlm, cctx->entropyWorkspace); in ZSTD_compressBegin_internal()
3352 cctx->dictID = (U32)dictID; in ZSTD_compressBegin_internal()
3353 cctx->dictContentSize = cdict ? cdict->dictContentSize : dictSize; in ZSTD_compressBegin_internal()
3358 size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx* cctx, in ZSTD_compressBegin_advanced_internal() argument
3369 return ZSTD_compressBegin_internal(cctx, in ZSTD_compressBegin_advanced_internal()
3378 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, in ZSTD_compressBegin_advanced() argument
3384 return ZSTD_compressBegin_advanced_internal(cctx, in ZSTD_compressBegin_advanced()
3390 size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compres… in ZSTD_compressBegin_usingDict() argument
3398 return ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL, in ZSTD_compressBegin_usingDict()
3402 size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel) in ZSTD_compressBegin() argument
3404 return ZSTD_compressBegin_usingDict(cctx, NULL, 0, compressionLevel); in ZSTD_compressBegin()
3411 static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity) in ZSTD_writeEpilogue() argument
3418 RETURN_ERROR_IF(cctx->stage == ZSTDcs_created, stage_wrong, "init missing"); in ZSTD_writeEpilogue()
3421 if (cctx->stage == ZSTDcs_init) { in ZSTD_writeEpilogue()
3422 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, &cctx->appliedParams, 0, 0); in ZSTD_writeEpilogue()
3426 cctx->stage = ZSTDcs_ongoing; in ZSTD_writeEpilogue()
3429 if (cctx->stage != ZSTDcs_ending) { in ZSTD_writeEpilogue()
3438 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_writeEpilogue()
3439 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_writeEpilogue()
3446 cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ in ZSTD_writeEpilogue()
3450 void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize) in ZSTD_CCtx_trace() argument
3452 (void)cctx; in ZSTD_CCtx_trace()
3456 size_t ZSTD_compressEnd (ZSTD_CCtx* cctx, in ZSTD_compressEnd() argument
3461 size_t const cSize = ZSTD_compressContinue_internal(cctx, in ZSTD_compressEnd()
3465 endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize); in ZSTD_compressEnd()
3467 assert(!(cctx->appliedParams.fParams.contentSizeFlag && cctx->pledgedSrcSizePlusOne == 0)); in ZSTD_compressEnd()
3468 if (cctx->pledgedSrcSizePlusOne != 0) { /* control src size */ in ZSTD_compressEnd()
3472 cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1, in ZSTD_compressEnd()
3475 (unsigned)cctx->pledgedSrcSizePlusOne-1, in ZSTD_compressEnd()
3476 (unsigned)cctx->consumedSrcSize); in ZSTD_compressEnd()
3478 ZSTD_CCtx_trace(cctx, endResult); in ZSTD_compressEnd()
3482 size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, in ZSTD_compress_advanced() argument
3492 return ZSTD_compress_advanced_internal(cctx, in ZSTD_compress_advanced()
3501 ZSTD_CCtx* cctx, in ZSTD_compress_advanced_internal() argument
3508 FORWARD_IF_ERROR( ZSTD_compressBegin_internal(cctx, in ZSTD_compress_advanced_internal()
3511 return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); in ZSTD_compress_advanced_internal()
3514 size_t ZSTD_compress_usingDict(ZSTD_CCtx* cctx, in ZSTD_compress_usingDict() argument
3527 …return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, &cctx… in ZSTD_compress_usingDict()
3530 size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx, in ZSTD_compressCCtx() argument
3536 assert(cctx != NULL); in ZSTD_compressCCtx()
3537 return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel); in ZSTD_compressCCtx()
3545 ZSTD_CCtx* cctx = ZSTD_createCCtx(); in ZSTD_compress() local
3546 RETURN_ERROR_IF(!cctx, memory_allocation, "ZSTD_createCCtx failed"); in ZSTD_compress()
3547 result = ZSTD_compressCCtx(cctx, dst, dstCapacity, src, srcSize, compressionLevel); in ZSTD_compress()
3548 ZSTD_freeCCtx(cctx); in ZSTD_compress()
3846 ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, in ZSTD_compressBegin_usingCDict_advanced() argument
3875 return ZSTD_compressBegin_internal(cctx, in ZSTD_compressBegin_usingCDict_advanced()
3885 size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) in ZSTD_compressBegin_usingCDict() argument
3889 return ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, ZSTD_CONTENTSIZE_UNKNOWN); in ZSTD_compressBegin_usingCDict()
3892 size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, in ZSTD_compress_usingCDict_advanced() argument
3897 …FORWARD_IF_ERROR(ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, srcSize), ""); /* … in ZSTD_compress_usingCDict_advanced()
3898 return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); in ZSTD_compress_usingCDict_advanced()
3906 size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, in ZSTD_compress_usingCDict() argument
3912 return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, fParams); in ZSTD_compress_usingCDict()
4082 static size_t ZSTD_nextInputSizeHint(const ZSTD_CCtx* cctx) in ZSTD_nextInputSizeHint() argument
4084 size_t hintInSize = cctx->inBuffTarget - cctx->inBuffPos; in ZSTD_nextInputSizeHint()
4085 if (hintInSize==0) hintInSize = cctx->blockSize; in ZSTD_nextInputSizeHint()
4260 static size_t ZSTD_nextInputSizeHint_MTorST(const ZSTD_CCtx* cctx) in ZSTD_nextInputSizeHint_MTorST() argument
4262 return ZSTD_nextInputSizeHint(cctx); in ZSTD_nextInputSizeHint_MTorST()
4275 static void ZSTD_setBufferExpectations(ZSTD_CCtx* cctx, ZSTD_outBuffer const* output, ZSTD_inBuffer… in ZSTD_setBufferExpectations() argument
4277 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
4278 cctx->expectedInBuffer = *input; in ZSTD_setBufferExpectations()
4280 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_setBufferExpectations()
4281 cctx->expectedOutBufferSize = output->size - output->pos; in ZSTD_setBufferExpectations()
4288 static size_t ZSTD_checkBufferStability(ZSTD_CCtx const* cctx, in ZSTD_checkBufferStability() argument
4293 if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
4294 ZSTD_inBuffer const expect = cctx->expectedInBuffer; in ZSTD_checkBufferStability()
4300 if (cctx->appliedParams.outBufferMode == ZSTD_bm_stable) { in ZSTD_checkBufferStability()
4302 if (cctx->expectedOutBufferSize != outBufferSize) in ZSTD_checkBufferStability()
4308 static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx, in ZSTD_CCtx_init_compressStream2() argument
4311 ZSTD_CCtx_params params = cctx->requestedParams; in ZSTD_CCtx_init_compressStream2()
4312 ZSTD_prefixDict const prefixDict = cctx->prefixDict; in ZSTD_CCtx_init_compressStream2()
4313 FORWARD_IF_ERROR( ZSTD_initLocalDict(cctx) , ""); /* Init the local dict if present. */ in ZSTD_CCtx_init_compressStream2()
4314 ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */ in ZSTD_CCtx_init_compressStream2()
4315 assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */ in ZSTD_CCtx_init_compressStream2()
4316 if (cctx->cdict) in ZSTD_CCtx_init_compressStream2()
4317 …params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of co… in ZSTD_CCtx_init_compressStream2()
4319 … if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = inSize + 1; /* auto-fix pledgedSrcSize */ in ZSTD_CCtx_init_compressStream2()
4323 : (cctx->cdict ? cctx->cdict->dictContentSize : 0); in ZSTD_CCtx_init_compressStream2()
4324 …ZSTD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, &params, cctx->pledgedSrcSizePlusOn… in ZSTD_CCtx_init_compressStream2()
4326 &params, cctx->pledgedSrcSizePlusOne-1, in ZSTD_CCtx_init_compressStream2()
4336 { U64 const pledgedSrcSize = cctx->pledgedSrcSizePlusOne - 1; in ZSTD_CCtx_init_compressStream2()
4338 FORWARD_IF_ERROR( ZSTD_compressBegin_internal(cctx, in ZSTD_CCtx_init_compressStream2()
4340 cctx->cdict, in ZSTD_CCtx_init_compressStream2()
4343 assert(cctx->appliedParams.nbWorkers == 0); in ZSTD_CCtx_init_compressStream2()
4344 cctx->inToCompress = 0; in ZSTD_CCtx_init_compressStream2()
4345 cctx->inBuffPos = 0; in ZSTD_CCtx_init_compressStream2()
4346 if (cctx->appliedParams.inBufferMode == ZSTD_bm_buffered) { in ZSTD_CCtx_init_compressStream2()
4350 cctx->inBuffTarget = cctx->blockSize + (cctx->blockSize == pledgedSrcSize); in ZSTD_CCtx_init_compressStream2()
4352 cctx->inBuffTarget = 0; in ZSTD_CCtx_init_compressStream2()
4354 cctx->outBuffContentSize = cctx->outBuffFlushedSize = 0; in ZSTD_CCtx_init_compressStream2()
4355 cctx->streamStage = zcss_load; in ZSTD_CCtx_init_compressStream2()
4356 cctx->frameEnded = 0; in ZSTD_CCtx_init_compressStream2()
4361 size_t ZSTD_compressStream2( ZSTD_CCtx* cctx, in ZSTD_compressStream2() argument
4371 assert(cctx != NULL); in ZSTD_compressStream2()
4374 if (cctx->streamStage == zcss_init) { in ZSTD_compressStream2()
4375 …FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size), "CompressStream2 initia… in ZSTD_compressStream2()
4376 …ZSTD_setBufferExpectations(cctx, output, input); /* Set initial buffer expectations now that we… in ZSTD_compressStream2()
4380 FORWARD_IF_ERROR(ZSTD_checkBufferStability(cctx, output, input, endOp), "invalid buffers"); in ZSTD_compressStream2()
4382 FORWARD_IF_ERROR( ZSTD_compressStream_generic(cctx, output, input, endOp) , ""); in ZSTD_compressStream2()
4384 ZSTD_setBufferExpectations(cctx, output, input); in ZSTD_compressStream2()
4385 return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */ in ZSTD_compressStream2()
4389 ZSTD_CCtx* cctx, in ZSTD_compressStream2_simpleArgs() argument
4397 size_t const cErr = ZSTD_compressStream2(cctx, &output, &input, endOp); in ZSTD_compressStream2_simpleArgs()
4403 size_t ZSTD_compress2(ZSTD_CCtx* cctx, in ZSTD_compress2() argument
4407 ZSTD_bufferMode_e const originalInBufferMode = cctx->requestedParams.inBufferMode; in ZSTD_compress2()
4408 ZSTD_bufferMode_e const originalOutBufferMode = cctx->requestedParams.outBufferMode; in ZSTD_compress2()
4410 ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only); in ZSTD_compress2()
4412 cctx->requestedParams.inBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
4413 cctx->requestedParams.outBufferMode = ZSTD_bm_stable; in ZSTD_compress2()
4416 size_t const result = ZSTD_compressStream2_simpleArgs(cctx, in ZSTD_compress2()
4421 cctx->requestedParams.inBufferMode = originalInBufferMode; in ZSTD_compress2()
4422 cctx->requestedParams.outBufferMode = originalOutBufferMode; in ZSTD_compress2()
4479 static size_t ZSTD_copySequencesToSeqStoreExplicitBlockDelim(ZSTD_CCtx* cctx, ZSTD_sequencePosition… in ZSTD_copySequencesToSeqStoreExplicitBlockDelim() argument
4492 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4493 dictSize = (U32)cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4494 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4495 dictSize = (U32)cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4499 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4508 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4511 cctx->appliedParams.cParams.windowLog, dictSize, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4512 cctx->appliedParams.cParams.minMatch), in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4515 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4517 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4520 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4524 ZSTD_storeLastLiterals(&cctx->seqStore, ip, inSeqs[idx].litLength); in ZSTD_copySequencesToSeqStoreExplicitBlockDelim()
4544 static size_t ZSTD_copySequencesToSeqStoreNoBlockDelim(ZSTD_CCtx* cctx, ZSTD_sequencePosition* seqP… in ZSTD_copySequencesToSeqStoreNoBlockDelim() argument
4561 if (cctx->cdict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4562 dictSize = cctx->cdict->dictContentSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4563 } else if (cctx->prefixDict.dict) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4564 dictSize = cctx->prefixDict.dictSize; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4570 ZSTD_memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4599 … if (matchLength > blockSize && firstHalfMatchLength >= cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4602 if (secondHalfMatchLength < cctx->appliedParams.cParams.minMatch) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4604 … endPosInSequence -= cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4605 … bytesAdjustment = cctx->appliedParams.cParams.minMatch - secondHalfMatchLength; in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4633 if (cctx->appliedParams.validateSequences) { in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4636 cctx->appliedParams.cParams.windowLog, dictSize, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4637 cctx->appliedParams.cParams.minMatch), in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4641 RETURN_ERROR_IF(idx - seqPos->idx > cctx->seqStore.maxNbSeq, memory_allocation, in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4643 ZSTD_storeSeq(&cctx->seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4650 ZSTD_memcpy(cctx->blockState.nextCBlock->rep, updatedRepcodes.rep, sizeof(repcodes_t)); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4658 ZSTD_storeLastLiterals(&cctx->seqStore, ip, lastLLSize); in ZSTD_copySequencesToSeqStoreNoBlockDelim()
4665 typedef size_t (*ZSTD_sequenceCopier) (ZSTD_CCtx* cctx, ZSTD_sequencePosition* seqPos,
4684 static size_t ZSTD_compressSequences_internal(ZSTD_CCtx* cctx, in ZSTD_compressSequences_internal() argument
4697 …ZSTD_sequenceCopier sequenceCopier = ZSTD_selectSequenceCopier(cctx->appliedParams.blockDelimiters… in ZSTD_compressSequences_internal()
4713 lastBlock = remaining <= cctx->blockSize; in ZSTD_compressSequences_internal()
4714 blockSize = lastBlock ? (U32)remaining : (U32)cctx->blockSize; in ZSTD_compressSequences_internal()
4715 ZSTD_resetSeqStore(&cctx->seqStore); in ZSTD_compressSequences_internal()
4718 additionalByteAdjustment = sequenceCopier(cctx, &seqPos, inSeqs, inSeqsSize, ip, blockSize); in ZSTD_compressSequences_internal()
4735 compressedSeqsSize = ZSTD_entropyCompressSequences(&cctx->seqStore, in ZSTD_compressSequences_internal()
4736 … &cctx->blockState.prevCBlock->entropy, &cctx->blockState.nextCBlock->entropy, in ZSTD_compressSequences_internal()
4737 &cctx->appliedParams, in ZSTD_compressSequences_internal()
4740cctx->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */, in ZSTD_compressSequences_internal()
4741 cctx->bmi2); in ZSTD_compressSequences_internal()
4745 if (!cctx->isFirstBlock && in ZSTD_compressSequences_internal()
4746 ZSTD_maybeRLE(&cctx->seqStore) && in ZSTD_compressSequences_internal()
4767 ZSTD_confirmRepcodesAndEntropyTables(cctx); in ZSTD_compressSequences_internal()
4768 if (cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat_valid) in ZSTD_compressSequences_internal()
4769 cctx->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat_check; in ZSTD_compressSequences_internal()
4788 cctx->isFirstBlock = 0; in ZSTD_compressSequences_internal()
4795 size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* dst, size_t dstCapacity, in ZSTD_compressSequences() argument
4805 assert(cctx != NULL); in ZSTD_compressSequences()
4806 …FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, ZSTD_e_end, srcSize), "CCtx initialization f… in ZSTD_compressSequences()
4808 …frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->appliedParams, srcSize, cctx->dict… in ZSTD_compressSequences()
4812 if (cctx->appliedParams.fParams.checksumFlag && srcSize) { in ZSTD_compressSequences()
4813 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compressSequences()
4816 compressedBlocksSize = ZSTD_compressSequences_internal(cctx, in ZSTD_compressSequences()
4824 if (cctx->appliedParams.fParams.checksumFlag) { in ZSTD_compressSequences()
4825 U32 const checksum = (U32) xxh64_digest(&cctx->xxhState); in ZSTD_compressSequences()