long decoder compatible with round and separate buffers

This commit is contained in:
Yann Collet 2016-11-28 19:59:11 -08:00
parent ce3527ca0c
commit 52e136ed3d
2 changed files with 9 additions and 3 deletions

View File

@ -55,14 +55,16 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
typedef int32_t S32;
typedef uint64_t U64;
typedef int64_t S64;
typedef intptr_t iPtrDiff;
#else
typedef unsigned char BYTE;
typedef unsigned char BYTE;
typedef unsigned short U16;
typedef signed short S16;
typedef unsigned int U32;
typedef signed int S32;
typedef unsigned long long U64;
typedef signed long long S64;
typedef ptrdiff_t iPtrDiff;
#endif

View File

@ -794,6 +794,8 @@ typedef struct {
FSE_DState_t stateML;
size_t prevOffset[ZSTD_REP_NUM];
const BYTE* ptr;
const BYTE* base;
iPtrDiff gotoDict;
} seqState_t;
@ -862,7 +864,8 @@ static seq_t ZSTD_decodeSequenceLong(seqState_t* seqState)
if (MEM_32bits() ||
(totalBits > 64 - 7 - (LLFSELog+MLFSELog+OffFSELog)) ) BIT_reloadDStream(&seqState->DStream);
seq.match = seqState->ptr + seq.litLength - seq.offset; /* only for single memory segment ! */
seq.match = seqState->ptr + seq.litLength - seq.offset; /* single memory segment ! */
if (seq.match < seqState->base) seq.match += seqState->gotoDict; /* what if seq.match underflows ? prefetch is a non issue, but match has now a wrong address */
/* ANS state update */
FSE_updateState(&seqState->stateLL, &seqState->DStream); /* <= 9 bits */
@ -954,7 +957,6 @@ size_t ZSTD_execSequenceLong(BYTE* op,
if (sequence.offset > (size_t)(oLitEnd - base)) {
/* offset beyond prefix */
if (sequence.offset > (size_t)(oLitEnd - vBase)) return ERROR(corruption_detected);
match = dictEnd - (base-match);
if (match + sequence.matchLength <= dictEnd) {
memmove(oLitEnd, match, sequence.matchLength);
return sequenceLength;
@ -1041,6 +1043,8 @@ static size_t ZSTD_decompressSequencesLong(
dctx->fseEntropy = 1;
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) seqState.prevOffset[i] = dctx->rep[i]; }
seqState.ptr = op;
seqState.base = base;
seqState.gotoDict = (iPtrDiff)(dictEnd - base);
CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected);
FSE_initDState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr);
FSE_initDState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr);