zstd-ruby 1.5.0.0 → 1.5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/README.md +1 -1
- data/ext/zstdruby/extconf.rb +2 -1
- data/ext/zstdruby/libzstd/Makefile +50 -175
- data/ext/zstdruby/libzstd/README.md +7 -1
- data/ext/zstdruby/libzstd/common/bitstream.h +24 -9
- data/ext/zstdruby/libzstd/common/compiler.h +89 -43
- data/ext/zstdruby/libzstd/common/entropy_common.c +11 -5
- data/ext/zstdruby/libzstd/common/error_private.h +79 -0
- data/ext/zstdruby/libzstd/common/fse.h +2 -1
- data/ext/zstdruby/libzstd/common/fse_decompress.c +1 -1
- data/ext/zstdruby/libzstd/common/huf.h +24 -22
- data/ext/zstdruby/libzstd/common/mem.h +18 -0
- data/ext/zstdruby/libzstd/common/pool.c +11 -6
- data/ext/zstdruby/libzstd/common/pool.h +2 -2
- data/ext/zstdruby/libzstd/common/portability_macros.h +137 -0
- data/ext/zstdruby/libzstd/common/xxhash.c +5 -805
- data/ext/zstdruby/libzstd/common/xxhash.h +5568 -167
- data/ext/zstdruby/libzstd/common/zstd_internal.h +95 -92
- data/ext/zstdruby/libzstd/common/zstd_trace.h +12 -3
- data/ext/zstdruby/libzstd/compress/clevels.h +134 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +63 -27
- data/ext/zstdruby/libzstd/compress/huf_compress.c +537 -104
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +307 -373
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +174 -83
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +4 -3
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +3 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +15 -14
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +4 -3
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +41 -27
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +295 -120
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +309 -130
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +482 -562
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +9 -7
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +4 -1
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +249 -148
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +76 -38
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +4 -1
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +727 -189
- data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +585 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +85 -22
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +744 -220
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -2
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +34 -3
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +23 -3
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +9 -2
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +11 -4
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +101 -30
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +2 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +3 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +3 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +3 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +3 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +3 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +3 -7
- data/ext/zstdruby/libzstd/libzstd.mk +203 -0
- data/ext/zstdruby/libzstd/libzstd.pc.in +1 -0
- data/ext/zstdruby/libzstd/module.modulemap +25 -0
- data/ext/zstdruby/libzstd/zdict.h +4 -4
- data/ext/zstdruby/libzstd/zstd.h +179 -136
- data/ext/zstdruby/zstdruby.c +2 -2
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +11 -6
@@ -22,6 +22,8 @@ extern "C" {
|
|
22
22
|
* Dependencies
|
23
23
|
******************************************/
|
24
24
|
#include "../zstd_errors.h" /* enum list */
|
25
|
+
#include "compiler.h"
|
26
|
+
#include "debug.h"
|
25
27
|
#include "zstd_deps.h" /* size_t */
|
26
28
|
|
27
29
|
|
@@ -73,6 +75,83 @@ ERR_STATIC const char* ERR_getErrorName(size_t code)
|
|
73
75
|
return ERR_getErrorString(ERR_getErrorCode(code));
|
74
76
|
}
|
75
77
|
|
78
|
+
/**
|
79
|
+
* Ignore: this is an internal helper.
|
80
|
+
*
|
81
|
+
* This is a helper function to help force C99-correctness during compilation.
|
82
|
+
* Under strict compilation modes, variadic macro arguments can't be empty.
|
83
|
+
* However, variadic function arguments can be. Using a function therefore lets
|
84
|
+
* us statically check that at least one (string) argument was passed,
|
85
|
+
* independent of the compilation flags.
|
86
|
+
*/
|
87
|
+
static INLINE_KEYWORD UNUSED_ATTR
|
88
|
+
void _force_has_format_string(const char *format, ...) {
|
89
|
+
(void)format;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Ignore: this is an internal helper.
|
94
|
+
*
|
95
|
+
* We want to force this function invocation to be syntactically correct, but
|
96
|
+
* we don't want to force runtime evaluation of its arguments.
|
97
|
+
*/
|
98
|
+
#define _FORCE_HAS_FORMAT_STRING(...) \
|
99
|
+
if (0) { \
|
100
|
+
_force_has_format_string(__VA_ARGS__); \
|
101
|
+
}
|
102
|
+
|
103
|
+
#define ERR_QUOTE(str) #str
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Return the specified error if the condition evaluates to true.
|
107
|
+
*
|
108
|
+
* In debug modes, prints additional information.
|
109
|
+
* In order to do that (particularly, printing the conditional that failed),
|
110
|
+
* this can't just wrap RETURN_ERROR().
|
111
|
+
*/
|
112
|
+
#define RETURN_ERROR_IF(cond, err, ...) \
|
113
|
+
if (cond) { \
|
114
|
+
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
115
|
+
__FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
|
116
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
117
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
118
|
+
RAWLOG(3, "\n"); \
|
119
|
+
return ERROR(err); \
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Unconditionally return the specified error.
|
124
|
+
*
|
125
|
+
* In debug modes, prints additional information.
|
126
|
+
*/
|
127
|
+
#define RETURN_ERROR(err, ...) \
|
128
|
+
do { \
|
129
|
+
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
130
|
+
__FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
|
131
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
132
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
133
|
+
RAWLOG(3, "\n"); \
|
134
|
+
return ERROR(err); \
|
135
|
+
} while(0);
|
136
|
+
|
137
|
+
/**
|
138
|
+
* If the provided expression evaluates to an error code, returns that error code.
|
139
|
+
*
|
140
|
+
* In debug modes, prints additional information.
|
141
|
+
*/
|
142
|
+
#define FORWARD_IF_ERROR(err, ...) \
|
143
|
+
do { \
|
144
|
+
size_t const err_code = (err); \
|
145
|
+
if (ERR_isError(err_code)) { \
|
146
|
+
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
147
|
+
__FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
|
148
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
149
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
150
|
+
RAWLOG(3, "\n"); \
|
151
|
+
return err_code; \
|
152
|
+
} \
|
153
|
+
} while(0);
|
154
|
+
|
76
155
|
#if defined (__cplusplus)
|
77
156
|
}
|
78
157
|
#endif
|
@@ -336,8 +336,9 @@ size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
|
|
336
336
|
/* FSE_buildCTable_wksp() :
|
337
337
|
* Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
|
338
338
|
* `wkspSize` must be >= `FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog)` of `unsigned`.
|
339
|
+
* See FSE_buildCTable_wksp() for breakdown of workspace usage.
|
339
340
|
*/
|
340
|
-
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog) (maxSymbolValue + 2 + (1ull << (tableLog
|
341
|
+
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog) (((maxSymbolValue + 2) + (1ull << (tableLog)))/2 + sizeof(U64)/sizeof(U32) /* additional 8 bytes for potential table overwrite */)
|
341
342
|
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE(maxSymbolValue, tableLog) (sizeof(unsigned) * FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog))
|
342
343
|
size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
343
344
|
|
@@ -365,7 +365,7 @@ static size_t FSE_decompress_wksp_body_default(void* dst, size_t dstCapacity, co
|
|
365
365
|
}
|
366
366
|
|
367
367
|
#if DYNAMIC_BMI2
|
368
|
-
|
368
|
+
BMI2_TARGET_ATTRIBUTE static size_t FSE_decompress_wksp_body_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
|
369
369
|
{
|
370
370
|
return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 1);
|
371
371
|
}
|
@@ -89,9 +89,9 @@ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
|
|
89
89
|
|
90
90
|
/** HUF_compress4X_wksp() :
|
91
91
|
* Same as HUF_compress2(), but uses externally allocated `workSpace`.
|
92
|
-
* `workspace` must
|
93
|
-
#define HUF_WORKSPACE_SIZE ((
|
94
|
-
#define
|
92
|
+
* `workspace` must be at least as large as HUF_WORKSPACE_SIZE */
|
93
|
+
#define HUF_WORKSPACE_SIZE ((8 << 10) + 512 /* sorting scratch space */)
|
94
|
+
#define HUF_WORKSPACE_SIZE_U64 (HUF_WORKSPACE_SIZE / sizeof(U64))
|
95
95
|
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
96
96
|
const void* src, size_t srcSize,
|
97
97
|
unsigned maxSymbolValue, unsigned tableLog,
|
@@ -116,11 +116,11 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|
116
116
|
|
117
117
|
|
118
118
|
/* *** Constants *** */
|
119
|
-
#define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to
|
119
|
+
#define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_TABLELOG_ABSOLUTEMAX */
|
120
120
|
#define HUF_TABLELOG_DEFAULT 11 /* default tableLog value when none specified */
|
121
121
|
#define HUF_SYMBOLVALUE_MAX 255
|
122
122
|
|
123
|
-
#define HUF_TABLELOG_ABSOLUTEMAX
|
123
|
+
#define HUF_TABLELOG_ABSOLUTEMAX 12 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
|
124
124
|
#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
|
125
125
|
# error "HUF_TABLELOG_MAX is too large !"
|
126
126
|
#endif
|
@@ -136,15 +136,11 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|
136
136
|
|
137
137
|
/* static allocation of HUF's Compression Table */
|
138
138
|
/* this is a private definition, just exposed for allocation and strict aliasing purpose. never EVER access its members directly */
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
}; /* typedef'd to HUF_CElt */
|
143
|
-
typedef struct HUF_CElt_s HUF_CElt; /* consider it an incomplete type */
|
144
|
-
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
145
|
-
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
139
|
+
typedef size_t HUF_CElt; /* consider it an incomplete type */
|
140
|
+
#define HUF_CTABLE_SIZE_ST(maxSymbolValue) ((maxSymbolValue)+2) /* Use tables of size_t, for proper alignment */
|
141
|
+
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_ST(maxSymbolValue) * sizeof(size_t))
|
146
142
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
147
|
-
HUF_CElt name[
|
143
|
+
HUF_CElt name[HUF_CTABLE_SIZE_ST(maxSymbolValue)] /* no final ; */
|
148
144
|
|
149
145
|
/* static allocation of HUF's DTable */
|
150
146
|
typedef U32 HUF_DTable;
|
@@ -194,6 +190,7 @@ size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSym
|
|
194
190
|
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
195
191
|
size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog, void* workspace, size_t workspaceSize);
|
196
192
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
193
|
+
size_t HUF_compress4X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2);
|
197
194
|
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
198
195
|
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
199
196
|
|
@@ -206,12 +203,13 @@ typedef enum {
|
|
206
203
|
* Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
207
204
|
* If it uses hufTable it does not modify hufTable or repeat.
|
208
205
|
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
209
|
-
* If preferRepeat then the old table will always be used if valid.
|
206
|
+
* If preferRepeat then the old table will always be used if valid.
|
207
|
+
* If suspectUncompressible then some sampling checks will be run to potentially skip huffman coding */
|
210
208
|
size_t HUF_compress4X_repeat(void* dst, size_t dstSize,
|
211
209
|
const void* src, size_t srcSize,
|
212
210
|
unsigned maxSymbolValue, unsigned tableLog,
|
213
211
|
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
214
|
-
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
|
212
|
+
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2, unsigned suspectUncompressible);
|
215
213
|
|
216
214
|
/** HUF_buildCTable_wksp() :
|
217
215
|
* Same as HUF_buildCTable(), but using externally allocated scratch buffer.
|
@@ -249,11 +247,10 @@ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
|
|
249
247
|
* Loading a CTable saved with HUF_writeCTable() */
|
250
248
|
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
|
251
249
|
|
252
|
-
/**
|
250
|
+
/** HUF_getNbBitsFromCTable() :
|
253
251
|
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
254
|
-
* Note 1 : is not inlined, as HUF_CElt definition is private
|
255
|
-
|
256
|
-
U32 HUF_getNbBits(const void* symbolTable, U32 symbolValue);
|
252
|
+
* Note 1 : is not inlined, as HUF_CElt definition is private */
|
253
|
+
U32 HUF_getNbBitsFromCTable(const HUF_CElt* symbolTable, U32 symbolValue);
|
257
254
|
|
258
255
|
/*
|
259
256
|
* HUF_decompress() does the following:
|
@@ -305,18 +302,20 @@ size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* c
|
|
305
302
|
/* ====================== */
|
306
303
|
|
307
304
|
size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
308
|
-
size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least
|
305
|
+
size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U64 U64 */
|
309
306
|
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
307
|
+
size_t HUF_compress1X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2);
|
310
308
|
/** HUF_compress1X_repeat() :
|
311
309
|
* Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
312
310
|
* If it uses hufTable it does not modify hufTable or repeat.
|
313
311
|
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
314
|
-
* If preferRepeat then the old table will always be used if valid.
|
312
|
+
* If preferRepeat then the old table will always be used if valid.
|
313
|
+
* If suspectUncompressible then some sampling checks will be run to potentially skip huffman coding */
|
315
314
|
size_t HUF_compress1X_repeat(void* dst, size_t dstSize,
|
316
315
|
const void* src, size_t srcSize,
|
317
316
|
unsigned maxSymbolValue, unsigned tableLog,
|
318
317
|
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
319
|
-
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
|
318
|
+
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2, unsigned suspectUncompressible);
|
320
319
|
|
321
320
|
size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
|
322
321
|
#ifndef HUF_FORCE_DECOMPRESS_X1
|
@@ -354,6 +353,9 @@ size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t ds
|
|
354
353
|
#ifndef HUF_FORCE_DECOMPRESS_X2
|
355
354
|
size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
|
356
355
|
#endif
|
356
|
+
#ifndef HUF_FORCE_DECOMPRESS_X1
|
357
|
+
size_t HUF_readDTableX2_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
|
358
|
+
#endif
|
357
359
|
|
358
360
|
#endif /* HUF_STATIC_LINKING_ONLY */
|
359
361
|
|
@@ -51,6 +51,8 @@ extern "C" {
|
|
51
51
|
# include <stdint.h> /* intptr_t */
|
52
52
|
# endif
|
53
53
|
typedef uint8_t BYTE;
|
54
|
+
typedef uint8_t U8;
|
55
|
+
typedef int8_t S8;
|
54
56
|
typedef uint16_t U16;
|
55
57
|
typedef int16_t S16;
|
56
58
|
typedef uint32_t U32;
|
@@ -63,6 +65,8 @@ extern "C" {
|
|
63
65
|
# error "this implementation requires char to be exactly 8-bit type"
|
64
66
|
#endif
|
65
67
|
typedef unsigned char BYTE;
|
68
|
+
typedef unsigned char U8;
|
69
|
+
typedef signed char S8;
|
66
70
|
#if USHRT_MAX != 65535
|
67
71
|
# error "this implementation requires short to be exactly 16-bit type"
|
68
72
|
#endif
|
@@ -153,8 +157,22 @@ MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
|
|
153
157
|
|
154
158
|
MEM_STATIC unsigned MEM_isLittleEndian(void)
|
155
159
|
{
|
160
|
+
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
161
|
+
return 1;
|
162
|
+
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
163
|
+
return 0;
|
164
|
+
#elif defined(__clang__) && __LITTLE_ENDIAN__
|
165
|
+
return 1;
|
166
|
+
#elif defined(__clang__) && __BIG_ENDIAN__
|
167
|
+
return 0;
|
168
|
+
#elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
|
169
|
+
return 1;
|
170
|
+
#elif defined(__DMC__) && defined(_M_IX86)
|
171
|
+
return 1;
|
172
|
+
#else
|
156
173
|
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
|
157
174
|
return one.c[0];
|
175
|
+
#endif
|
158
176
|
}
|
159
177
|
|
160
178
|
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
@@ -86,7 +86,7 @@ static void* POOL_thread(void* opaque) {
|
|
86
86
|
{ POOL_job const job = ctx->queue[ctx->queueHead];
|
87
87
|
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
|
88
88
|
ctx->numThreadsBusy++;
|
89
|
-
ctx->queueEmpty = ctx->queueHead == ctx->queueTail;
|
89
|
+
ctx->queueEmpty = (ctx->queueHead == ctx->queueTail);
|
90
90
|
/* Unlock the mutex, signal a pusher, and run the job */
|
91
91
|
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
92
92
|
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
@@ -105,6 +105,7 @@ static void* POOL_thread(void* opaque) {
|
|
105
105
|
assert(0); /* Unreachable */
|
106
106
|
}
|
107
107
|
|
108
|
+
/* ZSTD_createThreadPool() : public access point */
|
108
109
|
POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
|
109
110
|
return POOL_create (numThreads, 0);
|
110
111
|
}
|
@@ -114,7 +115,8 @@ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
|
114
115
|
}
|
115
116
|
|
116
117
|
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
117
|
-
ZSTD_customMem customMem)
|
118
|
+
ZSTD_customMem customMem)
|
119
|
+
{
|
118
120
|
POOL_ctx* ctx;
|
119
121
|
/* Check parameters */
|
120
122
|
if (!numThreads) { return NULL; }
|
@@ -192,7 +194,7 @@ void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
|
|
192
194
|
POOL_free (pool);
|
193
195
|
}
|
194
196
|
|
195
|
-
size_t POOL_sizeof(POOL_ctx
|
197
|
+
size_t POOL_sizeof(const POOL_ctx* ctx) {
|
196
198
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
197
199
|
return sizeof(*ctx)
|
198
200
|
+ ctx->queueSize * sizeof(POOL_job)
|
@@ -257,7 +259,8 @@ static int isQueueFull(POOL_ctx const* ctx) {
|
|
257
259
|
}
|
258
260
|
|
259
261
|
|
260
|
-
static void
|
262
|
+
static void
|
263
|
+
POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
|
261
264
|
{
|
262
265
|
POOL_job const job = {function, opaque};
|
263
266
|
assert(ctx != NULL);
|
@@ -313,7 +316,9 @@ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
|
313
316
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
314
317
|
}
|
315
318
|
|
316
|
-
POOL_ctx*
|
319
|
+
POOL_ctx*
|
320
|
+
POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem)
|
321
|
+
{
|
317
322
|
(void)numThreads;
|
318
323
|
(void)queueSize;
|
319
324
|
(void)customMem;
|
@@ -341,7 +346,7 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {
|
|
341
346
|
return 1;
|
342
347
|
}
|
343
348
|
|
344
|
-
size_t POOL_sizeof(POOL_ctx* ctx) {
|
349
|
+
size_t POOL_sizeof(const POOL_ctx* ctx) {
|
345
350
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
346
351
|
assert(ctx == &g_poolCtx);
|
347
352
|
return sizeof(*ctx);
|
@@ -53,7 +53,7 @@ int POOL_resize(POOL_ctx* ctx, size_t numThreads);
|
|
53
53
|
* @return threadpool memory usage
|
54
54
|
* note : compatible with NULL (returns 0 in this case)
|
55
55
|
*/
|
56
|
-
size_t POOL_sizeof(POOL_ctx* ctx);
|
56
|
+
size_t POOL_sizeof(const POOL_ctx* ctx);
|
57
57
|
|
58
58
|
/*! POOL_function :
|
59
59
|
* The function type that can be added to a thread pool.
|
@@ -70,7 +70,7 @@ void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
|
|
70
70
|
|
71
71
|
|
72
72
|
/*! POOL_tryAdd() :
|
73
|
-
* Add the job `function(opaque)` to thread pool _if_ a
|
73
|
+
* Add the job `function(opaque)` to thread pool _if_ a queue slot is available.
|
74
74
|
* Returns immediately even if not (does not block).
|
75
75
|
* @return : 1 if successful, 0 if not.
|
76
76
|
*/
|
@@ -0,0 +1,137 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
#ifndef ZSTD_PORTABILITY_MACROS_H
|
12
|
+
#define ZSTD_PORTABILITY_MACROS_H
|
13
|
+
|
14
|
+
/**
|
15
|
+
* This header file contains macro defintions to support portability.
|
16
|
+
* This header is shared between C and ASM code, so it MUST only
|
17
|
+
* contain macro definitions. It MUST not contain any C code.
|
18
|
+
*
|
19
|
+
* This header ONLY defines macros to detect platforms/feature support.
|
20
|
+
*
|
21
|
+
*/
|
22
|
+
|
23
|
+
|
24
|
+
/* compat. with non-clang compilers */
|
25
|
+
#ifndef __has_attribute
|
26
|
+
#define __has_attribute(x) 0
|
27
|
+
#endif
|
28
|
+
|
29
|
+
/* compat. with non-clang compilers */
|
30
|
+
#ifndef __has_builtin
|
31
|
+
# define __has_builtin(x) 0
|
32
|
+
#endif
|
33
|
+
|
34
|
+
/* compat. with non-clang compilers */
|
35
|
+
#ifndef __has_feature
|
36
|
+
# define __has_feature(x) 0
|
37
|
+
#endif
|
38
|
+
|
39
|
+
/* detects whether we are being compiled under msan */
|
40
|
+
#ifndef ZSTD_MEMORY_SANITIZER
|
41
|
+
# if __has_feature(memory_sanitizer)
|
42
|
+
# define ZSTD_MEMORY_SANITIZER 1
|
43
|
+
# else
|
44
|
+
# define ZSTD_MEMORY_SANITIZER 0
|
45
|
+
# endif
|
46
|
+
#endif
|
47
|
+
|
48
|
+
/* detects whether we are being compiled under asan */
|
49
|
+
#ifndef ZSTD_ADDRESS_SANITIZER
|
50
|
+
# if __has_feature(address_sanitizer)
|
51
|
+
# define ZSTD_ADDRESS_SANITIZER 1
|
52
|
+
# elif defined(__SANITIZE_ADDRESS__)
|
53
|
+
# define ZSTD_ADDRESS_SANITIZER 1
|
54
|
+
# else
|
55
|
+
# define ZSTD_ADDRESS_SANITIZER 0
|
56
|
+
# endif
|
57
|
+
#endif
|
58
|
+
|
59
|
+
/* detects whether we are being compiled under dfsan */
|
60
|
+
#ifndef ZSTD_DATAFLOW_SANITIZER
|
61
|
+
# if __has_feature(dataflow_sanitizer)
|
62
|
+
# define ZSTD_DATAFLOW_SANITIZER 1
|
63
|
+
# else
|
64
|
+
# define ZSTD_DATAFLOW_SANITIZER 0
|
65
|
+
# endif
|
66
|
+
#endif
|
67
|
+
|
68
|
+
/* Mark the internal assembly functions as hidden */
|
69
|
+
#ifdef __ELF__
|
70
|
+
# define ZSTD_HIDE_ASM_FUNCTION(func) .hidden func
|
71
|
+
#else
|
72
|
+
# define ZSTD_HIDE_ASM_FUNCTION(func)
|
73
|
+
#endif
|
74
|
+
|
75
|
+
/* Enable runtime BMI2 dispatch based on the CPU.
|
76
|
+
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
|
77
|
+
*/
|
78
|
+
#ifndef DYNAMIC_BMI2
|
79
|
+
#if ((defined(__clang__) && __has_attribute(__target__)) \
|
80
|
+
|| (defined(__GNUC__) \
|
81
|
+
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
|
82
|
+
&& (defined(__x86_64__) || defined(_M_X64)) \
|
83
|
+
&& !defined(__BMI2__)
|
84
|
+
# define DYNAMIC_BMI2 1
|
85
|
+
#else
|
86
|
+
# define DYNAMIC_BMI2 0
|
87
|
+
#endif
|
88
|
+
#endif
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Only enable assembly for GNUC comptabile compilers,
|
92
|
+
* because other platforms may not support GAS assembly syntax.
|
93
|
+
*
|
94
|
+
* Only enable assembly for Linux / MacOS, other platforms may
|
95
|
+
* work, but they haven't been tested. This could likely be
|
96
|
+
* extended to BSD systems.
|
97
|
+
*
|
98
|
+
* Disable assembly when MSAN is enabled, because MSAN requires
|
99
|
+
* 100% of code to be instrumented to work.
|
100
|
+
*/
|
101
|
+
#if defined(__GNUC__)
|
102
|
+
# if defined(__linux__) || defined(__linux) || defined(__APPLE__)
|
103
|
+
# if ZSTD_MEMORY_SANITIZER
|
104
|
+
# define ZSTD_ASM_SUPPORTED 0
|
105
|
+
# elif ZSTD_DATAFLOW_SANITIZER
|
106
|
+
# define ZSTD_ASM_SUPPORTED 0
|
107
|
+
# else
|
108
|
+
# define ZSTD_ASM_SUPPORTED 1
|
109
|
+
# endif
|
110
|
+
# else
|
111
|
+
# define ZSTD_ASM_SUPPORTED 0
|
112
|
+
# endif
|
113
|
+
#else
|
114
|
+
# define ZSTD_ASM_SUPPORTED 0
|
115
|
+
#endif
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Determines whether we should enable assembly for x86-64
|
119
|
+
* with BMI2.
|
120
|
+
*
|
121
|
+
* Enable if all of the following conditions hold:
|
122
|
+
* - ASM hasn't been explicitly disabled by defining ZSTD_DISABLE_ASM
|
123
|
+
* - Assembly is supported
|
124
|
+
* - We are compiling for x86-64 and either:
|
125
|
+
* - DYNAMIC_BMI2 is enabled
|
126
|
+
* - BMI2 is supported at compile time
|
127
|
+
*/
|
128
|
+
#if !defined(ZSTD_DISABLE_ASM) && \
|
129
|
+
ZSTD_ASM_SUPPORTED && \
|
130
|
+
defined(__x86_64__) && \
|
131
|
+
(DYNAMIC_BMI2 || defined(__BMI2__))
|
132
|
+
# define ZSTD_ENABLE_ASM_X86_64_BMI2 1
|
133
|
+
#else
|
134
|
+
# define ZSTD_ENABLE_ASM_X86_64_BMI2 0
|
135
|
+
#endif
|
136
|
+
|
137
|
+
#endif /* ZSTD_PORTABILITY_MACROS_H */
|