contrib/python-zstandard/zstd/common/bitstream.h
changeset 30822 b54a2984cdd4
parent 30434 2e484bdea8c4
child 37495 b1fb341d8a61
equal deleted inserted replaced
30821:7005c03f7387 30822:b54a2984cdd4
   264     if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
   264     if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
   265         bitD->start = (const char*)srcBuffer;
   265         bitD->start = (const char*)srcBuffer;
   266         bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
   266         bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
   267         bitD->bitContainer = MEM_readLEST(bitD->ptr);
   267         bitD->bitContainer = MEM_readLEST(bitD->ptr);
   268         { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
   268         { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
   269           bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
   269           bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
   270           if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
   270           if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
   271     } else {
   271     } else {
   272         bitD->start = (const char*)srcBuffer;
   272         bitD->start = (const char*)srcBuffer;
   273         bitD->ptr   = bitD->start;
   273         bitD->ptr   = bitD->start;
   274         bitD->bitContainer = *(const BYTE*)(bitD->start);
   274         bitD->bitContainer = *(const BYTE*)(bitD->start);
   296     return bitContainer >> start;
   296     return bitContainer >> start;
   297 }
   297 }
   298 
   298 
   299 MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
   299 MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
   300 {
   300 {
   301 #if defined(__BMI__) && defined(__GNUC__)   /* experimental */
   301 #if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008  /* experimental */
   302 #  if defined(__x86_64__)
   302 #  if defined(__x86_64__)
   303     if (sizeof(bitContainer)==8)
   303     if (sizeof(bitContainer)==8)
   304         return _bextr_u64(bitContainer, start, nbBits);
   304         return _bextr_u64(bitContainer, start, nbBits);
   305     else
   305     else
   306 #  endif
   306 #  endif
   365     BIT_skipBits(bitD, nbBits);
   365     BIT_skipBits(bitD, nbBits);
   366     return value;
   366     return value;
   367 }
   367 }
   368 
   368 
   369 /*! BIT_reloadDStream() :
   369 /*! BIT_reloadDStream() :
   370 *   Refill `BIT_DStream_t` from src buffer previously defined (see BIT_initDStream() ).
   370 *   Refill `bitD` from buffer previously set in BIT_initDStream() .
   371 *   This function is safe, it guarantees it will not read beyond src buffer.
   371 *   This function is safe, it guarantees it will not read beyond src buffer.
   372 *   @return : status of `BIT_DStream_t` internal register.
   372 *   @return : status of `BIT_DStream_t` internal register.
   373               if status == unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
   373               if status == BIT_DStream_unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
   374 MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
   374 MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
   375 {
   375 {
   376 	if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))  /* should not happen => corruption detected */
   376 	if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))  /* should not happen => corruption detected */
   377 		return BIT_DStream_overflow;
   377 		return BIT_DStream_overflow;
   378 
   378