Lines Matching +full:5 +full:- +full:byte
2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
12 * Free Software Foundation. This program is dual-licensed; you may select
17 /*-*************************************
28 /*-*************************************
35 /*-*************************************
40 /*-*************************************
45 ssPtr->lit = ssPtr->litStart; in ZSTD_resetSeqStore()
46 ssPtr->sequences = ssPtr->sequencesStart; in ZSTD_resetSeqStore()
47 ssPtr->longLengthID = 0; in ZSTD_resetSeqStore()
50 /*-*************************************
54 const BYTE *nextSrc; /* next block here to continue on curr prefix */
55 const BYTE *base; /* All regular indexes relative to this position */
56 const BYTE *dictBase; /* extDict indexes relative to this position */
63 U32 forceWindow; /* force back-references to respect limit of 1<<wLog, even for dictionary */
64 U32 forceRawDict; /* Force loading dictionary in "content-only" mode (no header analysis) */
118 cctx->customMem = customMem; in ZSTD_createCCtx_advanced()
127 cctx->workSpace = ZSTD_stackAllocAll(cctx->customMem.opaque, &cctx->workSpaceSize); in ZSTD_initCCtx()
136 ZSTD_free(cctx->workSpace, cctx->customMem); in ZSTD_freeCCtx()
137 ZSTD_free(cctx, cctx->customMem); in ZSTD_freeCCtx()
141 const seqStore_t *ZSTD_getSeqStore(const ZSTD_CCtx *ctx) /* hidden interface */ { return &(ctx->seq… in ZSTD_getSeqStore()
143 static ZSTD_parameters ZSTD_getParamsFromCCtx(const ZSTD_CCtx *cctx) { return cctx->params; } in ZSTD_getParamsFromCCtx()
171 return hashLog - btScale; in ZSTD_cycleLog()
190 U32 const srcLog = MAX(ZSTD_HASHLOG_MIN, ZSTD_highbit32((U32)(rSize)-1) + 1); in ZSTD_adjustCParams()
200 cPar.chainLog -= (cycleLog - cPar.windowLog); in ZSTD_adjustCParams()
219 U32 const end = (U32)(cctx->nextSrc - cctx->base); in ZSTD_continueCCtx()
220 cctx->params = params; in ZSTD_continueCCtx()
221 cctx->frameContentSize = frameContentSize; in ZSTD_continueCCtx()
222 cctx->lowLimit = end; in ZSTD_continueCCtx()
223 cctx->dictLimit = end; in ZSTD_continueCCtx()
224 cctx->nextToUpdate = end + 1; in ZSTD_continueCCtx()
225 cctx->stage = ZSTDcs_init; in ZSTD_continueCCtx()
226 cctx->dictID = 0; in ZSTD_continueCCtx()
227 cctx->loadedDictEnd = 0; in ZSTD_continueCCtx()
231 cctx->rep[i] = repStartValue[i]; in ZSTD_continueCCtx()
233 cctx->seqStore.litLengthSum = 0; /* force reset of btopt stats */ in ZSTD_continueCCtx()
234 xxh64_reset(&cctx->xxhState, 0); in ZSTD_continueCCtx()
245 if (ZSTD_equivalentParams(params, zc->params)) { in ZSTD_resetCCtx_advanced()
246 zc->flagStaticTables = 0; in ZSTD_resetCCtx_advanced()
247 zc->flagStaticHufTable = HUF_repeat_none; in ZSTD_resetCCtx_advanced()
269 if (zc->workSpaceSize < neededSpace) { in ZSTD_resetCCtx_advanced()
270 ZSTD_free(zc->workSpace, zc->customMem); in ZSTD_resetCCtx_advanced()
271 zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem); in ZSTD_resetCCtx_advanced()
272 if (zc->workSpace == NULL) in ZSTD_resetCCtx_advanced()
274 zc->workSpaceSize = neededSpace; in ZSTD_resetCCtx_advanced()
279 memset(zc->workSpace, 0, tableSpace); /* reset tables only */ in ZSTD_resetCCtx_advanced()
280 xxh64_reset(&zc->xxhState, 0); in ZSTD_resetCCtx_advanced()
281 zc->hashLog3 = hashLog3; in ZSTD_resetCCtx_advanced()
282 zc->hashTable = (U32 *)(zc->workSpace); in ZSTD_resetCCtx_advanced()
283 zc->chainTable = zc->hashTable + hSize; in ZSTD_resetCCtx_advanced()
284 zc->hashTable3 = zc->chainTable + chainSize; in ZSTD_resetCCtx_advanced()
285 ptr = zc->hashTable3 + h3Size; in ZSTD_resetCCtx_advanced()
286 zc->hufTable = (HUF_CElt *)ptr; in ZSTD_resetCCtx_advanced()
287 zc->flagStaticTables = 0; in ZSTD_resetCCtx_advanced()
288 zc->flagStaticHufTable = HUF_repeat_none; in ZSTD_resetCCtx_advanced()
291 zc->nextToUpdate = 1; in ZSTD_resetCCtx_advanced()
292 zc->nextSrc = NULL; in ZSTD_resetCCtx_advanced()
293 zc->base = NULL; in ZSTD_resetCCtx_advanced()
294 zc->dictBase = NULL; in ZSTD_resetCCtx_advanced()
295 zc->dictLimit = 0; in ZSTD_resetCCtx_advanced()
296 zc->lowLimit = 0; in ZSTD_resetCCtx_advanced()
297 zc->params = params; in ZSTD_resetCCtx_advanced()
298 zc->blockSize = blockSize; in ZSTD_resetCCtx_advanced()
299 zc->frameContentSize = frameContentSize; in ZSTD_resetCCtx_advanced()
303 zc->rep[i] = repStartValue[i]; in ZSTD_resetCCtx_advanced()
307 zc->seqStore.litFreq = (U32 *)ptr; in ZSTD_resetCCtx_advanced()
308 zc->seqStore.litLengthFreq = zc->seqStore.litFreq + (1 << Litbits); in ZSTD_resetCCtx_advanced()
309 zc->seqStore.matchLengthFreq = zc->seqStore.litLengthFreq + (MaxLL + 1); in ZSTD_resetCCtx_advanced()
310 zc->seqStore.offCodeFreq = zc->seqStore.matchLengthFreq + (MaxML + 1); in ZSTD_resetCCtx_advanced()
311 ptr = zc->seqStore.offCodeFreq + (MaxOff + 1); in ZSTD_resetCCtx_advanced()
312 zc->seqStore.matchTable = (ZSTD_match_t *)ptr; in ZSTD_resetCCtx_advanced()
313 ptr = zc->seqStore.matchTable + ZSTD_OPT_NUM + 1; in ZSTD_resetCCtx_advanced()
314 zc->seqStore.priceTable = (ZSTD_optimal_t *)ptr; in ZSTD_resetCCtx_advanced()
315 ptr = zc->seqStore.priceTable + ZSTD_OPT_NUM + 1; in ZSTD_resetCCtx_advanced()
316 zc->seqStore.litLengthSum = 0; in ZSTD_resetCCtx_advanced()
318 zc->seqStore.sequencesStart = (seqDef *)ptr; in ZSTD_resetCCtx_advanced()
319 ptr = zc->seqStore.sequencesStart + maxNbSeq; in ZSTD_resetCCtx_advanced()
320 zc->seqStore.llCode = (BYTE *)ptr; in ZSTD_resetCCtx_advanced()
321 zc->seqStore.mlCode = zc->seqStore.llCode + maxNbSeq; in ZSTD_resetCCtx_advanced()
322 zc->seqStore.ofCode = zc->seqStore.mlCode + maxNbSeq; in ZSTD_resetCCtx_advanced()
323 zc->seqStore.litStart = zc->seqStore.ofCode + maxNbSeq; in ZSTD_resetCCtx_advanced()
325 zc->stage = ZSTDcs_init; in ZSTD_resetCCtx_advanced()
326 zc->dictID = 0; in ZSTD_resetCCtx_advanced()
327 zc->loadedDictEnd = 0; in ZSTD_resetCCtx_advanced()
341 cctx->rep[i] = 0; in ZSTD_invalidateRepCodes()
350 if (srcCCtx->stage != ZSTDcs_init) in ZSTD_copyCCtx()
353 memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); in ZSTD_copyCCtx()
355 ZSTD_parameters params = srcCCtx->params; in ZSTD_copyCCtx()
362 …size_t const chainSize = (srcCCtx->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->para… in ZSTD_copyCCtx()
363 size_t const hSize = ((size_t)1) << srcCCtx->params.cParams.hashLog; in ZSTD_copyCCtx()
364 size_t const h3Size = (size_t)1 << srcCCtx->hashLog3; in ZSTD_copyCCtx()
366 memcpy(dstCCtx->workSpace, srcCCtx->workSpace, tableSpace); in ZSTD_copyCCtx()
370 dstCCtx->nextToUpdate = srcCCtx->nextToUpdate; in ZSTD_copyCCtx()
371 dstCCtx->nextToUpdate3 = srcCCtx->nextToUpdate3; in ZSTD_copyCCtx()
372 dstCCtx->nextSrc = srcCCtx->nextSrc; in ZSTD_copyCCtx()
373 dstCCtx->base = srcCCtx->base; in ZSTD_copyCCtx()
374 dstCCtx->dictBase = srcCCtx->dictBase; in ZSTD_copyCCtx()
375 dstCCtx->dictLimit = srcCCtx->dictLimit; in ZSTD_copyCCtx()
376 dstCCtx->lowLimit = srcCCtx->lowLimit; in ZSTD_copyCCtx()
377 dstCCtx->loadedDictEnd = srcCCtx->loadedDictEnd; in ZSTD_copyCCtx()
378 dstCCtx->dictID = srcCCtx->dictID; in ZSTD_copyCCtx()
381 dstCCtx->flagStaticTables = srcCCtx->flagStaticTables; in ZSTD_copyCCtx()
382 dstCCtx->flagStaticHufTable = srcCCtx->flagStaticHufTable; in ZSTD_copyCCtx()
383 if (srcCCtx->flagStaticTables) { in ZSTD_copyCCtx()
384 memcpy(dstCCtx->litlengthCTable, srcCCtx->litlengthCTable, sizeof(dstCCtx->litlengthCTable)); in ZSTD_copyCCtx()
385 …memcpy(dstCCtx->matchlengthCTable, srcCCtx->matchlengthCTable, sizeof(dstCCtx->matchlengthCTable)); in ZSTD_copyCCtx()
386 memcpy(dstCCtx->offcodeCTable, srcCCtx->offcodeCTable, sizeof(dstCCtx->offcodeCTable)); in ZSTD_copyCCtx()
388 if (srcCCtx->flagStaticHufTable) { in ZSTD_copyCCtx()
389 memcpy(dstCCtx->hufTable, srcCCtx->hufTable, 256 * 4); in ZSTD_copyCCtx()
404 table[u] -= reducerValue; in ZSTD_reduceTable()
413 U32 const hSize = 1 << zc->params.cParams.hashLog; in ZSTD_reduceIndex()
414 ZSTD_reduceTable(zc->hashTable, hSize, reducerValue); in ZSTD_reduceIndex()
418 …U32 const chainSize = (zc->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << zc->params.cParams.ch… in ZSTD_reduceIndex()
419 ZSTD_reduceTable(zc->chainTable, chainSize, reducerValue); in ZSTD_reduceIndex()
423 U32 const h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0; in ZSTD_reduceIndex()
424 ZSTD_reduceTable(zc->hashTable3, h3Size, reducerValue); in ZSTD_reduceIndex()
428 /*-*******************************************************
438 memcpy((BYTE *)dst + ZSTD_blockHeaderSize, src, srcSize); in ZSTD_noCompressBlock()
445 BYTE *const ostart = (BYTE * const)dst; in ZSTD_noCompressLiterals()
452 case 1: /* 2 - 1 - 5 */ ostart[0] = (BYTE)((U32)set_basic + (srcSize << 3)); break; in ZSTD_noCompressLiterals()
453 …case 2: /* 2 - 2 - 12 */ ZSTD_writeLE16(ostart, (U16)((U32)set_basic + (1 << 2) + (srcSize << 4)))… in ZSTD_noCompressLiterals()
455 …case 3: /* 2 - 2 - 20 */ ZSTD_writeLE32(ostart, (U32)((U32)set_basic + (3 << 2) + (srcSize << 4)))… in ZSTD_noCompressLiterals()
464 BYTE *const ostart = (BYTE * const)dst; in ZSTD_compressRleLiteralsBlock()
470 case 1: /* 2 - 1 - 5 */ ostart[0] = (BYTE)((U32)set_rle + (srcSize << 3)); break; in ZSTD_compressRleLiteralsBlock()
471 …case 2: /* 2 - 2 - 12 */ ZSTD_writeLE16(ostart, (U16)((U32)set_rle + (1 << 2) + (srcSize << 4))); … in ZSTD_compressRleLiteralsBlock()
473 …case 3: /* 2 - 2 - 20 */ ZSTD_writeLE32(ostart, (U32)((U32)set_rle + (3 << 2) + (srcSize << 4))); … in ZSTD_compressRleLiteralsBlock()
476 ostart[flSize] = *(const BYTE *)src; in ZSTD_compressRleLiteralsBlock()
486 BYTE *const ostart = (BYTE *)dst; in ZSTD_compressLiterals()
494 size_t const minLitSize = zc->flagStaticHufTable == HUF_repeat_valid ? 6 : LITERAL_NOENTROPY; in ZSTD_compressLiterals()
502 HUF_repeat repeat = zc->flagStaticHufTable; in ZSTD_compressLiterals()
503 int const preferRepeat = zc->params.cParams.strategy < ZSTD_lazy ? srcSize <= 1024 : 0; in ZSTD_compressLiterals()
506 …ream ? HUF_compress1X_repeat(ostart + lhSize, dstCapacity - lhSize, src, srcSize, 255, 11, zc->tmp… in ZSTD_compressLiterals()
507 sizeof(zc->tmpCounters), zc->hufTable, &repeat, preferRepeat) in ZSTD_compressLiterals()
508 …: HUF_compress4X_repeat(ostart + lhSize, dstCapacity - lhSize, src, srcSize, 255, 11, zc->tmpCount… in ZSTD_compressLiterals()
509 sizeof(zc->tmpCounters), zc->hufTable, &repeat, preferRepeat); in ZSTD_compressLiterals()
514 zc->flagStaticHufTable = HUF_repeat_check; in ZSTD_compressLiterals()
518 if ((cLitSize == 0) | (cLitSize >= srcSize - minGain)) { in ZSTD_compressLiterals()
519 zc->flagStaticHufTable = HUF_repeat_none; in ZSTD_compressLiterals()
523 zc->flagStaticHufTable = HUF_repeat_none; in ZSTD_compressLiterals()
529 case 3: /* 2 - 2 - 10 - 10 */ in ZSTD_compressLiterals()
535 case 4: /* 2 - 2 - 14 - 14 */ in ZSTD_compressLiterals()
541 default: /* should not be necessary, lhSize is only {3,4,5} */ in ZSTD_compressLiterals()
542 case 5: /* 2 - 2 - 18 - 18 */ in ZSTD_compressLiterals()
546 ostart[4] = (BYTE)(cLitSize >> 10); in ZSTD_compressLiterals()
553 static const BYTE LL_Code[64] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…
557 static const BYTE ML_Code[128] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1…
565 BYTE const LL_deltaCode = 19; in ZSTD_seqToCodes()
566 BYTE const ML_deltaCode = 36; in ZSTD_seqToCodes()
567 const seqDef *const sequences = seqStorePtr->sequencesStart; in ZSTD_seqToCodes()
568 BYTE *const llCodeTable = seqStorePtr->llCode; in ZSTD_seqToCodes()
569 BYTE *const ofCodeTable = seqStorePtr->ofCode; in ZSTD_seqToCodes()
570 BYTE *const mlCodeTable = seqStorePtr->mlCode; in ZSTD_seqToCodes()
571 U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_seqToCodes()
576 llCodeTable[u] = (llv > 63) ? (BYTE)ZSTD_highbit32(llv) + LL_deltaCode : LL_Code[llv]; in ZSTD_seqToCodes()
577 ofCodeTable[u] = (BYTE)ZSTD_highbit32(sequences[u].offset); in ZSTD_seqToCodes()
578 mlCodeTable[u] = (mlv > 127) ? (BYTE)ZSTD_highbit32(mlv) + ML_deltaCode : ML_Code[mlv]; in ZSTD_seqToCodes()
580 if (seqStorePtr->longLengthID == 1) in ZSTD_seqToCodes()
581 llCodeTable[seqStorePtr->longLengthPos] = MaxLL; in ZSTD_seqToCodes()
582 if (seqStorePtr->longLengthID == 2) in ZSTD_seqToCodes()
583 mlCodeTable[seqStorePtr->longLengthPos] = MaxML; in ZSTD_seqToCodes()
588 const int longOffsets = zc->params.cParams.windowLog > STREAM_ACCUMULATOR_MIN; in ZSTD_compressSequences_internal()
589 const seqStore_t *seqStorePtr = &(zc->seqStore); in ZSTD_compressSequences_internal()
590 FSE_CTable *CTable_LitLength = zc->litlengthCTable; in ZSTD_compressSequences_internal()
591 FSE_CTable *CTable_OffsetBits = zc->offcodeCTable; in ZSTD_compressSequences_internal()
592 FSE_CTable *CTable_MatchLength = zc->matchlengthCTable; in ZSTD_compressSequences_internal()
594 const seqDef *const sequences = seqStorePtr->sequencesStart; in ZSTD_compressSequences_internal()
595 const BYTE *const ofCodeTable = seqStorePtr->ofCode; in ZSTD_compressSequences_internal()
596 const BYTE *const llCodeTable = seqStorePtr->llCode; in ZSTD_compressSequences_internal()
597 const BYTE *const mlCodeTable = seqStorePtr->mlCode; in ZSTD_compressSequences_internal()
598 BYTE *const ostart = (BYTE *)dst; in ZSTD_compressSequences_internal()
599 BYTE *const oend = ostart + dstCapacity; in ZSTD_compressSequences_internal()
600 BYTE *op = ostart; in ZSTD_compressSequences_internal()
601 size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; in ZSTD_compressSequences_internal()
602 BYTE *seqHead; in ZSTD_compressSequences_internal()
607 size_t workspaceSize = sizeof(zc->tmpCounters); in ZSTD_compressSequences_internal()
610 count = (U32 *)zc->tmpCounters + spaceUsed32; in ZSTD_compressSequences_internal()
612 norm = (S16 *)((U32 *)zc->tmpCounters + spaceUsed32); in ZSTD_compressSequences_internal()
615 workspace = (U32 *)zc->tmpCounters + spaceUsed32; in ZSTD_compressSequences_internal()
616 workspaceSize -= (spaceUsed32 << 2); in ZSTD_compressSequences_internal()
621 const BYTE *const literals = seqStorePtr->litStart; in ZSTD_compressSequences_internal()
622 size_t const litSize = seqStorePtr->lit - literals; in ZSTD_compressSequences_internal()
630 if ((oend - op) < 3 /*max nbSeq Size*/ + 1 /*seqHead */) in ZSTD_compressSequences_internal()
633 *op++ = (BYTE)nbSeq; in ZSTD_compressSequences_internal()
635 op[0] = (BYTE)((nbSeq >> 8) + 0x80), op[1] = (BYTE)nbSeq, op += 2; in ZSTD_compressSequences_internal()
637 op[0] = 0xFF, ZSTD_writeLE16(op + 1, (U16)(nbSeq - LONGNBSEQ)), op += 3; in ZSTD_compressSequences_internal()
639 return op - ostart; in ZSTD_compressSequences_internal()
656 FSE_buildCTable_rle(CTable_LitLength, (BYTE)max); in ZSTD_compressSequences_internal()
658 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { in ZSTD_compressSequences_internal()
660 …} else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (LL_defaultNormLog - 1))… in ZSTD_compressSequences_internal()
666 if (count[llCodeTable[nbSeq - 1]] > 1) { in ZSTD_compressSequences_internal()
667 count[llCodeTable[nbSeq - 1]]--; in ZSTD_compressSequences_internal()
668 nbSeq_1--; in ZSTD_compressSequences_internal()
672 …size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protect… in ZSTD_compressSequences_internal()
688 FSE_buildCTable_rle(CTable_OffsetBits, (BYTE)max); in ZSTD_compressSequences_internal()
690 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { in ZSTD_compressSequences_internal()
692 …} else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (OF_defaultNormLog - 1))… in ZSTD_compressSequences_internal()
698 if (count[ofCodeTable[nbSeq - 1]] > 1) { in ZSTD_compressSequences_internal()
699 count[ofCodeTable[nbSeq - 1]]--; in ZSTD_compressSequences_internal()
700 nbSeq_1--; in ZSTD_compressSequences_internal()
704 …size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protect… in ZSTD_compressSequences_internal()
720 FSE_buildCTable_rle(CTable_MatchLength, (BYTE)max); in ZSTD_compressSequences_internal()
722 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { in ZSTD_compressSequences_internal()
724 …} else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (ML_defaultNormLog - 1))… in ZSTD_compressSequences_internal()
730 if (count[mlCodeTable[nbSeq - 1]] > 1) { in ZSTD_compressSequences_internal()
731 count[mlCodeTable[nbSeq - 1]]--; in ZSTD_compressSequences_internal()
732 nbSeq_1--; in ZSTD_compressSequences_internal()
736 …size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protect… in ZSTD_compressSequences_internal()
746 *seqHead = (BYTE)((LLtype << 6) + (Offtype << 4) + (MLtype << 2)); in ZSTD_compressSequences_internal()
747 zc->flagStaticTables = 0; in ZSTD_compressSequences_internal()
756 …CHECK_E(BIT_initCStream(&blockStream, op, oend - op), dstSize_tooSmall); /* not enough space remai… in ZSTD_compressSequences_internal()
759 FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq - 1]); in ZSTD_compressSequences_internal()
760 FSE_initCState2(&stateOffsetBits, CTable_OffsetBits, ofCodeTable[nbSeq - 1]); in ZSTD_compressSequences_internal()
761 FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq - 1]); in ZSTD_compressSequences_internal()
762 BIT_addBits(&blockStream, sequences[nbSeq - 1].litLength, LL_bits[llCodeTable[nbSeq - 1]]); in ZSTD_compressSequences_internal()
765 BIT_addBits(&blockStream, sequences[nbSeq - 1].matchLength, ML_bits[mlCodeTable[nbSeq - 1]]); in ZSTD_compressSequences_internal()
769 U32 const ofBits = ofCodeTable[nbSeq - 1]; in ZSTD_compressSequences_internal()
770 int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN - 1); in ZSTD_compressSequences_internal()
772 BIT_addBits(&blockStream, sequences[nbSeq - 1].offset, extraBits); in ZSTD_compressSequences_internal()
775 BIT_addBits(&blockStream, sequences[nbSeq - 1].offset >> extraBits, ofBits - extraBits); in ZSTD_compressSequences_internal()
777 BIT_addBits(&blockStream, sequences[nbSeq - 1].offset, ofCodeTable[nbSeq - 1]); in ZSTD_compressSequences_internal()
783 for (n = nbSeq - 2; n < nbSeq; n--) { /* intentional underflow */ in ZSTD_compressSequences_internal()
784 BYTE const llCode = llCodeTable[n]; in ZSTD_compressSequences_internal()
785 BYTE const ofCode = ofCodeTable[n]; in ZSTD_compressSequences_internal()
786 BYTE const mlCode = mlCodeTable[n]; in ZSTD_compressSequences_internal()
796 if (ZSTD_32bits() || (ofBits + mlBits + llBits >= 64 - 7 - (LLFSELog + MLFSELog + OffFSELog))) in ZSTD_compressSequences_internal()
805 int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN - 1); in ZSTD_compressSequences_internal()
810 BIT_addBits(&blockStream, sequences[n].offset >> extraBits, ofBits - extraBits); /* 31 */ in ZSTD_compressSequences_internal()
829 return op - ostart; in ZSTD_compressSequences_internal()
836 size_t const maxCSize = srcSize - minGain; in ZSTD_compressSequences()
847 zc->flagStaticHufTable = HUF_repeat_none; in ZSTD_compressSequences()
852 zc->rep[i] = zc->repToConfirm[i]; in ZSTD_compressSequences()
859 `matchCode` : matchLength - MINMATCH
864 ZSTD_wildcopy(seqStorePtr->lit, literals, litLength); in ZSTD_storeSeq()
865 seqStorePtr->lit += litLength; in ZSTD_storeSeq()
869 seqStorePtr->longLengthID = 1; in ZSTD_storeSeq()
870 seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_storeSeq()
872 seqStorePtr->sequences[0].litLength = (U16)litLength; in ZSTD_storeSeq()
875 seqStorePtr->sequences[0].offset = offsetCode + 1; in ZSTD_storeSeq()
879 seqStorePtr->longLengthID = 2; in ZSTD_storeSeq()
880 seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); in ZSTD_storeSeq()
882 seqStorePtr->sequences[0].matchLength = (U16)matchCode; in ZSTD_storeSeq()
884 seqStorePtr->sequences++; in ZSTD_storeSeq()
887 /*-*************************************
907 static size_t ZSTD_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *const pInLimit) in ZSTD_count()
909 const BYTE *const pStart = pIn; in ZSTD_count()
910 const BYTE *const pInLoopLimit = pInLimit - (sizeof(size_t) - 1); in ZSTD_count()
920 return (size_t)(pIn - pStart); in ZSTD_count()
923 if ((pIn < (pInLimit - 3)) && (ZSTD_read32(pMatch) == ZSTD_read32(pIn))) { in ZSTD_count()
927 if ((pIn < (pInLimit - 1)) && (ZSTD_read16(pMatch) == ZSTD_read16(pIn))) { in ZSTD_count()
933 return (size_t)(pIn - pStart); in ZSTD_count()
940 …atic size_t ZSTD_count_2segments(const BYTE *ip, const BYTE *match, const BYTE *iEnd, const BYTE *… in ZSTD_count_2segments()
942 const BYTE *const vEnd = MIN(ip + (mEnd - match), iEnd); in ZSTD_count_2segments()
949 /*-*************************************
953 static U32 ZSTD_hash3(U32 u, U32 h) { return ((u << (32 - 24)) * prime3bytes) >> (32 - h); } in ZSTD_hash3()
957 static U32 ZSTD_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32 - h); } in ZSTD_hash4()
961 static size_t ZSTD_hash5(U64 u, U32 h) { return (size_t)(((u << (64 - 40)) * prime5bytes) >> (64 - … in ZSTD_hash5()
965 static size_t ZSTD_hash6(U64 u, U32 h) { return (size_t)(((u << (64 - 48)) * prime6bytes) >> (64 - … in ZSTD_hash6()
969 static size_t ZSTD_hash7(U64 u, U32 h) { return (size_t)(((u << (64 - 56)) * prime7bytes) >> (64 - … in ZSTD_hash7()
973 static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u)*prime8bytes) >> (64 - h)); } in ZSTD_hash8()
982 case 5: return ZSTD_hash5Ptr(p, hBits); in ZSTD_hashPtr()
989 /*-*************************************
994 U32 *const hashTable = zc->hashTable; in ZSTD_fillHashTable()
995 U32 const hBits = zc->params.cParams.hashLog; in ZSTD_fillHashTable()
996 const BYTE *const base = zc->base; in ZSTD_fillHashTable()
997 const BYTE *ip = base + zc->nextToUpdate; in ZSTD_fillHashTable()
998 const BYTE *const iend = ((const BYTE *)end) - HASH_READ_SIZE; in ZSTD_fillHashTable()
1002 hashTable[ZSTD_hashPtr(ip, hBits, mls)] = (U32)(ip - base); in ZSTD_fillHashTable()
1010 U32 *const hashTable = cctx->hashTable; in ZSTD_compressBlock_fast_generic()
1011 U32 const hBits = cctx->params.cParams.hashLog; in ZSTD_compressBlock_fast_generic()
1012 seqStore_t *seqStorePtr = &(cctx->seqStore); in ZSTD_compressBlock_fast_generic()
1013 const BYTE *const base = cctx->base; in ZSTD_compressBlock_fast_generic()
1014 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_fast_generic()
1015 const BYTE *ip = istart; in ZSTD_compressBlock_fast_generic()
1016 const BYTE *anchor = istart; in ZSTD_compressBlock_fast_generic()
1017 const U32 lowestIndex = cctx->dictLimit; in ZSTD_compressBlock_fast_generic()
1018 const BYTE *const lowest = base + lowestIndex; in ZSTD_compressBlock_fast_generic()
1019 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_fast_generic()
1020 const BYTE *const ilimit = iend - HASH_READ_SIZE; in ZSTD_compressBlock_fast_generic()
1021 U32 offset_1 = cctx->rep[0], offset_2 = cctx->rep[1]; in ZSTD_compressBlock_fast_generic()
1027 U32 const maxRep = (U32)(ip - lowest); in ZSTD_compressBlock_fast_generic()
1038 U32 const curr = (U32)(ip - base); in ZSTD_compressBlock_fast_generic()
1040 const BYTE *match = base + matchIndex; in ZSTD_compressBlock_fast_generic()
1043 if ((offset_1 > 0) & (ZSTD_read32(ip + 1 - offset_1) == ZSTD_read32(ip + 1))) { in ZSTD_compressBlock_fast_generic()
1044 mLength = ZSTD_count(ip + 1 + 4, ip + 1 + 4 - offset_1, iend) + 4; in ZSTD_compressBlock_fast_generic()
1046 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, 0, mLength - MINMATCH); in ZSTD_compressBlock_fast_generic()
1050 ip += ((ip - anchor) >> g_searchStrength) + 1; in ZSTD_compressBlock_fast_generic()
1054 offset = (U32)(ip - match); in ZSTD_compressBlock_fast_generic()
1055 while (((ip > anchor) & (match > lowest)) && (ip[-1] == match[-1])) { in ZSTD_compressBlock_fast_generic()
1056 ip--; in ZSTD_compressBlock_fast_generic()
1057 match--; in ZSTD_compressBlock_fast_generic()
1063 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, offset + ZSTD_REP_MOVE, mLength - MINMATCH); in ZSTD_compressBlock_fast_generic()
1072 …[ZSTD_hashPtr(base + curr + 2, hBits, mls)] = curr + 2; /* here because curr+2 could be > iend-8 */ in ZSTD_compressBlock_fast_generic()
1073 hashTable[ZSTD_hashPtr(ip - 2, hBits, mls)] = (U32)(ip - 2 - base); in ZSTD_compressBlock_fast_generic()
1075 while ((ip <= ilimit) && ((offset_2 > 0) & (ZSTD_read32(ip) == ZSTD_read32(ip - offset_2)))) { in ZSTD_compressBlock_fast_generic()
1077 size_t const rLength = ZSTD_count(ip + 4, ip + 4 - offset_2, iend) + 4; in ZSTD_compressBlock_fast_generic()
1083 hashTable[ZSTD_hashPtr(ip, hBits, mls)] = (U32)(ip - base); in ZSTD_compressBlock_fast_generic()
1084 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, rLength - MINMATCH); in ZSTD_compressBlock_fast_generic()
1093 cctx->repToConfirm[0] = offset_1 ? offset_1 : offsetSaved; in ZSTD_compressBlock_fast_generic()
1094 cctx->repToConfirm[1] = offset_2 ? offset_2 : offsetSaved; in ZSTD_compressBlock_fast_generic()
1098 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_fast_generic()
1099 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_fast_generic()
1100 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_fast_generic()
1106 const U32 mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_fast()
1110 case 5: ZSTD_compressBlock_fast_generic(ctx, src, srcSize, 5); return; in ZSTD_compressBlock_fast()
1118 U32 *hashTable = ctx->hashTable; in ZSTD_compressBlock_fast_extDict_generic()
1119 const U32 hBits = ctx->params.cParams.hashLog; in ZSTD_compressBlock_fast_extDict_generic()
1120 seqStore_t *seqStorePtr = &(ctx->seqStore); in ZSTD_compressBlock_fast_extDict_generic()
1121 const BYTE *const base = ctx->base; in ZSTD_compressBlock_fast_extDict_generic()
1122 const BYTE *const dictBase = ctx->dictBase; in ZSTD_compressBlock_fast_extDict_generic()
1123 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_fast_extDict_generic()
1124 const BYTE *ip = istart; in ZSTD_compressBlock_fast_extDict_generic()
1125 const BYTE *anchor = istart; in ZSTD_compressBlock_fast_extDict_generic()
1126 const U32 lowestIndex = ctx->lowLimit; in ZSTD_compressBlock_fast_extDict_generic()
1127 const BYTE *const dictStart = dictBase + lowestIndex; in ZSTD_compressBlock_fast_extDict_generic()
1128 const U32 dictLimit = ctx->dictLimit; in ZSTD_compressBlock_fast_extDict_generic()
1129 const BYTE *const lowPrefixPtr = base + dictLimit; in ZSTD_compressBlock_fast_extDict_generic()
1130 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_compressBlock_fast_extDict_generic()
1131 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_fast_extDict_generic()
1132 const BYTE *const ilimit = iend - 8; in ZSTD_compressBlock_fast_extDict_generic()
1133 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1]; in ZSTD_compressBlock_fast_extDict_generic()
1139 const BYTE *matchBase = matchIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_fast_extDict_generic()
1140 const BYTE *match = matchBase + matchIndex; in ZSTD_compressBlock_fast_extDict_generic()
1141 const U32 curr = (U32)(ip - base); in ZSTD_compressBlock_fast_extDict_generic()
1142 const U32 repIndex = curr + 1 - offset_1; /* offset_1 expected <= curr +1 */ in ZSTD_compressBlock_fast_extDict_generic()
1143 const BYTE *repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_fast_extDict_generic()
1144 const BYTE *repMatch = repBase + repIndex; in ZSTD_compressBlock_fast_extDict_generic()
1148 …if ((((U32)((dictLimit - 1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > lowestInde… in ZSTD_compressBlock_fast_extDict_generic()
1150 const BYTE *repMatchEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_fast_extDict_generic()
1153 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, 0, mLength - MINMATCH); in ZSTD_compressBlock_fast_extDict_generic()
1156 ip += ((ip - anchor) >> g_searchStrength) + 1; in ZSTD_compressBlock_fast_extDict_generic()
1160 const BYTE *matchEnd = matchIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_fast_extDict_generic()
1161 const BYTE *lowMatchPtr = matchIndex < dictLimit ? dictStart : lowPrefixPtr; in ZSTD_compressBlock_fast_extDict_generic()
1164 while (((ip > anchor) & (match > lowMatchPtr)) && (ip[-1] == match[-1])) { in ZSTD_compressBlock_fast_extDict_generic()
1165 ip--; in ZSTD_compressBlock_fast_extDict_generic()
1166 match--; in ZSTD_compressBlock_fast_extDict_generic()
1169 offset = curr - matchIndex; in ZSTD_compressBlock_fast_extDict_generic()
1172 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, offset + ZSTD_REP_MOVE, mLength - MINMATCH); in ZSTD_compressBlock_fast_extDict_generic()
1183 hashTable[ZSTD_hashPtr(ip - 2, hBits, mls)] = (U32)(ip - 2 - base); in ZSTD_compressBlock_fast_extDict_generic()
1186 U32 const curr2 = (U32)(ip - base); in ZSTD_compressBlock_fast_extDict_generic()
1187 U32 const repIndex2 = curr2 - offset_2; in ZSTD_compressBlock_fast_extDict_generic()
1188 const BYTE *repMatch2 = repIndex2 < dictLimit ? dictBase + repIndex2 : base + repIndex2; in ZSTD_compressBlock_fast_extDict_generic()
1189 …if ((((U32)((dictLimit - 1) - repIndex2) >= 3) & (repIndex2 > lowestIndex)) /* intentional overflo… in ZSTD_compressBlock_fast_extDict_generic()
1191 const BYTE *const repEnd2 = repIndex2 < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_fast_extDict_generic()
1197 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, repLength2 - MINMATCH); in ZSTD_compressBlock_fast_extDict_generic()
1209 ctx->repToConfirm[0] = offset_1; in ZSTD_compressBlock_fast_extDict_generic()
1210 ctx->repToConfirm[1] = offset_2; in ZSTD_compressBlock_fast_extDict_generic()
1214 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_fast_extDict_generic()
1215 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_fast_extDict_generic()
1216 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_fast_extDict_generic()
1222 U32 const mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_fast_extDict()
1226 case 5: ZSTD_compressBlock_fast_extDict_generic(ctx, src, srcSize, 5); return; in ZSTD_compressBlock_fast_extDict()
1232 /*-*************************************
1237 U32 *const hashLarge = cctx->hashTable; in ZSTD_fillDoubleHashTable()
1238 U32 const hBitsL = cctx->params.cParams.hashLog; in ZSTD_fillDoubleHashTable()
1239 U32 *const hashSmall = cctx->chainTable; in ZSTD_fillDoubleHashTable()
1240 U32 const hBitsS = cctx->params.cParams.chainLog; in ZSTD_fillDoubleHashTable()
1241 const BYTE *const base = cctx->base; in ZSTD_fillDoubleHashTable()
1242 const BYTE *ip = base + cctx->nextToUpdate; in ZSTD_fillDoubleHashTable()
1243 const BYTE *const iend = ((const BYTE *)end) - HASH_READ_SIZE; in ZSTD_fillDoubleHashTable()
1247 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip - base); in ZSTD_fillDoubleHashTable()
1248 hashLarge[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip - base); in ZSTD_fillDoubleHashTable()
1256 U32 *const hashLong = cctx->hashTable; in ZSTD_compressBlock_doubleFast_generic()
1257 const U32 hBitsL = cctx->params.cParams.hashLog; in ZSTD_compressBlock_doubleFast_generic()
1258 U32 *const hashSmall = cctx->chainTable; in ZSTD_compressBlock_doubleFast_generic()
1259 const U32 hBitsS = cctx->params.cParams.chainLog; in ZSTD_compressBlock_doubleFast_generic()
1260 seqStore_t *seqStorePtr = &(cctx->seqStore); in ZSTD_compressBlock_doubleFast_generic()
1261 const BYTE *const base = cctx->base; in ZSTD_compressBlock_doubleFast_generic()
1262 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_doubleFast_generic()
1263 const BYTE *ip = istart; in ZSTD_compressBlock_doubleFast_generic()
1264 const BYTE *anchor = istart; in ZSTD_compressBlock_doubleFast_generic()
1265 const U32 lowestIndex = cctx->dictLimit; in ZSTD_compressBlock_doubleFast_generic()
1266 const BYTE *const lowest = base + lowestIndex; in ZSTD_compressBlock_doubleFast_generic()
1267 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_doubleFast_generic()
1268 const BYTE *const ilimit = iend - HASH_READ_SIZE; in ZSTD_compressBlock_doubleFast_generic()
1269 U32 offset_1 = cctx->rep[0], offset_2 = cctx->rep[1]; in ZSTD_compressBlock_doubleFast_generic()
1275 U32 const maxRep = (U32)(ip - lowest); in ZSTD_compressBlock_doubleFast_generic()
1287 U32 const curr = (U32)(ip - base); in ZSTD_compressBlock_doubleFast_generic()
1290 const BYTE *matchLong = base + matchIndexL; in ZSTD_compressBlock_doubleFast_generic()
1291 const BYTE *match = base + matchIndexS; in ZSTD_compressBlock_doubleFast_generic()
1294 …if ((offset_1 > 0) & (ZSTD_read32(ip + 1 - offset_1) == ZSTD_read32(ip + 1))) { /* note : by const… in ZSTD_compressBlock_doubleFast_generic()
1295 mLength = ZSTD_count(ip + 1 + 4, ip + 1 + 4 - offset_1, iend) + 4; in ZSTD_compressBlock_doubleFast_generic()
1297 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, 0, mLength - MINMATCH); in ZSTD_compressBlock_doubleFast_generic()
1302 offset = (U32)(ip - matchLong); in ZSTD_compressBlock_doubleFast_generic()
1303 while (((ip > anchor) & (matchLong > lowest)) && (ip[-1] == matchLong[-1])) { in ZSTD_compressBlock_doubleFast_generic()
1304 ip--; in ZSTD_compressBlock_doubleFast_generic()
1305 matchLong--; in ZSTD_compressBlock_doubleFast_generic()
1311 const BYTE *match3 = base + matchIndex3; in ZSTD_compressBlock_doubleFast_generic()
1316 offset = (U32)(ip - match3); in ZSTD_compressBlock_doubleFast_generic()
1317 while (((ip > anchor) & (match3 > lowest)) && (ip[-1] == match3[-1])) { in ZSTD_compressBlock_doubleFast_generic()
1318 ip--; in ZSTD_compressBlock_doubleFast_generic()
1319 match3--; in ZSTD_compressBlock_doubleFast_generic()
1324 offset = (U32)(ip - match); in ZSTD_compressBlock_doubleFast_generic()
1325 while (((ip > anchor) & (match > lowest)) && (ip[-1] == match[-1])) { in ZSTD_compressBlock_doubleFast_generic()
1326 ip--; in ZSTD_compressBlock_doubleFast_generic()
1327 match--; in ZSTD_compressBlock_doubleFast_generic()
1332 ip += ((ip - anchor) >> g_searchStrength) + 1; in ZSTD_compressBlock_doubleFast_generic()
1339 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, offset + ZSTD_REP_MOVE, mLength - MINMATCH); in ZSTD_compressBlock_doubleFast_generic()
1349 curr + 2; /* here because curr+2 could be > iend-8 */ in ZSTD_compressBlock_doubleFast_generic()
1350 …hashLong[ZSTD_hashPtr(ip - 2, hBitsL, 8)] = hashSmall[ZSTD_hashPtr(ip - 2, hBitsS, mls)] = (U32)(i… in ZSTD_compressBlock_doubleFast_generic()
1353 while ((ip <= ilimit) && ((offset_2 > 0) & (ZSTD_read32(ip) == ZSTD_read32(ip - offset_2)))) { in ZSTD_compressBlock_doubleFast_generic()
1355 size_t const rLength = ZSTD_count(ip + 4, ip + 4 - offset_2, iend) + 4; in ZSTD_compressBlock_doubleFast_generic()
1361 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip - base); in ZSTD_compressBlock_doubleFast_generic()
1362 hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip - base); in ZSTD_compressBlock_doubleFast_generic()
1363 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, rLength - MINMATCH); in ZSTD_compressBlock_doubleFast_generic()
1372 cctx->repToConfirm[0] = offset_1 ? offset_1 : offsetSaved; in ZSTD_compressBlock_doubleFast_generic()
1373 cctx->repToConfirm[1] = offset_2 ? offset_2 : offsetSaved; in ZSTD_compressBlock_doubleFast_generic()
1377 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_doubleFast_generic()
1378 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_doubleFast_generic()
1379 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_doubleFast_generic()
1385 const U32 mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_doubleFast()
1389 case 5: ZSTD_compressBlock_doubleFast_generic(ctx, src, srcSize, 5); return; in ZSTD_compressBlock_doubleFast()
1397 U32 *const hashLong = ctx->hashTable; in ZSTD_compressBlock_doubleFast_extDict_generic()
1398 U32 const hBitsL = ctx->params.cParams.hashLog; in ZSTD_compressBlock_doubleFast_extDict_generic()
1399 U32 *const hashSmall = ctx->chainTable; in ZSTD_compressBlock_doubleFast_extDict_generic()
1400 U32 const hBitsS = ctx->params.cParams.chainLog; in ZSTD_compressBlock_doubleFast_extDict_generic()
1401 seqStore_t *seqStorePtr = &(ctx->seqStore); in ZSTD_compressBlock_doubleFast_extDict_generic()
1402 const BYTE *const base = ctx->base; in ZSTD_compressBlock_doubleFast_extDict_generic()
1403 const BYTE *const dictBase = ctx->dictBase; in ZSTD_compressBlock_doubleFast_extDict_generic()
1404 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_doubleFast_extDict_generic()
1405 const BYTE *ip = istart; in ZSTD_compressBlock_doubleFast_extDict_generic()
1406 const BYTE *anchor = istart; in ZSTD_compressBlock_doubleFast_extDict_generic()
1407 const U32 lowestIndex = ctx->lowLimit; in ZSTD_compressBlock_doubleFast_extDict_generic()
1408 const BYTE *const dictStart = dictBase + lowestIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1409 const U32 dictLimit = ctx->dictLimit; in ZSTD_compressBlock_doubleFast_extDict_generic()
1410 const BYTE *const lowPrefixPtr = base + dictLimit; in ZSTD_compressBlock_doubleFast_extDict_generic()
1411 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_compressBlock_doubleFast_extDict_generic()
1412 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_doubleFast_extDict_generic()
1413 const BYTE *const ilimit = iend - 8; in ZSTD_compressBlock_doubleFast_extDict_generic()
1414 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1]; in ZSTD_compressBlock_doubleFast_extDict_generic()
1420 const BYTE *matchBase = matchIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_doubleFast_extDict_generic()
1421 const BYTE *match = matchBase + matchIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1425 const BYTE *matchLongBase = matchLongIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_doubleFast_extDict_generic()
1426 const BYTE *matchLong = matchLongBase + matchLongIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1428 const U32 curr = (U32)(ip - base); in ZSTD_compressBlock_doubleFast_extDict_generic()
1429 const U32 repIndex = curr + 1 - offset_1; /* offset_1 expected <= curr +1 */ in ZSTD_compressBlock_doubleFast_extDict_generic()
1430 const BYTE *repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_doubleFast_extDict_generic()
1431 const BYTE *repMatch = repBase + repIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1435 …if ((((U32)((dictLimit - 1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > lowestInde… in ZSTD_compressBlock_doubleFast_extDict_generic()
1437 const BYTE *repMatchEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_doubleFast_extDict_generic()
1440 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, 0, mLength - MINMATCH); in ZSTD_compressBlock_doubleFast_extDict_generic()
1443 const BYTE *matchEnd = matchLongIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_doubleFast_extDict_generic()
1444 const BYTE *lowMatchPtr = matchLongIndex < dictLimit ? dictStart : lowPrefixPtr; in ZSTD_compressBlock_doubleFast_extDict_generic()
1447 offset = curr - matchLongIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1448 while (((ip > anchor) & (matchLong > lowMatchPtr)) && (ip[-1] == matchLong[-1])) { in ZSTD_compressBlock_doubleFast_extDict_generic()
1449 ip--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1450 matchLong--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1455 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, offset + ZSTD_REP_MOVE, mLength - MINMATCH); in ZSTD_compressBlock_doubleFast_extDict_generic()
1460 const BYTE *const match3Base = matchIndex3 < dictLimit ? dictBase : base; in ZSTD_compressBlock_doubleFast_extDict_generic()
1461 const BYTE *match3 = match3Base + matchIndex3; in ZSTD_compressBlock_doubleFast_extDict_generic()
1465 const BYTE *matchEnd = matchIndex3 < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_doubleFast_extDict_generic()
1466 const BYTE *lowMatchPtr = matchIndex3 < dictLimit ? dictStart : lowPrefixPtr; in ZSTD_compressBlock_doubleFast_extDict_generic()
1469 offset = curr + 1 - matchIndex3; in ZSTD_compressBlock_doubleFast_extDict_generic()
1470 while (((ip > anchor) & (match3 > lowMatchPtr)) && (ip[-1] == match3[-1])) { in ZSTD_compressBlock_doubleFast_extDict_generic()
1471 ip--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1472 match3--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1476 const BYTE *matchEnd = matchIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_doubleFast_extDict_generic()
1477 const BYTE *lowMatchPtr = matchIndex < dictLimit ? dictStart : lowPrefixPtr; in ZSTD_compressBlock_doubleFast_extDict_generic()
1479 offset = curr - matchIndex; in ZSTD_compressBlock_doubleFast_extDict_generic()
1480 while (((ip > anchor) & (match > lowMatchPtr)) && (ip[-1] == match[-1])) { in ZSTD_compressBlock_doubleFast_extDict_generic()
1481 ip--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1482 match--; in ZSTD_compressBlock_doubleFast_extDict_generic()
1488 ZSTD_storeSeq(seqStorePtr, ip - anchor, anchor, offset + ZSTD_REP_MOVE, mLength - MINMATCH); in ZSTD_compressBlock_doubleFast_extDict_generic()
1491 ip += ((ip - anchor) >> g_searchStrength) + 1; in ZSTD_compressBlock_doubleFast_extDict_generic()
1504 hashSmall[ZSTD_hashPtr(ip - 2, hBitsS, mls)] = (U32)(ip - 2 - base); in ZSTD_compressBlock_doubleFast_extDict_generic()
1505 hashLong[ZSTD_hashPtr(ip - 2, hBitsL, 8)] = (U32)(ip - 2 - base); in ZSTD_compressBlock_doubleFast_extDict_generic()
1508 U32 const curr2 = (U32)(ip - base); in ZSTD_compressBlock_doubleFast_extDict_generic()
1509 U32 const repIndex2 = curr2 - offset_2; in ZSTD_compressBlock_doubleFast_extDict_generic()
1510 const BYTE *repMatch2 = repIndex2 < dictLimit ? dictBase + repIndex2 : base + repIndex2; in ZSTD_compressBlock_doubleFast_extDict_generic()
1511 …if ((((U32)((dictLimit - 1) - repIndex2) >= 3) & (repIndex2 > lowestIndex)) /* intentional overflo… in ZSTD_compressBlock_doubleFast_extDict_generic()
1513 const BYTE *const repEnd2 = repIndex2 < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_doubleFast_extDict_generic()
1519 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, repLength2 - MINMATCH); in ZSTD_compressBlock_doubleFast_extDict_generic()
1532 ctx->repToConfirm[0] = offset_1; in ZSTD_compressBlock_doubleFast_extDict_generic()
1533 ctx->repToConfirm[1] = offset_2; in ZSTD_compressBlock_doubleFast_extDict_generic()
1537 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_doubleFast_extDict_generic()
1538 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_doubleFast_extDict_generic()
1539 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_doubleFast_extDict_generic()
1545 U32 const mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_doubleFast_extDict()
1549 case 5: ZSTD_compressBlock_doubleFast_extDict_generic(ctx, src, srcSize, 5); return; in ZSTD_compressBlock_doubleFast_extDict()
1555 /*-*************************************
1559 * ip : assumed <= iend-8 .
1561 static U32 ZSTD_insertBt1(ZSTD_CCtx *zc, const BYTE *const ip, const U32 mls, const BYTE *const ien… in ZSTD_insertBt1()
1563 U32 *const hashTable = zc->hashTable; in ZSTD_insertBt1()
1564 U32 const hashLog = zc->params.cParams.hashLog; in ZSTD_insertBt1()
1566 U32 *const bt = zc->chainTable; in ZSTD_insertBt1()
1567 U32 const btLog = zc->params.cParams.chainLog - 1; in ZSTD_insertBt1()
1568 U32 const btMask = (1 << btLog) - 1; in ZSTD_insertBt1()
1571 const BYTE *const base = zc->base; in ZSTD_insertBt1()
1572 const BYTE *const dictBase = zc->dictBase; in ZSTD_insertBt1()
1573 const U32 dictLimit = zc->dictLimit; in ZSTD_insertBt1()
1574 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_insertBt1()
1575 const BYTE *const prefixStart = base + dictLimit; in ZSTD_insertBt1()
1576 const BYTE *match; in ZSTD_insertBt1()
1577 const U32 curr = (U32)(ip - base); in ZSTD_insertBt1()
1578 const U32 btLow = btMask >= curr ? 0 : curr - btMask; in ZSTD_insertBt1()
1582 U32 const windowLow = zc->lowLimit; in ZSTD_insertBt1()
1588 while (nbCompares-- && (matchIndex > windowLow)) { in ZSTD_insertBt1()
1605 if (matchLength > matchEndIdx - matchIndex) in ZSTD_insertBt1()
1637 return MIN(192, (U32)(bestLength - 384)); /* speed optimization */ in ZSTD_insertBt1()
1639 return matchEndIdx - curr - 8; in ZSTD_insertBt1()
1643 static size_t ZSTD_insertBtAndFindBestMatch(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const … in ZSTD_insertBtAndFindBestMatch()
1646 U32 *const hashTable = zc->hashTable; in ZSTD_insertBtAndFindBestMatch()
1647 U32 const hashLog = zc->params.cParams.hashLog; in ZSTD_insertBtAndFindBestMatch()
1649 U32 *const bt = zc->chainTable; in ZSTD_insertBtAndFindBestMatch()
1650 U32 const btLog = zc->params.cParams.chainLog - 1; in ZSTD_insertBtAndFindBestMatch()
1651 U32 const btMask = (1 << btLog) - 1; in ZSTD_insertBtAndFindBestMatch()
1654 const BYTE *const base = zc->base; in ZSTD_insertBtAndFindBestMatch()
1655 const BYTE *const dictBase = zc->dictBase; in ZSTD_insertBtAndFindBestMatch()
1656 const U32 dictLimit = zc->dictLimit; in ZSTD_insertBtAndFindBestMatch()
1657 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_insertBtAndFindBestMatch()
1658 const BYTE *const prefixStart = base + dictLimit; in ZSTD_insertBtAndFindBestMatch()
1659 const U32 curr = (U32)(ip - base); in ZSTD_insertBtAndFindBestMatch()
1660 const U32 btLow = btMask >= curr ? 0 : curr - btMask; in ZSTD_insertBtAndFindBestMatch()
1661 const U32 windowLow = zc->lowLimit; in ZSTD_insertBtAndFindBestMatch()
1670 while (nbCompares-- && (matchIndex > windowLow)) { in ZSTD_insertBtAndFindBestMatch()
1673 const BYTE *match; in ZSTD_insertBtAndFindBestMatch()
1687 if (matchLength > matchEndIdx - matchIndex) in ZSTD_insertBtAndFindBestMatch()
1689 …if ((4 * (int)(matchLength - bestLength)) > (int)(ZSTD_highbit32(curr - matchIndex + 1) - ZSTD_hig… in ZSTD_insertBtAndFindBestMatch()
1690 bestLength = matchLength, *offsetPtr = ZSTD_REP_MOVE + curr - matchIndex; in ZSTD_insertBtAndFindBestMatch()
1720 zc->nextToUpdate = (matchEndIdx > curr + 8) ? matchEndIdx - 8 : curr + 1; in ZSTD_insertBtAndFindBestMatch()
1724 static void ZSTD_updateTree(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iend, const U32 … in ZSTD_updateTree()
1726 const BYTE *const base = zc->base; in ZSTD_updateTree()
1727 const U32 target = (U32)(ip - base); in ZSTD_updateTree()
1728 U32 idx = zc->nextToUpdate; in ZSTD_updateTree()
1735 static size_t ZSTD_BtFindBestMatch(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iLimit, s… in ZSTD_BtFindBestMatch()
1737 if (ip < zc->base + zc->nextToUpdate) in ZSTD_BtFindBestMatch()
1744 …const BYTE *ip, const BYTE *const iLimit, size_t *offsetPtr, const U32 maxNbAttempts, const U32 ma… in ZSTD_BtFindBestMatch_selectMLS()
1749 case 5: return ZSTD_BtFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5); in ZSTD_BtFindBestMatch_selectMLS()
1755 static void ZSTD_updateTree_extDict(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iend, co… in ZSTD_updateTree_extDict()
1757 const BYTE *const base = zc->base; in ZSTD_updateTree_extDict()
1758 const U32 target = (U32)(ip - base); in ZSTD_updateTree_extDict()
1759 U32 idx = zc->nextToUpdate; in ZSTD_updateTree_extDict()
1766 static size_t ZSTD_BtFindBestMatch_extDict(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const i… in ZSTD_BtFindBestMatch_extDict()
1769 if (ip < zc->base + zc->nextToUpdate) in ZSTD_BtFindBestMatch_extDict()
1776 const BYTE *ip, const BYTE *const iLimit, size_t *offsetPtr, const U32 maxNbAttempts, in ZSTD_BtFindBestMatch_selectMLS_extDict()
1782 case 5: return ZSTD_BtFindBestMatch_extDict(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5); in ZSTD_BtFindBestMatch_selectMLS_extDict()
1796 U32 ZSTD_insertAndFindFirstIndex(ZSTD_CCtx *zc, const BYTE *ip, U32 mls) in ZSTD_insertAndFindFirstIndex()
1798 U32 *const hashTable = zc->hashTable; in ZSTD_insertAndFindFirstIndex()
1799 const U32 hashLog = zc->params.cParams.hashLog; in ZSTD_insertAndFindFirstIndex()
1800 U32 *const chainTable = zc->chainTable; in ZSTD_insertAndFindFirstIndex()
1801 const U32 chainMask = (1 << zc->params.cParams.chainLog) - 1; in ZSTD_insertAndFindFirstIndex()
1802 const BYTE *const base = zc->base; in ZSTD_insertAndFindFirstIndex()
1803 const U32 target = (U32)(ip - base); in ZSTD_insertAndFindFirstIndex()
1804 U32 idx = zc->nextToUpdate; in ZSTD_insertAndFindFirstIndex()
1813 zc->nextToUpdate = target; in ZSTD_insertAndFindFirstIndex()
1820 …const BYTE *const ip, const BYTE *const iLimit, size_t *offsetPtr, const U32 maxNbAttempts, const … in ZSTD_HcFindBestMatch_generic()
1823 U32 *const chainTable = zc->chainTable; in ZSTD_HcFindBestMatch_generic()
1824 const U32 chainSize = (1 << zc->params.cParams.chainLog); in ZSTD_HcFindBestMatch_generic()
1825 const U32 chainMask = chainSize - 1; in ZSTD_HcFindBestMatch_generic()
1826 const BYTE *const base = zc->base; in ZSTD_HcFindBestMatch_generic()
1827 const BYTE *const dictBase = zc->dictBase; in ZSTD_HcFindBestMatch_generic()
1828 const U32 dictLimit = zc->dictLimit; in ZSTD_HcFindBestMatch_generic()
1829 const BYTE *const prefixStart = base + dictLimit; in ZSTD_HcFindBestMatch_generic()
1830 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_HcFindBestMatch_generic()
1831 const U32 lowLimit = zc->lowLimit; in ZSTD_HcFindBestMatch_generic()
1832 const U32 curr = (U32)(ip - base); in ZSTD_HcFindBestMatch_generic()
1833 const U32 minChain = curr > chainSize ? curr - chainSize : 0; in ZSTD_HcFindBestMatch_generic()
1835 size_t ml = EQUAL_READ32 - 1; in ZSTD_HcFindBestMatch_generic()
1840 for (; (matchIndex > lowLimit) & (nbAttempts > 0); nbAttempts--) { in ZSTD_HcFindBestMatch_generic()
1841 const BYTE *match; in ZSTD_HcFindBestMatch_generic()
1849 …if (ZSTD_read32(match) == ZSTD_read32(ip)) /* assumption : matchIndex <= dictLimit-4 (by table con… in ZSTD_HcFindBestMatch_generic()
1856 *offsetPtr = curr - matchIndex + ZSTD_REP_MOVE; in ZSTD_HcFindBestMatch_generic()
1869 FORCE_INLINE size_t ZSTD_HcFindBestMatch_selectMLS(ZSTD_CCtx *zc, const BYTE *ip, const BYTE *const… in ZSTD_HcFindBestMatch_selectMLS()
1875 case 5: return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5, 0); in ZSTD_HcFindBestMatch_selectMLS()
1881 …ize_t ZSTD_HcFindBestMatch_extDict_selectMLS(ZSTD_CCtx *zc, const BYTE *ip, const BYTE *const iLim… in ZSTD_HcFindBestMatch_extDict_selectMLS()
1887 case 5: return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5, 1); in ZSTD_HcFindBestMatch_extDict_selectMLS()
1894 * Common parser - lazy strategy
1899 seqStore_t *seqStorePtr = &(ctx->seqStore); in ZSTD_compressBlock_lazy_generic()
1900 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_lazy_generic()
1901 const BYTE *ip = istart; in ZSTD_compressBlock_lazy_generic()
1902 const BYTE *anchor = istart; in ZSTD_compressBlock_lazy_generic()
1903 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_lazy_generic()
1904 const BYTE *const ilimit = iend - 8; in ZSTD_compressBlock_lazy_generic()
1905 const BYTE *const base = ctx->base + ctx->dictLimit; in ZSTD_compressBlock_lazy_generic()
1907 U32 const maxSearches = 1 << ctx->params.cParams.searchLog; in ZSTD_compressBlock_lazy_generic()
1908 U32 const mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_lazy_generic()
1910 …typedef size_t (*searchMax_f)(ZSTD_CCtx * zc, const BYTE *ip, const BYTE *iLimit, size_t *offsetPt… in ZSTD_compressBlock_lazy_generic()
1912 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1], savedOffset = 0; in ZSTD_compressBlock_lazy_generic()
1916 ctx->nextToUpdate3 = ctx->nextToUpdate; in ZSTD_compressBlock_lazy_generic()
1918 U32 const maxRep = (U32)(ip - base); in ZSTD_compressBlock_lazy_generic()
1929 const BYTE *start = ip + 1; in ZSTD_compressBlock_lazy_generic()
1932 if ((offset_1 > 0) & (ZSTD_read32(ip + 1) == ZSTD_read32(ip + 1 - offset_1))) { in ZSTD_compressBlock_lazy_generic()
1934 …matchLength = ZSTD_count(ip + 1 + EQUAL_READ32, ip + 1 + EQUAL_READ32 - offset_1, iend) + EQUAL_RE… in ZSTD_compressBlock_lazy_generic()
1948 ip += ((ip - anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */ in ZSTD_compressBlock_lazy_generic()
1956 if ((offset) && ((offset_1 > 0) & (ZSTD_read32(ip) == ZSTD_read32(ip - offset_1)))) { in ZSTD_compressBlock_lazy_generic()
1957 …size_t const mlRep = ZSTD_count(ip + EQUAL_READ32, ip + EQUAL_READ32 - offset_1, iend) + EQUAL_REA… in ZSTD_compressBlock_lazy_generic()
1959 int const gain1 = (int)(matchLength * 3 - ZSTD_highbit32((U32)offset + 1) + 1); in ZSTD_compressBlock_lazy_generic()
1966 int const gain2 = (int)(ml2 * 4 - ZSTD_highbit32((U32)offset2 + 1)); /* raw approx */ in ZSTD_compressBlock_lazy_generic()
1967 int const gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 4); in ZSTD_compressBlock_lazy_generic()
1977 if ((offset) && ((offset_1 > 0) & (ZSTD_read32(ip) == ZSTD_read32(ip - offset_1)))) { in ZSTD_compressBlock_lazy_generic()
1978 …size_t const ml2 = ZSTD_count(ip + EQUAL_READ32, ip + EQUAL_READ32 - offset_1, iend) + EQUAL_READ3… in ZSTD_compressBlock_lazy_generic()
1980 int const gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 1); in ZSTD_compressBlock_lazy_generic()
1987 int const gain2 = (int)(ml2 * 4 - ZSTD_highbit32((U32)offset2 + 1)); /* raw approx */ in ZSTD_compressBlock_lazy_generic()
1988 int const gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 7); in ZSTD_compressBlock_lazy_generic()
1999 * start[-offset+ZSTD_REP_MOVE-1] is undefined behavior. in ZSTD_compressBlock_lazy_generic()
2000 * (-offset+ZSTD_REP_MOVE-1) is unsigned, and is added to start, which in ZSTD_compressBlock_lazy_generic()
2005 while ((start > anchor) && (start > base + offset - ZSTD_REP_MOVE) && in ZSTD_compressBlock_lazy_generic()
2006 … (start[-1] == (start-offset+ZSTD_REP_MOVE)[-1])) /* only search for offset within prefix */ in ZSTD_compressBlock_lazy_generic()
2008 start--; in ZSTD_compressBlock_lazy_generic()
2012 offset_1 = (U32)(offset - ZSTD_REP_MOVE); in ZSTD_compressBlock_lazy_generic()
2018 size_t const litLength = start - anchor; in ZSTD_compressBlock_lazy_generic()
2019 ZSTD_storeSeq(seqStorePtr, litLength, anchor, (U32)offset, matchLength - MINMATCH); in ZSTD_compressBlock_lazy_generic()
2024 while ((ip <= ilimit) && ((offset_2 > 0) & (ZSTD_read32(ip) == ZSTD_read32(ip - offset_2)))) { in ZSTD_compressBlock_lazy_generic()
2026 matchLength = ZSTD_count(ip + EQUAL_READ32, ip + EQUAL_READ32 - offset_2, iend) + EQUAL_READ32; in ZSTD_compressBlock_lazy_generic()
2030 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, matchLength - MINMATCH); in ZSTD_compressBlock_lazy_generic()
2038 ctx->repToConfirm[0] = offset_1 ? offset_1 : savedOffset; in ZSTD_compressBlock_lazy_generic()
2039 ctx->repToConfirm[1] = offset_2 ? offset_2 : savedOffset; in ZSTD_compressBlock_lazy_generic()
2043 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_lazy_generic()
2044 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_lazy_generic()
2045 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_lazy_generic()
2060 seqStore_t *seqStorePtr = &(ctx->seqStore); in ZSTD_compressBlock_lazy_extDict_generic()
2061 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_lazy_extDict_generic()
2062 const BYTE *ip = istart; in ZSTD_compressBlock_lazy_extDict_generic()
2063 const BYTE *anchor = istart; in ZSTD_compressBlock_lazy_extDict_generic()
2064 const BYTE *const iend = istart + srcSize; in ZSTD_compressBlock_lazy_extDict_generic()
2065 const BYTE *const ilimit = iend - 8; in ZSTD_compressBlock_lazy_extDict_generic()
2066 const BYTE *const base = ctx->base; in ZSTD_compressBlock_lazy_extDict_generic()
2067 const U32 dictLimit = ctx->dictLimit; in ZSTD_compressBlock_lazy_extDict_generic()
2068 const U32 lowestIndex = ctx->lowLimit; in ZSTD_compressBlock_lazy_extDict_generic()
2069 const BYTE *const prefixStart = base + dictLimit; in ZSTD_compressBlock_lazy_extDict_generic()
2070 const BYTE *const dictBase = ctx->dictBase; in ZSTD_compressBlock_lazy_extDict_generic()
2071 const BYTE *const dictEnd = dictBase + dictLimit; in ZSTD_compressBlock_lazy_extDict_generic()
2072 const BYTE *const dictStart = dictBase + ctx->lowLimit; in ZSTD_compressBlock_lazy_extDict_generic()
2074 const U32 maxSearches = 1 << ctx->params.cParams.searchLog; in ZSTD_compressBlock_lazy_extDict_generic()
2075 const U32 mls = ctx->params.cParams.searchLength; in ZSTD_compressBlock_lazy_extDict_generic()
2077 …typedef size_t (*searchMax_f)(ZSTD_CCtx * zc, const BYTE *ip, const BYTE *iLimit, size_t *offsetPt… in ZSTD_compressBlock_lazy_extDict_generic()
2080 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1]; in ZSTD_compressBlock_lazy_extDict_generic()
2083 ctx->nextToUpdate3 = ctx->nextToUpdate; in ZSTD_compressBlock_lazy_extDict_generic()
2090 const BYTE *start = ip + 1; in ZSTD_compressBlock_lazy_extDict_generic()
2091 U32 curr = (U32)(ip - base); in ZSTD_compressBlock_lazy_extDict_generic()
2095 const U32 repIndex = (U32)(curr + 1 - offset_1); in ZSTD_compressBlock_lazy_extDict_generic()
2096 const BYTE *const repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_lazy_extDict_generic()
2097 const BYTE *const repMatch = repBase + repIndex; in ZSTD_compressBlock_lazy_extDict_generic()
2098 …if (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ in ZSTD_compressBlock_lazy_extDict_generic()
2101 const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_lazy_extDict_generic()
2118 ip += ((ip - anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */ in ZSTD_compressBlock_lazy_extDict_generic()
2129 const U32 repIndex = (U32)(curr - offset_1); in ZSTD_compressBlock_lazy_extDict_generic()
2130 const BYTE *const repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_lazy_extDict_generic()
2131 const BYTE *const repMatch = repBase + repIndex; in ZSTD_compressBlock_lazy_extDict_generic()
2132 …if (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ in ZSTD_compressBlock_lazy_extDict_generic()
2135 const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_lazy_extDict_generic()
2140 int const gain1 = (int)(matchLength * 3 - ZSTD_highbit32((U32)offset + 1) + 1); in ZSTD_compressBlock_lazy_extDict_generic()
2150 int const gain2 = (int)(ml2 * 4 - ZSTD_highbit32((U32)offset2 + 1)); /* raw approx */ in ZSTD_compressBlock_lazy_extDict_generic()
2151 int const gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 4); in ZSTD_compressBlock_lazy_extDict_generic()
2164 const U32 repIndex = (U32)(curr - offset_1); in ZSTD_compressBlock_lazy_extDict_generic()
2165 const BYTE *const repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_lazy_extDict_generic()
2166 const BYTE *const repMatch = repBase + repIndex; in ZSTD_compressBlock_lazy_extDict_generic()
2167 …if (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ in ZSTD_compressBlock_lazy_extDict_generic()
2170 const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_lazy_extDict_generic()
2175 int gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 1); in ZSTD_compressBlock_lazy_extDict_generic()
2185 int const gain2 = (int)(ml2 * 4 - ZSTD_highbit32((U32)offset2 + 1)); /* raw approx */ in ZSTD_compressBlock_lazy_extDict_generic()
2186 int const gain1 = (int)(matchLength * 4 - ZSTD_highbit32((U32)offset + 1) + 7); in ZSTD_compressBlock_lazy_extDict_generic()
2198 U32 const matchIndex = (U32)((start - base) - (offset - ZSTD_REP_MOVE)); in ZSTD_compressBlock_lazy_extDict_generic()
2199 const BYTE *match = (matchIndex < dictLimit) ? dictBase + matchIndex : base + matchIndex; in ZSTD_compressBlock_lazy_extDict_generic()
2200 const BYTE *const mStart = (matchIndex < dictLimit) ? dictStart : prefixStart; in ZSTD_compressBlock_lazy_extDict_generic()
2201 while ((start > anchor) && (match > mStart) && (start[-1] == match[-1])) { in ZSTD_compressBlock_lazy_extDict_generic()
2202 start--; in ZSTD_compressBlock_lazy_extDict_generic()
2203 match--; in ZSTD_compressBlock_lazy_extDict_generic()
2207 offset_1 = (U32)(offset - ZSTD_REP_MOVE); in ZSTD_compressBlock_lazy_extDict_generic()
2212 size_t const litLength = start - anchor; in ZSTD_compressBlock_lazy_extDict_generic()
2213 ZSTD_storeSeq(seqStorePtr, litLength, anchor, (U32)offset, matchLength - MINMATCH); in ZSTD_compressBlock_lazy_extDict_generic()
2219 const U32 repIndex = (U32)((ip - base) - offset_2); in ZSTD_compressBlock_lazy_extDict_generic()
2220 const BYTE *const repBase = repIndex < dictLimit ? dictBase : base; in ZSTD_compressBlock_lazy_extDict_generic()
2221 const BYTE *const repMatch = repBase + repIndex; in ZSTD_compressBlock_lazy_extDict_generic()
2222 …if (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ in ZSTD_compressBlock_lazy_extDict_generic()
2225 const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend; in ZSTD_compressBlock_lazy_extDict_generic()
2231 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, matchLength - MINMATCH); in ZSTD_compressBlock_lazy_extDict_generic()
2241 ctx->repToConfirm[0] = offset_1; in ZSTD_compressBlock_lazy_extDict_generic()
2242 ctx->repToConfirm[1] = offset_2; in ZSTD_compressBlock_lazy_extDict_generic()
2246 size_t const lastLLSize = iend - anchor; in ZSTD_compressBlock_lazy_extDict_generic()
2247 memcpy(seqStorePtr->lit, anchor, lastLLSize); in ZSTD_compressBlock_lazy_extDict_generic()
2248 seqStorePtr->lit += lastLLSize; in ZSTD_compressBlock_lazy_extDict_generic()
2335 … const blockCompressor = ZSTD_selectBlockCompressor(zc->params.cParams.strategy, zc->lowLimit < zc… in ZSTD_compressBlock_internal()
2336 const BYTE *const base = zc->base; in ZSTD_compressBlock_internal()
2337 const BYTE *const istart = (const BYTE *)src; in ZSTD_compressBlock_internal()
2338 const U32 curr = (U32)(istart - base); in ZSTD_compressBlock_internal()
2341 ZSTD_resetSeqStore(&(zc->seqStore)); in ZSTD_compressBlock_internal()
2342 if (curr > zc->nextToUpdate + 384) in ZSTD_compressBlock_internal()
2343 …zc->nextToUpdate = curr - MIN(192, (U32)(curr - zc->nextToUpdate - 384)); /* update tree not updat… in ZSTD_compressBlock_internal()
2357 size_t blockSize = cctx->blockSize; in ZSTD_compress_generic()
2359 const BYTE *ip = (const BYTE *)src; in ZSTD_compress_generic()
2360 BYTE *const ostart = (BYTE *)dst; in ZSTD_compress_generic()
2361 BYTE *op = ostart; in ZSTD_compress_generic()
2362 U32 const maxDist = 1 << cctx->params.cParams.windowLog; in ZSTD_compress_generic()
2364 if (cctx->params.fParams.checksumFlag && srcSize) in ZSTD_compress_generic()
2365 xxh64_update(&cctx->xxhState, src, srcSize); in ZSTD_compress_generic()
2377 if (cctx->lowLimit > (3U << 29)) { in ZSTD_compress_generic()
2378 …U32 const cycleMask = (1 << ZSTD_cycleLog(cctx->params.cParams.hashLog, cctx->params.cParams.strat… in ZSTD_compress_generic()
2379 U32 const curr = (U32)(ip - cctx->base); in ZSTD_compress_generic()
2380 U32 const newCurr = (curr & cycleMask) + (1 << cctx->params.cParams.windowLog); in ZSTD_compress_generic()
2381 U32 const correction = curr - newCurr; in ZSTD_compress_generic()
2384 cctx->base += correction; in ZSTD_compress_generic()
2385 cctx->dictBase += correction; in ZSTD_compress_generic()
2386 cctx->lowLimit -= correction; in ZSTD_compress_generic()
2387 cctx->dictLimit -= correction; in ZSTD_compress_generic()
2388 if (cctx->nextToUpdate < correction) in ZSTD_compress_generic()
2389 cctx->nextToUpdate = 0; in ZSTD_compress_generic()
2391 cctx->nextToUpdate -= correction; in ZSTD_compress_generic()
2394 if ((U32)(ip + blockSize - cctx->base) > cctx->loadedDictEnd + maxDist) { in ZSTD_compress_generic()
2396 U32 const newLowLimit = (U32)(ip + blockSize - cctx->base) - maxDist; in ZSTD_compress_generic()
2397 if (cctx->lowLimit < newLowLimit) in ZSTD_compress_generic()
2398 cctx->lowLimit = newLowLimit; in ZSTD_compress_generic()
2399 if (cctx->dictLimit < cctx->lowLimit) in ZSTD_compress_generic()
2400 cctx->dictLimit = cctx->lowLimit; in ZSTD_compress_generic()
2403 …cSize = ZSTD_compressBlock_internal(cctx, op + ZSTD_blockHeaderSize, dstCapacity - ZSTD_blockHeade… in ZSTD_compress_generic()
2411 ZSTD_writeLE32(op, cBlockHeader24); /* no pb, 4th byte will be overwritten */ in ZSTD_compress_generic()
2420 remaining -= blockSize; in ZSTD_compress_generic()
2421 dstCapacity -= cSize; in ZSTD_compress_generic()
2427 cctx->stage = ZSTDcs_ending; in ZSTD_compress_generic()
2428 return op - ostart; in ZSTD_compress_generic()
2433 BYTE *const op = (BYTE *)dst; in ZSTD_writeFrameHeader()
2434 U32 const dictIDSizeCode = (dictID > 0) + (dictID >= 256) + (dictID >= 65536); /* 0-3 */ in ZSTD_writeFrameHeader()
2438 BYTE const windowLogByte = (BYTE)((params.cParams.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN) << 3); in ZSTD_writeFrameHeader()
2440 …dSrcSize >= 256) + (pledgedSrcSize >= 65536 + 256) + (pledgedSrcSize >= 0xFFFFFFFFU) : 0; /* 0-3 */ in ZSTD_writeFrameHeader()
2441 …BYTE const frameHeaderDecriptionByte = (BYTE)(dictIDSizeCode + (checksumFlag << 2) + (singleSegmen… in ZSTD_writeFrameHeader()
2449 pos = 5; in ZSTD_writeFrameHeader()
2456 op[pos] = (BYTE)(dictID); in ZSTD_writeFrameHeader()
2472 op[pos++] = (BYTE)(pledgedSrcSize); in ZSTD_writeFrameHeader()
2475 ZSTD_writeLE16(op + pos, (U16)(pledgedSrcSize - 256)); in ZSTD_writeFrameHeader()
2492 const BYTE *const ip = (const BYTE *)src; in ZSTD_compressContinue_internal()
2495 if (cctx->stage == ZSTDcs_created) in ZSTD_compressContinue_internal()
2498 if (frame && (cctx->stage == ZSTDcs_init)) { in ZSTD_compressContinue_internal()
2499 …fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->params, cctx->frameContentSize, cctx->dictI… in ZSTD_compressContinue_internal()
2502 dstCapacity -= fhSize; in ZSTD_compressContinue_internal()
2504 cctx->stage = ZSTDcs_ongoing; in ZSTD_compressContinue_internal()
2508 if (src != cctx->nextSrc) { in ZSTD_compressContinue_internal()
2510 ptrdiff_t const delta = cctx->nextSrc - ip; in ZSTD_compressContinue_internal()
2511 cctx->lowLimit = cctx->dictLimit; in ZSTD_compressContinue_internal()
2512 cctx->dictLimit = (U32)(cctx->nextSrc - cctx->base); in ZSTD_compressContinue_internal()
2513 cctx->dictBase = cctx->base; in ZSTD_compressContinue_internal()
2514 cctx->base -= delta; in ZSTD_compressContinue_internal()
2515 cctx->nextToUpdate = cctx->dictLimit; in ZSTD_compressContinue_internal()
2516 if (cctx->dictLimit - cctx->lowLimit < HASH_READ_SIZE) in ZSTD_compressContinue_internal()
2517 cctx->lowLimit = cctx->dictLimit; /* too small extDict */ in ZSTD_compressContinue_internal()
2521 if ((ip + srcSize > cctx->dictBase + cctx->lowLimit) & (ip < cctx->dictBase + cctx->dictLimit)) { in ZSTD_compressContinue_internal()
2522 ptrdiff_t const highInputIdx = (ip + srcSize) - cctx->dictBase; in ZSTD_compressContinue_internal()
2523 …U32 const lowLimitMax = (highInputIdx > (ptrdiff_t)cctx->dictLimit) ? cctx->dictLimit : (U32)highI… in ZSTD_compressContinue_internal()
2524 cctx->lowLimit = lowLimitMax; in ZSTD_compressContinue_internal()
2527 cctx->nextSrc = ip + srcSize; in ZSTD_compressContinue_internal()
2544 size_t ZSTD_getBlockSizeMax(ZSTD_CCtx *cctx) { return MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, 1 << cctx->pa… in ZSTD_getBlockSizeMax()
2559 const BYTE *const ip = (const BYTE *)src; in ZSTD_loadDictionaryContent()
2560 const BYTE *const iend = ip + srcSize; in ZSTD_loadDictionaryContent()
2563 zc->lowLimit = zc->dictLimit; in ZSTD_loadDictionaryContent()
2564 zc->dictLimit = (U32)(zc->nextSrc - zc->base); in ZSTD_loadDictionaryContent()
2565 zc->dictBase = zc->base; in ZSTD_loadDictionaryContent()
2566 zc->base += ip - zc->nextSrc; in ZSTD_loadDictionaryContent()
2567 zc->nextToUpdate = zc->dictLimit; in ZSTD_loadDictionaryContent()
2568 zc->loadedDictEnd = zc->forceWindow ? 0 : (U32)(iend - zc->base); in ZSTD_loadDictionaryContent()
2570 zc->nextSrc = iend; in ZSTD_loadDictionaryContent()
2574 switch (zc->params.cParams.strategy) { in ZSTD_loadDictionaryContent()
2575 case ZSTD_fast: ZSTD_fillHashTable(zc, iend, zc->params.cParams.searchLength); break; in ZSTD_loadDictionaryContent()
2577 case ZSTD_dfast: ZSTD_fillDoubleHashTable(zc, iend, zc->params.cParams.searchLength); break; in ZSTD_loadDictionaryContent()
2583 ZSTD_insertAndFindFirstIndex(zc, iend - HASH_READ_SIZE, zc->params.cParams.searchLength); in ZSTD_loadDictionaryContent()
2590 …ZSTD_updateTree(zc, iend - HASH_READ_SIZE, iend, 1 << zc->params.cParams.searchLog, zc->params.cPa… in ZSTD_loadDictionaryContent()
2597 zc->nextToUpdate = (U32)(iend - zc->base); in ZSTD_loadDictionaryContent()
2619 * https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#dictionary-format
2628 const BYTE *dictPtr = (const BYTE *)dict; in ZSTD_loadZstdDictionary()
2629 const BYTE *const dictEnd = dictPtr + dictSize; in ZSTD_loadZstdDictionary()
2634 cctx->dictID = cctx->params.fParams.noDictIDFlag ? 0 : ZSTD_readLE32(dictPtr); in ZSTD_loadZstdDictionary()
2638 …fHeaderSize = HUF_readCTable_wksp(cctx->hufTable, 255, dictPtr, dictEnd - dictPtr, cctx->tmpCounte… in ZSTD_loadZstdDictionary()
2646 …derSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
2652 …CK_E(FSE_buildCTable_wksp(cctx->offcodeCTable, offcodeNCount, offcodeMaxValue, offcodeLog, cctx->t… in ZSTD_loadZstdDictionary()
2660 …E_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
2665 /* Every match length code must have non-zero probability */ in ZSTD_loadZstdDictionary()
2668 …_buildCTable_wksp(cctx->matchlengthCTable, matchlengthNCount, matchlengthMaxValue, matchlengthLog,… in ZSTD_loadZstdDictionary()
2676 …e = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
2681 /* Every literal length code must have non-zero probability */ in ZSTD_loadZstdDictionary()
2683 …(FSE_buildCTable_wksp(cctx->litlengthCTable, litlengthNCount, litlengthMaxValue, litlengthLog, cct… in ZSTD_loadZstdDictionary()
2690 cctx->rep[0] = ZSTD_readLE32(dictPtr + 0); in ZSTD_loadZstdDictionary()
2691 cctx->rep[1] = ZSTD_readLE32(dictPtr + 4); in ZSTD_loadZstdDictionary()
2692 cctx->rep[2] = ZSTD_readLE32(dictPtr + 8); in ZSTD_loadZstdDictionary()
2696 size_t const dictContentSize = (size_t)(dictEnd - dictPtr); in ZSTD_loadZstdDictionary()
2698 if (dictContentSize <= ((U32)-1) - 128 KB) { in ZSTD_loadZstdDictionary()
2708 if (cctx->rep[u] == 0) in ZSTD_loadZstdDictionary()
2710 if (cctx->rep[u] > dictContentSize) in ZSTD_loadZstdDictionary()
2715 cctx->flagStaticTables = 1; in ZSTD_loadZstdDictionary()
2716 cctx->flagStaticHufTable = HUF_repeat_valid; in ZSTD_loadZstdDictionary()
2729 if ((ZSTD_readLE32(dict) != ZSTD_DICT_MAGIC) || (cctx->forceRawDict)) in ZSTD_compress_insertDictionary()
2767 BYTE *const ostart = (BYTE *)dst; in ZSTD_writeEpilogue()
2768 BYTE *op = ostart; in ZSTD_writeEpilogue()
2771 if (cctx->stage == ZSTDcs_created) in ZSTD_writeEpilogue()
2775 if (cctx->stage == ZSTDcs_init) { in ZSTD_writeEpilogue()
2776 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->params, 0, 0); in ZSTD_writeEpilogue()
2779 dstCapacity -= fhSize; in ZSTD_writeEpilogue()
2781 cctx->stage = ZSTDcs_ongoing; in ZSTD_writeEpilogue()
2784 if (cctx->stage != ZSTDcs_ending) { in ZSTD_writeEpilogue()
2791 dstCapacity -= ZSTD_blockHeaderSize; in ZSTD_writeEpilogue()
2794 if (cctx->params.fParams.checksumFlag) { in ZSTD_writeEpilogue()
2795 U32 const checksum = (U32)xxh64_digest(&cctx->xxhState); in ZSTD_writeEpilogue()
2802 cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ in ZSTD_writeEpilogue()
2803 return op - ostart; in ZSTD_writeEpilogue()
2812 endResult = ZSTD_writeEpilogue(cctx, (char *)dst + cSize, dstCapacity - cSize); in ZSTD_compressEnd()
2863 cdict->dictBuffer = NULL; in ZSTD_createCDict_advanced()
2864 cdict->dictContent = dictBuffer; in ZSTD_createCDict_advanced()
2873 cdict->dictBuffer = internalBuffer; in ZSTD_createCDict_advanced()
2874 cdict->dictContent = internalBuffer; in ZSTD_createCDict_advanced()
2878 …size_t const errorCode = ZSTD_compressBegin_advanced(cctx, cdict->dictContent, dictSize, params, 0… in ZSTD_createCDict_advanced()
2880 ZSTD_free(cdict->dictBuffer, customMem); in ZSTD_createCDict_advanced()
2887 cdict->refContext = cctx; in ZSTD_createCDict_advanced()
2888 cdict->dictContentSize = dictSize; in ZSTD_createCDict_advanced()
2904 ZSTD_customMem const cMem = cdict->refContext->customMem; in ZSTD_freeCDict()
2905 ZSTD_freeCCtx(cdict->refContext); in ZSTD_freeCDict()
2906 ZSTD_free(cdict->dictBuffer, cMem); in ZSTD_freeCDict()
2912 …D_getParamsFromCDict(const ZSTD_CDict *cdict) { return ZSTD_getParamsFromCCtx(cdict->refContext); } in ZSTD_getParamsFromCDict()
2916 if (cdict->dictContentSize) in ZSTD_compressBegin_usingCDict()
2917 CHECK_F(ZSTD_copyCCtx(cctx, cdict->refContext, pledgedSrcSize)) in ZSTD_compressBegin_usingCDict()
2919 ZSTD_parameters params = cdict->refContext->params; in ZSTD_compressBegin_usingCDict()
2934 if (cdict->refContext->params.fParams.contentSizeFlag == 1) { in ZSTD_compress_usingCDict()
2935 cctx->params.fParams.contentSizeFlag = 1; in ZSTD_compress_usingCDict()
2936 cctx->frameContentSize = srcSize; in ZSTD_compress_usingCDict()
2938 cctx->params.fParams.contentSizeFlag = 0; in ZSTD_compress_usingCDict()
2993 memcpy(&zcs->customMem, &customMem, sizeof(ZSTD_customMem)); in ZSTD_createCStream_advanced()
2994 zcs->cctx = ZSTD_createCCtx_advanced(customMem); in ZSTD_createCStream_advanced()
2995 if (zcs->cctx == NULL) { in ZSTD_createCStream_advanced()
3007 ZSTD_customMem const cMem = zcs->customMem; in ZSTD_freeCStream()
3008 ZSTD_freeCCtx(zcs->cctx); in ZSTD_freeCStream()
3009 zcs->cctx = NULL; in ZSTD_freeCStream()
3010 ZSTD_freeCDict(zcs->cdictLocal); in ZSTD_freeCStream()
3011 zcs->cdictLocal = NULL; in ZSTD_freeCStream()
3012 ZSTD_free(zcs->inBuff, cMem); in ZSTD_freeCStream()
3013 zcs->inBuff = NULL; in ZSTD_freeCStream()
3014 ZSTD_free(zcs->outBuff, cMem); in ZSTD_freeCStream()
3015 zcs->outBuff = NULL; in ZSTD_freeCStream()
3024 …urn ZSTD_compressBound(ZSTD_BLOCKSIZE_ABSOLUTEMAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */; } in ZSTD_CStreamOutSize()
3028 if (zcs->inBuffSize == 0) in ZSTD_resetCStream_internal()
3031 if (zcs->cdict) in ZSTD_resetCStream_internal()
3032 CHECK_F(ZSTD_compressBegin_usingCDict(zcs->cctx, zcs->cdict, pledgedSrcSize)) in ZSTD_resetCStream_internal()
3034 CHECK_F(ZSTD_compressBegin_advanced(zcs->cctx, NULL, 0, zcs->params, pledgedSrcSize)); in ZSTD_resetCStream_internal()
3036 zcs->inToCompress = 0; in ZSTD_resetCStream_internal()
3037 zcs->inBuffPos = 0; in ZSTD_resetCStream_internal()
3038 zcs->inBuffTarget = zcs->blockSize; in ZSTD_resetCStream_internal()
3039 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; in ZSTD_resetCStream_internal()
3040 zcs->stage = zcss_load; in ZSTD_resetCStream_internal()
3041 zcs->frameEnded = 0; in ZSTD_resetCStream_internal()
3042 zcs->pledgedSrcSize = pledgedSrcSize; in ZSTD_resetCStream_internal()
3043 zcs->inputProcessed = 0; in ZSTD_resetCStream_internal()
3050 zcs->params.fParams.contentSizeFlag = (pledgedSrcSize > 0); in ZSTD_resetCStream()
3060 if (zcs->inBuffSize < neededInBuffSize) { in ZSTD_initCStream_advanced()
3061 zcs->inBuffSize = neededInBuffSize; in ZSTD_initCStream_advanced()
3062 ZSTD_free(zcs->inBuff, zcs->customMem); in ZSTD_initCStream_advanced()
3063 zcs->inBuff = (char *)ZSTD_malloc(neededInBuffSize, zcs->customMem); in ZSTD_initCStream_advanced()
3064 if (zcs->inBuff == NULL) in ZSTD_initCStream_advanced()
3067 zcs->blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, neededInBuffSize); in ZSTD_initCStream_advanced()
3069 if (zcs->outBuffSize < ZSTD_compressBound(zcs->blockSize) + 1) { in ZSTD_initCStream_advanced()
3070 zcs->outBuffSize = ZSTD_compressBound(zcs->blockSize) + 1; in ZSTD_initCStream_advanced()
3071 ZSTD_free(zcs->outBuff, zcs->customMem); in ZSTD_initCStream_advanced()
3072 zcs->outBuff = (char *)ZSTD_malloc(zcs->outBuffSize, zcs->customMem); in ZSTD_initCStream_advanced()
3073 if (zcs->outBuff == NULL) in ZSTD_initCStream_advanced()
3078 ZSTD_freeCDict(zcs->cdictLocal); in ZSTD_initCStream_advanced()
3079 zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize, 0, params, zcs->customMem); in ZSTD_initCStream_advanced()
3080 if (zcs->cdictLocal == NULL) in ZSTD_initCStream_advanced()
3082 zcs->cdict = zcs->cdictLocal; in ZSTD_initCStream_advanced()
3084 zcs->cdict = NULL; in ZSTD_initCStream_advanced()
3086 zcs->checksum = params.fParams.checksumFlag > 0; in ZSTD_initCStream_advanced()
3087 zcs->params = params; in ZSTD_initCStream_advanced()
3110 zcs->cdict = cdict; in ZSTD_initCStream_usingCDict()
3140 switch (zcs->stage) { in ZSTD_compressStream_generic()
3147 size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos; in ZSTD_compressStream_generic()
3148 size_t const loaded = ZSTD_limitCopy(zcs->inBuff + zcs->inBuffPos, toLoad, ip, iend - ip); in ZSTD_compressStream_generic()
3149 zcs->inBuffPos += loaded; in ZSTD_compressStream_generic()
3151 if ((zcs->inBuffPos == zcs->inToCompress) || (!flush && (toLoad != loaded))) { in ZSTD_compressStream_generic()
3160 size_t const iSize = zcs->inBuffPos - zcs->inToCompress; in ZSTD_compressStream_generic()
3161 size_t oSize = oend - op; in ZSTD_compressStream_generic()
3165 cDst = zcs->outBuff, oSize = zcs->outBuffSize; in ZSTD_compressStream_generic()
3166 …cSize = (flush == zsf_end) ? ZSTD_compressEnd(zcs->cctx, cDst, oSize, zcs->inBuff + zcs->inToCompr… in ZSTD_compressStream_generic()
3167 : ZSTD_compressContinue(zcs->cctx, cDst, oSize, zcs->inBuff + zcs->inToCompress, iSize); in ZSTD_compressStream_generic()
3171 zcs->frameEnded = 1; in ZSTD_compressStream_generic()
3173 zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize; in ZSTD_compressStream_generic()
3174 if (zcs->inBuffTarget > zcs->inBuffSize) in ZSTD_compressStream_generic()
3175 zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize; /* note : inBuffSize >= blockSize */ in ZSTD_compressStream_generic()
3176 zcs->inToCompress = zcs->inBuffPos; in ZSTD_compressStream_generic()
3181 zcs->outBuffContentSize = cSize; in ZSTD_compressStream_generic()
3182 zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
3183 zcs->stage = zcss_flush; /* pass-through to flush stage */ in ZSTD_compressStream_generic()
3188 size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; in ZSTD_compressStream_generic()
3189 …size_t const flushed = ZSTD_limitCopy(op, oend - op, zcs->outBuff + zcs->outBuffFlushedSize, toFlu… in ZSTD_compressStream_generic()
3191 zcs->outBuffFlushedSize += flushed; in ZSTD_compressStream_generic()
3196 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; in ZSTD_compressStream_generic()
3197 zcs->stage = zcss_load; in ZSTD_compressStream_generic()
3210 *srcSizePtr = ip - istart; in ZSTD_compressStream_generic()
3211 *dstCapacityPtr = op - ostart; in ZSTD_compressStream_generic()
3212 zcs->inputProcessed += *srcSizePtr; in ZSTD_compressStream_generic()
3213 if (zcs->frameEnded) in ZSTD_compressStream_generic()
3216 size_t hintInSize = zcs->inBuffTarget - zcs->inBuffPos; in ZSTD_compressStream_generic()
3218 hintInSize = zcs->blockSize; in ZSTD_compressStream_generic()
3225 size_t sizeRead = input->size - input->pos; in ZSTD_compressStream()
3226 size_t sizeWritten = output->size - output->pos; in ZSTD_compressStream()
3228 …mpressStream_generic(zcs, (char *)(output->dst) + output->pos, &sizeWritten, (const char *)(input-… in ZSTD_compressStream()
3229 input->pos += sizeRead; in ZSTD_compressStream()
3230 output->pos += sizeWritten; in ZSTD_compressStream()
3241 size_t sizeWritten = output->size - output->pos; in ZSTD_flushStream()
3242 …size_t const result = ZSTD_compressStream_generic(zcs, (char *)(output->dst) + output->pos, &sizeW… in ZSTD_flushStream()
3245 output->pos += sizeWritten; in ZSTD_flushStream()
3248 return zcs->outBuffContentSize - zcs->outBuffFlushedSize; /* remaining to flush */ in ZSTD_flushStream()
3253 BYTE *const ostart = (BYTE *)(output->dst) + output->pos; in ZSTD_endStream()
3254 BYTE *const oend = (BYTE *)(output->dst) + output->size; in ZSTD_endStream()
3255 BYTE *op = ostart; in ZSTD_endStream()
3257 if ((zcs->pledgedSrcSize) && (zcs->inputProcessed != zcs->pledgedSrcSize)) in ZSTD_endStream()
3260 if (zcs->stage != zcss_final) { in ZSTD_endStream()
3263 size_t sizeWritten = output->size - output->pos; in ZSTD_endStream()
3266 size_t const remainingToFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; in ZSTD_endStream()
3269 output->pos += sizeWritten; in ZSTD_endStream()
3270 return remainingToFlush + ZSTD_BLOCKHEADERSIZE /* final empty block */ + (zcs->checksum * 4); in ZSTD_endStream()
3273 zcs->stage = zcss_final; in ZSTD_endStream()
3274 …zcs->outBuffContentSize = !notEnded ? 0 : ZSTD_compressEnd(zcs->cctx, zcs->outBuff, zcs->outBuffSi… in ZSTD_endStream()
3280 size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; in ZSTD_endStream()
3281 …size_t const flushed = ZSTD_limitCopy(op, oend - op, zcs->outBuff + zcs->outBuffFlushedSize, toFlu… in ZSTD_endStream()
3283 zcs->outBuffFlushedSize += flushed; in ZSTD_endStream()
3284 output->pos += op - ostart; in ZSTD_endStream()
3286 zcs->stage = zcss_init; /* end reached */ in ZSTD_endStream()
3287 return toFlush - flushed; in ZSTD_endStream()
3291 /*-===== Pre-defined compression levels =====-*/
3301 {18, 12, 12, 1, 7, 16, ZSTD_fast}, /* level 0 - never used */
3304 {20, 16, 17, 1, 5, 16, ZSTD_dfast}, /* level 3.*/
3305 {20, 18, 18, 1, 5, 16, ZSTD_dfast}, /* level 4.*/
3306 {20, 15, 18, 3, 5, 16, ZSTD_greedy}, /* level 5 */
3307 {21, 16, 19, 2, 5, 16, ZSTD_lazy}, /* level 6 */
3308 {21, 17, 20, 3, 5, 16, ZSTD_lazy}, /* level 7 */
3309 {21, 18, 20, 3, 5, 16, ZSTD_lazy2}, /* level 8 */
3310 {21, 20, 20, 3, 5, 16, ZSTD_lazy2}, /* level 9 */
3311 {21, 19, 21, 4, 5, 16, ZSTD_lazy2}, /* level 10 */
3312 {22, 20, 22, 4, 5, 16, ZSTD_lazy2}, /* level 11 */
3313 {22, 20, 22, 5, 5, 16, ZSTD_lazy2}, /* level 12 */
3314 {22, 21, 22, 5, 5, 16, ZSTD_lazy2}, /* level 13 */
3315 {22, 21, 22, 6, 5, 16, ZSTD_lazy2}, /* level 14 */
3316 {22, 21, 21, 5, 5, 16, ZSTD_btlazy2}, /* level 15 */
3317 {23, 22, 22, 5, 5, 16, ZSTD_btlazy2}, /* level 16 */
3318 {23, 21, 22, 4, 5, 24, ZSTD_btopt}, /* level 17 */
3319 {23, 23, 22, 6, 5, 32, ZSTD_btopt}, /* level 18 */
3328 {0, 0, 0, 0, 0, 0, ZSTD_fast}, /* level 0 - not used */
3330 {18, 14, 13, 1, 5, 8, ZSTD_dfast}, /* level 2 */
3331 {18, 16, 15, 1, 5, 8, ZSTD_dfast}, /* level 3 */
3332 {18, 15, 17, 1, 5, 8, ZSTD_greedy}, /* level 4.*/
3333 {18, 16, 17, 4, 5, 8, ZSTD_greedy}, /* level 5.*/
3334 {18, 16, 17, 3, 5, 8, ZSTD_lazy}, /* level 6.*/
3337 {18, 17, 17, 5, 4, 8, ZSTD_lazy2}, /* level 9 */
3355 {17, 12, 12, 1, 7, 8, ZSTD_fast}, /* level 0 - not used */
3357 {17, 13, 16, 1, 5, 8, ZSTD_fast}, /* level 2 */
3358 {17, 16, 16, 2, 5, 8, ZSTD_dfast}, /* level 3 */
3360 {17, 15, 17, 4, 4, 8, ZSTD_greedy}, /* level 5 */
3364 {17, 17, 17, 5, 4, 8, ZSTD_lazy2}, /* level 9 */
3382 {14, 12, 12, 1, 7, 6, ZSTD_fast}, /* level 0 - not used */
3387 {14, 14, 14, 3, 4, 6, ZSTD_lazy}, /* level 5.*/
3389 {14, 14, 14, 5, 4, 6, ZSTD_lazy2}, /* level 7 */
3415 U64 const rSize = srcSize + dictSize ? srcSize + dictSize + addedSize : (U64)-1; in ZSTD_getCParams()
3422 if (ZSTD_32bits()) { /* auto-correction, for 32-bits mode */ in ZSTD_getCParams()