11#ifndef ZSTD_CCOMMON_H_MODULE
12#define ZSTD_CCOMMON_H_MODULE
27#define ZSTD_STATIC_LINKING_ONLY
29#define FSE_STATIC_LINKING_ONLY
31#define HUF_STATIC_LINKING_ONLY
33#ifndef XXH_STATIC_LINKING_ONLY
34# define XXH_STATIC_LINKING_ONLY
43#if defined (__cplusplus)
48#define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
49#define ZSTD_isError ERR_isError
50#define FSE_isError ERR_isError
51#define HUF_isError ERR_isError
59#define MIN(a,b) ((a)<(b) ? (a) : (b))
60#define MAX(a,b) ((a)>(b) ? (a) : (b))
61#define BOUNDED(min,val,max) (MAX(min,MIN(val,max)))
67#define ZSTD_OPT_NUM (1<<12)
83#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
84static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
85static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
87#define ZSTD_FRAMEIDSIZE 4
89#define ZSTD_BLOCKHEADERSIZE 3
93#define ZSTD_FRAMECHECKSUMSIZE 4
95#define MIN_SEQUENCES_SIZE 1
96#define MIN_CBLOCK_SIZE (1 + 1 + MIN_SEQUENCES_SIZE )
101#define LONGNBSEQ 0x7F00
106#define MaxLit ((1<<Litbits) - 1)
109#define DefaultMaxOff 28
111#define MaxSeq MAX(MaxLL, MaxML)
115#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
117#define ZSTD_MAX_HUF_HEADER_SIZE 128
119#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
122 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0,
124 1, 1, 1, 1, 2, 2, 3, 3,
125 4, 6, 7, 8, 9,10,11,12,
129 4, 3, 2, 2, 2, 2, 2, 2,
130 2, 2, 2, 2, 2, 1, 1, 1,
131 2, 2, 2, 2, 2, 2, 2, 2,
132 2, 3, 2, 1, 1, 1, 1, 1,
135#define LL_DEFAULTNORMLOG 6
139 0, 0, 0, 0, 0, 0, 0, 0,
140 0, 0, 0, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0,
143 1, 1, 1, 1, 2, 2, 3, 3,
144 4, 4, 5, 7, 8, 9,10,11,
148 1, 4, 3, 2, 2, 2, 2, 2,
149 2, 1, 1, 1, 1, 1, 1, 1,
150 1, 1, 1, 1, 1, 1, 1, 1,
151 1, 1, 1, 1, 1, 1, 1, 1,
152 1, 1, 1, 1, 1, 1, 1, 1,
153 1, 1, 1, 1, 1, 1,-1,-1,
156#define ML_DEFAULTNORMLOG 6
160 1, 1, 1, 1, 1, 1, 2, 2,
161 2, 1, 1, 1, 1, 1, 1, 1,
162 1, 1, 1, 1, 1, 1, 1, 1,
165#define OF_DEFAULTNORMLOG 5
172static void ZSTD_copy8(
void*
dst,
const void*
src) {
173#if defined(ZSTD_ARCH_ARM_NEON)
174 vst1_u8((uint8_t*)
dst, vld1_u8((
const uint8_t*)
src));
179#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
185static void ZSTD_copy16(
void*
dst,
const void*
src) {
186#if defined(ZSTD_ARCH_ARM_NEON)
187 vst1q_u8((uint8_t*)
dst, vld1q_u8((
const uint8_t*)
src));
188#elif defined(ZSTD_ARCH_X86_SSE2)
189 _mm_storeu_si128((__m128i*)
dst, _mm_loadu_si128((
const __m128i*)
src));
190#elif defined(__clang__)
199#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
201#define WILDCOPY_OVERLENGTH 32
202#define WILDCOPY_VECLEN 16
223 BYTE*
const oend =
op + length;
245 if (16 >= length)
return;
259 size_t const length =
MIN(dstCapacity,
srcSize);
267#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
274#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
367# if defined(_MSC_VER)
369 return _lzcnt_u32(val)^31;
373 _BitScanReverse(&r, val);
380# elif defined(__GNUC__) && (__GNUC__ >= 3)
381 return __builtin_clz (val) ^ 31;
382# elif defined(__ICCARM__)
383 return 31 - __CLZ(val);
385 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 };
392 return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
406# if defined(_MSC_VER) && defined(_WIN64)
408 return _tzcnt_u64(val);
412 _BitScanForward64(&r, (
U64)val);
419# elif defined(__GNUC__) && (__GNUC__ >= 4)
420 return __builtin_ctzll((
U64)val);
422 static const int DeBruijnBytePos[64] = { 0, 1, 2, 7, 3, 13, 8, 19,
423 4, 25, 14, 28, 9, 34, 20, 56,
424 5, 17, 26, 54, 15, 41, 29, 43,
425 10, 31, 38, 35, 21, 45, 49, 57,
426 63, 6, 12, 18, 24, 27, 33, 55,
427 16, 53, 40, 42, 30, 37, 44, 48,
428 62, 11, 23, 32, 52, 39, 36, 47,
429 61, 22, 51, 46, 60, 50, 59, 58 };
430 return DeBruijnBytePos[((
U64)((val & -(
long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
433# if defined(_MSC_VER)
436 _BitScanForward(&r, (
U32)val);
442# elif defined(__GNUC__) && (__GNUC__ >= 3)
443 return __builtin_ctz((
U32)val);
445 static const int DeBruijnBytePos[32] = { 0, 1, 28, 2, 29, 14, 24, 3,
446 30, 22, 20, 15, 25, 17, 4, 8,
447 31, 27, 13, 23, 21, 19, 16, 7,
448 26, 12, 18, 6, 11, 5, 10, 9 };
449 return DeBruijnBytePos[((
U32)((val & -(
S32)val) * 0x077CB531U)) >> 27];
486 return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
489#if defined (__cplusplus)
unsigned long long U64
Definition lz4.c:318
unsigned char BYTE
Definition lz4.c:314
unsigned int U32
Definition lz4.c:316
#define assert(condition)
Definition lz4.c:273
unsigned short U16
Definition lz4.c:315
char * dst
Definition lz4.h:833
char int srcSize
Definition lz4.h:806
const char * src
Definition lz4.h:866
Definition zstd_compress_internal.h:358
Definition zstd_decompress_internal.h:126
Definition zstd_internal.h:349
unsigned long long decompressedBound
Definition zstd_internal.h:351
size_t compressedSize
Definition zstd_internal.h:350
Definition zstd_internal.h:318
U32 litLength
Definition zstd_internal.h:319
U32 matchLength
Definition zstd_internal.h:320
Definition zstd_internal.h:462
U32 lastBlock
Definition zstd_internal.h:464
U32 origSize
Definition zstd_internal.h:465
blockType_e blockType
Definition zstd_internal.h:463
Definition zstd_internal.h:286
U16 litLength
Definition zstd_internal.h:288
U32 offBase
Definition zstd_internal.h:287
U16 mlBase
Definition zstd_internal.h:289
Definition zstd_internal.h:299
BYTE * llCode
Definition zstd_internal.h:304
BYTE * mlCode
Definition zstd_internal.h:305
U32 longLengthPos
Definition zstd_internal.h:315
size_t maxNbSeq
Definition zstd_internal.h:307
ZSTD_longLengthType_e longLengthType
Definition zstd_internal.h:314
size_t maxNbLit
Definition zstd_internal.h:308
BYTE * lit
Definition zstd_internal.h:303
BYTE * litStart
Definition zstd_internal.h:302
seqDef * sequences
Definition zstd_internal.h:301
seqDef * sequencesStart
Definition zstd_internal.h:300
BYTE * ofCode
Definition zstd_internal.h:306
#define UNUSED_ATTR
Definition compiler.h:81
#define FORCE_INLINE_ATTR
Definition compiler.h:33
#define U64(C)
Definition sha512_k.c:107
signed short S16
Definition util.h:73
#define S32(x)
Definition crc_macros.h:29
md5_starts & ctx
Definition zlib_interface.c:41
uint8_t U8
Definition mem.h:33
MEM_STATIC unsigned MEM_64bits(void)
Definition mem.h:95
#define MEM_STATIC
Definition mem.h:27
#define ZSTD_memmove(d, s, n)
Definition zstd_deps.h:33
#define ZSTD_memcpy(d, s, n)
Definition zstd_deps.h:32
MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void)
Definition cpu.h:32
void ZSTD_seqToCodes(const seqStore_t *seqStorePtr)
Definition zstd_compress.c:2388
#define MINMATCH
Definition zstd_internal.h:103
ZSTD_longLengthType_e
Definition zstd_internal.h:293
@ ZSTD_llt_matchLength
Definition zstd_internal.h:296
@ ZSTD_llt_literalLength
Definition zstd_internal.h:295
@ ZSTD_llt_none
Definition zstd_internal.h:294
#define MaxLL
Definition zstd_internal.h:108
#define MIN(a, b)
Definition zstd_internal.h:59
void * ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
Definition zstd_common.c:63
#define ZSTD_BLOCKHEADERSIZE
Definition zstd_internal.h:89
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
Definition zstd_internal.h:483
#define MaxML
Definition zstd_internal.h:107
#define OF_DEFAULTNORMLOG
Definition zstd_internal.h:165
MEM_STATIC U32 ZSTD_highbit32(U32 val)
Definition zstd_internal.h:363
void * ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
Definition zstd_common.c:56
MEM_STATIC unsigned ZSTD_countTrailingZeros(size_t val)
Definition zstd_internal.h:403
void ZSTD_customFree(void *ptr, ZSTD_customMem customMem)
Definition zstd_common.c:75
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
Definition zstd_internal.h:257
blockType_e
Definition zstd_internal.h:91
@ bt_compressed
Definition zstd_internal.h:91
@ bt_rle
Definition zstd_internal.h:91
@ bt_reserved
Definition zstd_internal.h:91
@ bt_raw
Definition zstd_internal.h:91
#define ML_DEFAULTNORMLOG
Definition zstd_internal.h:156
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
Definition zstd_decompress_block.c:653
symbolEncodingType_e
Definition zstd_internal.h:99
@ set_repeat
Definition zstd_internal.h:99
@ set_basic
Definition zstd_internal.h:99
@ set_compressed
Definition zstd_internal.h:99
@ set_rle
Definition zstd_internal.h:99
MEM_STATIC FORCE_INLINE_ATTR void ZSTD_wildcopy(void *dst, const void *src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
Definition zstd_internal.h:218
#define COPY8(d, s)
Definition zstd_internal.h:179
#define LL_DEFAULTNORMLOG
Definition zstd_internal.h:135
void ZSTD_invalidateRepCodes(ZSTD_CCtx *cctx)
Definition zstd_compress.c:2002
const seqStore_t * ZSTD_getSeqStore(const ZSTD_CCtx *ctx)
Definition zstd_compress.c:218
size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr)
Definition zstd_decompress_block.c:56
#define DefaultMaxOff
Definition zstd_internal.h:109
#define ZSTD_REP_NUM
Definition zstd_internal.h:69
ZSTD_overlap_e
Definition zstd_internal.h:204
@ ZSTD_overlap_src_before_dst
Definition zstd_internal.h:206
@ ZSTD_no_overlap
Definition zstd_internal.h:205
#define WILDCOPY_VECLEN
Definition zstd_internal.h:202
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const *seqStore, seqDef const *seq)
Definition zstd_internal.h:327
ZSTD_bufferMode_e
Definition zstd_internal.h:277
@ ZSTD_bm_stable
Definition zstd_internal.h:279
@ ZSTD_bm_buffered
Definition zstd_internal.h:278
#define COPY16(d, s)
Definition zstd_internal.h:199