brotli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +11 -3
- data/Gemfile +2 -0
- data/ext/brotli/brotli.c +279 -0
- data/ext/brotli/brotli.h +2 -0
- data/ext/brotli/buffer.c +95 -0
- data/ext/brotli/buffer.h +19 -0
- data/ext/brotli/extconf.rb +21 -81
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/dec/bit_reader.c +5 -5
- data/vendor/brotli/dec/bit_reader.h +15 -15
- data/vendor/brotli/dec/context.h +1 -1
- data/vendor/brotli/dec/decode.c +433 -348
- data/vendor/brotli/dec/decode.h +74 -48
- data/vendor/brotli/dec/huffman.c +5 -4
- data/vendor/brotli/dec/huffman.h +4 -4
- data/vendor/brotli/dec/port.h +2 -95
- data/vendor/brotli/dec/prefix.h +5 -3
- data/vendor/brotli/dec/state.c +15 -27
- data/vendor/brotli/dec/state.h +21 -17
- data/vendor/brotli/dec/transform.h +1 -1
- data/vendor/brotli/enc/backward_references.c +892 -0
- data/vendor/brotli/enc/backward_references.h +85 -102
- data/vendor/brotli/enc/backward_references_inc.h +147 -0
- data/vendor/brotli/enc/bit_cost.c +35 -0
- data/vendor/brotli/enc/bit_cost.h +23 -121
- data/vendor/brotli/enc/bit_cost_inc.h +127 -0
- data/vendor/brotli/enc/block_encoder_inc.h +33 -0
- data/vendor/brotli/enc/block_splitter.c +197 -0
- data/vendor/brotli/enc/block_splitter.h +40 -50
- data/vendor/brotli/enc/block_splitter_inc.h +432 -0
- data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
- data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
- data/vendor/brotli/enc/cluster.c +56 -0
- data/vendor/brotli/enc/cluster.h +23 -305
- data/vendor/brotli/enc/cluster_inc.h +315 -0
- data/vendor/brotli/enc/command.h +83 -76
- data/vendor/brotli/enc/compress_fragment.c +747 -0
- data/vendor/brotli/enc/compress_fragment.h +48 -37
- data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
- data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
- data/vendor/brotli/enc/compressor.cc +139 -0
- data/vendor/brotli/enc/compressor.h +146 -0
- data/vendor/brotli/enc/context.h +102 -96
- data/vendor/brotli/enc/dictionary_hash.h +9 -5
- data/vendor/brotli/enc/encode.c +1562 -0
- data/vendor/brotli/enc/encode.h +211 -199
- data/vendor/brotli/enc/encode_parallel.cc +161 -151
- data/vendor/brotli/enc/encode_parallel.h +7 -8
- data/vendor/brotli/enc/entropy_encode.c +501 -0
- data/vendor/brotli/enc/entropy_encode.h +107 -89
- data/vendor/brotli/enc/entropy_encode_static.h +29 -62
- data/vendor/brotli/enc/fast_log.h +26 -20
- data/vendor/brotli/enc/find_match_length.h +23 -20
- data/vendor/brotli/enc/hash.h +614 -871
- data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
- data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
- data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
- data/vendor/brotli/enc/histogram.c +95 -0
- data/vendor/brotli/enc/histogram.h +49 -83
- data/vendor/brotli/enc/histogram_inc.h +51 -0
- data/vendor/brotli/enc/literal_cost.c +178 -0
- data/vendor/brotli/enc/literal_cost.h +16 -10
- data/vendor/brotli/enc/memory.c +181 -0
- data/vendor/brotli/enc/memory.h +62 -0
- data/vendor/brotli/enc/metablock.c +515 -0
- data/vendor/brotli/enc/metablock.h +87 -57
- data/vendor/brotli/enc/metablock_inc.h +183 -0
- data/vendor/brotli/enc/port.h +73 -47
- data/vendor/brotli/enc/prefix.h +34 -61
- data/vendor/brotli/enc/quality.h +130 -0
- data/vendor/brotli/enc/ringbuffer.h +137 -122
- data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
- data/vendor/brotli/enc/static_dict.h +23 -18
- data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
- data/vendor/brotli/enc/streams.cc +7 -7
- data/vendor/brotli/enc/streams.h +32 -32
- data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
- data/vendor/brotli/enc/utf8_util.h +16 -9
- data/vendor/brotli/enc/write_bits.h +49 -43
- metadata +34 -25
- data/ext/brotli/brotli.cc +0 -181
- data/vendor/brotli/dec/Makefile +0 -12
- data/vendor/brotli/dec/dictionary.c +0 -9466
- data/vendor/brotli/dec/dictionary.h +0 -38
- data/vendor/brotli/dec/types.h +0 -38
- data/vendor/brotli/enc/Makefile +0 -14
- data/vendor/brotli/enc/backward_references.cc +0 -858
- data/vendor/brotli/enc/block_splitter.cc +0 -505
- data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
- data/vendor/brotli/enc/compress_fragment.cc +0 -701
- data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
- data/vendor/brotli/enc/dictionary.cc +0 -9466
- data/vendor/brotli/enc/dictionary.h +0 -41
- data/vendor/brotli/enc/encode.cc +0 -1180
- data/vendor/brotli/enc/entropy_encode.cc +0 -480
- data/vendor/brotli/enc/histogram.cc +0 -67
- data/vendor/brotli/enc/literal_cost.cc +0 -165
- data/vendor/brotli/enc/metablock.cc +0 -539
- data/vendor/brotli/enc/transform.h +0 -248
- data/vendor/brotli/enc/types.h +0 -29
@@ -4,101 +4,119 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Entropy encoding (Huffman) utilities. */
|
8
8
|
|
9
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_H_
|
11
11
|
|
12
|
-
#include
|
13
|
-
#include "./
|
14
|
-
#include "./prefix.h"
|
15
|
-
#include "./types.h"
|
12
|
+
#include "../common/types.h"
|
13
|
+
#include "./port.h"
|
16
14
|
|
17
|
-
|
15
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
18
18
|
|
19
|
-
|
20
|
-
struct HuffmanTree {
|
21
|
-
HuffmanTree() {}
|
22
|
-
HuffmanTree(uint32_t count, int16_t left, int16_t right)
|
23
|
-
: total_count_(count),
|
24
|
-
index_left_(left),
|
25
|
-
index_right_or_value_(right) {
|
26
|
-
}
|
19
|
+
/* A node of a Huffman tree. */
|
20
|
+
typedef struct HuffmanTree {
|
27
21
|
uint32_t total_count_;
|
28
22
|
int16_t index_left_;
|
29
23
|
int16_t index_right_or_value_;
|
30
|
-
};
|
31
|
-
|
32
|
-
void
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
|
104
|
-
|
24
|
+
} HuffmanTree;
|
25
|
+
|
26
|
+
static BROTLI_INLINE void InitHuffmanTree(HuffmanTree* self, uint32_t count,
|
27
|
+
int16_t left, int16_t right) {
|
28
|
+
self->total_count_ = count;
|
29
|
+
self->index_left_ = left;
|
30
|
+
self->index_right_or_value_ = right;
|
31
|
+
}
|
32
|
+
|
33
|
+
/* Returns 1 is assignment of depths succeded, otherwise 0. */
|
34
|
+
BROTLI_INTERNAL BROTLI_BOOL BrotliSetDepth(
|
35
|
+
int p, HuffmanTree* pool, uint8_t* depth, int max_depth);
|
36
|
+
|
37
|
+
/* This function will create a Huffman tree.
|
38
|
+
|
39
|
+
The (data,length) contains the population counts.
|
40
|
+
The tree_limit is the maximum bit depth of the Huffman codes.
|
41
|
+
|
42
|
+
The depth contains the tree, i.e., how many bits are used for
|
43
|
+
the symbol.
|
44
|
+
|
45
|
+
The actual Huffman tree is constructed in the tree[] array, which has to
|
46
|
+
be at least 2 * length + 1 long.
|
47
|
+
|
48
|
+
See http://en.wikipedia.org/wiki/Huffman_coding */
|
49
|
+
BROTLI_INTERNAL void BrotliCreateHuffmanTree(const uint32_t *data,
|
50
|
+
const size_t length,
|
51
|
+
const int tree_limit,
|
52
|
+
HuffmanTree* tree,
|
53
|
+
uint8_t *depth);
|
54
|
+
|
55
|
+
/* Change the population counts in a way that the consequent
|
56
|
+
Huffman tree compression, especially its rle-part will be more
|
57
|
+
likely to compress this data more efficiently.
|
58
|
+
|
59
|
+
length contains the size of the histogram.
|
60
|
+
counts contains the population counts.
|
61
|
+
good_for_rle is a buffer of at least length size */
|
62
|
+
BROTLI_INTERNAL void BrotliOptimizeHuffmanCountsForRle(
|
63
|
+
size_t length, uint32_t* counts, uint8_t* good_for_rle);
|
64
|
+
|
65
|
+
/* Write a Huffman tree from bit depths into the bitstream representation
|
66
|
+
of a Huffman tree. The generated Huffman tree is to be compressed once
|
67
|
+
more using a Huffman tree */
|
68
|
+
BROTLI_INTERNAL void BrotliWriteHuffmanTree(const uint8_t* depth,
|
69
|
+
size_t num,
|
70
|
+
size_t* tree_size,
|
71
|
+
uint8_t* tree,
|
72
|
+
uint8_t* extra_bits_data);
|
73
|
+
|
74
|
+
/* Get the actual bit values for a tree of bit depths. */
|
75
|
+
BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t *depth,
|
76
|
+
size_t len,
|
77
|
+
uint16_t *bits);
|
78
|
+
|
79
|
+
/* Input size optimized Shell sort. */
|
80
|
+
typedef BROTLI_BOOL (*HuffmanTreeComparator)(
|
81
|
+
const HuffmanTree*, const HuffmanTree*);
|
82
|
+
static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
83
|
+
const size_t n, HuffmanTreeComparator comparator) {
|
84
|
+
static const size_t gaps[] = {132, 57, 23, 10, 4, 1};
|
85
|
+
if (n < 13) {
|
86
|
+
/* Insertion sort. */
|
87
|
+
size_t i;
|
88
|
+
for (i = 1; i < n; ++i) {
|
89
|
+
HuffmanTree tmp = items[i];
|
90
|
+
size_t k = i;
|
91
|
+
size_t j = i - 1;
|
92
|
+
while (comparator(&tmp, &items[j])) {
|
93
|
+
items[k] = items[j];
|
94
|
+
k = j;
|
95
|
+
if (!j--) break;
|
96
|
+
}
|
97
|
+
items[k] = tmp;
|
98
|
+
}
|
99
|
+
return;
|
100
|
+
} else {
|
101
|
+
/* Shell sort. */
|
102
|
+
int g = n < 57 ? 2 : 0;
|
103
|
+
for (; g < 6; ++g) {
|
104
|
+
size_t gap = gaps[g];
|
105
|
+
size_t i;
|
106
|
+
for (i = gap; i < n; ++i) {
|
107
|
+
size_t j = i;
|
108
|
+
HuffmanTree tmp = items[i];
|
109
|
+
for (; j >= gap && comparator(&tmp, &items[j - gap]); j -= gap) {
|
110
|
+
items[j] = items[j - gap];
|
111
|
+
}
|
112
|
+
items[j] = tmp;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
119
|
+
} /* extern "C" */
|
120
|
+
#endif
|
121
|
+
|
122
|
+
#endif /* BROTLI_ENC_ENTROPY_ENCODE_H_ */
|
@@ -4,22 +4,25 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Static entropy codes used for faster meta-block encoding. */
|
8
8
|
|
9
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_
|
11
11
|
|
12
|
-
#include "
|
13
|
-
#include "
|
12
|
+
#include "../common/constants.h"
|
13
|
+
#include "../common/port.h"
|
14
|
+
#include "../common/types.h"
|
14
15
|
#include "./write_bits.h"
|
15
16
|
|
16
|
-
|
17
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
17
20
|
|
18
21
|
static const uint8_t kCodeLengthDepth[18] = {
|
19
22
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 0, 4, 4,
|
20
23
|
};
|
21
24
|
|
22
|
-
static const uint8_t kStaticCommandCodeDepth[
|
25
|
+
static const uint8_t kStaticCommandCodeDepth[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
23
26
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
24
27
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
25
28
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
@@ -77,11 +80,13 @@ static const uint32_t kCodeLengthBits[18] = {
|
|
77
80
|
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 15, 31, 0, 11, 7,
|
78
81
|
};
|
79
82
|
|
80
|
-
|
81
|
-
|
83
|
+
static BROTLI_INLINE void StoreStaticCodeLengthCode(
|
84
|
+
size_t* storage_ix, uint8_t* storage) {
|
85
|
+
BrotliWriteBits(
|
86
|
+
40, MAKE_UINT64_T(0x0000ffU, 0x55555554U), storage_ix, storage);
|
82
87
|
}
|
83
88
|
|
84
|
-
static const uint64_t kZeroRepsBits[
|
89
|
+
static const uint64_t kZeroRepsBits[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
85
90
|
0x00000000, 0x00000000, 0x00000000, 0x00000007, 0x00000017, 0x00000027,
|
86
91
|
0x00000037, 0x00000047, 0x00000057, 0x00000067, 0x00000077, 0x00000770,
|
87
92
|
0x00000b87, 0x00001387, 0x00001b87, 0x00002387, 0x00002b87, 0x00003387,
|
@@ -202,7 +207,7 @@ static const uint64_t kZeroRepsBits[704] = {
|
|
202
207
|
0x06f9cb87, 0x08f9cb87,
|
203
208
|
};
|
204
209
|
|
205
|
-
static const uint32_t kZeroRepsDepth[
|
210
|
+
static const uint32_t kZeroRepsDepth[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
206
211
|
0, 4, 8, 7, 7, 7, 7, 7, 7, 7, 7, 11, 14, 14, 14, 14,
|
207
212
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
208
213
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
@@ -249,7 +254,7 @@ static const uint32_t kZeroRepsDepth[704] = {
|
|
249
254
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
250
255
|
};
|
251
256
|
|
252
|
-
static const uint64_t kNonZeroRepsBits[
|
257
|
+
static const uint64_t kNonZeroRepsBits[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
253
258
|
0x0000000b, 0x0000001b, 0x0000002b, 0x0000003b, 0x000002cb, 0x000006cb,
|
254
259
|
0x00000acb, 0x00000ecb, 0x000002db, 0x000006db, 0x00000adb, 0x00000edb,
|
255
260
|
0x000002eb, 0x000006eb, 0x00000aeb, 0x00000eeb, 0x000002fb, 0x000006fb,
|
@@ -370,7 +375,7 @@ static const uint64_t kNonZeroRepsBits[704] = {
|
|
370
375
|
0x2baeb6db, 0x3baeb6db,
|
371
376
|
};
|
372
377
|
|
373
|
-
static const uint32_t kNonZeroRepsDepth[
|
378
|
+
static const uint32_t kNonZeroRepsDepth[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
374
379
|
6, 6, 6, 6, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
375
380
|
12, 12, 12, 12, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
376
381
|
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
@@ -417,47 +422,7 @@ static const uint32_t kNonZeroRepsDepth[704] = {
|
|
417
422
|
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
|
418
423
|
};
|
419
424
|
|
420
|
-
static const uint16_t
|
421
|
-
0, 128, 64, 192, 32, 160, 96, 224,
|
422
|
-
16, 144, 80, 208, 48, 176, 112, 240,
|
423
|
-
8, 136, 72, 200, 40, 168, 104, 232,
|
424
|
-
24, 152, 88, 216, 56, 184, 120, 248,
|
425
|
-
4, 132, 68, 196, 36, 164, 100, 228,
|
426
|
-
20, 148, 84, 212, 52, 180, 116, 244,
|
427
|
-
12, 140, 76, 204, 44, 172, 108, 236,
|
428
|
-
28, 156, 92, 220, 60, 188, 124, 252,
|
429
|
-
2, 130, 66, 194, 34, 162, 98, 226,
|
430
|
-
18, 146, 82, 210, 50, 178, 114, 242,
|
431
|
-
10, 138, 74, 202, 42, 170, 106, 234,
|
432
|
-
26, 154, 90, 218, 58, 186, 122, 250,
|
433
|
-
6, 134, 70, 198, 38, 166, 102, 230,
|
434
|
-
22, 150, 86, 214, 54, 182, 118, 246,
|
435
|
-
14, 142, 78, 206, 46, 174, 110, 238,
|
436
|
-
30, 158, 94, 222, 62, 190, 126, 254,
|
437
|
-
1, 129, 65, 193, 33, 161, 97, 225,
|
438
|
-
17, 145, 81, 209, 49, 177, 113, 241,
|
439
|
-
9, 137, 73, 201, 41, 169, 105, 233,
|
440
|
-
25, 153, 89, 217, 57, 185, 121, 249,
|
441
|
-
5, 133, 69, 197, 37, 165, 101, 229,
|
442
|
-
21, 149, 85, 213, 53, 181, 117, 245,
|
443
|
-
13, 141, 77, 205, 45, 173, 109, 237,
|
444
|
-
29, 157, 93, 221, 61, 189, 125, 253,
|
445
|
-
3, 131, 67, 195, 35, 163, 99, 227,
|
446
|
-
19, 147, 83, 211, 51, 179, 115, 243,
|
447
|
-
11, 139, 75, 203, 43, 171, 107, 235,
|
448
|
-
27, 155, 91, 219, 59, 187, 123, 251,
|
449
|
-
7, 135, 71, 199, 39, 167, 103, 231,
|
450
|
-
23, 151, 87, 215, 55, 183, 119, 247,
|
451
|
-
15, 143, 79, 207, 47, 175, 111, 239,
|
452
|
-
31, 159, 95, 223, 63, 191, 127, 255,
|
453
|
-
};
|
454
|
-
|
455
|
-
inline void StoreStaticLiteralHuffmanTree(size_t* storage_ix,
|
456
|
-
uint8_t* storage) {
|
457
|
-
WriteBits(32, 0x00010003U, storage_ix, storage);
|
458
|
-
}
|
459
|
-
|
460
|
-
static const uint16_t kStaticCommandCodeBits[kNumCommandPrefixes] = {
|
425
|
+
static const uint16_t kStaticCommandCodeBits[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
461
426
|
0, 256, 128, 384, 64, 320, 192, 448,
|
462
427
|
32, 288, 160, 416, 96, 352, 224, 480,
|
463
428
|
16, 272, 144, 400, 80, 336, 208, 464,
|
@@ -548,10 +513,11 @@ static const uint16_t kStaticCommandCodeBits[kNumCommandPrefixes] = {
|
|
548
513
|
255, 1279, 767, 1791, 511, 1535, 1023, 2047,
|
549
514
|
};
|
550
515
|
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
516
|
+
static BROTLI_INLINE void StoreStaticCommandHuffmanTree(
|
517
|
+
size_t* storage_ix, uint8_t* storage) {
|
518
|
+
BrotliWriteBits(
|
519
|
+
56, MAKE_UINT64_T(0x926244U, 0x16307003U), storage_ix, storage);
|
520
|
+
BrotliWriteBits(3, 0x00000000U, storage_ix, storage);
|
555
521
|
}
|
556
522
|
|
557
523
|
static const uint16_t kStaticDistanceCodeBits[64] = {
|
@@ -561,12 +527,13 @@ static const uint16_t kStaticDistanceCodeBits[64] = {
|
|
561
527
|
3, 35, 19, 51, 11, 43, 27, 59, 7, 39, 23, 55, 15, 47, 31, 63,
|
562
528
|
};
|
563
529
|
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
WriteBits(10, 0x00000000000000daU, storage_ix, storage);
|
530
|
+
static BROTLI_INLINE void StoreStaticDistanceHuffmanTree(
|
531
|
+
size_t* storage_ix, uint8_t* storage) {
|
532
|
+
BrotliWriteBits(28, 0x0369dc03U, storage_ix, storage);
|
568
533
|
}
|
569
534
|
|
570
|
-
|
535
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
536
|
+
} /* extern "C" */
|
537
|
+
#endif
|
571
538
|
|
572
|
-
#endif
|
539
|
+
#endif /* BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_ */
|
@@ -4,21 +4,23 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Utilities for fast computation of logarithms. */
|
8
8
|
|
9
9
|
#ifndef BROTLI_ENC_FAST_LOG_H_
|
10
10
|
#define BROTLI_ENC_FAST_LOG_H_
|
11
11
|
|
12
|
-
#include <assert.h>
|
13
12
|
#include <math.h>
|
14
13
|
|
15
|
-
#include "
|
14
|
+
#include "../common/types.h"
|
15
|
+
#include "../common/port.h"
|
16
16
|
|
17
|
-
|
17
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
18
20
|
|
19
|
-
static
|
21
|
+
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
20
22
|
#ifdef __GNUC__
|
21
|
-
return 31u ^
|
23
|
+
return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
|
22
24
|
#else
|
23
25
|
uint32_t result = 0;
|
24
26
|
while (n >>= 1) result++;
|
@@ -26,10 +28,10 @@ static inline uint32_t Log2FloorNonZero(size_t n) {
|
|
26
28
|
#endif
|
27
29
|
}
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
/* A lookup table for small values of log2(int) to be used in entropy
|
32
|
+
computation.
|
33
|
+
|
34
|
+
", ".join(["%.16ff" % x for x in [0.0]+[log2(x) for x in range(1, 256)]]) */
|
33
35
|
static const float kLog2Table[] = {
|
34
36
|
0.0000000000000000f, 0.0000000000000000f, 1.0000000000000000f,
|
35
37
|
1.5849625007211563f, 2.0000000000000000f, 2.3219280948873622f,
|
@@ -119,21 +121,25 @@ static const float kLog2Table[] = {
|
|
119
121
|
7.9943534368588578f
|
120
122
|
};
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
+
#define LOG_2_INV 1.4426950408889634
|
125
|
+
|
126
|
+
/* Faster logarithm for small integers, with the property of log2(0) == 0. */
|
127
|
+
static BROTLI_INLINE double FastLog2(size_t v) {
|
124
128
|
if (v < sizeof(kLog2Table) / sizeof(kLog2Table[0])) {
|
125
129
|
return kLog2Table[v];
|
126
130
|
}
|
127
|
-
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
return log(
|
131
|
+
#if (defined(_MSC_VER) && _MSC_VER <= 1700) || \
|
132
|
+
(defined(__ANDROID_API__) && __ANDROID_API__ < 18)
|
133
|
+
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
134
|
+
* function defined, so we use log() and a multiplication instead. */
|
135
|
+
return log((double)v) * LOG_2_INV;
|
132
136
|
#else
|
133
|
-
return log2(
|
137
|
+
return log2((double)v);
|
134
138
|
#endif
|
135
139
|
}
|
136
140
|
|
137
|
-
|
141
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
142
|
+
} /* extern "C" */
|
143
|
+
#endif
|
138
144
|
|
139
|
-
#endif
|
145
|
+
#endif /* BROTLI_ENC_FAST_LOG_H_ */
|
@@ -4,25 +4,26 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Function to find maximal matching prefixes of strings. */
|
8
8
|
|
9
9
|
#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
10
10
|
#define BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
11
11
|
|
12
|
-
|
12
|
+
#include "../common/types.h"
|
13
13
|
#include "./port.h"
|
14
|
-
#include "./types.h"
|
15
14
|
|
16
|
-
|
15
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
17
18
|
|
18
|
-
|
19
|
+
/* Separate implementation for little-endian 64-bit targets, for speed. */
|
19
20
|
#if defined(__GNUC__) && defined(_LP64) && defined(IS_LITTLE_ENDIAN)
|
20
21
|
|
21
|
-
static
|
22
|
-
|
23
|
-
|
22
|
+
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
23
|
+
const uint8_t* s2,
|
24
|
+
size_t limit) {
|
24
25
|
size_t matched = 0;
|
25
|
-
size_t limit2 = (limit >> 3) + 1;
|
26
|
+
size_t limit2 = (limit >> 3) + 1; /* + 1 is for pre-decrement in while */
|
26
27
|
while (PREDICT_TRUE(--limit2)) {
|
27
28
|
if (PREDICT_FALSE(BROTLI_UNALIGNED_LOAD64(s2) ==
|
28
29
|
BROTLI_UNALIGNED_LOAD64(s1 + matched))) {
|
@@ -31,12 +32,12 @@ static inline size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
|
31
32
|
} else {
|
32
33
|
uint64_t x =
|
33
34
|
BROTLI_UNALIGNED_LOAD64(s2) ^ BROTLI_UNALIGNED_LOAD64(s1 + matched);
|
34
|
-
size_t matching_bits =
|
35
|
+
size_t matching_bits = (size_t)__builtin_ctzll(x);
|
35
36
|
matched += matching_bits >> 3;
|
36
37
|
return matched;
|
37
38
|
}
|
38
39
|
}
|
39
|
-
limit = (limit & 7) + 1;
|
40
|
+
limit = (limit & 7) + 1; /* + 1 is for pre-decrement in while */
|
40
41
|
while (--limit) {
|
41
42
|
if (PREDICT_TRUE(s1[matched] == *s2)) {
|
42
43
|
++s2;
|
@@ -48,16 +49,16 @@ static inline size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
|
48
49
|
return matched;
|
49
50
|
}
|
50
51
|
#else
|
51
|
-
static
|
52
|
-
|
53
|
-
|
52
|
+
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
53
|
+
const uint8_t* s2,
|
54
|
+
size_t limit) {
|
54
55
|
size_t matched = 0;
|
55
56
|
const uint8_t* s2_limit = s2 + limit;
|
56
57
|
const uint8_t* s2_ptr = s2;
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
/* Find out how long the match is. We loop over the data 32 bits at a
|
59
|
+
time until we find a 32-bit block that doesn't match; then we find
|
60
|
+
the first non-matching bit and use that to calculate the total
|
61
|
+
length of the match. */
|
61
62
|
while (s2_ptr <= s2_limit - 4 &&
|
62
63
|
BROTLI_UNALIGNED_LOAD32(s2_ptr) ==
|
63
64
|
BROTLI_UNALIGNED_LOAD32(s1 + matched)) {
|
@@ -72,6 +73,8 @@ static inline size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
|
72
73
|
}
|
73
74
|
#endif
|
74
75
|
|
75
|
-
|
76
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
77
|
+
} /* extern "C" */
|
78
|
+
#endif
|
76
79
|
|
77
|
-
#endif
|
80
|
+
#endif /* BROTLI_ENC_FIND_MATCH_LENGTH_H_ */
|