shared const BIT_mask

dev
Yann Collet 2016-03-23 14:18:37 +01:00
parent 3c017867de
commit 6cf45dac81
2 changed files with 11 additions and 13 deletions

View File

@ -141,7 +141,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
/*-************************************************************** /*-**************************************************************
* Helper functions * Internal functions
****************************************************************/ ****************************************************************/
MEM_STATIC unsigned BIT_highbit32 (register U32 val) MEM_STATIC unsigned BIT_highbit32 (register U32 val)
{ {
@ -165,6 +165,9 @@ MEM_STATIC unsigned BIT_highbit32 (register U32 val)
# endif # endif
} }
/*===== Local Constants =====*/
static const unsigned BIT_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 */
/*-************************************************************** /*-**************************************************************
* bitStream encoding * bitStream encoding
@ -189,8 +192,7 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* startPtr, size_t ds
Does not check for register overflow ! */ Does not check for register overflow ! */
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits) MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned 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 */ bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
bitC->bitContainer |= (value & mask[nbBits]) << bitC->bitPos;
bitC->bitPos += nbBits; bitC->bitPos += nbBits;
} }
@ -290,18 +292,14 @@ MEM_STATIC size_t BIT_getUpperBits(size_t bitD, U32 const start)
return bitD >> start; return bitD >> start;
} }
MEM_STATIC size_t BIT_getNBits(size_t bitD, U32 const nbBits, U32 const start) MEM_STATIC size_t BIT_getMiddleBits(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) & BIT_mask[nbBits];
return (bitD >> start) & mask[nbBits];
} }
MEM_STATIC size_t BIT_consumeFirstBits(size_t* bitDPtr, U32 const nbBits) MEM_STATIC size_t BIT_getLowerBits(size_t bitD, 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 */ return bitD & BIT_mask[nbBits];
size_t const result = *bitDPtr & mask[nbBits];
*bitDPtr >>= nbBits;
return result;
} }
/*! BIT_lookBits() : /*! BIT_lookBits() :

View File

@ -655,8 +655,8 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
0x800000, 0x1000000, 0x2000000, 0x4000000, /*fake*/ 1, 1, 1, 1 }; 0x800000, 0x1000000, 0x2000000, 0x4000000, /*fake*/ 1, 1, 1, 1 };
/* sequence */ /* sequence */
seq->litLength = LL_base[llCode] + BIT_getNBits(allBits, llBits, 0); seq->litLength = LL_base[llCode] + BIT_getLowerBits(allBits, llBits);
seq->matchLength = ML_base[mlCode] + BIT_getNBits(allBits, mlBits, llBits) + mls; seq->matchLength = ML_base[mlCode] + mls + BIT_getMiddleBits(allBits, mlBits, llBits);
{ size_t const offset = ofCode ? OF_base[ofCode] + BIT_getUpperBits(allBits, llBits+mlBits) : { size_t const offset = ofCode ? OF_base[ofCode] + BIT_getUpperBits(allBits, llBits+mlBits) :
llCode ? seq->offset : seqState->prevOffset; llCode ? seq->offset : seqState->prevOffset;
if (ofCode | !llCode) seqState->prevOffset = seq->offset; /* cmove */ if (ofCode | !llCode) seqState->prevOffset = seq->offset; /* cmove */