brotli 0.2.0 → 0.4.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 +5 -5
- data/.github/workflows/main.yml +34 -0
- data/.github/workflows/publish.yml +34 -0
- data/Gemfile +6 -2
- data/Rakefile +18 -6
- data/bin/before_install.sh +9 -0
- data/brotli.gemspec +7 -13
- data/ext/brotli/brotli.c +209 -11
- data/ext/brotli/buffer.c +1 -7
- data/ext/brotli/buffer.h +1 -1
- data/ext/brotli/extconf.rb +45 -26
- data/lib/brotli/version.rb +1 -1
- data/smoke.sh +1 -1
- data/test/brotli_test.rb +104 -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 +149 -6
- data/vendor/brotli/c/{dec/context.h → common/context.c} +91 -186
- data/vendor/brotli/c/common/context.h +113 -0
- data/vendor/brotli/c/common/dictionary.bin +0 -0
- data/vendor/brotli/c/common/dictionary.bin.br +0 -0
- data/vendor/brotli/c/common/dictionary.c +11 -2
- data/vendor/brotli/c/common/dictionary.h +4 -4
- data/vendor/brotli/c/common/platform.c +22 -0
- data/vendor/brotli/c/common/platform.h +594 -0
- data/vendor/brotli/c/common/transform.c +291 -0
- data/vendor/brotli/c/common/transform.h +85 -0
- data/vendor/brotli/c/common/version.h +8 -1
- data/vendor/brotli/c/dec/bit_reader.c +29 -1
- data/vendor/brotli/c/dec/bit_reader.h +91 -100
- data/vendor/brotli/c/dec/decode.c +665 -437
- data/vendor/brotli/c/dec/huffman.c +65 -84
- data/vendor/brotli/c/dec/huffman.h +67 -14
- data/vendor/brotli/c/dec/prefix.h +1 -20
- data/vendor/brotli/c/dec/state.c +32 -45
- data/vendor/brotli/c/dec/state.h +173 -55
- data/vendor/brotli/c/enc/backward_references.c +27 -16
- data/vendor/brotli/c/enc/backward_references.h +7 -7
- data/vendor/brotli/c/enc/backward_references_hq.c +155 -116
- data/vendor/brotli/c/enc/backward_references_hq.h +22 -23
- data/vendor/brotli/c/enc/backward_references_inc.h +32 -22
- data/vendor/brotli/c/enc/bit_cost.c +1 -1
- data/vendor/brotli/c/enc/bit_cost.h +5 -5
- data/vendor/brotli/c/enc/block_encoder_inc.h +7 -6
- data/vendor/brotli/c/enc/block_splitter.c +5 -6
- data/vendor/brotli/c/enc/block_splitter.h +1 -1
- data/vendor/brotli/c/enc/block_splitter_inc.h +26 -17
- data/vendor/brotli/c/enc/brotli_bit_stream.c +107 -123
- data/vendor/brotli/c/enc/brotli_bit_stream.h +19 -38
- data/vendor/brotli/c/enc/cluster.c +1 -1
- data/vendor/brotli/c/enc/cluster.h +1 -1
- data/vendor/brotli/c/enc/cluster_inc.h +6 -3
- data/vendor/brotli/c/enc/command.c +28 -0
- data/vendor/brotli/c/enc/command.h +52 -42
- data/vendor/brotli/c/enc/compress_fragment.c +21 -22
- data/vendor/brotli/c/enc/compress_fragment.h +1 -1
- data/vendor/brotli/c/enc/compress_fragment_two_pass.c +102 -69
- data/vendor/brotli/c/enc/compress_fragment_two_pass.h +1 -1
- data/vendor/brotli/c/enc/dictionary_hash.c +1827 -1101
- data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
- data/vendor/brotli/c/enc/encode.c +358 -195
- data/vendor/brotli/c/enc/encoder_dict.c +33 -0
- data/vendor/brotli/c/enc/encoder_dict.h +43 -0
- data/vendor/brotli/c/enc/entropy_encode.c +16 -14
- data/vendor/brotli/c/enc/entropy_encode.h +7 -7
- data/vendor/brotli/c/enc/entropy_encode_static.h +3 -3
- data/vendor/brotli/c/enc/fast_log.c +105 -0
- data/vendor/brotli/c/enc/fast_log.h +20 -99
- data/vendor/brotli/c/enc/find_match_length.h +5 -6
- data/vendor/brotli/c/enc/hash.h +145 -103
- data/vendor/brotli/c/enc/hash_composite_inc.h +125 -0
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +93 -53
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +54 -53
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +58 -54
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +95 -63
- data/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +46 -43
- data/vendor/brotli/c/enc/histogram.c +9 -6
- data/vendor/brotli/c/enc/histogram.h +6 -3
- data/vendor/brotli/c/enc/histogram_inc.h +1 -1
- data/vendor/brotli/c/enc/literal_cost.c +5 -5
- data/vendor/brotli/c/enc/literal_cost.h +2 -2
- data/vendor/brotli/c/enc/memory.c +5 -16
- data/vendor/brotli/c/enc/memory.h +52 -1
- data/vendor/brotli/c/enc/metablock.c +171 -36
- data/vendor/brotli/c/enc/metablock.h +13 -8
- data/vendor/brotli/c/enc/metablock_inc.h +2 -2
- data/vendor/brotli/c/enc/params.h +46 -0
- data/vendor/brotli/c/enc/prefix.h +3 -4
- data/vendor/brotli/c/enc/quality.h +29 -24
- data/vendor/brotli/c/enc/ringbuffer.h +19 -12
- data/vendor/brotli/c/enc/static_dict.c +49 -45
- data/vendor/brotli/c/enc/static_dict.h +4 -3
- data/vendor/brotli/c/enc/static_dict_lut.h +1 -1
- data/vendor/brotli/c/enc/utf8_util.c +21 -21
- data/vendor/brotli/c/enc/utf8_util.h +1 -1
- data/vendor/brotli/c/enc/write_bits.h +35 -38
- data/vendor/brotli/c/include/brotli/decode.h +13 -8
- data/vendor/brotli/c/include/brotli/encode.h +54 -8
- data/vendor/brotli/c/include/brotli/port.h +225 -83
- data/vendor/brotli/c/include/brotli/types.h +0 -7
- metadata +28 -87
- data/.travis.yml +0 -30
- data/spec/brotli_spec.rb +0 -88
- data/spec/inflate_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -4
- data/vendor/brotli/c/dec/port.h +0 -168
- data/vendor/brotli/c/dec/transform.h +0 -300
- data/vendor/brotli/c/enc/context.h +0 -184
- data/vendor/brotli/c/enc/port.h +0 -184
@@ -0,0 +1,33 @@
|
|
1
|
+
/* Copyright 2017 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 "./encoder_dict.h"
|
8
|
+
|
9
|
+
#include "../common/dictionary.h"
|
10
|
+
#include "../common/transform.h"
|
11
|
+
#include "./dictionary_hash.h"
|
12
|
+
#include "./hash.h"
|
13
|
+
|
14
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
15
|
+
extern "C" {
|
16
|
+
#endif
|
17
|
+
|
18
|
+
void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict) {
|
19
|
+
dict->words = BrotliGetDictionary();
|
20
|
+
dict->num_transforms = (uint32_t)BrotliGetTransforms()->num_transforms;
|
21
|
+
|
22
|
+
dict->hash_table_words = kStaticDictionaryHashWords;
|
23
|
+
dict->hash_table_lengths = kStaticDictionaryHashLengths;
|
24
|
+
dict->buckets = kStaticDictionaryBuckets;
|
25
|
+
dict->dict_words = kStaticDictionaryWords;
|
26
|
+
|
27
|
+
dict->cutoffTransformsCount = kCutoffTransformsCount;
|
28
|
+
dict->cutoffTransforms = kCutoffTransforms;
|
29
|
+
}
|
30
|
+
|
31
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
32
|
+
} /* extern "C" */
|
33
|
+
#endif
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/* Copyright 2017 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
|
+
#ifndef BROTLI_ENC_ENCODER_DICT_H_
|
8
|
+
#define BROTLI_ENC_ENCODER_DICT_H_
|
9
|
+
|
10
|
+
#include "../common/dictionary.h"
|
11
|
+
#include "../common/platform.h"
|
12
|
+
#include <brotli/types.h>
|
13
|
+
#include "./static_dict_lut.h"
|
14
|
+
|
15
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
18
|
+
|
19
|
+
/* Dictionary data (words and transforms) for 1 possible context */
|
20
|
+
typedef struct BrotliEncoderDictionary {
|
21
|
+
const BrotliDictionary* words;
|
22
|
+
uint32_t num_transforms;
|
23
|
+
|
24
|
+
/* cut off for fast encoder */
|
25
|
+
uint32_t cutoffTransformsCount;
|
26
|
+
uint64_t cutoffTransforms;
|
27
|
+
|
28
|
+
/* from dictionary_hash.h, for fast encoder */
|
29
|
+
const uint16_t* hash_table_words;
|
30
|
+
const uint8_t* hash_table_lengths;
|
31
|
+
|
32
|
+
/* from static_dict_lut.h, for slow encoder */
|
33
|
+
const uint16_t* buckets;
|
34
|
+
const DictWord* dict_words;
|
35
|
+
} BrotliEncoderDictionary;
|
36
|
+
|
37
|
+
BROTLI_INTERNAL void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict);
|
38
|
+
|
39
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
40
|
+
} /* extern "C" */
|
41
|
+
#endif
|
42
|
+
|
43
|
+
#endif /* BROTLI_ENC_ENCODER_DICT_H_ */
|
@@ -11,19 +11,21 @@
|
|
11
11
|
#include <string.h> /* memset */
|
12
12
|
|
13
13
|
#include "../common/constants.h"
|
14
|
+
#include "../common/platform.h"
|
14
15
|
#include <brotli/types.h>
|
15
|
-
#include "./port.h"
|
16
16
|
|
17
17
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
18
|
extern "C" {
|
19
19
|
#endif
|
20
20
|
|
21
|
+
const size_t kBrotliShellGaps[] = {132, 57, 23, 10, 4, 1};
|
22
|
+
|
21
23
|
BROTLI_BOOL BrotliSetDepth(
|
22
24
|
int p0, HuffmanTree* pool, uint8_t* depth, int max_depth) {
|
23
25
|
int stack[16];
|
24
26
|
int level = 0;
|
25
27
|
int p = p0;
|
26
|
-
|
28
|
+
BROTLI_DCHECK(max_depth <= 15);
|
27
29
|
stack[0] = -1;
|
28
30
|
while (BROTLI_TRUE) {
|
29
31
|
if (pool[p].index_left_ >= 0) {
|
@@ -66,11 +68,11 @@ static BROTLI_INLINE BROTLI_BOOL SortHuffmanTree(
|
|
66
68
|
we are not planning to use this with extremely long blocks.
|
67
69
|
|
68
70
|
See http://en.wikipedia.org/wiki/Huffman_coding */
|
69
|
-
void BrotliCreateHuffmanTree(const uint32_t
|
71
|
+
void BrotliCreateHuffmanTree(const uint32_t* data,
|
70
72
|
const size_t length,
|
71
73
|
const int tree_limit,
|
72
74
|
HuffmanTree* tree,
|
73
|
-
uint8_t
|
75
|
+
uint8_t* depth) {
|
74
76
|
uint32_t count_limit;
|
75
77
|
HuffmanTree sentinel;
|
76
78
|
InitHuffmanTree(&sentinel, BROTLI_UINT32_MAX, -1, -1);
|
@@ -165,7 +167,7 @@ static void BrotliWriteHuffmanTreeRepetitions(
|
|
165
167
|
size_t* tree_size,
|
166
168
|
uint8_t* tree,
|
167
169
|
uint8_t* extra_bits_data) {
|
168
|
-
|
170
|
+
BROTLI_DCHECK(repetitions > 0);
|
169
171
|
if (previous_value != value) {
|
170
172
|
tree[*tree_size] = value;
|
171
173
|
extra_bits_data[*tree_size] = 0;
|
@@ -371,8 +373,8 @@ void BrotliOptimizeHuffmanCountsForRle(size_t length, uint32_t* counts,
|
|
371
373
|
}
|
372
374
|
|
373
375
|
static void DecideOverRleUse(const uint8_t* depth, const size_t length,
|
374
|
-
BROTLI_BOOL
|
375
|
-
BROTLI_BOOL
|
376
|
+
BROTLI_BOOL* use_rle_for_non_zero,
|
377
|
+
BROTLI_BOOL* use_rle_for_zero) {
|
376
378
|
size_t total_reps_zero = 0;
|
377
379
|
size_t total_reps_non_zero = 0;
|
378
380
|
size_t count_reps_zero = 1;
|
@@ -454,26 +456,26 @@ void BrotliWriteHuffmanTree(const uint8_t* depth,
|
|
454
456
|
|
455
457
|
static uint16_t BrotliReverseBits(size_t num_bits, uint16_t bits) {
|
456
458
|
static const size_t kLut[16] = { /* Pre-reversed 4-bit values. */
|
457
|
-
|
458
|
-
|
459
|
+
0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E,
|
460
|
+
0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F
|
459
461
|
};
|
460
|
-
size_t retval = kLut[bits &
|
462
|
+
size_t retval = kLut[bits & 0x0F];
|
461
463
|
size_t i;
|
462
464
|
for (i = 4; i < num_bits; i += 4) {
|
463
465
|
retval <<= 4;
|
464
466
|
bits = (uint16_t)(bits >> 4);
|
465
|
-
retval |= kLut[bits &
|
467
|
+
retval |= kLut[bits & 0x0F];
|
466
468
|
}
|
467
|
-
retval >>= ((0 - num_bits) &
|
469
|
+
retval >>= ((0 - num_bits) & 0x03);
|
468
470
|
return (uint16_t)retval;
|
469
471
|
}
|
470
472
|
|
471
473
|
/* 0..15 are values for bits */
|
472
474
|
#define MAX_HUFFMAN_BITS 16
|
473
475
|
|
474
|
-
void BrotliConvertBitDepthsToSymbols(const uint8_t
|
476
|
+
void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
|
475
477
|
size_t len,
|
476
|
-
uint16_t
|
478
|
+
uint16_t* bits) {
|
477
479
|
/* In Brotli, all bit depths are [1..15]
|
478
480
|
0 bit depth means that the symbol does not exist. */
|
479
481
|
uint16_t bl_count[MAX_HUFFMAN_BITS] = { 0 };
|
@@ -9,8 +9,8 @@
|
|
9
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_H_
|
11
11
|
|
12
|
+
#include "../common/platform.h"
|
12
13
|
#include <brotli/types.h>
|
13
|
-
#include "./port.h"
|
14
14
|
|
15
15
|
#if defined(__cplusplus) || defined(c_plusplus)
|
16
16
|
extern "C" {
|
@@ -46,11 +46,11 @@ BROTLI_INTERNAL BROTLI_BOOL BrotliSetDepth(
|
|
46
46
|
be at least 2 * length + 1 long.
|
47
47
|
|
48
48
|
See http://en.wikipedia.org/wiki/Huffman_coding */
|
49
|
-
BROTLI_INTERNAL void BrotliCreateHuffmanTree(const uint32_t
|
49
|
+
BROTLI_INTERNAL void BrotliCreateHuffmanTree(const uint32_t* data,
|
50
50
|
const size_t length,
|
51
51
|
const int tree_limit,
|
52
52
|
HuffmanTree* tree,
|
53
|
-
uint8_t
|
53
|
+
uint8_t* depth);
|
54
54
|
|
55
55
|
/* Change the population counts in a way that the consequent
|
56
56
|
Huffman tree compression, especially its RLE-part will be more
|
@@ -72,16 +72,16 @@ BROTLI_INTERNAL void BrotliWriteHuffmanTree(const uint8_t* depth,
|
|
72
72
|
uint8_t* extra_bits_data);
|
73
73
|
|
74
74
|
/* Get the actual bit values for a tree of bit depths. */
|
75
|
-
BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t
|
75
|
+
BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
|
76
76
|
size_t len,
|
77
|
-
uint16_t
|
77
|
+
uint16_t* bits);
|
78
78
|
|
79
|
+
BROTLI_INTERNAL extern const size_t kBrotliShellGaps[6];
|
79
80
|
/* Input size optimized Shell sort. */
|
80
81
|
typedef BROTLI_BOOL (*HuffmanTreeComparator)(
|
81
82
|
const HuffmanTree*, const HuffmanTree*);
|
82
83
|
static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
83
84
|
const size_t n, HuffmanTreeComparator comparator) {
|
84
|
-
static const size_t gaps[] = {132, 57, 23, 10, 4, 1};
|
85
85
|
if (n < 13) {
|
86
86
|
/* Insertion sort. */
|
87
87
|
size_t i;
|
@@ -101,7 +101,7 @@ static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
|
101
101
|
/* Shell sort. */
|
102
102
|
int g = n < 57 ? 2 : 0;
|
103
103
|
for (; g < 6; ++g) {
|
104
|
-
size_t gap =
|
104
|
+
size_t gap = kBrotliShellGaps[g];
|
105
105
|
size_t i;
|
106
106
|
for (i = gap; i < n; ++i) {
|
107
107
|
size_t j = i;
|
@@ -10,7 +10,7 @@
|
|
10
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_STATIC_H_
|
11
11
|
|
12
12
|
#include "../common/constants.h"
|
13
|
-
#include
|
13
|
+
#include "../common/platform.h"
|
14
14
|
#include <brotli/types.h>
|
15
15
|
#include "./write_bits.h"
|
16
16
|
|
@@ -83,7 +83,7 @@ static const uint32_t kCodeLengthBits[18] = {
|
|
83
83
|
static BROTLI_INLINE void StoreStaticCodeLengthCode(
|
84
84
|
size_t* storage_ix, uint8_t* storage) {
|
85
85
|
BrotliWriteBits(
|
86
|
-
40, BROTLI_MAKE_UINT64_T(
|
86
|
+
40, BROTLI_MAKE_UINT64_T(0x0000FFu, 0x55555554u), storage_ix, storage);
|
87
87
|
}
|
88
88
|
|
89
89
|
static const uint64_t kZeroRepsBits[BROTLI_NUM_COMMAND_SYMBOLS] = {
|
@@ -529,7 +529,7 @@ static const uint16_t kStaticDistanceCodeBits[64] = {
|
|
529
529
|
|
530
530
|
static BROTLI_INLINE void StoreStaticDistanceHuffmanTree(
|
531
531
|
size_t* storage_ix, uint8_t* storage) {
|
532
|
-
BrotliWriteBits(28,
|
532
|
+
BrotliWriteBits(28, 0x0369DC03u, storage_ix, storage);
|
533
533
|
}
|
534
534
|
|
535
535
|
#if defined(__cplusplus) || defined(c_plusplus)
|
@@ -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,16 +11,16 @@
|
|
11
11
|
|
12
12
|
#include <math.h>
|
13
13
|
|
14
|
+
#include "../common/platform.h"
|
14
15
|
#include <brotli/types.h>
|
15
|
-
#include <brotli/port.h>
|
16
16
|
|
17
17
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
18
|
extern "C" {
|
19
19
|
#endif
|
20
20
|
|
21
21
|
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
22
|
-
#if
|
23
|
-
return
|
22
|
+
#if defined(BROTLI_BSR32)
|
23
|
+
return BROTLI_BSR32((uint32_t)n);
|
24
24
|
#else
|
25
25
|
uint32_t result = 0;
|
26
26
|
while (n >>= 1) result++;
|
@@ -28,110 +28,31 @@ static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
|
28
28
|
#endif
|
29
29
|
}
|
30
30
|
|
31
|
+
#define BROTLI_LOG2_TABLE_SIZE 256
|
32
|
+
|
31
33
|
/* A lookup table for small values of log2(int) to be used in entropy
|
32
|
-
computation.
|
34
|
+
computation. */
|
35
|
+
BROTLI_INTERNAL extern const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE];
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f,
|
45
|
-
4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f,
|
46
|
-
4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f,
|
47
|
-
5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f,
|
48
|
-
5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f,
|
49
|
-
5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f,
|
50
|
-
5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f,
|
51
|
-
5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f,
|
52
|
-
5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f,
|
53
|
-
5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f,
|
54
|
-
5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f,
|
55
|
-
5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f,
|
56
|
-
5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f,
|
57
|
-
5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f,
|
58
|
-
6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f,
|
59
|
-
6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f,
|
60
|
-
6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f,
|
61
|
-
6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f,
|
62
|
-
6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f,
|
63
|
-
6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f,
|
64
|
-
6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f,
|
65
|
-
6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f,
|
66
|
-
6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f,
|
67
|
-
6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f,
|
68
|
-
6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f,
|
69
|
-
6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f,
|
70
|
-
6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f,
|
71
|
-
6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f,
|
72
|
-
6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f,
|
73
|
-
6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f,
|
74
|
-
6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f,
|
75
|
-
6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f,
|
76
|
-
6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f,
|
77
|
-
6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f,
|
78
|
-
6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f,
|
79
|
-
7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f,
|
80
|
-
7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f,
|
81
|
-
7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f,
|
82
|
-
7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f,
|
83
|
-
7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f,
|
84
|
-
7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f,
|
85
|
-
7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f,
|
86
|
-
7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f,
|
87
|
-
7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f,
|
88
|
-
7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f,
|
89
|
-
7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f,
|
90
|
-
7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f,
|
91
|
-
7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f,
|
92
|
-
7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f,
|
93
|
-
7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f,
|
94
|
-
7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f,
|
95
|
-
7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f,
|
96
|
-
7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f,
|
97
|
-
7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f,
|
98
|
-
7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f,
|
99
|
-
7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f,
|
100
|
-
7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f,
|
101
|
-
7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f,
|
102
|
-
7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f,
|
103
|
-
7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f,
|
104
|
-
7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f,
|
105
|
-
7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f,
|
106
|
-
7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f,
|
107
|
-
7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f,
|
108
|
-
7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f,
|
109
|
-
7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f,
|
110
|
-
7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f,
|
111
|
-
7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f,
|
112
|
-
7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f,
|
113
|
-
7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f,
|
114
|
-
7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f,
|
115
|
-
7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f,
|
116
|
-
7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f,
|
117
|
-
7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f,
|
118
|
-
7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f,
|
119
|
-
7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f,
|
120
|
-
7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f,
|
121
|
-
7.9943534368588578f
|
122
|
-
};
|
37
|
+
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
38
|
+
* function defined, so we use log() and a multiplication instead. */
|
39
|
+
#if !defined(BROTLI_HAVE_LOG2)
|
40
|
+
#if ((defined(_MSC_VER) && _MSC_VER <= 1700) || \
|
41
|
+
(defined(__ANDROID_API__) && __ANDROID_API__ < 18))
|
42
|
+
#define BROTLI_HAVE_LOG2 0
|
43
|
+
#else
|
44
|
+
#define BROTLI_HAVE_LOG2 1
|
45
|
+
#endif
|
46
|
+
#endif
|
123
47
|
|
124
48
|
#define LOG_2_INV 1.4426950408889634
|
125
49
|
|
126
50
|
/* Faster logarithm for small integers, with the property of log2(0) == 0. */
|
127
51
|
static BROTLI_INLINE double FastLog2(size_t v) {
|
128
|
-
if (v <
|
129
|
-
return
|
52
|
+
if (v < BROTLI_LOG2_TABLE_SIZE) {
|
53
|
+
return kBrotliLog2Table[v];
|
130
54
|
}
|
131
|
-
#if (
|
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. */
|
55
|
+
#if !(BROTLI_HAVE_LOG2)
|
135
56
|
return log((double)v) * LOG_2_INV;
|
136
57
|
#else
|
137
58
|
return log2((double)v);
|