Skip to content

Commit e64391f

Browse files
Update zstd to 1.3.8
1 parent b1e3215 commit e64391f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+8376
-4778
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ insert_final_newline = true
99
[*.{cpp,hpp,c,h,mm}]
1010
trim_trailing_whitespace = true
1111

12-
[*.{py,cs}]
12+
[{*.{py,cs},SCsub}]
1313
indent_style = space
1414
indent_size = 4
1515

core/SCsub

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ env_thirdparty.add_source_files(env.core_sources, thirdparty_minizip_sources)
103103
if env['builtin_zstd']:
104104
thirdparty_zstd_dir = "#thirdparty/zstd/"
105105
thirdparty_zstd_sources = [
106+
"common/debug.c",
106107
"common/entropy_common.c",
107108
"common/error_private.c",
108109
"common/fse_decompress.c",
@@ -111,15 +112,18 @@ if env['builtin_zstd']:
111112
"common/xxhash.c",
112113
"common/zstd_common.c",
113114
"compress/fse_compress.c",
115+
"compress/hist.c",
114116
"compress/huf_compress.c",
115117
"compress/zstd_compress.c",
116118
"compress/zstd_double_fast.c",
117119
"compress/zstd_fast.c",
118120
"compress/zstd_lazy.c",
119121
"compress/zstd_ldm.c",
120-
"compress/zstdmt_compress.c",
121122
"compress/zstd_opt.c",
123+
"compress/zstdmt_compress.c",
122124
"decompress/huf_decompress.c",
125+
"decompress/zstd_ddict.c",
126+
"decompress/zstd_decompress_block.c",
123127
"decompress/zstd_decompress.c",
124128
]
125129
thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]

core/io/compression.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
8181
} break;
8282
case MODE_ZSTD: {
8383
ZSTD_CCtx *cctx = ZSTD_createCCtx();
84-
ZSTD_CCtx_setParameter(cctx, ZSTD_p_compressionLevel, zstd_level);
84+
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, zstd_level);
8585
if (zstd_long_distance_matching) {
86-
ZSTD_CCtx_setParameter(cctx, ZSTD_p_enableLongDistanceMatching, 1);
87-
ZSTD_CCtx_setParameter(cctx, ZSTD_p_windowLog, zstd_window_log_size);
86+
ZSTD_CCtx_setParameter(cctx, ZSTD_c_enableLongDistanceMatching, 1);
87+
ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, zstd_window_log_size);
8888
}
8989
int max_dst_size = get_max_compressed_buffer_size(p_src_size, MODE_ZSTD);
9090
int ret = ZSTD_compressCCtx(cctx, p_dst, max_dst_size, p_src, p_src_size, zstd_level);

thirdparty/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,10 @@ Files extracted from upstream source:
534534
## zstd
535535

536536
- Upstream: https://github.com/facebook/zstd
537-
- Version: 1.3.4
537+
- Version: 1.3.8
538538
- License: BSD-3-Clause
539539

540540
Files extracted from upstream source:
541541

542542
- lib/{common/,compress/,decompress/,zstd.h}
543543
- LICENSE
544-
545-
- Applied the patch in `thirdparty/zstd/1314.diff` (PR 1314 upstream, already merged). Needed to build on UWP ARM. Can be removed when a new version is released with the patch.

thirdparty/zstd/1314.diff

-13
This file was deleted.

thirdparty/zstd/common/bitstream.h

+16-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* ******************************************************************
22
bitstream
33
Part of FSE library
4-
header file (to include)
5-
Copyright (C) 2013-2017, Yann Collet.
4+
Copyright (C) 2013-present, Yann Collet.
65
76
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
87
@@ -49,21 +48,10 @@ extern "C" {
4948
* Dependencies
5049
******************************************/
5150
#include "mem.h" /* unaligned access routines */
51+
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
5252
#include "error_private.h" /* error codes and messages */
5353

5454

55-
/*-*************************************
56-
* Debug
57-
***************************************/
58-
#if defined(BIT_DEBUG) && (BIT_DEBUG>=1)
59-
# include <assert.h>
60-
#else
61-
# ifndef assert
62-
# define assert(condition) ((void)0)
63-
# endif
64-
#endif
65-
66-
6755
/*=========================================
6856
* Target specific
6957
=========================================*/
@@ -83,8 +71,7 @@ extern "C" {
8371
* A critical property of these streams is that they encode and decode in **reverse** direction.
8472
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
8573
*/
86-
typedef struct
87-
{
74+
typedef struct {
8875
size_t bitContainer;
8976
unsigned bitPos;
9077
char* startPtr;
@@ -118,8 +105,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
118105
/*-********************************************
119106
* bitStream decoding API (read backward)
120107
**********************************************/
121-
typedef struct
122-
{
108+
typedef struct {
123109
size_t bitContainer;
124110
unsigned bitsConsumed;
125111
const char* ptr;
@@ -236,7 +222,8 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
236222
}
237223

238224
/*! BIT_addBitsFast() :
239-
* works only if `value` is _clean_, meaning all high bits above nbBits are 0 */
225+
* works only if `value` is _clean_,
226+
* meaning all high bits above nbBits are 0 */
240227
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
241228
size_t value, unsigned nbBits)
242229
{
@@ -352,17 +339,10 @@ MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
352339

353340
MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
354341
{
355-
#if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008 /* experimental */
356-
# if defined(__x86_64__)
357-
if (sizeof(bitContainer)==8)
358-
return _bextr_u64(bitContainer, start, nbBits);
359-
else
360-
# endif
361-
return _bextr_u32(bitContainer, start, nbBits);
362-
#else
342+
U32 const regMask = sizeof(bitContainer)*8 - 1;
343+
/* if start > regMask, bitstream is corrupted, and result is undefined */
363344
assert(nbBits < BIT_MASK_SIZE);
364-
return (bitContainer >> start) & BIT_mask[nbBits];
365-
#endif
345+
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
366346
}
367347

368348
MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
@@ -379,9 +359,13 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
379359
* @return : value extracted */
380360
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
381361
{
382-
#if defined(__BMI__) && defined(__GNUC__) /* experimental; fails if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8 */
362+
/* arbitrate between double-shift and shift+mask */
363+
#if 1
364+
/* if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8,
365+
* bitstream is likely corrupted, and result is undefined */
383366
return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits);
384367
#else
368+
/* this code path is slower on my os-x laptop */
385369
U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
386370
return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask);
387371
#endif
@@ -405,7 +389,7 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
405389
* Read (consume) next n bits from local register and update.
406390
* Pay attention to not read more than nbBits contained into local register.
407391
* @return : extracted value. */
408-
MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
392+
MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
409393
{
410394
size_t const value = BIT_lookBits(bitD, nbBits);
411395
BIT_skipBits(bitD, nbBits);
@@ -414,7 +398,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
414398

415399
/*! BIT_readBitsFast() :
416400
* unsafe version; only works only if nbBits >= 1 */
417-
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
401+
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
418402
{
419403
size_t const value = BIT_lookBitsFast(bitD, nbBits);
420404
assert(nbBits >= 1);

thirdparty/zstd/common/compiler.h

+39-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Compiler specifics
1616
*********************************************************/
1717
/* force inlining */
18+
19+
#if !defined(ZSTD_NO_INLINE)
1820
#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
1921
# define INLINE_KEYWORD inline
2022
#else
@@ -29,6 +31,13 @@
2931
# define FORCE_INLINE_ATTR
3032
#endif
3133

34+
#else
35+
36+
#define INLINE_KEYWORD
37+
#define FORCE_INLINE_ATTR
38+
39+
#endif
40+
3241
/**
3342
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
3443
* parameters. They must be inlined for the compiler to elimininate the constant
@@ -77,9 +86,9 @@
7786
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
7887
*/
7988
#ifndef DYNAMIC_BMI2
80-
#if (defined(__clang__) && __has_attribute(__target__)) \
89+
#if ((defined(__clang__) && __has_attribute(__target__)) \
8190
|| (defined(__GNUC__) \
82-
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \
91+
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
8392
&& (defined(__x86_64__) || defined(_M_X86)) \
8493
&& !defined(__BMI2__)
8594
# define DYNAMIC_BMI2 1
@@ -88,15 +97,35 @@
8897
#endif
8998
#endif
9099

91-
/* prefetch */
92-
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
93-
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
94-
# define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T0)
95-
#elif defined(__GNUC__)
96-
# define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
100+
/* prefetch
101+
* can be disabled, by declaring NO_PREFETCH build macro */
102+
#if defined(NO_PREFETCH)
103+
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
104+
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
97105
#else
98-
# define PREFETCH(ptr) /* disabled */
99-
#endif
106+
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
107+
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
108+
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
109+
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
110+
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
111+
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
112+
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
113+
# else
114+
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
115+
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
116+
# endif
117+
#endif /* NO_PREFETCH */
118+
119+
#define CACHELINE_SIZE 64
120+
121+
#define PREFETCH_AREA(p, s) { \
122+
const char* const _ptr = (const char*)(p); \
123+
size_t const _size = (size_t)(s); \
124+
size_t _pos; \
125+
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
126+
PREFETCH_L2(_ptr + _pos); \
127+
} \
128+
}
100129

101130
/* disable warnings */
102131
#ifdef _MSC_VER /* Visual Studio */

thirdparty/zstd/common/cpu.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
7272
"cpuid\n\t"
7373
"popl %%ebx\n\t"
7474
: "=a"(f1a), "=c"(f1c), "=d"(f1d)
75-
: "a"(1)
76-
:);
75+
: "a"(1));
7776
}
7877
if (n >= 7) {
7978
__asm__(
8079
"pushl %%ebx\n\t"
8180
"cpuid\n\t"
82-
"movl %%ebx, %%eax\n\r"
81+
"movl %%ebx, %%eax\n\t"
8382
"popl %%ebx"
8483
: "=a"(f7b), "=c"(f7c)
8584
: "a"(7), "c"(0)

thirdparty/zstd/common/debug.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ******************************************************************
2+
debug
3+
Part of FSE library
4+
Copyright (C) 2013-present, Yann Collet.
5+
6+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are
10+
met:
11+
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above
15+
copyright notice, this list of conditions and the following disclaimer
16+
in the documentation and/or other materials provided with the
17+
distribution.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
You can contact the author at :
32+
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
33+
****************************************************************** */
34+
35+
36+
/*
37+
* This module only hosts one global variable
38+
* which can be used to dynamically influence the verbosity of traces,
39+
* such as DEBUGLOG and RAWLOG
40+
*/
41+
42+
#include "debug.h"
43+
44+
int g_debuglevel = DEBUGLEVEL;

0 commit comments

Comments
 (0)