ReactOS  0.4.15-dev-5500-g82cf6c2
zstd_decompress_block.h File Reference
#include <stddef.h>
#include "zstd.h"
#include "zstd_internal.h"
#include "zstd_decompress_internal.h"
Include dependency graph for zstd_decompress_block.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

size_t ZSTD_decompressBlock_internal (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
 
void ZSTD_buildFSETable (ZSTD_seqSymbol *dt, const short *normalizedCounter, unsigned maxSymbolValue, const U32 *baseValue, const U32 *nbAdditionalBits, unsigned tableLog)
 

Function Documentation

◆ ZSTD_buildFSETable()

void ZSTD_buildFSETable ( ZSTD_seqSymbol dt,
const short normalizedCounter,
unsigned  maxSymbolValue,
const U32 baseValue,
const U32 nbAdditionalBits,
unsigned  tableLog 
)

Definition at line 368 of file zstd_decompress_block.c.

372 {
373  ZSTD_seqSymbol* const tableDecode = dt+1;
374  U16 symbolNext[MaxSeq+1];
375 
376  U32 const maxSV1 = maxSymbolValue + 1;
377  U32 const tableSize = 1 << tableLog;
378  U32 highThreshold = tableSize-1;
379 
380  /* Sanity Checks */
381  assert(maxSymbolValue <= MaxSeq);
382  assert(tableLog <= MaxFSELog);
383 
384  /* Init, lay down lowprob symbols */
385  { ZSTD_seqSymbol_header DTableH;
386  DTableH.tableLog = tableLog;
387  DTableH.fastMode = 1;
388  { S16 const largeLimit= (S16)(1 << (tableLog-1));
389  U32 s;
390  for (s=0; s<maxSV1; s++) {
391  if (normalizedCounter[s]==-1) {
392  tableDecode[highThreshold--].baseValue = s;
393  symbolNext[s] = 1;
394  } else {
395  if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
396  assert(normalizedCounter[s]>=0);
397  symbolNext[s] = (U16)normalizedCounter[s];
398  } } }
399  memcpy(dt, &DTableH, sizeof(DTableH));
400  }
401 
402  /* Spread symbols */
403  { U32 const tableMask = tableSize-1;
404  U32 const step = FSE_TABLESTEP(tableSize);
405  U32 s, position = 0;
406  for (s=0; s<maxSV1; s++) {
407  int i;
408  for (i=0; i<normalizedCounter[s]; i++) {
409  tableDecode[position].baseValue = s;
410  position = (position + step) & tableMask;
411  while (position > highThreshold) position = (position + step) & tableMask; /* lowprob area */
412  } }
413  assert(position == 0); /* position must reach all cells once, otherwise normalizedCounter is incorrect */
414  }
415 
416  /* Build Decoding table */
417  { U32 u;
418  for (u=0; u<tableSize; u++) {
419  U32 const symbol = tableDecode[u].baseValue;
420  U32 const nextState = symbolNext[symbol]++;
421  tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
422  tableDecode[u].nextState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
423  assert(nbAdditionalBits[symbol] < 255);
424  tableDecode[u].nbAdditionalBits = (BYTE)nbAdditionalBits[symbol];
425  tableDecode[u].baseValue = baseValue[symbol];
426  } }
427 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define MaxSeq
#define MaxFSELog
#define assert(x)
Definition: debug.h:53
MEM_STATIC unsigned BIT_highbit32(U32 val)
Definition: bitstream.h:139
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
unsigned char BYTE
Definition: xxhash.c:193
unsigned short U16
Definition: xxhash.c:194
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
signed short S16
Definition: mem.h:146
unsigned int U32
Definition: xxhash.c:195

Referenced by ZSTD_loadDEntropy().

◆ ZSTD_decompressBlock_internal()

size_t ZSTD_decompressBlock_internal ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const int  frame 
)

Definition at line 1341 of file zstd_decompress_block.c.

1344 { /* blockType == blockCompressed */
1345  const BYTE* ip = (const BYTE*)src;
1346  /* isLongOffset must be true if there are long offsets.
1347  * Offsets are long if they are larger than 2^STREAM_ACCUMULATOR_MIN.
1348  * We don't expect that to be the case in 64-bit mode.
1349  * In block mode, window size is not known, so we have to be conservative.
1350  * (note: but it could be evaluated from current-lowLimit)
1351  */
1352  ZSTD_longOffset_e const isLongOffset = (ZSTD_longOffset_e)(MEM_32bits() && (!frame || (dctx->fParams.windowSize > (1ULL << STREAM_ACCUMULATOR_MIN))));
1353  DEBUGLOG(5, "ZSTD_decompressBlock_internal (size : %u)", (U32)srcSize);
1354 
1355  RETURN_ERROR_IF(srcSize >= ZSTD_BLOCKSIZE_MAX, srcSize_wrong, "");
1356 
1357  /* Decode literals section */
1358  { size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize);
1359  DEBUGLOG(5, "ZSTD_decodeLiteralsBlock : %u", (U32)litCSize);
1360  if (ZSTD_isError(litCSize)) return litCSize;
1361  ip += litCSize;
1362  srcSize -= litCSize;
1363  }
1364 
1365  /* Build Decoding Tables */
1366  {
1367  /* These macros control at build-time which decompressor implementation
1368  * we use. If neither is defined, we do some inspection and dispatch at
1369  * runtime.
1370  */
1371 #if !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT) && \
1372  !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG)
1373  int usePrefetchDecoder = dctx->ddictIsCold;
1374 #endif
1375  int nbSeq;
1376  size_t const seqHSize = ZSTD_decodeSeqHeaders(dctx, &nbSeq, ip, srcSize);
1377  if (ZSTD_isError(seqHSize)) return seqHSize;
1378  ip += seqHSize;
1379  srcSize -= seqHSize;
1380 
1381  RETURN_ERROR_IF(dst == NULL && nbSeq > 0, dstSize_tooSmall, "NULL not handled");
1382 
1383 #if !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT) && \
1384  !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG)
1385  if ( !usePrefetchDecoder
1386  && (!frame || (dctx->fParams.windowSize > (1<<24)))
1387  && (nbSeq>ADVANCED_SEQS) ) { /* could probably use a larger nbSeq limit */
1388  U32 const shareLongOffsets = ZSTD_getLongOffsetsShare(dctx->OFTptr);
1389  U32 const minShare = MEM_64bits() ? 7 : 20; /* heuristic values, correspond to 2.73% and 7.81% */
1390  usePrefetchDecoder = (shareLongOffsets >= minShare);
1391  }
1392 #endif
1393 
1394  dctx->ddictIsCold = 0;
1395 
1396 #if !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT) && \
1397  !defined(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG)
1398  if (usePrefetchDecoder)
1399 #endif
1400 #ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
1401  return ZSTD_decompressSequencesLong(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset, frame);
1402 #endif
1403 
1404 #ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
1405  /* else */
1406  return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset, frame);
1407 #endif
1408  }
1409 }
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
ZSTD_frameHeader fParams
#define ZSTD_BLOCKSIZE_MAX
Definition: zstd.h:104
const ZSTD_seqSymbol * OFTptr
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:183
MEM_STATIC unsigned MEM_64bits(void)
Definition: mem.h:184
#define DEBUGLOG(l,...)
Definition: debug.h:106
#define ZSTD_isError
Definition: zstd_internal.h:46
#define ULL(a, b)
Definition: format_msg.c:27
#define RETURN_ERROR_IF(cond, err,...)
Definition: zstd_internal.h:91
Definition: dhcpd.h:61
#define ADVANCED_SEQS
static size_t ZSTD_decompressSequencesLong(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset, const int frame)
static unsigned ZSTD_getLongOffsetsShare(const ZSTD_seqSymbol *offTable)
size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx *dctx, const void *src, size_t srcSize)
GLenum src
Definition: glext.h:6340
unsigned char BYTE
Definition: xxhash.c:193
#define STREAM_ACCUMULATOR_MIN
Definition: bitstream.h:47
GLenum GLenum dst
Definition: glext.h:6340
#define NULL
Definition: types.h:112
unsigned int U32
Definition: xxhash.c:195
static size_t ZSTD_decompressSequences(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset, const int frame)

Referenced by ZSTD_decompressContinue(), and ZSTD_decompressFrame().