minor optimization (DSpeed 665)

This commit is contained in:
Yann Collet 2016-03-23 14:09:51 +01:00
parent 2512597576
commit 3c017867de
2 changed files with 15 additions and 4 deletions

View File

@ -285,6 +285,17 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
return srcSize;
}
MEM_STATIC size_t BIT_getUpperBits(size_t bitD, U32 const start)
{
return bitD >> start;
}
MEM_STATIC size_t BIT_getNBits(size_t bitD, U32 const nbBits, U32 const start)
{
static const unsigned mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF }; /* up to 26 bits */
return (bitD >> start) & mask[nbBits];
}
MEM_STATIC size_t BIT_consumeFirstBits(size_t* bitDPtr, U32 const nbBits)
{
static const unsigned mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF }; /* up to 26 bits */

View File

@ -635,7 +635,7 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
U32 const mlBits = ML_bits[mlCode];
U32 const ofBits = ofCode ? ofCode-1 : 0;
size_t allBits = BIT_readBits(&(seqState->DStream), llBits+mlBits+ofBits);
size_t const allBits = BIT_readBits(&(seqState->DStream), llBits+mlBits+ofBits);
static const U32 LL_base[MaxLL+1] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@ -655,9 +655,9 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
0x800000, 0x1000000, 0x2000000, 0x4000000, /*fake*/ 1, 1, 1, 1 };
/* sequence */
seq->litLength = LL_base[llCode] + BIT_consumeFirstBits(&allBits, llBits);
seq->matchLength = ML_base[mlCode] + BIT_consumeFirstBits(&allBits, mlBits) + mls;
{ size_t const offset = ofCode ? OF_base[ofCode] + BIT_consumeFirstBits(&allBits, ofBits) :
seq->litLength = LL_base[llCode] + BIT_getNBits(allBits, llBits, 0);
seq->matchLength = ML_base[mlCode] + BIT_getNBits(allBits, mlBits, llBits) + mls;
{ size_t const offset = ofCode ? OF_base[ofCode] + BIT_getUpperBits(allBits, llBits+mlBits) :
llCode ? seq->offset : seqState->prevOffset;
if (ofCode | !llCode) seqState->prevOffset = seq->offset; /* cmove */
seq->offset = offset;