ReactOS  0.4.15-dev-5492-g47f3a4e
bitstream.h File Reference
#include "mem.h"
#include "compiler.h"
#include "debug.h"
#include "error_private.h"
Include dependency graph for bitstream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BIT_CStream_t
 
struct  BIT_DStream_t
 

Macros

#define STREAM_ACCUMULATOR_MIN_32   25
 
#define STREAM_ACCUMULATOR_MIN_64   57
 
#define STREAM_ACCUMULATOR_MIN   ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))
 
#define BIT_MASK_SIZE   (sizeof(BIT_mask) / sizeof(BIT_mask[0]))
 

Enumerations

enum  BIT_DStream_status { BIT_DStream_unfinished = 0, BIT_DStream_endOfBuffer = 1, BIT_DStream_completed = 2, BIT_DStream_overflow = 3 }
 

Functions

MEM_STATIC size_t BIT_initCStream (BIT_CStream_t *bitC, void *dstBuffer, size_t dstCapacity)
 
MEM_STATIC void BIT_addBits (BIT_CStream_t *bitC, size_t value, unsigned nbBits)
 
MEM_STATIC void BIT_flushBits (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_closeCStream (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_initDStream (BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
 
MEM_STATIC size_t BIT_readBits (BIT_DStream_t *bitD, unsigned nbBits)
 
MEM_STATIC BIT_DStream_status BIT_reloadDStream (BIT_DStream_t *bitD)
 
MEM_STATIC unsigned BIT_endOfDStream (const BIT_DStream_t *bitD)
 
MEM_STATIC void BIT_addBitsFast (BIT_CStream_t *bitC, size_t value, unsigned nbBits)
 
MEM_STATIC void BIT_flushBitsFast (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_readBitsFast (BIT_DStream_t *bitD, unsigned nbBits)
 
MEM_STATIC unsigned BIT_highbit32 (U32 val)
 
MEM_STATIC size_t BIT_getUpperBits (size_t bitContainer, U32 const start)
 
MEM_STATIC size_t BIT_getMiddleBits (size_t bitContainer, U32 const start, U32 const nbBits)
 
MEM_STATIC size_t BIT_getLowerBits (size_t bitContainer, U32 const nbBits)
 
MEM_STATIC size_t BIT_lookBits (const BIT_DStream_t *bitD, U32 nbBits)
 
MEM_STATIC size_t BIT_lookBitsFast (const BIT_DStream_t *bitD, U32 nbBits)
 
MEM_STATIC void BIT_skipBits (BIT_DStream_t *bitD, U32 nbBits)
 
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast (BIT_DStream_t *bitD)
 

Variables

static const unsigned BIT_mask []
 

Macro Definition Documentation

◆ BIT_MASK_SIZE

#define BIT_MASK_SIZE   (sizeof(BIT_mask) / sizeof(BIT_mask[0]))

Definition at line 174 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN

#define STREAM_ACCUMULATOR_MIN   ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))

Definition at line 47 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN_32

#define STREAM_ACCUMULATOR_MIN_32   25

Definition at line 45 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN_64

#define STREAM_ACCUMULATOR_MIN_64   57

Definition at line 46 of file bitstream.h.

Enumeration Type Documentation

◆ BIT_DStream_status

Enumerator
BIT_DStream_unfinished 
BIT_DStream_endOfBuffer 
BIT_DStream_completed 
BIT_DStream_overflow 

Definition at line 99 of file bitstream.h.

Function Documentation

◆ BIT_addBits()

MEM_STATIC void BIT_addBits ( BIT_CStream_t bitC,
size_t  value,
unsigned  nbBits 
)

BIT_addBits() : can add up to 31 bits into bitC. Note : does not check for register overflow !

Definition at line 198 of file bitstream.h.

200 {
202  assert(nbBits < BIT_MASK_SIZE);
203  assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
204  bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
205  bitC->bitPos += nbBits;
206 }
Definition: pdh_main.c:93
#define assert(x)
Definition: debug.h:53
#define BIT_MASK_SIZE
Definition: bitstream.h:174
static const unsigned BIT_mask[]
Definition: bitstream.h:167
size_t bitContainer
Definition: bitstream.h:58
#define MEM_STATIC_ASSERT(c)
Definition: mem.h:47
unsigned bitPos
Definition: bitstream.h:59

Referenced by ZSTD_encodeSequences_body().

◆ BIT_addBitsFast()

MEM_STATIC void BIT_addBitsFast ( BIT_CStream_t bitC,
size_t  value,
unsigned  nbBits 
)

BIT_addBitsFast() : works only if value is clean, meaning all high bits above nbBits are 0

Definition at line 211 of file bitstream.h.

213 {
214  assert((value>>nbBits) == 0);
215  assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
216  bitC->bitContainer |= value << bitC->bitPos;
217  bitC->bitPos += nbBits;
218 }
Definition: pdh_main.c:93
#define assert(x)
Definition: debug.h:53
size_t bitContainer
Definition: bitstream.h:58
unsigned bitPos
Definition: bitstream.h:59

Referenced by BIT_closeCStream(), and HUF_encodeSymbol().

◆ BIT_closeCStream()

MEM_STATIC size_t BIT_closeCStream ( BIT_CStream_t bitC)

BIT_closeCStream() :

Returns
: size of CStream, in bytes, or 0 if it could not fit into dstBuffer

Definition at line 254 of file bitstream.h.

255 {
256  BIT_addBitsFast(bitC, 1, 1); /* endMark */
257  BIT_flushBits(bitC);
258  if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
259  return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
260 }
MEM_STATIC void BIT_flushBits(BIT_CStream_t *bitC)
Definition: bitstream.h:239
unsigned bitPos
Definition: bitstream.h:59
char * ptr
Definition: bitstream.h:61
char * endPtr
Definition: bitstream.h:62
char * startPtr
Definition: bitstream.h:60
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t *bitC, size_t value, unsigned nbBits)
Definition: bitstream.h:211

Referenced by FSE_compress_usingCTable_generic(), HUF_compress1X_usingCTable_internal_body(), and ZSTD_encodeSequences_body().

◆ BIT_endOfDStream()

MEM_STATIC unsigned BIT_endOfDStream ( const BIT_DStream_t DStream)

BIT_endOfDStream() :

Returns
: 1 if DStream has exactly reached its end (all bits consumed).

Definition at line 445 of file bitstream.h.

446 {
447  return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
448 }
const char * start
Definition: bitstream.h:95
const char * ptr
Definition: bitstream.h:94
size_t bitContainer
Definition: bitstream.h:92
unsigned bitsConsumed
Definition: bitstream.h:93

Referenced by HUF_decompress1X1_usingDTable_internal_body(), HUF_decompress1X2_usingDTable_internal_body(), HUF_decompress4X1_usingDTable_internal_body(), and HUF_decompress4X2_usingDTable_internal_body().

◆ BIT_flushBits()

MEM_STATIC void BIT_flushBits ( BIT_CStream_t bitC)

BIT_flushBits() : assumption : bitContainer has not overflowed safe version; check for buffer overflow, and prevents it. note : does not signal buffer overflow. overflow will be revealed later on using BIT_closeCStream()

Definition at line 239 of file bitstream.h.

240 {
241  size_t const nbBytes = bitC->bitPos >> 3;
242  assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
243  assert(bitC->ptr <= bitC->endPtr);
244  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
245  bitC->ptr += nbBytes;
246  if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
247  bitC->bitPos &= 7;
248  bitC->bitContainer >>= nbBytes*8;
249 }
#define assert(x)
Definition: debug.h:53
size_t bitContainer
Definition: bitstream.h:58
MEM_STATIC void MEM_writeLEST(void *memPtr, size_t val)
Definition: mem.h:386
unsigned bitPos
Definition: bitstream.h:59
char * ptr
Definition: bitstream.h:61
char * endPtr
Definition: bitstream.h:62

Referenced by BIT_closeCStream(), and ZSTD_encodeSequences_body().

◆ BIT_flushBitsFast()

MEM_STATIC void BIT_flushBitsFast ( BIT_CStream_t bitC)

BIT_flushBitsFast() : assumption : bitContainer has not overflowed unsafe version; does not check buffer overflow

Definition at line 223 of file bitstream.h.

224 {
225  size_t const nbBytes = bitC->bitPos >> 3;
226  assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
227  assert(bitC->ptr <= bitC->endPtr);
228  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
229  bitC->ptr += nbBytes;
230  bitC->bitPos &= 7;
231  bitC->bitContainer >>= nbBytes*8;
232 }
#define assert(x)
Definition: debug.h:53
size_t bitContainer
Definition: bitstream.h:58
MEM_STATIC void MEM_writeLEST(void *memPtr, size_t val)
Definition: mem.h:386
unsigned bitPos
Definition: bitstream.h:59
char * ptr
Definition: bitstream.h:61
char * endPtr
Definition: bitstream.h:62

◆ BIT_getLowerBits()

MEM_STATIC size_t BIT_getLowerBits ( size_t  bitContainer,
U32 const  nbBits 
)

Definition at line 333 of file bitstream.h.

334 {
335  assert(nbBits < BIT_MASK_SIZE);
336  return bitContainer & BIT_mask[nbBits];
337 }
#define assert(x)
Definition: debug.h:53
#define BIT_MASK_SIZE
Definition: bitstream.h:174
static const unsigned BIT_mask[]
Definition: bitstream.h:167

◆ BIT_getMiddleBits()

MEM_STATIC size_t BIT_getMiddleBits ( size_t  bitContainer,
U32 const  start,
U32 const  nbBits 
)

Definition at line 325 of file bitstream.h.

326 {
327  U32 const regMask = sizeof(bitContainer)*8 - 1;
328  /* if start > regMask, bitstream is corrupted, and result is undefined */
329  assert(nbBits < BIT_MASK_SIZE);
330  return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
331 }
#define assert(x)
Definition: debug.h:53
#define BIT_MASK_SIZE
Definition: bitstream.h:174
static const unsigned BIT_mask[]
Definition: bitstream.h:167
GLuint start
Definition: gl.h:1545
unsigned int U32
Definition: xxhash.c:195

Referenced by BIT_lookBits().

◆ BIT_getUpperBits()

MEM_STATIC size_t BIT_getUpperBits ( size_t  bitContainer,
U32 const  start 
)

Definition at line 320 of file bitstream.h.

321 {
322  return bitContainer >> start;
323 }
GLuint start
Definition: gl.h:1545

◆ BIT_highbit32()

MEM_STATIC unsigned BIT_highbit32 ( U32  val)

Definition at line 139 of file bitstream.h.

140 {
141  assert(val != 0);
142  {
143 # if defined(_MSC_VER) /* Visual */
144  unsigned long r=0;
145  return _BitScanReverse ( &r, val ) ? (unsigned)r : 0;
146 # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
147  return __builtin_clz (val) ^ 31;
148 # elif defined(__ICCARM__) /* IAR Intrinsic */
149  return 31 - __CLZ(val);
150 # else /* Software version */
151  static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
152  11, 14, 16, 18, 22, 25, 3, 30,
153  8, 12, 20, 28, 15, 17, 24, 7,
154  19, 27, 23, 6, 26, 5, 4, 31 };
155  U32 v = val;
156  v |= v >> 1;
157  v |= v >> 2;
158  v |= v >> 4;
159  v |= v >> 8;
160  v |= v >> 16;
161  return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
162 # endif
163  }
164 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define assert(x)
Definition: debug.h:53
GLuint GLfloat * val
Definition: glext.h:7180
const GLdouble * v
Definition: gl.h:2040
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:180
unsigned int U32
Definition: xxhash.c:195
static unsigned(__cdecl *hash_bstr)(bstr_t s)

Referenced by BIT_initDStream(), FSE_buildCTable_wksp(), FSE_buildDTable(), FSE_minTableLog(), FSE_optimalTableLog_internal(), HUF_readStats(), HUF_setMaxHeight(), and HUF_sort().

◆ BIT_initCStream()

MEM_STATIC size_t BIT_initCStream ( BIT_CStream_t bitC,
void startPtr,
size_t  dstCapacity 
)

BIT_initCStream() : dstCapacity must be > sizeof(size_t)

Returns
: 0 if success, otherwise an error code (can be tested using ERR_isError())

Definition at line 183 of file bitstream.h.

185 {
186  bitC->bitContainer = 0;
187  bitC->bitPos = 0;
188  bitC->startPtr = (char*)startPtr;
189  bitC->ptr = bitC->startPtr;
190  bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
191  if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
192  return 0;
193 }
#define ERROR(name)
Definition: error_private.h:53
size_t bitContainer
Definition: bitstream.h:58
unsigned bitPos
Definition: bitstream.h:59
char * ptr
Definition: bitstream.h:61
char * endPtr
Definition: bitstream.h:62
char * startPtr
Definition: bitstream.h:60

Referenced by FSE_compress_usingCTable_generic(), HUF_compress1X_usingCTable_internal_body(), and ZSTD_encodeSequences_body().

◆ BIT_initDStream()

MEM_STATIC size_t BIT_initDStream ( BIT_DStream_t bitD,
const void srcBuffer,
size_t  srcSize 
)

BIT_initDStream() : Initialize a BIT_DStream_t. bitD : a pointer to an already allocated BIT_DStream_t structure. srcSize must be the exact size of the bitStream, in bytes.

Returns
: size of stream (== srcSize), or an errorCode if a problem is detected

Definition at line 272 of file bitstream.h.

273 {
274  if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
275 
276  bitD->start = (const char*)srcBuffer;
277  bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
278 
279  if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */
280  bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
281  bitD->bitContainer = MEM_readLEST(bitD->ptr);
282  { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
283  bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
284  if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
285  } else {
286  bitD->ptr = bitD->start;
287  bitD->bitContainer = *(const BYTE*)(bitD->start);
288  switch(srcSize)
289  {
290  case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
291  /* fall-through */
292 
293  case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
294  /* fall-through */
295 
296  case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
297  /* fall-through */
298 
299  case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
300  /* fall-through */
301 
302  case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
303  /* fall-through */
304 
305  case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
306  /* fall-through */
307 
308  default: break;
309  }
310  { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
311  bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
312  if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */
313  }
314  bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
315  }
316 
317  return srcSize;
318 }
#define ERROR(name)
Definition: error_private.h:53
MEM_STATIC size_t MEM_readLEST(const void *memPtr)
Definition: mem.h:378
const char * start
Definition: bitstream.h:95
MEM_STATIC unsigned BIT_highbit32(U32 val)
Definition: bitstream.h:139
const char * ptr
Definition: bitstream.h:94
__kernel_size_t size_t
Definition: linux.h:237
size_t bitContainer
Definition: bitstream.h:92
unsigned bitsConsumed
Definition: bitstream.h:93
const char * limitPtr
Definition: bitstream.h:96
unsigned char BYTE
Definition: xxhash.c:193
#define memset(x, y, z)
Definition: compat.h:39
unsigned int U32
Definition: xxhash.c:195

Referenced by FSE_decompress_usingDTable_generic(), HUF_decompress1X1_usingDTable_internal_body(), HUF_decompress1X2_usingDTable_internal_body(), HUF_decompress4X1_usingDTable_internal_body(), and HUF_decompress4X2_usingDTable_internal_body().

◆ BIT_lookBits()

MEM_STATIC size_t BIT_lookBits ( const BIT_DStream_t bitD,
U32  nbBits 
)

BIT_lookBits() : Provides next n bits from local register. local register is not modified. On 32-bits, maxNbBits==24. On 64-bits, maxNbBits==56.

Returns
: value extracted

Definition at line 345 of file bitstream.h.

346 {
347  /* arbitrate between double-shift and shift+mask */
348 #if 1
349  /* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
350  * bitstream is likely corrupted, and result is undefined */
351  return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits);
352 #else
353  /* this code path is slower on my os-x laptop */
354  U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
355  return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask);
356 #endif
357 }
MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
Definition: bitstream.h:325
size_t bitContainer
Definition: bitstream.h:92
unsigned bitsConsumed
Definition: bitstream.h:93
unsigned int U32
Definition: xxhash.c:195

Referenced by BIT_readBits().

◆ BIT_lookBitsFast()

MEM_STATIC size_t BIT_lookBitsFast ( const BIT_DStream_t bitD,
U32  nbBits 
)

BIT_lookBitsFast() : unsafe version; only works if nbBits >= 1

Definition at line 361 of file bitstream.h.

362 {
363  U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
364  assert(nbBits >= 1);
365  return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
366 }
#define assert(x)
Definition: debug.h:53
size_t bitContainer
Definition: bitstream.h:92
unsigned bitsConsumed
Definition: bitstream.h:93
unsigned int U32
Definition: xxhash.c:195

Referenced by BIT_readBitsFast(), HUF_decodeLastSymbolX2(), HUF_decodeSymbolX1(), and HUF_decodeSymbolX2().

◆ BIT_readBits()

MEM_STATIC size_t BIT_readBits ( BIT_DStream_t bitD,
unsigned  nbBits 
)

BIT_readBits() : Read (consume) next n bits from local register and update. Pay attention to not read more than nbBits contained into local register.

Returns
: extracted value.

Definition at line 377 of file bitstream.h.

378 {
379  size_t const value = BIT_lookBits(bitD, nbBits);
380  BIT_skipBits(bitD, nbBits);
381  return value;
382 }
Definition: pdh_main.c:93
MEM_STATIC void BIT_skipBits(BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:368
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:345
GLsizei const GLfloat * value
Definition: glext.h:6069

◆ BIT_readBitsFast()

MEM_STATIC size_t BIT_readBitsFast ( BIT_DStream_t bitD,
unsigned  nbBits 
)

BIT_readBitsFast() : unsafe version; only works only if nbBits >= 1

Definition at line 386 of file bitstream.h.

387 {
388  size_t const value = BIT_lookBitsFast(bitD, nbBits);
389  assert(nbBits >= 1);
390  BIT_skipBits(bitD, nbBits);
391  return value;
392 }
Definition: pdh_main.c:93
#define assert(x)
Definition: debug.h:53
MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:361
MEM_STATIC void BIT_skipBits(BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:368
GLsizei const GLfloat * value
Definition: glext.h:6069

◆ BIT_reloadDStream()

MEM_STATIC BIT_DStream_status BIT_reloadDStream ( BIT_DStream_t bitD)

BIT_reloadDStream() : Refill bitD from buffer previously set in BIT_initDStream() . This function is safe, it guarantees it will not read beyond src buffer.

Returns
: status of BIT_DStream_t internal register. when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits

Definition at line 416 of file bitstream.h.

417 {
418  if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
419  return BIT_DStream_overflow;
420 
421  if (bitD->ptr >= bitD->limitPtr) {
422  return BIT_reloadDStreamFast(bitD);
423  }
424  if (bitD->ptr == bitD->start) {
425  if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
426  return BIT_DStream_completed;
427  }
428  /* start < ptr < limitPtr */
429  { U32 nbBytes = bitD->bitsConsumed >> 3;
431  if (bitD->ptr - nbBytes < bitD->start) {
432  nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */
434  }
435  bitD->ptr -= nbBytes;
436  bitD->bitsConsumed -= nbBytes*8;
437  bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
438  return result;
439  }
440 }
GLuint64EXT * result
Definition: glext.h:11304
MEM_STATIC size_t MEM_readLEST(const void *memPtr)
Definition: mem.h:378
const char * start
Definition: bitstream.h:95
const char * ptr
Definition: bitstream.h:94
BIT_DStream_status
Definition: bitstream.h:99
size_t bitContainer
Definition: bitstream.h:92
unsigned bitsConsumed
Definition: bitstream.h:93
const char * limitPtr
Definition: bitstream.h:96
GLuint start
Definition: gl.h:1545
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t *bitD)
Definition: bitstream.h:400
unsigned int U32
Definition: xxhash.c:195

Referenced by FSE_decompress_usingDTable_generic(), HUF_decodeStreamX1(), and HUF_decodeStreamX2().

◆ BIT_reloadDStreamFast()

MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast ( BIT_DStream_t bitD)

BIT_reloadDStreamFast() : Similar to BIT_reloadDStream(), but with two differences:

  1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
  2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this point you must use BIT_reloadDStream() to reload.

Definition at line 400 of file bitstream.h.

401 {
402  if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403  return BIT_DStream_overflow;
404  assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
405  bitD->ptr -= bitD->bitsConsumed >> 3;
406  bitD->bitsConsumed &= 7;
407  bitD->bitContainer = MEM_readLEST(bitD->ptr);
408  return BIT_DStream_unfinished;
409 }
MEM_STATIC size_t MEM_readLEST(const void *memPtr)
Definition: mem.h:378
#define assert(x)
Definition: debug.h:53
const char * ptr
Definition: bitstream.h:94
size_t bitContainer
Definition: bitstream.h:92
#define UNLIKELY(x)
Definition: compiler.h:162
unsigned bitsConsumed
Definition: bitstream.h:93
const char * limitPtr
Definition: bitstream.h:96

Referenced by BIT_reloadDStream(), HUF_decompress4X1_usingDTable_internal_body(), and HUF_decompress4X2_usingDTable_internal_body().

◆ BIT_skipBits()

MEM_STATIC void BIT_skipBits ( BIT_DStream_t bitD,
U32  nbBits 
)

Definition at line 368 of file bitstream.h.

369 {
370  bitD->bitsConsumed += nbBits;
371 }
unsigned bitsConsumed
Definition: bitstream.h:93

Referenced by BIT_readBits(), BIT_readBitsFast(), HUF_decodeLastSymbolX2(), HUF_decodeSymbolX1(), and HUF_decodeSymbolX2().

Variable Documentation

◆ BIT_mask

const unsigned BIT_mask[]
static
Initial value:
= {
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, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF,
0x3FFFFFFF, 0x7FFFFFFF}

Definition at line 167 of file bitstream.h.

Referenced by BIT_addBits(), BIT_getLowerBits(), and BIT_getMiddleBits().