• Home
  • Raw
  • Download

Lines Matching +full:- +full:p

1 /* LzmaEnc.c -- LZMA Encoder
2 2018-12-29: Igor Pavlov : Public domain */
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()
105 … res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }
121 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
132 size_t k = ((size_t)1 << ((slot >> 1) - 1)); in LzmaEnc_FastPosInit()
140 /* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
142 #define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
143 (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
144 res = p->g_FastPos[pos >> zz] + (zz * 2); }
148 #define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
149 (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
150 res = p->g_FastPos[pos >> zz] + (zz * 2); }
153 #define BSR2_RET(pos, res) { unsigned zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits -
154 res = p->g_FastPos[pos >> zz] + (zz * 2); }
158 p->g_FastPos[pos >> 6] + 12 : \
159 p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
162 #define GetPosSlot1(pos) p->g_FastPos[pos]
164 …etPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDistances - 1…
181 // > 1 : MATCH (extra-1) : LIT : REP0 (len)
202 #define kAlignMask (kAlignTableSize - 1)
229 #define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
249 #define GET_PRICE_LEN(p, posState, len) \ argument
250 ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
253 #define GET_PRICE_LEN(p, posState, len) \
254 …((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 -
395 #define COPY_ARR(dest, src, arr) memcpy(dest->arr, src->arr, sizeof(src->arr));
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()
476 // p->_maxMode = True; 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()
528 #define GetLenToPosState2(len) (((len) < kNumLenToPosStates - 1) ? (len) : kNumLenToPosStates - 1)
529 #define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates -
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) \
639 if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
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) \
650 mask = 0 - (UInt32)bit; \
653 range -= mask; \
654 (p)->low += mask; \
655 mask = (UInt32)bit - 1; \
657 mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
658 mask += ((1 << kNumMoveBits) - 1); \
659 ttt += (Int32)(mask - ttt) >> kNumMoveBits; \
661 RC_NORM(p) \
669 #define RC_BIT_0_BASE(p, prob) \ argument
670 range = newBound; *(prob) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
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()
699 // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1); 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()
720 // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (sym >> 8)), (sym >> 7) & 1); in LitEnc_EncodeMatched()
725 RC_BIT(p, prob, bit); in LitEnc_EncodeMatched()
728 p->range = range; in LitEnc_EncodeMatched()
739 UInt32 w = (i << kNumMoveReducingBits) + (1 << (kNumMoveReducingBits - 1)); in LzmaEnc_InitPriceTables()
752 ProbPrices[i] = (CProbPrice)((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount); in LzmaEnc_InitPriceTables()
759p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBit…
762 … ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
764 #define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
765 #define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
768 #define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
805 UInt32 range = rc->range; in RcTree_ReverseEncode()
816 while (--numBits); in RcTree_ReverseEncode()
817 rc->range = range; in RcTree_ReverseEncode()
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()
835 range = rc->range; in LenEnc_Encode()
845 rc->range = range; in LenEnc_Encode()
846 // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2); in LenEnc_Encode()
847 LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2); in LenEnc_Encode()
850 sym -= kLenNumLowSymbols; in LenEnc_Encode()
862 rc->range = range; in LenEnc_Encode()
883 CLenPriceEnc *p, in LenPriceEnc_UpdateTables() argument
891 unsigned prob = enc->low[0]; in LenPriceEnc_UpdateTables()
896 c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]); in LenPriceEnc_UpdateTables()
899 UInt32 *prices = p->prices[posState]; in LenPriceEnc_UpdateTables()
900 const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits)); in LenPriceEnc_UpdateTables()
910 a = GET_PRICEa_0(enc->low[0]); in LenPriceEnc_UpdateTables()
912 p->prices2[i] = a; in LenPriceEnc_UpdateTables()
913 a = GET_PRICEa_1(enc->low[0]); in LenPriceEnc_UpdateTables()
914 b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]); in LenPriceEnc_UpdateTables()
916 p->prices2[i] = b; in LenPriceEnc_UpdateTables()
917 a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]); in LenPriceEnc_UpdateTables()
921 // p->counter = numSymbols; in LenPriceEnc_UpdateTables()
922 // p->counter = 64; in LenPriceEnc_UpdateTables()
925 unsigned i = p->tableSize; in LenPriceEnc_UpdateTables()
929 const CLzmaProb *probs = enc->high; in LenPriceEnc_UpdateTables()
930 UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2; in LenPriceEnc_UpdateTables()
931 i -= kLenNumLowSymbols * 2 - 1; in LenPriceEnc_UpdateTables()
933 b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]); in LenPriceEnc_UpdateTables()
937 p->prices2[i] = a + in LenPriceEnc_UpdateTables()
938 // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices); in LenPriceEnc_UpdateTables()
939 LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices); in LenPriceEnc_UpdateTables()
941 // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices); in LenPriceEnc_UpdateTables()
942 unsigned sym = --i + (1 << (kLenNumHighBits - 1)); in LenPriceEnc_UpdateTables()
953 unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))]; 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()
1018 return (unsigned)(p2 - p1); in ReadMatchDistances()
1024 #define MARK_LIT ((UInt32)(Int32)-1)
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()
1076 cur -= len; in Backward()
1080 wr--; in Backward()
1081 p->opt[wr].len = (UInt32)len; in Backward()
1082 cur -= extra; in Backward()
1086 p->opt[wr].dist = dist; in Backward()
1091 p->opt[wr].dist = 0; in Backward()
1092 len--; in Backward()
1093 wr--; 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()
1106 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()
1159 data2 = data - 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()
1191 matchByte = *(data - reps[0]); 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()
1208 const CLzmaProb *probs = LIT_PROBS(position, *(data - 1)); 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()
1243 // ---------- REP ---------- 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()
1256 if (price2 < opt->price) in GetOptimum()
1258 opt->price = price2; in GetOptimum()
1259 opt->len = (UInt32)repLen; in GetOptimum()
1260 opt->dist = (UInt32)i; in GetOptimum()
1261 opt->extra = 0; in GetOptimum()
1264 while (--repLen >= 2); in GetOptimum()
1268 // ---------- MATCH ---------- 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()
1301 if (price < opt->price) in GetOptimum()
1303 opt->price = price; in GetOptimum()
1304 opt->len = (UInt32)len; in GetOptimum()
1305 opt->dist = dist + LZMA_NUM_REPS; in GetOptimum()
1306 opt->extra = 0; in GetOptimum()
1328 printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price); in GetOptimum()
1335 // ---------- Optimal Parsing ---------- in GetOptimum()
1352 if (cur >= kNumOpts - 64) in GetOptimum()
1355 UInt32 price = p->opt[cur].price; in GetOptimum()
1359 UInt32 price2 = p->opt[j].price; in GetOptimum()
1367 unsigned delta = best - cur; 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()
1390 // we need that check here, if skip_items in p->opt are possible in GetOptimum()
1392 if (curOpt->price >= kInfinityPrice) in GetOptimum()
1396 prev = cur - curOpt->len; in GetOptimum()
1398 if (curOpt->len == 1) in GetOptimum()
1400 state = (unsigned)p->opt[prev].state; in GetOptimum()
1410 UInt32 dist = curOpt->dist; in GetOptimum()
1412 if (curOpt->extra) in GetOptimum()
1414 prev -= (unsigned)curOpt->extra; in GetOptimum()
1416 if (curOpt->extra == 1) in GetOptimum()
1421 state = (unsigned)p->opt[prev].state; in GetOptimum()
1428 prevOpt = &p->opt[prev]; in GetOptimum()
1429 b0 = prevOpt->reps[0]; in GetOptimum()
1436 reps[1] = prevOpt->reps[1]; in GetOptimum()
1437 reps[2] = prevOpt->reps[2]; in GetOptimum()
1438 reps[3] = prevOpt->reps[3]; in GetOptimum()
1443 b0 = prevOpt->reps[1]; in GetOptimum()
1447 reps[2] = prevOpt->reps[2]; in GetOptimum()
1448 reps[3] = prevOpt->reps[3]; in GetOptimum()
1453 reps[0] = prevOpt->reps[dist]; in GetOptimum()
1454 reps[3] = prevOpt->reps[dist ^ 1]; in GetOptimum()
1460 reps[0] = (dist - LZMA_NUM_REPS + 1); in GetOptimum()
1462 reps[2] = prevOpt->reps[1]; in GetOptimum()
1463 reps[3] = prevOpt->reps[2]; in GetOptimum()
1467 curOpt->state = (CState)state; in GetOptimum()
1468 curOpt->reps[0] = reps[0]; in GetOptimum()
1469 curOpt->reps[1] = reps[1]; in GetOptimum()
1470 curOpt->reps[2] = reps[2]; in GetOptimum()
1471 curOpt->reps[3] = reps[3]; in GetOptimum()
1473 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
1475 matchByte = *(data - reps[0]); in GetOptimum()
1477 posState = (position & p->pbMask); in GetOptimum()
1489 UInt32 curPrice = curOpt->price; in GetOptimum()
1490 unsigned prob = p->isMatch[state][posState]; in GetOptimum()
1495 nextOpt = &p->opt[(size_t)cur + 1]; in GetOptimum()
1498 // here we can allow skip_items in p->opt, if we don't check (nextOpt->price < kInfinityPrice) in GetOptimum()
1500 if (nextOpt->price < kInfinityPrice in GetOptimum()
1503 || litPrice > nextOpt->price in GetOptimum()
1508 const CLzmaProb *probs = LIT_PROBS(position, *(data - 1)); in GetOptimum()
1510 LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1511 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1513 if (litPrice < nextOpt->price) in GetOptimum()
1515 nextOpt->price = litPrice; in GetOptimum()
1516 nextOpt->len = 1; in GetOptimum()
1522 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); in GetOptimum()
1524 numAvailFull = p->numAvail; in GetOptimum()
1526 unsigned temp = kNumOpts - 1 - cur; in GetOptimum()
1532 // ---------- SHORT_REP ---------- in GetOptimum()
1535 if (repMatchPrice < nextOpt->price) // 18.new in GetOptimum()
1536 // if (numAvailFull < 2 || data[1] != *(data - reps[0] + 1)) in GetOptimum()
1538 // nextOpt->price >= kInfinityPrice || in GetOptimum()
1539 nextOpt->len < 2 // we can check nextOpt->len, if skip items are not allowed in p->opt in GetOptimum()
1540 || (nextOpt->dist != 0 in GetOptimum()
1541 // && nextOpt->extra <= 1 // 17.old in GetOptimum()
1545 UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState); in GetOptimum()
1546 // if (shortRepPrice <= nextOpt->price) // 17.old in GetOptimum()
1547 if (shortRepPrice < nextOpt->price) // 18.new in GetOptimum()
1549 nextOpt->price = shortRepPrice; in GetOptimum()
1550 nextOpt->len = 1; in GetOptimum()
1558 numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); in GetOptimum()
1560 // numAvail <= p->numFastBytes in GetOptimum()
1562 // ---------- LIT : REP_0 ---------- in GetOptimum()
1569 const Byte *data2 = data - reps[0]; 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()
1593 len--; in GetOptimum()
1594 // price2 = price + GetPrice_Len_Rep_0(p, len, state2, posState2); in GetOptimum()
1595 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len); in GetOptimum()
1597 opt = &p->opt[offset]; in GetOptimum()
1598 // offset--; in GetOptimum()
1599 if (price2 < opt->price) in GetOptimum()
1601 opt->price = price2; in GetOptimum()
1602 opt->len = (UInt32)len; in GetOptimum()
1603 opt->dist = 0; in GetOptimum()
1604 opt->extra = 1; in GetOptimum()
1616 // ---------- REP ---------- in GetOptimum()
1623 const Byte *data2 = data - reps[repIndex]; 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()
1644 if (price2 < opt->price) in GetOptimum()
1646 opt->price = price2; in GetOptimum()
1647 opt->len = (UInt32)len2; in GetOptimum()
1648 opt->dist = (UInt32)repIndex; in GetOptimum()
1649 opt->extra = 0; in GetOptimum()
1652 while (--len2 >= 2); in GetOptimum()
1660 // ---------- REP : LIT : REP_0 ---------- in GetOptimum()
1664 unsigned limit = len2 + p->numFastBytes; in GetOptimum()
1670 if (data[len2 - 2] == data2[len2 - 2]) in GetOptimum()
1671 if (data[len2 - 1] == data2[len2 - 1]) 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()
1677 + LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]), 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()
1690 len2 -= len; in GetOptimum()
1702 len2--; in GetOptimum()
1703 // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2); in GetOptimum()
1704 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); in GetOptimum()
1706 opt = &p->opt[offset]; in GetOptimum()
1707 // offset--; in GetOptimum()
1708 if (price2 < opt->price) in GetOptimum()
1710 opt->price = price2; in GetOptimum()
1711 opt->len = (UInt32)len2; in GetOptimum()
1712 opt->extra = (CExtra)(len + 1); in GetOptimum()
1713 opt->dist = (UInt32)repIndex; in GetOptimum()
1725 // ---------- MATCH ---------- 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()
1762 unsigned lenNorm = len - 2; 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()
1770 if (price < opt->price) in GetOptimum()
1772 opt->price = price; in GetOptimum()
1773 opt->len = (UInt32)len; in GetOptimum()
1774 opt->dist = dist + LZMA_NUM_REPS; in GetOptimum()
1775 opt->extra = 0; in GetOptimum()
1781 // if (p->_maxMode) { in GetOptimum()
1784 const Byte *data2 = data - dist - 1; in GetOptimum()
1786 unsigned limit = len2 + p->numFastBytes; in GetOptimum()
1792 if (data[len2 - 2] == data2[len2 - 2]) in GetOptimum()
1793 if (data[len2 - 1] == data2[len2 - 1]) in GetOptimum()
1798 len2 -= len; in GetOptimum()
1803 unsigned posState2 = (position + len) & p->pbMask; in GetOptimum()
1805 price += GET_PRICE_0(p->isMatch[state2][posState2]); in GetOptimum()
1806 price += LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]), 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()
1823 len2--; in GetOptimum()
1824 // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2); in GetOptimum()
1825 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); in GetOptimum()
1826 opt = &p->opt[offset]; in GetOptimum()
1827 // offset--; in GetOptimum()
1828 if (price2 < opt->price) in GetOptimum()
1830 opt->price = price2; in GetOptimum()
1831 opt->len = (UInt32)len2; in GetOptimum()
1832 opt->extra = (CExtra)(len + 1); in GetOptimum()
1833 opt->dist = dist + LZMA_NUM_REPS; in GetOptimum()
1853 p->opt[last].price = kInfinityPrice; in GetOptimum()
1854 while (--last); 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()
1883 // if (mainLen < 2 && p->state == 0) return 1; // 18.06.notused 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()
1930 numPairs -= 2; in GetOptimumFast()
1931 mainLen--; 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()
1974 limit = mainLen - 1; 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()
2015 // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[0], (1 << kNumPosSlotBits) - 1); 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()
2028 …// RangeEnc_EncodeDirectBits(&p->rc, ((UInt32)1 << (30 - kNumAlignBits)) - 1, 30 - kNumAlignBits);… in WriteEndMarker()
2029 unsigned numBits = 30 - kNumAlignBits; in WriteEndMarker()
2033 p->rc.low += range; in WriteEndMarker()
2034 RC_NORM(&p->rc) in WriteEndMarker()
2036 while (--numBits); in WriteEndMarker()
2040 // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask); 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()
2087 // p->alignPriceCount = 0; 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()
2101 …// p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices); 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()
2119 unsigned footerBits = (posSlot >> 1) - 1; in FillDistancesPrices()
2121 const CLzmaProb *probs = p->posEncoders + (size_t)base * 2; in FillDistancesPrices()
2122 …// tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPric… in FillDistancesPrices()
2137 while (--footerBits); 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()
2155 // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices); in FillDistancesPrices()
2158 unsigned sym = slot + (1 << (kNumPosSlotBits - 1)); in FillDistancesPrices()
2165 prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))]; in FillDistancesPrices()
2171 … UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits); 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()
2286 // p->state = kLiteralNextStates[p->state]; 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()
2312 len = opt->len; 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()
2339 probs = LIT_PROBS(nowPos32, *(data - 1)); 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()
2425 // --p->lenEnc.counter; in LzmaEnc_CodeOneBlock()
2427 dist -= LZMA_NUM_REPS; 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()
2435 // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], posSlot); in LzmaEnc_CodeOneBlock()
2438 range = p->rc.range; in LzmaEnc_CodeOneBlock()
2439 probs = p->posSlotEncoder[GetLenToPosState(len)]; in LzmaEnc_CodeOneBlock()
2443 UInt32 bit = (sym >> (kNumPosSlotBits - 1)) & 1; in LzmaEnc_CodeOneBlock()
2445 RC_BIT(&p->rc, prob, bit); in LzmaEnc_CodeOneBlock()
2448 p->rc.range = range; in LzmaEnc_CodeOneBlock()
2453 unsigned footerBits = ((posSlot >> 1) - 1); in LzmaEnc_CodeOneBlock()
2458 … RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */)); in LzmaEnc_CodeOneBlock()
2462 UInt32 pos2 = (dist | 0xF) << (32 - footerBits); in LzmaEnc_CodeOneBlock()
2463 range = p->rc.range; in LzmaEnc_CodeOneBlock()
2464 … // RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits); in LzmaEnc_CodeOneBlock()
2469 p->rc.low += range & (0 - ((dist >> --footerBits) & 1)); in LzmaEnc_CodeOneBlock()
2470 RC_NORM(&p->rc) in LzmaEnc_CodeOneBlock()
2477 p->rc.low += range & (0 - (pos2 >> 31)); in LzmaEnc_CodeOneBlock()
2479 RC_NORM(&p->rc) in LzmaEnc_CodeOneBlock()
2484 … // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask); 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()
2494 // p->alignPriceCount++; 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()
2511 if (p->alignPriceCount >= 16) // kAlignTableSize in LzmaEnc_CodeOneBlock()
2512 FillAlignPrices(p); in LzmaEnc_CodeOneBlock()
2513 if (p->matchPriceCount >= 128) in LzmaEnc_CodeOneBlock()
2514 FillDistancesPrices(p); in LzmaEnc_CodeOneBlock()
2515 if (p->lenEnc.counter <= 0) in LzmaEnc_CodeOneBlock()
2516 LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); 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()
2535 processed = nowPos32 - startPos32; 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()
2575p->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()
2836 *destLen -= outStream.rem; 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()
2873 if (res == SZ_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase)) 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()
2902 UInt32 kDictMask = ((UInt32)1 << 20) - 1; in LzmaEnc_WriteProperties()
2903 if (dictSize < (UInt32)0xFFFFFFFF - kDictMask) in LzmaEnc_WriteProperties()
2920 return ((CLzmaEnc *)pp)->writeEndMark; in LzmaEnc_IsWriteEndMark()
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()
2949 *destLen -= outStream.rem; 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()