extzstd 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/contrib/zstd/CHANGELOG +188 -1
- data/contrib/zstd/CONTRIBUTING.md +157 -74
- data/contrib/zstd/LICENSE +4 -4
- data/contrib/zstd/Makefile +81 -58
- data/contrib/zstd/Package.swift +36 -0
- data/contrib/zstd/README.md +59 -35
- data/contrib/zstd/TESTING.md +2 -3
- data/contrib/zstd/appveyor.yml +49 -136
- data/contrib/zstd/lib/BUCK +5 -7
- data/contrib/zstd/lib/Makefile +87 -181
- data/contrib/zstd/lib/README.md +23 -6
- data/contrib/zstd/lib/common/allocations.h +55 -0
- data/contrib/zstd/lib/common/bits.h +200 -0
- data/contrib/zstd/lib/common/bitstream.h +33 -59
- data/contrib/zstd/lib/common/compiler.h +115 -45
- data/contrib/zstd/lib/common/cpu.h +1 -1
- data/contrib/zstd/lib/common/debug.c +1 -1
- data/contrib/zstd/lib/common/debug.h +1 -1
- data/contrib/zstd/lib/common/entropy_common.c +15 -37
- data/contrib/zstd/lib/common/error_private.c +9 -2
- data/contrib/zstd/lib/common/error_private.h +82 -3
- data/contrib/zstd/lib/common/fse.h +9 -85
- data/contrib/zstd/lib/common/fse_decompress.c +29 -111
- data/contrib/zstd/lib/common/huf.h +84 -172
- data/contrib/zstd/lib/common/mem.h +58 -49
- data/contrib/zstd/lib/common/pool.c +37 -16
- data/contrib/zstd/lib/common/pool.h +9 -3
- data/contrib/zstd/lib/common/portability_macros.h +156 -0
- data/contrib/zstd/lib/common/threading.c +68 -14
- data/contrib/zstd/lib/common/threading.h +5 -10
- data/contrib/zstd/lib/common/xxhash.c +7 -809
- data/contrib/zstd/lib/common/xxhash.h +5568 -167
- data/contrib/zstd/lib/common/zstd_common.c +1 -36
- data/contrib/zstd/lib/common/zstd_deps.h +1 -1
- data/contrib/zstd/lib/common/zstd_internal.h +64 -150
- data/contrib/zstd/lib/common/zstd_trace.h +163 -0
- data/contrib/zstd/lib/compress/clevels.h +134 -0
- data/contrib/zstd/lib/compress/fse_compress.c +69 -150
- data/contrib/zstd/lib/compress/hist.c +1 -1
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +773 -251
- data/contrib/zstd/lib/compress/zstd_compress.c +2650 -826
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +509 -180
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +33 -305
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/contrib/zstd/lib/compress/zstd_cwksp.h +266 -85
- data/contrib/zstd/lib/compress/zstd_double_fast.c +369 -132
- data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
- data/contrib/zstd/lib/compress/zstd_fast.c +722 -258
- data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
- data/contrib/zstd/lib/compress/zstd_lazy.c +1105 -360
- data/contrib/zstd/lib/compress/zstd_lazy.h +41 -1
- data/contrib/zstd/lib/compress/zstd_ldm.c +272 -208
- data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
- data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +324 -197
- data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
- data/contrib/zstd/lib/compress/zstdmt_compress.c +109 -53
- data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
- data/contrib/zstd/lib/decompress/huf_decompress.c +1071 -539
- data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +507 -82
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +962 -310
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +54 -6
- data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/contrib/zstd/lib/dictBuilder/cover.c +44 -32
- data/contrib/zstd/lib/dictBuilder/cover.h +6 -5
- data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +24 -16
- data/contrib/zstd/lib/dictBuilder/zdict.c +88 -95
- data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +16 -53
- data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +24 -69
- data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +25 -72
- data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +23 -69
- data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v05.c +35 -85
- data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +42 -87
- data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +35 -82
- data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
- data/contrib/zstd/lib/libzstd.mk +214 -0
- data/contrib/zstd/lib/libzstd.pc.in +4 -3
- data/contrib/zstd/lib/module.modulemap +35 -0
- data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
- data/contrib/zstd/lib/zstd.h +922 -293
- data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
- data/ext/extconf.rb +7 -6
- data/ext/extzstd.c +13 -10
- data/ext/libzstd_conf.h +0 -1
- data/ext/zstd_decompress_asm.S +1 -0
- metadata +16 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
|
@@ -15,288 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
#include "../common/zstd_internal.h" /* ZSTD_getSequenceLength */
|
|
17
17
|
#include "hist.h" /* HIST_countFast_wksp */
|
|
18
|
-
#include "zstd_compress_internal.h"
|
|
18
|
+
#include "zstd_compress_internal.h" /* ZSTD_[huf|fse|entropy]CTablesMetadata_t */
|
|
19
19
|
#include "zstd_compress_sequences.h"
|
|
20
20
|
#include "zstd_compress_literals.h"
|
|
21
21
|
|
|
22
|
-
/*-*************************************
|
|
23
|
-
* Superblock entropy buffer structs
|
|
24
|
-
***************************************/
|
|
25
|
-
/** ZSTD_hufCTablesMetadata_t :
|
|
26
|
-
* Stores Literals Block Type for a super-block in hType, and
|
|
27
|
-
* huffman tree description in hufDesBuffer.
|
|
28
|
-
* hufDesSize refers to the size of huffman tree description in bytes.
|
|
29
|
-
* This metadata is populated in ZSTD_buildSuperBlockEntropy_literal() */
|
|
30
|
-
typedef struct {
|
|
31
|
-
symbolEncodingType_e hType;
|
|
32
|
-
BYTE hufDesBuffer[ZSTD_MAX_HUF_HEADER_SIZE];
|
|
33
|
-
size_t hufDesSize;
|
|
34
|
-
} ZSTD_hufCTablesMetadata_t;
|
|
35
|
-
|
|
36
|
-
/** ZSTD_fseCTablesMetadata_t :
|
|
37
|
-
* Stores symbol compression modes for a super-block in {ll, ol, ml}Type, and
|
|
38
|
-
* fse tables in fseTablesBuffer.
|
|
39
|
-
* fseTablesSize refers to the size of fse tables in bytes.
|
|
40
|
-
* This metadata is populated in ZSTD_buildSuperBlockEntropy_sequences() */
|
|
41
|
-
typedef struct {
|
|
42
|
-
symbolEncodingType_e llType;
|
|
43
|
-
symbolEncodingType_e ofType;
|
|
44
|
-
symbolEncodingType_e mlType;
|
|
45
|
-
BYTE fseTablesBuffer[ZSTD_MAX_FSE_HEADERS_SIZE];
|
|
46
|
-
size_t fseTablesSize;
|
|
47
|
-
size_t lastCountSize; /* This is to account for bug in 1.3.4. More detail in ZSTD_compressSubBlock_sequences() */
|
|
48
|
-
} ZSTD_fseCTablesMetadata_t;
|
|
49
|
-
|
|
50
|
-
typedef struct {
|
|
51
|
-
ZSTD_hufCTablesMetadata_t hufMetadata;
|
|
52
|
-
ZSTD_fseCTablesMetadata_t fseMetadata;
|
|
53
|
-
} ZSTD_entropyCTablesMetadata_t;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/** ZSTD_buildSuperBlockEntropy_literal() :
|
|
57
|
-
* Builds entropy for the super-block literals.
|
|
58
|
-
* Stores literals block type (raw, rle, compressed, repeat) and
|
|
59
|
-
* huffman description table to hufMetadata.
|
|
60
|
-
* @return : size of huffman description table or error code */
|
|
61
|
-
static size_t ZSTD_buildSuperBlockEntropy_literal(void* const src, size_t srcSize,
|
|
62
|
-
const ZSTD_hufCTables_t* prevHuf,
|
|
63
|
-
ZSTD_hufCTables_t* nextHuf,
|
|
64
|
-
ZSTD_hufCTablesMetadata_t* hufMetadata,
|
|
65
|
-
const int disableLiteralsCompression,
|
|
66
|
-
void* workspace, size_t wkspSize)
|
|
67
|
-
{
|
|
68
|
-
BYTE* const wkspStart = (BYTE*)workspace;
|
|
69
|
-
BYTE* const wkspEnd = wkspStart + wkspSize;
|
|
70
|
-
BYTE* const countWkspStart = wkspStart;
|
|
71
|
-
unsigned* const countWksp = (unsigned*)workspace;
|
|
72
|
-
const size_t countWkspSize = (HUF_SYMBOLVALUE_MAX + 1) * sizeof(unsigned);
|
|
73
|
-
BYTE* const nodeWksp = countWkspStart + countWkspSize;
|
|
74
|
-
const size_t nodeWkspSize = wkspEnd-nodeWksp;
|
|
75
|
-
unsigned maxSymbolValue = 255;
|
|
76
|
-
unsigned huffLog = HUF_TABLELOG_DEFAULT;
|
|
77
|
-
HUF_repeat repeat = prevHuf->repeatMode;
|
|
78
|
-
|
|
79
|
-
DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_literal (srcSize=%zu)", srcSize);
|
|
80
|
-
|
|
81
|
-
/* Prepare nextEntropy assuming reusing the existing table */
|
|
82
|
-
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
|
83
|
-
|
|
84
|
-
if (disableLiteralsCompression) {
|
|
85
|
-
DEBUGLOG(5, "set_basic - disabled");
|
|
86
|
-
hufMetadata->hType = set_basic;
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* small ? don't even attempt compression (speed opt) */
|
|
91
|
-
# define COMPRESS_LITERALS_SIZE_MIN 63
|
|
92
|
-
{ size_t const minLitSize = (prevHuf->repeatMode == HUF_repeat_valid) ? 6 : COMPRESS_LITERALS_SIZE_MIN;
|
|
93
|
-
if (srcSize <= minLitSize) {
|
|
94
|
-
DEBUGLOG(5, "set_basic - too small");
|
|
95
|
-
hufMetadata->hType = set_basic;
|
|
96
|
-
return 0;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/* Scan input and build symbol stats */
|
|
101
|
-
{ size_t const largest = HIST_count_wksp (countWksp, &maxSymbolValue, (const BYTE*)src, srcSize, workspace, wkspSize);
|
|
102
|
-
FORWARD_IF_ERROR(largest, "HIST_count_wksp failed");
|
|
103
|
-
if (largest == srcSize) {
|
|
104
|
-
DEBUGLOG(5, "set_rle");
|
|
105
|
-
hufMetadata->hType = set_rle;
|
|
106
|
-
return 0;
|
|
107
|
-
}
|
|
108
|
-
if (largest <= (srcSize >> 7)+4) {
|
|
109
|
-
DEBUGLOG(5, "set_basic - no gain");
|
|
110
|
-
hufMetadata->hType = set_basic;
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* Validate the previous Huffman table */
|
|
116
|
-
if (repeat == HUF_repeat_check && !HUF_validateCTable((HUF_CElt const*)prevHuf->CTable, countWksp, maxSymbolValue)) {
|
|
117
|
-
repeat = HUF_repeat_none;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/* Build Huffman Tree */
|
|
121
|
-
ZSTD_memset(nextHuf->CTable, 0, sizeof(nextHuf->CTable));
|
|
122
|
-
huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue);
|
|
123
|
-
{ size_t const maxBits = HUF_buildCTable_wksp((HUF_CElt*)nextHuf->CTable, countWksp,
|
|
124
|
-
maxSymbolValue, huffLog,
|
|
125
|
-
nodeWksp, nodeWkspSize);
|
|
126
|
-
FORWARD_IF_ERROR(maxBits, "HUF_buildCTable_wksp");
|
|
127
|
-
huffLog = (U32)maxBits;
|
|
128
|
-
{ /* Build and write the CTable */
|
|
129
|
-
size_t const newCSize = HUF_estimateCompressedSize(
|
|
130
|
-
(HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue);
|
|
131
|
-
size_t const hSize = HUF_writeCTable(
|
|
132
|
-
hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer),
|
|
133
|
-
(HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog);
|
|
134
|
-
/* Check against repeating the previous CTable */
|
|
135
|
-
if (repeat != HUF_repeat_none) {
|
|
136
|
-
size_t const oldCSize = HUF_estimateCompressedSize(
|
|
137
|
-
(HUF_CElt const*)prevHuf->CTable, countWksp, maxSymbolValue);
|
|
138
|
-
if (oldCSize < srcSize && (oldCSize <= hSize + newCSize || hSize + 12 >= srcSize)) {
|
|
139
|
-
DEBUGLOG(5, "set_repeat - smaller");
|
|
140
|
-
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
|
141
|
-
hufMetadata->hType = set_repeat;
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (newCSize + hSize >= srcSize) {
|
|
146
|
-
DEBUGLOG(5, "set_basic - no gains");
|
|
147
|
-
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
|
148
|
-
hufMetadata->hType = set_basic;
|
|
149
|
-
return 0;
|
|
150
|
-
}
|
|
151
|
-
DEBUGLOG(5, "set_compressed (hSize=%u)", (U32)hSize);
|
|
152
|
-
hufMetadata->hType = set_compressed;
|
|
153
|
-
nextHuf->repeatMode = HUF_repeat_check;
|
|
154
|
-
return hSize;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** ZSTD_buildSuperBlockEntropy_sequences() :
|
|
160
|
-
* Builds entropy for the super-block sequences.
|
|
161
|
-
* Stores symbol compression modes and fse table to fseMetadata.
|
|
162
|
-
* @return : size of fse tables or error code */
|
|
163
|
-
static size_t ZSTD_buildSuperBlockEntropy_sequences(seqStore_t* seqStorePtr,
|
|
164
|
-
const ZSTD_fseCTables_t* prevEntropy,
|
|
165
|
-
ZSTD_fseCTables_t* nextEntropy,
|
|
166
|
-
const ZSTD_CCtx_params* cctxParams,
|
|
167
|
-
ZSTD_fseCTablesMetadata_t* fseMetadata,
|
|
168
|
-
void* workspace, size_t wkspSize)
|
|
169
|
-
{
|
|
170
|
-
BYTE* const wkspStart = (BYTE*)workspace;
|
|
171
|
-
BYTE* const wkspEnd = wkspStart + wkspSize;
|
|
172
|
-
BYTE* const countWkspStart = wkspStart;
|
|
173
|
-
unsigned* const countWksp = (unsigned*)workspace;
|
|
174
|
-
const size_t countWkspSize = (MaxSeq + 1) * sizeof(unsigned);
|
|
175
|
-
BYTE* const cTableWksp = countWkspStart + countWkspSize;
|
|
176
|
-
const size_t cTableWkspSize = wkspEnd-cTableWksp;
|
|
177
|
-
ZSTD_strategy const strategy = cctxParams->cParams.strategy;
|
|
178
|
-
FSE_CTable* CTable_LitLength = nextEntropy->litlengthCTable;
|
|
179
|
-
FSE_CTable* CTable_OffsetBits = nextEntropy->offcodeCTable;
|
|
180
|
-
FSE_CTable* CTable_MatchLength = nextEntropy->matchlengthCTable;
|
|
181
|
-
const BYTE* const ofCodeTable = seqStorePtr->ofCode;
|
|
182
|
-
const BYTE* const llCodeTable = seqStorePtr->llCode;
|
|
183
|
-
const BYTE* const mlCodeTable = seqStorePtr->mlCode;
|
|
184
|
-
size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart;
|
|
185
|
-
BYTE* const ostart = fseMetadata->fseTablesBuffer;
|
|
186
|
-
BYTE* const oend = ostart + sizeof(fseMetadata->fseTablesBuffer);
|
|
187
|
-
BYTE* op = ostart;
|
|
188
|
-
|
|
189
|
-
assert(cTableWkspSize >= (1 << MaxFSELog) * sizeof(FSE_FUNCTION_TYPE));
|
|
190
|
-
DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_sequences (nbSeq=%zu)", nbSeq);
|
|
191
|
-
ZSTD_memset(workspace, 0, wkspSize);
|
|
192
|
-
|
|
193
|
-
fseMetadata->lastCountSize = 0;
|
|
194
|
-
/* convert length/distances into codes */
|
|
195
|
-
ZSTD_seqToCodes(seqStorePtr);
|
|
196
|
-
/* build CTable for Literal Lengths */
|
|
197
|
-
{ U32 LLtype;
|
|
198
|
-
unsigned max = MaxLL;
|
|
199
|
-
size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, llCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
|
200
|
-
DEBUGLOG(5, "Building LL table");
|
|
201
|
-
nextEntropy->litlength_repeatMode = prevEntropy->litlength_repeatMode;
|
|
202
|
-
LLtype = ZSTD_selectEncodingType(&nextEntropy->litlength_repeatMode,
|
|
203
|
-
countWksp, max, mostFrequent, nbSeq,
|
|
204
|
-
LLFSELog, prevEntropy->litlengthCTable,
|
|
205
|
-
LL_defaultNorm, LL_defaultNormLog,
|
|
206
|
-
ZSTD_defaultAllowed, strategy);
|
|
207
|
-
assert(set_basic < set_compressed && set_rle < set_compressed);
|
|
208
|
-
assert(!(LLtype < set_compressed && nextEntropy->litlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
|
209
|
-
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype,
|
|
210
|
-
countWksp, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL,
|
|
211
|
-
prevEntropy->litlengthCTable, sizeof(prevEntropy->litlengthCTable),
|
|
212
|
-
cTableWksp, cTableWkspSize);
|
|
213
|
-
FORWARD_IF_ERROR(countSize, "ZSTD_buildCTable for LitLens failed");
|
|
214
|
-
if (LLtype == set_compressed)
|
|
215
|
-
fseMetadata->lastCountSize = countSize;
|
|
216
|
-
op += countSize;
|
|
217
|
-
fseMetadata->llType = (symbolEncodingType_e) LLtype;
|
|
218
|
-
} }
|
|
219
|
-
/* build CTable for Offsets */
|
|
220
|
-
{ U32 Offtype;
|
|
221
|
-
unsigned max = MaxOff;
|
|
222
|
-
size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, ofCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
|
223
|
-
/* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */
|
|
224
|
-
ZSTD_defaultPolicy_e const defaultPolicy = (max <= DefaultMaxOff) ? ZSTD_defaultAllowed : ZSTD_defaultDisallowed;
|
|
225
|
-
DEBUGLOG(5, "Building OF table");
|
|
226
|
-
nextEntropy->offcode_repeatMode = prevEntropy->offcode_repeatMode;
|
|
227
|
-
Offtype = ZSTD_selectEncodingType(&nextEntropy->offcode_repeatMode,
|
|
228
|
-
countWksp, max, mostFrequent, nbSeq,
|
|
229
|
-
OffFSELog, prevEntropy->offcodeCTable,
|
|
230
|
-
OF_defaultNorm, OF_defaultNormLog,
|
|
231
|
-
defaultPolicy, strategy);
|
|
232
|
-
assert(!(Offtype < set_compressed && nextEntropy->offcode_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
|
233
|
-
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype,
|
|
234
|
-
countWksp, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
|
235
|
-
prevEntropy->offcodeCTable, sizeof(prevEntropy->offcodeCTable),
|
|
236
|
-
cTableWksp, cTableWkspSize);
|
|
237
|
-
FORWARD_IF_ERROR(countSize, "ZSTD_buildCTable for Offsets failed");
|
|
238
|
-
if (Offtype == set_compressed)
|
|
239
|
-
fseMetadata->lastCountSize = countSize;
|
|
240
|
-
op += countSize;
|
|
241
|
-
fseMetadata->ofType = (symbolEncodingType_e) Offtype;
|
|
242
|
-
} }
|
|
243
|
-
/* build CTable for MatchLengths */
|
|
244
|
-
{ U32 MLtype;
|
|
245
|
-
unsigned max = MaxML;
|
|
246
|
-
size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, mlCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
|
247
|
-
DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op));
|
|
248
|
-
nextEntropy->matchlength_repeatMode = prevEntropy->matchlength_repeatMode;
|
|
249
|
-
MLtype = ZSTD_selectEncodingType(&nextEntropy->matchlength_repeatMode,
|
|
250
|
-
countWksp, max, mostFrequent, nbSeq,
|
|
251
|
-
MLFSELog, prevEntropy->matchlengthCTable,
|
|
252
|
-
ML_defaultNorm, ML_defaultNormLog,
|
|
253
|
-
ZSTD_defaultAllowed, strategy);
|
|
254
|
-
assert(!(MLtype < set_compressed && nextEntropy->matchlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
|
255
|
-
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype,
|
|
256
|
-
countWksp, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML,
|
|
257
|
-
prevEntropy->matchlengthCTable, sizeof(prevEntropy->matchlengthCTable),
|
|
258
|
-
cTableWksp, cTableWkspSize);
|
|
259
|
-
FORWARD_IF_ERROR(countSize, "ZSTD_buildCTable for MatchLengths failed");
|
|
260
|
-
if (MLtype == set_compressed)
|
|
261
|
-
fseMetadata->lastCountSize = countSize;
|
|
262
|
-
op += countSize;
|
|
263
|
-
fseMetadata->mlType = (symbolEncodingType_e) MLtype;
|
|
264
|
-
} }
|
|
265
|
-
assert((size_t) (op-ostart) <= sizeof(fseMetadata->fseTablesBuffer));
|
|
266
|
-
return op-ostart;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
/** ZSTD_buildSuperBlockEntropy() :
|
|
271
|
-
* Builds entropy for the super-block.
|
|
272
|
-
* @return : 0 on success or error code */
|
|
273
|
-
static size_t
|
|
274
|
-
ZSTD_buildSuperBlockEntropy(seqStore_t* seqStorePtr,
|
|
275
|
-
const ZSTD_entropyCTables_t* prevEntropy,
|
|
276
|
-
ZSTD_entropyCTables_t* nextEntropy,
|
|
277
|
-
const ZSTD_CCtx_params* cctxParams,
|
|
278
|
-
ZSTD_entropyCTablesMetadata_t* entropyMetadata,
|
|
279
|
-
void* workspace, size_t wkspSize)
|
|
280
|
-
{
|
|
281
|
-
size_t const litSize = seqStorePtr->lit - seqStorePtr->litStart;
|
|
282
|
-
DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy");
|
|
283
|
-
entropyMetadata->hufMetadata.hufDesSize =
|
|
284
|
-
ZSTD_buildSuperBlockEntropy_literal(seqStorePtr->litStart, litSize,
|
|
285
|
-
&prevEntropy->huf, &nextEntropy->huf,
|
|
286
|
-
&entropyMetadata->hufMetadata,
|
|
287
|
-
ZSTD_disableLiteralsCompression(cctxParams),
|
|
288
|
-
workspace, wkspSize);
|
|
289
|
-
FORWARD_IF_ERROR(entropyMetadata->hufMetadata.hufDesSize, "ZSTD_buildSuperBlockEntropy_literal failed");
|
|
290
|
-
entropyMetadata->fseMetadata.fseTablesSize =
|
|
291
|
-
ZSTD_buildSuperBlockEntropy_sequences(seqStorePtr,
|
|
292
|
-
&prevEntropy->fse, &nextEntropy->fse,
|
|
293
|
-
cctxParams,
|
|
294
|
-
&entropyMetadata->fseMetadata,
|
|
295
|
-
workspace, wkspSize);
|
|
296
|
-
FORWARD_IF_ERROR(entropyMetadata->fseMetadata.fseTablesSize, "ZSTD_buildSuperBlockEntropy_sequences failed");
|
|
297
|
-
return 0;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
22
|
/** ZSTD_compressSubBlock_literal() :
|
|
301
23
|
* Compresses literals section for a sub-block.
|
|
302
24
|
* When we have to write the Huffman table we will sometimes choose a header
|
|
@@ -304,7 +26,7 @@ ZSTD_buildSuperBlockEntropy(seqStore_t* seqStorePtr,
|
|
|
304
26
|
* before we know the table size + compressed size, so we have a bound on the
|
|
305
27
|
* table size. If we guessed incorrectly, we fall back to uncompressed literals.
|
|
306
28
|
*
|
|
307
|
-
* We write the header when writeEntropy=1 and set
|
|
29
|
+
* We write the header when writeEntropy=1 and set entropyWritten=1 when we succeeded
|
|
308
30
|
* in writing the header, otherwise it is set to 0.
|
|
309
31
|
*
|
|
310
32
|
* hufMetadata->hType has literals block type info.
|
|
@@ -314,13 +36,14 @@ ZSTD_buildSuperBlockEntropy(seqStore_t* seqStorePtr,
|
|
|
314
36
|
* If it is set_compressed, first sub-block's literals section will be Treeless_Literals_Block
|
|
315
37
|
* and the following sub-blocks' literals sections will be Treeless_Literals_Block.
|
|
316
38
|
* @return : compressed size of literals section of a sub-block
|
|
317
|
-
* Or 0 if
|
|
39
|
+
* Or 0 if unable to compress.
|
|
318
40
|
* Or error code */
|
|
319
|
-
static size_t
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
41
|
+
static size_t
|
|
42
|
+
ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
43
|
+
const ZSTD_hufCTablesMetadata_t* hufMetadata,
|
|
44
|
+
const BYTE* literals, size_t litSize,
|
|
45
|
+
void* dst, size_t dstSize,
|
|
46
|
+
const int bmi2, int writeEntropy, int* entropyWritten)
|
|
324
47
|
{
|
|
325
48
|
size_t const header = writeEntropy ? 200 : 0;
|
|
326
49
|
size_t const lhSize = 3 + (litSize >= (1 KB - header)) + (litSize >= (16 KB - header));
|
|
@@ -331,8 +54,6 @@ static size_t ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
331
54
|
symbolEncodingType_e hType = writeEntropy ? hufMetadata->hType : set_repeat;
|
|
332
55
|
size_t cLitSize = 0;
|
|
333
56
|
|
|
334
|
-
(void)bmi2; /* TODO bmi2... */
|
|
335
|
-
|
|
336
57
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal (litSize=%zu, lhSize=%zu, writeEntropy=%d)", litSize, lhSize, writeEntropy);
|
|
337
58
|
|
|
338
59
|
*entropyWritten = 0;
|
|
@@ -354,9 +75,9 @@ static size_t ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
354
75
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal (hSize=%zu)", hufMetadata->hufDesSize);
|
|
355
76
|
}
|
|
356
77
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
: HUF_compress4X_usingCTable(op, oend-op, literals, litSize, hufTable);
|
|
78
|
+
{ int const flags = bmi2 ? HUF_flags_bmi2 : 0;
|
|
79
|
+
const size_t cSize = singleStream ? HUF_compress1X_usingCTable(op, oend-op, literals, litSize, hufTable, flags)
|
|
80
|
+
: HUF_compress4X_usingCTable(op, oend-op, literals, litSize, hufTable, flags);
|
|
360
81
|
op += cSize;
|
|
361
82
|
cLitSize += cSize;
|
|
362
83
|
if (cSize == 0 || ERR_isError(cSize)) {
|
|
@@ -404,12 +125,17 @@ static size_t ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
404
125
|
return op-ostart;
|
|
405
126
|
}
|
|
406
127
|
|
|
407
|
-
static size_t
|
|
128
|
+
static size_t
|
|
129
|
+
ZSTD_seqDecompressedSize(seqStore_t const* seqStore,
|
|
130
|
+
const seqDef* sequences, size_t nbSeq,
|
|
131
|
+
size_t litSize, int lastSequence)
|
|
132
|
+
{
|
|
408
133
|
const seqDef* const sstart = sequences;
|
|
409
134
|
const seqDef* const send = sequences + nbSeq;
|
|
410
135
|
const seqDef* sp = sstart;
|
|
411
136
|
size_t matchLengthSum = 0;
|
|
412
137
|
size_t litLengthSum = 0;
|
|
138
|
+
(void)(litLengthSum); /* suppress unused variable warning on some environments */
|
|
413
139
|
while (send-sp > 0) {
|
|
414
140
|
ZSTD_sequenceLength const seqLen = ZSTD_getSequenceLength(seqStore, sp);
|
|
415
141
|
litLengthSum += seqLen.litLength;
|
|
@@ -433,13 +159,14 @@ static size_t ZSTD_seqDecompressedSize(seqStore_t const* seqStore, const seqDef*
|
|
|
433
159
|
* @return : compressed size of sequences section of a sub-block
|
|
434
160
|
* Or 0 if it is unable to compress
|
|
435
161
|
* Or error code. */
|
|
436
|
-
static size_t
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
162
|
+
static size_t
|
|
163
|
+
ZSTD_compressSubBlock_sequences(const ZSTD_fseCTables_t* fseTables,
|
|
164
|
+
const ZSTD_fseCTablesMetadata_t* fseMetadata,
|
|
165
|
+
const seqDef* sequences, size_t nbSeq,
|
|
166
|
+
const BYTE* llCode, const BYTE* mlCode, const BYTE* ofCode,
|
|
167
|
+
const ZSTD_CCtx_params* cctxParams,
|
|
168
|
+
void* dst, size_t dstCapacity,
|
|
169
|
+
const int bmi2, int writeEntropy, int* entropyWritten)
|
|
443
170
|
{
|
|
444
171
|
const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN;
|
|
445
172
|
BYTE* const ostart = (BYTE*)dst;
|
|
@@ -602,7 +329,7 @@ static size_t ZSTD_estimateSubBlockSize_literal(const BYTE* literals, size_t lit
|
|
|
602
329
|
static size_t ZSTD_estimateSubBlockSize_symbolType(symbolEncodingType_e type,
|
|
603
330
|
const BYTE* codeTable, unsigned maxCode,
|
|
604
331
|
size_t nbSeq, const FSE_CTable* fseCTable,
|
|
605
|
-
const
|
|
332
|
+
const U8* additionalBits,
|
|
606
333
|
short const* defaultNorm, U32 defaultNormLog, U32 defaultMax,
|
|
607
334
|
void* workspace, size_t wkspSize)
|
|
608
335
|
{
|
|
@@ -643,8 +370,9 @@ static size_t ZSTD_estimateSubBlockSize_sequences(const BYTE* ofCodeTable,
|
|
|
643
370
|
void* workspace, size_t wkspSize,
|
|
644
371
|
int writeEntropy)
|
|
645
372
|
{
|
|
646
|
-
size_t sequencesSectionHeaderSize = 3; /* Use hard coded size of 3 bytes */
|
|
373
|
+
size_t const sequencesSectionHeaderSize = 3; /* Use hard coded size of 3 bytes */
|
|
647
374
|
size_t cSeqSizeEstimate = 0;
|
|
375
|
+
if (nbSeq == 0) return sequencesSectionHeaderSize;
|
|
648
376
|
cSeqSizeEstimate += ZSTD_estimateSubBlockSize_symbolType(fseMetadata->ofType, ofCodeTable, MaxOff,
|
|
649
377
|
nbSeq, fseTables->offcodeCTable, NULL,
|
|
650
378
|
OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
|
@@ -751,7 +479,7 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
|
|
|
751
479
|
/* I think there is an optimization opportunity here.
|
|
752
480
|
* Calling ZSTD_estimateSubBlockSize for every sequence can be wasteful
|
|
753
481
|
* since it recalculates estimate from scratch.
|
|
754
|
-
* For example, it would recount literal distribution and symbol codes
|
|
482
|
+
* For example, it would recount literal distribution and symbol codes every time.
|
|
755
483
|
*/
|
|
756
484
|
cBlockSizeEstimate = ZSTD_estimateSubBlockSize(lp, litSize, ofCodePtr, llCodePtr, mlCodePtr, seqCount,
|
|
757
485
|
&nextCBlock->entropy, entropyMetadata,
|
|
@@ -815,7 +543,7 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
|
|
|
815
543
|
repcodes_t rep;
|
|
816
544
|
ZSTD_memcpy(&rep, prevCBlock->rep, sizeof(rep));
|
|
817
545
|
for (seq = sstart; seq < sp; ++seq) {
|
|
818
|
-
|
|
546
|
+
ZSTD_updateRep(rep.rep, seq->offBase, ZSTD_getSequenceLength(seqStorePtr, seq).litLength == 0);
|
|
819
547
|
}
|
|
820
548
|
ZSTD_memcpy(nextCBlock->rep, &rep, sizeof(rep));
|
|
821
549
|
}
|
|
@@ -830,7 +558,7 @@ size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
|
|
|
830
558
|
unsigned lastBlock) {
|
|
831
559
|
ZSTD_entropyCTablesMetadata_t entropyMetadata;
|
|
832
560
|
|
|
833
|
-
FORWARD_IF_ERROR(
|
|
561
|
+
FORWARD_IF_ERROR(ZSTD_buildBlockEntropyStats(&zc->seqStore,
|
|
834
562
|
&zc->blockState.prevCBlock->entropy,
|
|
835
563
|
&zc->blockState.nextCBlock->entropy,
|
|
836
564
|
&zc->appliedParams,
|