brotli 0.2.3 → 0.5.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 +4 -4
- data/.github/workflows/main.yml +37 -0
- data/.github/workflows/publish.yml +24 -0
- data/.gitmodules +1 -1
- data/Gemfile +6 -3
- data/README.md +2 -2
- data/Rakefile +16 -9
- data/brotli.gemspec +7 -13
- data/ext/brotli/brotli.c +210 -31
- data/ext/brotli/buffer.c +1 -7
- data/ext/brotli/buffer.h +1 -1
- data/ext/brotli/extconf.rb +25 -17
- data/lib/brotli/version.rb +1 -1
- data/test/brotli_test.rb +107 -0
- data/test/brotli_writer_test.rb +36 -0
- data/test/test_helper.rb +8 -0
- data/vendor/brotli/c/common/constants.c +15 -0
- data/vendor/brotli/c/common/constants.h +137 -0
- data/vendor/brotli/c/common/context.c +156 -0
- data/vendor/brotli/c/common/context.h +4 -152
- data/vendor/brotli/c/common/dictionary.bin.br +0 -0
- data/vendor/brotli/c/common/dictionary.c +14 -3
- data/vendor/brotli/c/common/platform.c +23 -0
- data/vendor/brotli/c/common/platform.h +95 -122
- data/vendor/brotli/c/common/shared_dictionary.c +521 -0
- data/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
- data/vendor/brotli/c/common/transform.c +60 -4
- data/vendor/brotli/c/common/transform.h +5 -0
- data/vendor/brotli/c/common/version.h +31 -6
- data/vendor/brotli/c/dec/bit_reader.c +34 -4
- data/vendor/brotli/c/dec/bit_reader.h +221 -107
- data/vendor/brotli/c/dec/decode.c +772 -403
- data/vendor/brotli/c/dec/huffman.c +7 -4
- data/vendor/brotli/c/dec/huffman.h +8 -13
- data/vendor/brotli/c/dec/prefix.h +1 -18
- data/vendor/brotli/c/dec/state.c +40 -21
- data/vendor/brotli/c/dec/state.h +201 -59
- data/vendor/brotli/c/enc/backward_references.c +88 -25
- data/vendor/brotli/c/enc/backward_references.h +10 -8
- data/vendor/brotli/c/enc/backward_references_hq.c +194 -80
- data/vendor/brotli/c/enc/backward_references_hq.h +17 -13
- data/vendor/brotli/c/enc/backward_references_inc.h +52 -16
- data/vendor/brotli/c/enc/bit_cost.c +8 -7
- data/vendor/brotli/c/enc/bit_cost.h +5 -4
- data/vendor/brotli/c/enc/block_splitter.c +40 -17
- data/vendor/brotli/c/enc/block_splitter.h +5 -4
- data/vendor/brotli/c/enc/block_splitter_inc.h +99 -49
- data/vendor/brotli/c/enc/brotli_bit_stream.c +142 -137
- data/vendor/brotli/c/enc/brotli_bit_stream.h +11 -6
- data/vendor/brotli/c/enc/cluster.c +10 -9
- data/vendor/brotli/c/enc/cluster.h +7 -6
- data/vendor/brotli/c/enc/cluster_inc.h +30 -22
- data/vendor/brotli/c/enc/command.c +28 -0
- data/vendor/brotli/c/enc/command.h +17 -16
- data/vendor/brotli/c/enc/compound_dictionary.c +207 -0
- data/vendor/brotli/c/enc/compound_dictionary.h +74 -0
- data/vendor/brotli/c/enc/compress_fragment.c +93 -83
- data/vendor/brotli/c/enc/compress_fragment.h +32 -7
- data/vendor/brotli/c/enc/compress_fragment_two_pass.c +100 -88
- data/vendor/brotli/c/enc/compress_fragment_two_pass.h +21 -3
- data/vendor/brotli/c/enc/dictionary_hash.c +1829 -1101
- data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
- data/vendor/brotli/c/enc/encode.c +550 -416
- data/vendor/brotli/c/enc/encoder_dict.c +613 -5
- data/vendor/brotli/c/enc/encoder_dict.h +120 -4
- data/vendor/brotli/c/enc/entropy_encode.c +5 -2
- data/vendor/brotli/c/enc/entropy_encode.h +4 -3
- data/vendor/brotli/c/enc/entropy_encode_static.h +5 -2
- data/vendor/brotli/c/enc/fast_log.c +105 -0
- data/vendor/brotli/c/enc/fast_log.h +21 -101
- data/vendor/brotli/c/enc/find_match_length.h +17 -25
- data/vendor/brotli/c/enc/hash.h +350 -120
- data/vendor/brotli/c/enc/hash_composite_inc.h +71 -67
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +92 -51
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +79 -84
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +53 -54
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +93 -62
- data/vendor/brotli/c/enc/hash_rolling_inc.h +25 -29
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +42 -40
- data/vendor/brotli/c/enc/histogram.c +4 -4
- data/vendor/brotli/c/enc/histogram.h +7 -6
- data/vendor/brotli/c/enc/literal_cost.c +20 -15
- data/vendor/brotli/c/enc/literal_cost.h +4 -2
- data/vendor/brotli/c/enc/memory.c +29 -5
- data/vendor/brotli/c/enc/memory.h +43 -14
- data/vendor/brotli/c/enc/metablock.c +95 -85
- data/vendor/brotli/c/enc/metablock.h +9 -8
- data/vendor/brotli/c/enc/metablock_inc.h +9 -7
- data/vendor/brotli/c/enc/params.h +7 -4
- data/vendor/brotli/c/enc/prefix.h +3 -2
- data/vendor/brotli/c/enc/quality.h +40 -3
- data/vendor/brotli/c/enc/ringbuffer.h +8 -4
- data/vendor/brotli/c/enc/state.h +104 -0
- data/vendor/brotli/c/enc/static_dict.c +60 -4
- data/vendor/brotli/c/enc/static_dict.h +3 -2
- data/vendor/brotli/c/enc/static_dict_lut.h +2 -0
- data/vendor/brotli/c/enc/utf8_util.c +2 -2
- data/vendor/brotli/c/enc/utf8_util.h +2 -1
- data/vendor/brotli/c/enc/write_bits.h +29 -26
- data/vendor/brotli/c/include/brotli/decode.h +67 -2
- data/vendor/brotli/c/include/brotli/encode.h +77 -3
- data/vendor/brotli/c/include/brotli/port.h +34 -3
- data/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
- metadata +23 -97
- data/.travis.yml +0 -31
- data/docs/Brotli/Error.html +0 -124
- data/docs/Brotli.html +0 -485
- data/docs/_index.html +0 -122
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -127
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -127
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -67
- data/docs/top-level-namespace.html +0 -110
- data/spec/brotli_spec.rb +0 -88
- data/spec/inflate_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -4
@@ -7,32 +7,148 @@
|
|
7
7
|
#ifndef BROTLI_ENC_ENCODER_DICT_H_
|
8
8
|
#define BROTLI_ENC_ENCODER_DICT_H_
|
9
9
|
|
10
|
+
#include <brotli/shared_dictionary.h>
|
11
|
+
#include <brotli/types.h>
|
12
|
+
|
10
13
|
#include "../common/dictionary.h"
|
11
14
|
#include "../common/platform.h"
|
12
|
-
#include
|
13
|
-
#include "
|
15
|
+
#include "compound_dictionary.h"
|
16
|
+
#include "memory.h"
|
17
|
+
#include "static_dict_lut.h"
|
14
18
|
|
15
19
|
#if defined(__cplusplus) || defined(c_plusplus)
|
16
20
|
extern "C" {
|
17
21
|
#endif
|
18
22
|
|
23
|
+
/*
|
24
|
+
Dictionary hierarchy for Encoder:
|
25
|
+
-SharedEncoderDictionary
|
26
|
+
--CompoundDictionary
|
27
|
+
---PreparedDictionary [up to 15x]
|
28
|
+
= prefix dictionary with precomputed hashes
|
29
|
+
--ContextualEncoderDictionary
|
30
|
+
---BrotliEncoderDictionary [up to 64x]
|
31
|
+
= for each context, precomputed static dictionary with words + transforms
|
32
|
+
|
33
|
+
Dictionary hiearchy from common: similar, but without precomputed hashes
|
34
|
+
-BrotliSharedDictionary
|
35
|
+
--BrotliDictionary [up to 64x]
|
36
|
+
--BrotliTransforms [up to 64x]
|
37
|
+
--const uint8_t* prefix [up to 15x]: compound dictionaries
|
38
|
+
*/
|
39
|
+
|
40
|
+
typedef struct BrotliTrieNode {
|
41
|
+
uint8_t single; /* if 1, sub is a single node for c instead of 256 */
|
42
|
+
uint8_t c;
|
43
|
+
uint8_t len_; /* untransformed length */
|
44
|
+
uint32_t idx_; /* word index + num words * transform index */
|
45
|
+
uint32_t sub; /* index of sub node(s) in the pool */
|
46
|
+
} BrotliTrieNode;
|
47
|
+
|
48
|
+
typedef struct BrotliTrie {
|
49
|
+
BrotliTrieNode* pool;
|
50
|
+
size_t pool_capacity;
|
51
|
+
size_t pool_size;
|
52
|
+
BrotliTrieNode root;
|
53
|
+
} BrotliTrie;
|
54
|
+
|
55
|
+
#if defined(BROTLI_EXPERIMENTAL)
|
56
|
+
BROTLI_INTERNAL const BrotliTrieNode* BrotliTrieSub(const BrotliTrie* trie,
|
57
|
+
const BrotliTrieNode* node, uint8_t c);
|
58
|
+
#endif /* BROTLI_EXPERIMENTAL */
|
59
|
+
|
19
60
|
/* Dictionary data (words and transforms) for 1 possible context */
|
20
61
|
typedef struct BrotliEncoderDictionary {
|
21
62
|
const BrotliDictionary* words;
|
63
|
+
uint32_t num_transforms;
|
22
64
|
|
23
65
|
/* cut off for fast encoder */
|
24
66
|
uint32_t cutoffTransformsCount;
|
25
67
|
uint64_t cutoffTransforms;
|
26
68
|
|
27
69
|
/* from dictionary_hash.h, for fast encoder */
|
28
|
-
const uint16_t*
|
70
|
+
const uint16_t* hash_table_words;
|
71
|
+
const uint8_t* hash_table_lengths;
|
29
72
|
|
30
73
|
/* from static_dict_lut.h, for slow encoder */
|
31
74
|
const uint16_t* buckets;
|
32
75
|
const DictWord* dict_words;
|
76
|
+
/* Heavy version, for use by slow encoder when there are custom transforms.
|
77
|
+
Contains every possible transformed dictionary word in a trie. It encodes
|
78
|
+
about as fast as the non-heavy encoder but consumes a lot of memory and
|
79
|
+
takes time to build. */
|
80
|
+
BrotliTrie trie;
|
81
|
+
BROTLI_BOOL has_words_heavy;
|
82
|
+
|
83
|
+
/* Reference to other dictionaries. */
|
84
|
+
const struct ContextualEncoderDictionary* parent;
|
85
|
+
|
86
|
+
/* Allocated memory, used only when not using the Brotli defaults */
|
87
|
+
uint16_t* hash_table_data_words_;
|
88
|
+
uint8_t* hash_table_data_lengths_;
|
89
|
+
size_t buckets_alloc_size_;
|
90
|
+
uint16_t* buckets_data_;
|
91
|
+
size_t dict_words_alloc_size_;
|
92
|
+
DictWord* dict_words_data_;
|
93
|
+
BrotliDictionary* words_instance_;
|
33
94
|
} BrotliEncoderDictionary;
|
34
95
|
|
35
|
-
|
96
|
+
/* Dictionary data for all 64 contexts */
|
97
|
+
typedef struct ContextualEncoderDictionary {
|
98
|
+
BROTLI_BOOL context_based;
|
99
|
+
uint8_t num_dictionaries;
|
100
|
+
uint8_t context_map[SHARED_BROTLI_NUM_DICTIONARY_CONTEXTS];
|
101
|
+
const BrotliEncoderDictionary* dict[SHARED_BROTLI_NUM_DICTIONARY_CONTEXTS];
|
102
|
+
|
103
|
+
/* If num_instances_ is 1, instance_ is used, else dynamic allocation with
|
104
|
+
instances_ is used. */
|
105
|
+
size_t num_instances_;
|
106
|
+
BrotliEncoderDictionary instance_;
|
107
|
+
BrotliEncoderDictionary* instances_;
|
108
|
+
} ContextualEncoderDictionary;
|
109
|
+
|
110
|
+
typedef struct SharedEncoderDictionary {
|
111
|
+
/* Magic value to distinguish this struct from PreparedDictionary for
|
112
|
+
certain external usages. */
|
113
|
+
uint32_t magic;
|
114
|
+
|
115
|
+
/* LZ77 prefix, compound dictionary */
|
116
|
+
CompoundDictionary compound;
|
117
|
+
|
118
|
+
/* Custom static dictionary (optionally context-based) */
|
119
|
+
ContextualEncoderDictionary contextual;
|
120
|
+
|
121
|
+
/* The maximum quality the dictionary was computed for */
|
122
|
+
int max_quality;
|
123
|
+
} SharedEncoderDictionary;
|
124
|
+
|
125
|
+
typedef struct ManagedDictionary {
|
126
|
+
uint32_t magic;
|
127
|
+
MemoryManager memory_manager_;
|
128
|
+
uint32_t* dictionary;
|
129
|
+
} ManagedDictionary;
|
130
|
+
|
131
|
+
/* Initializes to the brotli built-in dictionary */
|
132
|
+
BROTLI_INTERNAL void BrotliInitSharedEncoderDictionary(
|
133
|
+
SharedEncoderDictionary* dict);
|
134
|
+
|
135
|
+
#if defined(BROTLI_EXPERIMENTAL)
|
136
|
+
/* Initializes to shared dictionary that will be parsed from
|
137
|
+
encoded_dict. Requires that you keep the encoded_dict buffer
|
138
|
+
around, parts of data will point to it. */
|
139
|
+
BROTLI_INTERNAL BROTLI_BOOL BrotliInitCustomSharedEncoderDictionary(
|
140
|
+
MemoryManager* m, const uint8_t* encoded_dict, size_t size,
|
141
|
+
int quality, SharedEncoderDictionary* dict);
|
142
|
+
#endif /* BROTLI_EXPERIMENTAL */
|
143
|
+
|
144
|
+
BROTLI_INTERNAL void BrotliCleanupSharedEncoderDictionary(
|
145
|
+
MemoryManager* m, SharedEncoderDictionary* dict);
|
146
|
+
|
147
|
+
BROTLI_INTERNAL ManagedDictionary* BrotliCreateManagedDictionary(
|
148
|
+
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
|
149
|
+
|
150
|
+
BROTLI_INTERNAL void BrotliDestroyManagedDictionary(
|
151
|
+
ManagedDictionary* dictionary);
|
36
152
|
|
37
153
|
#if defined(__cplusplus) || defined(c_plusplus)
|
38
154
|
} /* extern "C" */
|
@@ -6,18 +6,21 @@
|
|
6
6
|
|
7
7
|
/* Entropy encoding (Huffman) utilities. */
|
8
8
|
|
9
|
-
#include "
|
9
|
+
#include "entropy_encode.h"
|
10
10
|
|
11
11
|
#include <string.h> /* memset */
|
12
12
|
|
13
|
+
#include <brotli/types.h>
|
14
|
+
|
13
15
|
#include "../common/constants.h"
|
14
16
|
#include "../common/platform.h"
|
15
|
-
#include <brotli/types.h>
|
16
17
|
|
17
18
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
19
|
extern "C" {
|
19
20
|
#endif
|
20
21
|
|
22
|
+
const size_t kBrotliShellGaps[] = {132, 57, 23, 10, 4, 1};
|
23
|
+
|
21
24
|
BROTLI_BOOL BrotliSetDepth(
|
22
25
|
int p0, HuffmanTree* pool, uint8_t* depth, int max_depth) {
|
23
26
|
int stack[16];
|
@@ -9,9 +9,10 @@
|
|
9
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_H_
|
11
11
|
|
12
|
-
#include "../common/platform.h"
|
13
12
|
#include <brotli/types.h>
|
14
13
|
|
14
|
+
#include "../common/platform.h"
|
15
|
+
|
15
16
|
#if defined(__cplusplus) || defined(c_plusplus)
|
16
17
|
extern "C" {
|
17
18
|
#endif
|
@@ -76,12 +77,12 @@ BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
|
|
76
77
|
size_t len,
|
77
78
|
uint16_t* bits);
|
78
79
|
|
80
|
+
BROTLI_INTERNAL extern const size_t kBrotliShellGaps[6];
|
79
81
|
/* Input size optimized Shell sort. */
|
80
82
|
typedef BROTLI_BOOL (*HuffmanTreeComparator)(
|
81
83
|
const HuffmanTree*, const HuffmanTree*);
|
82
84
|
static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
83
85
|
const size_t n, HuffmanTreeComparator comparator) {
|
84
|
-
static const size_t gaps[] = {132, 57, 23, 10, 4, 1};
|
85
86
|
if (n < 13) {
|
86
87
|
/* Insertion sort. */
|
87
88
|
size_t i;
|
@@ -101,7 +102,7 @@ static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
|
101
102
|
/* Shell sort. */
|
102
103
|
int g = n < 57 ? 2 : 0;
|
103
104
|
for (; g < 6; ++g) {
|
104
|
-
size_t gap =
|
105
|
+
size_t gap = kBrotliShellGaps[g];
|
105
106
|
size_t i;
|
106
107
|
for (i = gap; i < n; ++i) {
|
107
108
|
size_t j = i;
|
@@ -9,10 +9,11 @@
|
|
9
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_
|
11
11
|
|
12
|
+
#include <brotli/types.h>
|
13
|
+
|
12
14
|
#include "../common/constants.h"
|
13
15
|
#include "../common/platform.h"
|
14
|
-
#include
|
15
|
-
#include "./write_bits.h"
|
16
|
+
#include "write_bits.h"
|
16
17
|
|
17
18
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
19
|
extern "C" {
|
@@ -76,6 +77,7 @@ static const uint8_t kStaticDistanceCodeDepth[64] = {
|
|
76
77
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
77
78
|
};
|
78
79
|
|
80
|
+
/* GENERATED CODE START */
|
79
81
|
static const uint32_t kCodeLengthBits[18] = {
|
80
82
|
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 15, 31, 0, 11, 7,
|
81
83
|
};
|
@@ -531,6 +533,7 @@ static BROTLI_INLINE void StoreStaticDistanceHuffmanTree(
|
|
531
533
|
size_t* storage_ix, uint8_t* storage) {
|
532
534
|
BrotliWriteBits(28, 0x0369DC03u, storage_ix, storage);
|
533
535
|
}
|
536
|
+
/* GENERATED CODE END */
|
534
537
|
|
535
538
|
#if defined(__cplusplus) || defined(c_plusplus)
|
536
539
|
} /* extern "C" */
|
@@ -0,0 +1,105 @@
|
|
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
|
+
#include "fast_log.h"
|
8
|
+
|
9
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
10
|
+
extern "C" {
|
11
|
+
#endif
|
12
|
+
|
13
|
+
/* ", ".join(["%.16ff" % x for x in [0.0]+[log2(x) for x in range(1, 256)]]) */
|
14
|
+
const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE] = {
|
15
|
+
0.0000000000000000f, 0.0000000000000000f, 1.0000000000000000f,
|
16
|
+
1.5849625007211563f, 2.0000000000000000f, 2.3219280948873622f,
|
17
|
+
2.5849625007211561f, 2.8073549220576042f, 3.0000000000000000f,
|
18
|
+
3.1699250014423126f, 3.3219280948873626f, 3.4594316186372978f,
|
19
|
+
3.5849625007211565f, 3.7004397181410922f, 3.8073549220576037f,
|
20
|
+
3.9068905956085187f, 4.0000000000000000f, 4.0874628412503400f,
|
21
|
+
4.1699250014423122f, 4.2479275134435852f, 4.3219280948873626f,
|
22
|
+
4.3923174227787607f, 4.4594316186372973f, 4.5235619560570131f,
|
23
|
+
4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f,
|
24
|
+
4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f,
|
25
|
+
4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f,
|
26
|
+
5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f,
|
27
|
+
5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f,
|
28
|
+
5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f,
|
29
|
+
5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f,
|
30
|
+
5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f,
|
31
|
+
5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f,
|
32
|
+
5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f,
|
33
|
+
5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f,
|
34
|
+
5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f,
|
35
|
+
5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f,
|
36
|
+
5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f,
|
37
|
+
6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f,
|
38
|
+
6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f,
|
39
|
+
6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f,
|
40
|
+
6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f,
|
41
|
+
6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f,
|
42
|
+
6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f,
|
43
|
+
6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f,
|
44
|
+
6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f,
|
45
|
+
6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f,
|
46
|
+
6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f,
|
47
|
+
6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f,
|
48
|
+
6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f,
|
49
|
+
6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f,
|
50
|
+
6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f,
|
51
|
+
6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f,
|
52
|
+
6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f,
|
53
|
+
6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f,
|
54
|
+
6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f,
|
55
|
+
6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f,
|
56
|
+
6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f,
|
57
|
+
6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f,
|
58
|
+
7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f,
|
59
|
+
7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f,
|
60
|
+
7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f,
|
61
|
+
7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f,
|
62
|
+
7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f,
|
63
|
+
7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f,
|
64
|
+
7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f,
|
65
|
+
7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f,
|
66
|
+
7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f,
|
67
|
+
7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f,
|
68
|
+
7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f,
|
69
|
+
7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f,
|
70
|
+
7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f,
|
71
|
+
7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f,
|
72
|
+
7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f,
|
73
|
+
7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f,
|
74
|
+
7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f,
|
75
|
+
7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f,
|
76
|
+
7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f,
|
77
|
+
7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f,
|
78
|
+
7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f,
|
79
|
+
7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f,
|
80
|
+
7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f,
|
81
|
+
7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f,
|
82
|
+
7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f,
|
83
|
+
7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f,
|
84
|
+
7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f,
|
85
|
+
7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f,
|
86
|
+
7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f,
|
87
|
+
7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f,
|
88
|
+
7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f,
|
89
|
+
7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f,
|
90
|
+
7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f,
|
91
|
+
7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f,
|
92
|
+
7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f,
|
93
|
+
7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f,
|
94
|
+
7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f,
|
95
|
+
7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f,
|
96
|
+
7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f,
|
97
|
+
7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f,
|
98
|
+
7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f,
|
99
|
+
7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f,
|
100
|
+
7.9943534368588578f
|
101
|
+
};
|
102
|
+
|
103
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
104
|
+
} /* extern "C" */
|
105
|
+
#endif
|
@@ -11,18 +11,17 @@
|
|
11
11
|
|
12
12
|
#include <math.h>
|
13
13
|
|
14
|
-
#include "../common/platform.h"
|
15
14
|
#include <brotli/types.h>
|
16
15
|
|
16
|
+
#include "../common/platform.h"
|
17
|
+
|
17
18
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
19
|
extern "C" {
|
19
20
|
#endif
|
20
21
|
|
21
22
|
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
22
|
-
|
23
|
-
|
24
|
-
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
25
|
-
return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
|
23
|
+
#if defined(BROTLI_BSR32)
|
24
|
+
return BROTLI_BSR32((uint32_t)n);
|
26
25
|
#else
|
27
26
|
uint32_t result = 0;
|
28
27
|
while (n >>= 1) result++;
|
@@ -30,110 +29,31 @@ static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
|
30
29
|
#endif
|
31
30
|
}
|
32
31
|
|
32
|
+
#define BROTLI_LOG2_TABLE_SIZE 256
|
33
|
+
|
33
34
|
/* A lookup table for small values of log2(int) to be used in entropy
|
34
|
-
computation.
|
35
|
+
computation. */
|
36
|
+
BROTLI_INTERNAL extern const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE];
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f,
|
47
|
-
4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f,
|
48
|
-
4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f,
|
49
|
-
5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f,
|
50
|
-
5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f,
|
51
|
-
5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f,
|
52
|
-
5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f,
|
53
|
-
5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f,
|
54
|
-
5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f,
|
55
|
-
5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f,
|
56
|
-
5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f,
|
57
|
-
5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f,
|
58
|
-
5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f,
|
59
|
-
5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f,
|
60
|
-
6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f,
|
61
|
-
6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f,
|
62
|
-
6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f,
|
63
|
-
6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f,
|
64
|
-
6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f,
|
65
|
-
6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f,
|
66
|
-
6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f,
|
67
|
-
6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f,
|
68
|
-
6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f,
|
69
|
-
6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f,
|
70
|
-
6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f,
|
71
|
-
6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f,
|
72
|
-
6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f,
|
73
|
-
6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f,
|
74
|
-
6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f,
|
75
|
-
6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f,
|
76
|
-
6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f,
|
77
|
-
6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f,
|
78
|
-
6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f,
|
79
|
-
6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f,
|
80
|
-
6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f,
|
81
|
-
7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f,
|
82
|
-
7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f,
|
83
|
-
7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f,
|
84
|
-
7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f,
|
85
|
-
7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f,
|
86
|
-
7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f,
|
87
|
-
7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f,
|
88
|
-
7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f,
|
89
|
-
7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f,
|
90
|
-
7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f,
|
91
|
-
7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f,
|
92
|
-
7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f,
|
93
|
-
7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f,
|
94
|
-
7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f,
|
95
|
-
7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f,
|
96
|
-
7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f,
|
97
|
-
7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f,
|
98
|
-
7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f,
|
99
|
-
7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f,
|
100
|
-
7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f,
|
101
|
-
7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f,
|
102
|
-
7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f,
|
103
|
-
7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f,
|
104
|
-
7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f,
|
105
|
-
7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f,
|
106
|
-
7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f,
|
107
|
-
7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f,
|
108
|
-
7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f,
|
109
|
-
7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f,
|
110
|
-
7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f,
|
111
|
-
7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f,
|
112
|
-
7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f,
|
113
|
-
7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f,
|
114
|
-
7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f,
|
115
|
-
7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f,
|
116
|
-
7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f,
|
117
|
-
7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f,
|
118
|
-
7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f,
|
119
|
-
7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f,
|
120
|
-
7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f,
|
121
|
-
7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f,
|
122
|
-
7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f,
|
123
|
-
7.9943534368588578f
|
124
|
-
};
|
38
|
+
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
39
|
+
* function defined, so we use log() and a multiplication instead. */
|
40
|
+
#if !defined(BROTLI_HAVE_LOG2)
|
41
|
+
#if ((defined(_MSC_VER) && _MSC_VER <= 1700) || \
|
42
|
+
(defined(__ANDROID_API__) && __ANDROID_API__ < 18))
|
43
|
+
#define BROTLI_HAVE_LOG2 0
|
44
|
+
#else
|
45
|
+
#define BROTLI_HAVE_LOG2 1
|
46
|
+
#endif
|
47
|
+
#endif
|
125
48
|
|
126
49
|
#define LOG_2_INV 1.4426950408889634
|
127
50
|
|
128
51
|
/* Faster logarithm for small integers, with the property of log2(0) == 0. */
|
129
52
|
static BROTLI_INLINE double FastLog2(size_t v) {
|
130
|
-
if (v <
|
131
|
-
return
|
53
|
+
if (v < BROTLI_LOG2_TABLE_SIZE) {
|
54
|
+
return kBrotliLog2Table[v];
|
132
55
|
}
|
133
|
-
#if (
|
134
|
-
(defined(__ANDROID_API__) && __ANDROID_API__ < 18)
|
135
|
-
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
136
|
-
* function defined, so we use log() and a multiplication instead. */
|
56
|
+
#if !(BROTLI_HAVE_LOG2)
|
137
57
|
return log((double)v) * LOG_2_INV;
|
138
58
|
#else
|
139
59
|
return log2((double)v);
|
@@ -9,44 +9,36 @@
|
|
9
9
|
#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
10
10
|
#define BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
11
11
|
|
12
|
-
#include "../common/platform.h"
|
13
12
|
#include <brotli/types.h>
|
14
13
|
|
14
|
+
#include "../common/platform.h"
|
15
|
+
|
15
16
|
#if defined(__cplusplus) || defined(c_plusplus)
|
16
17
|
extern "C" {
|
17
18
|
#endif
|
18
19
|
|
19
20
|
/* Separate implementation for little-endian 64-bit targets, for speed. */
|
20
|
-
#if defined(
|
21
|
-
|
21
|
+
#if defined(BROTLI_TZCNT64) && BROTLI_64_BITS && BROTLI_LITTLE_ENDIAN
|
22
22
|
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
23
23
|
const uint8_t* s2,
|
24
24
|
size_t limit) {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^
|
34
|
-
BROTLI_UNALIGNED_LOAD64LE(s1 + matched);
|
35
|
-
size_t matching_bits = (size_t)__builtin_ctzll(x);
|
36
|
-
matched += matching_bits >> 3;
|
37
|
-
return matched;
|
25
|
+
const uint8_t *s1_orig = s1;
|
26
|
+
for (; limit >= 8; limit -= 8) {
|
27
|
+
uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^
|
28
|
+
BROTLI_UNALIGNED_LOAD64LE(s1);
|
29
|
+
s2 += 8;
|
30
|
+
if (x != 0) {
|
31
|
+
size_t matching_bits = (size_t)BROTLI_TZCNT64(x);
|
32
|
+
return (size_t)(s1 - s1_orig) + (matching_bits >> 3);
|
38
33
|
}
|
34
|
+
s1 += 8;
|
39
35
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
++matched;
|
45
|
-
} else {
|
46
|
-
return matched;
|
47
|
-
}
|
36
|
+
while (limit && *s1 == *s2) {
|
37
|
+
limit--;
|
38
|
+
++s2;
|
39
|
+
++s1;
|
48
40
|
}
|
49
|
-
return
|
41
|
+
return (size_t)(s1 - s1_orig);
|
50
42
|
}
|
51
43
|
#else
|
52
44
|
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|