#include "Precomp.h"
#include <string.h>
#if defined(SHOW_STAT) || defined(SHOW_STAT2)
#include <stdio.h>
#endif
#include "CpuArch.h"
#include "LzmaEnc.h"
#include "LzFind.h"
#ifndef _7ZIP_ST
#include "LzFindMt.h"
#endif
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,
ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
void LzmaEnc_Finish(CLzmaEncHandle pp);
void LzmaEnc_SaveState(CLzmaEncHandle pp);
void LzmaEnc_RestoreState(CLzmaEncHandle pp);
#ifdef SHOW_STAT
static unsigned g_STAT_OFFSET = 0;
#endif
#define kLzmaMaxHistorySize …
#define kNumTopBits …
#define kTopValue …
#define kNumBitModelTotalBits …
#define kBitModelTotal …
#define kNumMoveBits …
#define kProbInitValue …
#define kNumMoveReducingBits …
#define kNumBitPriceShiftBits …
#define REP_LEN_COUNT …
void LzmaEncProps_Init(CLzmaEncProps *p)
{ … }
void LzmaEncProps_Normalize(CLzmaEncProps *p)
{ … }
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
{ … }
#if defined(MY_CPU_ARM_OR_ARM64)
#if (defined(__clang__) && (__clang_major__ >= 6)) \
|| (defined(__GNUC__) && (__GNUC__ >= 6))
#define LZMA_LOG_BSR
#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
#define LZMA_LOG_BSR
#endif
#endif
#ifdef LZMA_LOG_BSR
#if defined(__clang__) \
|| defined(__GNUC__)
#define MY_clz …
#else
#ifdef MY_CPU_ARM_OR_ARM64
#define MY_clz …
#else
#define BSR2_RET …
#endif
#endif
#ifndef BSR2_RET
#define BSR2_RET …
#endif
unsigned GetPosSlot1(UInt32 pos);
unsigned GetPosSlot1(UInt32 pos)
{
unsigned res;
BSR2_RET(pos, res);
return res;
}
#define GetPosSlot2 …
#define GetPosSlot …
#else
#define kNumLogBits …
#define kDicLogSizeMaxCompress …
static void LzmaEnc_FastPosInit(Byte *g_FastPos)
{ … }
#define BSR2_RET(pos, res) …
#define GetPosSlot1(pos) …
#define GetPosSlot2(pos, res) …
#define GetPosSlot(pos, res) …
#endif
#define LZMA_NUM_REPS …
CState;
CExtra;
COptimal;
#define kNumOpts …
#define kPackReserve …
#define kNumLenToPosStates …
#define kNumPosSlotBits …
#define kDicLogSizeMax …
#define kDistTableSizeMax …
#define kNumAlignBits …
#define kAlignTableSize …
#define kAlignMask …
#define kStartPosModelIndex …
#define kEndPosModelIndex …
#define kNumFullDistances …
CLzmaProb;
#define LZMA_PB_MAX …
#define LZMA_LC_MAX …
#define LZMA_LP_MAX …
#define LZMA_NUM_PB_STATES_MAX …
#define kLenNumLowBits …
#define kLenNumLowSymbols …
#define kLenNumHighBits …
#define kLenNumHighSymbols …
#define kLenNumSymbolsTotal …
#define LZMA_MATCH_LEN_MIN …
#define LZMA_MATCH_LEN_MAX …
#define kNumStates …
CLenEnc;
CLenPriceEnc;
#define GET_PRICE_LEN(p, posState, len) …
CRangeEnc;
CSaveState;
CProbPrice;
CLzmaEnc;
#define MFB …
#define COPY_ARR(dest, src, arr) …
void LzmaEnc_SaveState(CLzmaEncHandle pp)
{ … }
void LzmaEnc_RestoreState(CLzmaEncHandle pp)
{ … }
SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
{ … }
void LzmaEnc_SetDataSize(CLzmaEncHandle pp, UInt64 expectedDataSiize)
{ … }
#define kState_Start …
#define kState_LitAfterMatch …
#define kState_LitAfterRep …
#define kState_MatchAfterLit …
#define kState_RepAfterLit …
static const Byte kLiteralNextStates[kNumStates] = …;
static const Byte kMatchNextStates[kNumStates] = …;
static const Byte kRepNextStates[kNumStates] = …;
static const Byte kShortRepNextStates[kNumStates]= …;
#define IsLitState(s) …
#define GetLenToPosState2(len) …
#define GetLenToPosState(len) …
#define kInfinityPrice …
static void RangeEnc_Construct(CRangeEnc *p)
{ … }
#define RangeEnc_GetProcessed(p) …
#define RangeEnc_GetProcessed_sizet(p) …
#define RC_BUF_SIZE …
static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
{ … }
static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
{ … }
static void RangeEnc_Init(CRangeEnc *p)
{ … }
MY_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p)
{ … }
MY_NO_INLINE static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
{ … }
static void RangeEnc_FlushData(CRangeEnc *p)
{ … }
#define RC_NORM(p) …
#define RC_BIT_PRE(p, prob) …
#ifdef _LZMA_ENC_USE_BRANCH
#define RC_BIT …
#else
#define RC_BIT(p, prob, bit) …
#endif
#define RC_BIT_0_BASE(p, prob) …
#define RC_BIT_1_BASE(p, prob) … \
#define RC_BIT_0(p, prob) …
#define RC_BIT_1(p, prob) …
static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
{ … }
static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
{ … }
static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte)
{ … }
static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
{ … }
#define GET_PRICE(prob, bit) …
#define GET_PRICEa(prob, bit) …
#define GET_PRICE_0(prob) …
#define GET_PRICE_1(prob) …
#define GET_PRICEa_0(prob) …
#define GET_PRICEa_1(prob) …
static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
{ … }
static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
{ … }
static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, unsigned sym)
{ … }
static void LenEnc_Init(CLenEnc *p)
{ … }
static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
{ … }
static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *prices, const CProbPrice *ProbPrices)
{ … }
MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables(
CLenPriceEnc *p,
unsigned numPosStates,
const CLenEnc *enc,
const CProbPrice *ProbPrices)
{ … }
#define MOVE_POS(p, num) …
static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
{ … }
#define MARK_LIT …
#define MakeAs_Lit(p) …
#define MakeAs_ShortRep(p) …
#define IsShortRep(p) …
#define GetPrice_ShortRep(p, state, posState) …
#define GetPrice_Rep_0(p, state, posState) …
MY_FORCE_INLINE
static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
{ … }
static unsigned Backward(CLzmaEnc *p, unsigned cur)
{ … }
#define LIT_PROBS(pos, prevByte) …
static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
{ … }
#define ChangePair(smallDist, bigDist) …
static unsigned GetOptimumFast(CLzmaEnc *p)
{ … }
static void WriteEndMarker(CLzmaEnc *p, unsigned posState)
{ … }
static SRes CheckErrors(CLzmaEnc *p)
{ … }
MY_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
{ … }
MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
{ … }
MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
{ … }
static void LzmaEnc_Construct(CLzmaEnc *p)
{ … }
CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
{ … }
static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
{ … }
static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
MY_NO_INLINE
static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpackSize)
{ … }
#define kBigHashDicLimit …
static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
static void LzmaEnc_Init(CLzmaEnc *p)
{ … }
static void LzmaEnc_InitPrices(CLzmaEnc *p)
{ … }
static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
ISeqInStream *inStream, UInt32 keepWindowSize,
ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
{ … }
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
void LzmaEnc_Finish(CLzmaEncHandle pp)
{ … }
CLzmaEnc_SeqOutStreamBuf;
static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size)
{ … }
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
{ … }
SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
{ … }
MY_NO_INLINE
static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
{ … }
SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
{ … }
unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle pp)
{ … }
SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ … }