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,7 +1,7 @@
|
|
|
1
1
|
/* ******************************************************************
|
|
2
2
|
* bitstream
|
|
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
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
#ifndef BITSTREAM_H_MODULE
|
|
15
15
|
#define BITSTREAM_H_MODULE
|
|
16
16
|
|
|
17
|
-
#if defined (__cplusplus)
|
|
18
|
-
extern "C" {
|
|
19
|
-
#endif
|
|
20
17
|
/*
|
|
21
18
|
* This API consists of small unitary functions, which must be inlined for best performance.
|
|
22
19
|
* Since link-time-optimization is not available for all compilers,
|
|
@@ -30,14 +27,14 @@ extern "C" {
|
|
|
30
27
|
#include "compiler.h" /* UNLIKELY() */
|
|
31
28
|
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
|
|
32
29
|
#include "error_private.h" /* error codes and messages */
|
|
33
|
-
|
|
30
|
+
#include "bits.h" /* ZSTD_highbit32 */
|
|
34
31
|
|
|
35
32
|
/*=========================================
|
|
36
33
|
* Target specific
|
|
37
34
|
=========================================*/
|
|
38
35
|
#ifndef ZSTD_NO_INTRINSICS
|
|
39
|
-
# if defined(__BMI__) && defined(__GNUC__)
|
|
40
|
-
# include <immintrin.h> /* support for bextr (experimental) */
|
|
36
|
+
# if (defined(__BMI__) || defined(__BMI2__)) && defined(__GNUC__)
|
|
37
|
+
# include <immintrin.h> /* support for bextr (experimental)/bzhi */
|
|
41
38
|
# elif defined(__ICCARM__)
|
|
42
39
|
# include <intrinsics.h>
|
|
43
40
|
# endif
|
|
@@ -51,12 +48,13 @@ extern "C" {
|
|
|
51
48
|
/*-******************************************
|
|
52
49
|
* bitStream encoding API (write forward)
|
|
53
50
|
********************************************/
|
|
51
|
+
typedef size_t BitContainerType;
|
|
54
52
|
/* bitStream can mix input from multiple sources.
|
|
55
53
|
* A critical property of these streams is that they encode and decode in **reverse** direction.
|
|
56
54
|
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
|
|
57
55
|
*/
|
|
58
56
|
typedef struct {
|
|
59
|
-
|
|
57
|
+
BitContainerType bitContainer;
|
|
60
58
|
unsigned bitPos;
|
|
61
59
|
char* startPtr;
|
|
62
60
|
char* ptr;
|
|
@@ -64,7 +62,7 @@ typedef struct {
|
|
|
64
62
|
} BIT_CStream_t;
|
|
65
63
|
|
|
66
64
|
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity);
|
|
67
|
-
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
|
65
|
+
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, BitContainerType value, unsigned nbBits);
|
|
68
66
|
MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC);
|
|
69
67
|
MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
|
|
70
68
|
|
|
@@ -73,7 +71,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
|
|
|
73
71
|
* `dstCapacity` must be >= sizeof(bitD->bitContainer), otherwise @return will be an error code.
|
|
74
72
|
*
|
|
75
73
|
* bits are first added to a local register.
|
|
76
|
-
* Local register is
|
|
74
|
+
* Local register is BitContainerType, 64-bits on 64-bits systems, or 32-bits on 32-bits systems.
|
|
77
75
|
* Writing data into memory is an explicit operation, performed by the flushBits function.
|
|
78
76
|
* Hence keep track how many bits are potentially stored into local register to avoid register overflow.
|
|
79
77
|
* After a flushBits, a maximum of 7 bits might still be stored into local register.
|
|
@@ -90,28 +88,28 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
|
|
|
90
88
|
* bitStream decoding API (read backward)
|
|
91
89
|
**********************************************/
|
|
92
90
|
typedef struct {
|
|
93
|
-
|
|
91
|
+
BitContainerType bitContainer;
|
|
94
92
|
unsigned bitsConsumed;
|
|
95
93
|
const char* ptr;
|
|
96
94
|
const char* start;
|
|
97
95
|
const char* limitPtr;
|
|
98
96
|
} BIT_DStream_t;
|
|
99
97
|
|
|
100
|
-
typedef enum { BIT_DStream_unfinished = 0,
|
|
101
|
-
BIT_DStream_endOfBuffer = 1,
|
|
102
|
-
BIT_DStream_completed = 2,
|
|
103
|
-
BIT_DStream_overflow = 3
|
|
104
|
-
|
|
98
|
+
typedef enum { BIT_DStream_unfinished = 0, /* fully refilled */
|
|
99
|
+
BIT_DStream_endOfBuffer = 1, /* still some bits left in bitstream */
|
|
100
|
+
BIT_DStream_completed = 2, /* bitstream entirely consumed, bit-exact */
|
|
101
|
+
BIT_DStream_overflow = 3 /* user requested more bits than present in bitstream */
|
|
102
|
+
} BIT_DStream_status; /* result of BIT_reloadDStream() */
|
|
105
103
|
|
|
106
104
|
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
|
|
107
|
-
MEM_STATIC
|
|
105
|
+
MEM_STATIC BitContainerType BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
|
|
108
106
|
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
|
|
109
107
|
MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
|
|
110
108
|
|
|
111
109
|
|
|
112
110
|
/* Start by invoking BIT_initDStream().
|
|
113
111
|
* A chunk of the bitStream is then stored into a local register.
|
|
114
|
-
* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (
|
|
112
|
+
* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (BitContainerType).
|
|
115
113
|
* You can then retrieve bitFields stored into the local register, **in reverse order**.
|
|
116
114
|
* Local register is explicitly reloaded from memory by the BIT_reloadDStream() method.
|
|
117
115
|
* A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished.
|
|
@@ -123,7 +121,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
|
|
|
123
121
|
/*-****************************************
|
|
124
122
|
* unsafe API
|
|
125
123
|
******************************************/
|
|
126
|
-
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
|
124
|
+
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, BitContainerType value, unsigned nbBits);
|
|
127
125
|
/* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */
|
|
128
126
|
|
|
129
127
|
MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC);
|
|
@@ -132,48 +130,6 @@ MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC);
|
|
|
132
130
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
|
133
131
|
/* faster, but works only if nbBits >= 1 */
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/*-**************************************************************
|
|
138
|
-
* Internal functions
|
|
139
|
-
****************************************************************/
|
|
140
|
-
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
|
141
|
-
{
|
|
142
|
-
assert(val != 0);
|
|
143
|
-
{
|
|
144
|
-
# if defined(_MSC_VER) /* Visual */
|
|
145
|
-
# if STATIC_BMI2 == 1
|
|
146
|
-
return _lzcnt_u32(val) ^ 31;
|
|
147
|
-
# else
|
|
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
|
-
}
|
|
156
|
-
# endif
|
|
157
|
-
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
|
158
|
-
return __builtin_clz (val) ^ 31;
|
|
159
|
-
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
|
160
|
-
return 31 - __CLZ(val);
|
|
161
|
-
# else /* Software version */
|
|
162
|
-
static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
|
|
163
|
-
11, 14, 16, 18, 22, 25, 3, 30,
|
|
164
|
-
8, 12, 20, 28, 15, 17, 24, 7,
|
|
165
|
-
19, 27, 23, 6, 26, 5, 4, 31 };
|
|
166
|
-
U32 v = val;
|
|
167
|
-
v |= v >> 1;
|
|
168
|
-
v |= v >> 2;
|
|
169
|
-
v |= v >> 4;
|
|
170
|
-
v |= v >> 8;
|
|
171
|
-
v |= v >> 16;
|
|
172
|
-
return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
|
|
173
|
-
# endif
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
133
|
/*===== Local Constants =====*/
|
|
178
134
|
static const unsigned BIT_mask[] = {
|
|
179
135
|
0, 1, 3, 7, 0xF, 0x1F,
|
|
@@ -203,16 +159,31 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
|
|
203
159
|
return 0;
|
|
204
160
|
}
|
|
205
161
|
|
|
162
|
+
FORCE_INLINE_TEMPLATE BitContainerType BIT_getLowerBits(BitContainerType bitContainer, U32 const nbBits)
|
|
163
|
+
{
|
|
164
|
+
#if STATIC_BMI2 && !defined(ZSTD_NO_INTRINSICS)
|
|
165
|
+
# if (defined(__x86_64__) || defined(_M_X64)) && !defined(__ILP32__)
|
|
166
|
+
return _bzhi_u64(bitContainer, nbBits);
|
|
167
|
+
# else
|
|
168
|
+
DEBUG_STATIC_ASSERT(sizeof(bitContainer) == sizeof(U32));
|
|
169
|
+
return _bzhi_u32(bitContainer, nbBits);
|
|
170
|
+
# endif
|
|
171
|
+
#else
|
|
172
|
+
assert(nbBits < BIT_MASK_SIZE);
|
|
173
|
+
return bitContainer & BIT_mask[nbBits];
|
|
174
|
+
#endif
|
|
175
|
+
}
|
|
176
|
+
|
|
206
177
|
/*! BIT_addBits() :
|
|
207
178
|
* can add up to 31 bits into `bitC`.
|
|
208
179
|
* Note : does not check for register overflow ! */
|
|
209
180
|
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
|
210
|
-
|
|
181
|
+
BitContainerType value, unsigned nbBits)
|
|
211
182
|
{
|
|
212
183
|
DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
|
|
213
184
|
assert(nbBits < BIT_MASK_SIZE);
|
|
214
185
|
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
|
215
|
-
bitC->bitContainer |= (value
|
|
186
|
+
bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
|
|
216
187
|
bitC->bitPos += nbBits;
|
|
217
188
|
}
|
|
218
189
|
|
|
@@ -220,7 +191,7 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
|
|
220
191
|
* works only if `value` is _clean_,
|
|
221
192
|
* meaning all high bits above nbBits are 0 */
|
|
222
193
|
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
|
223
|
-
|
|
194
|
+
BitContainerType value, unsigned nbBits)
|
|
224
195
|
{
|
|
225
196
|
assert((value>>nbBits) == 0);
|
|
226
197
|
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
|
@@ -267,7 +238,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
|
|
|
267
238
|
BIT_addBitsFast(bitC, 1, 1); /* endMark */
|
|
268
239
|
BIT_flushBits(bitC);
|
|
269
240
|
if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
|
|
270
|
-
return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
|
|
241
|
+
return (size_t)(bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
|
|
271
242
|
}
|
|
272
243
|
|
|
273
244
|
|
|
@@ -291,35 +262,35 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|
|
291
262
|
bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
|
|
292
263
|
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
|
293
264
|
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
|
294
|
-
bitD->bitsConsumed = lastByte ? 8 -
|
|
265
|
+
bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
|
|
295
266
|
if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
|
|
296
267
|
} else {
|
|
297
268
|
bitD->ptr = bitD->start;
|
|
298
269
|
bitD->bitContainer = *(const BYTE*)(bitD->start);
|
|
299
270
|
switch(srcSize)
|
|
300
271
|
{
|
|
301
|
-
case 7: bitD->bitContainer += (
|
|
272
|
+
case 7: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
|
|
302
273
|
ZSTD_FALLTHROUGH;
|
|
303
274
|
|
|
304
|
-
case 6: bitD->bitContainer += (
|
|
275
|
+
case 6: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
|
|
305
276
|
ZSTD_FALLTHROUGH;
|
|
306
277
|
|
|
307
|
-
case 5: bitD->bitContainer += (
|
|
278
|
+
case 5: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
|
|
308
279
|
ZSTD_FALLTHROUGH;
|
|
309
280
|
|
|
310
|
-
case 4: bitD->bitContainer += (
|
|
281
|
+
case 4: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[3]) << 24;
|
|
311
282
|
ZSTD_FALLTHROUGH;
|
|
312
283
|
|
|
313
|
-
case 3: bitD->bitContainer += (
|
|
284
|
+
case 3: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[2]) << 16;
|
|
314
285
|
ZSTD_FALLTHROUGH;
|
|
315
286
|
|
|
316
|
-
case 2: bitD->bitContainer += (
|
|
287
|
+
case 2: bitD->bitContainer += (BitContainerType)(((const BYTE*)(srcBuffer))[1]) << 8;
|
|
317
288
|
ZSTD_FALLTHROUGH;
|
|
318
289
|
|
|
319
290
|
default: break;
|
|
320
291
|
}
|
|
321
292
|
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
|
322
|
-
bitD->bitsConsumed = lastByte ? 8 -
|
|
293
|
+
bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
|
|
323
294
|
if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */
|
|
324
295
|
}
|
|
325
296
|
bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
|
|
@@ -328,12 +299,12 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|
|
328
299
|
return srcSize;
|
|
329
300
|
}
|
|
330
301
|
|
|
331
|
-
|
|
302
|
+
FORCE_INLINE_TEMPLATE BitContainerType BIT_getUpperBits(BitContainerType bitContainer, U32 const start)
|
|
332
303
|
{
|
|
333
304
|
return bitContainer >> start;
|
|
334
305
|
}
|
|
335
306
|
|
|
336
|
-
|
|
307
|
+
FORCE_INLINE_TEMPLATE BitContainerType BIT_getMiddleBits(BitContainerType bitContainer, U32 const start, U32 const nbBits)
|
|
337
308
|
{
|
|
338
309
|
U32 const regMask = sizeof(bitContainer)*8 - 1;
|
|
339
310
|
/* if start > regMask, bitstream is corrupted, and result is undefined */
|
|
@@ -343,30 +314,20 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 c
|
|
|
343
314
|
* such cpus old (pre-Haswell, 2013) and their performance is not of that
|
|
344
315
|
* importance.
|
|
345
316
|
*/
|
|
346
|
-
#if defined(__x86_64__) || defined(
|
|
317
|
+
#if defined(__x86_64__) || defined(_M_X64)
|
|
347
318
|
return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
|
|
348
319
|
#else
|
|
349
320
|
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
|
|
350
321
|
#endif
|
|
351
322
|
}
|
|
352
323
|
|
|
353
|
-
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
|
354
|
-
{
|
|
355
|
-
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1
|
|
356
|
-
return _bzhi_u64(bitContainer, nbBits);
|
|
357
|
-
#else
|
|
358
|
-
assert(nbBits < BIT_MASK_SIZE);
|
|
359
|
-
return bitContainer & BIT_mask[nbBits];
|
|
360
|
-
#endif
|
|
361
|
-
}
|
|
362
|
-
|
|
363
324
|
/*! BIT_lookBits() :
|
|
364
325
|
* Provides next n bits from local register.
|
|
365
326
|
* local register is not modified.
|
|
366
327
|
* On 32-bits, maxNbBits==24.
|
|
367
328
|
* On 64-bits, maxNbBits==56.
|
|
368
329
|
* @return : value extracted */
|
|
369
|
-
|
|
330
|
+
FORCE_INLINE_TEMPLATE BitContainerType BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
|
|
370
331
|
{
|
|
371
332
|
/* arbitrate between double-shift and shift+mask */
|
|
372
333
|
#if 1
|
|
@@ -382,14 +343,14 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_lookBits(const BIT_DStream_t* bitD, U3
|
|
|
382
343
|
|
|
383
344
|
/*! BIT_lookBitsFast() :
|
|
384
345
|
* unsafe version; only works if nbBits >= 1 */
|
|
385
|
-
MEM_STATIC
|
|
346
|
+
MEM_STATIC BitContainerType BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
|
|
386
347
|
{
|
|
387
348
|
U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
|
|
388
349
|
assert(nbBits >= 1);
|
|
389
350
|
return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
|
|
390
351
|
}
|
|
391
352
|
|
|
392
|
-
|
|
353
|
+
FORCE_INLINE_TEMPLATE void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
|
393
354
|
{
|
|
394
355
|
bitD->bitsConsumed += nbBits;
|
|
395
356
|
}
|
|
@@ -398,23 +359,38 @@ MEM_STATIC FORCE_INLINE_ATTR void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
|
|
398
359
|
* Read (consume) next n bits from local register and update.
|
|
399
360
|
* Pay attention to not read more than nbBits contained into local register.
|
|
400
361
|
* @return : extracted value. */
|
|
401
|
-
|
|
362
|
+
FORCE_INLINE_TEMPLATE BitContainerType BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
|
|
402
363
|
{
|
|
403
|
-
|
|
364
|
+
BitContainerType const value = BIT_lookBits(bitD, nbBits);
|
|
404
365
|
BIT_skipBits(bitD, nbBits);
|
|
405
366
|
return value;
|
|
406
367
|
}
|
|
407
368
|
|
|
408
369
|
/*! BIT_readBitsFast() :
|
|
409
|
-
* unsafe version; only works
|
|
410
|
-
MEM_STATIC
|
|
370
|
+
* unsafe version; only works if nbBits >= 1 */
|
|
371
|
+
MEM_STATIC BitContainerType BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
|
|
411
372
|
{
|
|
412
|
-
|
|
373
|
+
BitContainerType const value = BIT_lookBitsFast(bitD, nbBits);
|
|
413
374
|
assert(nbBits >= 1);
|
|
414
375
|
BIT_skipBits(bitD, nbBits);
|
|
415
376
|
return value;
|
|
416
377
|
}
|
|
417
378
|
|
|
379
|
+
/*! BIT_reloadDStream_internal() :
|
|
380
|
+
* Simple variant of BIT_reloadDStream(), with two conditions:
|
|
381
|
+
* 1. bitstream is valid : bitsConsumed <= sizeof(bitD->bitContainer)*8
|
|
382
|
+
* 2. look window is valid after shifted down : bitD->ptr >= bitD->start
|
|
383
|
+
*/
|
|
384
|
+
MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal(BIT_DStream_t* bitD)
|
|
385
|
+
{
|
|
386
|
+
assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
|
|
387
|
+
bitD->ptr -= bitD->bitsConsumed >> 3;
|
|
388
|
+
assert(bitD->ptr >= bitD->start);
|
|
389
|
+
bitD->bitsConsumed &= 7;
|
|
390
|
+
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
|
391
|
+
return BIT_DStream_unfinished;
|
|
392
|
+
}
|
|
393
|
+
|
|
418
394
|
/*! BIT_reloadDStreamFast() :
|
|
419
395
|
* Similar to BIT_reloadDStream(), but with two differences:
|
|
420
396
|
* 1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
|
|
@@ -425,31 +401,35 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
|
|
|
425
401
|
{
|
|
426
402
|
if (UNLIKELY(bitD->ptr < bitD->limitPtr))
|
|
427
403
|
return BIT_DStream_overflow;
|
|
428
|
-
|
|
429
|
-
bitD->ptr -= bitD->bitsConsumed >> 3;
|
|
430
|
-
bitD->bitsConsumed &= 7;
|
|
431
|
-
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
|
432
|
-
return BIT_DStream_unfinished;
|
|
404
|
+
return BIT_reloadDStream_internal(bitD);
|
|
433
405
|
}
|
|
434
406
|
|
|
435
407
|
/*! BIT_reloadDStream() :
|
|
436
408
|
* Refill `bitD` from buffer previously set in BIT_initDStream() .
|
|
437
|
-
* This function is safe, it guarantees it will not
|
|
409
|
+
* This function is safe, it guarantees it will not never beyond src buffer.
|
|
438
410
|
* @return : status of `BIT_DStream_t` internal register.
|
|
439
411
|
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
|
|
440
|
-
|
|
412
|
+
FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
|
441
413
|
{
|
|
442
|
-
|
|
414
|
+
/* note : once in overflow mode, a bitstream remains in this mode until it's reset */
|
|
415
|
+
if (UNLIKELY(bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8))) {
|
|
416
|
+
static const BitContainerType zeroFilled = 0;
|
|
417
|
+
bitD->ptr = (const char*)&zeroFilled; /* aliasing is allowed for char */
|
|
418
|
+
/* overflow detected, erroneous scenario or end of stream: no update */
|
|
443
419
|
return BIT_DStream_overflow;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
assert(bitD->ptr >= bitD->start);
|
|
444
423
|
|
|
445
424
|
if (bitD->ptr >= bitD->limitPtr) {
|
|
446
|
-
return
|
|
425
|
+
return BIT_reloadDStream_internal(bitD);
|
|
447
426
|
}
|
|
448
427
|
if (bitD->ptr == bitD->start) {
|
|
428
|
+
/* reached end of bitStream => no update */
|
|
449
429
|
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
|
|
450
430
|
return BIT_DStream_completed;
|
|
451
431
|
}
|
|
452
|
-
/* start < ptr < limitPtr */
|
|
432
|
+
/* start < ptr < limitPtr => cautious update */
|
|
453
433
|
{ U32 nbBytes = bitD->bitsConsumed >> 3;
|
|
454
434
|
BIT_DStream_status result = BIT_DStream_unfinished;
|
|
455
435
|
if (bitD->ptr - nbBytes < bitD->start) {
|
|
@@ -471,8 +451,4 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
|
|
|
471
451
|
return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
|
|
472
452
|
}
|
|
473
453
|
|
|
474
|
-
#if defined (__cplusplus)
|
|
475
|
-
}
|
|
476
|
-
#endif
|
|
477
|
-
|
|
478
454
|
#endif /* BITSTREAM_H_MODULE */
|