Skip to content

Commit baa9d16

Browse files
author
haruyama-makotpo
committed
Update zstd to v1.3.4
1 parent 67d7191 commit baa9d16

Some content is hidden

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

42 files changed

+5840
-3466
lines changed

ext/zstdruby/libzstd/BUCK

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ cxx_library(
2525
name='decompress',
2626
header_namespace='',
2727
visibility=['PUBLIC'],
28+
headers=subdir_glob([
29+
('decompress', '*_impl.h'),
30+
]),
2831
srcs=glob(['decompress/zstd*.c']),
2932
deps=[
3033
':common',
@@ -80,6 +83,15 @@ cxx_library(
8083
]),
8184
)
8285

86+
cxx_library(
87+
name='cpu',
88+
header_namespace='',
89+
visibility=['PUBLIC'],
90+
exported_headers=subdir_glob([
91+
('common', 'cpu.h'),
92+
]),
93+
)
94+
8395
cxx_library(
8496
name='bitstream',
8597
header_namespace='',
@@ -196,6 +208,7 @@ cxx_library(
196208
deps=[
197209
':bitstream',
198210
':compiler',
211+
':cpu',
199212
':entropy',
200213
':errors',
201214
':mem',

ext/zstdruby/libzstd/README.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ Zstandard library files
22
================================
33

44
The __lib__ directory is split into several sub-directories,
5-
in order to make it easier to select or exclude specific features.
5+
in order to make it easier to select or exclude features.
66

77

88
#### Building
99

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

15+
`libzstd` default scope includes compression, decompression, dictionary building,
16+
and decoding support for legacy formats >= v0.4.0.
17+
1518

1619
#### API
1720

@@ -27,49 +30,54 @@ Optional advanced features are exposed via :
2730
- `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
2831
it unlocks access to advanced experimental API,
2932
exposed in second part of `zstd.h`.
30-
These APIs shall ___never be used with dynamic library___ !
31-
They are not "stable", their definition may change in the future.
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___ !
3235
Only static linking is allowed.
3336

3437

3538
#### Modular build
3639

40+
It's possible to compile only a limited set of features.
41+
3742
- Directory `lib/common` is always required, for all variants.
3843
- Compression source code lies in `lib/compress`
3944
- Decompression source code lies in `lib/decompress`
4045
- It's possible to include only `compress` or only `decompress`, they don't depend on each other.
4146
- `lib/dictBuilder` : makes it possible to generate dictionaries from a set of samples.
42-
The API is exposed in `lib/dictBuilder/zdict.h`.
43-
This module depends on both `lib/common` and `lib/compress` .
44-
- `lib/legacy` : source code to decompress older zstd formats, starting from `v0.1`.
45-
This module depends on `lib/common` and `lib/decompress`.
46-
To enable this feature, it's necessary to define `ZSTD_LEGACY_SUPPORT = 1` during compilation.
47-
Typically, with `gcc`, add argument `-DZSTD_LEGACY_SUPPORT=1`.
48-
Using higher number limits the number of version supported.
49-
For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats starting from v0.2+".
50-
The API is exposed in `lib/legacy/zstd_legacy.h`.
51-
Each version also provides a (dedicated) set of advanced API.
52-
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
47+
The API is exposed in `lib/dictBuilder/zdict.h`.
48+
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`.
50+
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.
54+
For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats >= v0.2.0".
55+
`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".
59+
Once enabled, this capability is transparently triggered within decompression functions.
60+
It's also possible to invoke directly legacy API, as exposed in `lib/legacy/zstd_legacy.h`.
61+
Each version also provides an additional dedicated set of advanced API.
62+
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
63+
Note : `lib/legacy` only supports _decoding_ legacy formats.
5364

5465

5566
#### Multithreading support
5667

5768
Multithreading is disabled by default when building with `make`.
5869
Enabling multithreading requires 2 conditions :
5970
- set macro `ZSTD_MULTITHREAD`
60-
- on POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc` for example)
71+
- on POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
6172

6273
Both conditions are automatically triggered by invoking `make lib-mt` target.
6374
Note that, when linking a POSIX program with a multithreaded version of `libzstd`,
6475
it's necessary to trigger `-pthread` flag during link stage.
6576

66-
Multithreading capabilities are exposed via :
67-
- private API `lib/compress/zstdmt_compress.h`.
68-
Symbols defined in this header are currently exposed in `libzstd`, hence usable.
69-
Note however that this API is planned to be locked and remain strictly internal in the future.
70-
- advanced API `ZSTD_compress_generic()`, defined in `lib/zstd.h`, experimental section.
71-
This API is still considered experimental, but is designed to be labelled "stable" at some point in the future.
72-
It's the recommended entry point for multi-threading operations.
77+
Multithreading capabilities are exposed
78+
via [advanced API `ZSTD_compress_generic()` defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/dev/lib/zstd.h#L919).
79+
This API is still considered experimental,
80+
but is expected to become "stable" at some point in the future.
7381

7482

7583
#### Windows : using MinGW+MSYS to create DLL
@@ -92,7 +100,6 @@ The compiled executable will require ZSTD DLL which is available at `dll\libzstd
92100

93101
Obsolete API on their way out are stored in directory `lib/deprecated`.
94102
At this stage, it contains older streaming prototypes, in `lib/deprecated/zbuff.h`.
95-
Presence in this directory is temporary.
96103
These prototypes will be removed in some future version.
97104
Consider migrating code towards supported streaming API exposed in `zstd.h`.
98105

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
426426
* Refill `bitD` from buffer previously set in BIT_initDStream() .
427427
* This function is safe, it guarantees it will not read beyond src buffer.
428428
* @return : status of `BIT_DStream_t` internal register.
429-
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
429+
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
430430
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
431431
{
432432
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@
6363
# endif
6464
#endif
6565

66+
/* target attribute */
67+
#ifndef __has_attribute
68+
#define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
69+
#endif
70+
#if defined(__GNUC__)
71+
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
72+
#else
73+
# define TARGET_ATTRIBUTE(target)
74+
#endif
75+
76+
/* Enable runtime BMI2 dispatch based on the CPU.
77+
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
78+
*/
79+
#ifndef DYNAMIC_BMI2
80+
#if (defined(__clang__) && __has_attribute(__target__)) \
81+
|| (defined(__GNUC__) \
82+
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \
83+
&& (defined(__x86_64__) || defined(_M_X86)) \
84+
&& !defined(__BMI2__)
85+
# define DYNAMIC_BMI2 1
86+
#else
87+
# define DYNAMIC_BMI2 0
88+
#endif
89+
#endif
90+
6691
/* prefetch */
6792
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
6893
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */

ext/zstdruby/libzstd/common/cpu.h

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
* Copyright (c) 2018-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under both the BSD-style license (found in the
6+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
7+
* in the COPYING file in the root directory of this source tree).
8+
* You may select, at your option, one of the above-listed licenses.
9+
*/
10+
11+
#ifndef ZSTD_COMMON_CPU_H
12+
#define ZSTD_COMMON_CPU_H
13+
14+
/**
15+
* Implementation taken from folly/CpuId.h
16+
* https://github.com/facebook/folly/blob/master/folly/CpuId.h
17+
*/
18+
19+
#include <string.h>
20+
21+
#include "mem.h"
22+
23+
#ifdef _MSC_VER
24+
#include <intrin.h>
25+
#endif
26+
27+
typedef struct {
28+
U32 f1c;
29+
U32 f1d;
30+
U32 f7b;
31+
U32 f7c;
32+
} ZSTD_cpuid_t;
33+
34+
MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
35+
U32 f1c = 0;
36+
U32 f1d = 0;
37+
U32 f7b = 0;
38+
U32 f7c = 0;
39+
#ifdef _MSC_VER
40+
int reg[4];
41+
__cpuid((int*)reg, 0);
42+
{
43+
int const n = reg[0];
44+
if (n >= 1) {
45+
__cpuid((int*)reg, 1);
46+
f1c = (U32)reg[2];
47+
f1d = (U32)reg[3];
48+
}
49+
if (n >= 7) {
50+
__cpuidex((int*)reg, 7, 0);
51+
f7b = (U32)reg[1];
52+
f7c = (U32)reg[2];
53+
}
54+
}
55+
#elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
56+
/* The following block like the normal cpuid branch below, but gcc
57+
* reserves ebx for use of its pic register so we must specially
58+
* handle the save and restore to avoid clobbering the register
59+
*/
60+
U32 n;
61+
__asm__(
62+
"pushl %%ebx\n\t"
63+
"cpuid\n\t"
64+
"popl %%ebx\n\t"
65+
: "=a"(n)
66+
: "a"(0)
67+
: "ecx", "edx");
68+
if (n >= 1) {
69+
U32 f1a;
70+
__asm__(
71+
"pushl %%ebx\n\t"
72+
"cpuid\n\t"
73+
"popl %%ebx\n\t"
74+
: "=a"(f1a), "=c"(f1c), "=d"(f1d)
75+
: "a"(1)
76+
:);
77+
}
78+
if (n >= 7) {
79+
__asm__(
80+
"pushl %%ebx\n\t"
81+
"cpuid\n\t"
82+
"movl %%ebx, %%eax\n\r"
83+
"popl %%ebx"
84+
: "=a"(f7b), "=c"(f7c)
85+
: "a"(7), "c"(0)
86+
: "edx");
87+
}
88+
#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__)
89+
U32 n;
90+
__asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx");
91+
if (n >= 1) {
92+
U32 f1a;
93+
__asm__("cpuid" : "=a"(f1a), "=c"(f1c), "=d"(f1d) : "a"(1) : "ebx");
94+
}
95+
if (n >= 7) {
96+
U32 f7a;
97+
__asm__("cpuid"
98+
: "=a"(f7a), "=b"(f7b), "=c"(f7c)
99+
: "a"(7), "c"(0)
100+
: "edx");
101+
}
102+
#endif
103+
{
104+
ZSTD_cpuid_t cpuid;
105+
cpuid.f1c = f1c;
106+
cpuid.f1d = f1d;
107+
cpuid.f7b = f7b;
108+
cpuid.f7c = f7c;
109+
return cpuid;
110+
}
111+
}
112+
113+
#define X(name, r, bit) \
114+
MEM_STATIC int ZSTD_cpuid_##name(ZSTD_cpuid_t const cpuid) { \
115+
return ((cpuid.r) & (1U << bit)) != 0; \
116+
}
117+
118+
/* cpuid(1): Processor Info and Feature Bits. */
119+
#define C(name, bit) X(name, f1c, bit)
120+
C(sse3, 0)
121+
C(pclmuldq, 1)
122+
C(dtes64, 2)
123+
C(monitor, 3)
124+
C(dscpl, 4)
125+
C(vmx, 5)
126+
C(smx, 6)
127+
C(eist, 7)
128+
C(tm2, 8)
129+
C(ssse3, 9)
130+
C(cnxtid, 10)
131+
C(fma, 12)
132+
C(cx16, 13)
133+
C(xtpr, 14)
134+
C(pdcm, 15)
135+
C(pcid, 17)
136+
C(dca, 18)
137+
C(sse41, 19)
138+
C(sse42, 20)
139+
C(x2apic, 21)
140+
C(movbe, 22)
141+
C(popcnt, 23)
142+
C(tscdeadline, 24)
143+
C(aes, 25)
144+
C(xsave, 26)
145+
C(osxsave, 27)
146+
C(avx, 28)
147+
C(f16c, 29)
148+
C(rdrand, 30)
149+
#undef C
150+
#define D(name, bit) X(name, f1d, bit)
151+
D(fpu, 0)
152+
D(vme, 1)
153+
D(de, 2)
154+
D(pse, 3)
155+
D(tsc, 4)
156+
D(msr, 5)
157+
D(pae, 6)
158+
D(mce, 7)
159+
D(cx8, 8)
160+
D(apic, 9)
161+
D(sep, 11)
162+
D(mtrr, 12)
163+
D(pge, 13)
164+
D(mca, 14)
165+
D(cmov, 15)
166+
D(pat, 16)
167+
D(pse36, 17)
168+
D(psn, 18)
169+
D(clfsh, 19)
170+
D(ds, 21)
171+
D(acpi, 22)
172+
D(mmx, 23)
173+
D(fxsr, 24)
174+
D(sse, 25)
175+
D(sse2, 26)
176+
D(ss, 27)
177+
D(htt, 28)
178+
D(tm, 29)
179+
D(pbe, 31)
180+
#undef D
181+
182+
/* cpuid(7): Extended Features. */
183+
#define B(name, bit) X(name, f7b, bit)
184+
B(bmi1, 3)
185+
B(hle, 4)
186+
B(avx2, 5)
187+
B(smep, 7)
188+
B(bmi2, 8)
189+
B(erms, 9)
190+
B(invpcid, 10)
191+
B(rtm, 11)
192+
B(mpx, 14)
193+
B(avx512f, 16)
194+
B(avx512dq, 17)
195+
B(rdseed, 18)
196+
B(adx, 19)
197+
B(smap, 20)
198+
B(avx512ifma, 21)
199+
B(pcommit, 22)
200+
B(clflushopt, 23)
201+
B(clwb, 24)
202+
B(avx512pf, 26)
203+
B(avx512er, 27)
204+
B(avx512cd, 28)
205+
B(sha, 29)
206+
B(avx512bw, 30)
207+
B(avx512vl, 31)
208+
#undef B
209+
#define C(name, bit) X(name, f7c, bit)
210+
C(prefetchwt1, 0)
211+
C(avx512vbmi, 1)
212+
#undef C
213+
214+
#undef X
215+
216+
#endif /* ZSTD_COMMON_CPU_H */

0 commit comments

Comments
 (0)