multi_compress 0.1.0
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 +7 -0
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +116 -0
- data/ext/multi_compress/extconf.rb +171 -0
- data/ext/multi_compress/multi_compress.c +1534 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.c +15 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.h +201 -0
- data/ext/multi_compress/vendor/brotli/c/common/context.c +156 -0
- data/ext/multi_compress/vendor/brotli/c/common/context.h +113 -0
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +5916 -0
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +64 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.c +23 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.h +541 -0
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +521 -0
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.c +291 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.h +85 -0
- data/ext/multi_compress/vendor/brotli/c/common/version.h +51 -0
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +78 -0
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +423 -0
- data/ext/multi_compress/vendor/brotli/c/dec/decode.c +2875 -0
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +342 -0
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +122 -0
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +733 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.c +183 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.h +400 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +207 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +40 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +939 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +96 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_inc.h +189 -0
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +36 -0
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +64 -0
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +127 -0
- data/ext/multi_compress/vendor/brotli/c/enc/block_encoder_inc.h +34 -0
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +217 -0
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +52 -0
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +481 -0
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +1336 -0
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +89 -0
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +57 -0
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +49 -0
- data/ext/multi_compress/vendor/brotli/c/enc/cluster_inc.h +325 -0
- data/ext/multi_compress/vendor/brotli/c/enc/command.c +28 -0
- data/ext/multi_compress/vendor/brotli/c/enc/command.h +191 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +207 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +74 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +800 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +86 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +657 -0
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +72 -0
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +1848 -0
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +25 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encode.c +1996 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +640 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +157 -0
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +504 -0
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +123 -0
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +542 -0
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +105 -0
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +67 -0
- data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +72 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash.h +728 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_composite_inc.h +140 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +295 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +262 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +258 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +266 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +330 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +100 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +64 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram_inc.h +51 -0
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +180 -0
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +32 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.c +194 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.h +131 -0
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +677 -0
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +106 -0
- data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +185 -0
- data/ext/multi_compress/vendor/brotli/c/enc/params.h +47 -0
- data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +54 -0
- data/ext/multi_compress/vendor/brotli/c/enc/quality.h +202 -0
- data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +168 -0
- data/ext/multi_compress/vendor/brotli/c/enc/state.h +104 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +542 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +41 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +5866 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +85 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +33 -0
- data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +88 -0
- data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +409 -0
- data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +501 -0
- data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +305 -0
- data/ext/multi_compress/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
- data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +83 -0
- data/ext/multi_compress/vendor/lz4/lib/LICENSE +24 -0
- data/ext/multi_compress/vendor/lz4/lib/Makefile +244 -0
- data/ext/multi_compress/vendor/lz4/lib/README.md +193 -0
- data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +63 -0
- data/ext/multi_compress/vendor/lz4/lib/dll/example/README.md +69 -0
- data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.sln +25 -0
- data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
- data/ext/multi_compress/vendor/lz4/lib/liblz4-dll.rc.in +35 -0
- data/ext/multi_compress/vendor/lz4/lib/liblz4.pc.in +14 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4.c +2829 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4.h +884 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4file.c +341 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4file.h +93 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4frame.c +2136 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4frame.h +751 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4frame_static.h +47 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4hc.c +2192 -0
- data/ext/multi_compress/vendor/lz4/lib/lz4hc.h +414 -0
- data/ext/multi_compress/vendor/lz4/lib/xxhash.c +1030 -0
- data/ext/multi_compress/vendor/lz4/lib/xxhash.h +328 -0
- data/ext/multi_compress/vendor/zstd/lib/BUCK +232 -0
- data/ext/multi_compress/vendor/zstd/lib/Makefile +369 -0
- data/ext/multi_compress/vendor/zstd/lib/README.md +237 -0
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +200 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +457 -0
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +450 -0
- data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +249 -0
- data/ext/multi_compress/vendor/zstd/lib/common/debug.c +30 -0
- data/ext/multi_compress/vendor/zstd/lib/common/debug.h +116 -0
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +340 -0
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +63 -0
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +168 -0
- data/ext/multi_compress/vendor/zstd/lib/common/fse.h +640 -0
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +313 -0
- data/ext/multi_compress/vendor/zstd/lib/common/huf.h +286 -0
- data/ext/multi_compress/vendor/zstd/lib/common/mem.h +426 -0
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +371 -0
- data/ext/multi_compress/vendor/zstd/lib/common/pool.h +90 -0
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +158 -0
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +182 -0
- data/ext/multi_compress/vendor/zstd/lib/common/threading.h +150 -0
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +18 -0
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +7020 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +48 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +111 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +392 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +163 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +134 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +625 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +181 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +75 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +1464 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +7153 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +1534 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +235 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +39 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +442 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +54 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +688 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +748 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +770 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +50 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +968 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +38 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +2199 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +202 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +730 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +117 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +1576 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +80 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +1882 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +113 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +1944 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +244 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +44 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +2407 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +2215 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +73 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +240 -0
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +214 -0
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +26 -0
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +167 -0
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +77 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +1261 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +152 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +1913 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +67 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +766 -0
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +1133 -0
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +48 -0
- data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +63 -0
- data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +20 -0
- data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.sln +25 -0
- data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +181 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +452 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +2127 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +94 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +3465 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +93 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +3105 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +93 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +3598 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +142 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +4005 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +162 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +4106 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +172 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +4490 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +187 -0
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +237 -0
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +16 -0
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +35 -0
- data/ext/multi_compress/vendor/zstd/lib/zdict.h +474 -0
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +3089 -0
- data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +114 -0
- data/lib/multi_compress/version.rb +5 -0
- data/lib/multi_compress.rb +329 -0
- metadata +322 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* Copyright 2013 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* Collection of static dictionary words. */
|
|
8
|
+
|
|
9
|
+
#ifndef BROTLI_COMMON_DICTIONARY_H_
|
|
10
|
+
#define BROTLI_COMMON_DICTIONARY_H_
|
|
11
|
+
|
|
12
|
+
#include <brotli/port.h>
|
|
13
|
+
#include <brotli/types.h>
|
|
14
|
+
|
|
15
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
typedef struct BrotliDictionary {
|
|
20
|
+
/**
|
|
21
|
+
* Number of bits to encode index of dictionary word in a bucket.
|
|
22
|
+
*
|
|
23
|
+
* Specification: Appendix A. Static Dictionary Data
|
|
24
|
+
*
|
|
25
|
+
* Words in a dictionary are bucketed by length.
|
|
26
|
+
* @c 0 means that there are no words of a given length.
|
|
27
|
+
* Dictionary consists of words with length of [4..24] bytes.
|
|
28
|
+
* Values at [0..3] and [25..31] indices should not be addressed.
|
|
29
|
+
*/
|
|
30
|
+
uint8_t size_bits_by_length[32];
|
|
31
|
+
|
|
32
|
+
/* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
|
|
33
|
+
uint32_t offsets_by_length[32];
|
|
34
|
+
|
|
35
|
+
/* assert(data_size == offsets_by_length[31]) */
|
|
36
|
+
size_t data_size;
|
|
37
|
+
|
|
38
|
+
/* Data array is not bound, and should obey to size_bits_by_length values.
|
|
39
|
+
Specified size matches default (RFC 7932) dictionary. Its size is
|
|
40
|
+
defined by data_size */
|
|
41
|
+
const uint8_t* data;
|
|
42
|
+
} BrotliDictionary;
|
|
43
|
+
|
|
44
|
+
BROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sets dictionary data.
|
|
48
|
+
*
|
|
49
|
+
* When dictionary data is already set / present, this method is no-op.
|
|
50
|
+
*
|
|
51
|
+
* Dictionary data MUST be provided before BrotliGetDictionary is invoked.
|
|
52
|
+
* This method is used ONLY in multi-client environment (e.g. C + Java),
|
|
53
|
+
* to reduce storage by sharing single dictionary between implementations.
|
|
54
|
+
*/
|
|
55
|
+
BROTLI_COMMON_API void BrotliSetDictionaryData(const uint8_t* data);
|
|
56
|
+
|
|
57
|
+
#define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
|
|
58
|
+
#define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
|
|
59
|
+
|
|
60
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
|
61
|
+
} /* extern "C" */
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
#endif /* BROTLI_COMMON_DICTIONARY_H_ */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* Copyright 2016 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
|
|
9
|
+
#include <brotli/types.h>
|
|
10
|
+
|
|
11
|
+
#include "platform.h"
|
|
12
|
+
|
|
13
|
+
/* Default brotli_alloc_func */
|
|
14
|
+
void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
|
|
15
|
+
BROTLI_UNUSED(opaque);
|
|
16
|
+
return malloc(size);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Default brotli_free_func */
|
|
20
|
+
void BrotliDefaultFreeFunc(void* opaque, void* address) {
|
|
21
|
+
BROTLI_UNUSED(opaque);
|
|
22
|
+
free(address);
|
|
23
|
+
}
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
/* Copyright 2016 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* Macros for compiler / platform specific features and build options.
|
|
8
|
+
|
|
9
|
+
Build options are:
|
|
10
|
+
* BROTLI_BUILD_32_BIT disables 64-bit optimizations
|
|
11
|
+
* BROTLI_BUILD_64_BIT forces to use 64-bit optimizations
|
|
12
|
+
* BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
|
|
13
|
+
* BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
|
|
14
|
+
* BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
|
|
15
|
+
* BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
|
|
16
|
+
* BROTLI_BUILD_NO_UNALIGNED_READ_FAST forces off the fast-unaligned-read
|
|
17
|
+
optimizations (mainly for testing purposes)
|
|
18
|
+
* BROTLI_DEBUG dumps file name and line number when decoder detects stream
|
|
19
|
+
or memory error
|
|
20
|
+
* BROTLI_ENABLE_LOG enables asserts and dumps various state information
|
|
21
|
+
* BROTLI_ENABLE_DUMP overrides default "dump" behaviour
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#ifndef BROTLI_COMMON_PLATFORM_H_
|
|
25
|
+
#define BROTLI_COMMON_PLATFORM_H_
|
|
26
|
+
|
|
27
|
+
#include <string.h> /* memcpy */
|
|
28
|
+
|
|
29
|
+
#include <brotli/port.h>
|
|
30
|
+
#include <brotli/types.h>
|
|
31
|
+
|
|
32
|
+
#if defined(OS_LINUX) || defined(OS_CYGWIN) || defined(__EMSCRIPTEN__)
|
|
33
|
+
#include <endian.h>
|
|
34
|
+
#elif defined(OS_FREEBSD)
|
|
35
|
+
#include <machine/endian.h>
|
|
36
|
+
#elif defined(OS_MACOSX)
|
|
37
|
+
#include <machine/endian.h>
|
|
38
|
+
/* Let's try and follow the Linux convention */
|
|
39
|
+
#define BROTLI_X_BYTE_ORDER BYTE_ORDER
|
|
40
|
+
#define BROTLI_X_LITTLE_ENDIAN LITTLE_ENDIAN
|
|
41
|
+
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
#if BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
|
45
|
+
#include <intrin.h>
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
|
|
49
|
+
#include <assert.h>
|
|
50
|
+
#include <stdio.h>
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
/* The following macros were borrowed from https://github.com/nemequ/hedley
|
|
54
|
+
* with permission of original author - Evan Nemerson <evan@nemerson.com> */
|
|
55
|
+
|
|
56
|
+
/* >>> >>> >>> hedley macros */
|
|
57
|
+
|
|
58
|
+
/* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
|
|
59
|
+
compilers.
|
|
60
|
+
|
|
61
|
+
To apply compiler hint, enclose the branching condition into macros, like this:
|
|
62
|
+
|
|
63
|
+
if (BROTLI_PREDICT_TRUE(zero == 0)) {
|
|
64
|
+
// main execution path
|
|
65
|
+
} else {
|
|
66
|
+
// compiler should place this code outside of main execution path
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
OR:
|
|
70
|
+
|
|
71
|
+
if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
|
|
72
|
+
// compiler should place this code outside of main execution path
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
*/
|
|
76
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_expect, 3, 0, 0) || \
|
|
77
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
78
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 15, 0) || \
|
|
79
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
80
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
81
|
+
BROTLI_TI_VERSION_CHECK(7, 3, 0) || \
|
|
82
|
+
BROTLI_TINYC_VERSION_CHECK(0, 9, 27)
|
|
83
|
+
#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
|
|
84
|
+
#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
|
|
85
|
+
#else
|
|
86
|
+
#define BROTLI_PREDICT_FALSE(x) (x)
|
|
87
|
+
#define BROTLI_PREDICT_TRUE(x) (x)
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
|
91
|
+
!defined(__cplusplus)
|
|
92
|
+
#define BROTLI_RESTRICT restrict
|
|
93
|
+
#elif BROTLI_GNUC_VERSION_CHECK(3, 1, 0) || \
|
|
94
|
+
BROTLI_MSVC_VERSION_CHECK(14, 0, 0) || \
|
|
95
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
96
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
97
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
98
|
+
BROTLI_PGI_VERSION_CHECK(17, 10, 0) || \
|
|
99
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
100
|
+
BROTLI_IAR_VERSION_CHECK(8, 0, 0) || \
|
|
101
|
+
(BROTLI_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus))
|
|
102
|
+
#define BROTLI_RESTRICT __restrict
|
|
103
|
+
#elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
|
|
104
|
+
#define BROTLI_RESTRICT _Restrict
|
|
105
|
+
#else
|
|
106
|
+
#define BROTLI_RESTRICT
|
|
107
|
+
#endif
|
|
108
|
+
|
|
109
|
+
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
|
110
|
+
(defined(__cplusplus) && (__cplusplus >= 199711L))
|
|
111
|
+
#define BROTLI_MAYBE_INLINE inline
|
|
112
|
+
#elif defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) || \
|
|
113
|
+
BROTLI_ARM_VERSION_CHECK(6, 2, 0)
|
|
114
|
+
#define BROTLI_MAYBE_INLINE __inline__
|
|
115
|
+
#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) || \
|
|
116
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || BROTLI_TI_VERSION_CHECK(8, 0, 0)
|
|
117
|
+
#define BROTLI_MAYBE_INLINE __inline
|
|
118
|
+
#else
|
|
119
|
+
#define BROTLI_MAYBE_INLINE
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(always_inline, 4, 0, 0) || \
|
|
123
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
124
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
|
125
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
126
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
127
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
128
|
+
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
|
|
129
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE __attribute__((__always_inline__))
|
|
130
|
+
#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
|
|
131
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE __forceinline
|
|
132
|
+
#elif BROTLI_TI_VERSION_CHECK(7, 0, 0) && defined(__cplusplus)
|
|
133
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
|
|
134
|
+
#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
|
|
135
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("inline=forced")
|
|
136
|
+
#else
|
|
137
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE
|
|
138
|
+
#endif
|
|
139
|
+
|
|
140
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(noinline, 4, 0, 0) || \
|
|
141
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
142
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
|
143
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
144
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
145
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
146
|
+
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
|
|
147
|
+
#define BROTLI_NOINLINE __attribute__((__noinline__))
|
|
148
|
+
#elif BROTLI_MSVC_VERSION_CHECK(13, 10, 0)
|
|
149
|
+
#define BROTLI_NOINLINE __declspec(noinline)
|
|
150
|
+
#elif BROTLI_PGI_VERSION_CHECK(10, 2, 0)
|
|
151
|
+
#define BROTLI_NOINLINE _Pragma("noinline")
|
|
152
|
+
#elif BROTLI_TI_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
|
|
153
|
+
#define BROTLI_NOINLINE _Pragma("FUNC_CANNOT_INLINE;")
|
|
154
|
+
#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
|
|
155
|
+
#define BROTLI_NOINLINE _Pragma("inline=never")
|
|
156
|
+
#else
|
|
157
|
+
#define BROTLI_NOINLINE
|
|
158
|
+
#endif
|
|
159
|
+
|
|
160
|
+
/* <<< <<< <<< end of hedley macros. */
|
|
161
|
+
|
|
162
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \
|
|
163
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
164
|
+
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused))
|
|
165
|
+
#else
|
|
166
|
+
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE
|
|
167
|
+
#endif
|
|
168
|
+
|
|
169
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0)
|
|
170
|
+
#define BROTLI_ALIGNED(N) __attribute__((aligned(N)))
|
|
171
|
+
#else
|
|
172
|
+
#define BROTLI_ALIGNED(N)
|
|
173
|
+
#endif
|
|
174
|
+
|
|
175
|
+
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
|
|
176
|
+
(defined(M_ARM) && (M_ARM == 7))
|
|
177
|
+
#define BROTLI_TARGET_ARMV7
|
|
178
|
+
#endif /* ARMv7 */
|
|
179
|
+
|
|
180
|
+
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \
|
|
181
|
+
defined(__aarch64__) || defined(__ARM64_ARCH_8__)
|
|
182
|
+
#define BROTLI_TARGET_ARMV8_ANY
|
|
183
|
+
|
|
184
|
+
#if defined(__ARM_32BIT_STATE)
|
|
185
|
+
#define BROTLI_TARGET_ARMV8_32
|
|
186
|
+
#elif defined(__ARM_64BIT_STATE)
|
|
187
|
+
#define BROTLI_TARGET_ARMV8_64
|
|
188
|
+
#endif
|
|
189
|
+
|
|
190
|
+
#endif /* ARMv8 */
|
|
191
|
+
|
|
192
|
+
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
|
|
193
|
+
#define BROTLI_TARGET_NEON
|
|
194
|
+
#endif
|
|
195
|
+
|
|
196
|
+
#if defined(__i386) || defined(_M_IX86)
|
|
197
|
+
#define BROTLI_TARGET_X86
|
|
198
|
+
#endif
|
|
199
|
+
|
|
200
|
+
#if defined(__x86_64__) || defined(_M_X64)
|
|
201
|
+
#define BROTLI_TARGET_X64
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
#if defined(__PPC64__)
|
|
205
|
+
#define BROTLI_TARGET_POWERPC64
|
|
206
|
+
#endif
|
|
207
|
+
|
|
208
|
+
#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
|
|
209
|
+
#define BROTLI_TARGET_RISCV64
|
|
210
|
+
#endif
|
|
211
|
+
|
|
212
|
+
#if defined(__loongarch_lp64)
|
|
213
|
+
#define BROTLI_TARGET_LOONGARCH64
|
|
214
|
+
#endif
|
|
215
|
+
|
|
216
|
+
#if defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \
|
|
217
|
+
defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64) || \
|
|
218
|
+
defined(BROTLI_TARGET_LOONGARCH64)
|
|
219
|
+
#define BROTLI_TARGET_64_BITS 1
|
|
220
|
+
#else
|
|
221
|
+
#define BROTLI_TARGET_64_BITS 0
|
|
222
|
+
#endif
|
|
223
|
+
|
|
224
|
+
#if defined(BROTLI_BUILD_64_BIT)
|
|
225
|
+
#define BROTLI_64_BITS 1
|
|
226
|
+
#elif defined(BROTLI_BUILD_32_BIT)
|
|
227
|
+
#define BROTLI_64_BITS 0
|
|
228
|
+
#else
|
|
229
|
+
#define BROTLI_64_BITS BROTLI_TARGET_64_BITS
|
|
230
|
+
#endif
|
|
231
|
+
|
|
232
|
+
#if (BROTLI_64_BITS)
|
|
233
|
+
#define brotli_reg_t uint64_t
|
|
234
|
+
#else
|
|
235
|
+
#define brotli_reg_t uint32_t
|
|
236
|
+
#endif
|
|
237
|
+
|
|
238
|
+
#if defined(BROTLI_BUILD_BIG_ENDIAN)
|
|
239
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
240
|
+
#elif defined(BROTLI_BUILD_LITTLE_ENDIAN)
|
|
241
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
242
|
+
#elif defined(BROTLI_BUILD_ENDIAN_NEUTRAL)
|
|
243
|
+
/* Just break elif chain. */
|
|
244
|
+
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
|
245
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
246
|
+
#elif defined(_WIN32) || defined(BROTLI_TARGET_X64)
|
|
247
|
+
/* Win32 & x64 can currently always be assumed to be little endian */
|
|
248
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
249
|
+
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
|
250
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
251
|
+
#elif defined(BROTLI_X_BYTE_ORDER)
|
|
252
|
+
#if BROTLI_X_BYTE_ORDER == BROTLI_X_LITTLE_ENDIAN
|
|
253
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
254
|
+
#elif BROTLI_X_BYTE_ORDER == BROTLI_X_BIG_ENDIAN
|
|
255
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
256
|
+
#endif
|
|
257
|
+
#endif /* BROTLI_X_BYTE_ORDER */
|
|
258
|
+
|
|
259
|
+
#if !defined(BROTLI_LITTLE_ENDIAN)
|
|
260
|
+
#define BROTLI_LITTLE_ENDIAN 0
|
|
261
|
+
#endif
|
|
262
|
+
|
|
263
|
+
#if !defined(BROTLI_BIG_ENDIAN)
|
|
264
|
+
#define BROTLI_BIG_ENDIAN 0
|
|
265
|
+
#endif
|
|
266
|
+
|
|
267
|
+
#if defined(BROTLI_X_BYTE_ORDER)
|
|
268
|
+
#undef BROTLI_X_BYTE_ORDER
|
|
269
|
+
#undef BROTLI_X_LITTLE_ENDIAN
|
|
270
|
+
#undef BROTLI_X_BIG_ENDIAN
|
|
271
|
+
#endif
|
|
272
|
+
|
|
273
|
+
#if defined(BROTLI_BUILD_NO_UNALIGNED_READ_FAST)
|
|
274
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!0)
|
|
275
|
+
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
|
|
276
|
+
defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) || \
|
|
277
|
+
defined(BROTLI_TARGET_RISCV64) || defined(BROTLI_TARGET_LOONGARCH64)
|
|
278
|
+
/* These targets are known to generate efficient code for unaligned reads
|
|
279
|
+
* (e.g. a single instruction, not multiple 1-byte loads, shifted and or'd
|
|
280
|
+
* together). */
|
|
281
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!1)
|
|
282
|
+
#else
|
|
283
|
+
#define BROTLI_UNALIGNED_READ_FAST (!!0)
|
|
284
|
+
#endif
|
|
285
|
+
|
|
286
|
+
/* Portable unaligned memory access: read / write values via memcpy. */
|
|
287
|
+
static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
|
|
288
|
+
uint16_t t;
|
|
289
|
+
memcpy(&t, p, sizeof t);
|
|
290
|
+
return t;
|
|
291
|
+
}
|
|
292
|
+
static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
|
|
293
|
+
uint32_t t;
|
|
294
|
+
memcpy(&t, p, sizeof t);
|
|
295
|
+
return t;
|
|
296
|
+
}
|
|
297
|
+
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
|
298
|
+
uint64_t t;
|
|
299
|
+
memcpy(&t, p, sizeof t);
|
|
300
|
+
return t;
|
|
301
|
+
}
|
|
302
|
+
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
|
303
|
+
memcpy(p, &v, sizeof v);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
#if BROTLI_LITTLE_ENDIAN
|
|
307
|
+
/* Straight endianness. Just read / write values. */
|
|
308
|
+
#define BROTLI_UNALIGNED_LOAD16LE BrotliUnalignedRead16
|
|
309
|
+
#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
|
|
310
|
+
#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
|
|
311
|
+
#define BROTLI_UNALIGNED_STORE64LE BrotliUnalignedWrite64
|
|
312
|
+
#elif BROTLI_BIG_ENDIAN /* BROTLI_LITTLE_ENDIAN */
|
|
313
|
+
/* Explain compiler to byte-swap values. */
|
|
314
|
+
#define BROTLI_BSWAP16_(V) ((uint16_t)( \
|
|
315
|
+
(((V) & 0xFFU) << 8) | \
|
|
316
|
+
(((V) >> 8) & 0xFFU)))
|
|
317
|
+
static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
|
|
318
|
+
uint16_t value = BrotliUnalignedRead16(p);
|
|
319
|
+
return BROTLI_BSWAP16_(value);
|
|
320
|
+
}
|
|
321
|
+
#define BROTLI_BSWAP32_(V) ( \
|
|
322
|
+
(((V) & 0xFFU) << 24) | (((V) & 0xFF00U) << 8) | \
|
|
323
|
+
(((V) >> 8) & 0xFF00U) | (((V) >> 24) & 0xFFU))
|
|
324
|
+
static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
|
|
325
|
+
uint32_t value = BrotliUnalignedRead32(p);
|
|
326
|
+
return BROTLI_BSWAP32_(value);
|
|
327
|
+
}
|
|
328
|
+
#define BROTLI_BSWAP64_(V) ( \
|
|
329
|
+
(((V) & 0xFFU) << 56) | (((V) & 0xFF00U) << 40) | \
|
|
330
|
+
(((V) & 0xFF0000U) << 24) | (((V) & 0xFF000000U) << 8) | \
|
|
331
|
+
(((V) >> 8) & 0xFF000000U) | (((V) >> 24) & 0xFF0000U) | \
|
|
332
|
+
(((V) >> 40) & 0xFF00U) | (((V) >> 56) & 0xFFU))
|
|
333
|
+
static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
|
|
334
|
+
uint64_t value = BrotliUnalignedRead64(p);
|
|
335
|
+
return BROTLI_BSWAP64_(value);
|
|
336
|
+
}
|
|
337
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
338
|
+
uint64_t value = BROTLI_BSWAP64_(v);
|
|
339
|
+
BrotliUnalignedWrite64(p, value);
|
|
340
|
+
}
|
|
341
|
+
#else /* BROTLI_LITTLE_ENDIAN */
|
|
342
|
+
/* Read / store values byte-wise; hopefully compiler will understand. */
|
|
343
|
+
static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
|
|
344
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
345
|
+
return (uint16_t)(in[0] | (in[1] << 8));
|
|
346
|
+
}
|
|
347
|
+
static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
|
|
348
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
349
|
+
uint32_t value = (uint32_t)(in[0]);
|
|
350
|
+
value |= (uint32_t)(in[1]) << 8;
|
|
351
|
+
value |= (uint32_t)(in[2]) << 16;
|
|
352
|
+
value |= (uint32_t)(in[3]) << 24;
|
|
353
|
+
return value;
|
|
354
|
+
}
|
|
355
|
+
static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
|
|
356
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
357
|
+
uint64_t value = (uint64_t)(in[0]);
|
|
358
|
+
value |= (uint64_t)(in[1]) << 8;
|
|
359
|
+
value |= (uint64_t)(in[2]) << 16;
|
|
360
|
+
value |= (uint64_t)(in[3]) << 24;
|
|
361
|
+
value |= (uint64_t)(in[4]) << 32;
|
|
362
|
+
value |= (uint64_t)(in[5]) << 40;
|
|
363
|
+
value |= (uint64_t)(in[6]) << 48;
|
|
364
|
+
value |= (uint64_t)(in[7]) << 56;
|
|
365
|
+
return value;
|
|
366
|
+
}
|
|
367
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
368
|
+
uint8_t* out = (uint8_t*)p;
|
|
369
|
+
out[0] = (uint8_t)v;
|
|
370
|
+
out[1] = (uint8_t)(v >> 8);
|
|
371
|
+
out[2] = (uint8_t)(v >> 16);
|
|
372
|
+
out[3] = (uint8_t)(v >> 24);
|
|
373
|
+
out[4] = (uint8_t)(v >> 32);
|
|
374
|
+
out[5] = (uint8_t)(v >> 40);
|
|
375
|
+
out[6] = (uint8_t)(v >> 48);
|
|
376
|
+
out[7] = (uint8_t)(v >> 56);
|
|
377
|
+
}
|
|
378
|
+
#endif /* BROTLI_LITTLE_ENDIAN */
|
|
379
|
+
|
|
380
|
+
static BROTLI_INLINE void* BROTLI_UNALIGNED_LOAD_PTR(const void* p) {
|
|
381
|
+
void* v;
|
|
382
|
+
memcpy(&v, p, sizeof(void*));
|
|
383
|
+
return v;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE_PTR(void* p, const void* v) {
|
|
387
|
+
memcpy(p, &v, sizeof(void*));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */
|
|
391
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \
|
|
392
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
393
|
+
#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
|
|
394
|
+
#else
|
|
395
|
+
#define BROTLI_IS_CONSTANT(x) (!!0)
|
|
396
|
+
#endif
|
|
397
|
+
|
|
398
|
+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
|
|
399
|
+
#define BROTLI_HAS_UBFX (!!1)
|
|
400
|
+
#else
|
|
401
|
+
#define BROTLI_HAS_UBFX (!!0)
|
|
402
|
+
#endif
|
|
403
|
+
|
|
404
|
+
#if defined(BROTLI_ENABLE_LOG)
|
|
405
|
+
#define BROTLI_LOG(x) printf x
|
|
406
|
+
#else
|
|
407
|
+
#define BROTLI_LOG(x)
|
|
408
|
+
#endif
|
|
409
|
+
|
|
410
|
+
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
|
|
411
|
+
#define BROTLI_ENABLE_DUMP_DEFAULT 1
|
|
412
|
+
#define BROTLI_DCHECK(x) assert(x)
|
|
413
|
+
#else
|
|
414
|
+
#define BROTLI_ENABLE_DUMP_DEFAULT 0
|
|
415
|
+
#define BROTLI_DCHECK(x)
|
|
416
|
+
#endif
|
|
417
|
+
|
|
418
|
+
#if !defined(BROTLI_ENABLE_DUMP)
|
|
419
|
+
#define BROTLI_ENABLE_DUMP BROTLI_ENABLE_DUMP_DEFAULT
|
|
420
|
+
#endif
|
|
421
|
+
|
|
422
|
+
#if BROTLI_ENABLE_DUMP
|
|
423
|
+
static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
|
|
424
|
+
fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
|
|
425
|
+
fflush(stderr);
|
|
426
|
+
}
|
|
427
|
+
#define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__)
|
|
428
|
+
#else
|
|
429
|
+
#define BROTLI_DUMP() (void)(0)
|
|
430
|
+
#endif
|
|
431
|
+
|
|
432
|
+
/* BrotliRBit assumes brotli_reg_t fits native CPU register type. */
|
|
433
|
+
#if (BROTLI_64_BITS == BROTLI_TARGET_64_BITS)
|
|
434
|
+
/* TODO(eustas): add appropriate icc/sunpro/arm/ibm/ti checks. */
|
|
435
|
+
#if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
|
|
436
|
+
!defined(BROTLI_BUILD_NO_RBIT)
|
|
437
|
+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
|
|
438
|
+
/* TODO(eustas): detect ARMv6T2 and enable this code for it. */
|
|
439
|
+
static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
|
|
440
|
+
brotli_reg_t output;
|
|
441
|
+
__asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
|
|
442
|
+
return output;
|
|
443
|
+
}
|
|
444
|
+
#define BROTLI_RBIT(x) BrotliRBit(x)
|
|
445
|
+
#endif /* armv7 / armv8 */
|
|
446
|
+
#endif /* gcc || clang */
|
|
447
|
+
#endif /* brotli_reg_t is native */
|
|
448
|
+
#if !defined(BROTLI_RBIT)
|
|
449
|
+
static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }
|
|
450
|
+
#endif /* BROTLI_RBIT */
|
|
451
|
+
|
|
452
|
+
#define BROTLI_REPEAT_4(X) {X; X; X; X;}
|
|
453
|
+
#define BROTLI_REPEAT_5(X) {X; X; X; X; X;}
|
|
454
|
+
#define BROTLI_REPEAT_6(X) {X; X; X; X; X; X;}
|
|
455
|
+
|
|
456
|
+
#define BROTLI_UNUSED(X) (void)(X)
|
|
457
|
+
|
|
458
|
+
#define BROTLI_MIN_MAX(T) \
|
|
459
|
+
static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \
|
|
460
|
+
static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; }
|
|
461
|
+
BROTLI_MIN_MAX(double) BROTLI_MIN_MAX(float) BROTLI_MIN_MAX(int)
|
|
462
|
+
BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
|
|
463
|
+
#undef BROTLI_MIN_MAX
|
|
464
|
+
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
|
|
465
|
+
#define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B)))
|
|
466
|
+
|
|
467
|
+
#define BROTLI_SWAP(T, A, I, J) { \
|
|
468
|
+
T __brotli_swap_tmp = (A)[(I)]; \
|
|
469
|
+
(A)[(I)] = (A)[(J)]; \
|
|
470
|
+
(A)[(J)] = __brotli_swap_tmp; \
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
#if BROTLI_64_BITS
|
|
474
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \
|
|
475
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
476
|
+
#define BROTLI_TZCNT64 __builtin_ctzll
|
|
477
|
+
#elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
|
478
|
+
#if defined(BROTLI_TARGET_X64)
|
|
479
|
+
#define BROTLI_TZCNT64 _tzcnt_u64
|
|
480
|
+
#else /* BROTLI_TARGET_X64 */
|
|
481
|
+
static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) {
|
|
482
|
+
uint32_t lsb;
|
|
483
|
+
_BitScanForward64(&lsb, x);
|
|
484
|
+
return lsb;
|
|
485
|
+
}
|
|
486
|
+
#define BROTLI_TZCNT64 BrotliBsf64Msvc
|
|
487
|
+
#endif /* BROTLI_TARGET_X64 */
|
|
488
|
+
#endif /* __builtin_ctzll */
|
|
489
|
+
#endif /* BROTLI_64_BITS */
|
|
490
|
+
|
|
491
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
|
|
492
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
493
|
+
#define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x))
|
|
494
|
+
#elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0)
|
|
495
|
+
static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) {
|
|
496
|
+
unsigned long msb;
|
|
497
|
+
_BitScanReverse(&msb, x);
|
|
498
|
+
return (uint32_t)msb;
|
|
499
|
+
}
|
|
500
|
+
#define BROTLI_BSR32 BrotliBsr32Msvc
|
|
501
|
+
#endif /* __builtin_clz */
|
|
502
|
+
|
|
503
|
+
/* Default brotli_alloc_func */
|
|
504
|
+
BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size);
|
|
505
|
+
|
|
506
|
+
/* Default brotli_free_func */
|
|
507
|
+
BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address);
|
|
508
|
+
|
|
509
|
+
BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
|
|
510
|
+
BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
|
|
511
|
+
BROTLI_UNUSED(&BrotliUnalignedRead16);
|
|
512
|
+
BROTLI_UNUSED(&BrotliUnalignedRead32);
|
|
513
|
+
BROTLI_UNUSED(&BrotliUnalignedRead64);
|
|
514
|
+
BROTLI_UNUSED(&BrotliUnalignedWrite64);
|
|
515
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
|
|
516
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
|
|
517
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
|
|
518
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
|
|
519
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD_PTR);
|
|
520
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE_PTR);
|
|
521
|
+
BROTLI_UNUSED(&BrotliRBit);
|
|
522
|
+
BROTLI_UNUSED(&brotli_min_double);
|
|
523
|
+
BROTLI_UNUSED(&brotli_max_double);
|
|
524
|
+
BROTLI_UNUSED(&brotli_min_float);
|
|
525
|
+
BROTLI_UNUSED(&brotli_max_float);
|
|
526
|
+
BROTLI_UNUSED(&brotli_min_int);
|
|
527
|
+
BROTLI_UNUSED(&brotli_max_int);
|
|
528
|
+
BROTLI_UNUSED(&brotli_min_size_t);
|
|
529
|
+
BROTLI_UNUSED(&brotli_max_size_t);
|
|
530
|
+
BROTLI_UNUSED(&brotli_min_uint32_t);
|
|
531
|
+
BROTLI_UNUSED(&brotli_max_uint32_t);
|
|
532
|
+
BROTLI_UNUSED(&brotli_min_uint8_t);
|
|
533
|
+
BROTLI_UNUSED(&brotli_max_uint8_t);
|
|
534
|
+
BROTLI_UNUSED(&BrotliDefaultAllocFunc);
|
|
535
|
+
BROTLI_UNUSED(&BrotliDefaultFreeFunc);
|
|
536
|
+
#if BROTLI_ENABLE_DUMP
|
|
537
|
+
BROTLI_UNUSED(&BrotliDump);
|
|
538
|
+
#endif
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
#endif /* BROTLI_COMMON_PLATFORM_H_ */
|