9 #define kTopValue ((UInt32)1 << kNumTopBits)
11 #define kNumBitModelTotalBits 11
12 #define kBitModelTotal (1 << kNumBitModelTotalBits)
13 #define kNumMoveBits 5
15 #define RC_INIT_SIZE 5
18 if (range < kTopValue) { \
20 code = (code << 8) | (*buf++); \
26 bound = (range >> kNumBitModelTotalBits) * ttt; \
30 *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
34 *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
35 #define GET_BIT2(p, i, A0, A1) \
46 #define GET_BIT(p, i) GET_BIT2(p, i, ;, ;)
48 #define TREE_GET_BIT(probs, i) \
49 { GET_BIT((probs + i), i); }
50 #define TREE_DECODE(probs, limit, i) \
54 TREE_GET_BIT(probs, i); \
55 } while (i < limit); \
62 #define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
64 #define TREE_6_DECODE(probs, i) \
67 TREE_GET_BIT(probs, i); \
68 TREE_GET_BIT(probs, i); \
69 TREE_GET_BIT(probs, i); \
70 TREE_GET_BIT(probs, i); \
71 TREE_GET_BIT(probs, i); \
72 TREE_GET_BIT(probs, i); \
77 #define NORMALIZE_CHECK \
78 if (range < kTopValue) { \
79 if (buf >= bufLimit) \
82 code = (code << 8) | (*buf++); \
85 #define IF_BIT_0_CHECK(p) \
88 bound = (range >> kNumBitModelTotalBits) * ttt; \
90 #define UPDATE_0_CHECK range = bound;
91 #define UPDATE_1_CHECK \
94 #define GET_BIT2_CHECK(p, i, A0, A1) \
105 #define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ;, ;)
106 #define TREE_DECODE_CHECK(probs, limit, i) \
110 GET_BIT_CHECK(probs + i, i) \
111 } while (i < limit); \
115 #define kNumPosBitsMax 4
116 #define kNumPosStatesMax (1 << kNumPosBitsMax)
118 #define kLenNumLowBits 3
119 #define kLenNumLowSymbols (1 << kLenNumLowBits)
120 #define kLenNumMidBits 3
121 #define kLenNumMidSymbols (1 << kLenNumMidBits)
122 #define kLenNumHighBits 8
123 #define kLenNumHighSymbols (1 << kLenNumHighBits)
126 #define LenChoice2 (LenChoice + 1)
127 #define LenLow (LenChoice2 + 1)
128 #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
129 #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
130 #define kNumLenProbs (LenHigh + kLenNumHighSymbols)
132 #define kNumStates 12
133 #define kNumLitStates 7
135 #define kStartPosModelIndex 4
136 #define kEndPosModelIndex 14
137 #define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
139 #define kNumPosSlotBits 6
140 #define kNumLenToPosStates 4
142 #define kNumAlignBits 4
143 #define kAlignTableSize (1 << kNumAlignBits)
145 #define kMatchMinLen 2
146 #define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
149 #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
150 #define IsRepG0 (IsRep + kNumStates)
151 #define IsRepG1 (IsRepG0 + kNumStates)
152 #define IsRepG2 (IsRepG1 + kNumStates)
153 #define IsRep0Long (IsRepG2 + kNumStates)
154 #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
155 #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
156 #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
157 #define LenCoder (Align + kAlignTableSize)
158 #define RepLenCoder (LenCoder + kNumLenProbs)
159 #define Literal (RepLenCoder + kNumLenProbs)
161 #define LZMA_BASE_SIZE 1846
162 #define LZMA_LIT_SIZE 768
164 #define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
166 #if Literal != LZMA_BASE_SIZE
170 #define LZMA_DIC_MIN (1 << 12)
191 unsigned pbMask = ((unsigned)1 << (p->
prop.
pb)) - 1;
192 unsigned lpMask = ((unsigned)1 << (p->
prop.
lp)) - 1;
211 unsigned posState = processedPos & pbMask;
218 if (checkDicSize != 0 || processedPos != 0)
220 (((processedPos & lpMask) << lc) + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
223 state -= (state < 4) ? state : 3;
227 }
while (symbol < 0x100);
229 unsigned matchByte = p->
dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
230 unsigned offs = 0x100;
231 state -= (state < 10) ? 3 : 6;
237 bit = (matchByte & offs);
238 probLit = prob + offs + bit + symbol;
239 GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
240 }
while (symbol < 0x100);
242 dic[dicPos++] = (
Byte)symbol;
256 if (checkDicSize == 0 && processedPos == 0)
264 dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
334 unsigned posSlot = (unsigned)distance;
335 int numDirectBits = (int)(((distance >> 1) - 1));
336 distance = (2 | (distance & 1));
338 distance <<= numDirectBits;
339 prob = probs +
SpecPos + distance - posSlot - 1;
344 GET_BIT2(prob + i, i, ;, distance |= mask);
346 }
while (--numDirectBits != 0);
357 t = (0 - ((
UInt32)code >> 31));
358 distance = (distance << 1) + (t + 1);
369 }
while (--numDirectBits != 0);
370 prob = probs +
Align;
374 GET_BIT2(prob + i, i, ;, distance |= 1);
375 GET_BIT2(prob + i, i, ;, distance |= 2);
376 GET_BIT2(prob + i, i, ;, distance |= 4);
377 GET_BIT2(prob + i, i, ;, distance |= 8);
379 if (distance == (
UInt32)0xFFFFFFFF) {
390 if (checkDicSize == 0) {
391 if (distance >= processedPos)
393 }
else if (distance >= checkDicSize)
403 SizeT rem = limit - dicPos;
404 unsigned curLen = ((rem < len) ? (
unsigned)rem : len);
405 SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
407 processedPos += curLen;
410 if (pos + curLen <= dicBufSize) {
412 ptrdiff_t
src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
413 const Byte *lim = dest + curLen;
417 while (++dest != lim);
420 dic[dicPos++] = dic[pos];
421 if (++pos == dicBufSize)
423 }
while (--curLen != 0);
427 }
while (dicPos < limit && buf < bufLimit);
451 if (limit - dicPos < len)
452 len = (unsigned)(limit - dicPos);
460 dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
472 if (limit - p->
dicPos > rem)
497 const Byte *bufLimit = buf + inSize;
523 }
while (symbol < 0x100);
526 unsigned offs = 0x100;
532 bit = (matchByte & offs);
533 probLit = prob + offs + bit + symbol;
535 }
while (symbol < 0x100);
616 int numDirectBits = ((posSlot >> 1) - 1);
621 prob = probs +
SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
627 code -= range & (((code -
range) >> 31) - 1);
629 }
while (--numDirectBits != 0);
630 prob = probs +
Align;
637 }
while (--numDirectBits != 0);
649 p->
range = 0xFFFFFFFF;
676 for (i = 0; i < numProbs; i++)
685 SizeT inSize = *srcLen;
709 if (p->
dicPos >= dicLimit) {
730 const Byte *bufLimit;
734 memcpy(p->
tempBuf, src, inSize);
751 (*srcLen) += processed;
757 p->
tempBuf[rem++] = src[lookAhead++];
762 (*srcLen) += lookAhead;
774 lookAhead -= (rem - (unsigned)(p->
buf - p->
tempBuf));
775 (*srcLen) += lookAhead;
793 SizeT outSize = *destLen;
794 SizeT inSize = *srcLen;
795 *srcLen = *destLen = 0;
797 SizeT inSizeCur = inSize, outSizeCur, dicPos;
807 outSizeCur = dicPos + outSize;
808 curFinishMode = finishMode;
814 *srcLen += inSizeCur;
815 outSizeCur = p->
dicPos - dicPos;
816 memcpy(dest, p->
dic + dicPos, outSizeCur);
818 outSize -= outSizeCur;
819 *destLen += outSizeCur;
822 if (outSizeCur == 0 || outSize == 0)
849 dicSize = data[1] | ((
UInt32)data[2] << 8) | ((
UInt32)data[3] << 16) | ((
UInt32)data[4] << 24);
856 if (d >= (9 * 5 * 5))
873 if (p->
probs ==
nullptr)
896 if (p->
dic ==
nullptr) {
910 const Byte *propData,
917 SizeT inSize = *srcLen;
918 SizeT outSize = *destLen;
919 *srcLen = *destLen = 0;
#define SZ_ERROR_INPUT_EOF
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
#define LzmaProps_GetNumProbs(p)
#define GET_BIT_CHECK(p, i)
#define GET_BIT2(p, i, A0, A1)
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
#define kLenNumLowSymbols
static void LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
#define kStartPosModelIndex
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
#define TREE_DECODE(probs, limit, i)
#define GET_BIT2_CHECK(p, i, A0, A1)
const uint16_t range(const Frame &aFrame)
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
static int LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
if(conf_.getParameter< bool >("UseStripCablingDB"))
void *(* Alloc)(void *p, size_t size)
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
#define LZMA_REQUIRED_INPUT_MAX
#define kMatchSpecLenStart
#define kEndPosModelIndex
#define LzmaDec_Construct(p)
#define IF_BIT_0_CHECK(p)
void(* Free)(void *p, void *address)
#define kLenNumMidSymbols
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
#define kNumLenToPosStates
char data[epos_bytes_allocation]
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
#define TREE_DECODE_CHECK(probs, limit, i)
void LzmaDec_Init(CLzmaDec *p)
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
#define TREE_6_DECODE(probs, i)
static int LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
static void LzmaDec_InitStateReal(CLzmaDec *p)
tuple size
Write out results.
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
#define SZ_ERROR_UNSUPPORTED