multi_compress 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -3
- data/GET_STARTED.md +3 -3
- data/README.md +75 -66
- data/THIRD_PARTY_NOTICES.md +24 -0
- data/ext/multi_compress/brotli_dec_static_init.c +3 -0
- data/ext/multi_compress/brotli_enc_static_init.c +3 -0
- data/ext/multi_compress/extconf.rb +22 -1
- data/ext/multi_compress/multi_compress.c +152 -72
- data/ext/multi_compress/vendor/.vendored +2 -2
- data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
- data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
- data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
- data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
- data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
- data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
- data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
- data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
- data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
- data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
- data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
- data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
- data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
- data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
- data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
- data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
- data/ext/multi_compress/vendor/zstd/COPYING +339 -0
- data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
- data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
- data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
- data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
- data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
- data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
- data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
- data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
- data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
- data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
- data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
- data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
- data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
- data/lib/multi_compress/version.rb +1 -1
- metadata +29 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# ################################################################
|
|
2
|
-
# Copyright (c)
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
# All rights reserved.
|
|
4
4
|
#
|
|
5
5
|
# This source code is licensed under both the BSD-style license (found in the
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
# You may select, at your option, one of the above-listed licenses.
|
|
9
9
|
# ################################################################
|
|
10
10
|
|
|
11
|
+
# default target (when running `make` with no argument)
|
|
12
|
+
lib-release:
|
|
13
|
+
|
|
11
14
|
# Modules
|
|
12
15
|
ZSTD_LIB_COMPRESSION ?= 1
|
|
13
16
|
ZSTD_LIB_DECOMPRESSION ?= 1
|
|
@@ -54,13 +57,14 @@ VERSION := $(ZSTD_VERSION)
|
|
|
54
57
|
# Note: by default, the static library is built single-threaded and dynamic library is built
|
|
55
58
|
# multi-threaded. It is possible to force multi or single threaded builds by appending
|
|
56
59
|
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
|
|
57
|
-
|
|
58
|
-
default: lib-release
|
|
60
|
+
|
|
59
61
|
|
|
60
62
|
CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
|
|
61
63
|
LDFLAGS_DYNLIB += -pthread
|
|
62
|
-
|
|
64
|
+
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
|
|
63
65
|
|
|
66
|
+
# pkg-config Libs.private points to LDFLAGS_DYNLIB
|
|
67
|
+
PCLIB := $(LDFLAGS_DYNLIB)
|
|
64
68
|
|
|
65
69
|
ifeq ($(findstring GCC,$(CCVER)),GCC)
|
|
66
70
|
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
|
|
@@ -69,13 +73,15 @@ endif
|
|
|
69
73
|
|
|
70
74
|
# macOS linker doesn't support -soname, and use different extension
|
|
71
75
|
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
|
|
72
|
-
|
|
76
|
+
UNAME_TARGET_SYSTEM ?= $(UNAME)
|
|
77
|
+
|
|
78
|
+
ifeq ($(UNAME_TARGET_SYSTEM), Darwin)
|
|
73
79
|
SHARED_EXT = dylib
|
|
74
80
|
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
|
|
75
81
|
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
|
|
76
82
|
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
|
|
77
83
|
else
|
|
78
|
-
ifeq ($(
|
|
84
|
+
ifeq ($(UNAME_TARGET_SYSTEM), AIX)
|
|
79
85
|
SONAME_FLAGS =
|
|
80
86
|
else
|
|
81
87
|
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
|
|
@@ -91,7 +97,7 @@ all: lib
|
|
|
91
97
|
|
|
92
98
|
|
|
93
99
|
.PHONY: libzstd.a # must be run every time
|
|
94
|
-
libzstd.a: CPPFLAGS += $(
|
|
100
|
+
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATICLIB)
|
|
95
101
|
|
|
96
102
|
SET_CACHE_DIRECTORY = \
|
|
97
103
|
+$(MAKE) --no-print-directory $@ \
|
|
@@ -109,19 +115,19 @@ libzstd.a:
|
|
|
109
115
|
else
|
|
110
116
|
# BUILD_DIR is defined
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
$(
|
|
116
|
-
$(
|
|
117
|
-
$(
|
|
118
|
+
ZSTD_STATICLIB_DIR := $(BUILD_DIR)/static
|
|
119
|
+
ZSTD_STATICLIB := $(ZSTD_STATICLIB_DIR)/libzstd.a
|
|
120
|
+
ZSTD_STATICLIB_OBJ := $(addprefix $(ZSTD_STATICLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
|
|
121
|
+
$(ZSTD_STATICLIB): ARFLAGS = rcs
|
|
122
|
+
$(ZSTD_STATICLIB): | $(ZSTD_STATICLIB_DIR)
|
|
123
|
+
$(ZSTD_STATICLIB): $(ZSTD_STATICLIB_OBJ)
|
|
118
124
|
# Check for multithread flag at target execution time
|
|
119
125
|
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
|
|
120
126
|
@echo compiling multi-threaded static library $(LIBVER),\
|
|
121
127
|
@echo compiling single-threaded static library $(LIBVER))
|
|
122
128
|
$(AR) $(ARFLAGS) $@ $^
|
|
123
129
|
|
|
124
|
-
libzstd.a: $(
|
|
130
|
+
libzstd.a: $(ZSTD_STATICLIB)
|
|
125
131
|
cp -f $< $@
|
|
126
132
|
|
|
127
133
|
endif
|
|
@@ -182,14 +188,17 @@ lib : libzstd.a libzstd
|
|
|
182
188
|
# make does not consider implicit pattern rule for .PHONY target
|
|
183
189
|
|
|
184
190
|
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
|
|
185
|
-
%-mt :
|
|
191
|
+
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
|
|
186
192
|
%-mt : LDFLAGS_DYNLIB := -pthread
|
|
193
|
+
%-mt : PCLIB :=
|
|
194
|
+
%-mt : PCMTLIB := $(LDFLAGS_DYNLIB)
|
|
187
195
|
%-mt : %
|
|
188
196
|
@echo multi-threaded build completed
|
|
189
197
|
|
|
190
198
|
%-nomt : CPPFLAGS_DYNLIB :=
|
|
191
199
|
%-nomt : LDFLAGS_DYNLIB :=
|
|
192
|
-
%-nomt :
|
|
200
|
+
%-nomt : CPPFLAGS_STATICLIB :=
|
|
201
|
+
%-nomt : PCLIB :=
|
|
193
202
|
%-nomt : %
|
|
194
203
|
@echo single-threaded build completed
|
|
195
204
|
|
|
@@ -200,42 +209,52 @@ lib : libzstd.a libzstd
|
|
|
200
209
|
|
|
201
210
|
# Generate .h dependencies automatically
|
|
202
211
|
|
|
203
|
-
|
|
212
|
+
# -MMD: compiler generates dependency information as a side-effect of compilation, without system headers
|
|
213
|
+
# -MP: adds phony target for each dependency other than main file.
|
|
214
|
+
DEPFLAGS = -MMD -MP
|
|
204
215
|
|
|
205
|
-
|
|
216
|
+
# ensure that ZSTD_DYNLIB_DIR exists prior to generating %.o
|
|
217
|
+
$(ZSTD_DYNLIB_DIR)/%.o : %.c | $(ZSTD_DYNLIB_DIR)
|
|
206
218
|
@echo CC $@
|
|
207
|
-
$(COMPILE.c) $(DEPFLAGS) $(
|
|
219
|
+
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
|
208
220
|
|
|
209
|
-
$(
|
|
221
|
+
$(ZSTD_STATICLIB_DIR)/%.o : %.c | $(ZSTD_STATICLIB_DIR)
|
|
210
222
|
@echo CC $@
|
|
211
|
-
$(COMPILE.c) $(DEPFLAGS) $(
|
|
223
|
+
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
|
212
224
|
|
|
213
225
|
$(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
|
|
214
226
|
@echo AS $@
|
|
215
227
|
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
|
216
228
|
|
|
217
|
-
$(
|
|
229
|
+
$(ZSTD_STATICLIB_DIR)/%.o : %.S | $(ZSTD_STATICLIB_DIR)
|
|
218
230
|
@echo AS $@
|
|
219
231
|
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
|
220
232
|
|
|
221
|
-
MKDIR ?= mkdir
|
|
222
|
-
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(
|
|
223
|
-
$(MKDIR)
|
|
233
|
+
MKDIR ?= mkdir -p
|
|
234
|
+
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATICLIB_DIR):
|
|
235
|
+
$(MKDIR) $@
|
|
224
236
|
|
|
225
|
-
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(
|
|
237
|
+
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATICLIB_OBJ:.o=.d)
|
|
226
238
|
$(DEPFILES):
|
|
227
239
|
|
|
228
|
-
include
|
|
240
|
+
# The leading '-' means: do not fail is include fails (ex: directory does not exist yet)
|
|
241
|
+
-include $(wildcard $(DEPFILES))
|
|
229
242
|
|
|
230
243
|
|
|
231
|
-
# Special case :
|
|
232
|
-
|
|
233
|
-
|
|
244
|
+
# Special case : build library in single-thread mode _and_ without zstdmt_compress.c
|
|
245
|
+
# Note : we still need threading.c and pool.c for the dictionary builder,
|
|
246
|
+
# but they will correctly behave single-threaded.
|
|
247
|
+
ZSTDMT_FILES = zstdmt_compress.c
|
|
248
|
+
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(notdir $(ZSTD_FILES)))
|
|
234
249
|
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
|
|
235
250
|
libzstd-nomt: LDFLAGS += -shared
|
|
236
251
|
libzstd-nomt: $(ZSTD_NOMT_FILES)
|
|
237
252
|
@echo compiling single-thread dynamic library $(LIBVER)
|
|
238
253
|
@echo files : $(ZSTD_NOMT_FILES)
|
|
254
|
+
@if echo "$(ZSTD_NOMT_FILES)" | tr ' ' '\n' | $(GREP) -q zstdmt; then \
|
|
255
|
+
echo "Error: Found zstdmt in list."; \
|
|
256
|
+
exit 1; \
|
|
257
|
+
fi
|
|
239
258
|
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
|
240
259
|
|
|
241
260
|
.PHONY: clean
|
|
@@ -249,7 +268,7 @@ clean:
|
|
|
249
268
|
#-----------------------------------------------------------------------------
|
|
250
269
|
# make install is validated only for below listed environments
|
|
251
270
|
#-----------------------------------------------------------------------------
|
|
252
|
-
ifneq (,$(filter
|
|
271
|
+
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME)))
|
|
253
272
|
|
|
254
273
|
lib: libzstd.pc
|
|
255
274
|
|
|
@@ -280,13 +299,21 @@ PCLIBPREFIX := $(if $(findstring $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
|
|
|
280
299
|
# to PREFIX, rather than as a resolved value.
|
|
281
300
|
PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix})
|
|
282
301
|
|
|
283
|
-
|
|
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)))
|
|
284
311
|
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
|
|
285
312
|
else
|
|
286
313
|
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
|
|
287
314
|
endif
|
|
288
315
|
|
|
289
|
-
ifneq (,$(filter
|
|
316
|
+
ifneq (,$(filter SunOS,$(UNAME)))
|
|
290
317
|
INSTALL ?= ginstall
|
|
291
318
|
else
|
|
292
319
|
INSTALL ?= install
|
|
@@ -296,15 +323,20 @@ INSTALL_PROGRAM ?= $(INSTALL)
|
|
|
296
323
|
INSTALL_DATA ?= $(INSTALL) -m 644
|
|
297
324
|
|
|
298
325
|
|
|
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
|
|
299
330
|
libzstd.pc: libzstd.pc.in
|
|
300
331
|
@echo creating pkgconfig
|
|
301
|
-
@sed
|
|
332
|
+
@sed \
|
|
302
333
|
-e 's|@PREFIX@|$(PREFIX)|' \
|
|
303
334
|
-e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
|
|
304
335
|
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
|
|
305
336
|
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
|
|
306
337
|
-e 's|@VERSION@|$(VERSION)|' \
|
|
307
|
-
-e 's|@
|
|
338
|
+
-e 's|@LIBS_MT@|$(PCMTLIB)|' \
|
|
339
|
+
-e 's|@LIBS_PRIVATE@|$(PCLIB)|' \
|
|
308
340
|
$< >$@
|
|
309
341
|
|
|
310
342
|
.PHONY: install
|
|
@@ -27,12 +27,16 @@ Enabling multithreading requires 2 conditions :
|
|
|
27
27
|
|
|
28
28
|
For convenience, we provide a build target to generate multi and single threaded libraries:
|
|
29
29
|
- 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.
|
|
30
31
|
- Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`.
|
|
31
32
|
- By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`.
|
|
32
33
|
|
|
33
34
|
When linking a POSIX program with a multithreaded version of `libzstd`,
|
|
34
35
|
note that it's necessary to invoke the `-pthread` flag during link stage.
|
|
35
36
|
|
|
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
|
+
|
|
36
40
|
Multithreading capabilities are exposed
|
|
37
41
|
via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351).
|
|
38
42
|
|
|
@@ -88,10 +92,10 @@ The file structure is designed to make this selection manually achievable for an
|
|
|
88
92
|
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
|
|
89
93
|
|
|
90
94
|
- While invoking `make libzstd`, it's possible to define build macros
|
|
91
|
-
`ZSTD_LIB_COMPRESSION
|
|
95
|
+
`ZSTD_LIB_COMPRESSION`, `ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
|
|
92
96
|
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the
|
|
93
97
|
corresponding features. This will also disable compilation of all
|
|
94
|
-
dependencies (
|
|
98
|
+
dependencies (e.g. `ZSTD_LIB_COMPRESSION=0` will also disable
|
|
95
99
|
dictBuilder).
|
|
96
100
|
|
|
97
101
|
- There are a number of options that can help minimize the binary size of
|
|
@@ -119,6 +123,15 @@ The file structure is designed to make this selection manually achievable for an
|
|
|
119
123
|
binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and
|
|
120
124
|
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT` (implied by `ZSTD_LIB_MINIFY`).
|
|
121
125
|
|
|
126
|
+
On the compressor side, Zstd's compression levels map to several internal
|
|
127
|
+
strategies. In environments where the higher compression levels aren't used,
|
|
128
|
+
it is possible to exclude all but the fastest strategy with
|
|
129
|
+
`ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP=1`. (Note that this will change
|
|
130
|
+
the behavior of the default compression level.) Or if you want to retain the
|
|
131
|
+
default compressor as well, you can set
|
|
132
|
+
`ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP=1`, at the cost of an additional
|
|
133
|
+
~20KB or so.
|
|
134
|
+
|
|
122
135
|
For squeezing the last ounce of size out, you can also define
|
|
123
136
|
`ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`,
|
|
124
137
|
which removes the error messages that are otherwise returned by
|
|
@@ -136,6 +149,13 @@ The file structure is designed to make this selection manually achievable for an
|
|
|
136
149
|
will expose the deprecated `ZSTDMT` API exposed by `zstdmt_compress.h` in
|
|
137
150
|
the shared library, which is now hidden by default.
|
|
138
151
|
|
|
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
|
+
|
|
139
159
|
- The build macro `DYNAMIC_BMI2` can be set to 1 or 0 in order to generate binaries
|
|
140
160
|
which can detect at runtime the presence of BMI2 instructions, and use them only if present.
|
|
141
161
|
These instructions contribute to better performance, notably on the decoder side.
|
|
@@ -161,6 +181,17 @@ The file structure is designed to make this selection manually achievable for an
|
|
|
161
181
|
`ZSTD_DCtx` decompression contexts,
|
|
162
182
|
but might also result in a small decompression speed cost.
|
|
163
183
|
|
|
184
|
+
- The C compiler macros `ZSTDLIB_VISIBLE`, `ZSTDERRORLIB_VISIBLE` and `ZDICTLIB_VISIBLE`
|
|
185
|
+
can be overridden to control the visibility of zstd's API. Additionally,
|
|
186
|
+
`ZSTDLIB_STATIC_API` and `ZDICTLIB_STATIC_API` can be overridden to control the visibility
|
|
187
|
+
of zstd's static API. Specifically, it can be set to `ZSTDLIB_HIDDEN` to hide the symbols
|
|
188
|
+
from the shared library. These macros default to `ZSTDLIB_VISIBILITY`,
|
|
189
|
+
`ZSTDERRORLIB_VSIBILITY`, and `ZDICTLIB_VISIBILITY` if unset, for backwards compatibility
|
|
190
|
+
with the old macro names.
|
|
191
|
+
|
|
192
|
+
- The C compiler macro `HUF_DISABLE_FAST_DECODE` disables the newer Huffman fast C
|
|
193
|
+
and assembly decoding loops. You may want to use this macro if these loops are
|
|
194
|
+
slower on your platform.
|
|
164
195
|
|
|
165
196
|
#### Windows : using MinGW+MSYS to create DLL
|
|
166
197
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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
|
+
/* This file provides custom allocation primitives
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#define ZSTD_DEPS_NEED_MALLOC
|
|
15
|
+
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
|
16
|
+
|
|
17
|
+
#include "compiler.h" /* MEM_STATIC */
|
|
18
|
+
#define ZSTD_STATIC_LINKING_ONLY
|
|
19
|
+
#include "../zstd.h" /* ZSTD_customMem */
|
|
20
|
+
|
|
21
|
+
#ifndef ZSTD_ALLOCATIONS_H
|
|
22
|
+
#define ZSTD_ALLOCATIONS_H
|
|
23
|
+
|
|
24
|
+
/* custom memory allocation functions */
|
|
25
|
+
|
|
26
|
+
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
|
27
|
+
{
|
|
28
|
+
if (customMem.customAlloc)
|
|
29
|
+
return customMem.customAlloc(customMem.opaque, size);
|
|
30
|
+
return ZSTD_malloc(size);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
|
34
|
+
{
|
|
35
|
+
if (customMem.customAlloc) {
|
|
36
|
+
/* calloc implemented as malloc+memset;
|
|
37
|
+
* not as efficient as calloc, but next best guess for custom malloc */
|
|
38
|
+
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
|
39
|
+
ZSTD_memset(ptr, 0, size);
|
|
40
|
+
return ptr;
|
|
41
|
+
}
|
|
42
|
+
return ZSTD_calloc(1, size);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
|
|
46
|
+
{
|
|
47
|
+
if (ptr!=NULL) {
|
|
48
|
+
if (customMem.customFree)
|
|
49
|
+
customMem.customFree(customMem.opaque, ptr);
|
|
50
|
+
else
|
|
51
|
+
ZSTD_free(ptr);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#endif /* ZSTD_ALLOCATIONS_H */
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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_BITS_H
|
|
12
|
+
#define ZSTD_BITS_H
|
|
13
|
+
|
|
14
|
+
#include "mem.h"
|
|
15
|
+
|
|
16
|
+
MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
|
|
17
|
+
{
|
|
18
|
+
assert(val != 0);
|
|
19
|
+
{
|
|
20
|
+
static const U32 DeBruijnBytePos[32] = {0, 1, 28, 2, 29, 14, 24, 3,
|
|
21
|
+
30, 22, 20, 15, 25, 17, 4, 8,
|
|
22
|
+
31, 27, 13, 23, 21, 19, 16, 7,
|
|
23
|
+
26, 12, 18, 6, 11, 5, 10, 9};
|
|
24
|
+
return DeBruijnBytePos[((U32) ((val & -(S32) val) * 0x077CB531U)) >> 27];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
|
|
29
|
+
{
|
|
30
|
+
assert(val != 0);
|
|
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
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val)
|
|
53
|
+
{
|
|
54
|
+
assert(val != 0);
|
|
55
|
+
{
|
|
56
|
+
static const U32 DeBruijnClz[32] = {0, 9, 1, 10, 13, 21, 2, 29,
|
|
57
|
+
11, 14, 16, 18, 22, 25, 3, 30,
|
|
58
|
+
8, 12, 20, 28, 15, 17, 24, 7,
|
|
59
|
+
19, 27, 23, 6, 26, 5, 4, 31};
|
|
60
|
+
val |= val >> 1;
|
|
61
|
+
val |= val >> 2;
|
|
62
|
+
val |= val >> 4;
|
|
63
|
+
val |= val >> 8;
|
|
64
|
+
val |= val >> 16;
|
|
65
|
+
return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
|
|
70
|
+
{
|
|
71
|
+
assert(val != 0);
|
|
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
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
|
|
94
|
+
{
|
|
95
|
+
assert(val != 0);
|
|
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);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
#endif
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
|
|
126
|
+
{
|
|
127
|
+
assert(val != 0);
|
|
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);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
#endif
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
MEM_STATIC unsigned ZSTD_NbCommonBytes(size_t val)
|
|
158
|
+
{
|
|
159
|
+
if (MEM_isLittleEndian()) {
|
|
160
|
+
if (MEM_64bits()) {
|
|
161
|
+
return ZSTD_countTrailingZeros64((U64)val) >> 3;
|
|
162
|
+
} else {
|
|
163
|
+
return ZSTD_countTrailingZeros32((U32)val) >> 3;
|
|
164
|
+
}
|
|
165
|
+
} else { /* Big Endian CPU */
|
|
166
|
+
if (MEM_64bits()) {
|
|
167
|
+
return ZSTD_countLeadingZeros64((U64)val) >> 3;
|
|
168
|
+
} else {
|
|
169
|
+
return ZSTD_countLeadingZeros32((U32)val) >> 3;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
MEM_STATIC unsigned ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
|
175
|
+
{
|
|
176
|
+
assert(val != 0);
|
|
177
|
+
return 31 - ZSTD_countLeadingZeros32(val);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* ZSTD_rotateRight_*():
|
|
181
|
+
* Rotates a bitfield to the right by "count" bits.
|
|
182
|
+
* https://en.wikipedia.org/w/index.php?title=Circular_shift&oldid=991635599#Implementing_circular_shifts
|
|
183
|
+
*/
|
|
184
|
+
MEM_STATIC
|
|
185
|
+
U64 ZSTD_rotateRight_U64(U64 const value, U32 count) {
|
|
186
|
+
assert(count < 64);
|
|
187
|
+
count &= 0x3F; /* for fickle pattern recognition */
|
|
188
|
+
return (value >> count) | (U64)(value << ((0U - count) & 0x3F));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
MEM_STATIC
|
|
192
|
+
U32 ZSTD_rotateRight_U32(U32 const value, U32 count) {
|
|
193
|
+
assert(count < 32);
|
|
194
|
+
count &= 0x1F; /* for fickle pattern recognition */
|
|
195
|
+
return (value >> count) | (U32)(value << ((0U - count) & 0x1F));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
MEM_STATIC
|
|
199
|
+
U16 ZSTD_rotateRight_U16(U16 const value, U32 count) {
|
|
200
|
+
assert(count < 16);
|
|
201
|
+
count &= 0x0F; /* for fickle pattern recognition */
|
|
202
|
+
return (value >> count) | (U16)(value << ((0U - count) & 0x0F));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#endif /* ZSTD_BITS_H */
|