Skip to content

Commit

Permalink
Update zstd
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat-OuO committed Dec 24, 2024
1 parent 8c30a8d commit e5e6124
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 44 deletions.
4 changes: 4 additions & 0 deletions src/external/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@
* Alignment check
*****************************************************************/

/* @return 1 if @u is a 2^n value, 0 otherwise
* useful to check a value is valid for alignment restrictions */
MEM_STATIC int ZSTD_isPower2(size_t u) { return (u & (u - 1)) == 0; }

/* this test was initially positioned in mem.h,
* but this file is removed (or replaced) for linux kernel
* so it's now hosted in compiler.h,
Expand Down
2 changes: 1 addition & 1 deletion src/external/common/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
U32 f7b = 0;
U32 f7c = 0;
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
#if !defined(__clang__) || __clang_major__ >= 16
#if !defined(_M_X64) || !defined(__clang__) || __clang_major__ >= 16
int reg[4];
__cpuid((int*) reg, 0);
{
Expand Down
2 changes: 1 addition & 1 deletion src/external/common/error_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef ZSTD_ErrorCode ERR_enum;
******************************************/
#undef ERROR /* already defined on Visual Studio */
#define ERROR(name) ZSTD_ERROR(name)
#define ZSTD_ERROR(name) ((size_t) - PREFIX(name))
#define ZSTD_ERROR(name) ((size_t) -PREFIX(name))

ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }

Expand Down
2 changes: 1 addition & 1 deletion src/external/common/xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3487,7 +3487,7 @@ static XXH_PUREF xxh_u64 XXH64_finalize(xxh_u64 hash,
}
if (len >= 4)
{
hash ^= (xxh_u64) (XXH_get32bits(ptr)) * XXH_PRIME64_1;
hash ^= (xxh_u64) (XXH_get32bits(ptr)) *XXH_PRIME64_1;
ptr += 4;
hash = XXH_rotl64(hash, 23) * XXH_PRIME64_2 + XXH_PRIME64_3;
len -= 4;
Expand Down
5 changes: 2 additions & 3 deletions src/external/decompress/zstd_decompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,8 @@ static size_t ZSTD_decompressFrame(
}
ZSTD_DCtx_trace_end(dctx, (U64) (op - ostart), (U64) (ip - istart), /* streaming */ 0);
/* Allow caller to get size read */
DEBUGLOG(4,
"ZSTD_decompressFrame: decompressed frame of size %zi, consuming %zi bytes of input",
op - ostart, ip - (const BYTE*) *srcPtr);
DEBUGLOG(4, "ZSTD_decompressFrame: decompressed frame of size %i, consuming %i bytes of input",
(int) (op - ostart), (int) (ip - (const BYTE*) *srcPtr));
*srcPtr = ip;
*srcSizePtr = remainingSrcSize;
return (size_t) (op - ostart);
Expand Down
82 changes: 60 additions & 22 deletions src/external/zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ extern "C" {
#define ZSTD_H_235446

/* ====== Dependencies ======*/
#include <limits.h> /* INT_MAX */
#include <stddef.h> /* size_t */


Expand Down Expand Up @@ -109,7 +108,7 @@ extern "C" {
/*------ Version ------*/
#define ZSTD_VERSION_MAJOR 1
#define ZSTD_VERSION_MINOR 5
#define ZSTD_VERSION_RELEASE 6
#define ZSTD_VERSION_RELEASE 7
#define ZSTD_VERSION_NUMBER \
(ZSTD_VERSION_MAJOR * 100 * 100 + ZSTD_VERSION_MINOR * 100 + ZSTD_VERSION_RELEASE)

Expand Down Expand Up @@ -149,7 +148,7 @@ ZSTDLIB_API const char* ZSTD_versionString(void);


/***************************************
* Simple API
* Simple Core API
***************************************/
/*! ZSTD_compress() :
* Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
Expand All @@ -174,6 +173,9 @@ ZSTDLIB_API size_t ZSTD_decompress(void* dst,
const void* src,
size_t compressedSize);


/*====== Decompression helper functions ======*/

/*! ZSTD_getFrameContentSize() : requires v1.3.0+
* `src` should point to the start of a ZSTD encoded frame.
* `srcSize` must be at least as large as the frame header.
Expand Down Expand Up @@ -220,22 +222,23 @@ unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);


/*====== Helper functions ======*/
/* ZSTD_compressBound() :
/*====== Compression helper functions ======*/

/*! ZSTD_compressBound() :
* maximum compressed size in worst case single-pass scenario.
* When invoking `ZSTD_compress()` or any other one-pass compression function,
* When invoking `ZSTD_compress()`, or any other one-pass compression function,
* it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
* as it eliminates one potential failure scenario,
* aka not enough room in dst buffer to write the compressed frame.
* Note : ZSTD_compressBound() itself can fail, if @srcSize > ZSTD_MAX_INPUT_SIZE .
* Note : ZSTD_compressBound() itself can fail, if @srcSize >= ZSTD_MAX_INPUT_SIZE .
* In which case, ZSTD_compressBound() will return an error code
* which can be tested using ZSTD_isError().
*
* ZSTD_COMPRESSBOUND() :
* same as ZSTD_compressBound(), but as a macro.
* It can be used to produce constants, which can be useful for static allocation,
* for example to size a static array on stack.
* Will produce constant value 0 if srcSize too large.
* Will produce constant value 0 if srcSize is too large.
*/
#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t) == 8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
#define ZSTD_COMPRESSBOUND(srcSize) \
Expand All @@ -247,15 +250,22 @@ ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
: 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
ZSTDLIB_API size_t ZSTD_compressBound(
size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */


/*====== Error helper functions ======*/
#include "zstd_errors.h" /* list of errors */
/* ZSTD_isError() :
* Most ZSTD_* functions returning a size_t value can be tested for error,
* using ZSTD_isError().
* @return 1 if error, 0 otherwise
*/
ZSTDLIB_API unsigned
ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
ZSTD_isError(size_t result); /*!< tells if a `size_t` function result is an error code */
ZSTDLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(
size_t
functionResult); /* convert a result into an error code, which can be compared to error enum list */
ZSTDLIB_API const char*
ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */
ZSTD_getErrorName(size_t result); /*!< provides readable string from a function result */
ZSTDLIB_API int
ZSTD_minCLevel(void); /*!< minimum negative compression level allowed, requires v1.4.0+ */
ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */
Expand All @@ -268,25 +278,25 @@ ZSTDLIB_API int ZSTD_defaultCLevel(
***************************************/
/*= Compression context
* When compressing many times,
* it is recommended to allocate a context just once,
* it is recommended to allocate a compression context just once,
* and reuse it for each successive compression operation.
* This will make workload friendlier for system's memory.
* This will make the workload easier for system's memory.
* Note : re-using context is just a speed / resource optimization.
* It doesn't change the compression ratio, which remains identical.
* Note 2 : In multi-threaded environments,
* use one different context per thread for parallel execution.
* Note 2: For parallel execution in multi-threaded environments,
* use one different context per thread .
*/
typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* compatible with NULL pointer */

/*! ZSTD_compressCCtx() :
* Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
* Important : in order to mirror `ZSTD_compress()` behavior,
* this function compresses at the requested compression level,
* __ignoring any other advanced parameter__ .
* If any advanced parameter was set using the advanced API,
* they will all be reset. Only `compressionLevel` remains.
* they will all be reset. Only @compressionLevel remains.
*/
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
void* dst,
Expand Down Expand Up @@ -517,7 +527,8 @@ typedef enum {
* ZSTD_c_stableOutBuffer
* ZSTD_c_blockDelimiters
* ZSTD_c_validateSequences
* ZSTD_c_useBlockSplitter
* ZSTD_c_blockSplitterLevel
* ZSTD_c_splitAfterSequences
* ZSTD_c_useRowMatchFinder
* ZSTD_c_prefetchCDictTables
* ZSTD_c_enableSeqProducerFallback
Expand All @@ -544,7 +555,8 @@ typedef enum {
ZSTD_c_experimentalParam16 = 1013,
ZSTD_c_experimentalParam17 = 1014,
ZSTD_c_experimentalParam18 = 1015,
ZSTD_c_experimentalParam19 = 1016
ZSTD_c_experimentalParam19 = 1016,
ZSTD_c_experimentalParam20 = 1017
} ZSTD_cParameter;

typedef struct {
Expand Down Expand Up @@ -1246,6 +1258,8 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY

#include <limits.h> /* INT_MAX */

/* This can be overridden externally to hide static symbols. */
#ifndef ZSTDLIB_STATIC_API
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT == 1)
Expand Down Expand Up @@ -2261,16 +2275,40 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cc
*/
#define ZSTD_c_validateSequences ZSTD_c_experimentalParam12

/* ZSTD_c_useBlockSplitter
* Controlled with ZSTD_paramSwitch_e enum.
/* ZSTD_c_blockSplitterLevel
* note: this parameter only influences the first splitter stage,
* which is active before producing the sequences.
* ZSTD_c_splitAfterSequences controls the next splitter stage,
* which is active after sequence production.
* Note that both can be combined.
* Allowed values are between 0 and ZSTD_BLOCKSPLITTER_LEVEL_MAX included.
* 0 means "auto", which will select a value depending on current ZSTD_c_strategy.
* 1 means no splitting.
* Then, values from 2 to 6 are sorted in increasing cpu load order.
*
* Note that currently the first block is never split,
* to ensure expansion guarantees in presence of incompressible data.
*/
#define ZSTD_BLOCKSPLITTER_LEVEL_MAX 6
#define ZSTD_c_blockSplitterLevel ZSTD_c_experimentalParam20

/* ZSTD_c_splitAfterSequences
* This is a stronger splitter algorithm,
* based on actual sequences previously produced by the selected parser.
* It's also slower, and as a consequence, mostly used for high compression levels.
* While the post-splitter does overlap with the pre-splitter,
* both can nonetheless be combined,
* notably with ZSTD_c_blockSplitterLevel at ZSTD_BLOCKSPLITTER_LEVEL_MAX,
* resulting in higher compression ratio than just one of them.
*
* Default is ZSTD_ps_auto.
* Set to ZSTD_ps_disable to never use block splitter.
* Set to ZSTD_ps_enable to always use block splitter.
*
* By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
* block splitting based on the compression parameters.
*/
#define ZSTD_c_useBlockSplitter ZSTD_c_experimentalParam13
#define ZSTD_c_splitAfterSequences ZSTD_c_experimentalParam13

/* ZSTD_c_useRowMatchFinder
* Controlled with ZSTD_paramSwitch_e enum.
Expand Down Expand Up @@ -2349,7 +2387,6 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cc
* that overrides the default ZSTD_BLOCKSIZE_MAX. It cannot be used to set upper
* bounds greater than ZSTD_BLOCKSIZE_MAX or bounds lower than 1KB (will make
* compressBound() inaccurate). Only currently meant to be used for testing.
*
*/
#define ZSTD_c_maxBlockSize ZSTD_c_experimentalParam18

Expand Down Expand Up @@ -2377,6 +2414,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cc
*/
#define ZSTD_c_searchForExternalRepcodes ZSTD_c_experimentalParam19


/*! ZSTD_CCtx_getParameter() :
* Get the requested compression parameter value, selected by enum ZSTD_cParameter,
* and store it into int* value.
Expand Down
14 changes: 3 additions & 11 deletions src/external/zstd_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
extern "C" {
#endif

/*===== dependency =====*/
#include <stddef.h> /* size_t */


/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
#ifndef ZSTDERRORLIB_VISIBLE
/* Backwards compatibility with old macro name */
Expand Down Expand Up @@ -103,13 +99,9 @@ typedef enum {
120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
} ZSTD_ErrorCode;

/*! ZSTD_getErrorCode() :
convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
which can be used to compare with enum list published above */
ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
ZSTDERRORLIB_API const char* ZSTD_getErrorString(
ZSTD_ErrorCode
code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
ZSTDERRORLIB_API const char* ZSTD_getErrorString(
ZSTD_ErrorCode
code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */


#if defined(__cplusplus)
Expand Down
6 changes: 2 additions & 4 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ using psqt_vec_t = int32x4_t;
#define vec_add_16(a, b) vaddq_s16(a, b)
#define vec_sub_16(a, b) vsubq_s16(a, b)
#define vec_mulhi_16(a, b) vqdmulhq_s16(a, b)
#define vec_zero() \
vec_t { 0 }
#define vec_zero() vec_t{0}
#define vec_set_16(a) vdupq_n_s16(a)
#define vec_max_16(a, b) vmaxq_s16(a, b)
#define vec_min_16(a, b) vminq_s16(a, b)
Expand All @@ -167,8 +166,7 @@ using psqt_vec_t = int32x4_t;
#define vec_store_psqt(a, b) *(a) = (b)
#define vec_add_psqt_32(a, b) vaddq_s32(a, b)
#define vec_sub_psqt_32(a, b) vsubq_s32(a, b)
#define vec_zero_psqt() \
psqt_vec_t { 0 }
#define vec_zero_psqt() psqt_vec_t{0}
#define NumRegistersSIMD 16
#define MaxChunkSize 16

Expand Down
2 changes: 1 addition & 1 deletion src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ThreadPool {
std::vector<std::unique_ptr<Thread>> threads;
std::vector<NumaIndex> boundThreadToNumaNode;

uint64_t accumulate(std::atomic<uint64_t> Search::Worker::*member) const {
uint64_t accumulate(std::atomic<uint64_t> Search::Worker::* member) const {

uint64_t sum = 0;
for (auto&& th : threads)
Expand Down

0 comments on commit e5e6124

Please sign in to comment.