CMS 3D CMS Logo

Macros | Enumerations | Functions
LzmaDec.cc File Reference
#include "LzmaDec.h"
#include <cstring>

Go to the source code of this file.

Macros

#define Align   (SpecPos + kNumFullDistances - kEndPosModelIndex)
 
#define GET_BIT(p, i)   GET_BIT2(p, i, ;, ;)
 
#define GET_BIT2(p, i, A0, A1)
 
#define GET_BIT2_CHECK(p, i, A0, A1)
 
#define GET_BIT_CHECK(p, i)   GET_BIT2_CHECK(p, i, ;, ;)
 
#define IF_BIT_0(p)
 
#define IF_BIT_0_CHECK(p)
 
#define IsMatch   0
 
#define IsRep   (IsMatch + (kNumStates << kNumPosBitsMax))
 
#define IsRep0Long   (IsRepG2 + kNumStates)
 
#define IsRepG0   (IsRep + kNumStates)
 
#define IsRepG1   (IsRepG0 + kNumStates)
 
#define IsRepG2   (IsRepG1 + kNumStates)
 
#define kAlignTableSize   (1 << kNumAlignBits)
 
#define kBitModelTotal   (1 << kNumBitModelTotalBits)
 
#define kEndPosModelIndex   14
 
#define kLenNumHighBits   8
 
#define kLenNumHighSymbols   (1 << kLenNumHighBits)
 
#define kLenNumLowBits   3
 
#define kLenNumLowSymbols   (1 << kLenNumLowBits)
 
#define kLenNumMidBits   3
 
#define kLenNumMidSymbols   (1 << kLenNumMidBits)
 
#define kMatchMinLen   2
 
#define kMatchSpecLenStart   (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
 
#define kNumAlignBits   4
 
#define kNumBitModelTotalBits   11
 
#define kNumFullDistances   (1 << (kEndPosModelIndex >> 1))
 
#define kNumLenProbs   (LenHigh + kLenNumHighSymbols)
 
#define kNumLenToPosStates   4
 
#define kNumLitStates   7
 
#define kNumMoveBits   5
 
#define kNumPosBitsMax   4
 
#define kNumPosSlotBits   6
 
#define kNumPosStatesMax   (1 << kNumPosBitsMax)
 
#define kNumStates   12
 
#define kNumTopBits   24
 
#define kStartPosModelIndex   4
 
#define kTopValue   ((UInt32)1 << kNumTopBits)
 
#define LenChoice   0
 
#define LenChoice2   (LenChoice + 1)
 
#define LenCoder   (Align + kAlignTableSize)
 
#define LenHigh   (LenMid + (kNumPosStatesMax << kLenNumMidBits))
 
#define LenLow   (LenChoice2 + 1)
 
#define LenMid   (LenLow + (kNumPosStatesMax << kLenNumLowBits))
 
#define Literal   (RepLenCoder + kNumLenProbs)
 
#define LZMA_BASE_SIZE   1846
 
#define LZMA_DIC_MIN   (1 << 12)
 
#define LZMA_LIT_SIZE   768
 
#define LzmaProps_GetNumProbs(p)   ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
 
#define NORMALIZE
 
#define NORMALIZE_CHECK
 
#define PosSlot   (IsRep0Long + (kNumStates << kNumPosBitsMax))
 
#define RC_INIT_SIZE   5
 
#define RepLenCoder   (LenCoder + kNumLenProbs)
 
#define SpecPos   (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
 
#define TREE_6_DECODE(probs, i)
 
#define TREE_DECODE(probs, limit, i)
 
#define TREE_DECODE_CHECK(probs, limit, i)
 
#define TREE_GET_BIT(probs, i)   { GET_BIT((probs + i), i); }
 
#define UPDATE_0(p)
 
#define UPDATE_0_CHECK   range = bound;
 
#define UPDATE_1(p)
 
#define UPDATE_1_CHECK
 

Enumerations

enum  ELzmaDummy { DUMMY_ERROR, DUMMY_LIT, DUMMY_MATCH, DUMMY_REP }
 

Functions

SRes LzmaDec_Allocate (CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
 
SRes LzmaDec_AllocateProbs (CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
 
static SRes LzmaDec_AllocateProbs2 (CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
 
static int LzmaDec_DecodeReal (CLzmaDec *p, SizeT limit, const Byte *bufLimit)
 
static int LzmaDec_DecodeReal2 (CLzmaDec *p, SizeT limit, const Byte *bufLimit)
 
SRes LzmaDec_DecodeToBuf (CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
SRes LzmaDec_DecodeToDic (CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
void LzmaDec_Free (CLzmaDec *p, ISzAlloc *alloc)
 
static void LzmaDec_FreeDict (CLzmaDec *p, ISzAlloc *alloc)
 
void LzmaDec_FreeProbs (CLzmaDec *p, ISzAlloc *alloc)
 
void LzmaDec_Init (CLzmaDec *p)
 
void LzmaDec_InitDicAndState (CLzmaDec *p, Bool initDic, Bool initState)
 
static void LzmaDec_InitRc (CLzmaDec *p, const Byte *data)
 
static void LzmaDec_InitStateReal (CLzmaDec *p)
 
static ELzmaDummy LzmaDec_TryDummy (const CLzmaDec *p, const Byte *buf, SizeT inSize)
 
static void LzmaDec_WriteRem (CLzmaDec *p, SizeT limit)
 
SRes LzmaDecode (Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
 
SRes LzmaProps_Decode (CLzmaProps *p, const Byte *data, unsigned size)
 

Macro Definition Documentation

◆ Align

#define Align   (SpecPos + kNumFullDistances - kEndPosModelIndex)

Definition at line 156 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ GET_BIT

#define GET_BIT (   p,
 
)    GET_BIT2(p, i, ;, ;)

Definition at line 46 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ GET_BIT2

#define GET_BIT2 (   p,
  i,
  A0,
  A1 
)
Value:
IF_BIT_0(p) { \
UPDATE_0(p); \
i = (i + i); \
A0; \
} \
else { \
UPDATE_1(p); \
i = (i + i) + 1; \
A1; \
}
#define IF_BIT_0(p)
Definition: LzmaDec.cc:23

Definition at line 35 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ GET_BIT2_CHECK

#define GET_BIT2_CHECK (   p,
  i,
  A0,
  A1 
)
Value:
UPDATE_0_CHECK; \
i = (i + i); \
A0; \
} \
else { \
UPDATE_1_CHECK; \
i = (i + i) + 1; \
A1; \
}
#define IF_BIT_0_CHECK(p)
Definition: LzmaDec.cc:85

Definition at line 94 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ GET_BIT_CHECK

#define GET_BIT_CHECK (   p,
 
)    GET_BIT2_CHECK(p, i, ;, ;)

Definition at line 105 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ IF_BIT_0

#define IF_BIT_0 (   p)
Value:
ttt = *(p); \
NORMALIZE; \
bound = (range >> kNumBitModelTotalBits) * ttt; \
if (code < bound)
#define kNumBitModelTotalBits
Definition: LzmaDec.cc:11

Definition at line 23 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ IF_BIT_0_CHECK

#define IF_BIT_0_CHECK (   p)
Value:
ttt = *(p); \
NORMALIZE_CHECK; \
bound = (range >> kNumBitModelTotalBits) * ttt; \
if (code < bound)
#define kNumBitModelTotalBits
Definition: LzmaDec.cc:11

Definition at line 85 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ IsMatch

#define IsMatch   0

Definition at line 148 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ IsRep

#define IsRep   (IsMatch + (kNumStates << kNumPosBitsMax))

Definition at line 149 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ IsRep0Long

#define IsRep0Long   (IsRepG2 + kNumStates)

Definition at line 153 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ IsRepG0

#define IsRepG0   (IsRep + kNumStates)

Definition at line 150 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ IsRepG1

#define IsRepG1   (IsRepG0 + kNumStates)

Definition at line 151 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ IsRepG2

#define IsRepG2   (IsRepG1 + kNumStates)

Definition at line 152 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kAlignTableSize

#define kAlignTableSize   (1 << kNumAlignBits)

Definition at line 143 of file LzmaDec.cc.

◆ kBitModelTotal

#define kBitModelTotal   (1 << kNumBitModelTotalBits)

Definition at line 12 of file LzmaDec.cc.

Referenced by LzmaDec_InitStateReal().

◆ kEndPosModelIndex

#define kEndPosModelIndex   14

Definition at line 136 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kLenNumHighBits

#define kLenNumHighBits   8

Definition at line 122 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kLenNumHighSymbols

#define kLenNumHighSymbols   (1 << kLenNumHighBits)

Definition at line 123 of file LzmaDec.cc.

◆ kLenNumLowBits

#define kLenNumLowBits   3

Definition at line 118 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kLenNumLowSymbols

#define kLenNumLowSymbols   (1 << kLenNumLowBits)

Definition at line 119 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kLenNumMidBits

#define kLenNumMidBits   3

Definition at line 120 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kLenNumMidSymbols

#define kLenNumMidSymbols   (1 << kLenNumMidBits)

Definition at line 121 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kMatchMinLen

#define kMatchMinLen   2

Definition at line 145 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ kMatchSpecLenStart

#define kMatchSpecLenStart   (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)

◆ kNumAlignBits

#define kNumAlignBits   4

Definition at line 142 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumBitModelTotalBits

#define kNumBitModelTotalBits   11

Definition at line 11 of file LzmaDec.cc.

◆ kNumFullDistances

#define kNumFullDistances   (1 << (kEndPosModelIndex >> 1))

Definition at line 137 of file LzmaDec.cc.

◆ kNumLenProbs

#define kNumLenProbs   (LenHigh + kLenNumHighSymbols)

Definition at line 130 of file LzmaDec.cc.

◆ kNumLenToPosStates

#define kNumLenToPosStates   4

Definition at line 140 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumLitStates

#define kNumLitStates   7

Definition at line 133 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumMoveBits

#define kNumMoveBits   5

Definition at line 13 of file LzmaDec.cc.

◆ kNumPosBitsMax

#define kNumPosBitsMax   4

Definition at line 115 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumPosSlotBits

#define kNumPosSlotBits   6

Definition at line 139 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumPosStatesMax

#define kNumPosStatesMax   (1 << kNumPosBitsMax)

Definition at line 116 of file LzmaDec.cc.

◆ kNumStates

#define kNumStates   12

Definition at line 132 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kNumTopBits

#define kNumTopBits   24

Definition at line 8 of file LzmaDec.cc.

◆ kStartPosModelIndex

#define kStartPosModelIndex   4

Definition at line 135 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ kTopValue

#define kTopValue   ((UInt32)1 << kNumTopBits)

Definition at line 9 of file LzmaDec.cc.

◆ LenChoice

#define LenChoice   0

Definition at line 125 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ LenChoice2

#define LenChoice2   (LenChoice + 1)

Definition at line 126 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ LenCoder

#define LenCoder   (Align + kAlignTableSize)

Definition at line 157 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ LenHigh

#define LenHigh   (LenMid + (kNumPosStatesMax << kLenNumMidBits))

Definition at line 129 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ LenLow

#define LenLow   (LenChoice2 + 1)

Definition at line 127 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ LenMid

#define LenMid   (LenLow + (kNumPosStatesMax << kLenNumLowBits))

Definition at line 128 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ Literal

#define Literal   (RepLenCoder + kNumLenProbs)

Definition at line 159 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), LzmaDec_InitStateReal(), and LzmaDec_TryDummy().

◆ LZMA_BASE_SIZE

#define LZMA_BASE_SIZE   1846

Definition at line 161 of file LzmaDec.cc.

◆ LZMA_DIC_MIN

#define LZMA_DIC_MIN   (1 << 12)

Definition at line 170 of file LzmaDec.cc.

Referenced by LzmaProps_Decode().

◆ LZMA_LIT_SIZE

#define LZMA_LIT_SIZE   768

Definition at line 162 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), LzmaDec_InitStateReal(), and LzmaDec_TryDummy().

◆ LzmaProps_GetNumProbs

#define LzmaProps_GetNumProbs (   p)    ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))

Definition at line 164 of file LzmaDec.cc.

Referenced by LzmaDec_AllocateProbs2().

◆ NORMALIZE

#define NORMALIZE
Value:
if (range < kTopValue) { \
range <<= 8; \
code = (code << 8) | (*buf++); \
}
#define kTopValue
Definition: LzmaDec.cc:9

Definition at line 17 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ NORMALIZE_CHECK

#define NORMALIZE_CHECK
Value:
if (range < kTopValue) { \
if (buf >= bufLimit) \
return DUMMY_ERROR; \
range <<= 8; \
code = (code << 8) | (*buf++); \
}
#define kTopValue
Definition: LzmaDec.cc:9

Definition at line 77 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ PosSlot

#define PosSlot   (IsRep0Long + (kNumStates << kNumPosBitsMax))

Definition at line 154 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ RC_INIT_SIZE

#define RC_INIT_SIZE   5

Definition at line 15 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeToDic(), and LzmaDecode().

◆ RepLenCoder

#define RepLenCoder   (LenCoder + kNumLenProbs)

Definition at line 158 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ SpecPos

#define SpecPos   (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))

Definition at line 155 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal(), and LzmaDec_TryDummy().

◆ TREE_6_DECODE

#define TREE_6_DECODE (   probs,
 
)
Value:
{ \
i = 1; \
TREE_GET_BIT(probs, i); \
TREE_GET_BIT(probs, i); \
TREE_GET_BIT(probs, i); \
TREE_GET_BIT(probs, i); \
TREE_GET_BIT(probs, i); \
TREE_GET_BIT(probs, i); \
i -= 0x40; \
}

Definition at line 64 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ TREE_DECODE

#define TREE_DECODE (   probs,
  limit,
 
)
Value:
{ \
i = 1; \
do { \
TREE_GET_BIT(probs, i); \
} while (i < limit); \
i -= limit; \
}

Definition at line 50 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ TREE_DECODE_CHECK

#define TREE_DECODE_CHECK (   probs,
  limit,
 
)
Value:
{ \
i = 1; \
do { \
GET_BIT_CHECK(probs + i, i) \
} while (i < limit); \
i -= limit; \
}

Definition at line 106 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ TREE_GET_BIT

#define TREE_GET_BIT (   probs,
 
)    { GET_BIT((probs + i), i); }

Definition at line 48 of file LzmaDec.cc.

◆ UPDATE_0

#define UPDATE_0 (   p)
Value:
range = bound; \
*(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
#define kBitModelTotal
Definition: LzmaDec.cc:12
#define CLzmaProb
Definition: LzmaDec.h:20
#define kNumMoveBits
Definition: LzmaDec.cc:13

Definition at line 28 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ UPDATE_0_CHECK

#define UPDATE_0_CHECK   range = bound;

Definition at line 90 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

◆ UPDATE_1

#define UPDATE_1 (   p)
Value:
range -= bound; \
code -= bound; \
*(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
#define CLzmaProb
Definition: LzmaDec.h:20
#define kNumMoveBits
Definition: LzmaDec.cc:13

Definition at line 31 of file LzmaDec.cc.

Referenced by LzmaDec_DecodeReal().

◆ UPDATE_1_CHECK

#define UPDATE_1_CHECK
Value:
range -= bound; \
code -= bound;

Definition at line 91 of file LzmaDec.cc.

Referenced by LzmaDec_TryDummy().

Enumeration Type Documentation

◆ ELzmaDummy

enum ELzmaDummy
Enumerator
DUMMY_ERROR 
DUMMY_LIT 
DUMMY_MATCH 
DUMMY_REP 

Definition at line 487 of file LzmaDec.cc.

487  {
488  DUMMY_ERROR, /* unexpected end of input stream */
489  DUMMY_LIT,
490  DUMMY_MATCH,
491  DUMMY_REP
492 } ELzmaDummy;
ELzmaDummy
Definition: LzmaDec.cc:487

Function Documentation

◆ LzmaDec_Allocate()

SRes LzmaDec_Allocate ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 887 of file LzmaDec.cc.

References ISzAlloc::Alloc, _CLzmaProps::dicSize, LzmaDec_AllocateProbs2(), LzmaDec_FreeDict(), LzmaDec_FreeProbs(), LzmaProps_Decode(), AlCaHLTBitMon_ParallelJobs::p, RINOK, SZ_ERROR_MEM, and SZ_OK.

Referenced by LzmaFile::Open().

887  {
888  CLzmaProps propNew;
889  SizeT dicBufSize;
890  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
891  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
892  dicBufSize = propNew.dicSize;
893  if (p->dic == nullptr || dicBufSize != p->dicBufSize) {
894  LzmaDec_FreeDict(p, alloc);
895  p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
896  if (p->dic == nullptr) {
897  LzmaDec_FreeProbs(p, alloc);
898  return SZ_ERROR_MEM;
899  }
900  }
901  p->dicBufSize = dicBufSize;
902  p->prop = propNew;
903  return SZ_OK;
904 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
#define RINOK(x)
Definition: Types.h:52
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:832
void *(* Alloc)(void *p, size_t size)
Definition: Types.h:216
size_t SizeT
Definition: Types.h:97
UInt32 dicSize
Definition: LzmaDec.h:29
#define SZ_OK
Definition: Types.h:25
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
Definition: LzmaDec.cc:867
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:842
unsigned char Byte
Definition: Types.h:60
#define SZ_ERROR_MEM
Definition: Types.h:28

◆ LzmaDec_AllocateProbs()

SRes LzmaDec_AllocateProbs ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 879 of file LzmaDec.cc.

References LzmaDec_AllocateProbs2(), LzmaProps_Decode(), AlCaHLTBitMon_ParallelJobs::p, RINOK, and SZ_OK.

Referenced by LzmaDecode().

879  {
880  CLzmaProps propNew;
881  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
882  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
883  p->prop = propNew;
884  return SZ_OK;
885 }
#define RINOK(x)
Definition: Types.h:52
#define SZ_OK
Definition: Types.h:25
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
Definition: LzmaDec.cc:867
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:842

◆ LzmaDec_AllocateProbs2()

static SRes LzmaDec_AllocateProbs2 ( CLzmaDec p,
const CLzmaProps propNew,
ISzAlloc alloc 
)
static

Definition at line 867 of file LzmaDec.cc.

References ISzAlloc::Alloc, CLzmaProb, LzmaDec_FreeProbs(), LzmaProps_GetNumProbs, AlCaHLTBitMon_ParallelJobs::p, SZ_ERROR_MEM, and SZ_OK.

Referenced by LzmaDec_Allocate(), and LzmaDec_AllocateProbs().

867  {
868  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
869  if (p->probs == nullptr || numProbs != p->numProbs) {
870  LzmaDec_FreeProbs(p, alloc);
871  p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
872  p->numProbs = numProbs;
873  if (p->probs == nullptr)
874  return SZ_ERROR_MEM;
875  }
876  return SZ_OK;
877 }
#define LzmaProps_GetNumProbs(p)
Definition: LzmaDec.cc:164
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
void *(* Alloc)(void *p, size_t size)
Definition: Types.h:216
unsigned int UInt32
Definition: Types.h:69
#define SZ_OK
Definition: Types.h:25
#define CLzmaProb
Definition: LzmaDec.h:20
#define SZ_ERROR_MEM
Definition: Types.h:28

◆ LzmaDec_DecodeReal()

static int LzmaDec_DecodeReal ( CLzmaDec p,
SizeT  limit,
const Byte bufLimit 
)
static

Definition at line 186 of file LzmaDec.cc.

References Align, triggerObjects_cff::bit, visDQMUpload::buf, CLzmaProb, mps_fire::dest, HLT_2023v12_cff::distance, GET_BIT, GET_BIT2, mps_fire::i, IF_BIT_0, createfilelist::int, IsMatch, IsRep, IsRep0Long, IsRepG0, IsRepG1, IsRepG2, kEndPosModelIndex, kLenNumHighBits, kLenNumLowBits, kLenNumLowSymbols, kLenNumMidBits, kLenNumMidSymbols, kMatchMinLen, kMatchSpecLenStart, kNumAlignBits, kNumLenToPosStates, kNumLitStates, kNumPosBitsMax, kNumPosSlotBits, kNumStates, kStartPosModelIndex, LenChoice, LenChoice2, LenCoder, LenHigh, LenLow, LenMid, remoteMonitoring_LASER_era2018_cfg::limit, Literal, LZMA_LIT_SIZE, gpuClustering::pixelStatus::mask, NORMALIZE, hltrates_dqm_sourceclient-live_cfg::offset, AlCaHLTBitMon_ParallelJobs::p, PosSlot, TtFullHadEvtBuilder_cfi::prob, FastTimerService_cff::range, RepLenCoder, SpecPos, TrackRefitter_38T_cff::src, SZ_ERROR_DATA, SZ_OK, submitPVValidationJobs::t, TREE_6_DECODE, TREE_DECODE, UPDATE_0, and UPDATE_1.

Referenced by LzmaDec_DecodeReal2().

186  {
187  CLzmaProb *probs = p->probs;
188 
189  unsigned state = p->state;
190  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
191  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
192  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
193  unsigned lc = p->prop.lc;
194 
195  Byte *dic = p->dic;
196  SizeT dicBufSize = p->dicBufSize;
197  SizeT dicPos = p->dicPos;
198 
199  UInt32 processedPos = p->processedPos;
200  UInt32 checkDicSize = p->checkDicSize;
201  unsigned len = 0;
202 
203  const Byte *buf = p->buf;
204  UInt32 range = p->range;
205  UInt32 code = p->code;
206 
207  do {
208  CLzmaProb *prob;
209  UInt32 bound;
210  unsigned ttt;
211  unsigned posState = processedPos & pbMask;
212 
213  prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
214  IF_BIT_0(prob) {
215  unsigned symbol;
216  UPDATE_0(prob);
217  prob = probs + Literal;
218  if (checkDicSize != 0 || processedPos != 0)
219  prob += (LZMA_LIT_SIZE *
220  (((processedPos & lpMask) << lc) + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
221 
222  if (state < kNumLitStates) {
223  state -= (state < 4) ? state : 3;
224  symbol = 1;
225  do {
226  GET_BIT(prob + symbol, symbol)
227  } while (symbol < 0x100);
228  } else {
229  unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
230  unsigned offs = 0x100;
231  state -= (state < 10) ? 3 : 6;
232  symbol = 1;
233  do {
234  unsigned bit;
235  CLzmaProb *probLit;
236  matchByte <<= 1;
237  bit = (matchByte & offs);
238  probLit = prob + offs + bit + symbol;
239  GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
240  } while (symbol < 0x100);
241  }
242  dic[dicPos++] = (Byte)symbol;
243  processedPos++;
244  continue;
245  }
246  else {
247  UPDATE_1(prob);
248  prob = probs + IsRep + state;
249  IF_BIT_0(prob) {
250  UPDATE_0(prob);
251  state += kNumStates;
252  prob = probs + LenCoder;
253  }
254  else {
255  UPDATE_1(prob);
256  if (checkDicSize == 0 && processedPos == 0)
257  return SZ_ERROR_DATA;
258  prob = probs + IsRepG0 + state;
259  IF_BIT_0(prob) {
260  UPDATE_0(prob);
261  prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
262  IF_BIT_0(prob) {
263  UPDATE_0(prob);
264  dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
265  dicPos++;
266  processedPos++;
267  state = state < kNumLitStates ? 9 : 11;
268  continue;
269  }
270  UPDATE_1(prob);
271  }
272  else {
274  UPDATE_1(prob);
275  prob = probs + IsRepG1 + state;
276  IF_BIT_0(prob) {
277  UPDATE_0(prob);
278  distance = rep1;
279  }
280  else {
281  UPDATE_1(prob);
282  prob = probs + IsRepG2 + state;
283  IF_BIT_0(prob) {
284  UPDATE_0(prob);
285  distance = rep2;
286  }
287  else {
288  UPDATE_1(prob);
289  distance = rep3;
290  rep3 = rep2;
291  }
292  rep2 = rep1;
293  }
294  rep1 = rep0;
295  rep0 = distance;
296  }
297  state = state < kNumLitStates ? 8 : 11;
298  prob = probs + RepLenCoder;
299  }
300  {
301  unsigned limit, offset;
302  CLzmaProb *probLen = prob + LenChoice;
303  IF_BIT_0(probLen) {
304  UPDATE_0(probLen);
305  probLen = prob + LenLow + (posState << kLenNumLowBits);
306  offset = 0;
307  limit = (1 << kLenNumLowBits);
308  }
309  else {
310  UPDATE_1(probLen);
311  probLen = prob + LenChoice2;
312  IF_BIT_0(probLen) {
313  UPDATE_0(probLen);
314  probLen = prob + LenMid + (posState << kLenNumMidBits);
316  limit = (1 << kLenNumMidBits);
317  }
318  else {
319  UPDATE_1(probLen);
320  probLen = prob + LenHigh;
322  limit = (1 << kLenNumHighBits);
323  }
324  }
325  TREE_DECODE(probLen, limit, len);
326  len += offset;
327  }
328 
329  if (state >= kNumStates) {
331  prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
333  if (distance >= kStartPosModelIndex) {
334  unsigned posSlot = (unsigned)distance;
335  int numDirectBits = (int)(((distance >> 1) - 1));
336  distance = (2 | (distance & 1));
337  if (posSlot < kEndPosModelIndex) {
338  distance <<= numDirectBits;
339  prob = probs + SpecPos + distance - posSlot - 1;
340  {
341  UInt32 mask = 1;
342  unsigned i = 1;
343  do {
344  GET_BIT2(prob + i, i, ;, distance |= mask);
345  mask <<= 1;
346  } while (--numDirectBits != 0);
347  }
348  } else {
349  numDirectBits -= kNumAlignBits;
350  do {
351  NORMALIZE
352  range >>= 1;
353 
354  {
355  UInt32 t;
356  code -= range;
357  t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
358  distance = (distance << 1) + (t + 1);
359  code += range & t;
360  }
361  /*
362  distance <<= 1;
363  if (code >= range)
364  {
365  code -= range;
366  distance |= 1;
367  }
368  */
369  } while (--numDirectBits != 0);
370  prob = probs + Align;
372  {
373  unsigned i = 1;
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);
378  }
379  if (distance == (UInt32)0xFFFFFFFF) {
380  len += kMatchSpecLenStart;
381  state -= kNumStates;
382  break;
383  }
384  }
385  }
386  rep3 = rep2;
387  rep2 = rep1;
388  rep1 = rep0;
389  rep0 = distance + 1;
390  if (checkDicSize == 0) {
391  if (distance >= processedPos)
392  return SZ_ERROR_DATA;
393  } else if (distance >= checkDicSize)
394  return SZ_ERROR_DATA;
396  }
397 
398  len += kMatchMinLen;
399 
400  if (limit == dicPos)
401  return SZ_ERROR_DATA;
402  {
403  SizeT rem = limit - dicPos;
404  unsigned curLen = ((rem < len) ? (unsigned)rem : len);
405  SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
406 
407  processedPos += curLen;
408 
409  len -= curLen;
410  if (pos + curLen <= dicBufSize) {
411  Byte *dest = dic + dicPos;
412  ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
413  const Byte *lim = dest + curLen;
414  dicPos += curLen;
415  do
416  *(dest) = (Byte) * (dest + src);
417  while (++dest != lim);
418  } else {
419  do {
420  dic[dicPos++] = dic[pos];
421  if (++pos == dicBufSize)
422  pos = 0;
423  } while (--curLen != 0);
424  }
425  }
426  }
427  } while (dicPos < limit && buf < bufLimit);
428  NORMALIZE;
429  p->buf = buf;
430  p->range = range;
431  p->code = code;
432  p->remainLen = len;
433  p->dicPos = dicPos;
434  p->processedPos = processedPos;
435  p->reps[0] = rep0;
436  p->reps[1] = rep1;
437  p->reps[2] = rep2;
438  p->reps[3] = rep3;
439  p->state = state;
440 
441  return SZ_OK;
442 }
#define UPDATE_0(p)
Definition: LzmaDec.cc:28
#define SZ_ERROR_DATA
Definition: Types.h:27
#define IsRepG0
Definition: LzmaDec.cc:150
#define IsRepG1
Definition: LzmaDec.cc:151
#define GET_BIT2(p, i, A0, A1)
Definition: LzmaDec.cc:35
#define LenChoice2
Definition: LzmaDec.cc:126
#define UPDATE_1(p)
Definition: LzmaDec.cc:31
#define LZMA_LIT_SIZE
Definition: LzmaDec.cc:162
#define kLenNumLowSymbols
Definition: LzmaDec.cc:119
#define NORMALIZE
Definition: LzmaDec.cc:17
#define kStartPosModelIndex
Definition: LzmaDec.cc:135
#define Literal
Definition: LzmaDec.cc:159
#define TREE_DECODE(probs, limit, i)
Definition: LzmaDec.cc:50
#define SpecPos
Definition: LzmaDec.cc:155
constexpr uint32_t mask
Definition: gpuClustering.h:26
#define RepLenCoder
Definition: LzmaDec.cc:158
#define LenMid
Definition: LzmaDec.cc:128
size_t SizeT
Definition: Types.h:97
#define IsRepG2
Definition: LzmaDec.cc:152
#define LenCoder
Definition: LzmaDec.cc:157
#define IsRep0Long
Definition: LzmaDec.cc:153
#define LenChoice
Definition: LzmaDec.cc:125
unsigned int UInt32
Definition: Types.h:69
#define kMatchSpecLenStart
Definition: LzmaDec.cc:146
#define Align
Definition: LzmaDec.cc:156
#define kEndPosModelIndex
Definition: LzmaDec.cc:136
#define SZ_OK
Definition: Types.h:25
#define kNumStates
Definition: LzmaDec.cc:132
#define LenLow
Definition: LzmaDec.cc:127
#define CLzmaProb
Definition: LzmaDec.h:20
#define kLenNumMidBits
Definition: LzmaDec.cc:120
#define kNumPosBitsMax
Definition: LzmaDec.cc:115
#define kMatchMinLen
Definition: LzmaDec.cc:145
#define kLenNumMidSymbols
Definition: LzmaDec.cc:121
#define kNumLenToPosStates
Definition: LzmaDec.cc:140
#define GET_BIT(p, i)
Definition: LzmaDec.cc:46
#define kLenNumHighBits
Definition: LzmaDec.cc:122
#define PosSlot
Definition: LzmaDec.cc:154
#define IF_BIT_0(p)
Definition: LzmaDec.cc:23
unsigned char Byte
Definition: Types.h:60
#define kLenNumLowBits
Definition: LzmaDec.cc:118
#define TREE_6_DECODE(probs, i)
Definition: LzmaDec.cc:64
#define kNumPosSlotBits
Definition: LzmaDec.cc:139
#define LenHigh
Definition: LzmaDec.cc:129
#define IsMatch
Definition: LzmaDec.cc:148
#define kNumLitStates
Definition: LzmaDec.cc:133
#define kNumAlignBits
Definition: LzmaDec.cc:142
#define IsRep
Definition: LzmaDec.cc:149

◆ LzmaDec_DecodeReal2()

static int LzmaDec_DecodeReal2 ( CLzmaDec p,
SizeT  limit,
const Byte bufLimit 
)
static

Definition at line 467 of file LzmaDec.cc.

References kMatchSpecLenStart, remoteMonitoring_LASER_era2018_cfg::limit, LzmaDec_DecodeReal(), LzmaDec_WriteRem(), AlCaHLTBitMon_ParallelJobs::p, and RINOK.

Referenced by LzmaDec_DecodeToDic().

467  {
468  do {
469  SizeT limit2 = limit;
470  if (p->checkDicSize == 0) {
471  UInt32 rem = p->prop.dicSize - p->processedPos;
472  if (limit - p->dicPos > rem)
473  limit2 = p->dicPos + rem;
474  }
475  RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
476  if (p->processedPos >= p->prop.dicSize)
477  p->checkDicSize = p->prop.dicSize;
479  } while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
480 
481  if (p->remainLen > kMatchSpecLenStart) {
482  p->remainLen = kMatchSpecLenStart;
483  }
484  return 0;
485 }
#define RINOK(x)
Definition: Types.h:52
static void LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
Definition: LzmaDec.cc:444
size_t SizeT
Definition: Types.h:97
unsigned int UInt32
Definition: Types.h:69
#define kMatchSpecLenStart
Definition: LzmaDec.cc:146
static int LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
Definition: LzmaDec.cc:186

◆ LzmaDec_DecodeToBuf()

SRes LzmaDec_DecodeToBuf ( CLzmaDec p,
Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 786 of file LzmaDec.cc.

References mps_fire::dest, LZMA_FINISH_ANY, LzmaDec_DecodeToDic(), AlCaHLTBitMon_ParallelJobs::p, TrackRefitter_38T_cff::src, mps_update::status, and SZ_OK.

Referenced by LzmaFile::DecodeAll(), and LzmaFile::DecodeBuffer().

792  {
793  SizeT outSize = *destLen;
794  SizeT inSize = *srcLen;
795  *srcLen = *destLen = 0;
796  for (;;) {
797  SizeT inSizeCur = inSize, outSizeCur, dicPos;
798  ELzmaFinishMode curFinishMode;
799  SRes res;
800  if (p->dicPos == p->dicBufSize)
801  p->dicPos = 0;
802  dicPos = p->dicPos;
803  if (outSize > p->dicBufSize - dicPos) {
804  outSizeCur = p->dicBufSize;
805  curFinishMode = LZMA_FINISH_ANY;
806  } else {
807  outSizeCur = dicPos + outSize;
808  curFinishMode = finishMode;
809  }
810 
811  res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
812  src += inSizeCur;
813  inSize -= inSizeCur;
814  *srcLen += inSizeCur;
815  outSizeCur = p->dicPos - dicPos;
816  memcpy(dest, p->dic + dicPos, outSizeCur);
817  dest += outSizeCur;
818  outSize -= outSizeCur;
819  *destLen += outSizeCur;
820  if (res != 0)
821  return res;
822  if (outSizeCur == 0 || outSize == 0)
823  return SZ_OK;
824  }
825 }
ELzmaFinishMode
Definition: LzmaDec.h:79
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:683
Definition: Electron.h:6
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
#define SZ_OK
Definition: Types.h:25

◆ LzmaDec_DecodeToDic()

SRes LzmaDec_DecodeToDic ( CLzmaDec p,
SizeT  dicLimit,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 683 of file LzmaDec.cc.

References DUMMY_ERROR, DUMMY_MATCH, caHitNtupletGeneratorKernels::if(), kMatchSpecLenStart, LZMA_FINISH_ANY, LZMA_REQUIRED_INPUT_MAX, LZMA_STATUS_FINISHED_WITH_MARK, LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK, LZMA_STATUS_NEEDS_MORE_INPUT, LZMA_STATUS_NOT_FINISHED, LZMA_STATUS_NOT_SPECIFIED, LzmaDec_DecodeReal2(), LzmaDec_InitRc(), LzmaDec_InitStateReal(), LzmaDec_TryDummy(), LzmaDec_WriteRem(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, TrackRefitter_38T_cff::src, mps_update::status, SZ_ERROR_DATA, and SZ_OK.

Referenced by LzmaDec_DecodeToBuf(), and LzmaDecode().

684  {
685  SizeT inSize = *srcLen;
686  (*srcLen) = 0;
687  LzmaDec_WriteRem(p, dicLimit);
688 
690 
691  while (p->remainLen != kMatchSpecLenStart) {
692  int checkEndMarkNow;
693 
694  if (p->needFlush != 0) {
695  for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
696  p->tempBuf[p->tempBufSize++] = *src++;
697  if (p->tempBufSize < RC_INIT_SIZE) {
699  return SZ_OK;
700  }
701  if (p->tempBuf[0] != 0)
702  return SZ_ERROR_DATA;
703 
704  LzmaDec_InitRc(p, p->tempBuf);
705  p->tempBufSize = 0;
706  }
707 
708  checkEndMarkNow = 0;
709  if (p->dicPos >= dicLimit) {
710  if (p->remainLen == 0 && p->code == 0) {
712  return SZ_OK;
713  }
714  if (finishMode == LZMA_FINISH_ANY) {
716  return SZ_OK;
717  }
718  if (p->remainLen != 0) {
720  return SZ_ERROR_DATA;
721  }
722  checkEndMarkNow = 1;
723  }
724 
725  if (p->needInitState)
727 
728  if (p->tempBufSize == 0) {
729  SizeT processed;
730  const Byte *bufLimit;
731  if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) {
732  int dummyRes = LzmaDec_TryDummy(p, src, inSize);
733  if (dummyRes == DUMMY_ERROR) {
734  memcpy(p->tempBuf, src, inSize);
735  p->tempBufSize = (unsigned)inSize;
736  (*srcLen) += inSize;
738  return SZ_OK;
739  }
740  if (checkEndMarkNow && dummyRes != DUMMY_MATCH) {
742  return SZ_ERROR_DATA;
743  }
744  bufLimit = src;
745  } else
746  bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
747  p->buf = src;
748  if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
749  return SZ_ERROR_DATA;
750  processed = (SizeT)(p->buf - src);
751  (*srcLen) += processed;
752  src += processed;
753  inSize -= processed;
754  } else {
755  unsigned rem = p->tempBufSize, lookAhead = 0;
756  while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
757  p->tempBuf[rem++] = src[lookAhead++];
758  p->tempBufSize = rem;
759  if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) {
760  int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
761  if (dummyRes == DUMMY_ERROR) {
762  (*srcLen) += lookAhead;
764  return SZ_OK;
765  }
766  if (checkEndMarkNow && dummyRes != DUMMY_MATCH) {
768  return SZ_ERROR_DATA;
769  }
770  }
771  p->buf = p->tempBuf;
772  if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
773  return SZ_ERROR_DATA;
774  lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
775  (*srcLen) += lookAhead;
776  src += lookAhead;
777  inSize -= lookAhead;
778  p->tempBufSize = 0;
779  }
780  }
781  if (p->code == 0)
783  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
784 }
#define SZ_ERROR_DATA
Definition: Types.h:27
static void LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
Definition: LzmaDec.cc:444
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
Definition: LzmaDec.cc:647
size_t SizeT
Definition: Types.h:97
static int LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
Definition: LzmaDec.cc:467
#define LZMA_REQUIRED_INPUT_MAX
Definition: LzmaDec.h:45
#define kMatchSpecLenStart
Definition: LzmaDec.cc:146
#define SZ_OK
Definition: Types.h:25
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
unsigned char Byte
Definition: Types.h:60
static void LzmaDec_InitStateReal(CLzmaDec *p)
Definition: LzmaDec.cc:672
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
Definition: LzmaDec.cc:494

◆ LzmaDec_Free()

void LzmaDec_Free ( CLzmaDec p,
ISzAlloc alloc 
)

Definition at line 837 of file LzmaDec.cc.

References LzmaDec_FreeDict(), LzmaDec_FreeProbs(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Close().

837  {
838  LzmaDec_FreeProbs(p, alloc);
839  LzmaDec_FreeDict(p, alloc);
840 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:832

◆ LzmaDec_FreeDict()

static void LzmaDec_FreeDict ( CLzmaDec p,
ISzAlloc alloc 
)
static

Definition at line 832 of file LzmaDec.cc.

References ISzAlloc::Free, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_Allocate(), and LzmaDec_Free().

832  {
833  alloc->Free(alloc, p->dic);
834  p->dic = nullptr;
835 }
void(* Free)(void *p, void *address)
Definition: Types.h:217

◆ LzmaDec_FreeProbs()

void LzmaDec_FreeProbs ( CLzmaDec p,
ISzAlloc alloc 
)

Definition at line 827 of file LzmaDec.cc.

References ISzAlloc::Free, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_Allocate(), LzmaDec_AllocateProbs2(), LzmaDec_Free(), and LzmaDecode().

827  {
828  alloc->Free(alloc, p->probs);
829  p->probs = nullptr;
830 }
void(* Free)(void *p, void *address)
Definition: Types.h:217

◆ LzmaDec_Init()

void LzmaDec_Init ( CLzmaDec p)

Definition at line 667 of file LzmaDec.cc.

References LzmaDec_InitDicAndState(), AlCaHLTBitMon_ParallelJobs::p, and True.

Referenced by LzmaDecode(), and LzmaFile::Open().

667  {
668  p->dicPos = 0;
670 }
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
Definition: LzmaDec.cc:653
#define True
Definition: Types.h:101

◆ LzmaDec_InitDicAndState()

void LzmaDec_InitDicAndState ( CLzmaDec p,
Bool  initDic,
Bool  initState 
)

Definition at line 653 of file LzmaDec.cc.

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_Init().

653  {
654  p->needFlush = 1;
655  p->remainLen = 0;
656  p->tempBufSize = 0;
657 
658  if (initDic) {
659  p->processedPos = 0;
660  p->checkDicSize = 0;
661  p->needInitState = 1;
662  }
663  if (initState)
664  p->needInitState = 1;
665 }

◆ LzmaDec_InitRc()

static void LzmaDec_InitRc ( CLzmaDec p,
const Byte data 
)
static

Definition at line 647 of file LzmaDec.cc.

References data, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_DecodeToDic().

647  {
648  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
649  p->range = 0xFFFFFFFF;
650  p->needFlush = 0;
651 }
unsigned int UInt32
Definition: Types.h:69
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79

◆ LzmaDec_InitStateReal()

static void LzmaDec_InitStateReal ( CLzmaDec p)
static

Definition at line 672 of file LzmaDec.cc.

References CLzmaProb, mps_fire::i, kBitModelTotal, Literal, LZMA_LIT_SIZE, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_DecodeToDic().

672  {
673  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
674  UInt32 i;
675  CLzmaProb *probs = p->probs;
676  for (i = 0; i < numProbs; i++)
677  probs[i] = kBitModelTotal >> 1;
678  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
679  p->state = 0;
680  p->needInitState = 0;
681 }
#define LZMA_LIT_SIZE
Definition: LzmaDec.cc:162
#define Literal
Definition: LzmaDec.cc:159
#define kBitModelTotal
Definition: LzmaDec.cc:12
unsigned int UInt32
Definition: Types.h:69
#define CLzmaProb
Definition: LzmaDec.h:20

◆ LzmaDec_TryDummy()

static ELzmaDummy LzmaDec_TryDummy ( const CLzmaDec p,
const Byte buf,
SizeT  inSize 
)
static

Definition at line 494 of file LzmaDec.cc.

References Align, triggerObjects_cff::bit, visDQMUpload::buf, CLzmaProb, DUMMY_LIT, DUMMY_MATCH, DUMMY_REP, GET_BIT2_CHECK, GET_BIT_CHECK, mps_fire::i, IF_BIT_0_CHECK, IsMatch, IsRep, IsRep0Long, IsRepG0, IsRepG1, IsRepG2, kEndPosModelIndex, kLenNumHighBits, kLenNumLowBits, kLenNumLowSymbols, kLenNumMidBits, kLenNumMidSymbols, kNumAlignBits, kNumLenToPosStates, kNumLitStates, kNumPosBitsMax, kNumPosSlotBits, kNumStates, kStartPosModelIndex, LenChoice, LenChoice2, LenCoder, LenHigh, LenLow, LenMid, remoteMonitoring_LASER_era2018_cfg::limit, Literal, LZMA_LIT_SIZE, NORMALIZE_CHECK, hltrates_dqm_sourceclient-live_cfg::offset, AlCaHLTBitMon_ParallelJobs::p, PosSlot, TtFullHadEvtBuilder_cfi::prob, FastTimerService_cff::range, RepLenCoder, SpecPos, TREE_DECODE_CHECK, UPDATE_0_CHECK, and UPDATE_1_CHECK.

Referenced by LzmaDec_DecodeToDic().

494  {
495  UInt32 range = p->range;
496  UInt32 code = p->code;
497  const Byte *bufLimit = buf + inSize;
498  CLzmaProb *probs = p->probs;
499  unsigned state = p->state;
500  ELzmaDummy res;
501 
502  {
503  CLzmaProb *prob;
504  UInt32 bound;
505  unsigned ttt;
506  unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
507 
508  prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
511 
512  /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
513 
514  prob = probs + Literal;
515  if (p->checkDicSize != 0 || p->processedPos != 0)
516  prob += (LZMA_LIT_SIZE * ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
517  (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
518 
519  if (state < kNumLitStates) {
520  unsigned symbol = 1;
521  do {
522  GET_BIT_CHECK(prob + symbol, symbol)
523  } while (symbol < 0x100);
524  } else {
525  unsigned matchByte = p->dic[p->dicPos - p->reps[0] + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
526  unsigned offs = 0x100;
527  unsigned symbol = 1;
528  do {
529  unsigned bit;
530  CLzmaProb *probLit;
531  matchByte <<= 1;
532  bit = (matchByte & offs);
533  probLit = prob + offs + bit + symbol;
534  GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
535  } while (symbol < 0x100);
536  }
537  res = DUMMY_LIT;
538  }
539  else {
540  unsigned len;
542 
543  prob = probs + IsRep + state;
546  state = 0;
547  prob = probs + LenCoder;
548  res = DUMMY_MATCH;
549  }
550  else {
552  res = DUMMY_REP;
553  prob = probs + IsRepG0 + state;
556  prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
560  return DUMMY_REP;
561  }
562  else {
564  }
565  }
566  else {
568  prob = probs + IsRepG1 + state;
570  else {
572  prob = probs + IsRepG2 + state;
574  else {
576  }
577  }
578  }
579  state = kNumStates;
580  prob = probs + RepLenCoder;
581  }
582  {
583  unsigned limit, offset;
584  CLzmaProb *probLen = prob + LenChoice;
585  IF_BIT_0_CHECK(probLen) {
587  probLen = prob + LenLow + (posState << kLenNumLowBits);
588  offset = 0;
589  limit = 1 << kLenNumLowBits;
590  }
591  else {
593  probLen = prob + LenChoice2;
594  IF_BIT_0_CHECK(probLen) {
596  probLen = prob + LenMid + (posState << kLenNumMidBits);
598  limit = 1 << kLenNumMidBits;
599  }
600  else {
602  probLen = prob + LenHigh;
604  limit = 1 << kLenNumHighBits;
605  }
606  }
607  TREE_DECODE_CHECK(probLen, limit, len);
608  len += offset;
609  }
610 
611  if (state < 4) {
612  unsigned posSlot;
613  prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
614  TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
615  if (posSlot >= kStartPosModelIndex) {
616  int numDirectBits = ((posSlot >> 1) - 1);
617 
618  /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
619 
620  if (posSlot < kEndPosModelIndex) {
621  prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
622  } else {
623  numDirectBits -= kNumAlignBits;
624  do {
626  range >>= 1;
627  code -= range & (((code - range) >> 31) - 1);
628  /* if (code >= range) code -= range; */
629  } while (--numDirectBits != 0);
630  prob = probs + Align;
631  numDirectBits = kNumAlignBits;
632  }
633  {
634  unsigned i = 1;
635  do {
636  GET_BIT_CHECK(prob + i, i);
637  } while (--numDirectBits != 0);
638  }
639  }
640  }
641  }
642  }
644  return res;
645 }
#define IsRepG0
Definition: LzmaDec.cc:150
#define IsRepG1
Definition: LzmaDec.cc:151
#define GET_BIT_CHECK(p, i)
Definition: LzmaDec.cc:105
#define LenChoice2
Definition: LzmaDec.cc:126
#define LZMA_LIT_SIZE
Definition: LzmaDec.cc:162
#define kLenNumLowSymbols
Definition: LzmaDec.cc:119
#define NORMALIZE_CHECK
Definition: LzmaDec.cc:77
#define kStartPosModelIndex
Definition: LzmaDec.cc:135
#define Literal
Definition: LzmaDec.cc:159
#define SpecPos
Definition: LzmaDec.cc:155
#define GET_BIT2_CHECK(p, i, A0, A1)
Definition: LzmaDec.cc:94
Definition: Electron.h:6
#define RepLenCoder
Definition: LzmaDec.cc:158
ELzmaDummy
Definition: LzmaDec.cc:487
#define LenMid
Definition: LzmaDec.cc:128
#define IsRepG2
Definition: LzmaDec.cc:152
#define LenCoder
Definition: LzmaDec.cc:157
#define IsRep0Long
Definition: LzmaDec.cc:153
#define LenChoice
Definition: LzmaDec.cc:125
unsigned int UInt32
Definition: Types.h:69
#define Align
Definition: LzmaDec.cc:156
#define kEndPosModelIndex
Definition: LzmaDec.cc:136
#define kNumStates
Definition: LzmaDec.cc:132
#define IF_BIT_0_CHECK(p)
Definition: LzmaDec.cc:85
#define LenLow
Definition: LzmaDec.cc:127
#define CLzmaProb
Definition: LzmaDec.h:20
#define kLenNumMidBits
Definition: LzmaDec.cc:120
#define UPDATE_1_CHECK
Definition: LzmaDec.cc:91
#define kNumPosBitsMax
Definition: LzmaDec.cc:115
#define kLenNumMidSymbols
Definition: LzmaDec.cc:121
#define UPDATE_0_CHECK
Definition: LzmaDec.cc:90
#define kNumLenToPosStates
Definition: LzmaDec.cc:140
#define kLenNumHighBits
Definition: LzmaDec.cc:122
#define PosSlot
Definition: LzmaDec.cc:154
#define TREE_DECODE_CHECK(probs, limit, i)
Definition: LzmaDec.cc:106
unsigned char Byte
Definition: Types.h:60
#define kLenNumLowBits
Definition: LzmaDec.cc:118
#define kNumPosSlotBits
Definition: LzmaDec.cc:139
#define LenHigh
Definition: LzmaDec.cc:129
#define IsMatch
Definition: LzmaDec.cc:148
#define kNumLitStates
Definition: LzmaDec.cc:133
#define kNumAlignBits
Definition: LzmaDec.cc:142
#define IsRep
Definition: LzmaDec.cc:149

◆ LzmaDec_WriteRem()

static void LzmaDec_WriteRem ( CLzmaDec p,
SizeT  limit 
)
static

Definition at line 444 of file LzmaDec.cc.

References kMatchSpecLenStart, remoteMonitoring_LASER_era2018_cfg::limit, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_DecodeReal2(), and LzmaDec_DecodeToDic().

444  {
445  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) {
446  Byte *dic = p->dic;
447  SizeT dicPos = p->dicPos;
448  SizeT dicBufSize = p->dicBufSize;
449  unsigned len = p->remainLen;
450  UInt32 rep0 = p->reps[0];
451  if (limit - dicPos < len)
452  len = (unsigned)(limit - dicPos);
453 
454  if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
455  p->checkDicSize = p->prop.dicSize;
456 
457  p->processedPos += len;
458  p->remainLen -= len;
459  while (len-- != 0) {
460  dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
461  dicPos++;
462  }
463  p->dicPos = dicPos;
464  }
465 }
size_t SizeT
Definition: Types.h:97
unsigned int UInt32
Definition: Types.h:69
#define kMatchSpecLenStart
Definition: LzmaDec.cc:146
unsigned char Byte
Definition: Types.h:60

◆ LzmaDecode()

SRes LzmaDecode ( Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
const Byte propData,
unsigned  propSize,
ELzmaFinishMode  finishMode,
ELzmaStatus status,
ISzAlloc alloc 
)

Definition at line 906 of file LzmaDec.cc.

References mps_fire::dest, LZMA_STATUS_NEEDS_MORE_INPUT, LzmaDec_AllocateProbs(), LzmaDec_Construct, LzmaDec_DecodeToDic(), LzmaDec_FreeProbs(), LzmaDec_Init(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, TrackRefitter_38T_cff::src, mps_update::status, SZ_ERROR_INPUT_EOF, and SZ_OK.

914  {
915  CLzmaDec p;
916  SRes res;
917  SizeT inSize = *srcLen;
918  SizeT outSize = *destLen;
919  *srcLen = *destLen = 0;
920  if (inSize < RC_INIT_SIZE)
921  return SZ_ERROR_INPUT_EOF;
922 
924  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
925  if (res != 0)
926  return res;
927  p.dic = dest;
928  p.dicBufSize = outSize;
929 
930  LzmaDec_Init(&p);
931 
932  *srcLen = inSize;
933  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
934 
937 
938  (*destLen) = p.dicPos;
939  LzmaDec_FreeProbs(&p, alloc);
940  return res;
941 }
#define SZ_ERROR_INPUT_EOF
Definition: Types.h:32
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:683
Definition: Electron.h:6
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:879
#define SZ_OK
Definition: Types.h:25
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:67
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:667

◆ LzmaProps_Decode()

SRes LzmaProps_Decode ( CLzmaProps p,
const Byte data,
unsigned  size 
)

Definition at line 842 of file LzmaDec.cc.

References ztail::d, data, LZMA_DIC_MIN, LZMA_PROPS_SIZE, AlCaHLTBitMon_ParallelJobs::p, findQualityFiles::size, SZ_ERROR_UNSUPPORTED, and SZ_OK.

Referenced by LzmaDec_Allocate(), and LzmaDec_AllocateProbs().

842  {
843  UInt32 dicSize;
844  Byte d;
845 
846  if (size < LZMA_PROPS_SIZE)
847  return SZ_ERROR_UNSUPPORTED;
848  else
849  dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
850 
851  if (dicSize < LZMA_DIC_MIN)
852  dicSize = LZMA_DIC_MIN;
853  p->dicSize = dicSize;
854 
855  d = data[0];
856  if (d >= (9 * 5 * 5))
857  return SZ_ERROR_UNSUPPORTED;
858 
859  p->lc = d % 9;
860  d /= 9;
861  p->pb = d / 5;
862  p->lp = d % 5;
863 
864  return SZ_OK;
865 }
size
Write out results.
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:25
unsigned int UInt32
Definition: Types.h:69
#define SZ_OK
Definition: Types.h:25
d
Definition: ztail.py:151
#define LZMA_DIC_MIN
Definition: LzmaDec.cc:170
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned char Byte
Definition: Types.h:60
#define SZ_ERROR_UNSUPPORTED
Definition: Types.h:30