extzstd 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -14
- data/contrib/zstd/CHANGELOG +114 -56
- data/contrib/zstd/CONTRIBUTING.md +14 -0
- data/contrib/zstd/Makefile +37 -31
- data/contrib/zstd/README.md +6 -0
- data/contrib/zstd/appveyor.yml +4 -1
- data/contrib/zstd/lib/Makefile +231 -134
- data/contrib/zstd/lib/README.md +28 -0
- data/contrib/zstd/lib/common/bitstream.h +24 -15
- data/contrib/zstd/lib/common/compiler.h +116 -3
- data/contrib/zstd/lib/common/cpu.h +0 -2
- data/contrib/zstd/lib/common/debug.h +11 -18
- data/contrib/zstd/lib/common/entropy_common.c +188 -42
- data/contrib/zstd/lib/common/error_private.c +1 -0
- data/contrib/zstd/lib/common/error_private.h +1 -1
- data/contrib/zstd/lib/common/fse.h +38 -11
- data/contrib/zstd/lib/common/fse_decompress.c +123 -16
- data/contrib/zstd/lib/common/huf.h +26 -5
- data/contrib/zstd/lib/common/mem.h +66 -93
- data/contrib/zstd/lib/common/pool.c +22 -16
- data/contrib/zstd/lib/common/pool.h +1 -1
- data/contrib/zstd/lib/common/threading.c +6 -5
- data/contrib/zstd/lib/common/xxhash.c +18 -56
- data/contrib/zstd/lib/common/xxhash.h +1 -1
- data/contrib/zstd/lib/common/zstd_common.c +9 -9
- data/contrib/zstd/lib/common/zstd_deps.h +111 -0
- data/contrib/zstd/lib/common/zstd_errors.h +1 -0
- data/contrib/zstd/lib/common/zstd_internal.h +89 -58
- data/contrib/zstd/lib/compress/fse_compress.c +30 -23
- data/contrib/zstd/lib/compress/hist.c +26 -28
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +210 -95
- data/contrib/zstd/lib/compress/zstd_compress.c +1339 -409
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +119 -41
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +4 -4
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +17 -3
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +23 -19
- data/contrib/zstd/lib/compress/zstd_cwksp.h +60 -24
- data/contrib/zstd/lib/compress/zstd_double_fast.c +22 -22
- data/contrib/zstd/lib/compress/zstd_fast.c +19 -19
- data/contrib/zstd/lib/compress/zstd_lazy.c +351 -77
- data/contrib/zstd/lib/compress/zstd_lazy.h +20 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +59 -18
- data/contrib/zstd/lib/compress/zstd_ldm.h +6 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +190 -45
- data/contrib/zstd/lib/compress/zstdmt_compress.c +74 -406
- data/contrib/zstd/lib/compress/zstdmt_compress.h +26 -108
- data/contrib/zstd/lib/decompress/huf_decompress.c +302 -200
- data/contrib/zstd/lib/decompress/zstd_ddict.c +8 -8
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +125 -80
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +145 -37
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +5 -2
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +11 -10
- data/contrib/zstd/lib/dictBuilder/cover.c +29 -20
- data/contrib/zstd/lib/dictBuilder/cover.h +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +20 -19
- data/contrib/zstd/lib/dictBuilder/zdict.c +15 -16
- data/contrib/zstd/lib/dictBuilder/zdict.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +6 -2
- data/contrib/zstd/lib/legacy/zstd_v05.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +5 -1
- data/contrib/zstd/lib/libzstd.pc.in +3 -3
- data/contrib/zstd/lib/zstd.h +348 -47
- data/ext/extzstd.c +6 -0
- data/ext/extzstd.h +6 -0
- data/gemstub.rb +3 -21
- data/lib/extzstd.rb +0 -2
- data/lib/extzstd/version.rb +6 -1
- data/test/test_basic.rb +0 -5
- metadata +5 -4
@@ -14,7 +14,7 @@
|
|
14
14
|
/*-*******************************************************
|
15
15
|
* Dependencies
|
16
16
|
*********************************************************/
|
17
|
-
#include
|
17
|
+
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
|
18
18
|
#include "../common/compiler.h" /* prefetch */
|
19
19
|
#include "../common/cpu.h" /* bmi2 */
|
20
20
|
#include "../common/mem.h" /* low level memory routines */
|
@@ -44,7 +44,7 @@
|
|
44
44
|
/*_*******************************************************
|
45
45
|
* Memory operations
|
46
46
|
**********************************************************/
|
47
|
-
static void ZSTD_copy4(void* dst, const void* src) {
|
47
|
+
static void ZSTD_copy4(void* dst, const void* src) { ZSTD_memcpy(dst, src, 4); }
|
48
48
|
|
49
49
|
|
50
50
|
/*-*************************************************************
|
@@ -166,7 +166,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
|
166
166
|
dctx->litSize = litSize;
|
167
167
|
dctx->litEntropy = 1;
|
168
168
|
if (litEncType==set_compressed) dctx->HUFptr = dctx->entropy.hufTable;
|
169
|
-
|
169
|
+
ZSTD_memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH);
|
170
170
|
return litCSize + lhSize;
|
171
171
|
}
|
172
172
|
|
@@ -191,10 +191,10 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
|
191
191
|
|
192
192
|
if (lhSize+litSize+WILDCOPY_OVERLENGTH > srcSize) { /* risk reading beyond src buffer with wildcopy */
|
193
193
|
RETURN_ERROR_IF(litSize+lhSize > srcSize, corruption_detected, "");
|
194
|
-
|
194
|
+
ZSTD_memcpy(dctx->litBuffer, istart+lhSize, litSize);
|
195
195
|
dctx->litPtr = dctx->litBuffer;
|
196
196
|
dctx->litSize = litSize;
|
197
|
-
|
197
|
+
ZSTD_memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH);
|
198
198
|
return lhSize+litSize;
|
199
199
|
}
|
200
200
|
/* direct reference into compressed stream */
|
@@ -223,7 +223,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
|
223
223
|
break;
|
224
224
|
}
|
225
225
|
RETURN_ERROR_IF(litSize > ZSTD_BLOCKSIZE_MAX, corruption_detected, "");
|
226
|
-
|
226
|
+
ZSTD_memset(dctx->litBuffer, istart[lhSize], litSize + WILDCOPY_OVERLENGTH);
|
227
227
|
dctx->litPtr = dctx->litBuffer;
|
228
228
|
dctx->litSize = litSize;
|
229
229
|
return lhSize+1;
|
@@ -364,23 +364,26 @@ static void ZSTD_buildSeqTable_rle(ZSTD_seqSymbol* dt, U32 baseValue, U32 nbAddB
|
|
364
364
|
* generate FSE decoding table for one symbol (ll, ml or off)
|
365
365
|
* cannot fail if input is valid =>
|
366
366
|
* all inputs are presumed validated at this stage */
|
367
|
-
|
368
|
-
|
367
|
+
FORCE_INLINE_TEMPLATE
|
368
|
+
void ZSTD_buildFSETable_body(ZSTD_seqSymbol* dt,
|
369
369
|
const short* normalizedCounter, unsigned maxSymbolValue,
|
370
370
|
const U32* baseValue, const U32* nbAdditionalBits,
|
371
|
-
unsigned tableLog)
|
371
|
+
unsigned tableLog, void* wksp, size_t wkspSize)
|
372
372
|
{
|
373
373
|
ZSTD_seqSymbol* const tableDecode = dt+1;
|
374
|
-
U16 symbolNext[MaxSeq+1];
|
375
|
-
|
376
374
|
U32 const maxSV1 = maxSymbolValue + 1;
|
377
375
|
U32 const tableSize = 1 << tableLog;
|
378
|
-
|
376
|
+
|
377
|
+
U16* symbolNext = (U16*)wksp;
|
378
|
+
BYTE* spread = (BYTE*)(symbolNext + MaxSeq + 1);
|
379
|
+
U32 highThreshold = tableSize - 1;
|
380
|
+
|
379
381
|
|
380
382
|
/* Sanity Checks */
|
381
383
|
assert(maxSymbolValue <= MaxSeq);
|
382
384
|
assert(tableLog <= MaxFSELog);
|
383
|
-
|
385
|
+
assert(wkspSize >= ZSTD_BUILD_FSE_TABLE_WKSP_SIZE);
|
386
|
+
(void)wkspSize;
|
384
387
|
/* Init, lay down lowprob symbols */
|
385
388
|
{ ZSTD_seqSymbol_header DTableH;
|
386
389
|
DTableH.tableLog = tableLog;
|
@@ -396,16 +399,69 @@ ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
|
396
399
|
assert(normalizedCounter[s]>=0);
|
397
400
|
symbolNext[s] = (U16)normalizedCounter[s];
|
398
401
|
} } }
|
399
|
-
|
402
|
+
ZSTD_memcpy(dt, &DTableH, sizeof(DTableH));
|
400
403
|
}
|
401
404
|
|
402
405
|
/* Spread symbols */
|
403
|
-
|
406
|
+
assert(tableSize <= 512);
|
407
|
+
/* Specialized symbol spreading for the case when there are
|
408
|
+
* no low probability (-1 count) symbols. When compressing
|
409
|
+
* small blocks we avoid low probability symbols to hit this
|
410
|
+
* case, since header decoding speed matters more.
|
411
|
+
*/
|
412
|
+
if (highThreshold == tableSize - 1) {
|
413
|
+
size_t const tableMask = tableSize-1;
|
414
|
+
size_t const step = FSE_TABLESTEP(tableSize);
|
415
|
+
/* First lay down the symbols in order.
|
416
|
+
* We use a uint64_t to lay down 8 bytes at a time. This reduces branch
|
417
|
+
* misses since small blocks generally have small table logs, so nearly
|
418
|
+
* all symbols have counts <= 8. We ensure we have 8 bytes at the end of
|
419
|
+
* our buffer to handle the over-write.
|
420
|
+
*/
|
421
|
+
{
|
422
|
+
U64 const add = 0x0101010101010101ull;
|
423
|
+
size_t pos = 0;
|
424
|
+
U64 sv = 0;
|
425
|
+
U32 s;
|
426
|
+
for (s=0; s<maxSV1; ++s, sv += add) {
|
427
|
+
int i;
|
428
|
+
int const n = normalizedCounter[s];
|
429
|
+
MEM_write64(spread + pos, sv);
|
430
|
+
for (i = 8; i < n; i += 8) {
|
431
|
+
MEM_write64(spread + pos + i, sv);
|
432
|
+
}
|
433
|
+
pos += n;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
/* Now we spread those positions across the table.
|
437
|
+
* The benefit of doing it in two stages is that we avoid the the
|
438
|
+
* variable size inner loop, which caused lots of branch misses.
|
439
|
+
* Now we can run through all the positions without any branch misses.
|
440
|
+
* We unroll the loop twice, since that is what emperically worked best.
|
441
|
+
*/
|
442
|
+
{
|
443
|
+
size_t position = 0;
|
444
|
+
size_t s;
|
445
|
+
size_t const unroll = 2;
|
446
|
+
assert(tableSize % unroll == 0); /* FSE_MIN_TABLELOG is 5 */
|
447
|
+
for (s = 0; s < (size_t)tableSize; s += unroll) {
|
448
|
+
size_t u;
|
449
|
+
for (u = 0; u < unroll; ++u) {
|
450
|
+
size_t const uPosition = (position + (u * step)) & tableMask;
|
451
|
+
tableDecode[uPosition].baseValue = spread[s + u];
|
452
|
+
}
|
453
|
+
position = (position + (unroll * step)) & tableMask;
|
454
|
+
}
|
455
|
+
assert(position == 0);
|
456
|
+
}
|
457
|
+
} else {
|
458
|
+
U32 const tableMask = tableSize-1;
|
404
459
|
U32 const step = FSE_TABLESTEP(tableSize);
|
405
460
|
U32 s, position = 0;
|
406
461
|
for (s=0; s<maxSV1; s++) {
|
407
462
|
int i;
|
408
|
-
|
463
|
+
int const n = normalizedCounter[s];
|
464
|
+
for (i=0; i<n; i++) {
|
409
465
|
tableDecode[position].baseValue = s;
|
410
466
|
position = (position + step) & tableMask;
|
411
467
|
while (position > highThreshold) position = (position + step) & tableMask; /* lowprob area */
|
@@ -414,7 +470,8 @@ ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
|
414
470
|
}
|
415
471
|
|
416
472
|
/* Build Decoding table */
|
417
|
-
{
|
473
|
+
{
|
474
|
+
U32 u;
|
418
475
|
for (u=0; u<tableSize; u++) {
|
419
476
|
U32 const symbol = tableDecode[u].baseValue;
|
420
477
|
U32 const nextState = symbolNext[symbol]++;
|
@@ -423,7 +480,46 @@ ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
|
423
480
|
assert(nbAdditionalBits[symbol] < 255);
|
424
481
|
tableDecode[u].nbAdditionalBits = (BYTE)nbAdditionalBits[symbol];
|
425
482
|
tableDecode[u].baseValue = baseValue[symbol];
|
426
|
-
|
483
|
+
}
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
/* Avoids the FORCE_INLINE of the _body() function. */
|
488
|
+
static void ZSTD_buildFSETable_body_default(ZSTD_seqSymbol* dt,
|
489
|
+
const short* normalizedCounter, unsigned maxSymbolValue,
|
490
|
+
const U32* baseValue, const U32* nbAdditionalBits,
|
491
|
+
unsigned tableLog, void* wksp, size_t wkspSize)
|
492
|
+
{
|
493
|
+
ZSTD_buildFSETable_body(dt, normalizedCounter, maxSymbolValue,
|
494
|
+
baseValue, nbAdditionalBits, tableLog, wksp, wkspSize);
|
495
|
+
}
|
496
|
+
|
497
|
+
#if DYNAMIC_BMI2
|
498
|
+
TARGET_ATTRIBUTE("bmi2") static void ZSTD_buildFSETable_body_bmi2(ZSTD_seqSymbol* dt,
|
499
|
+
const short* normalizedCounter, unsigned maxSymbolValue,
|
500
|
+
const U32* baseValue, const U32* nbAdditionalBits,
|
501
|
+
unsigned tableLog, void* wksp, size_t wkspSize)
|
502
|
+
{
|
503
|
+
ZSTD_buildFSETable_body(dt, normalizedCounter, maxSymbolValue,
|
504
|
+
baseValue, nbAdditionalBits, tableLog, wksp, wkspSize);
|
505
|
+
}
|
506
|
+
#endif
|
507
|
+
|
508
|
+
void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
509
|
+
const short* normalizedCounter, unsigned maxSymbolValue,
|
510
|
+
const U32* baseValue, const U32* nbAdditionalBits,
|
511
|
+
unsigned tableLog, void* wksp, size_t wkspSize, int bmi2)
|
512
|
+
{
|
513
|
+
#if DYNAMIC_BMI2
|
514
|
+
if (bmi2) {
|
515
|
+
ZSTD_buildFSETable_body_bmi2(dt, normalizedCounter, maxSymbolValue,
|
516
|
+
baseValue, nbAdditionalBits, tableLog, wksp, wkspSize);
|
517
|
+
return;
|
518
|
+
}
|
519
|
+
#endif
|
520
|
+
(void)bmi2;
|
521
|
+
ZSTD_buildFSETable_body_default(dt, normalizedCounter, maxSymbolValue,
|
522
|
+
baseValue, nbAdditionalBits, tableLog, wksp, wkspSize);
|
427
523
|
}
|
428
524
|
|
429
525
|
|
@@ -435,7 +531,8 @@ static size_t ZSTD_buildSeqTable(ZSTD_seqSymbol* DTableSpace, const ZSTD_seqSymb
|
|
435
531
|
const void* src, size_t srcSize,
|
436
532
|
const U32* baseValue, const U32* nbAdditionalBits,
|
437
533
|
const ZSTD_seqSymbol* defaultTable, U32 flagRepeatTable,
|
438
|
-
int ddictIsCold, int nbSeq
|
534
|
+
int ddictIsCold, int nbSeq, U32* wksp, size_t wkspSize,
|
535
|
+
int bmi2)
|
439
536
|
{
|
440
537
|
switch(type)
|
441
538
|
{
|
@@ -467,7 +564,7 @@ static size_t ZSTD_buildSeqTable(ZSTD_seqSymbol* DTableSpace, const ZSTD_seqSymb
|
|
467
564
|
size_t const headerSize = FSE_readNCount(norm, &max, &tableLog, src, srcSize);
|
468
565
|
RETURN_ERROR_IF(FSE_isError(headerSize), corruption_detected, "");
|
469
566
|
RETURN_ERROR_IF(tableLog > maxLog, corruption_detected, "");
|
470
|
-
ZSTD_buildFSETable(DTableSpace, norm, max, baseValue, nbAdditionalBits, tableLog);
|
567
|
+
ZSTD_buildFSETable(DTableSpace, norm, max, baseValue, nbAdditionalBits, tableLog, wksp, wkspSize, bmi2);
|
471
568
|
*DTablePtr = DTableSpace;
|
472
569
|
return headerSize;
|
473
570
|
}
|
@@ -499,7 +596,8 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
|
499
596
|
if (nbSeq > 0x7F) {
|
500
597
|
if (nbSeq == 0xFF) {
|
501
598
|
RETURN_ERROR_IF(ip+2 > iend, srcSize_wrong, "");
|
502
|
-
nbSeq = MEM_readLE16(ip) + LONGNBSEQ
|
599
|
+
nbSeq = MEM_readLE16(ip) + LONGNBSEQ;
|
600
|
+
ip+=2;
|
503
601
|
} else {
|
504
602
|
RETURN_ERROR_IF(ip >= iend, srcSize_wrong, "");
|
505
603
|
nbSeq = ((nbSeq-0x80)<<8) + *ip++;
|
@@ -520,7 +618,9 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
|
520
618
|
ip, iend-ip,
|
521
619
|
LL_base, LL_bits,
|
522
620
|
LL_defaultDTable, dctx->fseEntropy,
|
523
|
-
dctx->ddictIsCold, nbSeq
|
621
|
+
dctx->ddictIsCold, nbSeq,
|
622
|
+
dctx->workspace, sizeof(dctx->workspace),
|
623
|
+
dctx->bmi2);
|
524
624
|
RETURN_ERROR_IF(ZSTD_isError(llhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
525
625
|
ip += llhSize;
|
526
626
|
}
|
@@ -530,7 +630,9 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
|
530
630
|
ip, iend-ip,
|
531
631
|
OF_base, OF_bits,
|
532
632
|
OF_defaultDTable, dctx->fseEntropy,
|
533
|
-
dctx->ddictIsCold, nbSeq
|
633
|
+
dctx->ddictIsCold, nbSeq,
|
634
|
+
dctx->workspace, sizeof(dctx->workspace),
|
635
|
+
dctx->bmi2);
|
534
636
|
RETURN_ERROR_IF(ZSTD_isError(ofhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
535
637
|
ip += ofhSize;
|
536
638
|
}
|
@@ -540,7 +642,9 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
|
540
642
|
ip, iend-ip,
|
541
643
|
ML_base, ML_bits,
|
542
644
|
ML_defaultDTable, dctx->fseEntropy,
|
543
|
-
dctx->ddictIsCold, nbSeq
|
645
|
+
dctx->ddictIsCold, nbSeq,
|
646
|
+
dctx->workspace, sizeof(dctx->workspace),
|
647
|
+
dctx->bmi2);
|
544
648
|
RETURN_ERROR_IF(ZSTD_isError(mlhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
545
649
|
ip += mlhSize;
|
546
650
|
}
|
@@ -686,12 +790,12 @@ size_t ZSTD_execSequenceEnd(BYTE* op,
|
|
686
790
|
RETURN_ERROR_IF(sequence.offset > (size_t)(oLitEnd - virtualStart), corruption_detected, "");
|
687
791
|
match = dictEnd - (prefixStart-match);
|
688
792
|
if (match + sequence.matchLength <= dictEnd) {
|
689
|
-
|
793
|
+
ZSTD_memmove(oLitEnd, match, sequence.matchLength);
|
690
794
|
return sequenceLength;
|
691
795
|
}
|
692
796
|
/* span extDict & currentPrefixSegment */
|
693
797
|
{ size_t const length1 = dictEnd - match;
|
694
|
-
|
798
|
+
ZSTD_memmove(oLitEnd, match, length1);
|
695
799
|
op = oLitEnd + length1;
|
696
800
|
sequence.matchLength -= length1;
|
697
801
|
match = prefixStart;
|
@@ -752,12 +856,12 @@ size_t ZSTD_execSequence(BYTE* op,
|
|
752
856
|
RETURN_ERROR_IF(UNLIKELY(sequence.offset > (size_t)(oLitEnd - virtualStart)), corruption_detected, "");
|
753
857
|
match = dictEnd + (match - prefixStart);
|
754
858
|
if (match + sequence.matchLength <= dictEnd) {
|
755
|
-
|
859
|
+
ZSTD_memmove(oLitEnd, match, sequence.matchLength);
|
756
860
|
return sequenceLength;
|
757
861
|
}
|
758
862
|
/* span extDict & currentPrefixSegment */
|
759
863
|
{ size_t const length1 = dictEnd - match;
|
760
|
-
|
864
|
+
ZSTD_memmove(oLitEnd, match, length1);
|
761
865
|
op = oLitEnd + length1;
|
762
866
|
sequence.matchLength -= length1;
|
763
867
|
match = prefixStart;
|
@@ -948,7 +1052,7 @@ ZSTD_decodeSequence(seqState_t* seqState, const ZSTD_longOffset_e longOffsets, c
|
|
948
1052
|
}
|
949
1053
|
|
950
1054
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
951
|
-
|
1055
|
+
MEM_STATIC int ZSTD_dictionaryIsActive(ZSTD_DCtx const* dctx, BYTE const* prefixStart, BYTE const* oLitEnd)
|
952
1056
|
{
|
953
1057
|
size_t const windowSize = dctx->fParams.windowSize;
|
954
1058
|
/* No dictionary used. */
|
@@ -969,6 +1073,7 @@ MEM_STATIC void ZSTD_assertValidSequence(
|
|
969
1073
|
seq_t const seq,
|
970
1074
|
BYTE const* prefixStart, BYTE const* virtualStart)
|
971
1075
|
{
|
1076
|
+
#if DEBUGLEVEL >= 1
|
972
1077
|
size_t const windowSize = dctx->fParams.windowSize;
|
973
1078
|
size_t const sequenceSize = seq.litLength + seq.matchLength;
|
974
1079
|
BYTE const* const oLitEnd = op + seq.litLength;
|
@@ -986,6 +1091,9 @@ MEM_STATIC void ZSTD_assertValidSequence(
|
|
986
1091
|
/* Offset must be within our window. */
|
987
1092
|
assert(seq.offset <= windowSize);
|
988
1093
|
}
|
1094
|
+
#else
|
1095
|
+
(void)dctx, (void)op, (void)oend, (void)seq, (void)prefixStart, (void)virtualStart;
|
1096
|
+
#endif
|
989
1097
|
}
|
990
1098
|
#endif
|
991
1099
|
|
@@ -1080,14 +1188,14 @@ ZSTD_decompressSequences_body( ZSTD_DCtx* dctx,
|
|
1080
1188
|
#endif
|
1081
1189
|
DEBUGLOG(6, "regenerated sequence size : %u", (U32)oneSeqSize);
|
1082
1190
|
BIT_reloadDStream(&(seqState.DStream));
|
1191
|
+
op += oneSeqSize;
|
1083
1192
|
/* gcc and clang both don't like early returns in this loop.
|
1084
|
-
*
|
1085
|
-
* Instead save an error and report it at the end.
|
1086
|
-
* When there is an error, don't increment op, so we don't
|
1087
|
-
* overwrite.
|
1193
|
+
* Instead break and check for an error at the end of the loop.
|
1088
1194
|
*/
|
1089
|
-
if (UNLIKELY(ZSTD_isError(oneSeqSize)))
|
1090
|
-
|
1195
|
+
if (UNLIKELY(ZSTD_isError(oneSeqSize))) {
|
1196
|
+
error = oneSeqSize;
|
1197
|
+
break;
|
1198
|
+
}
|
1091
1199
|
if (UNLIKELY(!--nbSeq)) break;
|
1092
1200
|
}
|
1093
1201
|
|
@@ -1104,7 +1212,7 @@ ZSTD_decompressSequences_body( ZSTD_DCtx* dctx,
|
|
1104
1212
|
{ size_t const lastLLSize = litEnd - litPtr;
|
1105
1213
|
RETURN_ERROR_IF(lastLLSize > (size_t)(oend-op), dstSize_tooSmall, "");
|
1106
1214
|
if (op != NULL) {
|
1107
|
-
|
1215
|
+
ZSTD_memcpy(op, litPtr, lastLLSize);
|
1108
1216
|
op += lastLLSize;
|
1109
1217
|
}
|
1110
1218
|
}
|
@@ -1209,7 +1317,7 @@ ZSTD_decompressSequencesLong_body(
|
|
1209
1317
|
{ size_t const lastLLSize = litEnd - litPtr;
|
1210
1318
|
RETURN_ERROR_IF(lastLLSize > (size_t)(oend-op), dstSize_tooSmall, "");
|
1211
1319
|
if (op != NULL) {
|
1212
|
-
|
1320
|
+
ZSTD_memcpy(op, litPtr, lastLLSize);
|
1213
1321
|
op += lastLLSize;
|
1214
1322
|
}
|
1215
1323
|
}
|
@@ -15,7 +15,7 @@
|
|
15
15
|
/*-*******************************************************
|
16
16
|
* Dependencies
|
17
17
|
*********************************************************/
|
18
|
-
#include
|
18
|
+
#include "../common/zstd_deps.h" /* size_t */
|
19
19
|
#include "../zstd.h" /* DCtx, and some public functions */
|
20
20
|
#include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */
|
21
21
|
#include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
|
@@ -48,12 +48,15 @@ size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
|
|
48
48
|
* this function must be called with valid parameters only
|
49
49
|
* (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
|
50
50
|
* in which case it cannot fail.
|
51
|
+
* The workspace must be 4-byte aligned and at least ZSTD_BUILD_FSE_TABLE_WKSP_SIZE bytes, which is
|
52
|
+
* defined in zstd_decompress_internal.h.
|
51
53
|
* Internal use only.
|
52
54
|
*/
|
53
55
|
void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
54
56
|
const short* normalizedCounter, unsigned maxSymbolValue,
|
55
57
|
const U32* baseValue, const U32* nbAdditionalBits,
|
56
|
-
unsigned tableLog
|
58
|
+
unsigned tableLog, void* wksp, size_t wkspSize,
|
59
|
+
int bmi2);
|
57
60
|
|
58
61
|
|
59
62
|
#endif /* ZSTD_DEC_BLOCK_H */
|
@@ -27,26 +27,26 @@
|
|
27
27
|
/*-*******************************************************
|
28
28
|
* Constants
|
29
29
|
*********************************************************/
|
30
|
-
static const U32 LL_base[MaxLL+1] = {
|
30
|
+
static UNUSED_ATTR const U32 LL_base[MaxLL+1] = {
|
31
31
|
0, 1, 2, 3, 4, 5, 6, 7,
|
32
32
|
8, 9, 10, 11, 12, 13, 14, 15,
|
33
33
|
16, 18, 20, 22, 24, 28, 32, 40,
|
34
34
|
48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
|
35
35
|
0x2000, 0x4000, 0x8000, 0x10000 };
|
36
36
|
|
37
|
-
static const U32 OF_base[MaxOff+1] = {
|
37
|
+
static UNUSED_ATTR const U32 OF_base[MaxOff+1] = {
|
38
38
|
0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D,
|
39
39
|
0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD,
|
40
40
|
0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD,
|
41
41
|
0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD };
|
42
42
|
|
43
|
-
static const U32 OF_bits[MaxOff+1] = {
|
43
|
+
static UNUSED_ATTR const U32 OF_bits[MaxOff+1] = {
|
44
44
|
0, 1, 2, 3, 4, 5, 6, 7,
|
45
45
|
8, 9, 10, 11, 12, 13, 14, 15,
|
46
46
|
16, 17, 18, 19, 20, 21, 22, 23,
|
47
47
|
24, 25, 26, 27, 28, 29, 30, 31 };
|
48
48
|
|
49
|
-
static const U32 ML_base[MaxML+1] = {
|
49
|
+
static UNUSED_ATTR const U32 ML_base[MaxML+1] = {
|
50
50
|
3, 4, 5, 6, 7, 8, 9, 10,
|
51
51
|
11, 12, 13, 14, 15, 16, 17, 18,
|
52
52
|
19, 20, 21, 22, 23, 24, 25, 26,
|
@@ -73,12 +73,16 @@ static const U32 ML_base[MaxML+1] = {
|
|
73
73
|
|
74
74
|
#define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log)))
|
75
75
|
|
76
|
+
#define ZSTD_BUILD_FSE_TABLE_WKSP_SIZE (sizeof(S16) * (MaxSeq + 1) + (1u << MaxFSELog) + sizeof(U64))
|
77
|
+
#define ZSTD_BUILD_FSE_TABLE_WKSP_SIZE_U32 ((ZSTD_BUILD_FSE_TABLE_WKSP_SIZE + sizeof(U32) - 1) / sizeof(U32))
|
78
|
+
|
76
79
|
typedef struct {
|
77
80
|
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]; /* Note : Space reserved for FSE Tables */
|
78
81
|
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]; /* is also used as temporary workspace while building hufTable during DDict creation */
|
79
82
|
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]; /* and therefore must be at least HUF_DECOMPRESS_WORKSPACE_SIZE large */
|
80
83
|
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]; /* can accommodate HUF_decompress4X */
|
81
84
|
U32 rep[ZSTD_REP_NUM];
|
85
|
+
U32 workspace[ZSTD_BUILD_FSE_TABLE_WKSP_SIZE_U32];
|
82
86
|
} ZSTD_entropyDTables_t;
|
83
87
|
|
84
88
|
typedef enum { ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader,
|
@@ -95,11 +99,6 @@ typedef enum {
|
|
95
99
|
ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
|
96
100
|
} ZSTD_dictUses_e;
|
97
101
|
|
98
|
-
typedef enum {
|
99
|
-
ZSTD_obm_buffered = 0, /* Buffer the output */
|
100
|
-
ZSTD_obm_stable = 1 /* ZSTD_outBuffer is stable */
|
101
|
-
} ZSTD_outBufferMode_e;
|
102
|
-
|
103
102
|
struct ZSTD_DCtx_s
|
104
103
|
{
|
105
104
|
const ZSTD_seqSymbol* LLTptr;
|
@@ -122,6 +121,8 @@ struct ZSTD_DCtx_s
|
|
122
121
|
XXH64_state_t xxhState;
|
123
122
|
size_t headerSize;
|
124
123
|
ZSTD_format_e format;
|
124
|
+
ZSTD_forceIgnoreChecksum_e forceIgnoreChecksum; /* User specified: if == 1, will ignore checksums in compressed frame. Default == 0 */
|
125
|
+
U32 validateChecksum; /* if == 1, will validate checksum. Is == 1 if (fParams.checksumFlag == 1) and (forceIgnoreChecksum == 0). */
|
125
126
|
const BYTE* litPtr;
|
126
127
|
ZSTD_customMem customMem;
|
127
128
|
size_t litSize;
|
@@ -152,7 +153,7 @@ struct ZSTD_DCtx_s
|
|
152
153
|
U32 legacyVersion;
|
153
154
|
U32 hostageByte;
|
154
155
|
int noForwardProgress;
|
155
|
-
|
156
|
+
ZSTD_bufferMode_e outBufferMode;
|
156
157
|
ZSTD_outBuffer expectedOutBuffer;
|
157
158
|
|
158
159
|
/* workspace */
|