ReactOS  0.4.15-dev-4616-g17e0e44
zstd_internal.h File Reference
#include "compiler.h"
#include "mem.h"
#include "debug.h"
#include "error_private.h"
#include "zstd.h"
#include "fse.h"
#include "huf.h"
#include "../xxhash.h"
Include dependency graph for zstd_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  seqDef_s
 
struct  seqStore_t
 
struct  ZSTD_sequenceLength
 
struct  ZSTD_frameSizeInfo
 
struct  blockProperties_t
 

Macros

#define ZSTD_STATIC_LINKING_ONLY
 
#define FSE_STATIC_LINKING_ONLY
 
#define HUF_STATIC_LINKING_ONLY
 
#define XXH_STATIC_LINKING_ONLY   /* XXH64_state_t */
 
#define ZSTD_STATIC_ASSERT(c)   DEBUG_STATIC_ASSERT(c)
 
#define ZSTD_isError   ERR_isError /* for inlining */
 
#define FSE_isError   ERR_isError
 
#define HUF_isError   ERR_isError
 
#define MIN(a, b)   ((a)<(b) ? (a) : (b))
 
#define MAX(a, b)   ((a)>(b) ? (a) : (b))
 
#define _FORCE_HAS_FORMAT_STRING(...)
 
#define RETURN_ERROR_IF(cond, err, ...)
 
#define RETURN_ERROR(err, ...)
 
#define FORWARD_IF_ERROR(err, ...)
 
#define ZSTD_OPT_NUM   (1<<12)
 
#define ZSTD_REP_NUM   3 /* number of repcodes */
 
#define ZSTD_REP_MOVE   (ZSTD_REP_NUM-1)
 
#define KB   *(1 <<10)
 
#define MB   *(1 <<20)
 
#define GB   *(1U<<30)
 
#define BIT7   128
 
#define BIT6   64
 
#define BIT5   32
 
#define BIT4   16
 
#define BIT1   2
 
#define BIT0   1
 
#define ZSTD_WINDOWLOG_ABSOLUTEMIN   10
 
#define ZSTD_FRAMEIDSIZE   4 /* magic number size */
 
#define ZSTD_BLOCKHEADERSIZE   3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
 
#define ZSTD_FRAMECHECKSUMSIZE   4
 
#define MIN_SEQUENCES_SIZE   1 /* nbSeq==0 */
 
#define MIN_CBLOCK_SIZE   (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
 
#define HufLog   12
 
#define LONGNBSEQ   0x7F00
 
#define MINMATCH   3
 
#define Litbits   8
 
#define MaxLit   ((1<<Litbits) - 1)
 
#define MaxML   52
 
#define MaxLL   35
 
#define DefaultMaxOff   28
 
#define MaxOff   31
 
#define MaxSeq   MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
 
#define MLFSELog   9
 
#define LLFSELog   9
 
#define OffFSELog   8
 
#define MaxFSELog   MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
 
#define LL_DEFAULTNORMLOG   6 /* for static allocation */
 
#define ML_DEFAULTNORMLOG   6 /* for static allocation */
 
#define OF_DEFAULTNORMLOG   5 /* for static allocation */
 
#define COPY8(d, s)   { ZSTD_copy8(d,s); d+=8; s+=8; }
 
#define COPY16(d, s)   { ZSTD_copy16(d,s); d+=16; s+=16; }
 
#define WILDCOPY_OVERLENGTH   32
 
#define WILDCOPY_VECLEN   16
 
#define ZSTD_WORKSPACETOOLARGE_FACTOR   3
 
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION   128
 

Typedefs

typedef struct seqDef_s seqDef
 

Enumerations

enum  blockType_e { bt_raw, bt_rle, bt_compressed, bt_reserved }
 
enum  symbolEncodingType_e { set_basic, set_rle, set_compressed, set_repeat }
 
enum  ZSTD_overlap_e { ZSTD_no_overlap, ZSTD_overlap_src_before_dst }
 

Functions

static INLINE_KEYWORD UNUSED_ATTR void _force_has_format_string (const char *format,...)
 
static void ZSTD_copy8 (void *dst, const void *src)
 
static void ZSTD_copy16 (void *dst, const void *src)
 
MEM_STATIC FORCE_INLINE_ATTR void ZSTD_wildcopy (void *dst, const void *src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
 
MEM_STATIC size_t ZSTD_limitCopy (void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength (seqStore_t const *seqStore, seqDef const *seq)
 
const seqStore_tZSTD_getSeqStore (const ZSTD_CCtx *ctx)
 
void ZSTD_seqToCodes (const seqStore_t *seqStorePtr)
 
voidZSTD_malloc (size_t size, ZSTD_customMem customMem)
 
voidZSTD_calloc (size_t size, ZSTD_customMem customMem)
 
void ZSTD_free (void *ptr, ZSTD_customMem customMem)
 
MEM_STATIC U32 ZSTD_highbit32 (U32 val)
 
void ZSTD_invalidateRepCodes (ZSTD_CCtx *cctx)
 
size_t ZSTD_getcBlockSize (const void *src, size_t srcSize, blockProperties_t *bpPtr)
 
size_t ZSTD_decodeSeqHeaders (ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
 

Variables

static const U32 repStartValue [ZSTD_REP_NUM] = { 1, 4, 8 }
 
static const size_t ZSTD_fcs_fieldSize [4] = { 0, 2, 4, 8 }
 
static const size_t ZSTD_did_fieldSize [4] = { 0, 1, 2, 4 }
 
static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE
 
static const U32 LL_bits [MaxLL+1]
 
static const S16 LL_defaultNorm [MaxLL+1]
 
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG
 
static const U32 ML_bits [MaxML+1]
 
static const S16 ML_defaultNorm [MaxML+1]
 
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG
 
static const S16 OF_defaultNorm [DefaultMaxOff+1]
 
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG
 

Macro Definition Documentation

◆ _FORCE_HAS_FORMAT_STRING

#define _FORCE_HAS_FORMAT_STRING (   ...)
Value:
if (0) { \
_force_has_format_string(__VA_ARGS__); \
}

Ignore: this is an internal helper.

We want to force this function invocation to be syntactically correct, but we don't want to force runtime evaluation of its arguments.

Definition at line 79 of file zstd_internal.h.

◆ BIT0

#define BIT0   1

Definition at line 153 of file zstd_internal.h.

◆ BIT1

#define BIT1   2

Definition at line 152 of file zstd_internal.h.

◆ BIT4

#define BIT4   16

Definition at line 151 of file zstd_internal.h.

◆ BIT5

#define BIT5   32

Definition at line 150 of file zstd_internal.h.

◆ BIT6

#define BIT6   64

Definition at line 149 of file zstd_internal.h.

◆ BIT7

#define BIT7   128

Definition at line 148 of file zstd_internal.h.

◆ COPY16

#define COPY16 (   d,
  s 
)    { ZSTD_copy16(d,s); d+=16; s+=16; }

Definition at line 246 of file zstd_internal.h.

◆ COPY8

#define COPY8 (   d,
  s 
)    { ZSTD_copy8(d,s); d+=8; s+=8; }

Definition at line 238 of file zstd_internal.h.

◆ DefaultMaxOff

#define DefaultMaxOff   28

Definition at line 181 of file zstd_internal.h.

◆ FORWARD_IF_ERROR

#define FORWARD_IF_ERROR (   err,
  ... 
)
Value:
do { \
size_t const err_code = (err); \
if (ERR_isError(err_code)) { \
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
__FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
RAWLOG(3, ": " __VA_ARGS__); \
RAWLOG(3, "\n"); \
return err_code; \
} \
} while(0);
ERR_STATIC const char * ERR_getErrorName(size_t code)
Definition: error_private.h:71
#define ZSTD_QUOTE(str)
Definition: zstd.h:81
ERR_STATIC unsigned ERR_isError(size_t code)
Definition: error_private.h:56
#define err(...)

If the provided expression evaluates to an error code, returns that error code.

In debug modes, prints additional information.

Definition at line 121 of file zstd_internal.h.

◆ FSE_isError

#define FSE_isError   ERR_isError

Definition at line 47 of file zstd_internal.h.

◆ FSE_STATIC_LINKING_ONLY

#define FSE_STATIC_LINKING_ONLY

Definition at line 31 of file zstd_internal.h.

◆ GB

#define GB   *(1U<<30)

Definition at line 146 of file zstd_internal.h.

◆ HUF_isError

#define HUF_isError   ERR_isError

Definition at line 48 of file zstd_internal.h.

◆ HUF_STATIC_LINKING_ONLY

#define HUF_STATIC_LINKING_ONLY

Definition at line 33 of file zstd_internal.h.

◆ HufLog

#define HufLog   12

Definition at line 170 of file zstd_internal.h.

◆ KB

#define KB   *(1 <<10)

Definition at line 144 of file zstd_internal.h.

◆ Litbits

#define Litbits   8

Definition at line 177 of file zstd_internal.h.

◆ LL_DEFAULTNORMLOG

#define LL_DEFAULTNORMLOG   6 /* for static allocation */

Definition at line 199 of file zstd_internal.h.

◆ LLFSELog

#define LLFSELog   9

Definition at line 185 of file zstd_internal.h.

◆ LONGNBSEQ

#define LONGNBSEQ   0x7F00

Definition at line 173 of file zstd_internal.h.

◆ MAX

#define MAX (   a,
  b 
)    ((a)>(b) ? (a) : (b))

Definition at line 57 of file zstd_internal.h.

◆ MaxFSELog

#define MaxFSELog   MAX(MAX(MLFSELog, LLFSELog), OffFSELog)

Definition at line 187 of file zstd_internal.h.

◆ MaxLit

#define MaxLit   ((1<<Litbits) - 1)

Definition at line 178 of file zstd_internal.h.

◆ MaxLL

#define MaxLL   35

Definition at line 180 of file zstd_internal.h.

◆ MaxML

#define MaxML   52

Definition at line 179 of file zstd_internal.h.

◆ MaxOff

#define MaxOff   31

Definition at line 182 of file zstd_internal.h.

◆ MaxSeq

#define MaxSeq   MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */

Definition at line 183 of file zstd_internal.h.

◆ MB

#define MB   *(1 <<20)

Definition at line 145 of file zstd_internal.h.

◆ MIN

#define MIN (   a,
  b 
)    ((a)<(b) ? (a) : (b))

Definition at line 56 of file zstd_internal.h.

◆ MIN_CBLOCK_SIZE

#define MIN_CBLOCK_SIZE   (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */

Definition at line 168 of file zstd_internal.h.

◆ MIN_SEQUENCES_SIZE

#define MIN_SEQUENCES_SIZE   1 /* nbSeq==0 */

Definition at line 167 of file zstd_internal.h.

◆ MINMATCH

#define MINMATCH   3

Definition at line 175 of file zstd_internal.h.

◆ ML_DEFAULTNORMLOG

#define ML_DEFAULTNORMLOG   6 /* for static allocation */

Definition at line 216 of file zstd_internal.h.

◆ MLFSELog

#define MLFSELog   9

Definition at line 184 of file zstd_internal.h.

◆ OF_DEFAULTNORMLOG

#define OF_DEFAULTNORMLOG   5 /* for static allocation */

Definition at line 223 of file zstd_internal.h.

◆ OffFSELog

#define OffFSELog   8

Definition at line 186 of file zstd_internal.h.

◆ RETURN_ERROR

#define RETURN_ERROR (   err,
  ... 
)
Value:
do { \
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
__FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
RAWLOG(3, ": " __VA_ARGS__); \
RAWLOG(3, "\n"); \
return ERROR(err); \
} while(0);
#define ERROR(name)
Definition: error_private.h:53
#define ZSTD_QUOTE(str)
Definition: zstd.h:81
#define err(...)

Unconditionally return the specified error.

In debug modes, prints additional information.

Definition at line 106 of file zstd_internal.h.

◆ RETURN_ERROR_IF

#define RETURN_ERROR_IF (   cond,
  err,
  ... 
)
Value:
if (cond) { \
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
__FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
RAWLOG(3, ": " __VA_ARGS__); \
RAWLOG(3, "\n"); \
return ERROR(err); \
}
#define ERROR(name)
Definition: error_private.h:53
#define ZSTD_QUOTE(str)
Definition: zstd.h:81
#define err(...)

Return the specified error if the condition evaluates to true.

In debug modes, prints additional information. In order to do that (particularly, printing the conditional that failed), this can't just wrap RETURN_ERROR().

Definition at line 91 of file zstd_internal.h.

◆ WILDCOPY_OVERLENGTH

#define WILDCOPY_OVERLENGTH   32

Definition at line 248 of file zstd_internal.h.

◆ WILDCOPY_VECLEN

#define WILDCOPY_VECLEN   16

Definition at line 249 of file zstd_internal.h.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY   /* XXH64_state_t */

Definition at line 36 of file zstd_internal.h.

◆ ZSTD_BLOCKHEADERSIZE

#define ZSTD_BLOCKHEADERSIZE   3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */

Definition at line 161 of file zstd_internal.h.

◆ ZSTD_FRAMECHECKSUMSIZE

#define ZSTD_FRAMECHECKSUMSIZE   4

Definition at line 165 of file zstd_internal.h.

◆ ZSTD_FRAMEIDSIZE

#define ZSTD_FRAMEIDSIZE   4 /* magic number size */

Definition at line 159 of file zstd_internal.h.

◆ ZSTD_isError

#define ZSTD_isError   ERR_isError /* for inlining */

Definition at line 46 of file zstd_internal.h.

◆ ZSTD_OPT_NUM

#define ZSTD_OPT_NUM   (1<<12)

Definition at line 138 of file zstd_internal.h.

◆ ZSTD_REP_MOVE

#define ZSTD_REP_MOVE   (ZSTD_REP_NUM-1)

Definition at line 141 of file zstd_internal.h.

◆ ZSTD_REP_NUM

#define ZSTD_REP_NUM   3 /* number of repcodes */

Definition at line 140 of file zstd_internal.h.

◆ ZSTD_STATIC_ASSERT

#define ZSTD_STATIC_ASSERT (   c)    DEBUG_STATIC_ASSERT(c)

Definition at line 45 of file zstd_internal.h.

◆ ZSTD_STATIC_LINKING_ONLY

#define ZSTD_STATIC_LINKING_ONLY

Definition at line 29 of file zstd_internal.h.

◆ ZSTD_WINDOWLOG_ABSOLUTEMIN

#define ZSTD_WINDOWLOG_ABSOLUTEMIN   10

Definition at line 155 of file zstd_internal.h.

◆ ZSTD_WORKSPACETOOLARGE_FACTOR

#define ZSTD_WORKSPACETOOLARGE_FACTOR   3

Definition at line 314 of file zstd_internal.h.

◆ ZSTD_WORKSPACETOOLARGE_MAXDURATION

#define ZSTD_WORKSPACETOOLARGE_MAXDURATION   128

Definition at line 321 of file zstd_internal.h.

Typedef Documentation

◆ seqDef

Enumeration Type Documentation

◆ blockType_e

Enumerator
bt_raw 
bt_rle 
bt_compressed 
bt_reserved 

Definition at line 163 of file zstd_internal.h.

◆ symbolEncodingType_e

Enumerator
set_basic 
set_rle 
set_compressed 
set_repeat 

Definition at line 171 of file zstd_internal.h.

◆ ZSTD_overlap_e

Enumerator
ZSTD_no_overlap 
ZSTD_overlap_src_before_dst 

Definition at line 251 of file zstd_internal.h.

251  {
254  /* ZSTD_overlap_dst_before_src, */
ZSTD_overlap_e

Function Documentation

◆ _force_has_format_string()

static INLINE_KEYWORD UNUSED_ATTR void _force_has_format_string ( const char format,
  ... 
)
static

Ignore: this is an internal helper.

This is a helper function to help force C99-correctness during compilation. Under strict compilation modes, variadic macro arguments can't be empty. However, variadic function arguments can be. Using a function therefore lets us statically check that at least one (string) argument was passed, independent of the compilation flags.

Definition at line 69 of file zstd_internal.h.

69  {
70  (void)format;
71 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546

◆ ZSTD_calloc()

void* ZSTD_calloc ( size_t  size,
ZSTD_customMem  customMem 
)

Definition at line 61 of file zstd_common.c.

62 {
63  /* calloc implemented as malloc+memset;
64  * not as efficient as calloc, but next best guess for custom malloc */
65  void* const ptr = customMem.customAlloc(customMem.opaque, size);
66  memset(ptr, 0, size);
67  return ptr;
68 }
static PVOID ptr
Definition: dispmode.c:27
GLsizeiptr size
Definition: glext.h:5919
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ZSTD_createCCtxParams_advanced().

◆ ZSTD_copy16()

static void ZSTD_copy16 ( void dst,
const void src 
)
static

Definition at line 239 of file zstd_internal.h.

239  {
240 #ifdef __aarch64__
241  vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
242 #else
243  memcpy(dst, src, 16);
244 #endif
245 }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
BYTE uint8_t
Definition: msvideo1.c:66
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_storeSeq().

◆ ZSTD_copy8()

static void ZSTD_copy8 ( void dst,
const void src 
)
static

Definition at line 230 of file zstd_internal.h.

230  {
231 #ifdef __aarch64__
232  vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
233 #else
234  memcpy(dst, src, 8);
235 #endif
236 }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
BYTE uint8_t
Definition: msvideo1.c:66
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_decodeSeqHeaders()

size_t ZSTD_decodeSeqHeaders ( ZSTD_DCtx dctx,
int nbSeqPtr,
const void src,
size_t  srcSize 
)

ZSTD_decodeSeqHeaders() : decode sequence header from src

Definition at line 480 of file zstd_decompress_block.c.

482 {
483  const BYTE* const istart = (const BYTE* const)src;
484  const BYTE* const iend = istart + srcSize;
485  const BYTE* ip = istart;
486  int nbSeq;
487  DEBUGLOG(5, "ZSTD_decodeSeqHeaders");
488 
489  /* check */
490  RETURN_ERROR_IF(srcSize < MIN_SEQUENCES_SIZE, srcSize_wrong, "");
491 
492  /* SeqHead */
493  nbSeq = *ip++;
494  if (!nbSeq) {
495  *nbSeqPtr=0;
496  RETURN_ERROR_IF(srcSize != 1, srcSize_wrong, "");
497  return 1;
498  }
499  if (nbSeq > 0x7F) {
500  if (nbSeq == 0xFF) {
501  RETURN_ERROR_IF(ip+2 > iend, srcSize_wrong, "");
502  nbSeq = MEM_readLE16(ip) + LONGNBSEQ, ip+=2;
503  } else {
504  RETURN_ERROR_IF(ip >= iend, srcSize_wrong, "");
505  nbSeq = ((nbSeq-0x80)<<8) + *ip++;
506  }
507  }
508  *nbSeqPtr = nbSeq;
509 
510  /* FSE table descriptors */
511  RETURN_ERROR_IF(ip+1 > iend, srcSize_wrong, ""); /* minimum possible size: 1 byte for symbol encoding types */
512  { symbolEncodingType_e const LLtype = (symbolEncodingType_e)(*ip >> 6);
513  symbolEncodingType_e const OFtype = (symbolEncodingType_e)((*ip >> 4) & 3);
514  symbolEncodingType_e const MLtype = (symbolEncodingType_e)((*ip >> 2) & 3);
515  ip++;
516 
517  /* Build DTables */
518  { size_t const llhSize = ZSTD_buildSeqTable(dctx->entropy.LLTable, &dctx->LLTptr,
519  LLtype, MaxLL, LLFSELog,
520  ip, iend-ip,
521  LL_base, LL_bits,
523  dctx->ddictIsCold, nbSeq);
524  RETURN_ERROR_IF(ZSTD_isError(llhSize), corruption_detected, "ZSTD_buildSeqTable failed");
525  ip += llhSize;
526  }
527 
528  { size_t const ofhSize = ZSTD_buildSeqTable(dctx->entropy.OFTable, &dctx->OFTptr,
529  OFtype, MaxOff, OffFSELog,
530  ip, iend-ip,
531  OF_base, OF_bits,
533  dctx->ddictIsCold, nbSeq);
534  RETURN_ERROR_IF(ZSTD_isError(ofhSize), corruption_detected, "ZSTD_buildSeqTable failed");
535  ip += ofhSize;
536  }
537 
538  { size_t const mlhSize = ZSTD_buildSeqTable(dctx->entropy.MLTable, &dctx->MLTptr,
539  MLtype, MaxML, MLFSELog,
540  ip, iend-ip,
541  ML_base, ML_bits,
543  dctx->ddictIsCold, nbSeq);
544  RETURN_ERROR_IF(ZSTD_isError(mlhSize), corruption_detected, "ZSTD_buildSeqTable failed");
545  ip += mlhSize;
546  }
547  }
548 
549  return ip-istart;
550 }
symbolEncodingType_e
static const U32 LL_bits[MaxLL+1]
const ZSTD_seqSymbol * OFTptr
static const U32 LL_base[MaxLL+1]
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
static const ZSTD_seqSymbol LL_defaultDTable[(1<< LL_DEFAULTNORMLOG)+1]
static const ZSTD_seqSymbol ML_defaultDTable[(1<< ML_DEFAULTNORMLOG)+1]
#define DEBUGLOG(l,...)
Definition: debug.h:106
static size_t ZSTD_buildSeqTable(ZSTD_seqSymbol *DTableSpace, const ZSTD_seqSymbol **DTablePtr, symbolEncodingType_e type, unsigned max, U32 maxLog, const void *src, size_t srcSize, const U32 *baseValue, const U32 *nbAdditionalBits, const ZSTD_seqSymbol *defaultTable, U32 flagRepeatTable, int ddictIsCold, int nbSeq)
#define ZSTD_isError
Definition: zstd_internal.h:46
#define MIN_SEQUENCES_SIZE
static const U32 ML_base[MaxML+1]
#define MaxML
#define MLFSELog
const ZSTD_seqSymbol * LLTptr
const ZSTD_seqSymbol * MLTptr
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:314
#define RETURN_ERROR_IF(cond, err,...)
Definition: zstd_internal.h:91
Definition: dhcpd.h:61
ZSTD_entropyDTables_t entropy
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
#define OffFSELog
#define LONGNBSEQ
GLenum src
Definition: glext.h:6340
static const ZSTD_seqSymbol OF_defaultDTable[(1<< OF_DEFAULTNORMLOG)+1]
unsigned char BYTE
Definition: xxhash.c:193
#define MaxOff
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
static const U32 ML_bits[MaxML+1]
#define MaxLL
static const U32 OF_base[MaxOff+1]
#define LLFSELog
static const U32 OF_bits[MaxOff+1]

◆ ZSTD_free()

void ZSTD_free ( void ptr,
ZSTD_customMem  customMem 
)

Definition at line 70 of file zstd_common.c.

71 {
72  if (ptr!=NULL)
73  customMem.customFree(customMem.opaque, ptr);
74 }
static PVOID ptr
Definition: dispmode.c:27
#define NULL
Definition: types.h:112

Referenced by ZSTD_clearAllDicts(), ZSTD_createCDict_advanced(), ZSTD_cwksp_free(), ZSTD_decompressStream(), ZSTD_freeCCtx(), ZSTD_freeCCtxParams(), ZSTD_freeCDict(), ZSTD_freeDCtx(), ZSTD_freeDDict(), and ZSTD_getSequences().

◆ ZSTD_getcBlockSize()

size_t ZSTD_getcBlockSize ( const void src,
size_t  srcSize,
blockProperties_t bpPtr 
)

ZSTD_getcBlockSize() : Provides the size of compressed block from block header src

Definition at line 56 of file zstd_decompress_block.c.

58 {
59  RETURN_ERROR_IF(srcSize < ZSTD_blockHeaderSize, srcSize_wrong, "");
60 
61  { U32 const cBlockHeader = MEM_readLE24(src);
62  U32 const cSize = cBlockHeader >> 3;
63  bpPtr->lastBlock = cBlockHeader & 1;
64  bpPtr->blockType = (blockType_e)((cBlockHeader >> 1) & 3);
65  bpPtr->origSize = cSize; /* only useful for RLE */
66  if (bpPtr->blockType == bt_rle) return 1;
67  RETURN_ERROR_IF(bpPtr->blockType == bt_reserved, corruption_detected, "");
68  return cSize;
69  }
70 }
blockType_e blockType
blockType_e
static const size_t ZSTD_blockHeaderSize
#define RETURN_ERROR_IF(cond, err,...)
Definition: zstd_internal.h:91
GLenum src
Definition: glext.h:6340
unsigned int U32
Definition: xxhash.c:195
MEM_STATIC U32 MEM_readLE24(const void *memPtr)
Definition: mem.h:335

Referenced by ZSTD_decompressContinue(), ZSTD_decompressFrame(), and ZSTD_findFrameSizeInfo().

◆ ZSTD_getSeqStore()

const seqStore_t* ZSTD_getSeqStore ( const ZSTD_CCtx ctx)

Definition at line 190 of file zstd_compress.c.

190 { return &(ctx->seqStore); }

Referenced by ZSTD_copyBlockSequences().

◆ ZSTD_getSequenceLength()

MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength ( seqStore_t const seqStore,
seqDef const seq 
)

Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences indicated by longLengthPos and longLengthID, and adds MINMATCH back to matchLength.

Definition at line 356 of file zstd_internal.h.

357 {
358  ZSTD_sequenceLength seqLen;
359  seqLen.litLength = seq->litLength;
360  seqLen.matchLength = seq->matchLength + MINMATCH;
361  if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
362  if (seqStore->longLengthID == 1) {
363  seqLen.litLength += 0xFFFF;
364  }
365  if (seqStore->longLengthID == 2) {
366  seqLen.matchLength += 0xFFFF;
367  }
368  }
369  return seqLen;
370 }
#define MINMATCH
unsigned int U32
Definition: xxhash.c:195

Referenced by ZSTD_compressSubBlock_multi(), and ZSTD_seqDecompressedSize().

◆ ZSTD_highbit32()

MEM_STATIC U32 ZSTD_highbit32 ( U32  val)

Definition at line 392 of file zstd_internal.h.

393 {
394  assert(val != 0);
395  {
396 # if defined(_MSC_VER) /* Visual */
397  unsigned long r=0;
398  return _BitScanReverse(&r, val) ? (unsigned)r : 0;
399 # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
400  return __builtin_clz (val) ^ 31;
401 # elif defined(__ICCARM__) /* IAR Intrinsic */
402  return 31 - __CLZ(val);
403 # else /* Software version */
404  static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
405  U32 v = val;
406  v |= v >> 1;
407  v |= v >> 2;
408  v |= v >> 4;
409  v |= v >> 8;
410  v |= v >> 16;
411  return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
412 # endif
413  }
414 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define U(x)
Definition: wordpad.c:45
#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 ZSTD_adjustCParams_internal(), ZSTD_bitWeight(), ZSTD_compressBegin_usingCDict_advanced(), ZSTD_compressBlock_lazy_extDict_generic(), ZSTD_compressBlock_lazy_generic(), ZSTD_DUBT_findBestMatch(), ZSTD_DUBT_findBetterDictMatch(), ZSTD_fracWeight(), ZSTD_getMatchPrice(), ZSTD_LLcode(), ZSTD_loadZstdDictionary(), ZSTD_MLcode(), ZSTD_seqToCodes(), and ZSTD_updateStats().

◆ ZSTD_invalidateRepCodes()

void ZSTD_invalidateRepCodes ( ZSTD_CCtx cctx)

Definition at line 1593 of file zstd_compress.c.

1593  {
1594  int i;
1595  for (i=0; i<ZSTD_REP_NUM; i++) cctx->blockState.prevCBlock->rep[i] = 0;
1597 }
MEM_STATIC U32 ZSTD_window_hasExtDict(ZSTD_window_t const window)
#define assert(x)
Definition: debug.h:53
ZSTD_blockState_t blockState
ZSTD_matchState_t matchState
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
ZSTD_compressedBlockState_t * prevCBlock
#define ZSTD_REP_NUM

◆ ZSTD_limitCopy()

MEM_STATIC size_t ZSTD_limitCopy ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

Definition at line 304 of file zstd_internal.h.

305 {
306  size_t const length = MIN(dstCapacity, srcSize);
307  if (length > 0) {
308  memcpy(dst, src, length);
309  }
310  return length;
311 }
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define MIN(a, b)
Definition: zstd_internal.h:56
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_compressStream_generic(), and ZSTD_decompressStream().

◆ ZSTD_malloc()

void* ZSTD_malloc ( size_t  size,
ZSTD_customMem  customMem 
)

◆ ZSTD_seqToCodes()

void ZSTD_seqToCodes ( const seqStore_t seqStorePtr)

Definition at line 1929 of file zstd_compress.c.

1930 {
1931  const seqDef* const sequences = seqStorePtr->sequencesStart;
1932  BYTE* const llCodeTable = seqStorePtr->llCode;
1933  BYTE* const ofCodeTable = seqStorePtr->ofCode;
1934  BYTE* const mlCodeTable = seqStorePtr->mlCode;
1935  U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart);
1936  U32 u;
1937  assert(nbSeq <= seqStorePtr->maxNbSeq);
1938  for (u=0; u<nbSeq; u++) {
1939  U32 const llv = sequences[u].litLength;
1940  U32 const mlv = sequences[u].matchLength;
1941  llCodeTable[u] = (BYTE)ZSTD_LLcode(llv);
1942  ofCodeTable[u] = (BYTE)ZSTD_highbit32(sequences[u].offset);
1943  mlCodeTable[u] = (BYTE)ZSTD_MLcode(mlv);
1944  }
1945  if (seqStorePtr->longLengthID==1)
1946  llCodeTable[seqStorePtr->longLengthPos] = MaxLL;
1947  if (seqStorePtr->longLengthID==2)
1948  mlCodeTable[seqStorePtr->longLengthPos] = MaxML;
1949 }
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
BYTE * ofCode
#define assert(x)
Definition: debug.h:53
seqDef * sequencesStart
seqDef * sequences
MEM_STATIC U32 ZSTD_MLcode(U32 mlBase)
#define MaxML
GLintptr offset
Definition: glext.h:5920
BYTE * mlCode
unsigned char BYTE
Definition: xxhash.c:193
static struct msg_sequence * sequences[NUM_MSG_SEQUENCES]
Definition: button.c:54
MEM_STATIC U32 ZSTD_highbit32(U32 val)
#define MaxLL
BYTE * llCode
MEM_STATIC U32 ZSTD_LLcode(U32 litLength)
unsigned int U32
Definition: xxhash.c:195

Referenced by ZSTD_buildSuperBlockEntropy_sequences(), and ZSTD_compressSequences_internal().

◆ ZSTD_wildcopy()

MEM_STATIC FORCE_INLINE_ATTR void ZSTD_wildcopy ( void dst,
const void src,
ptrdiff_t  length,
ZSTD_overlap_e const  ovtype 
)

ZSTD_wildcopy() : Custom version of memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)

Parameters
ovtypecontrols the overlap detection
  • ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
  • ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart. The src buffer must be before the dst buffer.

Definition at line 265 of file zstd_internal.h.

266 {
267  ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
268  const BYTE* ip = (const BYTE*)src;
269  BYTE* op = (BYTE*)dst;
270  BYTE* const oend = op + length;
271 
272  assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
273 
274  if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
275  /* Handle short offset copies. */
276  do {
277  COPY8(op, ip)
278  } while (op < oend);
279  } else {
280  assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
281  /* Separate out the first COPY16() call because the copy length is
282  * almost certain to be short, so the branches have different
283  * probabilities. Since it is almost certain to be short, only do
284  * one COPY16() in the first call. Then, do two calls per loop since
285  * at that point it is more likely to have a high trip count.
286  */
287 #ifndef __aarch64__
288  do {
289  COPY16(op, ip);
290  }
291  while (op < oend);
292 #else
293  COPY16(op, ip);
294  if (op >= oend) return;
295  do {
296  COPY16(op, ip);
297  COPY16(op, ip);
298  }
299  while (op < oend);
300 #endif
301  }
302 }
#define assert(x)
Definition: debug.h:53
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define WILDCOPY_VECLEN
Definition: dhcpd.h:61
UINT op
Definition: effect.c:236
GLenum src
Definition: glext.h:6340
unsigned char BYTE
Definition: xxhash.c:193
#define COPY8(d, s)
GLenum GLenum dst
Definition: glext.h:6340
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define COPY16(d, s)

Referenced by ZSTD_safecopyLiterals(), and ZSTD_storeSeq().

Variable Documentation

◆ LL_bits

const U32 LL_bits[MaxLL+1]
static
Initial value:
= { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 2, 2, 3, 3,
4, 6, 7, 8, 9,10,11,12,
13,14,15,16 }

Definition at line 189 of file zstd_internal.h.

Referenced by ZSTD_encodeSequences_body(), ZSTD_estimateSubBlockSize_sequences(), ZSTD_litLengthPrice(), and ZSTD_loadDEntropy().

◆ LL_defaultNorm

const S16 LL_defaultNorm[MaxLL+1]
static
Initial value:
= { 4, 3, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2,
2, 3, 2, 1, 1, 1, 1, 1,
-1,-1,-1,-1 }

Definition at line 194 of file zstd_internal.h.

Referenced by ZSTD_buildSuperBlockEntropy_sequences(), ZSTD_compressSequences_internal(), and ZSTD_estimateSubBlockSize_sequences().

◆ LL_defaultNormLog

◆ ML_bits

const U32 ML_bits[MaxML+1]
static
Initial value:
= { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 2, 2, 3, 3,
4, 4, 5, 7, 8, 9,10,11,
12,13,14,15,16 }

Definition at line 202 of file zstd_internal.h.

Referenced by ZSTD_encodeSequences_body(), ZSTD_estimateSubBlockSize_sequences(), ZSTD_getMatchPrice(), and ZSTD_loadDEntropy().

◆ ML_defaultNorm

const S16 ML_defaultNorm[MaxML+1]
static
Initial value:
= { 1, 4, 3, 2, 2, 2, 2, 2,
2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,-1,-1,
-1,-1,-1,-1,-1 }

Definition at line 209 of file zstd_internal.h.

Referenced by ZSTD_buildSuperBlockEntropy_sequences(), ZSTD_compressSequences_internal(), and ZSTD_estimateSubBlockSize_sequences().

◆ ML_defaultNormLog

◆ OF_defaultNorm

const S16 OF_defaultNorm[DefaultMaxOff+1]
static
Initial value:
= { 1, 1, 1, 1, 1, 1, 2, 2,
2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
-1,-1,-1,-1,-1 }

Definition at line 219 of file zstd_internal.h.

Referenced by ZSTD_buildSuperBlockEntropy_sequences(), ZSTD_compressSequences_internal(), and ZSTD_estimateSubBlockSize_sequences().

◆ OF_defaultNormLog

◆ repStartValue

const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 }
static

◆ ZSTD_blockHeaderSize

◆ ZSTD_did_fieldSize

const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 }
static

Definition at line 157 of file zstd_internal.h.

Referenced by ZSTD_frameHeaderSize_internal().

◆ ZSTD_fcs_fieldSize

const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 }
static

Definition at line 156 of file zstd_internal.h.

Referenced by ZSTD_frameHeaderSize_internal().