Skip to content

Commit f725127

Browse files
nodejs-github-botRafaelGSS
authored andcommitted
deps: update zstd to 1.5.7
PR-URL: #57940 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fd6adb7 commit f725127

Some content is hidden

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

62 files changed

+2860
-1572
lines changed

deps/zstd/lib/Makefile

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi
6363
LDFLAGS_DYNLIB += -pthread
6464
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
6565

66+
# pkg-config Libs.private points to LDFLAGS_DYNLIB
67+
PCLIB := $(LDFLAGS_DYNLIB)
6668

6769
ifeq ($(findstring GCC,$(CCVER)),GCC)
6870
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
@@ -71,13 +73,15 @@ endif
7173

7274
# macOS linker doesn't support -soname, and use different extension
7375
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
74-
ifeq ($(UNAME), Darwin)
76+
UNAME_TARGET_SYSTEM ?= $(UNAME)
77+
78+
ifeq ($(UNAME_TARGET_SYSTEM), Darwin)
7579
SHARED_EXT = dylib
7680
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
7781
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
7882
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
7983
else
80-
ifeq ($(UNAME), AIX)
84+
ifeq ($(UNAME_TARGET_SYSTEM), AIX)
8185
SONAME_FLAGS =
8286
else
8387
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
@@ -186,12 +190,15 @@ lib : libzstd.a libzstd
186190
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
187191
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
188192
%-mt : LDFLAGS_DYNLIB := -pthread
193+
%-mt : PCLIB :=
194+
%-mt : PCMTLIB := $(LDFLAGS_DYNLIB)
189195
%-mt : %
190196
@echo multi-threaded build completed
191197

192198
%-nomt : CPPFLAGS_DYNLIB :=
193199
%-nomt : LDFLAGS_DYNLIB :=
194200
%-nomt : CPPFLAGS_STATICLIB :=
201+
%-nomt : PCLIB :=
195202
%-nomt : %
196203
@echo single-threaded build completed
197204

@@ -261,7 +268,7 @@ clean:
261268
#-----------------------------------------------------------------------------
262269
# make install is validated only for below listed environments
263270
#-----------------------------------------------------------------------------
264-
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT))
271+
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME)))
265272

266273
lib: libzstd.pc
267274

@@ -292,13 +299,21 @@ PCLIBPREFIX := $(if $(findstring $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
292299
# to PREFIX, rather than as a resolved value.
293300
PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix})
294301

295-
ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
302+
303+
ifneq ($(MT),)
304+
PCLIB :=
305+
PCMTLIB := $(LDFLAGS_DYNLIB)
306+
else
307+
PCLIB := $(LDFLAGS_DYNLIB)
308+
endif
309+
310+
ifneq (,$(filter FreeBSD NetBSD DragonFly,$(UNAME)))
296311
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
297312
else
298313
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
299314
endif
300315

301-
ifneq (,$(filter $(UNAME),SunOS))
316+
ifneq (,$(filter SunOS,$(UNAME)))
302317
INSTALL ?= ginstall
303318
else
304319
INSTALL ?= install
@@ -308,6 +323,10 @@ INSTALL_PROGRAM ?= $(INSTALL)
308323
INSTALL_DATA ?= $(INSTALL) -m 644
309324

310325

326+
# pkg-config library define.
327+
# For static single-threaded library declare -pthread in Libs.private
328+
# For static multi-threaded library declare -pthread in Libs and Cflags
329+
.PHONY: libzstd.pc
311330
libzstd.pc: libzstd.pc.in
312331
@echo creating pkgconfig
313332
@sed \
@@ -316,7 +335,8 @@ libzstd.pc: libzstd.pc.in
316335
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
317336
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
318337
-e 's|@VERSION@|$(VERSION)|' \
319-
-e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
338+
-e 's|@LIBS_MT@|$(PCMTLIB)|' \
339+
-e 's|@LIBS_PRIVATE@|$(PCLIB)|' \
320340
$< >$@
321341

322342
.PHONY: install

deps/zstd/lib/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ Enabling multithreading requires 2 conditions :
2727

2828
For convenience, we provide a build target to generate multi and single threaded libraries:
2929
- Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`.
30+
Note that the `.pc` generated on calling `make lib-mt` will already include the require Libs and Cflags.
3031
- Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`.
3132
- By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`.
3233

3334
When linking a POSIX program with a multithreaded version of `libzstd`,
3435
note that it's necessary to invoke the `-pthread` flag during link stage.
3536

37+
The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library
38+
is compiled. To correctly generate a `.pc` for the multi-threaded static library, set `MT=1` as ENV variable.
39+
3640
Multithreading capabilities are exposed
3741
via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351).
3842

@@ -145,6 +149,13 @@ The file structure is designed to make this selection manually achievable for an
145149
will expose the deprecated `ZSTDMT` API exposed by `zstdmt_compress.h` in
146150
the shared library, which is now hidden by default.
147151

152+
- The build macro `STATIC_BMI2` can be set to 1 to force usage of `bmi2` instructions.
153+
It is generally not necessary to set this build macro,
154+
because `STATIC_BMI2` will be automatically set to 1
155+
on detecting the presence of the corresponding instruction set in the compilation target.
156+
It's nonetheless available as an optional manual toggle for better control,
157+
and can also be used to forcefully disable `bmi2` instructions by setting it to 0.
158+
148159
- The build macro `DYNAMIC_BMI2` can be set to 1 or 0 in order to generate binaries
149160
which can detect at runtime the presence of BMI2 instructions, and use them only if present.
150161
These instructions contribute to better performance, notably on the decoder side.

deps/zstd/lib/common/bits.h

Lines changed: 92 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
2828
MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
2929
{
3030
assert(val != 0);
31-
# if defined(_MSC_VER)
32-
# if STATIC_BMI2 == 1
33-
return (unsigned)_tzcnt_u32(val);
34-
# else
35-
if (val != 0) {
36-
unsigned long r;
37-
_BitScanForward(&r, val);
38-
return (unsigned)r;
39-
} else {
40-
/* Should not reach this code path */
41-
__assume(0);
42-
}
43-
# endif
44-
# elif defined(__GNUC__) && (__GNUC__ >= 4)
45-
return (unsigned)__builtin_ctz(val);
46-
# else
47-
return ZSTD_countTrailingZeros32_fallback(val);
48-
# endif
31+
#if defined(_MSC_VER)
32+
# if STATIC_BMI2
33+
return (unsigned)_tzcnt_u32(val);
34+
# else
35+
if (val != 0) {
36+
unsigned long r;
37+
_BitScanForward(&r, val);
38+
return (unsigned)r;
39+
} else {
40+
__assume(0); /* Should not reach this code path */
41+
}
42+
# endif
43+
#elif defined(__GNUC__) && (__GNUC__ >= 4)
44+
return (unsigned)__builtin_ctz(val);
45+
#elif defined(__ICCARM__)
46+
return (unsigned)__builtin_ctz(val);
47+
#else
48+
return ZSTD_countTrailingZeros32_fallback(val);
49+
#endif
4950
}
5051

51-
MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val) {
52+
MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val)
53+
{
5254
assert(val != 0);
5355
{
5456
static const U32 DeBruijnClz[32] = {0, 9, 1, 10, 13, 21, 2, 29,
@@ -67,86 +69,89 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val) {
6769
MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
6870
{
6971
assert(val != 0);
70-
# if defined(_MSC_VER)
71-
# if STATIC_BMI2 == 1
72-
return (unsigned)_lzcnt_u32(val);
73-
# else
74-
if (val != 0) {
75-
unsigned long r;
76-
_BitScanReverse(&r, val);
77-
return (unsigned)(31 - r);
78-
} else {
79-
/* Should not reach this code path */
80-
__assume(0);
81-
}
82-
# endif
83-
# elif defined(__GNUC__) && (__GNUC__ >= 4)
84-
return (unsigned)__builtin_clz(val);
85-
# else
86-
return ZSTD_countLeadingZeros32_fallback(val);
87-
# endif
72+
#if defined(_MSC_VER)
73+
# if STATIC_BMI2
74+
return (unsigned)_lzcnt_u32(val);
75+
# else
76+
if (val != 0) {
77+
unsigned long r;
78+
_BitScanReverse(&r, val);
79+
return (unsigned)(31 - r);
80+
} else {
81+
__assume(0); /* Should not reach this code path */
82+
}
83+
# endif
84+
#elif defined(__GNUC__) && (__GNUC__ >= 4)
85+
return (unsigned)__builtin_clz(val);
86+
#elif defined(__ICCARM__)
87+
return (unsigned)__builtin_clz(val);
88+
#else
89+
return ZSTD_countLeadingZeros32_fallback(val);
90+
#endif
8891
}
8992

9093
MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
9194
{
9295
assert(val != 0);
93-
# if defined(_MSC_VER) && defined(_WIN64)
94-
# if STATIC_BMI2 == 1
95-
return (unsigned)_tzcnt_u64(val);
96-
# else
97-
if (val != 0) {
98-
unsigned long r;
99-
_BitScanForward64(&r, val);
100-
return (unsigned)r;
101-
} else {
102-
/* Should not reach this code path */
103-
__assume(0);
104-
}
105-
# endif
106-
# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__)
107-
return (unsigned)__builtin_ctzll(val);
108-
# else
109-
{
110-
U32 mostSignificantWord = (U32)(val >> 32);
111-
U32 leastSignificantWord = (U32)val;
112-
if (leastSignificantWord == 0) {
113-
return 32 + ZSTD_countTrailingZeros32(mostSignificantWord);
114-
} else {
115-
return ZSTD_countTrailingZeros32(leastSignificantWord);
116-
}
96+
#if defined(_MSC_VER) && defined(_WIN64)
97+
# if STATIC_BMI2
98+
return (unsigned)_tzcnt_u64(val);
99+
# else
100+
if (val != 0) {
101+
unsigned long r;
102+
_BitScanForward64(&r, val);
103+
return (unsigned)r;
104+
} else {
105+
__assume(0); /* Should not reach this code path */
106+
}
107+
# endif
108+
#elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__)
109+
return (unsigned)__builtin_ctzll(val);
110+
#elif defined(__ICCARM__)
111+
return (unsigned)__builtin_ctzll(val);
112+
#else
113+
{
114+
U32 mostSignificantWord = (U32)(val >> 32);
115+
U32 leastSignificantWord = (U32)val;
116+
if (leastSignificantWord == 0) {
117+
return 32 + ZSTD_countTrailingZeros32(mostSignificantWord);
118+
} else {
119+
return ZSTD_countTrailingZeros32(leastSignificantWord);
117120
}
118-
# endif
121+
}
122+
#endif
119123
}
120124

121125
MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
122126
{
123127
assert(val != 0);
124-
# if defined(_MSC_VER) && defined(_WIN64)
125-
# if STATIC_BMI2 == 1
126-
return (unsigned)_lzcnt_u64(val);
127-
# else
128-
if (val != 0) {
129-
unsigned long r;
130-
_BitScanReverse64(&r, val);
131-
return (unsigned)(63 - r);
132-
} else {
133-
/* Should not reach this code path */
134-
__assume(0);
135-
}
136-
# endif
137-
# elif defined(__GNUC__) && (__GNUC__ >= 4)
138-
return (unsigned)(__builtin_clzll(val));
139-
# else
140-
{
141-
U32 mostSignificantWord = (U32)(val >> 32);
142-
U32 leastSignificantWord = (U32)val;
143-
if (mostSignificantWord == 0) {
144-
return 32 + ZSTD_countLeadingZeros32(leastSignificantWord);
145-
} else {
146-
return ZSTD_countLeadingZeros32(mostSignificantWord);
147-
}
128+
#if defined(_MSC_VER) && defined(_WIN64)
129+
# if STATIC_BMI2
130+
return (unsigned)_lzcnt_u64(val);
131+
# else
132+
if (val != 0) {
133+
unsigned long r;
134+
_BitScanReverse64(&r, val);
135+
return (unsigned)(63 - r);
136+
} else {
137+
__assume(0); /* Should not reach this code path */
138+
}
139+
# endif
140+
#elif defined(__GNUC__) && (__GNUC__ >= 4)
141+
return (unsigned)(__builtin_clzll(val));
142+
#elif defined(__ICCARM__)
143+
return (unsigned)(__builtin_clzll(val));
144+
#else
145+
{
146+
U32 mostSignificantWord = (U32)(val >> 32);
147+
U32 leastSignificantWord = (U32)val;
148+
if (mostSignificantWord == 0) {
149+
return 32 + ZSTD_countLeadingZeros32(leastSignificantWord);
150+
} else {
151+
return ZSTD_countLeadingZeros32(mostSignificantWord);
148152
}
149-
# endif
153+
}
154+
#endif
150155
}
151156

152157
MEM_STATIC unsigned ZSTD_NbCommonBytes(size_t val)

0 commit comments

Comments
 (0)