multi_compress 0.6.1 → 0.7.0
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/CHANGELOG.md +41 -0
- data/GET_STARTED.md +4 -2
- data/README.md +1 -1
- data/THIRD_PARTY_NOTICES.md +2 -2
- data/ext/multi_compress/exports.darwin +1 -0
- data/ext/multi_compress/exports.map +4 -0
- data/ext/multi_compress/extconf.rb +20 -0
- data/ext/multi_compress/multi_compress.c +123 -73
- data/ext/multi_compress/vendor/.vendored +1 -1
- data/ext/multi_compress/vendor/zstd/lib/BUCK +10 -5
- data/ext/multi_compress/vendor/zstd/lib/README.md +25 -5
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +6 -2
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +3 -3
- data/ext/multi_compress/vendor/zstd/lib/common/bmi2.h +40 -0
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +37 -11
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +7 -6
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +4 -3
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +16 -19
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +31 -0
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +16 -2
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +9 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +4 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +300 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +4 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +4 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +775 -214
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +35 -6
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +9 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +14 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +49 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +11 -11
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +16 -18
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +64 -39
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +30 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +78 -64
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +182 -18
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +59 -27
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +194 -93
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +225 -85
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +19 -2
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +136 -91
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +77 -77
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +48 -42
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +18 -14
- data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +66 -20
- data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +10 -6
- data/ext/multi_compress/vendor/zstd/lib/install_oses.mk +17 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +10 -8
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +5 -364
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +4 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +7 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +8 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +1 -0
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +8 -7
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +1 -0
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +0 -21
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +209 -112
- data/lib/multi_compress/reader/read_operations.rb +2 -0
- data/lib/multi_compress/version.rb +1 -1
- data/multi_compress.gemspec +2 -0
- data/mysql_udf/Makefile +12 -5
- data/mysql_udf/multi_compress_mysql.exports +6 -0
- data/postgres_extension/Makefile +2 -1
- data/postgres_extension/test/run_e2e.sh +28 -10
- metadata +6 -5
- data/ext/multi_compress/vendor/lz4/lib/Makefile +0 -244
- data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +0 -63
- data/ext/multi_compress/vendor/zstd/lib/Makefile +0 -389
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +0 -48
|
@@ -141,6 +141,10 @@ MEM_STATIC ZSTD_SequenceLength ZSTD_getSequenceLength(SeqStore_t const* seqStore
|
|
|
141
141
|
|
|
142
142
|
const SeqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
|
143
143
|
int ZSTD_seqToCodes(const SeqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
|
144
|
+
/* Derives the half-open sequence range [startIdx, endIdx). */
|
|
145
|
+
void ZSTD_deriveSeqStoreChunk(SeqStore_t* resultSeqStore,
|
|
146
|
+
const SeqStore_t* originalSeqStore,
|
|
147
|
+
size_t startIdx, size_t endIdx);
|
|
144
148
|
|
|
145
149
|
|
|
146
150
|
/***********************************************
|
|
@@ -465,14 +469,19 @@ typedef struct {
|
|
|
465
469
|
SeqStore_t currSeqStore;
|
|
466
470
|
SeqStore_t nextSeqStore;
|
|
467
471
|
|
|
468
|
-
U32 partitions[ZSTD_MAX_NB_BLOCK_SPLITS];
|
|
472
|
+
U32 partitions[ZSTD_MAX_NB_BLOCK_SPLITS + 1]; /* splits, followed by the end of the block */
|
|
469
473
|
ZSTD_entropyCTablesMetadata_t entropyMetadata;
|
|
470
474
|
} ZSTD_blockSplitCtx;
|
|
471
475
|
|
|
472
476
|
struct ZSTD_CCtx_s {
|
|
473
477
|
ZSTD_compressionStage_e stage;
|
|
474
478
|
int cParamsChanged; /* == 1 if cParams(except wlog) or compression level are changed in requestedParams. Triggers transmission of new params to ZSTDMT (if available) then reset to 0. */
|
|
475
|
-
|
|
479
|
+
#if DYNAMIC_BMI2
|
|
480
|
+
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise when CPU state
|
|
481
|
+
* is cached per context. Never read this directly: use ZSTD_CCtx_get_bmi2(),
|
|
482
|
+
* which also handles builds
|
|
483
|
+
* where cached CPU state is not used. */
|
|
484
|
+
#endif
|
|
476
485
|
ZSTD_CCtx_params requestedParams;
|
|
477
486
|
ZSTD_CCtx_params appliedParams;
|
|
478
487
|
ZSTD_CCtx_params simpleApiParams; /* Param storage used by the simple API - not sticky. Must only be used in top-level simple API functions for storage. */
|
|
@@ -545,6 +554,26 @@ struct ZSTD_CCtx_s {
|
|
|
545
554
|
size_t extSeqBufCapacity;
|
|
546
555
|
};
|
|
547
556
|
|
|
557
|
+
/**
|
|
558
|
+
* @returns the cached per-context BMI2 dispatch hint, or 0 when the build does
|
|
559
|
+
* not use cached CPU state.
|
|
560
|
+
*
|
|
561
|
+
* Beware: this is *not* a "does the CPU support BMI2" test. When BMI2 is enabled
|
|
562
|
+
* at compile time, DYNAMIC_BMI2 is 0: the whole library is already compiled with
|
|
563
|
+
* BMI2, no separate variant exists, and this returns 0 even though the CPU does
|
|
564
|
+
* support BMI2. Only use the result as a dispatch hint passed to a lower-level
|
|
565
|
+
* BMI2/default selector. Integrations may ignore the cached hint and consult
|
|
566
|
+
* their own CPU-feature policy at that selector.
|
|
567
|
+
*/
|
|
568
|
+
MEM_STATIC int ZSTD_CCtx_get_bmi2(const struct ZSTD_CCtx_s* cctx) {
|
|
569
|
+
#if DYNAMIC_BMI2
|
|
570
|
+
return cctx->bmi2;
|
|
571
|
+
#else
|
|
572
|
+
(void)cctx;
|
|
573
|
+
return 0;
|
|
574
|
+
#endif
|
|
575
|
+
}
|
|
576
|
+
|
|
548
577
|
typedef enum { ZSTD_dtlm_fast, ZSTD_dtlm_full } ZSTD_dictTableLoadMethod_e;
|
|
549
578
|
typedef enum { ZSTD_tfp_forCCtx, ZSTD_tfp_forCDict } ZSTD_tableFillPurpose_e;
|
|
550
579
|
|
|
@@ -707,7 +736,7 @@ ZSTD_safecopyLiterals(BYTE* op, BYTE const* ip, BYTE const* const iend, BYTE con
|
|
|
707
736
|
{
|
|
708
737
|
assert(iend > ilimit_w);
|
|
709
738
|
if (ip <= ilimit_w) {
|
|
710
|
-
ZSTD_wildcopy(op, ip, ilimit_w - ip, ZSTD_no_overlap);
|
|
739
|
+
ZSTD_wildcopy(op, ip, (size_t)(ilimit_w - ip), ZSTD_no_overlap);
|
|
711
740
|
op += ilimit_w - ip;
|
|
712
741
|
ip = ilimit_w;
|
|
713
742
|
}
|
|
@@ -800,7 +829,7 @@ ZSTD_storeSeq(SeqStore_t* seqStorePtr,
|
|
|
800
829
|
ZSTD_STATIC_ASSERT(WILDCOPY_OVERLENGTH >= 16);
|
|
801
830
|
ZSTD_copy16(seqStorePtr->lit, literals);
|
|
802
831
|
if (litLength > 16) {
|
|
803
|
-
ZSTD_wildcopy(seqStorePtr->lit+16, literals+16,
|
|
832
|
+
ZSTD_wildcopy(seqStorePtr->lit+16, literals+16, litLength-16, ZSTD_no_overlap);
|
|
804
833
|
}
|
|
805
834
|
} else {
|
|
806
835
|
ZSTD_safecopyLiterals(seqStorePtr->lit, literals, litEnd, litLimit_w);
|
|
@@ -1516,14 +1545,14 @@ void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
|
|
1516
1545
|
|
|
1517
1546
|
typedef struct {
|
|
1518
1547
|
U32 idx; /* Index in array of ZSTD_Sequence */
|
|
1519
|
-
|
|
1548
|
+
U64 posInSequence; /* Position within sequence at idx. The sum of its lengths may exceed U32. */
|
|
1520
1549
|
size_t posInSrc; /* Number of bytes given by sequences provided so far */
|
|
1521
1550
|
} ZSTD_SequencePosition;
|
|
1522
1551
|
|
|
1523
1552
|
/* for benchmark */
|
|
1524
1553
|
size_t ZSTD_convertBlockSequences(ZSTD_CCtx* cctx,
|
|
1525
1554
|
const ZSTD_Sequence* const inSeqs, size_t nbSequences,
|
|
1526
|
-
int
|
|
1555
|
+
int repcodeResolution);
|
|
1527
1556
|
|
|
1528
1557
|
typedef struct {
|
|
1529
1558
|
size_t nbSequences;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
/*-*************************************
|
|
12
12
|
* Dependencies
|
|
13
13
|
***************************************/
|
|
14
|
+
#include "../common/bmi2.h"
|
|
14
15
|
#include "zstd_compress_sequences.h"
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -300,6 +301,7 @@ ZSTD_encodeSequences_body(
|
|
|
300
301
|
FSE_CState_t stateOffsetBits;
|
|
301
302
|
FSE_CState_t stateLitLength;
|
|
302
303
|
|
|
304
|
+
assert(MEM_32bits() || !longOffsets);
|
|
303
305
|
RETURN_ERROR_IF(
|
|
304
306
|
ERR_isError(BIT_initCStream(&blockStream, dst, dstCapacity)),
|
|
305
307
|
dstSize_tooSmall, "not enough space remaining");
|
|
@@ -315,7 +317,7 @@ ZSTD_encodeSequences_body(
|
|
|
315
317
|
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
|
316
318
|
BIT_addBits(&blockStream, sequences[nbSeq-1].mlBase, ML_bits[mlCodeTable[nbSeq-1]]);
|
|
317
319
|
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
|
318
|
-
if (longOffsets) {
|
|
320
|
+
if (MEM_32bits() && longOffsets) {
|
|
319
321
|
U32 const ofBits = ofCodeTable[nbSeq-1];
|
|
320
322
|
unsigned const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
|
321
323
|
if (extraBits) {
|
|
@@ -353,7 +355,7 @@ ZSTD_encodeSequences_body(
|
|
|
353
355
|
if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream);
|
|
354
356
|
BIT_addBits(&blockStream, sequences[n].mlBase, mlBits);
|
|
355
357
|
if (MEM_32bits() || (ofBits+mlBits+llBits > 56)) BIT_flushBits(&blockStream);
|
|
356
|
-
if (longOffsets) {
|
|
358
|
+
if (MEM_32bits() && longOffsets) {
|
|
357
359
|
unsigned const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
|
358
360
|
if (extraBits) {
|
|
359
361
|
BIT_addBits(&blockStream, sequences[n].offBase, extraBits);
|
|
@@ -414,6 +416,10 @@ ZSTD_encodeSequences_bmi2(
|
|
|
414
416
|
sequences, nbSeq, longOffsets);
|
|
415
417
|
}
|
|
416
418
|
|
|
419
|
+
#else
|
|
420
|
+
|
|
421
|
+
#define ZSTD_encodeSequences_bmi2 ZSTD_encodeSequences_default
|
|
422
|
+
|
|
417
423
|
#endif
|
|
418
424
|
|
|
419
425
|
size_t ZSTD_encodeSequences(
|
|
@@ -424,15 +430,13 @@ size_t ZSTD_encodeSequences(
|
|
|
424
430
|
SeqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2)
|
|
425
431
|
{
|
|
426
432
|
DEBUGLOG(5, "ZSTD_encodeSequences: dstCapacity = %u", (unsigned)dstCapacity);
|
|
427
|
-
|
|
428
|
-
if (bmi2) {
|
|
433
|
+
if (ZSTD_USE_BMI2(bmi2)) {
|
|
429
434
|
return ZSTD_encodeSequences_bmi2(dst, dstCapacity,
|
|
430
435
|
CTable_MatchLength, mlCodeTable,
|
|
431
436
|
CTable_OffsetBits, ofCodeTable,
|
|
432
437
|
CTable_LitLength, llCodeTable,
|
|
433
438
|
sequences, nbSeq, longOffsets);
|
|
434
439
|
}
|
|
435
|
-
#endif
|
|
436
440
|
(void)bmi2;
|
|
437
441
|
return ZSTD_encodeSequences_default(dst, dstCapacity,
|
|
438
442
|
CTable_MatchLength, mlCodeTable,
|
|
@@ -49,7 +49,7 @@ ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
49
49
|
size_t const lhSize = 3 + (litSize >= (1 KB - header)) + (litSize >= (16 KB - header));
|
|
50
50
|
BYTE* const ostart = (BYTE*)dst;
|
|
51
51
|
BYTE* const oend = ostart + dstSize;
|
|
52
|
-
BYTE* op = ostart
|
|
52
|
+
BYTE* op = ostart;
|
|
53
53
|
U32 const singleStream = lhSize == 3;
|
|
54
54
|
SymbolEncodingType_e hType = writeEntropy ? hufMetadata->hType : set_repeat;
|
|
55
55
|
size_t cLitSize = 0;
|
|
@@ -62,13 +62,18 @@ ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
62
62
|
return ZSTD_noCompressLiterals(dst, dstSize, literals, litSize);
|
|
63
63
|
} else if (hufMetadata->hType == set_rle) {
|
|
64
64
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal using rle literal");
|
|
65
|
+
RETURN_ERROR_IF(dstSize < 4, dstSize_tooSmall, "");
|
|
65
66
|
return ZSTD_compressRleLiteralsBlock(dst, dstSize, literals, litSize);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
assert(litSize > 0);
|
|
69
70
|
assert(hufMetadata->hType == set_compressed || hufMetadata->hType == set_repeat);
|
|
70
71
|
|
|
72
|
+
RETURN_ERROR_IF(dstSize < lhSize, dstSize_tooSmall, "");
|
|
73
|
+
op += lhSize;
|
|
71
74
|
if (writeEntropy && hufMetadata->hType == set_compressed) {
|
|
75
|
+
RETURN_ERROR_IF(hufMetadata->hufDesSize > (size_t)(oend-op),
|
|
76
|
+
dstSize_tooSmall, "");
|
|
72
77
|
ZSTD_memcpy(op, hufMetadata->hufDesBuffer, hufMetadata->hufDesSize);
|
|
73
78
|
op += hufMetadata->hufDesSize;
|
|
74
79
|
cLitSize += hufMetadata->hufDesSize;
|
|
@@ -78,12 +83,12 @@ ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
|
|
78
83
|
{ int const flags = bmi2 ? HUF_flags_bmi2 : 0;
|
|
79
84
|
const size_t cSize = singleStream ? HUF_compress1X_usingCTable(op, (size_t)(oend-op), literals, litSize, hufTable, flags)
|
|
80
85
|
: HUF_compress4X_usingCTable(op, (size_t)(oend-op), literals, litSize, hufTable, flags);
|
|
81
|
-
op += cSize;
|
|
82
|
-
cLitSize += cSize;
|
|
83
86
|
if (cSize == 0 || ERR_isError(cSize)) {
|
|
84
87
|
DEBUGLOG(5, "Failed to write entropy tables %s", ZSTD_getErrorName(cSize));
|
|
85
88
|
return 0;
|
|
86
89
|
}
|
|
90
|
+
op += cSize;
|
|
91
|
+
cLitSize += cSize;
|
|
87
92
|
/* If we expand and we aren't writing a header then emit uncompressed */
|
|
88
93
|
if (!writeEntropy && cLitSize >= litSize) {
|
|
89
94
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal using raw literal because uncompressible");
|
|
@@ -200,6 +205,8 @@ ZSTD_compressSubBlock_sequences(const ZSTD_fseCTables_t* fseTables,
|
|
|
200
205
|
const U32 Offtype = fseMetadata->ofType;
|
|
201
206
|
const U32 MLtype = fseMetadata->mlType;
|
|
202
207
|
DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (fseTablesSize=%zu)", fseMetadata->fseTablesSize);
|
|
208
|
+
RETURN_ERROR_IF(fseMetadata->fseTablesSize > (size_t)(oend-op),
|
|
209
|
+
dstSize_tooSmall, "");
|
|
203
210
|
*seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2));
|
|
204
211
|
ZSTD_memcpy(op, fseMetadata->fseTablesBuffer, fseMetadata->fseTablesSize);
|
|
205
212
|
op += fseMetadata->fseTablesSize;
|
|
@@ -274,9 +281,11 @@ static size_t ZSTD_compressSubBlock(const ZSTD_entropyCTables_t* entropy,
|
|
|
274
281
|
{
|
|
275
282
|
BYTE* const ostart = (BYTE*)dst;
|
|
276
283
|
BYTE* const oend = ostart + dstCapacity;
|
|
277
|
-
BYTE* op = ostart
|
|
284
|
+
BYTE* op = ostart;
|
|
278
285
|
DEBUGLOG(5, "ZSTD_compressSubBlock (litSize=%zu, nbSeq=%zu, writeLitEntropy=%d, writeSeqEntropy=%d, lastBlock=%d)",
|
|
279
286
|
litSize, nbSeq, writeLitEntropy, writeSeqEntropy, lastBlock);
|
|
287
|
+
RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize, dstSize_tooSmall, "");
|
|
288
|
+
op += ZSTD_blockHeaderSize;
|
|
280
289
|
{ size_t cLitSize = ZSTD_compressSubBlock_literal((const HUF_CElt*)entropy->huf.CTable,
|
|
281
290
|
&entropyMetadata->hufMetadata, literals, litSize,
|
|
282
291
|
op, (size_t)(oend-op),
|
|
@@ -683,6 +692,6 @@ size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
|
|
|
683
692
|
&zc->appliedParams,
|
|
684
693
|
dst, dstCapacity,
|
|
685
694
|
src, srcSize,
|
|
686
|
-
zc
|
|
695
|
+
ZSTD_CCtx_get_bmi2(zc), lastBlock,
|
|
687
696
|
zc->tmpWorkspace, zc->tmpWkspSize /* statically allocated in resetCCtx */);
|
|
688
697
|
}
|
|
@@ -375,8 +375,8 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
|
|
|
375
375
|
/* init */
|
|
376
376
|
ip += (dictAndPrefixLength == 0);
|
|
377
377
|
|
|
378
|
-
/*
|
|
379
|
-
* disabling. */
|
|
378
|
+
/* Dictionary repcodes are validated when the CDict is attached.
|
|
379
|
+
* dictMatchState repCode checks don't handle repCode == 0 disabling. */
|
|
380
380
|
assert(offset_1 <= dictAndPrefixLength);
|
|
381
381
|
assert(offset_2 <= dictAndPrefixLength);
|
|
382
382
|
|
|
@@ -532,8 +532,8 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
|
|
|
532
532
|
/* init */
|
|
533
533
|
DEBUGLOG(5, "ZSTD_compressBlock_fast_dictMatchState_generic");
|
|
534
534
|
ip0 += (dictAndPrefixLength == 0);
|
|
535
|
-
/*
|
|
536
|
-
* disabling. */
|
|
535
|
+
/* Dictionary repcodes are validated when the CDict is attached.
|
|
536
|
+
* dictMatchState repCode checks don't handle repCode == 0 disabling. */
|
|
537
537
|
assert(offset_1 <= dictAndPrefixLength);
|
|
538
538
|
assert(offset_2 <= dictAndPrefixLength);
|
|
539
539
|
|
|
@@ -1050,6 +1050,44 @@ ZSTD_row_getNEONMask(const U32 rowEntries, const BYTE* const src, const BYTE tag
|
|
|
1050
1050
|
}
|
|
1051
1051
|
}
|
|
1052
1052
|
#endif
|
|
1053
|
+
#if defined(ZSTD_ARCH_RISCV_RVV) && (__riscv_xlen == 64)
|
|
1054
|
+
FORCE_INLINE_TEMPLATE ZSTD_VecMask
|
|
1055
|
+
ZSTD_row_getRVVMask(int rowEntries, const BYTE* const src, const BYTE tag, const U32 head)
|
|
1056
|
+
{
|
|
1057
|
+
ZSTD_VecMask matches;
|
|
1058
|
+
size_t vl;
|
|
1059
|
+
|
|
1060
|
+
if (rowEntries == 16) {
|
|
1061
|
+
vl = __riscv_vsetvl_e8m1(16);
|
|
1062
|
+
{
|
|
1063
|
+
vuint8m1_t chunk = __riscv_vle8_v_u8m1(src, vl);
|
|
1064
|
+
vbool8_t mask = __riscv_vmseq_vx_u8m1_b8(chunk, tag, vl);
|
|
1065
|
+
vuint16m1_t mask_u16 = __riscv_vreinterpret_v_b8_u16m1(mask);
|
|
1066
|
+
matches = __riscv_vmv_x_s_u16m1_u16(mask_u16);
|
|
1067
|
+
return ZSTD_rotateRight_U16((U16)matches, head);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
} else if (rowEntries == 32) {
|
|
1071
|
+
vl = __riscv_vsetvl_e8m2(32);
|
|
1072
|
+
{
|
|
1073
|
+
vuint8m2_t chunk = __riscv_vle8_v_u8m2(src, vl);
|
|
1074
|
+
vbool4_t mask = __riscv_vmseq_vx_u8m2_b4(chunk, tag, vl);
|
|
1075
|
+
vuint32m1_t mask_u32 = __riscv_vreinterpret_v_b4_u32m1(mask);
|
|
1076
|
+
matches = __riscv_vmv_x_s_u32m1_u32(mask_u32);
|
|
1077
|
+
return ZSTD_rotateRight_U32((U32)matches, head);
|
|
1078
|
+
}
|
|
1079
|
+
} else { // rowEntries = 64
|
|
1080
|
+
vl = __riscv_vsetvl_e8m4(64);
|
|
1081
|
+
{
|
|
1082
|
+
vuint8m4_t chunk = __riscv_vle8_v_u8m4(src, vl);
|
|
1083
|
+
vbool2_t mask = __riscv_vmseq_vx_u8m4_b2(chunk, tag, vl);
|
|
1084
|
+
vuint64m1_t mask_u64 = __riscv_vreinterpret_v_b2_u64m1(mask);
|
|
1085
|
+
matches = __riscv_vmv_x_s_u64m1_u64(mask_u64);
|
|
1086
|
+
return ZSTD_rotateRight_U64(matches, head);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
#endif
|
|
1053
1091
|
|
|
1054
1092
|
/* Returns a ZSTD_VecMask (U64) that has the nth group (determined by
|
|
1055
1093
|
* ZSTD_row_matchMaskGroupWidth) of bits set to 1 if the newly-computed "tag"
|
|
@@ -1069,14 +1107,20 @@ ZSTD_row_getMatchMask(const BYTE* const tagRow, const BYTE tag, const U32 headGr
|
|
|
1069
1107
|
|
|
1070
1108
|
return ZSTD_row_getSSEMask(rowEntries / 16, src, tag, headGrouped);
|
|
1071
1109
|
|
|
1072
|
-
#
|
|
1110
|
+
#elif defined(ZSTD_ARCH_RISCV_RVV) && (__riscv_xlen == 64)
|
|
1111
|
+
|
|
1112
|
+
return ZSTD_row_getRVVMask(rowEntries, src, tag, headGrouped);
|
|
1073
1113
|
|
|
1074
|
-
#
|
|
1114
|
+
#else
|
|
1115
|
+
|
|
1116
|
+
#if defined(ZSTD_ARCH_ARM_NEON)
|
|
1075
1117
|
/* This NEON path only works for little endian - otherwise use SWAR below */
|
|
1076
1118
|
if (MEM_isLittleEndian()) {
|
|
1077
1119
|
return ZSTD_row_getNEONMask(rowEntries, src, tag, headGrouped);
|
|
1078
1120
|
}
|
|
1079
|
-
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
#endif
|
|
1080
1124
|
/* SWAR */
|
|
1081
1125
|
{ const int chunkSize = sizeof(size_t);
|
|
1082
1126
|
const size_t shiftAmount = ((chunkSize * 8) - chunkSize);
|
|
@@ -1557,8 +1601,8 @@ size_t ZSTD_compressBlock_lazy_generic(
|
|
|
1557
1601
|
if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
|
|
1558
1602
|
}
|
|
1559
1603
|
if (isDxS) {
|
|
1560
|
-
/*
|
|
1561
|
-
* disabling. */
|
|
1604
|
+
/* Dictionary repcodes are validated when the CDict is attached.
|
|
1605
|
+
* dictMatchState repCode checks don't handle repCode == 0 disabling. */
|
|
1562
1606
|
assert(offset_1 <= dictAndPrefixLength);
|
|
1563
1607
|
assert(offset_2 <= dictAndPrefixLength);
|
|
1564
1608
|
}
|
|
@@ -20,11 +20,6 @@
|
|
|
20
20
|
#define LDM_MIN_MATCH_LENGTH 64
|
|
21
21
|
#define LDM_HASH_RLOG 7
|
|
22
22
|
|
|
23
|
-
typedef struct {
|
|
24
|
-
U64 rolling;
|
|
25
|
-
U64 stopMask;
|
|
26
|
-
} ldmRollingHashState_t;
|
|
27
|
-
|
|
28
23
|
/** ZSTD_ldm_gear_init():
|
|
29
24
|
*
|
|
30
25
|
* Initializes the rolling hash state such that it will honor the
|
|
@@ -62,8 +57,8 @@ static void ZSTD_ldm_gear_init(ldmRollingHashState_t* state, ldmParams_t const*
|
|
|
62
57
|
* splits. This effectively resets the hash state. This is used when skipping
|
|
63
58
|
* over data, either at the beginning of a block, or skipping sections.
|
|
64
59
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
|
|
61
|
+
BYTE const* data, size_t minMatchLength)
|
|
67
62
|
{
|
|
68
63
|
U64 hash = state->rolling;
|
|
69
64
|
size_t n = 0;
|
|
@@ -82,6 +77,7 @@ static void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
|
|
|
82
77
|
GEAR_ITER_ONCE();
|
|
83
78
|
}
|
|
84
79
|
#undef GEAR_ITER_ONCE
|
|
80
|
+
state->rolling = hash;
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
/** ZSTD_ldm_gear_feed():
|
|
@@ -93,9 +89,9 @@ static void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
|
|
|
93
89
|
*
|
|
94
90
|
* Precondition: The splits array must not be full.
|
|
95
91
|
* Returns: The number of bytes processed. */
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
size_t ZSTD_ldm_gear_feed(ldmRollingHashState_t* state,
|
|
93
|
+
BYTE const* data, size_t size,
|
|
94
|
+
size_t* splits, unsigned* numSplits)
|
|
99
95
|
{
|
|
100
96
|
size_t n;
|
|
101
97
|
U64 hash, mask;
|
|
@@ -152,7 +148,11 @@ void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
|
|
152
148
|
}
|
|
153
149
|
}
|
|
154
150
|
if (params->hashLog == 0) {
|
|
155
|
-
|
|
151
|
+
if (params->windowLog <= params->hashRateLog) {
|
|
152
|
+
params->hashLog = ZSTD_HASHLOG_MIN;
|
|
153
|
+
} else {
|
|
154
|
+
params->hashLog = BOUNDED(ZSTD_HASHLOG_MIN, params->windowLog - params->hashRateLog, ZSTD_HASHLOG_MAX);
|
|
155
|
+
}
|
|
156
156
|
}
|
|
157
157
|
if (params->minMatchLength == 0) {
|
|
158
158
|
params->minMatchLength = LDM_MIN_MATCH_LENGTH;
|
|
@@ -20,6 +20,17 @@
|
|
|
20
20
|
|
|
21
21
|
#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
|
|
22
22
|
|
|
23
|
+
typedef struct {
|
|
24
|
+
U64 rolling;
|
|
25
|
+
U64 stopMask;
|
|
26
|
+
} ldmRollingHashState_t;
|
|
27
|
+
|
|
28
|
+
void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
|
|
29
|
+
BYTE const* data, size_t minMatchLength);
|
|
30
|
+
size_t ZSTD_ldm_gear_feed(ldmRollingHashState_t* state,
|
|
31
|
+
BYTE const* data, size_t size,
|
|
32
|
+
size_t* splits, unsigned* numSplits);
|
|
33
|
+
|
|
23
34
|
void ZSTD_ldm_fillHashTable(
|
|
24
35
|
ldmState_t* state, const BYTE* ip,
|
|
25
36
|
const BYTE* iend, ldmParams_t const* params);
|
|
@@ -130,6 +130,16 @@ static U32 ZSTD_scaleStats(unsigned* table, U32 lastEltIndex, U32 logTarget)
|
|
|
130
130
|
return ZSTD_downscaleStats(table, lastEltIndex, ZSTD_highbit32(factor), base_1guaranteed);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/* Dictionary tables can assign costs at or above the frequency scale:
|
|
134
|
+
* absent FSE symbols cost tableLog+1, and the Huffman reader accepts tables
|
|
135
|
+
* deeper than LitHufLog. Keep a minimum frequency of 1 without underflowing
|
|
136
|
+
* the shift. A zero cost also retains its historical minimum frequency. */
|
|
137
|
+
static U32 ZSTD_freqFromBitCost(U32 bitCost, U32 scaleLog)
|
|
138
|
+
{
|
|
139
|
+
assert(scaleLog < 31);
|
|
140
|
+
return bitCost > 0 && bitCost < scaleLog ? 1U << (scaleLog - bitCost) : 1;
|
|
141
|
+
}
|
|
142
|
+
|
|
133
143
|
/* ZSTD_rescaleFreqs() :
|
|
134
144
|
* if first block (detected by optPtr->litLengthSum == 0) : init statistics
|
|
135
145
|
* take hints from dictionary if there is one
|
|
@@ -168,8 +178,7 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
|
|
|
168
178
|
for (lit=0; lit<=MaxLit; lit++) {
|
|
169
179
|
U32 const scaleLog = 11; /* scale to 2K */
|
|
170
180
|
U32 const bitCost = HUF_getNbBitsFromCTable(optPtr->symbolCosts->huf.CTable, lit);
|
|
171
|
-
|
|
172
|
-
optPtr->litFreq[lit] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
|
|
181
|
+
optPtr->litFreq[lit] = ZSTD_freqFromBitCost(bitCost, scaleLog);
|
|
173
182
|
optPtr->litSum += optPtr->litFreq[lit];
|
|
174
183
|
} }
|
|
175
184
|
|
|
@@ -180,8 +189,7 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
|
|
|
180
189
|
for (ll=0; ll<=MaxLL; ll++) {
|
|
181
190
|
U32 const scaleLog = 10; /* scale to 1K */
|
|
182
191
|
U32 const bitCost = FSE_getMaxNbBits(llstate.symbolTT, ll);
|
|
183
|
-
|
|
184
|
-
optPtr->litLengthFreq[ll] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
|
|
192
|
+
optPtr->litLengthFreq[ll] = ZSTD_freqFromBitCost(bitCost, scaleLog);
|
|
185
193
|
optPtr->litLengthSum += optPtr->litLengthFreq[ll];
|
|
186
194
|
} }
|
|
187
195
|
|
|
@@ -192,8 +200,7 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
|
|
|
192
200
|
for (ml=0; ml<=MaxML; ml++) {
|
|
193
201
|
U32 const scaleLog = 10;
|
|
194
202
|
U32 const bitCost = FSE_getMaxNbBits(mlstate.symbolTT, ml);
|
|
195
|
-
|
|
196
|
-
optPtr->matchLengthFreq[ml] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
|
|
203
|
+
optPtr->matchLengthFreq[ml] = ZSTD_freqFromBitCost(bitCost, scaleLog);
|
|
197
204
|
optPtr->matchLengthSum += optPtr->matchLengthFreq[ml];
|
|
198
205
|
} }
|
|
199
206
|
|
|
@@ -204,8 +211,7 @@ ZSTD_rescaleFreqs(optState_t* const optPtr,
|
|
|
204
211
|
for (of=0; of<=MaxOff; of++) {
|
|
205
212
|
U32 const scaleLog = 10;
|
|
206
213
|
U32 const bitCost = FSE_getMaxNbBits(ofstate.symbolTT, of);
|
|
207
|
-
|
|
208
|
-
optPtr->offCodeFreq[of] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
|
|
214
|
+
optPtr->offCodeFreq[of] = ZSTD_freqFromBitCost(bitCost, scaleLog);
|
|
209
215
|
optPtr->offCodeSum += optPtr->offCodeFreq[of];
|
|
210
216
|
} }
|
|
211
217
|
|
|
@@ -1382,16 +1388,8 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
|
|
|
1382
1388
|
assert(storeEnd < ZSTD_OPT_SIZE);
|
|
1383
1389
|
DEBUGLOG(6, "last stretch copied into pos=%u (llen=%u,mlen=%u,ofc=%u)",
|
|
1384
1390
|
storeEnd, lastStretch.litlen, lastStretch.mlen, lastStretch.off);
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
opt[storeEnd].litlen = lastStretch.litlen;
|
|
1388
|
-
opt[storeEnd].mlen = 0;
|
|
1389
|
-
storeStart = storeEnd-1;
|
|
1390
|
-
opt[storeStart] = lastStretch;
|
|
1391
|
-
} {
|
|
1392
|
-
opt[storeEnd] = lastStretch; /* note: litlen will be fixed */
|
|
1393
|
-
storeStart = storeEnd;
|
|
1394
|
-
}
|
|
1391
|
+
opt[storeEnd] = lastStretch; /* note: litlen will be fixed */
|
|
1392
|
+
storeStart = storeEnd;
|
|
1395
1393
|
while (1) {
|
|
1396
1394
|
ZSTD_optimal_t nextStretch = opt[stretchPos];
|
|
1397
1395
|
opt[storeStart].litlen = nextStretch.litlen;
|
|
@@ -90,7 +90,7 @@ ZSTD_GEN_RECORD_FINGERPRINT(11, 9)
|
|
|
90
90
|
ZSTD_GEN_RECORD_FINGERPRINT(43, 8)
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
static U64
|
|
93
|
+
static U64 ZSTD_abs64(S64 s64) { return (U64)((s64 < 0) ? -s64 : s64); }
|
|
94
94
|
|
|
95
95
|
static U64 fpDistance(const Fingerprint* fp1, const Fingerprint* fp2, unsigned hashLog)
|
|
96
96
|
{
|
|
@@ -99,7 +99,7 @@ static U64 fpDistance(const Fingerprint* fp1, const Fingerprint* fp2, unsigned h
|
|
|
99
99
|
assert(hashLog <= HASHLOG_MAX);
|
|
100
100
|
for (n = 0; n < ((size_t)1 << hashLog); n++) {
|
|
101
101
|
distance +=
|
|
102
|
-
|
|
102
|
+
ZSTD_abs64((S64)fp1->events[n] * (S64)fp2->nbEvents - (S64)fp2->events[n] * (S64)fp1->nbEvents);
|
|
103
103
|
}
|
|
104
104
|
return distance;
|
|
105
105
|
}
|
|
@@ -219,7 +219,7 @@ static size_t ZSTD_splitBlock_fromBorders(const void* blockStart, size_t blockSi
|
|
|
219
219
|
{ U64 const distFromBegin = fpDistance(&fpstats->pastEvents, middleEvents, 8);
|
|
220
220
|
U64 const distFromEnd = fpDistance(&fpstats->newEvents, middleEvents, 8);
|
|
221
221
|
U64 const minDistance = SEGMENT_SIZE * SEGMENT_SIZE / 3;
|
|
222
|
-
if (
|
|
222
|
+
if (ZSTD_abs64((S64)distFromBegin - (S64)distFromEnd) < minDistance)
|
|
223
223
|
return 64 KB;
|
|
224
224
|
return (distFromBegin > distFromEnd) ? 32 KB : 96 KB;
|
|
225
225
|
}
|