zstd-ruby 1.5.0.0 → 1.5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -2
  3. data/README.md +1 -1
  4. data/ext/zstdruby/extconf.rb +1 -0
  5. data/ext/zstdruby/libzstd/Makefile +50 -175
  6. data/ext/zstdruby/libzstd/README.md +7 -1
  7. data/ext/zstdruby/libzstd/common/bitstream.h +24 -9
  8. data/ext/zstdruby/libzstd/common/compiler.h +89 -43
  9. data/ext/zstdruby/libzstd/common/entropy_common.c +11 -5
  10. data/ext/zstdruby/libzstd/common/error_private.h +79 -0
  11. data/ext/zstdruby/libzstd/common/fse.h +2 -1
  12. data/ext/zstdruby/libzstd/common/fse_decompress.c +1 -1
  13. data/ext/zstdruby/libzstd/common/huf.h +24 -22
  14. data/ext/zstdruby/libzstd/common/mem.h +18 -0
  15. data/ext/zstdruby/libzstd/common/portability_macros.h +131 -0
  16. data/ext/zstdruby/libzstd/common/xxhash.c +5 -805
  17. data/ext/zstdruby/libzstd/common/xxhash.h +5568 -167
  18. data/ext/zstdruby/libzstd/common/zstd_internal.h +92 -88
  19. data/ext/zstdruby/libzstd/common/zstd_trace.h +12 -3
  20. data/ext/zstdruby/libzstd/compress/clevels.h +134 -0
  21. data/ext/zstdruby/libzstd/compress/fse_compress.c +63 -27
  22. data/ext/zstdruby/libzstd/compress/huf_compress.c +537 -104
  23. data/ext/zstdruby/libzstd/compress/zstd_compress.c +194 -278
  24. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +102 -44
  25. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +4 -3
  26. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +3 -1
  27. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +5 -4
  28. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +3 -2
  29. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +3 -3
  30. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +289 -114
  31. data/ext/zstdruby/libzstd/compress/zstd_fast.c +302 -123
  32. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +418 -502
  33. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +4 -4
  34. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +1 -1
  35. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +4 -1
  36. data/ext/zstdruby/libzstd/compress/zstd_opt.c +186 -108
  37. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +59 -29
  38. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +727 -189
  39. data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +571 -0
  40. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +85 -22
  41. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +744 -220
  42. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -2
  43. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +34 -3
  44. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +23 -3
  45. data/ext/zstdruby/libzstd/dictBuilder/cover.c +9 -2
  46. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +11 -4
  47. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +99 -28
  48. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +2 -6
  49. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +3 -7
  50. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +3 -7
  51. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +3 -7
  52. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +3 -7
  53. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +3 -7
  54. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +3 -7
  55. data/ext/zstdruby/libzstd/libzstd.mk +185 -0
  56. data/ext/zstdruby/libzstd/libzstd.pc.in +1 -0
  57. data/ext/zstdruby/libzstd/modulemap/module.modulemap +4 -0
  58. data/ext/zstdruby/libzstd/zdict.h +4 -4
  59. data/ext/zstdruby/libzstd/zstd.h +179 -136
  60. data/ext/zstdruby/zstdruby.c +2 -2
  61. data/lib/zstd-ruby/version.rb +1 -1
  62. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32e9b82b8d17f82c2e75104bbac8b5a63a510d1e46af93d31b103534cf947e40
4
- data.tar.gz: 264b1409dd10bc7ba8436576a1de143116b2d4616a24d58e66bb7e1ccd024b98
3
+ metadata.gz: 9c5390f204466dadf3276d3d7841d5dcc0c2be4f9cdafd11be705b6304b8cb27
4
+ data.tar.gz: 3538385c093224f15c6199ae51cdedb944a1b6e0ff4e9c3287ea907911fb07b9
5
5
  SHA512:
6
- metadata.gz: 736aaee9390871b6dfb7a03254c2c3cf86ccb2e2f46936cc147e4b3772438591f11a589e6f38fbd52c24214007a9d2293ddb9fe987dba84912608af802f179f9
7
- data.tar.gz: a9c3846d7ae00794301da5dce514b2f6ef90cea9a3cc293659a4d7f1bc54de82973ad90c86a388967eddb6466449cccacc5094f170b21870ffeb0208329c393d
6
+ metadata.gz: 8fc0f3ca375ee6b9fd6564eb0807c8d9e5c0f39e19ba9a9692d07c28e55e2fc70a625d3dc682ae402eb7bce76caf114f0c5b103a047f46c88b033bc2bdccc52f
7
+ data.tar.gz: 2bdb03fade1bca81eedcac96a63b5cbaea4774373f06f483ce77978a3795241e523905b6845c5fac0c70465df3575691e70441cca7a68b7f32b81202c82e69c0
@@ -15,7 +15,7 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby-version: ['2.5', '2.6', '2.7', '3.0']
18
+ ruby-version: ['2.6', '2.7', '3.0', '3.1']
19
19
 
20
20
  steps:
21
21
  - uses: actions/checkout@v2
@@ -23,7 +23,7 @@ jobs:
23
23
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
24
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
25
  # uses: ruby/setup-ruby@v1
26
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
26
+ uses: ruby/setup-ruby@168d6a54b412713c0ed60998a78093a270ca8d84
27
27
  with:
28
28
  ruby-version: ${{ matrix.ruby-version }}
29
29
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/README.md CHANGED
@@ -10,7 +10,7 @@ See https://github.com/facebook/zstd
10
10
  Fork from https://github.com/jarredholman/ruby-zstd.
11
11
 
12
12
  ## Zstd version
13
- v1.5.0 (https://github.com/facebook/zstd/tree/v1.5.0)
13
+ v1.5.1 (https://github.com/facebook/zstd/tree/v1.5.1)
14
14
 
15
15
  ## Installation
16
16
 
@@ -1,6 +1,7 @@
1
1
  require "mkmf"
2
2
 
3
3
  $CFLAGS = '-I. -O3 -std=c99'
4
+ $CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
4
5
 
5
6
  Dir.chdir File.expand_path('..', __FILE__) do
6
7
  $srcs = Dir['**/*.c']
@@ -8,110 +8,13 @@
8
8
  # You may select, at your option, one of the above-listed licenses.
9
9
  # ################################################################
10
10
 
11
- # Note: by default, the static library is built single-threaded and dynamic library is built
12
- # multi-threaded. It is possible to force multi or single threaded builds by appending
13
- # -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
14
- .PHONY: default
15
- default: lib-release
16
-
17
- # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
18
- $(V)$(VERBOSE).SILENT:
19
-
20
- # When cross-compiling from linux to windows,
21
- # one might need to specify TARGET_SYSTEM as "Windows."
22
- # Building from Fedora fails without it.
23
- # (but Ubuntu and Debian don't need to set anything)
24
- TARGET_SYSTEM ?= $(OS)
25
-
26
- # Version numbers
27
- LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
28
- LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
29
- LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
30
- LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
31
- LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
32
- LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
33
- LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
34
- LIBVER := $(shell echo $(LIBVER_SCRIPT))
35
- VERSION?= $(LIBVER)
36
- CCVER := $(shell $(CC) --version)
37
-
38
- # ZSTD_LIB_MINIFY is a helper variable that
39
- # configures a bunch of other variables to space-optimized defaults.
40
- ZSTD_LIB_MINIFY ?= 0
41
- ifneq ($(ZSTD_LIB_MINIFY), 0)
42
- HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
43
- ZSTD_LEGACY_SUPPORT ?= 0
44
- ZSTD_LIB_DEPRECATED ?= 0
45
- HUF_FORCE_DECOMPRESS_X1 ?= 1
46
- ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
47
- ZSTD_NO_INLINE ?= 1
48
- ZSTD_STRIP_ERROR_STRINGS ?= 1
49
- ifneq ($(HAVE_CC_OZ), 0)
50
- # Some compilers (clang) support an even more space-optimized setting.
51
- CFLAGS += -Oz
52
- else
53
- CFLAGS += -Os
54
- endif
55
- CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
56
- -DDYNAMIC_BMI2=0 -DNDEBUG
57
- else
58
- CFLAGS += -O3
59
- endif
60
-
61
- DEBUGLEVEL ?= 0
62
- CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
63
- ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
64
- CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
65
- endif
66
- DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
67
- -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
68
- -Wstrict-prototypes -Wundef -Wpointer-arith \
69
- -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
70
- -Wredundant-decls -Wmissing-prototypes -Wc++-compat
71
- CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
72
- FLAGS = $(CPPFLAGS) $(CFLAGS)
73
-
74
- CPPFLAGS_DYNLIB = -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
75
- LDFLAGS_DYNLIB = -pthread
76
- CPPFLAGS_STATLIB = # static library build defaults to single-threaded
77
-
78
- HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
79
- GREP_OPTIONS ?=
80
- ifeq ($HAVE_COLORNEVER, 1)
81
- GREP_OPTIONS += --color=never
82
- endif
83
- GREP = grep $(GREP_OPTIONS)
84
- SED_ERE_OPT ?= -E
85
-
86
- ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
87
- ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
88
- ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
89
- ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
90
- ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
91
- ZSTD_FILES := $(ZSTDCOMMON_FILES)
92
-
93
- ifeq ($(findstring GCC,$(CCVER)),GCC)
94
- decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
95
- endif
96
-
97
11
  # Modules
98
12
  ZSTD_LIB_COMPRESSION ?= 1
99
13
  ZSTD_LIB_DECOMPRESSION ?= 1
100
14
  ZSTD_LIB_DICTBUILDER ?= 1
101
15
  ZSTD_LIB_DEPRECATED ?= 0
102
16
 
103
- # Legacy support
104
- ZSTD_LEGACY_SUPPORT ?= 5
105
- ZSTD_LEGACY_MULTITHREADED_API ?= 0
106
-
107
- # Build size optimizations
108
- HUF_FORCE_DECOMPRESS_X1 ?= 0
109
- HUF_FORCE_DECOMPRESS_X2 ?= 0
110
- ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
111
- ZSTD_FORCE_DECOMPRESS_LONG ?= 0
112
- ZSTD_NO_INLINE ?= 0
113
- ZSTD_STRIP_ERROR_STRINGS ?= 0
114
-
17
+ # Input variables for libzstd.mk
115
18
  ifeq ($(ZSTD_LIB_COMPRESSION), 0)
116
19
  ZSTD_LIB_DICTBUILDER = 0
117
20
  ZSTD_LIB_DEPRECATED = 0
@@ -122,86 +25,46 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
122
25
  ZSTD_LIB_DEPRECATED = 0
123
26
  endif
124
27
 
28
+ include libzstd.mk
29
+
30
+ ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
31
+
125
32
  ifneq ($(ZSTD_LIB_COMPRESSION), 0)
126
- ZSTD_FILES += $(ZSTDCOMP_FILES)
33
+ ZSTD_FILES += $(ZSTD_COMPRESS_FILES)
127
34
  endif
128
35
 
129
36
  ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
130
- ZSTD_FILES += $(ZSTDDECOMP_FILES)
37
+ ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES)
131
38
  endif
132
39
 
133
40
  ifneq ($(ZSTD_LIB_DEPRECATED), 0)
134
- ZSTD_FILES += $(ZDEPR_FILES)
41
+ ZSTD_FILES += $(ZSTD_DEPRECATED_FILES)
135
42
  endif
136
43
 
137
44
  ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
138
- ZSTD_FILES += $(ZDICT_FILES)
139
- endif
140
-
141
- ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
142
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
143
- endif
144
-
145
- ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
146
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
147
- endif
148
-
149
- ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
150
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
151
- endif
152
-
153
- ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
154
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
155
- endif
156
-
157
- ifneq ($(ZSTD_NO_INLINE), 0)
158
- CFLAGS += -DZSTD_NO_INLINE
159
- endif
160
-
161
- ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
162
- CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
45
+ ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES)
163
46
  endif
164
47
 
165
- ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
166
- CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
167
- endif
168
-
169
- ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
170
- ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
171
- ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
172
- endif
173
- endif
174
- CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
175
-
176
48
  ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
177
- ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
49
+ ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o)
50
+ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o)
178
51
 
179
- ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
180
- vpath %.c $(ZSTD_SUBDIR)
52
+ VERSION := $(ZSTD_VERSION)
181
53
 
182
- UNAME := $(shell uname)
54
+ # Note: by default, the static library is built single-threaded and dynamic library is built
55
+ # multi-threaded. It is possible to force multi or single threaded builds by appending
56
+ # -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
57
+ .PHONY: default
58
+ default: lib-release
59
+
60
+ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
61
+ LDFLAGS_DYNLIB += -pthread
62
+ CPPFLAGS_STATLIB += # static library build defaults to single-threaded
183
63
 
184
- ifndef BUILD_DIR
185
- ifeq ($(UNAME), Darwin)
186
- ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
187
- HASH ?= md5
188
- endif
189
- else ifeq ($(UNAME), FreeBSD)
190
- HASH ?= gmd5sum
191
- else ifeq ($(UNAME), NetBSD)
192
- HASH ?= md5 -n
193
- else ifeq ($(UNAME), OpenBSD)
194
- HASH ?= md5
195
- endif
196
- HASH ?= md5sum
197
64
 
198
- HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
199
- HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
200
- ifeq ($(HAVE_HASH),0)
201
- $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
202
- BUILD_DIR := obj/generic_noconf
65
+ ifeq ($(findstring GCC,$(CCVER)),GCC)
66
+ decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
203
67
  endif
204
- endif # BUILD_DIR
205
68
 
206
69
 
207
70
  # macOS linker doesn't support -soname, and use different extension
@@ -212,19 +75,16 @@ ifeq ($(UNAME), Darwin)
212
75
  SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
213
76
  SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
214
77
  else
215
- SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
78
+ ifeq ($(UNAME), AIX)
79
+ SONAME_FLAGS =
80
+ else
81
+ SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
82
+ endif
216
83
  SHARED_EXT = so
217
84
  SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
218
85
  SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
219
86
  endif
220
87
 
221
- SET_CACHE_DIRECTORY = \
222
- +$(MAKE) --no-print-directory $@ \
223
- BUILD_DIR=obj/$(HASH_DIR) \
224
- CPPFLAGS="$(CPPFLAGS)" \
225
- CFLAGS="$(CFLAGS)" \
226
- LDFLAGS="$(LDFLAGS)"
227
-
228
88
 
229
89
  .PHONY: all
230
90
  all: lib
@@ -233,6 +93,13 @@ all: lib
233
93
  .PHONY: libzstd.a # must be run every time
234
94
  libzstd.a: CPPFLAGS += $(CPPFLAGS_STATLIB)
235
95
 
96
+ SET_CACHE_DIRECTORY = \
97
+ +$(MAKE) --no-print-directory $@ \
98
+ BUILD_DIR=obj/$(HASH_DIR) \
99
+ CPPFLAGS="$(CPPFLAGS)" \
100
+ CFLAGS="$(CFLAGS)" \
101
+ LDFLAGS="$(LDFLAGS)"
102
+
236
103
  ifndef BUILD_DIR
237
104
  # determine BUILD_DIR from compilation flags
238
105
 
@@ -343,6 +210,14 @@ $(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
343
210
  @echo CC $@
344
211
  $(COMPILE.c) $(DEPFLAGS) $(ZSTD_STATLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
345
212
 
213
+ $(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
214
+ @echo AS $@
215
+ $(COMPILE.c) $(OUTPUT_OPTION) $<
216
+
217
+ $(ZSTD_STATLIB_DIR)/%.o : %.S | $(ZSTD_STATLIB_DIR)
218
+ @echo AS $@
219
+ $(COMPILE.c) $(OUTPUT_OPTION) $<
220
+
346
221
  MKDIR ?= mkdir
347
222
  $(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATLIB_DIR):
348
223
  $(MKDIR) -p $@
@@ -374,9 +249,9 @@ clean:
374
249
  #-----------------------------------------------------------------------------
375
250
  # make install is validated only for below listed environments
376
251
  #-----------------------------------------------------------------------------
377
- ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
252
+ ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX))
378
253
 
379
- all: libzstd.pc
254
+ lib: libzstd.pc
380
255
 
381
256
  HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
382
257
 
@@ -421,16 +296,16 @@ INSTALL_PROGRAM ?= $(INSTALL)
421
296
  INSTALL_DATA ?= $(INSTALL) -m 644
422
297
 
423
298
 
424
- libzstd.pc:
425
299
  libzstd.pc: libzstd.pc.in
426
300
  @echo creating pkgconfig
427
301
  @sed $(SED_ERE_OPT) \
428
302
  -e 's|@PREFIX@|$(PREFIX)|' \
429
303
  -e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
430
- -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
431
- -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
432
- -e 's|@VERSION@|$(VERSION)|' \
433
- $< >$@
304
+ -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
305
+ -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
306
+ -e 's|@VERSION@|$(VERSION)|' \
307
+ -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
308
+ $< >$@
434
309
 
435
310
  .PHONY: install
436
311
  install: install-pc install-static install-shared install-includes
@@ -125,7 +125,7 @@ The file structure is designed to make this selection manually achievable for an
125
125
  `ZSTD_getErrorName` (implied by `ZSTD_LIB_MINIFY`).
126
126
 
127
127
  Finally, when integrating into your application, make sure you're doing link-
128
- time optimation and unused symbol garbage collection (via some combination of,
128
+ time optimization and unused symbol garbage collection (via some combination of,
129
129
  e.g., `-flto`, `-ffat-lto-objects`, `-fuse-linker-plugin`,
130
130
  `-ffunction-sections`, `-fdata-sections`, `-fmerge-all-constants`,
131
131
  `-Wl,--gc-sections`, `-Wl,-z,norelro`, and an archiver that understands
@@ -155,6 +155,12 @@ The file structure is designed to make this selection manually achievable for an
155
155
  - The build macro `ZSTD_NO_INTRINSICS` can be defined to disable all explicit intrinsics.
156
156
  Compiler builtins are still used.
157
157
 
158
+ - The build macro `ZSTD_DECODER_INTERNAL_BUFFER` can be set to control
159
+ the amount of extra memory used during decompression to store literals.
160
+ This defaults to 64kB. Reducing this value reduces the memory footprint of
161
+ `ZSTD_DCtx` decompression contexts,
162
+ but might also result in a small decompression speed cost.
163
+
158
164
 
159
165
  #### Windows : using MinGW+MSYS to create DLL
160
166
 
@@ -143,10 +143,16 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val)
143
143
  {
144
144
  # if defined(_MSC_VER) /* Visual */
145
145
  # if STATIC_BMI2 == 1
146
- return _lzcnt_u32(val) ^ 31;
146
+ return _lzcnt_u32(val) ^ 31;
147
147
  # else
148
- unsigned long r = 0;
149
- return _BitScanReverse(&r, val) ? (unsigned)r : 0;
148
+ if (val != 0) {
149
+ unsigned long r;
150
+ _BitScanReverse(&r, val);
151
+ return (unsigned)r;
152
+ } else {
153
+ /* Should not reach this code path */
154
+ __assume(0);
155
+ }
150
156
  # endif
151
157
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
152
158
  return __builtin_clz (val) ^ 31;
@@ -293,22 +299,22 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
293
299
  switch(srcSize)
294
300
  {
295
301
  case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
296
- /* fall-through */
302
+ ZSTD_FALLTHROUGH;
297
303
 
298
304
  case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
299
- /* fall-through */
305
+ ZSTD_FALLTHROUGH;
300
306
 
301
307
  case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
302
- /* fall-through */
308
+ ZSTD_FALLTHROUGH;
303
309
 
304
310
  case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
305
- /* fall-through */
311
+ ZSTD_FALLTHROUGH;
306
312
 
307
313
  case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
308
- /* fall-through */
314
+ ZSTD_FALLTHROUGH;
309
315
 
310
316
  case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
311
- /* fall-through */
317
+ ZSTD_FALLTHROUGH;
312
318
 
313
319
  default: break;
314
320
  }
@@ -332,7 +338,16 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 c
332
338
  U32 const regMask = sizeof(bitContainer)*8 - 1;
333
339
  /* if start > regMask, bitstream is corrupted, and result is undefined */
334
340
  assert(nbBits < BIT_MASK_SIZE);
341
+ /* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better
342
+ * than accessing memory. When bmi2 instruction is not present, we consider
343
+ * such cpus old (pre-Haswell, 2013) and their performance is not of that
344
+ * importance.
345
+ */
346
+ #if defined(__x86_64__) || defined(_M_X86)
347
+ return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
348
+ #else
335
349
  return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
350
+ #endif
336
351
  }
337
352
 
338
353
  MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
@@ -11,6 +11,8 @@
11
11
  #ifndef ZSTD_COMPILER_H
12
12
  #define ZSTD_COMPILER_H
13
13
 
14
+ #include "portability_macros.h"
15
+
14
16
  /*-*******************************************************
15
17
  * Compiler specifics
16
18
  *********************************************************/
@@ -40,7 +42,7 @@
40
42
 
41
43
  /**
42
44
  On MSVC qsort requires that functions passed into it use the __cdecl calling conversion(CC).
43
- This explictly marks such functions as __cdecl so that the code will still compile
45
+ This explicitly marks such functions as __cdecl so that the code will still compile
44
46
  if a CC other than __cdecl has been made the default.
45
47
  */
46
48
  #if defined(_MSC_VER)
@@ -92,29 +94,17 @@
92
94
 
93
95
 
94
96
  /* target attribute */
95
- #ifndef __has_attribute
96
- #define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
97
- #endif
98
97
  #if defined(__GNUC__) || defined(__ICCARM__)
99
98
  # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
100
99
  #else
101
100
  # define TARGET_ATTRIBUTE(target)
102
101
  #endif
103
102
 
104
- /* Enable runtime BMI2 dispatch based on the CPU.
105
- * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
103
+ /* Target attribute for BMI2 dynamic dispatch.
104
+ * Enable lzcnt, bmi, and bmi2.
105
+ * We test for bmi1 & bmi2. lzcnt is included in bmi1.
106
106
  */
107
- #ifndef DYNAMIC_BMI2
108
- #if ((defined(__clang__) && __has_attribute(__target__)) \
109
- || (defined(__GNUC__) \
110
- && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
111
- && (defined(__x86_64__) || defined(_M_X86)) \
112
- && !defined(__BMI2__)
113
- # define DYNAMIC_BMI2 1
114
- #else
115
- # define DYNAMIC_BMI2 0
116
- #endif
117
- #endif
107
+ #define BMI2_TARGET_ATTRIBUTE TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
118
108
 
119
109
  /* prefetch
120
110
  * can be disabled, by declaring NO_PREFETCH build macro */
@@ -150,8 +140,9 @@
150
140
  }
151
141
 
152
142
  /* vectorization
153
- * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
154
- #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__)
143
+ * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
144
+ * and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
145
+ #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
155
146
  # if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
156
147
  # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
157
148
  # else
@@ -197,25 +188,91 @@
197
188
  #define STATIC_BMI2 0
198
189
  #endif
199
190
 
200
- /* compat. with non-clang compilers */
201
- #ifndef __has_builtin
202
- # define __has_builtin(x) 0
191
+ /* compile time determination of SIMD support */
192
+ #if !defined(ZSTD_NO_INTRINSICS)
193
+ # if defined(__SSE2__) || defined(_M_AMD64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
194
+ # define ZSTD_ARCH_X86_SSE2
195
+ # endif
196
+ # if defined(__ARM_NEON) || defined(_M_ARM64)
197
+ # define ZSTD_ARCH_ARM_NEON
198
+ # endif
199
+ #
200
+ # if defined(ZSTD_ARCH_X86_SSE2)
201
+ # include <emmintrin.h>
202
+ # elif defined(ZSTD_ARCH_ARM_NEON)
203
+ # include <arm_neon.h>
204
+ # endif
203
205
  #endif
204
206
 
205
- /* compat. with non-clang compilers */
206
- #ifndef __has_feature
207
- # define __has_feature(x) 0
207
+ /* C-language Attributes are added in C23. */
208
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
209
+ # define ZSTD_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
210
+ #else
211
+ # define ZSTD_HAS_C_ATTRIBUTE(x) 0
208
212
  #endif
209
213
 
210
- /* detects whether we are being compiled under msan */
211
- #ifndef ZSTD_MEMORY_SANITIZER
212
- # if __has_feature(memory_sanitizer)
213
- # define ZSTD_MEMORY_SANITIZER 1
214
- # else
215
- # define ZSTD_MEMORY_SANITIZER 0
216
- # endif
214
+ /* Only use C++ attributes in C++. Some compilers report support for C++
215
+ * attributes when compiling with C.
216
+ */
217
+ #if defined(__cplusplus) && defined(__has_cpp_attribute)
218
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
219
+ #else
220
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) 0
217
221
  #endif
218
222
 
223
+ /* Define ZSTD_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute.
224
+ * - C23: https://en.cppreference.com/w/c/language/attributes/fallthrough
225
+ * - CPP17: https://en.cppreference.com/w/cpp/language/attributes/fallthrough
226
+ * - Else: __attribute__((__fallthrough__))
227
+ */
228
+ #ifndef ZSTD_FALLTHROUGH
229
+ # if ZSTD_HAS_C_ATTRIBUTE(fallthrough)
230
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
231
+ # elif ZSTD_HAS_CPP_ATTRIBUTE(fallthrough)
232
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
233
+ # elif __has_attribute(__fallthrough__)
234
+ /* Leading semicolon is to satisfy gcc-11 with -pedantic. Without the semicolon
235
+ * gcc complains about: a label can only be part of a statement and a declaration is not a statement.
236
+ */
237
+ # define ZSTD_FALLTHROUGH ; __attribute__((__fallthrough__))
238
+ # else
239
+ # define ZSTD_FALLTHROUGH
240
+ # endif
241
+ #endif
242
+
243
+ /*-**************************************************************
244
+ * Alignment check
245
+ *****************************************************************/
246
+
247
+ /* this test was initially positioned in mem.h,
248
+ * but this file is removed (or replaced) for linux kernel
249
+ * so it's now hosted in compiler.h,
250
+ * which remains valid for both user & kernel spaces.
251
+ */
252
+
253
+ #ifndef ZSTD_ALIGNOF
254
+ # if defined(__GNUC__) || defined(_MSC_VER)
255
+ /* covers gcc, clang & MSVC */
256
+ /* note : this section must come first, before C11,
257
+ * due to a limitation in the kernel source generator */
258
+ # define ZSTD_ALIGNOF(T) __alignof(T)
259
+
260
+ # elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
261
+ /* C11 support */
262
+ # include <stdalign.h>
263
+ # define ZSTD_ALIGNOF(T) alignof(T)
264
+
265
+ # else
266
+ /* No known support for alignof() - imperfect backup */
267
+ # define ZSTD_ALIGNOF(T) (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))
268
+
269
+ # endif
270
+ #endif /* ZSTD_ALIGNOF */
271
+
272
+ /*-**************************************************************
273
+ * Sanitizer
274
+ *****************************************************************/
275
+
219
276
  #if ZSTD_MEMORY_SANITIZER
220
277
  /* Not all platforms that support msan provide sanitizers/msan_interface.h.
221
278
  * We therefore declare the functions we need ourselves, rather than trying to
@@ -237,17 +294,6 @@ void __msan_poison(const volatile void *a, size_t size);
237
294
  intptr_t __msan_test_shadow(const volatile void *x, size_t size);
238
295
  #endif
239
296
 
240
- /* detects whether we are being compiled under asan */
241
- #ifndef ZSTD_ADDRESS_SANITIZER
242
- # if __has_feature(address_sanitizer)
243
- # define ZSTD_ADDRESS_SANITIZER 1
244
- # elif defined(__SANITIZE_ADDRESS__)
245
- # define ZSTD_ADDRESS_SANITIZER 1
246
- # else
247
- # define ZSTD_ADDRESS_SANITIZER 0
248
- # endif
249
- #endif
250
-
251
297
  #if ZSTD_ADDRESS_SANITIZER
252
298
  /* Not all platforms that support asan provide sanitizers/asan_interface.h.
253
299
  * We therefore declare the functions we need ourselves, rather than trying to
@@ -43,8 +43,14 @@ static U32 FSE_ctz(U32 val)
43
43
  assert(val != 0);
44
44
  {
45
45
  # if defined(_MSC_VER) /* Visual */
46
- unsigned long r=0;
47
- return _BitScanForward(&r, val) ? (unsigned)r : 0;
46
+ if (val != 0) {
47
+ unsigned long r;
48
+ _BitScanForward(&r, val);
49
+ return (unsigned)r;
50
+ } else {
51
+ /* Should not reach this code path */
52
+ __assume(0);
53
+ }
48
54
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
49
55
  return __builtin_ctz(val);
50
56
  # elif defined(__ICCARM__) /* IAR Intrinsic */
@@ -217,7 +223,7 @@ static size_t FSE_readNCount_body_default(
217
223
  }
218
224
 
219
225
  #if DYNAMIC_BMI2
220
- TARGET_ATTRIBUTE("bmi2") static size_t FSE_readNCount_body_bmi2(
226
+ BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
221
227
  short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
222
228
  const void* headerBuffer, size_t hbSize)
223
229
  {
@@ -299,7 +305,7 @@ HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
299
305
  ZSTD_memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
300
306
  weightTotal = 0;
301
307
  { U32 n; for (n=0; n<oSize; n++) {
302
- if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
308
+ if (huffWeight[n] > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
303
309
  rankStats[huffWeight[n]]++;
304
310
  weightTotal += (1 << huffWeight[n]) >> 1;
305
311
  } }
@@ -337,7 +343,7 @@ static size_t HUF_readStats_body_default(BYTE* huffWeight, size_t hwSize, U32* r
337
343
  }
338
344
 
339
345
  #if DYNAMIC_BMI2
340
- static TARGET_ATTRIBUTE("bmi2") size_t HUF_readStats_body_bmi2(BYTE* huffWeight, size_t hwSize, U32* rankStats,
346
+ static BMI2_TARGET_ATTRIBUTE size_t HUF_readStats_body_bmi2(BYTE* huffWeight, size_t hwSize, U32* rankStats,
341
347
  U32* nbSymbolsPtr, U32* tableLogPtr,
342
348
  const void* src, size_t srcSize,
343
349
  void* workSpace, size_t wkspSize)