Lines Matching refs:p
43 void LzmaEncProps_Init(CLzmaEncProps *p) in LzmaEncProps_Init() argument
45 p->level = 5; in LzmaEncProps_Init()
46 p->dictSize = p->mc = 0; in LzmaEncProps_Init()
47 p->reduceSize = (UInt64)(Int64)-1; in LzmaEncProps_Init()
48 p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1; in LzmaEncProps_Init()
49 p->writeEndMark = 0; in LzmaEncProps_Init()
52 void LzmaEncProps_Normalize(CLzmaEncProps *p) in LzmaEncProps_Normalize() argument
54 int level = p->level; in LzmaEncProps_Normalize()
56 p->level = level; in LzmaEncProps_Normalize()
58 …if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level <= 7 ? (1 << 25… in LzmaEncProps_Normalize()
59 if (p->dictSize > p->reduceSize) in LzmaEncProps_Normalize()
62 UInt32 reduceSize = (UInt32)p->reduceSize; in LzmaEncProps_Normalize()
65 if (reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; } in LzmaEncProps_Normalize()
66 if (reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; } in LzmaEncProps_Normalize()
70 if (p->lc < 0) p->lc = 3; in LzmaEncProps_Normalize()
71 if (p->lp < 0) p->lp = 0; in LzmaEncProps_Normalize()
72 if (p->pb < 0) p->pb = 2; in LzmaEncProps_Normalize()
74 if (p->algo < 0) p->algo = (level < 5 ? 0 : 1); in LzmaEncProps_Normalize()
75 if (p->fb < 0) p->fb = (level < 7 ? 32 : 64); in LzmaEncProps_Normalize()
76 if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1); in LzmaEncProps_Normalize()
77 if (p->numHashBytes < 0) p->numHashBytes = 4; in LzmaEncProps_Normalize()
78 if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1); in LzmaEncProps_Normalize()
80 if (p->numThreads < 0) in LzmaEncProps_Normalize()
81 p->numThreads = in LzmaEncProps_Normalize()
83 ((p->btMode && p->algo) ? 2 : 1); in LzmaEncProps_Normalize()
154 res = p->g_FastPos[pos >> zz] + (zz * 2); }
162 #define GetPosSlot1(pos) p->g_FastPos[pos]
164 #define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDista…
249 #define GET_PRICE_LEN(p, posState, len) \ argument
250 ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
399 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SaveState() local
400 CSaveState *dest = &p->saveState; in LzmaEnc_SaveState()
402 dest->state = p->state; in LzmaEnc_SaveState()
404 dest->lenProbs = p->lenProbs; in LzmaEnc_SaveState()
405 dest->repLenProbs = p->repLenProbs; in LzmaEnc_SaveState()
407 COPY_ARR(dest, p, reps); in LzmaEnc_SaveState()
409 COPY_ARR(dest, p, posAlignEncoder); in LzmaEnc_SaveState()
410 COPY_ARR(dest, p, isRep); in LzmaEnc_SaveState()
411 COPY_ARR(dest, p, isRepG0); in LzmaEnc_SaveState()
412 COPY_ARR(dest, p, isRepG1); in LzmaEnc_SaveState()
413 COPY_ARR(dest, p, isRepG2); in LzmaEnc_SaveState()
414 COPY_ARR(dest, p, isMatch); in LzmaEnc_SaveState()
415 COPY_ARR(dest, p, isRep0Long); in LzmaEnc_SaveState()
416 COPY_ARR(dest, p, posSlotEncoder); in LzmaEnc_SaveState()
417 COPY_ARR(dest, p, posEncoders); in LzmaEnc_SaveState()
419 memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << p->lclp) * sizeof(CLzmaProb)); in LzmaEnc_SaveState()
426 const CSaveState *p = &dest->saveState; in LzmaEnc_RestoreState() local
428 dest->state = p->state; in LzmaEnc_RestoreState()
430 dest->lenProbs = p->lenProbs; in LzmaEnc_RestoreState()
431 dest->repLenProbs = p->repLenProbs; in LzmaEnc_RestoreState()
433 COPY_ARR(dest, p, reps); in LzmaEnc_RestoreState()
435 COPY_ARR(dest, p, posAlignEncoder); in LzmaEnc_RestoreState()
436 COPY_ARR(dest, p, isRep); in LzmaEnc_RestoreState()
437 COPY_ARR(dest, p, isRepG0); in LzmaEnc_RestoreState()
438 COPY_ARR(dest, p, isRepG1); in LzmaEnc_RestoreState()
439 COPY_ARR(dest, p, isRepG2); in LzmaEnc_RestoreState()
440 COPY_ARR(dest, p, isMatch); in LzmaEnc_RestoreState()
441 COPY_ARR(dest, p, isRep0Long); in LzmaEnc_RestoreState()
442 COPY_ARR(dest, p, posSlotEncoder); in LzmaEnc_RestoreState()
443 COPY_ARR(dest, p, posEncoders); in LzmaEnc_RestoreState()
445 memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << dest->lclp) * sizeof(CLzmaProb)); in LzmaEnc_RestoreState()
452 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SetProps() local
463 p->dictSize = props.dictSize; in LzmaEnc_SetProps()
470 p->numFastBytes = fb; in LzmaEnc_SetProps()
472 p->lc = props.lc; in LzmaEnc_SetProps()
473 p->lp = props.lp; in LzmaEnc_SetProps()
474 p->pb = props.pb; in LzmaEnc_SetProps()
475 p->fastMode = (props.algo == 0); in LzmaEnc_SetProps()
477 p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0); in LzmaEnc_SetProps()
487 p->matchFinderBase.numHashBytes = numHashBytes; in LzmaEnc_SetProps()
490 p->matchFinderBase.cutValue = props.mc; in LzmaEnc_SetProps()
492 p->writeEndMark = props.writeEndMark; in LzmaEnc_SetProps()
502 p->multiThread = (props.numThreads > 1); in LzmaEnc_SetProps()
511 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SetDataSize() local
512 p->matchFinderBase.expectedDataSize = expectedDataSiize; in LzmaEnc_SetDataSize()
533 static void RangeEnc_Construct(CRangeEnc *p) in RangeEnc_Construct() argument
535 p->outStream = NULL; in RangeEnc_Construct()
536 p->bufBase = NULL; in RangeEnc_Construct()
539 #define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize) argument
540 #define RangeEnc_GetProcessed_sizet(p) ((size_t)(p)->processed + ((p)->buf - (p)->bufBase) + (size_… argument
544 static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc) in RangeEnc_Alloc() argument
546 if (!p->bufBase) in RangeEnc_Alloc()
548 p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE); in RangeEnc_Alloc()
549 if (!p->bufBase) in RangeEnc_Alloc()
551 p->bufLim = p->bufBase + RC_BUF_SIZE; in RangeEnc_Alloc()
556 static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc) in RangeEnc_Free() argument
558 ISzAlloc_Free(alloc, p->bufBase); in RangeEnc_Free()
559 p->bufBase = 0; in RangeEnc_Free()
562 static void RangeEnc_Init(CRangeEnc *p) in RangeEnc_Init() argument
565 p->range = 0xFFFFFFFF; in RangeEnc_Init()
566 p->cache = 0; in RangeEnc_Init()
567 p->low = 0; in RangeEnc_Init()
568 p->cacheSize = 0; in RangeEnc_Init()
570 p->buf = p->bufBase; in RangeEnc_Init()
572 p->processed = 0; in RangeEnc_Init()
573 p->res = SZ_OK; in RangeEnc_Init()
576 MY_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p) in RangeEnc_FlushStream() argument
579 if (p->res != SZ_OK) in RangeEnc_FlushStream()
581 num = p->buf - p->bufBase; in RangeEnc_FlushStream()
582 if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num)) in RangeEnc_FlushStream()
583 p->res = SZ_ERROR_WRITE; in RangeEnc_FlushStream()
584 p->processed += num; in RangeEnc_FlushStream()
585 p->buf = p->bufBase; in RangeEnc_FlushStream()
588 MY_NO_INLINE static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p) in RangeEnc_ShiftLow() argument
590 UInt32 low = (UInt32)p->low; in RangeEnc_ShiftLow()
591 unsigned high = (unsigned)(p->low >> 32); in RangeEnc_ShiftLow()
592 p->low = (UInt32)(low << 8); in RangeEnc_ShiftLow()
596 Byte *buf = p->buf; in RangeEnc_ShiftLow()
597 *buf++ = (Byte)(p->cache + high); in RangeEnc_ShiftLow()
598 p->cache = (unsigned)(low >> 24); in RangeEnc_ShiftLow()
599 p->buf = buf; in RangeEnc_ShiftLow()
600 if (buf == p->bufLim) in RangeEnc_ShiftLow()
601 RangeEnc_FlushStream(p); in RangeEnc_ShiftLow()
602 if (p->cacheSize == 0) in RangeEnc_ShiftLow()
608 Byte *buf = p->buf; in RangeEnc_ShiftLow()
610 p->buf = buf; in RangeEnc_ShiftLow()
611 if (buf == p->bufLim) in RangeEnc_ShiftLow()
612 RangeEnc_FlushStream(p); in RangeEnc_ShiftLow()
613 if (--p->cacheSize == 0) in RangeEnc_ShiftLow()
617 p->cacheSize++; in RangeEnc_ShiftLow()
620 static void RangeEnc_FlushData(CRangeEnc *p) in RangeEnc_FlushData() argument
624 RangeEnc_ShiftLow(p); in RangeEnc_FlushData()
627 #define RC_NORM(p) if (range < kTopValue) { range <<= 8; RangeEnc_ShiftLow(p); } argument
629 #define RC_BIT_PRE(p, prob) \ argument
637 #define RC_BIT(p, prob, bit) { \ argument
638 RC_BIT_PRE(p, prob) \
640 else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
642 RC_NORM(p) \
647 #define RC_BIT(p, prob, bit) { \ argument
649 RC_BIT_PRE(p, prob) \
654 (p)->low += mask; \
661 RC_NORM(p) \
669 #define RC_BIT_0_BASE(p, prob) \ argument
672 #define RC_BIT_1_BASE(p, prob) \ argument
673 range -= newBound; (p)->low += newBound; *(prob) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); \
675 #define RC_BIT_0(p, prob) \ argument
676 RC_BIT_0_BASE(p, prob) \
677 RC_NORM(p)
679 #define RC_BIT_1(p, prob) \ argument
680 RC_BIT_1_BASE(p, prob) \
681 RC_NORM(p)
683 static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob) in RangeEnc_EncodeBit_0() argument
686 range = p->range; in RangeEnc_EncodeBit_0()
687 RC_BIT_PRE(p, prob) in RangeEnc_EncodeBit_0()
688 RC_BIT_0(p, prob) in RangeEnc_EncodeBit_0()
689 p->range = range; in RangeEnc_EncodeBit_0()
692 static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym) in LitEnc_Encode() argument
694 UInt32 range = p->range; in LitEnc_Encode()
703 RC_BIT(p, prob, bit); in LitEnc_Encode()
706 p->range = range; in LitEnc_Encode()
709 static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte) in LitEnc_EncodeMatched() argument
711 UInt32 range = p->range; in LitEnc_EncodeMatched()
725 RC_BIT(p, prob, bit); in LitEnc_EncodeMatched()
728 p->range = range; in LitEnc_EncodeMatched()
759 …p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBit…
764 #define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
765 #define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
822 static void LenEnc_Init(CLenEnc *p) in LenEnc_Init() argument
826 p->low[i] = kProbInitValue; in LenEnc_Init()
828 p->high[i] = kProbInitValue; in LenEnc_Init()
831 static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState) in LenEnc_Encode() argument
834 CLzmaProb *probs = p->low; in LenEnc_Encode()
847 LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2); in LenEnc_Encode()
883 CLenPriceEnc *p, in LenPriceEnc_UpdateTables() argument
899 UInt32 *prices = p->prices[posState]; in LenPriceEnc_UpdateTables()
925 unsigned i = p->tableSize; in LenPriceEnc_UpdateTables()
930 UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2; in LenPriceEnc_UpdateTables()
962 size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]); in LenPriceEnc_UpdateTables()
964 … memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num); in LenPriceEnc_UpdateTables()
977 #define MOVE_POS(p, num) { \ argument
978 p->additionalOffset += (num); \
979 p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
982 static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes) in ReadMatchDistances() argument
986 p->additionalOffset++; in ReadMatchDistances()
987 p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in ReadMatchDistances()
988 numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches); in ReadMatchDistances()
997 printf("%2u %6u | ", p->matches[i], p->matches[i + 1]); in ReadMatchDistances()
1004 unsigned len = p->matches[(size_t)numPairs - 2]; in ReadMatchDistances()
1005 if (len != p->numFastBytes) in ReadMatchDistances()
1008 UInt32 numAvail = p->numAvail; in ReadMatchDistances()
1012 const Byte *p1 = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in ReadMatchDistances()
1014 ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[(size_t)numPairs - 1]; in ReadMatchDistances()
1026 #define MakeAs_Lit(p) { (p)->dist = MARK_LIT; (p)->extra = 0; } argument
1027 #define MakeAs_ShortRep(p) { (p)->dist = 0; (p)->extra = 0; } argument
1028 #define IsShortRep(p) ((p)->dist == 0) argument
1031 #define GetPrice_ShortRep(p, state, posState) \ argument
1032 ( GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]))
1034 #define GetPrice_Rep_0(p, state, posState) ( \ argument
1035 GET_PRICE_1(p->isMatch[state][posState]) \
1036 + GET_PRICE_1(p->isRep0Long[state][posState])) \
1037 + GET_PRICE_1(p->isRep[state]) \
1038 + GET_PRICE_0(p->isRepG0[state])
1041 static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState) in GetPrice_PureRep() argument
1044 UInt32 prob = p->isRepG0[state]; in GetPrice_PureRep()
1048 price += GET_PRICE_1(p->isRep0Long[state][posState]); in GetPrice_PureRep()
1053 prob = p->isRepG1[state]; in GetPrice_PureRep()
1059 price += GET_PRICE(p->isRepG2[state], repIndex - 2); in GetPrice_PureRep()
1066 static unsigned Backward(CLzmaEnc *p, unsigned cur) in Backward() argument
1069 p->optEnd = wr; in Backward()
1073 UInt32 dist = p->opt[cur].dist; in Backward()
1074 unsigned len = (unsigned)p->opt[cur].len; in Backward()
1075 unsigned extra = (unsigned)p->opt[cur].extra; in Backward()
1081 p->opt[wr].len = (UInt32)len; in Backward()
1086 p->opt[wr].dist = dist; in Backward()
1091 p->opt[wr].dist = 0; in Backward()
1094 p->opt[wr].dist = MARK_LIT; in Backward()
1095 p->opt[wr].len = 1; in Backward()
1101 p->backRes = dist; in Backward()
1102 p->optCur = wr; in Backward()
1107 p->opt[wr].dist = dist; in Backward()
1108 p->opt[wr].len = (UInt32)len; in Backward()
1115 (p->litProbs + (UInt32)3 * (((((pos) << 8) + (prevByte)) & p->lpMask) << p->lc))
1118 static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) in GetOptimum() argument
1132 p->optCur = p->optEnd = 0; in GetOptimum()
1134 if (p->additionalOffset == 0) in GetOptimum()
1135 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
1138 mainLen = p->longestMatchLen; in GetOptimum()
1139 numPairs = p->numPairs; in GetOptimum()
1142 numAvail = p->numAvail; in GetOptimum()
1145 p->backRes = MARK_LIT; in GetOptimum()
1151 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
1158 reps[i] = p->reps[i]; in GetOptimum()
1172 if (repLens[repMaxIndex] >= p->numFastBytes) in GetOptimum()
1175 p->backRes = (UInt32)repMaxIndex; in GetOptimum()
1177 MOVE_POS(p, len - 1) in GetOptimum()
1181 matches = p->matches; in GetOptimum()
1183 if (mainLen >= p->numFastBytes) in GetOptimum()
1185 p->backRes = matches[(size_t)numPairs - 1] + LZMA_NUM_REPS; in GetOptimum()
1186 MOVE_POS(p, mainLen - 1) in GetOptimum()
1199 p->backRes = MARK_LIT; in GetOptimum()
1203 p->opt[0].state = (CState)p->state; in GetOptimum()
1205 posState = (position & p->pbMask); in GetOptimum()
1209 p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) + in GetOptimum()
1210 (!IsLitState(p->state) ? in GetOptimum()
1211 LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1212 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1215 MakeAs_Lit(&p->opt[1]); in GetOptimum()
1217 matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]); in GetOptimum()
1218 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]); in GetOptimum()
1223 UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, p->state, posState); in GetOptimum()
1224 if (shortRepPrice < p->opt[1].price) in GetOptimum()
1226 p->opt[1].price = shortRepPrice; in GetOptimum()
1227 MakeAs_ShortRep(&p->opt[1]); in GetOptimum()
1231 p->backRes = p->opt[1].dist; in GetOptimum()
1236 p->opt[1].len = 1; in GetOptimum()
1238 p->opt[0].reps[0] = reps[0]; in GetOptimum()
1239 p->opt[0].reps[1] = reps[1]; in GetOptimum()
1240 p->opt[0].reps[2] = reps[2]; in GetOptimum()
1241 p->opt[0].reps[3] = reps[3]; in GetOptimum()
1251 price = repMatchPrice + GetPrice_PureRep(p, i, p->state, posState); in GetOptimum()
1254 UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, repLen); in GetOptimum()
1255 COptimal *opt = &p->opt[repLen]; in GetOptimum()
1274 UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]); in GetOptimum()
1286 UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len); in GetOptimum()
1290 price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)]; in GetOptimum()
1295 price += p->alignPrices[dist & kAlignMask]; in GetOptimum()
1296 price += p->posSlotPrices[lenToPosState][slot]; in GetOptimum()
1299 opt = &p->opt[len]; in GetOptimum()
1328 printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price); in GetOptimum()
1355 UInt32 price = p->opt[cur].price; in GetOptimum()
1359 UInt32 price2 = p->opt[j].price; in GetOptimum()
1370 MOVE_POS(p, delta); in GetOptimum()
1377 newLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
1379 if (newLen >= p->numFastBytes) in GetOptimum()
1381 p->numPairs = numPairs; in GetOptimum()
1382 p->longestMatchLen = newLen; in GetOptimum()
1386 curOpt = &p->opt[cur]; in GetOptimum()
1400 state = (unsigned)p->opt[prev].state; in GetOptimum()
1421 state = (unsigned)p->opt[prev].state; in GetOptimum()
1428 prevOpt = &p->opt[prev]; in GetOptimum()
1473 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
1477 posState = (position & p->pbMask); in GetOptimum()
1490 unsigned prob = p->isMatch[state][posState]; in GetOptimum()
1495 nextOpt = &p->opt[(size_t)cur + 1]; in GetOptimum()
1510 LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1511 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1522 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); in GetOptimum()
1524 numAvailFull = p->numAvail; in GetOptimum()
1545 UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState); in GetOptimum()
1558 numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); in GetOptimum()
1573 unsigned limit = p->numFastBytes + 1; in GetOptimum()
1581 unsigned posState2 = (position + 1) & p->pbMask; in GetOptimum()
1582 UInt32 price = litPrice + GetPrice_Rep_0(p, state2, posState2); in GetOptimum()
1595 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len); in GetOptimum()
1597 opt = &p->opt[offset]; in GetOptimum()
1639 price = repMatchPrice + GetPrice_PureRep(p, repIndex, state, posState); in GetOptimum()
1642 UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, len2); in GetOptimum()
1643 COptimal *opt = &p->opt[cur + len2]; in GetOptimum()
1664 unsigned limit = len2 + p->numFastBytes; in GetOptimum()
1674 unsigned posState2 = (position + len) & p->pbMask; in GetOptimum()
1675 price += GET_PRICE_LEN(&p->repLenEnc, posState, len) in GetOptimum()
1676 + GET_PRICE_0(p->isMatch[state2][posState2]) in GetOptimum()
1678 data[len], data2[len], p->ProbPrices); in GetOptimum()
1682 posState2 = (posState2 + 1) & p->pbMask; in GetOptimum()
1685 price += GetPrice_Rep_0(p, state2, posState2); in GetOptimum()
1704 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); in GetOptimum()
1706 opt = &p->opt[offset]; in GetOptimum()
1739 UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); in GetOptimum()
1759 UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len); in GetOptimum()
1765 price += p->distancesPrices[lenNorm][dist & (kNumFullDistances - 1)]; in GetOptimum()
1767 price += p->posSlotPrices[lenNorm][posSlot] + p->alignPrices[dist & kAlignMask]; in GetOptimum()
1769 opt = &p->opt[cur + len]; in GetOptimum()
1786 unsigned limit = len2 + p->numFastBytes; in GetOptimum()
1803 unsigned posState2 = (position + len) & p->pbMask; in GetOptimum()
1805 price += GET_PRICE_0(p->isMatch[state2][posState2]); in GetOptimum()
1807 data[len], data2[len], p->ProbPrices); in GetOptimum()
1812 posState2 = (posState2 + 1) & p->pbMask; in GetOptimum()
1813 price += GetPrice_Rep_0(p, state2, posState2); in GetOptimum()
1825 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); in GetOptimum()
1826 opt = &p->opt[offset]; in GetOptimum()
1853 p->opt[last].price = kInfinityPrice; in GetOptimum()
1856 return Backward(p, cur); in GetOptimum()
1865 static unsigned GetOptimumFast(CLzmaEnc *p) in GetOptimumFast() argument
1871 if (p->additionalOffset == 0) in GetOptimumFast()
1872 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimumFast()
1875 mainLen = p->longestMatchLen; in GetOptimumFast()
1876 numPairs = p->numPairs; in GetOptimumFast()
1879 numAvail = p->numAvail; in GetOptimumFast()
1880 p->backRes = MARK_LIT; in GetOptimumFast()
1886 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1892 const Byte *data2 = data - p->reps[i]; in GetOptimumFast()
1897 if (len >= p->numFastBytes) in GetOptimumFast()
1899 p->backRes = (UInt32)i; in GetOptimumFast()
1900 MOVE_POS(p, len - 1) in GetOptimumFast()
1910 if (mainLen >= p->numFastBytes) in GetOptimumFast()
1912 p->backRes = p->matches[(size_t)numPairs - 1] + LZMA_NUM_REPS; in GetOptimumFast()
1913 MOVE_POS(p, mainLen - 1) in GetOptimumFast()
1921 mainDist = p->matches[(size_t)numPairs - 1]; in GetOptimumFast()
1925 if (mainLen != p->matches[(size_t)numPairs - 4] + 1) in GetOptimumFast()
1927 dist2 = p->matches[(size_t)numPairs - 3]; in GetOptimumFast()
1943 p->backRes = (UInt32)repIndex; in GetOptimumFast()
1944 MOVE_POS(p, repLen - 1) in GetOptimumFast()
1952 unsigned len1 = ReadMatchDistances(p, &p->numPairs); in GetOptimumFast()
1953 p->longestMatchLen = len1; in GetOptimumFast()
1957 UInt32 newDist = p->matches[(size_t)p->numPairs - 1]; in GetOptimumFast()
1966 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1971 const Byte *data2 = data - p->reps[i]; in GetOptimumFast()
1984 p->backRes = mainDist + LZMA_NUM_REPS; in GetOptimumFast()
1987 MOVE_POS(p, mainLen - 2) in GetOptimumFast()
1995 static void WriteEndMarker(CLzmaEnc *p, unsigned posState) in WriteEndMarker() argument
1998 range = p->rc.range; in WriteEndMarker()
2001 CLzmaProb *prob = &p->isMatch[p->state][posState]; in WriteEndMarker()
2002 RC_BIT_PRE(&p->rc, prob) in WriteEndMarker()
2003 RC_BIT_1(&p->rc, prob) in WriteEndMarker()
2004 prob = &p->isRep[p->state]; in WriteEndMarker()
2005 RC_BIT_PRE(&p->rc, prob) in WriteEndMarker()
2006 RC_BIT_0(&p->rc, prob) in WriteEndMarker()
2008 p->state = kMatchNextStates[p->state]; in WriteEndMarker()
2010 p->rc.range = range; in WriteEndMarker()
2011 LenEnc_Encode(&p->lenProbs, &p->rc, 0, posState); in WriteEndMarker()
2012 range = p->rc.range; in WriteEndMarker()
2016 CLzmaProb *probs = p->posSlotEncoder[0]; in WriteEndMarker()
2021 RC_BIT_PRE(p, probs + m) in WriteEndMarker()
2022 RC_BIT_1(&p->rc, probs + m); in WriteEndMarker()
2033 p->rc.low += range; in WriteEndMarker()
2034 RC_NORM(&p->rc) in WriteEndMarker()
2041 CLzmaProb *probs = p->posAlignEncoder; in WriteEndMarker()
2046 RC_BIT_PRE(p, probs + m) in WriteEndMarker()
2047 RC_BIT_1(&p->rc, probs + m); in WriteEndMarker()
2052 p->rc.range = range; in WriteEndMarker()
2056 static SRes CheckErrors(CLzmaEnc *p) in CheckErrors() argument
2058 if (p->result != SZ_OK) in CheckErrors()
2059 return p->result; in CheckErrors()
2060 if (p->rc.res != SZ_OK) in CheckErrors()
2061 p->result = SZ_ERROR_WRITE; in CheckErrors()
2062 if (p->matchFinderBase.result != SZ_OK) in CheckErrors()
2063 p->result = SZ_ERROR_READ; in CheckErrors()
2064 if (p->result != SZ_OK) in CheckErrors()
2065 p->finished = True; in CheckErrors()
2066 return p->result; in CheckErrors()
2070 MY_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos) in Flush() argument
2073 p->finished = True; in Flush()
2074 if (p->writeEndMark) in Flush()
2075 WriteEndMarker(p, nowPos & p->pbMask); in Flush()
2076 RangeEnc_FlushData(&p->rc); in Flush()
2077 RangeEnc_FlushStream(&p->rc); in Flush()
2078 return CheckErrors(p); in Flush()
2082 MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p) in FillAlignPrices() argument
2085 const CProbPrice *ProbPrices = p->ProbPrices; in FillAlignPrices()
2086 const CLzmaProb *probs = p->posAlignEncoder; in FillAlignPrices()
2099 p->alignPrices[i ] = price + GET_PRICEa_0(prob); in FillAlignPrices()
2100 p->alignPrices[i + 8] = price + GET_PRICEa_1(prob); in FillAlignPrices()
2106 MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p) in FillDistancesPrices() argument
2113 const CProbPrice *ProbPrices = p->ProbPrices; in FillDistancesPrices()
2114 p->matchPriceCount = 0; in FillDistancesPrices()
2121 const CLzmaProb *probs = p->posEncoders + (size_t)base * 2; in FillDistancesPrices()
2149 unsigned distTableSize2 = (p->distTableSize + 1) >> 1; in FillDistancesPrices()
2150 UInt32 *posSlotPrices = p->posSlotPrices[lps]; in FillDistancesPrices()
2151 const CLzmaProb *probs = p->posSlotEncoder[lps]; in FillDistancesPrices()
2181 UInt32 *dp = p->distancesPrices[lps]; in FillDistancesPrices()
2201 void LzmaEnc_Construct(CLzmaEnc *p) in LzmaEnc_Construct() argument
2203 RangeEnc_Construct(&p->rc); in LzmaEnc_Construct()
2204 MatchFinder_Construct(&p->matchFinderBase); in LzmaEnc_Construct()
2207 MatchFinderMt_Construct(&p->matchFinderMt); in LzmaEnc_Construct()
2208 p->matchFinderMt.MatchFinder = &p->matchFinderBase; in LzmaEnc_Construct()
2214 LzmaEnc_SetProps(p, &props); in LzmaEnc_Construct()
2218 LzmaEnc_FastPosInit(p->g_FastPos); in LzmaEnc_Construct()
2221 LzmaEnc_InitPriceTables(p->ProbPrices); in LzmaEnc_Construct()
2222 p->litProbs = NULL; in LzmaEnc_Construct()
2223 p->saveState.litProbs = NULL; in LzmaEnc_Construct()
2229 void *p; in LzmaEnc_Create() local
2230 p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc)); in LzmaEnc_Create()
2231 if (p) in LzmaEnc_Create()
2232 LzmaEnc_Construct((CLzmaEnc *)p); in LzmaEnc_Create()
2233 return p; in LzmaEnc_Create()
2236 void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc) in LzmaEnc_FreeLits() argument
2238 ISzAlloc_Free(alloc, p->litProbs); in LzmaEnc_FreeLits()
2239 ISzAlloc_Free(alloc, p->saveState.litProbs); in LzmaEnc_FreeLits()
2240 p->litProbs = NULL; in LzmaEnc_FreeLits()
2241 p->saveState.litProbs = NULL; in LzmaEnc_FreeLits()
2244 void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig) in LzmaEnc_Destruct() argument
2247 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig); in LzmaEnc_Destruct()
2250 MatchFinder_Free(&p->matchFinderBase, allocBig); in LzmaEnc_Destruct()
2251 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Destruct()
2252 RangeEnc_Free(&p->rc, alloc); in LzmaEnc_Destruct()
2255 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig) in LzmaEnc_Destroy() argument
2257 LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig); in LzmaEnc_Destroy()
2258 ISzAlloc_Free(alloc, p); in LzmaEnc_Destroy()
2262 static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpackSize) in LzmaEnc_CodeOneBlock() argument
2265 if (p->needInit) in LzmaEnc_CodeOneBlock()
2267 p->matchFinder.Init(p->matchFinderObj); in LzmaEnc_CodeOneBlock()
2268 p->needInit = 0; in LzmaEnc_CodeOneBlock()
2271 if (p->finished) in LzmaEnc_CodeOneBlock()
2272 return p->result; in LzmaEnc_CodeOneBlock()
2273 RINOK(CheckErrors(p)); in LzmaEnc_CodeOneBlock()
2275 nowPos32 = (UInt32)p->nowPos64; in LzmaEnc_CodeOneBlock()
2278 if (p->nowPos64 == 0) in LzmaEnc_CodeOneBlock()
2282 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
2283 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
2284 ReadMatchDistances(p, &numPairs); in LzmaEnc_CodeOneBlock()
2285 RangeEnc_EncodeBit_0(&p->rc, &p->isMatch[kState_Start][0]); in LzmaEnc_CodeOneBlock()
2287 curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset); in LzmaEnc_CodeOneBlock()
2288 LitEnc_Encode(&p->rc, p->litProbs, curByte); in LzmaEnc_CodeOneBlock()
2289 p->additionalOffset--; in LzmaEnc_CodeOneBlock()
2293 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0) in LzmaEnc_CodeOneBlock()
2302 if (p->fastMode) in LzmaEnc_CodeOneBlock()
2303 len = GetOptimumFast(p); in LzmaEnc_CodeOneBlock()
2306 unsigned oci = p->optCur; in LzmaEnc_CodeOneBlock()
2307 if (p->optEnd == oci) in LzmaEnc_CodeOneBlock()
2308 len = GetOptimum(p, nowPos32); in LzmaEnc_CodeOneBlock()
2311 const COptimal *opt = &p->opt[oci]; in LzmaEnc_CodeOneBlock()
2313 p->backRes = opt->dist; in LzmaEnc_CodeOneBlock()
2314 p->optCur = oci + 1; in LzmaEnc_CodeOneBlock()
2318 posState = (unsigned)nowPos32 & p->pbMask; in LzmaEnc_CodeOneBlock()
2319 range = p->rc.range; in LzmaEnc_CodeOneBlock()
2320 probs = &p->isMatch[p->state][posState]; in LzmaEnc_CodeOneBlock()
2322 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2324 dist = p->backRes; in LzmaEnc_CodeOneBlock()
2336 RC_BIT_0(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2337 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2338 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_CodeOneBlock()
2341 state = p->state; in LzmaEnc_CodeOneBlock()
2342 p->state = kLiteralNextStates[state]; in LzmaEnc_CodeOneBlock()
2344 LitEnc_Encode(&p->rc, probs, curByte); in LzmaEnc_CodeOneBlock()
2346 LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0])); in LzmaEnc_CodeOneBlock()
2350 RC_BIT_1(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2351 probs = &p->isRep[p->state]; in LzmaEnc_CodeOneBlock()
2352 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2356 RC_BIT_1(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2357 probs = &p->isRepG0[p->state]; in LzmaEnc_CodeOneBlock()
2358 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2361 RC_BIT_0(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2362 probs = &p->isRep0Long[p->state][posState]; in LzmaEnc_CodeOneBlock()
2363 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2366 RC_BIT_1_BASE(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2370 RC_BIT_0_BASE(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2371 p->state = kShortRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
2376 RC_BIT_1(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2377 probs = &p->isRepG1[p->state]; in LzmaEnc_CodeOneBlock()
2378 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2381 RC_BIT_0_BASE(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2382 dist = p->reps[1]; in LzmaEnc_CodeOneBlock()
2386 RC_BIT_1(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2387 probs = &p->isRepG2[p->state]; in LzmaEnc_CodeOneBlock()
2388 RC_BIT_PRE(&p->rc, probs) in LzmaEnc_CodeOneBlock()
2391 RC_BIT_0_BASE(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2392 dist = p->reps[2]; in LzmaEnc_CodeOneBlock()
2396 RC_BIT_1_BASE(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2397 dist = p->reps[3]; in LzmaEnc_CodeOneBlock()
2398 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
2400 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
2402 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
2403 p->reps[0] = dist; in LzmaEnc_CodeOneBlock()
2406 RC_NORM(&p->rc) in LzmaEnc_CodeOneBlock()
2408 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2412 LenEnc_Encode(&p->repLenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState); in LzmaEnc_CodeOneBlock()
2413 --p->repLenEncCounter; in LzmaEnc_CodeOneBlock()
2414 p->state = kRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
2420 RC_BIT_0(&p->rc, probs); in LzmaEnc_CodeOneBlock()
2421 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2422 p->state = kMatchNextStates[p->state]; in LzmaEnc_CodeOneBlock()
2424 LenEnc_Encode(&p->lenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState); in LzmaEnc_CodeOneBlock()
2428 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
2429 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
2430 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
2431 p->reps[0] = dist + 1; in LzmaEnc_CodeOneBlock()
2433 p->matchPriceCount++; in LzmaEnc_CodeOneBlock()
2438 range = p->rc.range; in LzmaEnc_CodeOneBlock()
2439 probs = p->posSlotEncoder[GetLenToPosState(len)]; in LzmaEnc_CodeOneBlock()
2445 RC_BIT(&p->rc, prob, bit); in LzmaEnc_CodeOneBlock()
2448 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2458 … RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */)); in LzmaEnc_CodeOneBlock()
2463 range = p->rc.range; in LzmaEnc_CodeOneBlock()
2477 p->rc.low += range & (0 - (pos2 >> 31)); in LzmaEnc_CodeOneBlock()
2479 RC_NORM(&p->rc) in LzmaEnc_CodeOneBlock()
2489 … bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit; in LzmaEnc_CodeOneBlock()
2490 … bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit; in LzmaEnc_CodeOneBlock()
2491 … bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit; in LzmaEnc_CodeOneBlock()
2492 bit = dist & 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); in LzmaEnc_CodeOneBlock()
2493 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2502 p->additionalOffset -= len; in LzmaEnc_CodeOneBlock()
2504 if (p->additionalOffset == 0) in LzmaEnc_CodeOneBlock()
2508 if (!p->fastMode) in LzmaEnc_CodeOneBlock()
2518 if (p->matchPriceCount >= 64) in LzmaEnc_CodeOneBlock()
2520 FillAlignPrices(p); in LzmaEnc_CodeOneBlock()
2522 FillDistancesPrices(p); in LzmaEnc_CodeOneBlock()
2524 LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); in LzmaEnc_CodeOneBlock()
2526 if (p->repLenEncCounter <= 0) in LzmaEnc_CodeOneBlock()
2528 p->repLenEncCounter = REP_LEN_COUNT; in LzmaEnc_CodeOneBlock()
2529 LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices); in LzmaEnc_CodeOneBlock()
2533 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
2540 || RangeEnc_GetProcessed_sizet(&p->rc) + kPackReserve >= maxPackSize) in LzmaEnc_CodeOneBlock()
2545 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
2546 return CheckErrors(p); in LzmaEnc_CodeOneBlock()
2551 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
2552 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
2559 static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocB… in LzmaEnc_Alloc() argument
2562 if (!RangeEnc_Alloc(&p->rc, alloc)) in LzmaEnc_Alloc()
2566 p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0)); in LzmaEnc_Alloc()
2570 unsigned lclp = p->lc + p->lp; in LzmaEnc_Alloc()
2571 if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp) in LzmaEnc_Alloc()
2573 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
2574 p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb)); in LzmaEnc_Alloc()
2575 …p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaP… in LzmaEnc_Alloc()
2576 if (!p->litProbs || !p->saveState.litProbs) in LzmaEnc_Alloc()
2578 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
2581 p->lclp = lclp; in LzmaEnc_Alloc()
2585 p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0); in LzmaEnc_Alloc()
2587 if (beforeSize + p->dictSize < keepWindowSize) in LzmaEnc_Alloc()
2588 beforeSize = keepWindowSize - p->dictSize; in LzmaEnc_Alloc()
2591 if (p->mtMode) in LzmaEnc_Alloc()
2593 RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, in LzmaEnc_Alloc()
2597 p->matchFinderObj = &p->matchFinderMt; in LzmaEnc_Alloc()
2598 p->matchFinderBase.bigHash = (Byte)( in LzmaEnc_Alloc()
2599 (p->dictSize > kBigHashDicLimit && p->matchFinderBase.hashMask >= 0xFFFFFF) ? 1 : 0); in LzmaEnc_Alloc()
2600 MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder); in LzmaEnc_Alloc()
2605 …if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_… in LzmaEnc_Alloc()
2607 p->matchFinderObj = &p->matchFinderBase; in LzmaEnc_Alloc()
2608 MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder); in LzmaEnc_Alloc()
2614 void LzmaEnc_Init(CLzmaEnc *p) in LzmaEnc_Init() argument
2617 p->state = 0; in LzmaEnc_Init()
2618 p->reps[0] = in LzmaEnc_Init()
2619 p->reps[1] = in LzmaEnc_Init()
2620 p->reps[2] = in LzmaEnc_Init()
2621 p->reps[3] = 1; in LzmaEnc_Init()
2623 RangeEnc_Init(&p->rc); in LzmaEnc_Init()
2626 p->posAlignEncoder[i] = kProbInitValue; in LzmaEnc_Init()
2633 p->isMatch[i][j] = kProbInitValue; in LzmaEnc_Init()
2634 p->isRep0Long[i][j] = kProbInitValue; in LzmaEnc_Init()
2636 p->isRep[i] = kProbInitValue; in LzmaEnc_Init()
2637 p->isRepG0[i] = kProbInitValue; in LzmaEnc_Init()
2638 p->isRepG1[i] = kProbInitValue; in LzmaEnc_Init()
2639 p->isRepG2[i] = kProbInitValue; in LzmaEnc_Init()
2645 CLzmaProb *probs = p->posSlotEncoder[i]; in LzmaEnc_Init()
2653 p->posEncoders[i] = kProbInitValue; in LzmaEnc_Init()
2657 UInt32 num = (UInt32)0x300 << (p->lp + p->lc); in LzmaEnc_Init()
2659 CLzmaProb *probs = p->litProbs; in LzmaEnc_Init()
2665 LenEnc_Init(&p->lenProbs); in LzmaEnc_Init()
2666 LenEnc_Init(&p->repLenProbs); in LzmaEnc_Init()
2668 p->optEnd = 0; in LzmaEnc_Init()
2669 p->optCur = 0; in LzmaEnc_Init()
2673 p->opt[i].price = kInfinityPrice; in LzmaEnc_Init()
2676 p->additionalOffset = 0; in LzmaEnc_Init()
2678 p->pbMask = (1 << p->pb) - 1; in LzmaEnc_Init()
2679 p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc); in LzmaEnc_Init()
2683 void LzmaEnc_InitPrices(CLzmaEnc *p) in LzmaEnc_InitPrices() argument
2685 if (!p->fastMode) in LzmaEnc_InitPrices()
2687 FillDistancesPrices(p); in LzmaEnc_InitPrices()
2688 FillAlignPrices(p); in LzmaEnc_InitPrices()
2691 p->lenEnc.tableSize = in LzmaEnc_InitPrices()
2692 p->repLenEnc.tableSize = in LzmaEnc_InitPrices()
2693 p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN; in LzmaEnc_InitPrices()
2695 p->repLenEncCounter = REP_LEN_COUNT; in LzmaEnc_InitPrices()
2697 LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); in LzmaEnc_InitPrices()
2698 LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices); in LzmaEnc_InitPrices()
2701 static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr… in LzmaEnc_AllocAndInit() argument
2705 if (p->dictSize <= ((UInt32)1 << i)) in LzmaEnc_AllocAndInit()
2707 p->distTableSize = i * 2; in LzmaEnc_AllocAndInit()
2709 p->finished = False; in LzmaEnc_AllocAndInit()
2710 p->result = SZ_OK; in LzmaEnc_AllocAndInit()
2711 RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig)); in LzmaEnc_AllocAndInit()
2712 LzmaEnc_Init(p); in LzmaEnc_AllocAndInit()
2713 LzmaEnc_InitPrices(p); in LzmaEnc_AllocAndInit()
2714 p->nowPos64 = 0; in LzmaEnc_AllocAndInit()
2721 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Prepare() local
2722 p->matchFinderBase.stream = inStream; in LzmaEnc_Prepare()
2723 p->needInit = 1; in LzmaEnc_Prepare()
2724 p->rc.outStream = outStream; in LzmaEnc_Prepare()
2725 return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig); in LzmaEnc_Prepare()
2732 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_PrepareForLzma2() local
2733 p->matchFinderBase.stream = inStream; in LzmaEnc_PrepareForLzma2()
2734 p->needInit = 1; in LzmaEnc_PrepareForLzma2()
2735 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_PrepareForLzma2()
2738 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen) in LzmaEnc_SetInputBuf() argument
2740 p->matchFinderBase.directInput = 1; in LzmaEnc_SetInputBuf()
2741 p->matchFinderBase.bufferBase = (Byte *)src; in LzmaEnc_SetInputBuf()
2742 p->matchFinderBase.directInputRem = srcLen; in LzmaEnc_SetInputBuf()
2748 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemPrepare() local
2749 LzmaEnc_SetInputBuf(p, src, srcLen); in LzmaEnc_MemPrepare()
2750 p->needInit = 1; in LzmaEnc_MemPrepare()
2753 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_MemPrepare()
2759 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Finish() local
2760 if (p->mtMode) in LzmaEnc_Finish()
2761 MatchFinderMt_ReleaseStream(&p->matchFinderMt); in LzmaEnc_Finish()
2778 CLzmaEnc_SeqOutStreamBuf *p = CONTAINER_FROM_VTBL(pp, CLzmaEnc_SeqOutStreamBuf, vt); in SeqOutStreamBuf_Write() local
2779 if (p->rem < size) in SeqOutStreamBuf_Write()
2781 size = p->rem; in SeqOutStreamBuf_Write()
2782 p->overflow = True; in SeqOutStreamBuf_Write()
2784 memcpy(p->data, data, size); in SeqOutStreamBuf_Write()
2785 p->rem -= size; in SeqOutStreamBuf_Write()
2786 p->data += size; in SeqOutStreamBuf_Write()
2793 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetNumAvailableBytes() local
2794 return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in LzmaEnc_GetNumAvailableBytes()
2800 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetCurBuf() local
2801 return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_GetCurBuf()
2808 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_CodeOneMemBlock() local
2818 p->writeEndMark = False; in LzmaEnc_CodeOneMemBlock()
2819 p->finished = False; in LzmaEnc_CodeOneMemBlock()
2820 p->result = SZ_OK; in LzmaEnc_CodeOneMemBlock()
2823 LzmaEnc_Init(p); in LzmaEnc_CodeOneMemBlock()
2824 LzmaEnc_InitPrices(p); in LzmaEnc_CodeOneMemBlock()
2826 nowPos64 = p->nowPos64; in LzmaEnc_CodeOneMemBlock()
2827 RangeEnc_Init(&p->rc); in LzmaEnc_CodeOneMemBlock()
2828 p->rc.outStream = &outStream.vt; in LzmaEnc_CodeOneMemBlock()
2833 res = LzmaEnc_CodeOneBlock(p, desiredPackSize, *unpackSize); in LzmaEnc_CodeOneMemBlock()
2835 *unpackSize = (UInt32)(p->nowPos64 - nowPos64); in LzmaEnc_CodeOneMemBlock()
2844 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress) in LzmaEnc_Encode2() argument
2856 res = LzmaEnc_CodeOneBlock(p, 0, 0); in LzmaEnc_Encode2()
2857 if (res != SZ_OK || p->finished) in LzmaEnc_Encode2()
2861 res = ICompressProgress_Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc)); in LzmaEnc_Encode2()
2870 LzmaEnc_Finish(p); in LzmaEnc_Encode2()
2892 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_WriteProperties() local
2894 UInt32 dictSize = p->dictSize; in LzmaEnc_WriteProperties()
2898 props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc); in LzmaEnc_WriteProperties()
2928 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemEncode() local
2937 p->writeEndMark = writeEndMark; in LzmaEnc_MemEncode()
2938 p->rc.outStream = &outStream.vt; in LzmaEnc_MemEncode()
2944 res = LzmaEnc_Encode2(p, progress); in LzmaEnc_MemEncode()
2945 if (res == SZ_OK && p->nowPos64 != srcLen) in LzmaEnc_MemEncode()
2960 CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); in LzmaEncode() local
2962 if (!p) in LzmaEncode()
2965 res = LzmaEnc_SetProps(p, props); in LzmaEncode()
2968 res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize); in LzmaEncode()
2970 res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen, in LzmaEncode()
2974 LzmaEnc_Destroy(p, alloc, allocBig); in LzmaEncode()