1*3117ece4Schristos /* 2*3117ece4Schristos * Copyright (c) Meta Platforms, Inc. and affiliates. 3*3117ece4Schristos * All rights reserved. 4*3117ece4Schristos * 5*3117ece4Schristos * This source code is licensed under both the BSD-style license (found in the 6*3117ece4Schristos * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*3117ece4Schristos * in the COPYING file in the root directory of this source tree). 8*3117ece4Schristos * You may select, at your option, one of the above-listed licenses. 9*3117ece4Schristos */ 10*3117ece4Schristos 11*3117ece4Schristos #ifndef ZSTD_CCOMMON_H_MODULE 12*3117ece4Schristos #define ZSTD_CCOMMON_H_MODULE 13*3117ece4Schristos 14*3117ece4Schristos /* this module contains definitions which must be identical 15*3117ece4Schristos * across compression, decompression and dictBuilder. 16*3117ece4Schristos * It also contains a few functions useful to at least 2 of them 17*3117ece4Schristos * and which benefit from being inlined */ 18*3117ece4Schristos 19*3117ece4Schristos /*-************************************* 20*3117ece4Schristos * Dependencies 21*3117ece4Schristos ***************************************/ 22*3117ece4Schristos #include "compiler.h" 23*3117ece4Schristos #include "cpu.h" 24*3117ece4Schristos #include "mem.h" 25*3117ece4Schristos #include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */ 26*3117ece4Schristos #include "error_private.h" 27*3117ece4Schristos #define ZSTD_STATIC_LINKING_ONLY 28*3117ece4Schristos #include "../zstd.h" 29*3117ece4Schristos #define FSE_STATIC_LINKING_ONLY 30*3117ece4Schristos #include "fse.h" 31*3117ece4Schristos #include "huf.h" 32*3117ece4Schristos #ifndef XXH_STATIC_LINKING_ONLY 33*3117ece4Schristos # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ 34*3117ece4Schristos #endif 35*3117ece4Schristos #include "xxhash.h" /* XXH_reset, update, digest */ 36*3117ece4Schristos #ifndef ZSTD_NO_TRACE 37*3117ece4Schristos # include "zstd_trace.h" 38*3117ece4Schristos #else 39*3117ece4Schristos # define ZSTD_TRACE 0 40*3117ece4Schristos #endif 41*3117ece4Schristos 42*3117ece4Schristos #if defined (__cplusplus) 43*3117ece4Schristos extern "C" { 44*3117ece4Schristos #endif 45*3117ece4Schristos 46*3117ece4Schristos /* ---- static assert (debug) --- */ 47*3117ece4Schristos #define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) 48*3117ece4Schristos #define ZSTD_isError ERR_isError /* for inlining */ 49*3117ece4Schristos #define FSE_isError ERR_isError 50*3117ece4Schristos #define HUF_isError ERR_isError 51*3117ece4Schristos 52*3117ece4Schristos 53*3117ece4Schristos /*-************************************* 54*3117ece4Schristos * shared macros 55*3117ece4Schristos ***************************************/ 56*3117ece4Schristos #undef MIN 57*3117ece4Schristos #undef MAX 58*3117ece4Schristos #define MIN(a,b) ((a)<(b) ? (a) : (b)) 59*3117ece4Schristos #define MAX(a,b) ((a)>(b) ? (a) : (b)) 60*3117ece4Schristos #define BOUNDED(min,val,max) (MAX(min,MIN(val,max))) 61*3117ece4Schristos 62*3117ece4Schristos 63*3117ece4Schristos /*-************************************* 64*3117ece4Schristos * Common constants 65*3117ece4Schristos ***************************************/ 66*3117ece4Schristos #define ZSTD_OPT_NUM (1<<12) 67*3117ece4Schristos 68*3117ece4Schristos #define ZSTD_REP_NUM 3 /* number of repcodes */ 69*3117ece4Schristos static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 }; 70*3117ece4Schristos 71*3117ece4Schristos #define KB *(1 <<10) 72*3117ece4Schristos #define MB *(1 <<20) 73*3117ece4Schristos #define GB *(1U<<30) 74*3117ece4Schristos 75*3117ece4Schristos #define BIT7 128 76*3117ece4Schristos #define BIT6 64 77*3117ece4Schristos #define BIT5 32 78*3117ece4Schristos #define BIT4 16 79*3117ece4Schristos #define BIT1 2 80*3117ece4Schristos #define BIT0 1 81*3117ece4Schristos 82*3117ece4Schristos #define ZSTD_WINDOWLOG_ABSOLUTEMIN 10 83*3117ece4Schristos static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 }; 84*3117ece4Schristos static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 }; 85*3117ece4Schristos 86*3117ece4Schristos #define ZSTD_FRAMEIDSIZE 4 /* magic number size */ 87*3117ece4Schristos 88*3117ece4Schristos #define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */ 89*3117ece4Schristos static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE; 90*3117ece4Schristos typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e; 91*3117ece4Schristos 92*3117ece4Schristos #define ZSTD_FRAMECHECKSUMSIZE 4 93*3117ece4Schristos 94*3117ece4Schristos #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */ 95*3117ece4Schristos #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */) /* for a non-null block */ 96*3117ece4Schristos #define MIN_LITERALS_FOR_4_STREAMS 6 97*3117ece4Schristos 98*3117ece4Schristos typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e; 99*3117ece4Schristos 100*3117ece4Schristos #define LONGNBSEQ 0x7F00 101*3117ece4Schristos 102*3117ece4Schristos #define MINMATCH 3 103*3117ece4Schristos 104*3117ece4Schristos #define Litbits 8 105*3117ece4Schristos #define LitHufLog 11 106*3117ece4Schristos #define MaxLit ((1<<Litbits) - 1) 107*3117ece4Schristos #define MaxML 52 108*3117ece4Schristos #define MaxLL 35 109*3117ece4Schristos #define DefaultMaxOff 28 110*3117ece4Schristos #define MaxOff 31 111*3117ece4Schristos #define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */ 112*3117ece4Schristos #define MLFSELog 9 113*3117ece4Schristos #define LLFSELog 9 114*3117ece4Schristos #define OffFSELog 8 115*3117ece4Schristos #define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog) 116*3117ece4Schristos #define MaxMLBits 16 117*3117ece4Schristos #define MaxLLBits 16 118*3117ece4Schristos 119*3117ece4Schristos #define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */ 120*3117ece4Schristos /* Each table cannot take more than #symbols * FSELog bits */ 121*3117ece4Schristos #define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8) 122*3117ece4Schristos 123*3117ece4Schristos static UNUSED_ATTR const U8 LL_bits[MaxLL+1] = { 124*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 125*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 126*3117ece4Schristos 1, 1, 1, 1, 2, 2, 3, 3, 127*3117ece4Schristos 4, 6, 7, 8, 9,10,11,12, 128*3117ece4Schristos 13,14,15,16 129*3117ece4Schristos }; 130*3117ece4Schristos static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = { 131*3117ece4Schristos 4, 3, 2, 2, 2, 2, 2, 2, 132*3117ece4Schristos 2, 2, 2, 2, 2, 1, 1, 1, 133*3117ece4Schristos 2, 2, 2, 2, 2, 2, 2, 2, 134*3117ece4Schristos 2, 3, 2, 1, 1, 1, 1, 1, 135*3117ece4Schristos -1,-1,-1,-1 136*3117ece4Schristos }; 137*3117ece4Schristos #define LL_DEFAULTNORMLOG 6 /* for static allocation */ 138*3117ece4Schristos static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG; 139*3117ece4Schristos 140*3117ece4Schristos static UNUSED_ATTR const U8 ML_bits[MaxML+1] = { 141*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 142*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 143*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 144*3117ece4Schristos 0, 0, 0, 0, 0, 0, 0, 0, 145*3117ece4Schristos 1, 1, 1, 1, 2, 2, 3, 3, 146*3117ece4Schristos 4, 4, 5, 7, 8, 9,10,11, 147*3117ece4Schristos 12,13,14,15,16 148*3117ece4Schristos }; 149*3117ece4Schristos static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = { 150*3117ece4Schristos 1, 4, 3, 2, 2, 2, 2, 2, 151*3117ece4Schristos 2, 1, 1, 1, 1, 1, 1, 1, 152*3117ece4Schristos 1, 1, 1, 1, 1, 1, 1, 1, 153*3117ece4Schristos 1, 1, 1, 1, 1, 1, 1, 1, 154*3117ece4Schristos 1, 1, 1, 1, 1, 1, 1, 1, 155*3117ece4Schristos 1, 1, 1, 1, 1, 1,-1,-1, 156*3117ece4Schristos -1,-1,-1,-1,-1 157*3117ece4Schristos }; 158*3117ece4Schristos #define ML_DEFAULTNORMLOG 6 /* for static allocation */ 159*3117ece4Schristos static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG; 160*3117ece4Schristos 161*3117ece4Schristos static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = { 162*3117ece4Schristos 1, 1, 1, 1, 1, 1, 2, 2, 163*3117ece4Schristos 2, 1, 1, 1, 1, 1, 1, 1, 164*3117ece4Schristos 1, 1, 1, 1, 1, 1, 1, 1, 165*3117ece4Schristos -1,-1,-1,-1,-1 166*3117ece4Schristos }; 167*3117ece4Schristos #define OF_DEFAULTNORMLOG 5 /* for static allocation */ 168*3117ece4Schristos static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG; 169*3117ece4Schristos 170*3117ece4Schristos 171*3117ece4Schristos /*-******************************************* 172*3117ece4Schristos * Shared functions to include for inlining 173*3117ece4Schristos *********************************************/ 174*3117ece4Schristos static void ZSTD_copy8(void* dst, const void* src) { 175*3117ece4Schristos #if defined(ZSTD_ARCH_ARM_NEON) 176*3117ece4Schristos vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src)); 177*3117ece4Schristos #else 178*3117ece4Schristos ZSTD_memcpy(dst, src, 8); 179*3117ece4Schristos #endif 180*3117ece4Schristos } 181*3117ece4Schristos #define COPY8(d,s) do { ZSTD_copy8(d,s); d+=8; s+=8; } while (0) 182*3117ece4Schristos 183*3117ece4Schristos /* Need to use memmove here since the literal buffer can now be located within 184*3117ece4Schristos the dst buffer. In circumstances where the op "catches up" to where the 185*3117ece4Schristos literal buffer is, there can be partial overlaps in this call on the final 186*3117ece4Schristos copy if the literal is being shifted by less than 16 bytes. */ 187*3117ece4Schristos static void ZSTD_copy16(void* dst, const void* src) { 188*3117ece4Schristos #if defined(ZSTD_ARCH_ARM_NEON) 189*3117ece4Schristos vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src)); 190*3117ece4Schristos #elif defined(ZSTD_ARCH_X86_SSE2) 191*3117ece4Schristos _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src)); 192*3117ece4Schristos #elif defined(__clang__) 193*3117ece4Schristos ZSTD_memmove(dst, src, 16); 194*3117ece4Schristos #else 195*3117ece4Schristos /* ZSTD_memmove is not inlined properly by gcc */ 196*3117ece4Schristos BYTE copy16_buf[16]; 197*3117ece4Schristos ZSTD_memcpy(copy16_buf, src, 16); 198*3117ece4Schristos ZSTD_memcpy(dst, copy16_buf, 16); 199*3117ece4Schristos #endif 200*3117ece4Schristos } 201*3117ece4Schristos #define COPY16(d,s) do { ZSTD_copy16(d,s); d+=16; s+=16; } while (0) 202*3117ece4Schristos 203*3117ece4Schristos #define WILDCOPY_OVERLENGTH 32 204*3117ece4Schristos #define WILDCOPY_VECLEN 16 205*3117ece4Schristos 206*3117ece4Schristos typedef enum { 207*3117ece4Schristos ZSTD_no_overlap, 208*3117ece4Schristos ZSTD_overlap_src_before_dst 209*3117ece4Schristos /* ZSTD_overlap_dst_before_src, */ 210*3117ece4Schristos } ZSTD_overlap_e; 211*3117ece4Schristos 212*3117ece4Schristos /*! ZSTD_wildcopy() : 213*3117ece4Schristos * Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0) 214*3117ece4Schristos * @param ovtype controls the overlap detection 215*3117ece4Schristos * - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart. 216*3117ece4Schristos * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart. 217*3117ece4Schristos * The src buffer must be before the dst buffer. 218*3117ece4Schristos */ 219*3117ece4Schristos MEM_STATIC FORCE_INLINE_ATTR 220*3117ece4Schristos void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype) 221*3117ece4Schristos { 222*3117ece4Schristos ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src; 223*3117ece4Schristos const BYTE* ip = (const BYTE*)src; 224*3117ece4Schristos BYTE* op = (BYTE*)dst; 225*3117ece4Schristos BYTE* const oend = op + length; 226*3117ece4Schristos 227*3117ece4Schristos if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) { 228*3117ece4Schristos /* Handle short offset copies. */ 229*3117ece4Schristos do { 230*3117ece4Schristos COPY8(op, ip); 231*3117ece4Schristos } while (op < oend); 232*3117ece4Schristos } else { 233*3117ece4Schristos assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN); 234*3117ece4Schristos /* Separate out the first COPY16() call because the copy length is 235*3117ece4Schristos * almost certain to be short, so the branches have different 236*3117ece4Schristos * probabilities. Since it is almost certain to be short, only do 237*3117ece4Schristos * one COPY16() in the first call. Then, do two calls per loop since 238*3117ece4Schristos * at that point it is more likely to have a high trip count. 239*3117ece4Schristos */ 240*3117ece4Schristos ZSTD_copy16(op, ip); 241*3117ece4Schristos if (16 >= length) return; 242*3117ece4Schristos op += 16; 243*3117ece4Schristos ip += 16; 244*3117ece4Schristos do { 245*3117ece4Schristos COPY16(op, ip); 246*3117ece4Schristos COPY16(op, ip); 247*3117ece4Schristos } 248*3117ece4Schristos while (op < oend); 249*3117ece4Schristos } 250*3117ece4Schristos } 251*3117ece4Schristos 252*3117ece4Schristos MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize) 253*3117ece4Schristos { 254*3117ece4Schristos size_t const length = MIN(dstCapacity, srcSize); 255*3117ece4Schristos if (length > 0) { 256*3117ece4Schristos ZSTD_memcpy(dst, src, length); 257*3117ece4Schristos } 258*3117ece4Schristos return length; 259*3117ece4Schristos } 260*3117ece4Schristos 261*3117ece4Schristos /* define "workspace is too large" as this number of times larger than needed */ 262*3117ece4Schristos #define ZSTD_WORKSPACETOOLARGE_FACTOR 3 263*3117ece4Schristos 264*3117ece4Schristos /* when workspace is continuously too large 265*3117ece4Schristos * during at least this number of times, 266*3117ece4Schristos * context's memory usage is considered wasteful, 267*3117ece4Schristos * because it's sized to handle a worst case scenario which rarely happens. 268*3117ece4Schristos * In which case, resize it down to free some memory */ 269*3117ece4Schristos #define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128 270*3117ece4Schristos 271*3117ece4Schristos /* Controls whether the input/output buffer is buffered or stable. */ 272*3117ece4Schristos typedef enum { 273*3117ece4Schristos ZSTD_bm_buffered = 0, /* Buffer the input/output */ 274*3117ece4Schristos ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */ 275*3117ece4Schristos } ZSTD_bufferMode_e; 276*3117ece4Schristos 277*3117ece4Schristos 278*3117ece4Schristos /*-******************************************* 279*3117ece4Schristos * Private declarations 280*3117ece4Schristos *********************************************/ 281*3117ece4Schristos typedef struct seqDef_s { 282*3117ece4Schristos U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */ 283*3117ece4Schristos U16 litLength; 284*3117ece4Schristos U16 mlBase; /* mlBase == matchLength - MINMATCH */ 285*3117ece4Schristos } seqDef; 286*3117ece4Schristos 287*3117ece4Schristos /* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */ 288*3117ece4Schristos typedef enum { 289*3117ece4Schristos ZSTD_llt_none = 0, /* no longLengthType */ 290*3117ece4Schristos ZSTD_llt_literalLength = 1, /* represents a long literal */ 291*3117ece4Schristos ZSTD_llt_matchLength = 2 /* represents a long match */ 292*3117ece4Schristos } ZSTD_longLengthType_e; 293*3117ece4Schristos 294*3117ece4Schristos typedef struct { 295*3117ece4Schristos seqDef* sequencesStart; 296*3117ece4Schristos seqDef* sequences; /* ptr to end of sequences */ 297*3117ece4Schristos BYTE* litStart; 298*3117ece4Schristos BYTE* lit; /* ptr to end of literals */ 299*3117ece4Schristos BYTE* llCode; 300*3117ece4Schristos BYTE* mlCode; 301*3117ece4Schristos BYTE* ofCode; 302*3117ece4Schristos size_t maxNbSeq; 303*3117ece4Schristos size_t maxNbLit; 304*3117ece4Schristos 305*3117ece4Schristos /* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength 306*3117ece4Schristos * in the seqStore that has a value larger than U16 (if it exists). To do so, we increment 307*3117ece4Schristos * the existing value of the litLength or matchLength by 0x10000. 308*3117ece4Schristos */ 309*3117ece4Schristos ZSTD_longLengthType_e longLengthType; 310*3117ece4Schristos U32 longLengthPos; /* Index of the sequence to apply long length modification to */ 311*3117ece4Schristos } seqStore_t; 312*3117ece4Schristos 313*3117ece4Schristos typedef struct { 314*3117ece4Schristos U32 litLength; 315*3117ece4Schristos U32 matchLength; 316*3117ece4Schristos } ZSTD_sequenceLength; 317*3117ece4Schristos 318*3117ece4Schristos /** 319*3117ece4Schristos * Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences 320*3117ece4Schristos * indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength. 321*3117ece4Schristos */ 322*3117ece4Schristos MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq) 323*3117ece4Schristos { 324*3117ece4Schristos ZSTD_sequenceLength seqLen; 325*3117ece4Schristos seqLen.litLength = seq->litLength; 326*3117ece4Schristos seqLen.matchLength = seq->mlBase + MINMATCH; 327*3117ece4Schristos if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) { 328*3117ece4Schristos if (seqStore->longLengthType == ZSTD_llt_literalLength) { 329*3117ece4Schristos seqLen.litLength += 0x10000; 330*3117ece4Schristos } 331*3117ece4Schristos if (seqStore->longLengthType == ZSTD_llt_matchLength) { 332*3117ece4Schristos seqLen.matchLength += 0x10000; 333*3117ece4Schristos } 334*3117ece4Schristos } 335*3117ece4Schristos return seqLen; 336*3117ece4Schristos } 337*3117ece4Schristos 338*3117ece4Schristos /** 339*3117ece4Schristos * Contains the compressed frame size and an upper-bound for the decompressed frame size. 340*3117ece4Schristos * Note: before using `compressedSize`, check for errors using ZSTD_isError(). 341*3117ece4Schristos * similarly, before using `decompressedBound`, check for errors using: 342*3117ece4Schristos * `decompressedBound != ZSTD_CONTENTSIZE_ERROR` 343*3117ece4Schristos */ 344*3117ece4Schristos typedef struct { 345*3117ece4Schristos size_t nbBlocks; 346*3117ece4Schristos size_t compressedSize; 347*3117ece4Schristos unsigned long long decompressedBound; 348*3117ece4Schristos } ZSTD_frameSizeInfo; /* decompress & legacy */ 349*3117ece4Schristos 350*3117ece4Schristos const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */ 351*3117ece4Schristos int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */ 352*3117ece4Schristos 353*3117ece4Schristos 354*3117ece4Schristos /* ZSTD_invalidateRepCodes() : 355*3117ece4Schristos * ensures next compression will not use repcodes from previous block. 356*3117ece4Schristos * Note : only works with regular variant; 357*3117ece4Schristos * do not use with extDict variant ! */ 358*3117ece4Schristos void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); /* zstdmt, adaptive_compression (shouldn't get this definition from here) */ 359*3117ece4Schristos 360*3117ece4Schristos 361*3117ece4Schristos typedef struct { 362*3117ece4Schristos blockType_e blockType; 363*3117ece4Schristos U32 lastBlock; 364*3117ece4Schristos U32 origSize; 365*3117ece4Schristos } blockProperties_t; /* declared here for decompress and fullbench */ 366*3117ece4Schristos 367*3117ece4Schristos /*! ZSTD_getcBlockSize() : 368*3117ece4Schristos * Provides the size of compressed block from block header `src` */ 369*3117ece4Schristos /* Used by: decompress, fullbench */ 370*3117ece4Schristos size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, 371*3117ece4Schristos blockProperties_t* bpPtr); 372*3117ece4Schristos 373*3117ece4Schristos /*! ZSTD_decodeSeqHeaders() : 374*3117ece4Schristos * decode sequence header from src */ 375*3117ece4Schristos /* Used by: zstd_decompress_block, fullbench */ 376*3117ece4Schristos size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr, 377*3117ece4Schristos const void* src, size_t srcSize); 378*3117ece4Schristos 379*3117ece4Schristos /** 380*3117ece4Schristos * @returns true iff the CPU supports dynamic BMI2 dispatch. 381*3117ece4Schristos */ 382*3117ece4Schristos MEM_STATIC int ZSTD_cpuSupportsBmi2(void) 383*3117ece4Schristos { 384*3117ece4Schristos ZSTD_cpuid_t cpuid = ZSTD_cpuid(); 385*3117ece4Schristos return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid); 386*3117ece4Schristos } 387*3117ece4Schristos 388*3117ece4Schristos #if defined (__cplusplus) 389*3117ece4Schristos } 390*3117ece4Schristos #endif 391*3117ece4Schristos 392*3117ece4Schristos #endif /* ZSTD_CCOMMON_H_MODULE */ 393