zstd-ruby 1.4.5.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 +237 -138
- data/ext/zstdruby/libzstd/README.md +28 -0
- data/ext/zstdruby/libzstd/common/bitstream.h +25 -16
- data/ext/zstdruby/libzstd/common/compiler.h +118 -4
- data/ext/zstdruby/libzstd/common/cpu.h +1 -3
- data/ext/zstdruby/libzstd/common/debug.c +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +12 -19
- data/ext/zstdruby/libzstd/common/entropy_common.c +189 -43
- data/ext/zstdruby/libzstd/common/error_private.c +2 -1
- data/ext/zstdruby/libzstd/common/error_private.h +2 -2
- data/ext/zstdruby/libzstd/common/fse.h +40 -12
- data/ext/zstdruby/libzstd/common/fse_decompress.c +124 -17
- data/ext/zstdruby/libzstd/common/huf.h +27 -6
- data/ext/zstdruby/libzstd/common/mem.h +67 -94
- data/ext/zstdruby/libzstd/common/pool.c +23 -17
- data/ext/zstdruby/libzstd/common/pool.h +2 -2
- data/ext/zstdruby/libzstd/common/threading.c +6 -5
- data/ext/zstdruby/libzstd/common/xxhash.c +19 -57
- data/ext/zstdruby/libzstd/common/xxhash.h +2 -2
- 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 +2 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +90 -59
- 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 +31 -24
- data/ext/zstdruby/libzstd/compress/hist.c +27 -29
- data/ext/zstdruby/libzstd/compress/hist.h +2 -2
- data/ext/zstdruby/libzstd/compress/huf_compress.c +217 -101
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +1495 -478
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +143 -44
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +7 -7
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +18 -4
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -21
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +62 -26
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +23 -23
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +21 -21
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +352 -78
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +276 -209
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +8 -2
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +191 -46
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +79 -410
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +27 -109
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +303 -201
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +9 -9
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +370 -87
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +153 -45
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +6 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +28 -11
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -1
- 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 +40 -31
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +2 -2
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +26 -25
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +22 -24
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +5 -4
- data/ext/zstdruby/libzstd/dll/example/Makefile +1 -1
- data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +7 -3
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
- data/ext/zstdruby/libzstd/libzstd.pc.in +3 -3
- data/ext/zstdruby/libzstd/zstd.h +414 -54
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +7 -3
- data/.travis.yml +0 -14
@@ -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
|
@@ -19,26 +19,14 @@
|
|
19
19
|
/* Note : This is an internal API.
|
20
20
|
* These APIs used to be exposed with ZSTDLIB_API,
|
21
21
|
* because it used to be the only way to invoke MT compression.
|
22
|
-
* Now,
|
23
|
-
* instead.
|
24
|
-
*
|
25
|
-
* If you depend on these APIs and can't switch, then define
|
26
|
-
* ZSTD_LEGACY_MULTITHREADED_API when making the dynamic library.
|
27
|
-
* However, we may completely remove these functions in a future
|
28
|
-
* release, so please switch soon.
|
22
|
+
* Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead.
|
29
23
|
*
|
30
24
|
* This API requires ZSTD_MULTITHREAD to be defined during compilation,
|
31
25
|
* otherwise ZSTDMT_createCCtx*() will fail.
|
32
26
|
*/
|
33
27
|
|
34
|
-
#ifdef ZSTD_LEGACY_MULTITHREADED_API
|
35
|
-
# define ZSTDMT_API ZSTDLIB_API
|
36
|
-
#else
|
37
|
-
# define ZSTDMT_API
|
38
|
-
#endif
|
39
|
-
|
40
28
|
/* === Dependencies === */
|
41
|
-
#include
|
29
|
+
#include "../common/zstd_deps.h" /* size_t */
|
42
30
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
|
43
31
|
#include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
|
44
32
|
|
@@ -54,78 +42,34 @@
|
|
54
42
|
#define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))
|
55
43
|
|
56
44
|
|
45
|
+
/* ========================================================
|
46
|
+
* === Private interface, for use by ZSTD_compress.c ===
|
47
|
+
* === Not exposed in libzstd. Never invoke directly ===
|
48
|
+
* ======================================================== */
|
49
|
+
|
57
50
|
/* === Memory management === */
|
58
51
|
typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
|
59
52
|
/* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
ZSTDMT_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
|
65
|
-
|
66
|
-
ZSTDMT_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
|
67
|
-
|
68
|
-
|
69
|
-
/* === Simple one-pass compression function === */
|
70
|
-
|
71
|
-
ZSTDMT_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
|
72
|
-
void* dst, size_t dstCapacity,
|
73
|
-
const void* src, size_t srcSize,
|
74
|
-
int compressionLevel);
|
75
|
-
|
53
|
+
ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
|
54
|
+
ZSTD_customMem cMem,
|
55
|
+
ZSTD_threadPool *pool);
|
56
|
+
size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
|
76
57
|
|
58
|
+
size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
|
77
59
|
|
78
60
|
/* === Streaming functions === */
|
79
61
|
|
80
|
-
|
81
|
-
ZSTDMT_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize); /**< if srcSize is not known at reset time, use ZSTD_CONTENTSIZE_UNKNOWN. Note: for compatibility with older programs, 0 means the same as ZSTD_CONTENTSIZE_UNKNOWN, but it will change in the future to mean "empty" */
|
82
|
-
|
83
|
-
ZSTDMT_API size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
|
84
|
-
ZSTDMT_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
|
85
|
-
|
86
|
-
ZSTDMT_API size_t ZSTDMT_flushStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
|
87
|
-
ZSTDMT_API size_t ZSTDMT_endStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
|
88
|
-
|
89
|
-
|
90
|
-
/* === Advanced functions and parameters === */
|
91
|
-
|
92
|
-
ZSTDMT_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
|
93
|
-
void* dst, size_t dstCapacity,
|
94
|
-
const void* src, size_t srcSize,
|
95
|
-
const ZSTD_CDict* cdict,
|
96
|
-
ZSTD_parameters params,
|
97
|
-
int overlapLog);
|
98
|
-
|
99
|
-
ZSTDMT_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
|
100
|
-
const void* dict, size_t dictSize, /* dict can be released after init, a local copy is preserved within zcs */
|
101
|
-
ZSTD_parameters params,
|
102
|
-
unsigned long long pledgedSrcSize); /* pledgedSrcSize is optional and can be zero == unknown */
|
103
|
-
|
104
|
-
ZSTDMT_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
|
105
|
-
const ZSTD_CDict* cdict,
|
106
|
-
ZSTD_frameParameters fparams,
|
107
|
-
unsigned long long pledgedSrcSize); /* note : zero means empty */
|
108
|
-
|
109
|
-
/* ZSTDMT_parameter :
|
110
|
-
* List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
|
111
|
-
typedef enum {
|
112
|
-
ZSTDMT_p_jobSize, /* Each job is compressed in parallel. By default, this value is dynamically determined depending on compression parameters. Can be set explicitly here. */
|
113
|
-
ZSTDMT_p_overlapLog, /* Each job may reload a part of previous job to enhance compression ratio; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window. This is a "sticky" parameter : its value will be re-used on next compression job */
|
114
|
-
ZSTDMT_p_rsyncable /* Enables rsyncable mode. */
|
115
|
-
} ZSTDMT_parameter;
|
116
|
-
|
117
|
-
/* ZSTDMT_setMTCtxParameter() :
|
118
|
-
* allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
|
119
|
-
* The function must be called typically after ZSTD_createCCtx() but __before ZSTDMT_init*() !__
|
120
|
-
* Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
|
121
|
-
* @return : 0, or an error code (which can be tested using ZSTD_isError()) */
|
122
|
-
ZSTDMT_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int value);
|
123
|
-
|
124
|
-
/* ZSTDMT_getMTCtxParameter() :
|
125
|
-
* Query the ZSTDMT_CCtx for a parameter value.
|
126
|
-
* @return : 0, or an error code (which can be tested using ZSTD_isError()) */
|
127
|
-
ZSTDMT_API size_t ZSTDMT_getMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int* value);
|
62
|
+
size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
|
128
63
|
|
64
|
+
/*! ZSTDMT_initCStream_internal() :
|
65
|
+
* Private use only. Init streaming operation.
|
66
|
+
* expects params to be valid.
|
67
|
+
* must receive dict, or cdict, or none, but not both.
|
68
|
+
* @return : 0, or an error code */
|
69
|
+
size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs,
|
70
|
+
const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
|
71
|
+
const ZSTD_CDict* cdict,
|
72
|
+
ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
|
129
73
|
|
130
74
|
/*! ZSTDMT_compressStream_generic() :
|
131
75
|
* Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
|
@@ -134,16 +78,10 @@ ZSTDMT_API size_t ZSTDMT_getMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter
|
|
134
78
|
* 0 if fully flushed
|
135
79
|
* or an error code
|
136
80
|
* note : needs to be init using any ZSTD_initCStream*() variant */
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
/* ========================================================
|
144
|
-
* === Private interface, for use by ZSTD_compress.c ===
|
145
|
-
* === Not exposed in libzstd. Never invoke directly ===
|
146
|
-
* ======================================================== */
|
81
|
+
size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
|
82
|
+
ZSTD_outBuffer* output,
|
83
|
+
ZSTD_inBuffer* input,
|
84
|
+
ZSTD_EndDirective endOp);
|
147
85
|
|
148
86
|
/*! ZSTDMT_toFlushNow()
|
149
87
|
* Tell how many bytes are ready to be flushed immediately.
|
@@ -153,15 +91,6 @@ ZSTDMT_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
|
|
153
91
|
* therefore flushing is limited by speed of oldest job. */
|
154
92
|
size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx);
|
155
93
|
|
156
|
-
/*! ZSTDMT_CCtxParam_setMTCtxParameter()
|
157
|
-
* like ZSTDMT_setMTCtxParameter(), but into a ZSTD_CCtx_Params */
|
158
|
-
size_t ZSTDMT_CCtxParam_setMTCtxParameter(ZSTD_CCtx_params* params, ZSTDMT_parameter parameter, int value);
|
159
|
-
|
160
|
-
/*! ZSTDMT_CCtxParam_setNbWorkers()
|
161
|
-
* Set nbWorkers, and clamp it.
|
162
|
-
* Also reset jobSize and overlapLog */
|
163
|
-
size_t ZSTDMT_CCtxParam_setNbWorkers(ZSTD_CCtx_params* params, unsigned nbWorkers);
|
164
|
-
|
165
94
|
/*! ZSTDMT_updateCParams_whileCompressing() :
|
166
95
|
* Updates only a selected set of compression parameters, to remain compatible with current frame.
|
167
96
|
* New parameters will be applied to next compression job. */
|
@@ -174,17 +103,6 @@ void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_p
|
|
174
103
|
ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);
|
175
104
|
|
176
105
|
|
177
|
-
/*! ZSTDMT_initCStream_internal() :
|
178
|
-
* Private use only. Init streaming operation.
|
179
|
-
* expects params to be valid.
|
180
|
-
* must receive dict, or cdict, or none, but not both.
|
181
|
-
* @return : 0, or an error code */
|
182
|
-
size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs,
|
183
|
-
const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
|
184
|
-
const ZSTD_CDict* cdict,
|
185
|
-
ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
|
186
|
-
|
187
|
-
|
188
106
|
#if defined (__cplusplus)
|
189
107
|
}
|
190
108
|
#endif
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* ******************************************************************
|
2
2
|
* huff0 huffman decoder,
|
3
3
|
* part of Finite State Entropy library
|
4
|
-
* Copyright (c) 2013-
|
4
|
+
* Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
|
5
5
|
*
|
6
6
|
* You can contact the author at :
|
7
7
|
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
@@ -15,7 +15,7 @@
|
|
15
15
|
/* **************************************************************
|
16
16
|
* Dependencies
|
17
17
|
****************************************************************/
|
18
|
-
#include
|
18
|
+
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memset */
|
19
19
|
#include "../common/compiler.h"
|
20
20
|
#include "../common/bitstream.h" /* BIT_* */
|
21
21
|
#include "../common/fse.h" /* to compress headers */
|
@@ -103,7 +103,7 @@ typedef struct { BYTE maxTableLog; BYTE tableType; BYTE tableLog; BYTE reserved;
|
|
103
103
|
static DTableDesc HUF_getDTableDesc(const HUF_DTable* table)
|
104
104
|
{
|
105
105
|
DTableDesc dtd;
|
106
|
-
|
106
|
+
ZSTD_memcpy(&dtd, table, sizeof(dtd));
|
107
107
|
return dtd;
|
108
108
|
}
|
109
109
|
|
@@ -115,29 +115,51 @@ static DTableDesc HUF_getDTableDesc(const HUF_DTable* table)
|
|
115
115
|
/*-***************************/
|
116
116
|
typedef struct { BYTE byte; BYTE nbBits; } HUF_DEltX1; /* single-symbol decoding */
|
117
117
|
|
118
|
+
/**
|
119
|
+
* Packs 4 HUF_DEltX1 structs into a U64. This is used to lay down 4 entries at
|
120
|
+
* a time.
|
121
|
+
*/
|
122
|
+
static U64 HUF_DEltX1_set4(BYTE symbol, BYTE nbBits) {
|
123
|
+
U64 D4;
|
124
|
+
if (MEM_isLittleEndian()) {
|
125
|
+
D4 = symbol + (nbBits << 8);
|
126
|
+
} else {
|
127
|
+
D4 = (symbol << 8) + nbBits;
|
128
|
+
}
|
129
|
+
D4 *= 0x0001000100010001ULL;
|
130
|
+
return D4;
|
131
|
+
}
|
132
|
+
|
133
|
+
typedef struct {
|
134
|
+
U32 rankVal[HUF_TABLELOG_ABSOLUTEMAX + 1];
|
135
|
+
U32 rankStart[HUF_TABLELOG_ABSOLUTEMAX + 1];
|
136
|
+
U32 statsWksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
|
137
|
+
BYTE symbols[HUF_SYMBOLVALUE_MAX + 1];
|
138
|
+
BYTE huffWeight[HUF_SYMBOLVALUE_MAX + 1];
|
139
|
+
} HUF_ReadDTableX1_Workspace;
|
140
|
+
|
141
|
+
|
118
142
|
size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize)
|
143
|
+
{
|
144
|
+
return HUF_readDTableX1_wksp_bmi2(DTable, src, srcSize, workSpace, wkspSize, /* bmi2 */ 0);
|
145
|
+
}
|
146
|
+
|
147
|
+
size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2)
|
119
148
|
{
|
120
149
|
U32 tableLog = 0;
|
121
150
|
U32 nbSymbols = 0;
|
122
151
|
size_t iSize;
|
123
152
|
void* const dtPtr = DTable + 1;
|
124
153
|
HUF_DEltX1* const dt = (HUF_DEltX1*)dtPtr;
|
154
|
+
HUF_ReadDTableX1_Workspace* wksp = (HUF_ReadDTableX1_Workspace*)workSpace;
|
125
155
|
|
126
|
-
|
127
|
-
|
128
|
-
size_t spaceUsed32 = 0;
|
129
|
-
|
130
|
-
rankVal = (U32 *)workSpace + spaceUsed32;
|
131
|
-
spaceUsed32 += HUF_TABLELOG_ABSOLUTEMAX + 1;
|
132
|
-
huffWeight = (BYTE *)((U32 *)workSpace + spaceUsed32);
|
133
|
-
spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;
|
134
|
-
|
135
|
-
if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);
|
156
|
+
DEBUG_STATIC_ASSERT(HUF_DECOMPRESS_WORKSPACE_SIZE >= sizeof(*wksp));
|
157
|
+
if (sizeof(*wksp) > wkspSize) return ERROR(tableLog_tooLarge);
|
136
158
|
|
137
159
|
DEBUG_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUF_DTable));
|
138
|
-
/*
|
160
|
+
/* ZSTD_memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
|
139
161
|
|
140
|
-
iSize =
|
162
|
+
iSize = HUF_readStats_wksp(wksp->huffWeight, HUF_SYMBOLVALUE_MAX + 1, wksp->rankVal, &nbSymbols, &tableLog, src, srcSize, wksp->statsWksp, sizeof(wksp->statsWksp), bmi2);
|
141
163
|
if (HUF_isError(iSize)) return iSize;
|
142
164
|
|
143
165
|
/* Table header */
|
@@ -145,52 +167,117 @@ size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize
|
|
145
167
|
if (tableLog > (U32)(dtd.maxTableLog+1)) return ERROR(tableLog_tooLarge); /* DTable too small, Huffman tree cannot fit in */
|
146
168
|
dtd.tableType = 0;
|
147
169
|
dtd.tableLog = (BYTE)tableLog;
|
148
|
-
|
170
|
+
ZSTD_memcpy(DTable, &dtd, sizeof(dtd));
|
149
171
|
}
|
150
172
|
|
151
|
-
/*
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
173
|
+
/* Compute symbols and rankStart given rankVal:
|
174
|
+
*
|
175
|
+
* rankVal already contains the number of values of each weight.
|
176
|
+
*
|
177
|
+
* symbols contains the symbols ordered by weight. First are the rankVal[0]
|
178
|
+
* weight 0 symbols, followed by the rankVal[1] weight 1 symbols, and so on.
|
179
|
+
* symbols[0] is filled (but unused) to avoid a branch.
|
180
|
+
*
|
181
|
+
* rankStart contains the offset where each rank belongs in the DTable.
|
182
|
+
* rankStart[0] is not filled because there are no entries in the table for
|
183
|
+
* weight 0.
|
184
|
+
*/
|
185
|
+
{
|
186
|
+
int n;
|
187
|
+
int nextRankStart = 0;
|
188
|
+
int const unroll = 4;
|
189
|
+
int const nLimit = (int)nbSymbols - unroll + 1;
|
190
|
+
for (n=0; n<(int)tableLog+1; n++) {
|
191
|
+
U32 const curr = nextRankStart;
|
192
|
+
nextRankStart += wksp->rankVal[n];
|
193
|
+
wksp->rankStart[n] = curr;
|
194
|
+
}
|
195
|
+
for (n=0; n < nLimit; n += unroll) {
|
196
|
+
int u;
|
197
|
+
for (u=0; u < unroll; ++u) {
|
198
|
+
size_t const w = wksp->huffWeight[n+u];
|
199
|
+
wksp->symbols[wksp->rankStart[w]++] = (BYTE)(n+u);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
for (; n < (int)nbSymbols; ++n) {
|
203
|
+
size_t const w = wksp->huffWeight[n];
|
204
|
+
wksp->symbols[wksp->rankStart[w]++] = (BYTE)n;
|
205
|
+
}
|
206
|
+
}
|
158
207
|
|
159
|
-
/* fill DTable
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
for (
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
dt[
|
183
|
-
|
208
|
+
/* fill DTable
|
209
|
+
* We fill all entries of each weight in order.
|
210
|
+
* That way length is a constant for each iteration of the outter loop.
|
211
|
+
* We can switch based on the length to a different inner loop which is
|
212
|
+
* optimized for that particular case.
|
213
|
+
*/
|
214
|
+
{
|
215
|
+
U32 w;
|
216
|
+
int symbol=wksp->rankVal[0];
|
217
|
+
int rankStart=0;
|
218
|
+
for (w=1; w<tableLog+1; ++w) {
|
219
|
+
int const symbolCount = wksp->rankVal[w];
|
220
|
+
int const length = (1 << w) >> 1;
|
221
|
+
int uStart = rankStart;
|
222
|
+
BYTE const nbBits = (BYTE)(tableLog + 1 - w);
|
223
|
+
int s;
|
224
|
+
int u;
|
225
|
+
switch (length) {
|
226
|
+
case 1:
|
227
|
+
for (s=0; s<symbolCount; ++s) {
|
228
|
+
HUF_DEltX1 D;
|
229
|
+
D.byte = wksp->symbols[symbol + s];
|
230
|
+
D.nbBits = nbBits;
|
231
|
+
dt[uStart] = D;
|
232
|
+
uStart += 1;
|
233
|
+
}
|
234
|
+
break;
|
235
|
+
case 2:
|
236
|
+
for (s=0; s<symbolCount; ++s) {
|
237
|
+
HUF_DEltX1 D;
|
238
|
+
D.byte = wksp->symbols[symbol + s];
|
239
|
+
D.nbBits = nbBits;
|
240
|
+
dt[uStart+0] = D;
|
241
|
+
dt[uStart+1] = D;
|
242
|
+
uStart += 2;
|
243
|
+
}
|
244
|
+
break;
|
245
|
+
case 4:
|
246
|
+
for (s=0; s<symbolCount; ++s) {
|
247
|
+
U64 const D4 = HUF_DEltX1_set4(wksp->symbols[symbol + s], nbBits);
|
248
|
+
MEM_write64(dt + uStart, D4);
|
249
|
+
uStart += 4;
|
250
|
+
}
|
251
|
+
break;
|
252
|
+
case 8:
|
253
|
+
for (s=0; s<symbolCount; ++s) {
|
254
|
+
U64 const D4 = HUF_DEltX1_set4(wksp->symbols[symbol + s], nbBits);
|
255
|
+
MEM_write64(dt + uStart, D4);
|
256
|
+
MEM_write64(dt + uStart + 4, D4);
|
257
|
+
uStart += 8;
|
258
|
+
}
|
259
|
+
break;
|
260
|
+
default:
|
261
|
+
for (s=0; s<symbolCount; ++s) {
|
262
|
+
U64 const D4 = HUF_DEltX1_set4(wksp->symbols[symbol + s], nbBits);
|
263
|
+
for (u=0; u < length; u += 16) {
|
264
|
+
MEM_write64(dt + uStart + u + 0, D4);
|
265
|
+
MEM_write64(dt + uStart + u + 4, D4);
|
266
|
+
MEM_write64(dt + uStart + u + 8, D4);
|
267
|
+
MEM_write64(dt + uStart + u + 12, D4);
|
268
|
+
}
|
269
|
+
assert(u == length);
|
270
|
+
uStart += length;
|
271
|
+
}
|
272
|
+
break;
|
273
|
+
}
|
274
|
+
symbol += symbolCount;
|
275
|
+
rankStart += symbolCount * length;
|
276
|
+
}
|
277
|
+
}
|
184
278
|
return iSize;
|
185
279
|
}
|
186
280
|
|
187
|
-
size_t HUF_readDTableX1(HUF_DTable* DTable, const void* src, size_t srcSize)
|
188
|
-
{
|
189
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
190
|
-
return HUF_readDTableX1_wksp(DTable, src, srcSize,
|
191
|
-
workSpace, sizeof(workSpace));
|
192
|
-
}
|
193
|
-
|
194
281
|
FORCE_INLINE_TEMPLATE BYTE
|
195
282
|
HUF_decodeSymbolX1(BIT_DStream_t* Dstream, const HUF_DEltX1* dt, const U32 dtLog)
|
196
283
|
{
|
@@ -389,20 +476,6 @@ size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
|
389
476
|
}
|
390
477
|
|
391
478
|
|
392
|
-
size_t HUF_decompress1X1_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
393
|
-
const void* cSrc, size_t cSrcSize)
|
394
|
-
{
|
395
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
396
|
-
return HUF_decompress1X1_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
|
397
|
-
workSpace, sizeof(workSpace));
|
398
|
-
}
|
399
|
-
|
400
|
-
size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
401
|
-
{
|
402
|
-
HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
|
403
|
-
return HUF_decompress1X1_DCtx (DTable, dst, dstSize, cSrc, cSrcSize);
|
404
|
-
}
|
405
|
-
|
406
479
|
size_t HUF_decompress4X1_usingDTable(
|
407
480
|
void* dst, size_t dstSize,
|
408
481
|
const void* cSrc, size_t cSrcSize,
|
@@ -419,8 +492,7 @@ static size_t HUF_decompress4X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size
|
|
419
492
|
{
|
420
493
|
const BYTE* ip = (const BYTE*) cSrc;
|
421
494
|
|
422
|
-
size_t const hSize =
|
423
|
-
workSpace, wkspSize);
|
495
|
+
size_t const hSize = HUF_readDTableX1_wksp_bmi2(dctx, cSrc, cSrcSize, workSpace, wkspSize, bmi2);
|
424
496
|
if (HUF_isError(hSize)) return hSize;
|
425
497
|
if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
|
426
498
|
ip += hSize; cSrcSize -= hSize;
|
@@ -436,18 +508,6 @@ size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|
436
508
|
}
|
437
509
|
|
438
510
|
|
439
|
-
size_t HUF_decompress4X1_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
440
|
-
{
|
441
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
442
|
-
return HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
443
|
-
workSpace, sizeof(workSpace));
|
444
|
-
}
|
445
|
-
size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
446
|
-
{
|
447
|
-
HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
|
448
|
-
return HUF_decompress4X1_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
449
|
-
}
|
450
|
-
|
451
511
|
#endif /* HUF_FORCE_DECOMPRESS_X2 */
|
452
512
|
|
453
513
|
|
@@ -474,7 +534,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 co
|
|
474
534
|
U32 rankVal[HUF_TABLELOG_MAX + 1];
|
475
535
|
|
476
536
|
/* get pre-calculated rankVal */
|
477
|
-
|
537
|
+
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(rankVal));
|
478
538
|
|
479
539
|
/* fill skipped values */
|
480
540
|
if (minWeight>1) {
|
@@ -516,7 +576,7 @@ static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
|
|
516
576
|
const U32 minBits = nbBitsBaseline - maxWeight;
|
517
577
|
U32 s;
|
518
578
|
|
519
|
-
|
579
|
+
ZSTD_memcpy(rankVal, rankValOrigin, sizeof(rankVal));
|
520
580
|
|
521
581
|
/* fill DTable */
|
522
582
|
for (s=0; s<sortedListSize; s++) {
|
@@ -581,11 +641,11 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
|
|
581
641
|
if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);
|
582
642
|
|
583
643
|
rankStart = rankStart0 + 1;
|
584
|
-
|
644
|
+
ZSTD_memset(rankStats, 0, sizeof(U32) * (2 * HUF_TABLELOG_MAX + 2 + 1));
|
585
645
|
|
586
646
|
DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable)); /* if compiler fails here, assertion is wrong */
|
587
647
|
if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
|
588
|
-
/*
|
648
|
+
/* ZSTD_memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
|
589
649
|
|
590
650
|
iSize = HUF_readStats(weightList, HUF_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
|
591
651
|
if (HUF_isError(iSize)) return iSize;
|
@@ -599,9 +659,9 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
|
|
599
659
|
/* Get start index of each weight */
|
600
660
|
{ U32 w, nextRankStart = 0;
|
601
661
|
for (w=1; w<maxW+1; w++) {
|
602
|
-
U32
|
662
|
+
U32 curr = nextRankStart;
|
603
663
|
nextRankStart += rankStats[w];
|
604
|
-
rankStart[w] =
|
664
|
+
rankStart[w] = curr;
|
605
665
|
}
|
606
666
|
rankStart[0] = nextRankStart; /* put all 0w symbols at the end of sorted list*/
|
607
667
|
sizeOfSort = nextRankStart;
|
@@ -624,9 +684,9 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
|
|
624
684
|
U32 nextRankVal = 0;
|
625
685
|
U32 w;
|
626
686
|
for (w=1; w<maxW+1; w++) {
|
627
|
-
U32
|
687
|
+
U32 curr = nextRankVal;
|
628
688
|
nextRankVal += rankStats[w] << (w+rescale);
|
629
|
-
rankVal0[w] =
|
689
|
+
rankVal0[w] = curr;
|
630
690
|
} }
|
631
691
|
{ U32 const minBits = tableLog+1 - maxW;
|
632
692
|
U32 consumed;
|
@@ -644,23 +704,16 @@ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
|
|
644
704
|
|
645
705
|
dtd.tableLog = (BYTE)maxTableLog;
|
646
706
|
dtd.tableType = 1;
|
647
|
-
|
707
|
+
ZSTD_memcpy(DTable, &dtd, sizeof(dtd));
|
648
708
|
return iSize;
|
649
709
|
}
|
650
710
|
|
651
|
-
size_t HUF_readDTableX2(HUF_DTable* DTable, const void* src, size_t srcSize)
|
652
|
-
{
|
653
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
654
|
-
return HUF_readDTableX2_wksp(DTable, src, srcSize,
|
655
|
-
workSpace, sizeof(workSpace));
|
656
|
-
}
|
657
|
-
|
658
711
|
|
659
712
|
FORCE_INLINE_TEMPLATE U32
|
660
713
|
HUF_decodeSymbolX2(void* op, BIT_DStream_t* DStream, const HUF_DEltX2* dt, const U32 dtLog)
|
661
714
|
{
|
662
715
|
size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
|
663
|
-
|
716
|
+
ZSTD_memcpy(op, dt+val, 2);
|
664
717
|
BIT_skipBits(DStream, dt[val].nbBits);
|
665
718
|
return dt[val].length;
|
666
719
|
}
|
@@ -669,7 +722,7 @@ FORCE_INLINE_TEMPLATE U32
|
|
669
722
|
HUF_decodeLastSymbolX2(void* op, BIT_DStream_t* DStream, const HUF_DEltX2* dt, const U32 dtLog)
|
670
723
|
{
|
671
724
|
size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
|
672
|
-
|
725
|
+
ZSTD_memcpy(op, dt+val, 1);
|
673
726
|
if (dt[val].length==1) BIT_skipBits(DStream, dt[val].nbBits);
|
674
727
|
else {
|
675
728
|
if (DStream->bitsConsumed < (sizeof(DStream->bitContainer)*8)) {
|
@@ -890,20 +943,6 @@ size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
|
890
943
|
}
|
891
944
|
|
892
945
|
|
893
|
-
size_t HUF_decompress1X2_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
894
|
-
const void* cSrc, size_t cSrcSize)
|
895
|
-
{
|
896
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
897
|
-
return HUF_decompress1X2_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
|
898
|
-
workSpace, sizeof(workSpace));
|
899
|
-
}
|
900
|
-
|
901
|
-
size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
902
|
-
{
|
903
|
-
HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
|
904
|
-
return HUF_decompress1X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
905
|
-
}
|
906
|
-
|
907
946
|
size_t HUF_decompress4X2_usingDTable(
|
908
947
|
void* dst, size_t dstSize,
|
909
948
|
const void* cSrc, size_t cSrcSize,
|
@@ -937,20 +976,6 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|
937
976
|
}
|
938
977
|
|
939
978
|
|
940
|
-
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize,
|
941
|
-
const void* cSrc, size_t cSrcSize)
|
942
|
-
{
|
943
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
944
|
-
return HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
945
|
-
workSpace, sizeof(workSpace));
|
946
|
-
}
|
947
|
-
|
948
|
-
size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
949
|
-
{
|
950
|
-
HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
|
951
|
-
return HUF_decompress4X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
952
|
-
}
|
953
|
-
|
954
979
|
#endif /* HUF_FORCE_DECOMPRESS_X1 */
|
955
980
|
|
956
981
|
|
@@ -1051,67 +1076,6 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize)
|
|
1051
1076
|
}
|
1052
1077
|
|
1053
1078
|
|
1054
|
-
typedef size_t (*decompressionAlgo)(void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
|
1055
|
-
|
1056
|
-
size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1057
|
-
{
|
1058
|
-
#if !defined(HUF_FORCE_DECOMPRESS_X1) && !defined(HUF_FORCE_DECOMPRESS_X2)
|
1059
|
-
static const decompressionAlgo decompress[2] = { HUF_decompress4X1, HUF_decompress4X2 };
|
1060
|
-
#endif
|
1061
|
-
|
1062
|
-
/* validation checks */
|
1063
|
-
if (dstSize == 0) return ERROR(dstSize_tooSmall);
|
1064
|
-
if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
|
1065
|
-
if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
|
1066
|
-
if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
|
1067
|
-
|
1068
|
-
{ U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
|
1069
|
-
#if defined(HUF_FORCE_DECOMPRESS_X1)
|
1070
|
-
(void)algoNb;
|
1071
|
-
assert(algoNb == 0);
|
1072
|
-
return HUF_decompress4X1(dst, dstSize, cSrc, cSrcSize);
|
1073
|
-
#elif defined(HUF_FORCE_DECOMPRESS_X2)
|
1074
|
-
(void)algoNb;
|
1075
|
-
assert(algoNb == 1);
|
1076
|
-
return HUF_decompress4X2(dst, dstSize, cSrc, cSrcSize);
|
1077
|
-
#else
|
1078
|
-
return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
|
1079
|
-
#endif
|
1080
|
-
}
|
1081
|
-
}
|
1082
|
-
|
1083
|
-
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1084
|
-
{
|
1085
|
-
/* validation checks */
|
1086
|
-
if (dstSize == 0) return ERROR(dstSize_tooSmall);
|
1087
|
-
if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
|
1088
|
-
if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
|
1089
|
-
if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
|
1090
|
-
|
1091
|
-
{ U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
|
1092
|
-
#if defined(HUF_FORCE_DECOMPRESS_X1)
|
1093
|
-
(void)algoNb;
|
1094
|
-
assert(algoNb == 0);
|
1095
|
-
return HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
|
1096
|
-
#elif defined(HUF_FORCE_DECOMPRESS_X2)
|
1097
|
-
(void)algoNb;
|
1098
|
-
assert(algoNb == 1);
|
1099
|
-
return HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
|
1100
|
-
#else
|
1101
|
-
return algoNb ? HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) :
|
1102
|
-
HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) ;
|
1103
|
-
#endif
|
1104
|
-
}
|
1105
|
-
}
|
1106
|
-
|
1107
|
-
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1108
|
-
{
|
1109
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1110
|
-
return HUF_decompress4X_hufOnly_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1111
|
-
workSpace, sizeof(workSpace));
|
1112
|
-
}
|
1113
|
-
|
1114
|
-
|
1115
1079
|
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst,
|
1116
1080
|
size_t dstSize, const void* cSrc,
|
1117
1081
|
size_t cSrcSize, void* workSpace,
|
@@ -1145,8 +1109,8 @@ size_t HUF_decompress1X_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|
1145
1109
|
/* validation checks */
|
1146
1110
|
if (dstSize == 0) return ERROR(dstSize_tooSmall);
|
1147
1111
|
if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
|
1148
|
-
if (cSrcSize == dstSize) {
|
1149
|
-
if (cSrcSize == 1) {
|
1112
|
+
if (cSrcSize == dstSize) { ZSTD_memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
|
1113
|
+
if (cSrcSize == 1) { ZSTD_memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
|
1150
1114
|
|
1151
1115
|
{ U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
|
1152
1116
|
#if defined(HUF_FORCE_DECOMPRESS_X1)
|
@@ -1168,14 +1132,6 @@ size_t HUF_decompress1X_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|
1168
1132
|
}
|
1169
1133
|
}
|
1170
1134
|
|
1171
|
-
size_t HUF_decompress1X_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize,
|
1172
|
-
const void* cSrc, size_t cSrcSize)
|
1173
|
-
{
|
1174
|
-
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1175
|
-
return HUF_decompress1X_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1176
|
-
workSpace, sizeof(workSpace));
|
1177
|
-
}
|
1178
|
-
|
1179
1135
|
|
1180
1136
|
size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2)
|
1181
1137
|
{
|
@@ -1199,7 +1155,7 @@ size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstS
|
|
1199
1155
|
{
|
1200
1156
|
const BYTE* ip = (const BYTE*) cSrc;
|
1201
1157
|
|
1202
|
-
size_t const hSize =
|
1158
|
+
size_t const hSize = HUF_readDTableX1_wksp_bmi2(dctx, cSrc, cSrcSize, workSpace, wkspSize, bmi2);
|
1203
1159
|
if (HUF_isError(hSize)) return hSize;
|
1204
1160
|
if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
|
1205
1161
|
ip += hSize; cSrcSize -= hSize;
|
@@ -1246,3 +1202,149 @@ size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t ds
|
|
1246
1202
|
#endif
|
1247
1203
|
}
|
1248
1204
|
}
|
1205
|
+
|
1206
|
+
#ifndef ZSTD_NO_UNUSED_FUNCTIONS
|
1207
|
+
#ifndef HUF_FORCE_DECOMPRESS_X2
|
1208
|
+
size_t HUF_readDTableX1(HUF_DTable* DTable, const void* src, size_t srcSize)
|
1209
|
+
{
|
1210
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1211
|
+
return HUF_readDTableX1_wksp(DTable, src, srcSize,
|
1212
|
+
workSpace, sizeof(workSpace));
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
size_t HUF_decompress1X1_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
1216
|
+
const void* cSrc, size_t cSrcSize)
|
1217
|
+
{
|
1218
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1219
|
+
return HUF_decompress1X1_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
|
1220
|
+
workSpace, sizeof(workSpace));
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1224
|
+
{
|
1225
|
+
HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
|
1226
|
+
return HUF_decompress1X1_DCtx (DTable, dst, dstSize, cSrc, cSrcSize);
|
1227
|
+
}
|
1228
|
+
#endif
|
1229
|
+
|
1230
|
+
#ifndef HUF_FORCE_DECOMPRESS_X1
|
1231
|
+
size_t HUF_readDTableX2(HUF_DTable* DTable, const void* src, size_t srcSize)
|
1232
|
+
{
|
1233
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1234
|
+
return HUF_readDTableX2_wksp(DTable, src, srcSize,
|
1235
|
+
workSpace, sizeof(workSpace));
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
size_t HUF_decompress1X2_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize,
|
1239
|
+
const void* cSrc, size_t cSrcSize)
|
1240
|
+
{
|
1241
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1242
|
+
return HUF_decompress1X2_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
|
1243
|
+
workSpace, sizeof(workSpace));
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1247
|
+
{
|
1248
|
+
HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
|
1249
|
+
return HUF_decompress1X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
1250
|
+
}
|
1251
|
+
#endif
|
1252
|
+
|
1253
|
+
#ifndef HUF_FORCE_DECOMPRESS_X2
|
1254
|
+
size_t HUF_decompress4X1_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1255
|
+
{
|
1256
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1257
|
+
return HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1258
|
+
workSpace, sizeof(workSpace));
|
1259
|
+
}
|
1260
|
+
size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1261
|
+
{
|
1262
|
+
HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
|
1263
|
+
return HUF_decompress4X1_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
1264
|
+
}
|
1265
|
+
#endif
|
1266
|
+
|
1267
|
+
#ifndef HUF_FORCE_DECOMPRESS_X1
|
1268
|
+
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize,
|
1269
|
+
const void* cSrc, size_t cSrcSize)
|
1270
|
+
{
|
1271
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1272
|
+
return HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1273
|
+
workSpace, sizeof(workSpace));
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1277
|
+
{
|
1278
|
+
HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
|
1279
|
+
return HUF_decompress4X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
|
1280
|
+
}
|
1281
|
+
#endif
|
1282
|
+
|
1283
|
+
typedef size_t (*decompressionAlgo)(void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
|
1284
|
+
|
1285
|
+
size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1286
|
+
{
|
1287
|
+
#if !defined(HUF_FORCE_DECOMPRESS_X1) && !defined(HUF_FORCE_DECOMPRESS_X2)
|
1288
|
+
static const decompressionAlgo decompress[2] = { HUF_decompress4X1, HUF_decompress4X2 };
|
1289
|
+
#endif
|
1290
|
+
|
1291
|
+
/* validation checks */
|
1292
|
+
if (dstSize == 0) return ERROR(dstSize_tooSmall);
|
1293
|
+
if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
|
1294
|
+
if (cSrcSize == dstSize) { ZSTD_memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
|
1295
|
+
if (cSrcSize == 1) { ZSTD_memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
|
1296
|
+
|
1297
|
+
{ U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
|
1298
|
+
#if defined(HUF_FORCE_DECOMPRESS_X1)
|
1299
|
+
(void)algoNb;
|
1300
|
+
assert(algoNb == 0);
|
1301
|
+
return HUF_decompress4X1(dst, dstSize, cSrc, cSrcSize);
|
1302
|
+
#elif defined(HUF_FORCE_DECOMPRESS_X2)
|
1303
|
+
(void)algoNb;
|
1304
|
+
assert(algoNb == 1);
|
1305
|
+
return HUF_decompress4X2(dst, dstSize, cSrc, cSrcSize);
|
1306
|
+
#else
|
1307
|
+
return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
|
1308
|
+
#endif
|
1309
|
+
}
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1313
|
+
{
|
1314
|
+
/* validation checks */
|
1315
|
+
if (dstSize == 0) return ERROR(dstSize_tooSmall);
|
1316
|
+
if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
|
1317
|
+
if (cSrcSize == dstSize) { ZSTD_memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
|
1318
|
+
if (cSrcSize == 1) { ZSTD_memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
|
1319
|
+
|
1320
|
+
{ U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
|
1321
|
+
#if defined(HUF_FORCE_DECOMPRESS_X1)
|
1322
|
+
(void)algoNb;
|
1323
|
+
assert(algoNb == 0);
|
1324
|
+
return HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
|
1325
|
+
#elif defined(HUF_FORCE_DECOMPRESS_X2)
|
1326
|
+
(void)algoNb;
|
1327
|
+
assert(algoNb == 1);
|
1328
|
+
return HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
|
1329
|
+
#else
|
1330
|
+
return algoNb ? HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) :
|
1331
|
+
HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) ;
|
1332
|
+
#endif
|
1333
|
+
}
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
1337
|
+
{
|
1338
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1339
|
+
return HUF_decompress4X_hufOnly_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1340
|
+
workSpace, sizeof(workSpace));
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
size_t HUF_decompress1X_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize,
|
1344
|
+
const void* cSrc, size_t cSrcSize)
|
1345
|
+
{
|
1346
|
+
U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
|
1347
|
+
return HUF_decompress1X_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
|
1348
|
+
workSpace, sizeof(workSpace));
|
1349
|
+
}
|
1350
|
+
#endif
|