multi_compress 0.3.2 → 0.3.4
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 +17 -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 +79 -3
- data/ext/multi_compress/multi_compress.c +199 -120
- 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
- data/lib/multi_compress.rb +80 -41
- 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
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
#ifndef ZSTD_COMPILER_H
|
|
12
12
|
#define ZSTD_COMPILER_H
|
|
13
13
|
|
|
14
|
+
#include <stddef.h>
|
|
15
|
+
|
|
14
16
|
#include "portability_macros.h"
|
|
15
17
|
|
|
16
18
|
/*-*******************************************************
|
|
@@ -25,7 +27,7 @@
|
|
|
25
27
|
# define INLINE_KEYWORD
|
|
26
28
|
#endif
|
|
27
29
|
|
|
28
|
-
#if defined(__GNUC__) || defined(
|
|
30
|
+
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
|
|
29
31
|
# define FORCE_INLINE_ATTR __attribute__((always_inline))
|
|
30
32
|
#elif defined(_MSC_VER)
|
|
31
33
|
# define FORCE_INLINE_ATTR __forceinline
|
|
@@ -51,12 +53,19 @@
|
|
|
51
53
|
# define WIN_CDECL
|
|
52
54
|
#endif
|
|
53
55
|
|
|
56
|
+
/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
|
|
57
|
+
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
|
|
58
|
+
# define UNUSED_ATTR __attribute__((unused))
|
|
59
|
+
#else
|
|
60
|
+
# define UNUSED_ATTR
|
|
61
|
+
#endif
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
|
|
56
65
|
* parameters. They must be inlined for the compiler to eliminate the constant
|
|
57
66
|
* branches.
|
|
58
67
|
*/
|
|
59
|
-
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
|
|
68
|
+
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR UNUSED_ATTR
|
|
60
69
|
/**
|
|
61
70
|
* HINT_INLINE is used to help the compiler generate better code. It is *not*
|
|
62
71
|
* used for "templates", so it can be tweaked based on the compilers
|
|
@@ -71,21 +80,37 @@
|
|
|
71
80
|
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
|
|
72
81
|
# define HINT_INLINE static INLINE_KEYWORD
|
|
73
82
|
#else
|
|
74
|
-
# define HINT_INLINE
|
|
83
|
+
# define HINT_INLINE FORCE_INLINE_TEMPLATE
|
|
75
84
|
#endif
|
|
76
85
|
|
|
77
|
-
/*
|
|
86
|
+
/* "soft" inline :
|
|
87
|
+
* The compiler is free to select if it's a good idea to inline or not.
|
|
88
|
+
* The main objective is to silence compiler warnings
|
|
89
|
+
* when a defined function in included but not used.
|
|
90
|
+
*
|
|
91
|
+
* Note : this macro is prefixed `MEM_` because it used to be provided by `mem.h` unit.
|
|
92
|
+
* Updating the prefix is probably preferable, but requires a fairly large codemod,
|
|
93
|
+
* since this name is used everywhere.
|
|
94
|
+
*/
|
|
95
|
+
#ifndef MEM_STATIC /* already defined in Linux Kernel mem.h */
|
|
78
96
|
#if defined(__GNUC__)
|
|
79
|
-
# define UNUSED_ATTR
|
|
97
|
+
# define MEM_STATIC static __inline UNUSED_ATTR
|
|
98
|
+
#elif defined(__IAR_SYSTEMS_ICC__)
|
|
99
|
+
# define MEM_STATIC static inline UNUSED_ATTR
|
|
100
|
+
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
|
101
|
+
# define MEM_STATIC static inline
|
|
102
|
+
#elif defined(_MSC_VER)
|
|
103
|
+
# define MEM_STATIC static __inline
|
|
80
104
|
#else
|
|
81
|
-
# define
|
|
105
|
+
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
|
106
|
+
#endif
|
|
82
107
|
#endif
|
|
83
108
|
|
|
84
109
|
/* force no inlining */
|
|
85
110
|
#ifdef _MSC_VER
|
|
86
111
|
# define FORCE_NOINLINE static __declspec(noinline)
|
|
87
112
|
#else
|
|
88
|
-
# if defined(__GNUC__) || defined(
|
|
113
|
+
# if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
|
|
89
114
|
# define FORCE_NOINLINE static __attribute__((__noinline__))
|
|
90
115
|
# else
|
|
91
116
|
# define FORCE_NOINLINE static
|
|
@@ -94,7 +119,7 @@
|
|
|
94
119
|
|
|
95
120
|
|
|
96
121
|
/* target attribute */
|
|
97
|
-
#if defined(__GNUC__) || defined(
|
|
122
|
+
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
|
|
98
123
|
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
|
|
99
124
|
#else
|
|
100
125
|
# define TARGET_ATTRIBUTE(target)
|
|
@@ -109,10 +134,10 @@
|
|
|
109
134
|
/* prefetch
|
|
110
135
|
* can be disabled, by declaring NO_PREFETCH build macro */
|
|
111
136
|
#if defined(NO_PREFETCH)
|
|
112
|
-
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
|
113
|
-
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
|
137
|
+
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
|
|
138
|
+
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
|
|
114
139
|
#else
|
|
115
|
-
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
|
|
140
|
+
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) && !defined(_M_ARM64EC) /* _mm_prefetch() is not defined outside of x86/x64 */
|
|
116
141
|
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
|
|
117
142
|
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
|
|
118
143
|
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
|
|
@@ -120,24 +145,25 @@
|
|
|
120
145
|
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
|
|
121
146
|
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
|
|
122
147
|
# elif defined(__aarch64__)
|
|
123
|
-
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
|
|
124
|
-
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
|
|
148
|
+
# define PREFETCH_L1(ptr) do { __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr))); } while (0)
|
|
149
|
+
# define PREFETCH_L2(ptr) do { __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr))); } while (0)
|
|
125
150
|
# else
|
|
126
|
-
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
|
127
|
-
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
|
151
|
+
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
|
|
152
|
+
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
|
|
128
153
|
# endif
|
|
129
154
|
#endif /* NO_PREFETCH */
|
|
130
155
|
|
|
131
156
|
#define CACHELINE_SIZE 64
|
|
132
157
|
|
|
133
|
-
#define PREFETCH_AREA(p, s)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
158
|
+
#define PREFETCH_AREA(p, s) \
|
|
159
|
+
do { \
|
|
160
|
+
const char* const _ptr = (const char*)(p); \
|
|
161
|
+
size_t const _size = (size_t)(s); \
|
|
162
|
+
size_t _pos; \
|
|
163
|
+
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
|
|
164
|
+
PREFETCH_L2(_ptr + _pos); \
|
|
165
|
+
} \
|
|
166
|
+
} while (0)
|
|
141
167
|
|
|
142
168
|
/* vectorization
|
|
143
169
|
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
|
|
@@ -165,6 +191,12 @@
|
|
|
165
191
|
#define UNLIKELY(x) (x)
|
|
166
192
|
#endif
|
|
167
193
|
|
|
194
|
+
#if __has_builtin(__builtin_unreachable) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
|
|
195
|
+
# define ZSTD_UNREACHABLE do { assert(0), __builtin_unreachable(); } while (0)
|
|
196
|
+
#else
|
|
197
|
+
# define ZSTD_UNREACHABLE do { assert(0); } while (0)
|
|
198
|
+
#endif
|
|
199
|
+
|
|
168
200
|
/* disable warnings */
|
|
169
201
|
#ifdef _MSC_VER /* Visual Studio */
|
|
170
202
|
# include <intrin.h> /* For Visual 2005 */
|
|
@@ -175,28 +207,21 @@
|
|
|
175
207
|
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
|
|
176
208
|
#endif
|
|
177
209
|
|
|
178
|
-
/*Like DYNAMIC_BMI2 but for compile time determination of BMI2 support*/
|
|
179
|
-
#ifndef STATIC_BMI2
|
|
180
|
-
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86))
|
|
181
|
-
# ifdef __AVX2__ //MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2
|
|
182
|
-
# define STATIC_BMI2 1
|
|
183
|
-
# endif
|
|
184
|
-
# endif
|
|
185
|
-
#endif
|
|
186
|
-
|
|
187
|
-
#ifndef STATIC_BMI2
|
|
188
|
-
#define STATIC_BMI2 0
|
|
189
|
-
#endif
|
|
190
|
-
|
|
191
210
|
/* compile time determination of SIMD support */
|
|
192
211
|
#if !defined(ZSTD_NO_INTRINSICS)
|
|
193
|
-
# if defined(
|
|
212
|
+
# if defined(__AVX2__)
|
|
213
|
+
# define ZSTD_ARCH_X86_AVX2
|
|
214
|
+
# endif
|
|
215
|
+
# if defined(__SSE2__) || defined(_M_X64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
|
|
194
216
|
# define ZSTD_ARCH_X86_SSE2
|
|
195
217
|
# endif
|
|
196
218
|
# if defined(__ARM_NEON) || defined(_M_ARM64)
|
|
197
219
|
# define ZSTD_ARCH_ARM_NEON
|
|
198
220
|
# endif
|
|
199
221
|
#
|
|
222
|
+
# if defined(ZSTD_ARCH_X86_AVX2)
|
|
223
|
+
# include <immintrin.h>
|
|
224
|
+
# endif
|
|
200
225
|
# if defined(ZSTD_ARCH_X86_SSE2)
|
|
201
226
|
# include <emmintrin.h>
|
|
202
227
|
# elif defined(ZSTD_ARCH_ARM_NEON)
|
|
@@ -241,9 +266,15 @@
|
|
|
241
266
|
#endif
|
|
242
267
|
|
|
243
268
|
/*-**************************************************************
|
|
244
|
-
* Alignment
|
|
269
|
+
* Alignment
|
|
245
270
|
*****************************************************************/
|
|
246
271
|
|
|
272
|
+
/* @return 1 if @u is a 2^n value, 0 otherwise
|
|
273
|
+
* useful to check a value is valid for alignment restrictions */
|
|
274
|
+
MEM_STATIC int ZSTD_isPower2(size_t u) {
|
|
275
|
+
return (u & (u-1)) == 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
247
278
|
/* this test was initially positioned in mem.h,
|
|
248
279
|
* but this file is removed (or replaced) for linux kernel
|
|
249
280
|
* so it's now hosted in compiler.h,
|
|
@@ -269,11 +300,105 @@
|
|
|
269
300
|
# endif
|
|
270
301
|
#endif /* ZSTD_ALIGNOF */
|
|
271
302
|
|
|
303
|
+
#ifndef ZSTD_ALIGNED
|
|
304
|
+
/* C90-compatible alignment macro (GCC/Clang). Adjust for other compilers if needed. */
|
|
305
|
+
# if defined(__GNUC__) || defined(__clang__)
|
|
306
|
+
# define ZSTD_ALIGNED(a) __attribute__((aligned(a)))
|
|
307
|
+
# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
|
|
308
|
+
# define ZSTD_ALIGNED(a) _Alignas(a)
|
|
309
|
+
#elif defined(_MSC_VER)
|
|
310
|
+
# define ZSTD_ALIGNED(n) __declspec(align(n))
|
|
311
|
+
# else
|
|
312
|
+
/* this compiler will require its own alignment instruction */
|
|
313
|
+
# define ZSTD_ALIGNED(...)
|
|
314
|
+
# endif
|
|
315
|
+
#endif /* ZSTD_ALIGNED */
|
|
316
|
+
|
|
317
|
+
|
|
272
318
|
/*-**************************************************************
|
|
273
319
|
* Sanitizer
|
|
274
320
|
*****************************************************************/
|
|
275
321
|
|
|
276
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Zstd relies on pointer overflow in its decompressor.
|
|
324
|
+
* We add this attribute to functions that rely on pointer overflow.
|
|
325
|
+
*/
|
|
326
|
+
#ifndef ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
|
327
|
+
# if __has_attribute(no_sanitize)
|
|
328
|
+
# if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 8
|
|
329
|
+
/* gcc < 8 only has signed-integer-overlow which triggers on pointer overflow */
|
|
330
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR __attribute__((no_sanitize("signed-integer-overflow")))
|
|
331
|
+
# else
|
|
332
|
+
/* older versions of clang [3.7, 5.0) will warn that pointer-overflow is ignored. */
|
|
333
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR __attribute__((no_sanitize("pointer-overflow")))
|
|
334
|
+
# endif
|
|
335
|
+
# else
|
|
336
|
+
# define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
|
337
|
+
# endif
|
|
338
|
+
#endif
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Helper function to perform a wrapped pointer difference without triggering
|
|
342
|
+
* UBSAN.
|
|
343
|
+
*
|
|
344
|
+
* @returns lhs - rhs with wrapping
|
|
345
|
+
*/
|
|
346
|
+
MEM_STATIC
|
|
347
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
|
348
|
+
ptrdiff_t ZSTD_wrappedPtrDiff(unsigned char const* lhs, unsigned char const* rhs)
|
|
349
|
+
{
|
|
350
|
+
return lhs - rhs;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Helper function to perform a wrapped pointer add without triggering UBSAN.
|
|
355
|
+
*
|
|
356
|
+
* @return ptr + add with wrapping
|
|
357
|
+
*/
|
|
358
|
+
MEM_STATIC
|
|
359
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
|
360
|
+
unsigned char const* ZSTD_wrappedPtrAdd(unsigned char const* ptr, ptrdiff_t add)
|
|
361
|
+
{
|
|
362
|
+
return ptr + add;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Helper function to perform a wrapped pointer subtraction without triggering
|
|
367
|
+
* UBSAN.
|
|
368
|
+
*
|
|
369
|
+
* @return ptr - sub with wrapping
|
|
370
|
+
*/
|
|
371
|
+
MEM_STATIC
|
|
372
|
+
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
|
|
373
|
+
unsigned char const* ZSTD_wrappedPtrSub(unsigned char const* ptr, ptrdiff_t sub)
|
|
374
|
+
{
|
|
375
|
+
return ptr - sub;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Helper function to add to a pointer that works around C's undefined behavior
|
|
380
|
+
* of adding 0 to NULL.
|
|
381
|
+
*
|
|
382
|
+
* @returns `ptr + add` except it defines `NULL + 0 == NULL`.
|
|
383
|
+
*/
|
|
384
|
+
MEM_STATIC
|
|
385
|
+
unsigned char* ZSTD_maybeNullPtrAdd(unsigned char* ptr, ptrdiff_t add)
|
|
386
|
+
{
|
|
387
|
+
return add > 0 ? ptr + add : ptr;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/* Issue #3240 reports an ASAN failure on an llvm-mingw build. Out of an
|
|
391
|
+
* abundance of caution, disable our custom poisoning on mingw. */
|
|
392
|
+
#ifdef __MINGW32__
|
|
393
|
+
#ifndef ZSTD_ASAN_DONT_POISON_WORKSPACE
|
|
394
|
+
#define ZSTD_ASAN_DONT_POISON_WORKSPACE 1
|
|
395
|
+
#endif
|
|
396
|
+
#ifndef ZSTD_MSAN_DONT_POISON_WORKSPACE
|
|
397
|
+
#define ZSTD_MSAN_DONT_POISON_WORKSPACE 1
|
|
398
|
+
#endif
|
|
399
|
+
#endif
|
|
400
|
+
|
|
401
|
+
#if ZSTD_MEMORY_SANITIZER && !defined(ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
|
277
402
|
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
|
278
403
|
* We therefore declare the functions we need ourselves, rather than trying to
|
|
279
404
|
* include the header file... */
|
|
@@ -292,9 +417,13 @@ void __msan_poison(const volatile void *a, size_t size);
|
|
|
292
417
|
/* Returns the offset of the first (at least partially) poisoned byte in the
|
|
293
418
|
memory range, or -1 if the whole range is good. */
|
|
294
419
|
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
|
420
|
+
|
|
421
|
+
/* Print shadow and origin for the memory range to stderr in a human-readable
|
|
422
|
+
format. */
|
|
423
|
+
void __msan_print_shadow(const volatile void *x, size_t size);
|
|
295
424
|
#endif
|
|
296
425
|
|
|
297
|
-
#if ZSTD_ADDRESS_SANITIZER
|
|
426
|
+
#if ZSTD_ADDRESS_SANITIZER && !defined(ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
|
298
427
|
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
|
299
428
|
* We therefore declare the functions we need ourselves, rather than trying to
|
|
300
429
|
* include the header file... */
|
|
@@ -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
|
|
@@ -35,6 +35,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
|
|
|
35
35
|
U32 f7b = 0;
|
|
36
36
|
U32 f7c = 0;
|
|
37
37
|
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
|
38
|
+
#if !defined(_M_X64) || !defined(__clang__) || __clang_major__ >= 16
|
|
38
39
|
int reg[4];
|
|
39
40
|
__cpuid((int*)reg, 0);
|
|
40
41
|
{
|
|
@@ -50,6 +51,41 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
|
|
|
50
51
|
f7c = (U32)reg[2];
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
#else
|
|
55
|
+
/* Clang compiler has a bug (fixed in https://reviews.llvm.org/D101338) in
|
|
56
|
+
* which the `__cpuid` intrinsic does not save and restore `rbx` as it needs
|
|
57
|
+
* to due to being a reserved register. So in that case, do the `cpuid`
|
|
58
|
+
* ourselves. Clang supports inline assembly anyway.
|
|
59
|
+
*/
|
|
60
|
+
U32 n;
|
|
61
|
+
__asm__(
|
|
62
|
+
"pushq %%rbx\n\t"
|
|
63
|
+
"cpuid\n\t"
|
|
64
|
+
"popq %%rbx\n\t"
|
|
65
|
+
: "=a"(n)
|
|
66
|
+
: "a"(0)
|
|
67
|
+
: "rcx", "rdx");
|
|
68
|
+
if (n >= 1) {
|
|
69
|
+
U32 f1a;
|
|
70
|
+
__asm__(
|
|
71
|
+
"pushq %%rbx\n\t"
|
|
72
|
+
"cpuid\n\t"
|
|
73
|
+
"popq %%rbx\n\t"
|
|
74
|
+
: "=a"(f1a), "=c"(f1c), "=d"(f1d)
|
|
75
|
+
: "a"(1)
|
|
76
|
+
:);
|
|
77
|
+
}
|
|
78
|
+
if (n >= 7) {
|
|
79
|
+
__asm__(
|
|
80
|
+
"pushq %%rbx\n\t"
|
|
81
|
+
"cpuid\n\t"
|
|
82
|
+
"movq %%rbx, %%rax\n\t"
|
|
83
|
+
"popq %%rbx"
|
|
84
|
+
: "=a"(f7b), "=c"(f7c)
|
|
85
|
+
: "a"(7), "c"(0)
|
|
86
|
+
: "rdx");
|
|
87
|
+
}
|
|
88
|
+
#endif
|
|
53
89
|
#elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
|
|
54
90
|
/* The following block like the normal cpuid branch below, but gcc
|
|
55
91
|
* reserves ebx for use of its pic register so we must specially
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* ******************************************************************
|
|
2
2
|
* debug
|
|
3
3
|
* Part of FSE library
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
5
|
*
|
|
6
6
|
* You can contact the author at :
|
|
7
7
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
@@ -21,4 +21,10 @@
|
|
|
21
21
|
|
|
22
22
|
#include "debug.h"
|
|
23
23
|
|
|
24
|
+
#if !defined(ZSTD_LINUX_KERNEL) || (DEBUGLEVEL>=2)
|
|
25
|
+
/* We only use this when DEBUGLEVEL>=2, but we get -Werror=pedantic errors if a
|
|
26
|
+
* translation unit is empty. So remove this from Linux kernel builds, but
|
|
27
|
+
* otherwise just leave it in.
|
|
28
|
+
*/
|
|
24
29
|
int g_debuglevel = DEBUGLEVEL;
|
|
30
|
+
#endif
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* ******************************************************************
|
|
2
2
|
* debug
|
|
3
3
|
* Part of FSE library
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
5
|
*
|
|
6
6
|
* You can contact the author at :
|
|
7
7
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
#ifndef DEBUG_H_12987983217
|
|
33
33
|
#define DEBUG_H_12987983217
|
|
34
34
|
|
|
35
|
-
#if defined (__cplusplus)
|
|
36
|
-
extern "C" {
|
|
37
|
-
#endif
|
|
38
|
-
|
|
39
35
|
|
|
40
36
|
/* static assert is triggered at compile time, leaving no runtime artefact.
|
|
41
37
|
* static assert only works with compile-time constants.
|
|
@@ -85,23 +81,27 @@ extern int g_debuglevel; /* the variable is only declared,
|
|
|
85
81
|
It's useful when enabling very verbose levels
|
|
86
82
|
on selective conditions (such as position in src) */
|
|
87
83
|
|
|
88
|
-
# define RAWLOG(l, ...)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
# define RAWLOG(l, ...) \
|
|
85
|
+
do { \
|
|
86
|
+
if (l<=g_debuglevel) { \
|
|
87
|
+
ZSTD_DEBUG_PRINT(__VA_ARGS__); \
|
|
88
|
+
} \
|
|
89
|
+
} while (0)
|
|
90
|
+
|
|
91
|
+
#define STRINGIFY(x) #x
|
|
92
|
+
#define TOSTRING(x) STRINGIFY(x)
|
|
93
|
+
#define LINE_AS_STRING TOSTRING(__LINE__)
|
|
94
|
+
|
|
95
|
+
# define DEBUGLOG(l, ...) \
|
|
96
|
+
do { \
|
|
97
|
+
if (l<=g_debuglevel) { \
|
|
98
|
+
ZSTD_DEBUG_PRINT(__FILE__ ":" LINE_AS_STRING ": " __VA_ARGS__); \
|
|
99
|
+
ZSTD_DEBUG_PRINT(" \n"); \
|
|
100
|
+
} \
|
|
101
|
+
} while (0)
|
|
97
102
|
#else
|
|
98
|
-
# define RAWLOG(l, ...)
|
|
99
|
-
# define DEBUGLOG(l, ...)
|
|
100
|
-
#endif
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
#if defined (__cplusplus)
|
|
104
|
-
}
|
|
103
|
+
# define RAWLOG(l, ...) do { } while (0) /* disabled */
|
|
104
|
+
# define DEBUGLOG(l, ...) do { } while (0) /* disabled */
|
|
105
105
|
#endif
|
|
106
106
|
|
|
107
107
|
#endif /* DEBUG_H_12987983217 */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* ******************************************************************
|
|
2
2
|
* Common functions of New Generation Entropy library
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* You can contact the author at :
|
|
6
6
|
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
#include "error_private.h" /* ERR_*, ERROR */
|
|
20
20
|
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
|
21
21
|
#include "fse.h"
|
|
22
|
-
#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
|
|
23
22
|
#include "huf.h"
|
|
23
|
+
#include "bits.h" /* ZSDT_highbit32, ZSTD_countTrailingZeros32 */
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
/*=== Version ===*/
|
|
@@ -38,34 +38,6 @@ const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
|
|
38
38
|
/*-**************************************************************
|
|
39
39
|
* FSE NCount encoding-decoding
|
|
40
40
|
****************************************************************/
|
|
41
|
-
static U32 FSE_ctz(U32 val)
|
|
42
|
-
{
|
|
43
|
-
assert(val != 0);
|
|
44
|
-
{
|
|
45
|
-
# if defined(_MSC_VER) /* Visual */
|
|
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
|
-
}
|
|
54
|
-
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
|
55
|
-
return __builtin_ctz(val);
|
|
56
|
-
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
|
57
|
-
return __CTZ(val);
|
|
58
|
-
# else /* Software version */
|
|
59
|
-
U32 count = 0;
|
|
60
|
-
while ((val & 1) == 0) {
|
|
61
|
-
val >>= 1;
|
|
62
|
-
++count;
|
|
63
|
-
}
|
|
64
|
-
return count;
|
|
65
|
-
# endif
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
41
|
FORCE_INLINE_TEMPLATE
|
|
70
42
|
size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
|
71
43
|
const void* headerBuffer, size_t hbSize)
|
|
@@ -113,7 +85,7 @@ size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigne
|
|
|
113
85
|
* repeat.
|
|
114
86
|
* Avoid UB by setting the high bit to 1.
|
|
115
87
|
*/
|
|
116
|
-
int repeats =
|
|
88
|
+
int repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
|
|
117
89
|
while (repeats >= 12) {
|
|
118
90
|
charnum += 3 * 12;
|
|
119
91
|
if (LIKELY(ip <= iend-7)) {
|
|
@@ -124,7 +96,7 @@ size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigne
|
|
|
124
96
|
ip = iend - 4;
|
|
125
97
|
}
|
|
126
98
|
bitStream = MEM_readLE32(ip) >> bitCount;
|
|
127
|
-
repeats =
|
|
99
|
+
repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
|
|
128
100
|
}
|
|
129
101
|
charnum += 3 * repeats;
|
|
130
102
|
bitStream >>= 2 * repeats;
|
|
@@ -189,7 +161,7 @@ size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigne
|
|
|
189
161
|
* know that threshold > 1.
|
|
190
162
|
*/
|
|
191
163
|
if (remaining <= 1) break;
|
|
192
|
-
nbBits =
|
|
164
|
+
nbBits = ZSTD_highbit32(remaining) + 1;
|
|
193
165
|
threshold = 1 << (nbBits - 1);
|
|
194
166
|
}
|
|
195
167
|
if (charnum >= maxSV1) break;
|
|
@@ -264,7 +236,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|
|
264
236
|
const void* src, size_t srcSize)
|
|
265
237
|
{
|
|
266
238
|
U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
|
|
267
|
-
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /*
|
|
239
|
+
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* flags */ 0);
|
|
268
240
|
}
|
|
269
241
|
|
|
270
242
|
FORCE_INLINE_TEMPLATE size_t
|
|
@@ -312,14 +284,14 @@ HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|
|
312
284
|
if (weightTotal == 0) return ERROR(corruption_detected);
|
|
313
285
|
|
|
314
286
|
/* get last non-null symbol weight (implied, total must be 2^n) */
|
|
315
|
-
{ U32 const tableLog =
|
|
287
|
+
{ U32 const tableLog = ZSTD_highbit32(weightTotal) + 1;
|
|
316
288
|
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
|
317
289
|
*tableLogPtr = tableLog;
|
|
318
290
|
/* determine last weight */
|
|
319
291
|
{ U32 const total = 1 << tableLog;
|
|
320
292
|
U32 const rest = total - weightTotal;
|
|
321
|
-
U32 const verif = 1 <<
|
|
322
|
-
U32 const lastWeight =
|
|
293
|
+
U32 const verif = 1 << ZSTD_highbit32(rest);
|
|
294
|
+
U32 const lastWeight = ZSTD_highbit32(rest) + 1;
|
|
323
295
|
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
|
324
296
|
huffWeight[oSize] = (BYTE)lastWeight;
|
|
325
297
|
rankStats[lastWeight]++;
|
|
@@ -356,13 +328,13 @@ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|
|
356
328
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
|
357
329
|
const void* src, size_t srcSize,
|
|
358
330
|
void* workSpace, size_t wkspSize,
|
|
359
|
-
int
|
|
331
|
+
int flags)
|
|
360
332
|
{
|
|
361
333
|
#if DYNAMIC_BMI2
|
|
362
|
-
if (
|
|
334
|
+
if (flags & HUF_flags_bmi2) {
|
|
363
335
|
return HUF_readStats_body_bmi2(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
|
364
336
|
}
|
|
365
337
|
#endif
|
|
366
|
-
(void)
|
|
338
|
+
(void)flags;
|
|
367
339
|
return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
|
368
340
|
}
|
|
@@ -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
|
|
@@ -27,9 +27,11 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
|
27
27
|
case PREFIX(version_unsupported): return "Version not supported";
|
|
28
28
|
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
|
29
29
|
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
|
30
|
-
case PREFIX(corruption_detected): return "
|
|
30
|
+
case PREFIX(corruption_detected): return "Data corruption detected";
|
|
31
31
|
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
|
32
|
+
case PREFIX(literals_headerWrong): return "Header of Literals' block doesn't respect format specification";
|
|
32
33
|
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
|
34
|
+
case PREFIX(parameter_combination_unsupported): return "Unsupported combination of parameters";
|
|
33
35
|
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
|
34
36
|
case PREFIX(init_missing): return "Context should be init first";
|
|
35
37
|
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
|
@@ -38,17 +40,23 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
|
38
40
|
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
|
39
41
|
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
|
|
40
42
|
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
|
43
|
+
case PREFIX(cannotProduce_uncompressedBlock): return "This mode cannot generate an uncompressed block";
|
|
44
|
+
case PREFIX(stabilityCondition_notRespected): return "pledged buffer stability condition is not respected";
|
|
41
45
|
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
|
42
46
|
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
|
43
47
|
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
|
44
48
|
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
|
45
49
|
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
|
46
50
|
case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
|
|
51
|
+
case PREFIX(noForwardProgress_destFull): return "Operation made no progress over multiple calls, due to output buffer being full";
|
|
52
|
+
case PREFIX(noForwardProgress_inputEmpty): return "Operation made no progress over multiple calls, due to input being empty";
|
|
47
53
|
/* following error codes are not stable and may be removed or changed in a future version */
|
|
48
54
|
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
|
49
55
|
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
|
50
56
|
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
|
|
51
57
|
case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
|
|
58
|
+
case PREFIX(sequenceProducer_failed): return "Block-level external sequence producer returned an error code";
|
|
59
|
+
case PREFIX(externalSequences_invalid): return "External sequences are not valid";
|
|
52
60
|
case PREFIX(maxCode):
|
|
53
61
|
default: return notErrorCode;
|
|
54
62
|
}
|