diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index ee57b853..a854aaf7 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -627,48 +627,45 @@ typedef struct { static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls) { /* Literal length */ - U32 const litCode = FSE_peekSymbol(&(seqState->stateLL)); - { static const U32 LL_base[MaxLL+1] = { + U32 const llCode = FSE_peekSymbol(&(seqState->stateLL)); + U32 const mlCode = FSE_peekSymbol(&(seqState->stateML)); + U32 const ofCode = FSE_peekSymbol(&(seqState->stateOffb)); /* <= maxOff, by table construction */ + + U32 const llBits = LL_bits[llCode]; + U32 const mlBits = ML_bits[mlCode]; + U32 const ofBits = ofCode ? ofCode-1 : 0; + + static const U32 LL_base[MaxLL+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 28, 32, 40, 48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000 }; - seq->litLength = LL_base[litCode] + BIT_readBits(&(seqState->DStream), LL_bits[litCode]); - } - /* MatchLength */ - { static const U32 ML_base[MaxML+1] = { + static const U32 ML_base[MaxML+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 36, 38, 40, 44, 48, 56, 64, 80, 96, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000 }; - U32 const mlCode = FSE_peekSymbol(&(seqState->stateML)); - seq->matchLength = ML_base[mlCode] + BIT_readBits(&(seqState->DStream), ML_bits[mlCode]) + mls; - } - /* Offset */ - { static const U32 offsetPrefix[MaxOff+1] = { + static const U32 OF_base[MaxOff+1] = { 1 /*fake*/, 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000, 0x1000000, 0x2000000, 0x4000000, /*fake*/ 1, 1, 1, 1 }; - U32 const offsetCode = FSE_peekSymbol(&(seqState->stateOffb)); /* <= maxOff, by table construction */ - U32 const nbBits = offsetCode ? offsetCode-1 : 0; - size_t const offset = offsetCode ? offsetPrefix[offsetCode] + BIT_readBits(&(seqState->DStream), nbBits) : - litCode ? seq->offset : seqState->prevOffset; - if (offsetCode | !litCode) seqState->prevOffset = seq->offset; /* cmove */ + + seq->litLength = LL_base[llCode] + BIT_readBits(&(seqState->DStream), llBits); + seq->matchLength = ML_base[mlCode] + BIT_readBits(&(seqState->DStream), mlBits) + mls; + + /* Offset */ + { size_t const offset = ofCode ? OF_base[ofCode] + BIT_readBits(&(seqState->DStream), ofBits) : + llCode ? seq->offset : seqState->prevOffset; + if (ofCode | !llCode) seqState->prevOffset = seq->offset; /* cmove */ seq->offset = offset; - if (MEM_32bits()) BIT_reloadDStream(&(seqState->DStream)); } /* ANS state update */ FSE_updateState(&(seqState->stateLL), &(seqState->DStream)); - if (MEM_32bits()) BIT_reloadDStream(&(seqState->DStream)); - FSE_updateState(&(seqState->stateML), &(seqState->DStream)); - if (MEM_32bits()) BIT_reloadDStream(&(seqState->DStream)); - FSE_updateState(&(seqState->stateOffb), &(seqState->DStream)); - if (MEM_32bits()) BIT_reloadDStream(&(seqState->DStream)); }