zstdlib 0.3.0-x64-mingw32 → 0.8.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +30 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/ext/zstdlib/extconf.rb +3 -3
- data/ext/zstdlib/ruby/zlib-2.7/zstdlib.c +4895 -0
- data/ext/zstdlib/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/bitstream.h +59 -51
- data/ext/zstdlib/zstd-1.5.0/lib/common/compiler.h +289 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/cpu.h +1 -3
- data/ext/zstdlib/zstd-1.5.0/lib/common/debug.c +24 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/debug.h +22 -49
- data/ext/zstdlib/zstd-1.5.0/lib/common/entropy_common.c +362 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.c +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.h +8 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse.h +50 -42
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse_decompress.c +149 -55
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/huf.h +43 -39
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/mem.h +69 -25
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.c +30 -20
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.c +51 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.h +36 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.c +40 -92
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.h +12 -32
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_internal.h +490 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_trace.h +154 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/fse_compress.c +47 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.c +41 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.h +13 -33
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/huf_compress.c +332 -193
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress.c +6393 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_internal.h +522 -86
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.c +25 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.c +50 -24
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.h +11 -4
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.c +572 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_cwksp.h +662 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.c +43 -41
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.c +85 -80
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.h +2 -2
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.c +2184 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.h +125 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.c +333 -208
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.h +15 -3
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.c +228 -129
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstdmt_compress.c +151 -440
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstdmt_compress.h +110 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/huf_decompress.c +395 -276
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.c +20 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress.c +628 -231
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.c +606 -380
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.h +8 -5
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_internal.h +39 -9
- data/ext/zstdlib/zstd-1.5.0/lib/zdict.h +452 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/zstd.h +740 -153
- data/ext/zstdlib/{zstd-1.4.2/lib/common → zstd-1.5.0/lib}/zstd_errors.h +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzclose.c +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzguts.h +0 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzlib.c +9 -9
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzread.c +16 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzwrite.c +8 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.c +131 -45
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/2.7/zstdlib.so +0 -0
- metadata +76 -67
- data/ext/zstdlib/zstd-1.4.2/lib/common/compiler.h +0 -147
- data/ext/zstdlib/zstd-1.4.2/lib/common/debug.c +0 -44
- data/ext/zstdlib/zstd-1.4.2/lib/common/entropy_common.c +0 -236
- data/ext/zstdlib/zstd-1.4.2/lib/common/zstd_internal.h +0 -371
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_compress.c +0 -3904
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.c +0 -1111
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstdmt_compress.h +0 -192
@@ -1,35 +1,15 @@
|
|
1
1
|
/* ******************************************************************
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
notice, this list of conditions and the following disclaimer.
|
14
|
-
* Redistributions in binary form must reproduce the above
|
15
|
-
copyright notice, this list of conditions and the following disclaimer
|
16
|
-
in the documentation and/or other materials provided with the
|
17
|
-
distribution.
|
18
|
-
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
-
|
31
|
-
You can contact the author at :
|
32
|
-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
2
|
+
* huff0 huffman codec,
|
3
|
+
* part of Finite State Entropy library
|
4
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
5
|
+
*
|
6
|
+
* You can contact the author at :
|
7
|
+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
8
|
+
*
|
9
|
+
* This source code is licensed under both the BSD-style license (found in the
|
10
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
11
|
+
* in the COPYING file in the root directory of this source tree).
|
12
|
+
* You may select, at your option, one of the above-listed licenses.
|
33
13
|
****************************************************************** */
|
34
14
|
|
35
15
|
#if defined (__cplusplus)
|
@@ -40,7 +20,7 @@ extern "C" {
|
|
40
20
|
#define HUF_H_298734234
|
41
21
|
|
42
22
|
/* *** Dependencies *** */
|
43
|
-
#include
|
23
|
+
#include "zstd_deps.h" /* size_t */
|
44
24
|
|
45
25
|
|
46
26
|
/* *** library symbols visibility *** */
|
@@ -110,7 +90,7 @@ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
|
|
110
90
|
/** HUF_compress4X_wksp() :
|
111
91
|
* Same as HUF_compress2(), but uses externally allocated `workSpace`.
|
112
92
|
* `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */
|
113
|
-
#define HUF_WORKSPACE_SIZE (6 << 10)
|
93
|
+
#define HUF_WORKSPACE_SIZE ((6 << 10) + 256)
|
114
94
|
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
|
115
95
|
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
116
96
|
const void* src, size_t srcSize,
|
@@ -131,6 +111,8 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|
131
111
|
|
132
112
|
/* *** Dependencies *** */
|
133
113
|
#include "mem.h" /* U32 */
|
114
|
+
#define FSE_STATIC_LINKING_ONLY
|
115
|
+
#include "fse.h"
|
134
116
|
|
135
117
|
|
136
118
|
/* *** Constants *** */
|
@@ -153,12 +135,16 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|
153
135
|
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
154
136
|
|
155
137
|
/* static allocation of HUF's Compression Table */
|
138
|
+
/* this is a private definition, just exposed for allocation and strict aliasing purpose. never EVER access its members directly */
|
139
|
+
struct HUF_CElt_s {
|
140
|
+
U16 val;
|
141
|
+
BYTE nbBits;
|
142
|
+
}; /* typedef'd to HUF_CElt */
|
143
|
+
typedef struct HUF_CElt_s HUF_CElt; /* consider it an incomplete type */
|
156
144
|
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
157
145
|
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
158
146
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
159
|
-
|
160
|
-
void* name##hv = &(name##hb); \
|
161
|
-
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
147
|
+
HUF_CElt name[HUF_CTABLE_SIZE_U32(maxSymbolValue)] /* no final ; */
|
162
148
|
|
163
149
|
/* static allocation of HUF's DTable */
|
164
150
|
typedef U32 HUF_DTable;
|
@@ -204,10 +190,12 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|
204
190
|
* or to save and regenerate 'CTable' using external methods.
|
205
191
|
*/
|
206
192
|
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
|
207
|
-
typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
|
208
193
|
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
|
209
194
|
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
195
|
+
size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog, void* workspace, size_t workspaceSize);
|
210
196
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
197
|
+
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
198
|
+
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
211
199
|
|
212
200
|
typedef enum {
|
213
201
|
HUF_repeat_none, /**< Cannot use the previous table */
|
@@ -244,9 +232,22 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
|
|
244
232
|
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
245
233
|
const void* src, size_t srcSize);
|
246
234
|
|
235
|
+
/*! HUF_readStats_wksp() :
|
236
|
+
* Same as HUF_readStats() but takes an external workspace which must be
|
237
|
+
* 4-byte aligned and its size must be >= HUF_READ_STATS_WORKSPACE_SIZE.
|
238
|
+
* If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
|
239
|
+
*/
|
240
|
+
#define HUF_READ_STATS_WORKSPACE_SIZE_U32 FSE_DECOMPRESS_WKSP_SIZE_U32(6, HUF_TABLELOG_MAX-1)
|
241
|
+
#define HUF_READ_STATS_WORKSPACE_SIZE (HUF_READ_STATS_WORKSPACE_SIZE_U32 * sizeof(unsigned))
|
242
|
+
size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
|
243
|
+
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
244
|
+
const void* src, size_t srcSize,
|
245
|
+
void* workspace, size_t wkspSize,
|
246
|
+
int bmi2);
|
247
|
+
|
247
248
|
/** HUF_readCTable() :
|
248
249
|
* Loading a CTable saved with HUF_writeCTable() */
|
249
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
250
|
+
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
|
250
251
|
|
251
252
|
/** HUF_getNbBits() :
|
252
253
|
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
@@ -278,7 +279,7 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
|
|
278
279
|
* a required workspace size greater than that specified in the following
|
279
280
|
* macro.
|
280
281
|
*/
|
281
|
-
#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
|
282
|
+
#define HUF_DECOMPRESS_WORKSPACE_SIZE ((2 << 10) + (1 << 9))
|
282
283
|
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
|
283
284
|
|
284
285
|
#ifndef HUF_FORCE_DECOMPRESS_X2
|
@@ -350,6 +351,9 @@ size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstS
|
|
350
351
|
#endif
|
351
352
|
size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
|
352
353
|
size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2);
|
354
|
+
#ifndef HUF_FORCE_DECOMPRESS_X2
|
355
|
+
size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
|
356
|
+
#endif
|
353
357
|
|
354
358
|
#endif /* HUF_STATIC_LINKING_ONLY */
|
355
359
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -18,8 +18,10 @@ extern "C" {
|
|
18
18
|
/*-****************************************
|
19
19
|
* Dependencies
|
20
20
|
******************************************/
|
21
|
-
#include <stddef.h>
|
22
|
-
#include
|
21
|
+
#include <stddef.h> /* size_t, ptrdiff_t */
|
22
|
+
#include "compiler.h" /* __has_builtin */
|
23
|
+
#include "debug.h" /* DEBUG_STATIC_ASSERT */
|
24
|
+
#include "zstd_deps.h" /* ZSTD_memcpy */
|
23
25
|
|
24
26
|
|
25
27
|
/*-****************************************
|
@@ -39,20 +41,15 @@ extern "C" {
|
|
39
41
|
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
40
42
|
#endif
|
41
43
|
|
42
|
-
#ifndef __has_builtin
|
43
|
-
# define __has_builtin(x) 0 /* compat. with non-clang compilers */
|
44
|
-
#endif
|
45
|
-
|
46
|
-
/* code only tested on 32 and 64 bits systems */
|
47
|
-
#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
|
48
|
-
MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
49
|
-
|
50
|
-
|
51
44
|
/*-**************************************************************
|
52
45
|
* Basic Types
|
53
46
|
*****************************************************************/
|
54
47
|
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
55
|
-
#
|
48
|
+
# if defined(_AIX)
|
49
|
+
# include <inttypes.h>
|
50
|
+
# else
|
51
|
+
# include <stdint.h> /* intptr_t */
|
52
|
+
# endif
|
56
53
|
typedef uint8_t BYTE;
|
57
54
|
typedef uint16_t U16;
|
58
55
|
typedef int16_t S16;
|
@@ -84,7 +81,53 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
84
81
|
|
85
82
|
|
86
83
|
/*-**************************************************************
|
87
|
-
* Memory I/O
|
84
|
+
* Memory I/O API
|
85
|
+
*****************************************************************/
|
86
|
+
/*=== Static platform detection ===*/
|
87
|
+
MEM_STATIC unsigned MEM_32bits(void);
|
88
|
+
MEM_STATIC unsigned MEM_64bits(void);
|
89
|
+
MEM_STATIC unsigned MEM_isLittleEndian(void);
|
90
|
+
|
91
|
+
/*=== Native unaligned read/write ===*/
|
92
|
+
MEM_STATIC U16 MEM_read16(const void* memPtr);
|
93
|
+
MEM_STATIC U32 MEM_read32(const void* memPtr);
|
94
|
+
MEM_STATIC U64 MEM_read64(const void* memPtr);
|
95
|
+
MEM_STATIC size_t MEM_readST(const void* memPtr);
|
96
|
+
|
97
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value);
|
98
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value);
|
99
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value);
|
100
|
+
|
101
|
+
/*=== Little endian unaligned read/write ===*/
|
102
|
+
MEM_STATIC U16 MEM_readLE16(const void* memPtr);
|
103
|
+
MEM_STATIC U32 MEM_readLE24(const void* memPtr);
|
104
|
+
MEM_STATIC U32 MEM_readLE32(const void* memPtr);
|
105
|
+
MEM_STATIC U64 MEM_readLE64(const void* memPtr);
|
106
|
+
MEM_STATIC size_t MEM_readLEST(const void* memPtr);
|
107
|
+
|
108
|
+
MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val);
|
109
|
+
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val);
|
110
|
+
MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32);
|
111
|
+
MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64);
|
112
|
+
MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val);
|
113
|
+
|
114
|
+
/*=== Big endian unaligned read/write ===*/
|
115
|
+
MEM_STATIC U32 MEM_readBE32(const void* memPtr);
|
116
|
+
MEM_STATIC U64 MEM_readBE64(const void* memPtr);
|
117
|
+
MEM_STATIC size_t MEM_readBEST(const void* memPtr);
|
118
|
+
|
119
|
+
MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32);
|
120
|
+
MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64);
|
121
|
+
MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val);
|
122
|
+
|
123
|
+
/*=== Byteswap ===*/
|
124
|
+
MEM_STATIC U32 MEM_swap32(U32 in);
|
125
|
+
MEM_STATIC U64 MEM_swap64(U64 in);
|
126
|
+
MEM_STATIC size_t MEM_swapST(size_t in);
|
127
|
+
|
128
|
+
|
129
|
+
/*-**************************************************************
|
130
|
+
* Memory I/O Implementation
|
88
131
|
*****************************************************************/
|
89
132
|
/* MEM_FORCE_MEMORY_ACCESS :
|
90
133
|
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
@@ -100,9 +143,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
100
143
|
* Prefer these methods in priority order (0 > 1 > 2)
|
101
144
|
*/
|
102
145
|
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
103
|
-
# if defined(
|
104
|
-
# define MEM_FORCE_MEMORY_ACCESS 2
|
105
|
-
# elif defined(__INTEL_COMPILER) || defined(__GNUC__)
|
146
|
+
# if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
|
106
147
|
# define MEM_FORCE_MEMORY_ACCESS 1
|
107
148
|
# endif
|
108
149
|
#endif
|
@@ -163,37 +204,37 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v =
|
|
163
204
|
|
164
205
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
165
206
|
{
|
166
|
-
U16 val;
|
207
|
+
U16 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
167
208
|
}
|
168
209
|
|
169
210
|
MEM_STATIC U32 MEM_read32(const void* memPtr)
|
170
211
|
{
|
171
|
-
U32 val;
|
212
|
+
U32 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
172
213
|
}
|
173
214
|
|
174
215
|
MEM_STATIC U64 MEM_read64(const void* memPtr)
|
175
216
|
{
|
176
|
-
U64 val;
|
217
|
+
U64 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
177
218
|
}
|
178
219
|
|
179
220
|
MEM_STATIC size_t MEM_readST(const void* memPtr)
|
180
221
|
{
|
181
|
-
size_t val;
|
222
|
+
size_t val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
182
223
|
}
|
183
224
|
|
184
225
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
185
226
|
{
|
186
|
-
|
227
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
187
228
|
}
|
188
229
|
|
189
230
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value)
|
190
231
|
{
|
191
|
-
|
232
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
192
233
|
}
|
193
234
|
|
194
235
|
MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
195
236
|
{
|
196
|
-
|
237
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
197
238
|
}
|
198
239
|
|
199
240
|
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
@@ -265,7 +306,7 @@ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
|
|
265
306
|
|
266
307
|
MEM_STATIC U32 MEM_readLE24(const void* memPtr)
|
267
308
|
{
|
268
|
-
return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
|
309
|
+
return (U32)MEM_readLE16(memPtr) + ((U32)(((const BYTE*)memPtr)[2]) << 16);
|
269
310
|
}
|
270
311
|
|
271
312
|
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
|
@@ -372,6 +413,9 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
|
|
372
413
|
MEM_writeBE64(memPtr, (U64)val);
|
373
414
|
}
|
374
415
|
|
416
|
+
/* code only tested on 32 and 64 bits systems */
|
417
|
+
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
418
|
+
|
375
419
|
|
376
420
|
#if defined (__cplusplus)
|
377
421
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -10,9 +10,9 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
/* ====== Dependencies ======= */
|
13
|
-
#include
|
13
|
+
#include "zstd_deps.h" /* size_t */
|
14
14
|
#include "debug.h" /* assert */
|
15
|
-
#include "zstd_internal.h" /*
|
15
|
+
#include "zstd_internal.h" /* ZSTD_customMalloc, ZSTD_customFree */
|
16
16
|
#include "pool.h"
|
17
17
|
|
18
18
|
/* ====== Compiler specifics ====== */
|
@@ -105,6 +105,10 @@ static void* POOL_thread(void* opaque) {
|
|
105
105
|
assert(0); /* Unreachable */
|
106
106
|
}
|
107
107
|
|
108
|
+
POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
|
109
|
+
return POOL_create (numThreads, 0);
|
110
|
+
}
|
111
|
+
|
108
112
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
109
113
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
110
114
|
}
|
@@ -115,24 +119,28 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
|
115
119
|
/* Check parameters */
|
116
120
|
if (!numThreads) { return NULL; }
|
117
121
|
/* Allocate the context and zero initialize */
|
118
|
-
ctx = (POOL_ctx*)
|
122
|
+
ctx = (POOL_ctx*)ZSTD_customCalloc(sizeof(POOL_ctx), customMem);
|
119
123
|
if (!ctx) { return NULL; }
|
120
124
|
/* Initialize the job queue.
|
121
125
|
* It needs one extra space since one space is wasted to differentiate
|
122
126
|
* empty and full queues.
|
123
127
|
*/
|
124
128
|
ctx->queueSize = queueSize + 1;
|
125
|
-
ctx->queue = (POOL_job*)
|
129
|
+
ctx->queue = (POOL_job*)ZSTD_customMalloc(ctx->queueSize * sizeof(POOL_job), customMem);
|
126
130
|
ctx->queueHead = 0;
|
127
131
|
ctx->queueTail = 0;
|
128
132
|
ctx->numThreadsBusy = 0;
|
129
133
|
ctx->queueEmpty = 1;
|
130
|
-
|
131
|
-
|
132
|
-
|
134
|
+
{
|
135
|
+
int error = 0;
|
136
|
+
error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
|
137
|
+
error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
|
138
|
+
error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
|
139
|
+
if (error) { POOL_free(ctx); return NULL; }
|
140
|
+
}
|
133
141
|
ctx->shutdown = 0;
|
134
142
|
/* Allocate space for the thread handles */
|
135
|
-
ctx->threads = (ZSTD_pthread_t*)
|
143
|
+
ctx->threads = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
|
136
144
|
ctx->threadCapacity = 0;
|
137
145
|
ctx->customMem = customMem;
|
138
146
|
/* Check for errors */
|
@@ -175,12 +183,14 @@ void POOL_free(POOL_ctx *ctx) {
|
|
175
183
|
ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
|
176
184
|
ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
|
177
185
|
ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
|
178
|
-
|
179
|
-
|
180
|
-
|
186
|
+
ZSTD_customFree(ctx->queue, ctx->customMem);
|
187
|
+
ZSTD_customFree(ctx->threads, ctx->customMem);
|
188
|
+
ZSTD_customFree(ctx, ctx->customMem);
|
181
189
|
}
|
182
190
|
|
183
|
-
|
191
|
+
void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
|
192
|
+
POOL_free (pool);
|
193
|
+
}
|
184
194
|
|
185
195
|
size_t POOL_sizeof(POOL_ctx *ctx) {
|
186
196
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
@@ -199,11 +209,11 @@ static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
|
|
199
209
|
return 0;
|
200
210
|
}
|
201
211
|
/* numThreads > threadCapacity */
|
202
|
-
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)
|
212
|
+
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
|
203
213
|
if (!threadPool) return 1;
|
204
214
|
/* replace existing thread pool */
|
205
|
-
|
206
|
-
|
215
|
+
ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
|
216
|
+
ZSTD_customFree(ctx->threads, ctx->customMem);
|
207
217
|
ctx->threads = threadPool;
|
208
218
|
/* Initialize additional threads */
|
209
219
|
{ size_t threadId;
|
@@ -297,7 +307,7 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque)
|
|
297
307
|
struct POOL_ctx_s {
|
298
308
|
int dummy;
|
299
309
|
};
|
300
|
-
static POOL_ctx
|
310
|
+
static POOL_ctx g_poolCtx;
|
301
311
|
|
302
312
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
303
313
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
@@ -307,11 +317,11 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customM
|
|
307
317
|
(void)numThreads;
|
308
318
|
(void)queueSize;
|
309
319
|
(void)customMem;
|
310
|
-
return &
|
320
|
+
return &g_poolCtx;
|
311
321
|
}
|
312
322
|
|
313
323
|
void POOL_free(POOL_ctx* ctx) {
|
314
|
-
assert(!ctx || ctx == &
|
324
|
+
assert(!ctx || ctx == &g_poolCtx);
|
315
325
|
(void)ctx;
|
316
326
|
}
|
317
327
|
|
@@ -333,7 +343,7 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {
|
|
333
343
|
|
334
344
|
size_t POOL_sizeof(POOL_ctx* ctx) {
|
335
345
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
336
|
-
assert(ctx == &
|
346
|
+
assert(ctx == &g_poolCtx);
|
337
347
|
return sizeof(*ctx);
|
338
348
|
}
|
339
349
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -16,9 +16,9 @@ extern "C" {
|
|
16
16
|
#endif
|
17
17
|
|
18
18
|
|
19
|
-
#include
|
19
|
+
#include "zstd_deps.h"
|
20
20
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
|
21
|
-
#include "zstd.h"
|
21
|
+
#include "../zstd.h"
|
22
22
|
|
23
23
|
typedef struct POOL_ctx_s POOL_ctx;
|
24
24
|
|