Skip to content

Commit be69af5

Browse files
authored
Merge pull request #17 from SpringMT/update-zstd-for-v1.3.7
Update zstd for v1.3.7
2 parents 0ca4b99 + 1ccb930 commit be69af5

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

+2246
-914
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
sudo: false
22
language: ruby
33
rvm:
4-
- 2.4.1
5-
- 2.3.3
4+
- 2.6.0
5+
- 2.5.3
6+
- 2.4.5
7+
- 2.3.8
68
- 2.2
79

810
before_install: gem install bundler -v 1.14.3

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.5 (https://github.com/facebook/zstd/tree/v1.3.5)
13+
v1.3.7 (https://github.com/facebook/zstd/tree/v1.3.7)
1414

1515
## Installation
1616

ext/zstdruby/libzstd/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ cxx_library(
6969
]),
7070
headers=subdir_glob([
7171
('dictBuilder', 'divsufsort.h'),
72+
('dictBuilder', 'cover.h'),
7273
]),
7374
srcs=glob(['dictBuilder/*.c']),
7475
deps=[':common'],

ext/zstdruby/libzstd/Makefile

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
1919
VERSION?= $(LIBVER)
2020

2121
CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
22+
ifeq ($(OS),Windows_NT) # MinGW assumed
23+
CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
24+
endif
2225
CFLAGS ?= -O3
23-
DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26+
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
2427
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
2528
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
2629
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
27-
-Wredundant-decls
30+
-Wredundant-decls -Wmissing-prototypes
2831
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
2932
FLAGS = $(CPPFLAGS) $(CFLAGS)
3033

34+
GREP = grep --color=never
35+
3136
ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
3237
ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
3338
ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
3439
ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
3540
ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
3641
ZSTD_FILES := $(ZSTDCOMMON_FILES)
3742

38-
ZSTD_LEGACY_SUPPORT ?= 4
43+
ZSTD_LEGACY_SUPPORT ?= 5
3944
ZSTD_LIB_COMPRESSION ?= 1
4045
ZSTD_LIB_DECOMPRESSION ?= 1
4146
ZSTD_LIB_DICTBUILDER ?= 1
@@ -52,11 +57,11 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
5257
endif
5358

5459
ifneq ($(ZSTD_LIB_COMPRESSION), 0)
55-
ZSTD_FILES += $(ZSTDCOMP_FILES)
60+
ZSTD_FILES += $(ZSTDCOMP_FILES)
5661
endif
5762

5863
ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
59-
ZSTD_FILES += $(ZSTDDECOMP_FILES)
64+
ZSTD_FILES += $(ZSTDDECOMP_FILES)
6065
endif
6166

6267
ifneq ($(ZSTD_LIB_DEPRECATED), 0)
@@ -69,7 +74,7 @@ endif
6974

7075
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
7176
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
72-
ZSTD_FILES += $(shell ls legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
77+
ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
7378
endif
7479
CPPFLAGS += -I./legacy
7580
endif
@@ -91,8 +96,6 @@ else
9196
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
9297
endif
9398

94-
LIBZSTD = libzstd.$(SHARED_EXT_VER)
95-
9699

97100
.PHONY: default all clean install uninstall
98101

@@ -108,19 +111,28 @@ libzstd.a: $(ZSTD_OBJ)
108111
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
109112
libzstd.a-mt: libzstd.a
110113

111-
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
114+
ifneq (,$(filter Windows%,$(OS)))
115+
116+
LIBZSTD = dll\libzstd.dll
112117
$(LIBZSTD): $(ZSTD_FILES)
113118
@echo compiling dynamic library $(LIBVER)
114-
ifneq (,$(filter Windows%,$(OS)))
115-
@$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll
116-
dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib
119+
@$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o $@
120+
dlltool -D $@ -d dll\libzstd.def -l dll\libzstd.lib
121+
117122
else
123+
124+
LIBZSTD = libzstd.$(SHARED_EXT_VER)
125+
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
126+
$(LIBZSTD): $(ZSTD_FILES)
127+
@echo compiling dynamic library $(LIBVER)
118128
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
119129
@echo creating versioned links
120130
@ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
121131
@ln -sf $@ libzstd.$(SHARED_EXT)
132+
122133
endif
123134

135+
124136
libzstd : $(LIBZSTD)
125137

126138
libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
@@ -154,7 +166,7 @@ clean:
154166
#-----------------------------------------------------------------------------
155167
# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
156168
#-----------------------------------------------------------------------------
157-
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
169+
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
158170

159171
DESTDIR ?=
160172
# directory variables : GNU conventions prefer lowercase

ext/zstdruby/libzstd/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ including commands variables, staged install, directory variables and standard t
1313
- `make install` : install libraries in default system directories
1414

1515
`libzstd` default scope includes compression, decompression, dictionary building,
16-
and decoding support for legacy formats >= v0.4.0.
16+
and decoding support for legacy formats >= v0.5.0.
1717

1818

1919
#### API
@@ -48,23 +48,24 @@ It's possible to compile only a limited set of features.
4848
This module depends on both `lib/common` and `lib/compress` .
4949
- `lib/legacy` : source code to decompress legacy zstd formats, starting from `v0.1.0`.
5050
This module depends on `lib/common` and `lib/decompress`.
51-
To enable this feature, it's required to define `ZSTD_LEGACY_SUPPORT` during compilation.
52-
Typically, with `gcc`, add argument `-DZSTD_LEGACY_SUPPORT=1`.
53-
Using higher number limits versions supported.
51+
To enable this feature, define `ZSTD_LEGACY_SUPPORT` during compilation.
52+
Specifying a number limits versions supported to that version onward.
5453
For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats >= v0.2.0".
5554
`ZSTD_LEGACY_SUPPORT=3` means : "support legacy formats >= v0.3.0", and so on.
56-
Starting v0.8.0, all versions of `zstd` produce frames compliant with specification.
57-
As a consequence, `ZSTD_LEGACY_SUPPORT=8` (or more) doesn't trigger legacy support.
58-
Also, `ZSTD_LEGACY_SUPPORT=0` means "do __not__ support legacy formats".
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".
5960
Once enabled, this capability is transparently triggered within decompression functions.
6061
It's also possible to invoke directly legacy API, as exposed in `lib/legacy/zstd_legacy.h`.
6162
Each version also provides an additional dedicated set of advanced API.
6263
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
6364
Note : `lib/legacy` only supports _decoding_ legacy formats.
64-
- Similarly, you can define `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
65-
and `ZSTD_LIB_DEPRECATED` as 0 to forgo compilation of the corresponding features. This will
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
6667
also disable compilation of all dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable
67-
dictBuilder).
68+
dictBuilder).
6869

6970

7071
#### Multithreading support

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,10 @@ MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
339339

340340
MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
341341
{
342-
#if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008 /* experimental */
343-
# if defined(__x86_64__)
344-
if (sizeof(bitContainer)==8)
345-
return _bextr_u64(bitContainer, start, nbBits);
346-
else
347-
# endif
348-
return _bextr_u32(bitContainer, start, nbBits);
349-
#else
342+
U32 const regMask = sizeof(bitContainer)*8 - 1;
343+
/* if start > regMask, bitstream is corrupted, and result is undefined */
350344
assert(nbBits < BIT_MASK_SIZE);
351-
return (bitContainer >> start) & BIT_mask[nbBits];
352-
#endif
345+
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
353346
}
354347

355348
MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
@@ -366,9 +359,13 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
366359
* @return : value extracted */
367360
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
368361
{
369-
#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 */
370366
return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits);
371367
#else
368+
/* this code path is slower on my os-x laptop */
372369
U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
373370
return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask);
374371
#endif

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,37 @@
8888
#endif
8989
#endif
9090

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__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
96-
# define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
91+
/* 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. */
99+
#if defined(NO_PREFETCH)
100+
# define PREFETCH(ptr) (void)(ptr) /* disabled */
97101
#else
98-
# define PREFETCH(ptr) /* disabled */
99-
#endif
102+
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
103+
# 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)
105+
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
106+
# define PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
107+
# else
108+
# define PREFETCH(ptr) (void)(ptr) /* disabled */
109+
# endif
110+
#endif /* NO_PREFETCH */
111+
112+
#define CACHELINE_SIZE 64
113+
114+
#define PREFETCH_AREA(p, s) { \
115+
const char* const _ptr = (const char*)(p); \
116+
size_t const _size = (size_t)(s); \
117+
size_t _pos; \
118+
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
119+
PREFETCH(_ptr + _pos); \
120+
} \
121+
}
100122

101123
/* disable warnings */
102124
#ifdef _MSC_VER /* Visual Studio */

ext/zstdruby/libzstd/common/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
3636
U32 f1d = 0;
3737
U32 f7b = 0;
3838
U32 f7c = 0;
39-
#ifdef _MSC_VER
39+
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
4040
int reg[4];
4141
__cpuid((int*)reg, 0);
4242
{

ext/zstdruby/libzstd/common/mem.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ extern "C" {
3939
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
4040
#endif
4141

42+
#ifndef __has_builtin
43+
# define __has_builtin(x) 0 /* compat. with non-clang compilers */
44+
#endif
45+
4246
/* code only tested on 32 and 64 bits systems */
4347
#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
4448
MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
@@ -57,11 +61,23 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
5761
typedef uint64_t U64;
5862
typedef int64_t S64;
5963
#else
64+
# include <limits.h>
65+
#if CHAR_BIT != 8
66+
# error "this implementation requires char to be exactly 8-bit type"
67+
#endif
6068
typedef unsigned char BYTE;
69+
#if USHRT_MAX != 65535
70+
# error "this implementation requires short to be exactly 16-bit type"
71+
#endif
6172
typedef unsigned short U16;
6273
typedef signed short S16;
74+
#if UINT_MAX != 4294967295
75+
# error "this implementation requires int to be exactly 32-bit type"
76+
#endif
6377
typedef unsigned int U32;
6478
typedef signed int S32;
79+
/* note : there are no limits defined for long long type in C90.
80+
* limits exist in C99, however, in such case, <stdint.h> is preferred */
6581
typedef unsigned long long U64;
6682
typedef signed long long S64;
6783
#endif
@@ -186,7 +202,8 @@ MEM_STATIC U32 MEM_swap32(U32 in)
186202
{
187203
#if defined(_MSC_VER) /* Visual Studio */
188204
return _byteswap_ulong(in);
189-
#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
205+
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
206+
|| (defined(__clang__) && __has_builtin(__builtin_bswap32))
190207
return __builtin_bswap32(in);
191208
#else
192209
return ((in << 24) & 0xff000000 ) |
@@ -200,7 +217,8 @@ MEM_STATIC U64 MEM_swap64(U64 in)
200217
{
201218
#if defined(_MSC_VER) /* Visual Studio */
202219
return _byteswap_uint64(in);
203-
#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
220+
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
221+
|| (defined(__clang__) && __has_builtin(__builtin_bswap64))
204222
return __builtin_bswap64(in);
205223
#else
206224
return ((in << 56) & 0xff00000000000000ULL) |

ext/zstdruby/libzstd/common/xxhash.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
/* Modify the local functions below should you wish to use some other memory routines */
9999
/* for malloc(), free() */
100100
#include <stdlib.h>
101+
#include <stddef.h> /* size_t */
101102
static void* XXH_malloc(size_t s) { return malloc(s); }
102103
static void XXH_free (void* p) { free(p); }
103104
/* for memcpy() */

0 commit comments

Comments
 (0)