zstd-ruby 1.4.0.0 → 1.4.9.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 +35 -0
- data/README.md +2 -2
- data/ext/zstdruby/libzstd/Makefile +274 -107
- data/ext/zstdruby/libzstd/README.md +75 -16
- data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
- data/ext/zstdruby/libzstd/common/compiler.h +154 -5
- data/ext/zstdruby/libzstd/common/cpu.h +1 -3
- data/ext/zstdruby/libzstd/common/debug.c +11 -31
- data/ext/zstdruby/libzstd/common/debug.h +22 -49
- data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
- data/ext/zstdruby/libzstd/common/error_private.c +3 -1
- data/ext/zstdruby/libzstd/common/error_private.h +7 -3
- data/ext/zstdruby/libzstd/common/fse.h +50 -42
- data/ext/zstdruby/libzstd/common/fse_decompress.c +134 -50
- data/ext/zstdruby/libzstd/common/huf.h +41 -38
- data/ext/zstdruby/libzstd/common/mem.h +68 -22
- data/ext/zstdruby/libzstd/common/pool.c +30 -20
- data/ext/zstdruby/libzstd/common/pool.h +3 -3
- data/ext/zstdruby/libzstd/common/threading.c +51 -4
- data/ext/zstdruby/libzstd/common/threading.h +36 -4
- data/ext/zstdruby/libzstd/common/xxhash.c +39 -89
- data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
- data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
- data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
- data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +231 -72
- data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
- data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +47 -63
- data/ext/zstdruby/libzstd/compress/hist.c +41 -63
- data/ext/zstdruby/libzstd/compress/hist.h +13 -33
- data/ext/zstdruby/libzstd/compress/huf_compress.c +288 -172
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +2504 -1626
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +446 -85
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +433 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +849 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +561 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +82 -60
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +106 -80
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +411 -105
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +296 -207
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +14 -3
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +260 -148
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +153 -440
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +29 -110
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +356 -238
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +641 -238
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +600 -371
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +40 -9
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +197 -78
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +52 -7
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +84 -66
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +58 -36
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +60 -31
- data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
- data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +115 -111
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +28 -14
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +28 -14
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +36 -19
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +122 -107
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +29 -23
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +34 -24
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
- data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
- data/ext/zstdruby/libzstd/zstd.h +655 -118
- data/lib/zstd-ruby/version.rb +1 -1
- data/zstd-ruby.gemspec +1 -1
- metadata +20 -10
- data/.travis.yml +0 -14
@@ -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) 2013-2021, 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,11 @@ 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);
|
210
195
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
196
|
+
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
197
|
+
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
211
198
|
|
212
199
|
typedef enum {
|
213
200
|
HUF_repeat_none, /**< Cannot use the previous table */
|
@@ -244,9 +231,22 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
|
|
244
231
|
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
245
232
|
const void* src, size_t srcSize);
|
246
233
|
|
234
|
+
/*! HUF_readStats_wksp() :
|
235
|
+
* Same as HUF_readStats() but takes an external workspace which must be
|
236
|
+
* 4-byte aligned and its size must be >= HUF_READ_STATS_WORKSPACE_SIZE.
|
237
|
+
* If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
|
238
|
+
*/
|
239
|
+
#define HUF_READ_STATS_WORKSPACE_SIZE_U32 FSE_DECOMPRESS_WKSP_SIZE_U32(6, HUF_TABLELOG_MAX-1)
|
240
|
+
#define HUF_READ_STATS_WORKSPACE_SIZE (HUF_READ_STATS_WORKSPACE_SIZE_U32 * sizeof(unsigned))
|
241
|
+
size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
|
242
|
+
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
243
|
+
const void* src, size_t srcSize,
|
244
|
+
void* workspace, size_t wkspSize,
|
245
|
+
int bmi2);
|
246
|
+
|
247
247
|
/** HUF_readCTable() :
|
248
248
|
* Loading a CTable saved with HUF_writeCTable() */
|
249
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
249
|
+
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
|
250
250
|
|
251
251
|
/** HUF_getNbBits() :
|
252
252
|
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
@@ -350,6 +350,9 @@ size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstS
|
|
350
350
|
#endif
|
351
351
|
size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
|
352
352
|
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);
|
353
|
+
#ifndef HUF_FORCE_DECOMPRESS_X2
|
354
|
+
size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
|
355
|
+
#endif
|
353
356
|
|
354
357
|
#endif /* HUF_STATIC_LINKING_ONLY */
|
355
358
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, 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.
|
@@ -102,7 +145,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
102
145
|
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
103
146
|
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
104
147
|
# define MEM_FORCE_MEMORY_ACCESS 2
|
105
|
-
# elif defined(__INTEL_COMPILER) || defined(__GNUC__)
|
148
|
+
# elif defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
|
106
149
|
# define MEM_FORCE_MEMORY_ACCESS 1
|
107
150
|
# endif
|
108
151
|
#endif
|
@@ -163,37 +206,37 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v =
|
|
163
206
|
|
164
207
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
165
208
|
{
|
166
|
-
U16 val;
|
209
|
+
U16 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
167
210
|
}
|
168
211
|
|
169
212
|
MEM_STATIC U32 MEM_read32(const void* memPtr)
|
170
213
|
{
|
171
|
-
U32 val;
|
214
|
+
U32 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
172
215
|
}
|
173
216
|
|
174
217
|
MEM_STATIC U64 MEM_read64(const void* memPtr)
|
175
218
|
{
|
176
|
-
U64 val;
|
219
|
+
U64 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
177
220
|
}
|
178
221
|
|
179
222
|
MEM_STATIC size_t MEM_readST(const void* memPtr)
|
180
223
|
{
|
181
|
-
size_t val;
|
224
|
+
size_t val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
182
225
|
}
|
183
226
|
|
184
227
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
185
228
|
{
|
186
|
-
|
229
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
187
230
|
}
|
188
231
|
|
189
232
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value)
|
190
233
|
{
|
191
|
-
|
234
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
192
235
|
}
|
193
236
|
|
194
237
|
MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
195
238
|
{
|
196
|
-
|
239
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
197
240
|
}
|
198
241
|
|
199
242
|
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
@@ -372,6 +415,9 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
|
|
372
415
|
MEM_writeBE64(memPtr, (U64)val);
|
373
416
|
}
|
374
417
|
|
418
|
+
/* code only tested on 32 and 64 bits systems */
|
419
|
+
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
420
|
+
|
375
421
|
|
376
422
|
#if defined (__cplusplus)
|
377
423
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, 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) 2016-
|
2
|
+
* Copyright (c) 2016-2021, 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
|
|
@@ -2,18 +2,21 @@
|
|
2
2
|
* Copyright (c) 2016 Tino Reichardt
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
|
+
* You can contact the author at:
|
6
|
+
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
7
|
+
*
|
5
8
|
* This source code is licensed under both the BSD-style license (found in the
|
6
9
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
10
|
* in the COPYING file in the root directory of this source tree).
|
8
|
-
*
|
9
|
-
* You can contact the author at:
|
10
|
-
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
11
|
+
* You may select, at your option, one of the above-listed licenses.
|
11
12
|
*/
|
12
13
|
|
13
14
|
/**
|
14
15
|
* This file will hold wrapper for systems, which do not support pthreads
|
15
16
|
*/
|
16
17
|
|
18
|
+
#include "threading.h"
|
19
|
+
|
17
20
|
/* create fake symbol to avoid empty translation unit warning */
|
18
21
|
int g_ZSTD_threading_useless_symbol;
|
19
22
|
|
@@ -28,7 +31,6 @@ int g_ZSTD_threading_useless_symbol;
|
|
28
31
|
/* === Dependencies === */
|
29
32
|
#include <process.h>
|
30
33
|
#include <errno.h>
|
31
|
-
#include "threading.h"
|
32
34
|
|
33
35
|
|
34
36
|
/* === Implementation === */
|
@@ -73,3 +75,48 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
|
|
73
75
|
}
|
74
76
|
|
75
77
|
#endif /* ZSTD_MULTITHREAD */
|
78
|
+
|
79
|
+
#if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
|
80
|
+
|
81
|
+
#define ZSTD_DEPS_NEED_MALLOC
|
82
|
+
#include "zstd_deps.h"
|
83
|
+
|
84
|
+
int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
|
85
|
+
{
|
86
|
+
*mutex = (pthread_mutex_t*)ZSTD_malloc(sizeof(pthread_mutex_t));
|
87
|
+
if (!*mutex)
|
88
|
+
return 1;
|
89
|
+
return pthread_mutex_init(*mutex, attr);
|
90
|
+
}
|
91
|
+
|
92
|
+
int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
|
93
|
+
{
|
94
|
+
if (!*mutex)
|
95
|
+
return 0;
|
96
|
+
{
|
97
|
+
int const ret = pthread_mutex_destroy(*mutex);
|
98
|
+
ZSTD_free(*mutex);
|
99
|
+
return ret;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
|
104
|
+
{
|
105
|
+
*cond = (pthread_cond_t*)ZSTD_malloc(sizeof(pthread_cond_t));
|
106
|
+
if (!*cond)
|
107
|
+
return 1;
|
108
|
+
return pthread_cond_init(*cond, attr);
|
109
|
+
}
|
110
|
+
|
111
|
+
int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
|
112
|
+
{
|
113
|
+
if (!*cond)
|
114
|
+
return 0;
|
115
|
+
{
|
116
|
+
int const ret = pthread_cond_destroy(*cond);
|
117
|
+
ZSTD_free(*cond);
|
118
|
+
return ret;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
#endif
|