Skip to content

Commit fb7b1f1

Browse files
author
haruyama.makoto
committed
Update zstd to v1.3.8
1 parent be69af5 commit fb7b1f1

Some content is hidden

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

47 files changed

+4964
-3545
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See https://github.com/facebook/zstd
1010
Fork from https://github.com/jarredholman/ruby-zstd.
1111

1212
## Zstd version
13-
v1.3.7 (https://github.com/facebook/zstd/tree/v1.3.7)
13+
v1.3.8 (https://github.com/facebook/zstd/tree/v1.3.8)
1414

1515
## Installation
1616

ext/zstdruby/libzstd/BUCK

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cxx_library(
22
name='zstd',
33
header_namespace='',
4+
exported_headers=['zstd.h'],
45
visibility=['PUBLIC'],
56
deps=[
67
':common',
@@ -17,7 +18,7 @@ cxx_library(
1718
exported_headers=subdir_glob([
1819
('compress', 'zstd*.h'),
1920
]),
20-
srcs=glob(['compress/zstd*.c']),
21+
srcs=glob(['compress/zstd*.c', 'compress/hist.c']),
2122
deps=[':common'],
2223
)
2324

@@ -40,7 +41,7 @@ cxx_library(
4041
header_namespace='',
4142
visibility=['PUBLIC'],
4243
exported_headers=subdir_glob([
43-
('decprecated', '*.h'),
44+
('deprecated', '*.h'),
4445
]),
4546
srcs=glob(['deprecated/*.c']),
4647
deps=[':common'],
@@ -118,6 +119,7 @@ cxx_library(
118119
'decompress/huf_decompress.c',
119120
],
120121
deps=[
122+
':debug',
121123
':bitstream',
122124
':compiler',
123125
':errors',
@@ -204,9 +206,20 @@ cxx_library(
204206
],
205207
)
206208

209+
cxx_library(
210+
name='debug',
211+
header_namespace='',
212+
visibility=['PUBLIC'],
213+
exported_headers=subdir_glob([
214+
('common', 'debug.h'),
215+
]),
216+
srcs=['common/debug.c'],
217+
)
218+
207219
cxx_library(
208220
name='common',
209221
deps=[
222+
':debug',
210223
':bitstream',
211224
':compiler',
212225
':cpu',

ext/zstdruby/libzstd/Makefile

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
2727
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
2828
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
2929
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
30-
-Wredundant-decls -Wmissing-prototypes
30+
-Wredundant-decls -Wmissing-prototypes -Wc++-compat
3131
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
3232
FLAGS = $(CPPFLAGS) $(CFLAGS)
3333

34-
GREP = grep --color=never
34+
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
35+
GREP_OPTIONS ?=
36+
ifeq ($HAVE_COLORNEVER, 1)
37+
GREP_OPTIONS += --color=never
38+
endif
39+
GREP = grep $(GREP_OPTIONS)
3540

3641
ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
3742
ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
@@ -45,6 +50,12 @@ ZSTD_LIB_COMPRESSION ?= 1
4550
ZSTD_LIB_DECOMPRESSION ?= 1
4651
ZSTD_LIB_DICTBUILDER ?= 1
4752
ZSTD_LIB_DEPRECATED ?= 1
53+
HUF_FORCE_DECOMPRESS_X1 ?= 0
54+
HUF_FORCE_DECOMPRESS_X2 ?= 0
55+
ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
56+
ZSTD_FORCE_DECOMPRESS_LONG ?= 0
57+
ZSTD_NO_INLINE ?= 0
58+
ZSTD_STRIP_ERROR_STRINGS ?= 0
4859

4960
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
5061
ZSTD_LIB_DICTBUILDER = 0
@@ -72,6 +83,30 @@ ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
7283
ZSTD_FILES += $(ZDICT_FILES)
7384
endif
7485

86+
ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
87+
CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
88+
endif
89+
90+
ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
91+
CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
92+
endif
93+
94+
ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
95+
CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
96+
endif
97+
98+
ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
99+
CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
100+
endif
101+
102+
ifneq ($(ZSTD_NO_INLINE), 0)
103+
CFLAGS += -DZSTD_NO_INLINE
104+
endif
105+
106+
ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
107+
CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
108+
endif
109+
75110
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
76111
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
77112
ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')

ext/zstdruby/libzstd/README.md

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@ in order to make it easier to select or exclude features.
77

88
#### Building
99

10-
`Makefile` script is provided, supporting all standard [Makefile conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html#Makefile-Conventions),
10+
`Makefile` script is provided, supporting [Makefile conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html#Makefile-Conventions),
1111
including commands variables, staged install, directory variables and standard targets.
1212
- `make` : generates both static and dynamic libraries
13-
- `make install` : install libraries in default system directories
13+
- `make install` : install libraries and headers in target system directories
1414

15-
`libzstd` default scope includes compression, decompression, dictionary building,
16-
and decoding support for legacy formats >= v0.5.0.
15+
`libzstd` default scope is pretty large, including compression, decompression, dictionary builder,
16+
and support for decoding legacy formats >= v0.5.0.
17+
The scope can be reduced on demand (see paragraph _modular build_).
18+
19+
20+
#### Multithreading support
21+
22+
Multithreading is disabled by default when building with `make`.
23+
Enabling multithreading requires 2 conditions :
24+
- set build macro `ZSTD_MULTITHREAD` (`-DZSTD_MULTITHREAD` for `gcc`)
25+
- for POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
26+
27+
Both conditions are automatically applied when invoking `make lib-mt` target.
28+
29+
When linking a POSIX program with a multithreaded version of `libzstd`,
30+
note that it's necessary to request the `-pthread` flag during link stage.
31+
32+
Multithreading capabilities are exposed
33+
via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.3.8/lib/zstd.h#L592).
34+
This API is still labelled experimental,
35+
but is expected to become "stable" in the near future.
1736

1837

1938
#### API
@@ -26,63 +45,70 @@ Zstandard's stable API is exposed within [lib/zstd.h](zstd.h).
2645
Optional advanced features are exposed via :
2746

2847
- `lib/common/zstd_errors.h` : translates `size_t` function results
29-
into an `ZSTD_ErrorCode`, for accurate error handling.
48+
into a `ZSTD_ErrorCode`, for accurate error handling.
49+
3050
- `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
31-
it unlocks access to advanced experimental API,
32-
exposed in second part of `zstd.h`.
33-
These APIs are not "stable", their definition may change in the future.
34-
As a consequence, it shall ___never be used with dynamic library___ !
51+
it unlocks access to the experimental API,
52+
exposed in the second part of `zstd.h`.
53+
All definitions in the experimental APIs are unstable,
54+
they may still change in the future, or even be removed.
55+
As a consequence, experimental definitions shall ___never be used with dynamic library___ !
3556
Only static linking is allowed.
3657

3758

3859
#### Modular build
3960

40-
It's possible to compile only a limited set of features.
61+
It's possible to compile only a limited set of features within `libzstd`.
62+
The file structure is designed to make this selection manually achievable for any build system :
4163

4264
- Directory `lib/common` is always required, for all variants.
65+
4366
- Compression source code lies in `lib/compress`
67+
4468
- Decompression source code lies in `lib/decompress`
69+
4570
- It's possible to include only `compress` or only `decompress`, they don't depend on each other.
71+
4672
- `lib/dictBuilder` : makes it possible to generate dictionaries from a set of samples.
4773
The API is exposed in `lib/dictBuilder/zdict.h`.
4874
This module depends on both `lib/common` and `lib/compress` .
49-
- `lib/legacy` : source code to decompress legacy zstd formats, starting from `v0.1.0`.
75+
76+
- `lib/legacy` : makes it possible to decompress legacy zstd formats, starting from `v0.1.0`.
5077
This module depends on `lib/common` and `lib/decompress`.
5178
To enable this feature, define `ZSTD_LEGACY_SUPPORT` during compilation.
5279
Specifying a number limits versions supported to that version onward.
5380
For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats >= v0.2.0".
54-
`ZSTD_LEGACY_SUPPORT=3` means : "support legacy formats >= v0.3.0", and so on.
55-
Currently, the default library setting is `ZST_LEGACY_SUPPORT=5`.
56-
It can be changed at build by any other value.
57-
Note that any number >= 8 translates into "do __not__ support legacy formats",
58-
since all versions of `zstd` >= v0.8 are compatible with v1+ specification.
59-
`ZSTD_LEGACY_SUPPORT=0` also means "do __not__ support legacy formats".
60-
Once enabled, this capability is transparently triggered within decompression functions.
61-
It's also possible to invoke directly legacy API, as exposed in `lib/legacy/zstd_legacy.h`.
62-
Each version also provides an additional dedicated set of advanced API.
81+
Conversely, `ZSTD_LEGACY_SUPPORT=0` means "do __not__ support legacy formats".
82+
By default, this build macro is set as `ZSTD_LEGACY_SUPPORT=5`.
83+
Decoding supported legacy format is a transparent capability triggered within decompression functions.
84+
It's also allowed to invoke legacy API directly, exposed in `lib/legacy/zstd_legacy.h`.
85+
Each version does also provide its own set of advanced API.
6386
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
64-
Note : `lib/legacy` only supports _decoding_ legacy formats.
65-
- Similarly, you can define `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
66-
and `ZSTD_LIB_DEPRECATED` as 0 to forgo compilation of the corresponding features. This will
67-
also disable compilation of all dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable
68-
dictBuilder).
6987

88+
- While invoking `make libzstd`, it's possible to define build macros
89+
`ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
90+
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the corresponding features.
91+
This will also disable compilation of all dependencies
92+
(eg. `ZSTD_LIB_COMPRESSION=0` will also disable dictBuilder).
7093

71-
#### Multithreading support
94+
- There are some additional build macros that can be used to minify the decoder.
7295

73-
Multithreading is disabled by default when building with `make`.
74-
Enabling multithreading requires 2 conditions :
75-
- set macro `ZSTD_MULTITHREAD`
76-
- on POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
77-
78-
Both conditions are automatically triggered by invoking `make lib-mt` target.
79-
Note that, when linking a POSIX program with a multithreaded version of `libzstd`,
80-
it's necessary to trigger `-pthread` flag during link stage.
96+
Zstandard often has more than one implementation of a piece of functionality,
97+
where each implementation optimizes for different scenarios. For example, the
98+
Huffman decoder has complementary implementations that decode the stream one
99+
symbol at a time or two symbols at a time. Zstd normally includes both (and
100+
dispatches between them at runtime), but by defining `HUF_FORCE_DECOMPRESS_X1`
101+
or `HUF_FORCE_DECOMPRESS_X2`, you can force the use of one or the other, avoiding
102+
compilation of the other. Similarly, `ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT`
103+
and `ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG` force the compilation and use of
104+
only one or the other of two decompression implementations. The smallest
105+
binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and
106+
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT`.
81107

82-
Multithreading capabilities are exposed
83-
via [advanced API `ZSTD_compress_generic()` defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/dev/lib/zstd.h#L919).
84-
This API is still considered experimental,
85-
but is expected to become "stable" at some point in the future.
108+
For squeezing the last ounce of size out, you can also define
109+
`ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`,
110+
which removes the error messages that are otherwise returned by
111+
`ZSTD_getErrorName`.
86112

87113

88114
#### Windows : using MinGW+MSYS to create DLL
@@ -113,8 +139,8 @@ Consider migrating code towards supported streaming API exposed in `zstd.h`.
113139

114140
The other files are not source code. There are :
115141

116-
- `LICENSE` : contains the BSD license text
117-
- `Makefile` : `make` script to build and install zstd library (static and dynamic)
118142
- `BUCK` : support for `buck` build system (https://buckbuild.com/)
119-
- `libzstd.pc.in` : for `pkg-config` (used in `make install`)
143+
- `Makefile` : `make` script to build and install zstd library (static and dynamic)
120144
- `README.md` : this file
145+
- `dll/` : resources directory for Windows compilation
146+
- `libzstd.pc.in` : script for `pkg-config` (used in `make install`)

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
389389
* Read (consume) next n bits from local register and update.
390390
* Pay attention to not read more than nbBits contained into local register.
391391
* @return : extracted value. */
392-
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)
393393
{
394394
size_t const value = BIT_lookBits(bitD, nbBits);
395395
BIT_skipBits(bitD, nbBits);
@@ -398,7 +398,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
398398

399399
/*! BIT_readBitsFast() :
400400
* unsafe version; only works only if nbBits >= 1 */
401-
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)
402402
{
403403
size_t const value = BIT_lookBitsFast(bitD, nbBits);
404404
assert(nbBits >= 1);

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 19 additions & 12 deletions
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
@@ -89,23 +98,21 @@
8998
#endif
9099

91100
/* prefetch
92-
* can be disabled, by declaring NO_PREFETCH macro
93-
* All prefetch invocations use a single default locality 2,
94-
* generating instruction prefetcht1,
95-
* which, according to Intel, means "load data into L2 cache".
96-
* This is a good enough "middle ground" for the time being,
97-
* though in theory, it would be better to specialize locality depending on data being prefetched.
98-
* Tests could not determine any sensible difference based on locality value. */
101+
* can be disabled, by declaring NO_PREFETCH build macro */
99102
#if defined(NO_PREFETCH)
100-
# define PREFETCH(ptr) (void)(ptr) /* disabled */
103+
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
104+
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
101105
#else
102106
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
103107
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
104-
# define PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
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)
105110
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
106-
# define PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
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 */)
107113
# else
108-
# define PREFETCH(ptr) (void)(ptr) /* disabled */
114+
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
115+
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
109116
# endif
110117
#endif /* NO_PREFETCH */
111118

@@ -116,7 +123,7 @@
116123
size_t const _size = (size_t)(s); \
117124
size_t _pos; \
118125
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
119-
PREFETCH(_ptr + _pos); \
126+
PREFETCH_L2(_ptr + _pos); \
120127
} \
121128
}
122129

ext/zstdruby/libzstd/common/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
7878
__asm__(
7979
"pushl %%ebx\n\t"
8080
"cpuid\n\t"
81-
"movl %%ebx, %%eax\n\r"
81+
"movl %%ebx, %%eax\n\t"
8282
"popl %%ebx"
8383
: "=a"(f7b), "=c"(f7c)
8484
: "a"(7), "c"(0)

0 commit comments

Comments
 (0)