brotli 0.2.0 → 0.2.1
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/Gemfile +1 -0
- data/Rakefile +6 -1
- data/brotli.gemspec +1 -1
- data/docs/Brotli.html +485 -0
- data/docs/Brotli/Error.html +124 -0
- data/docs/_index.html +122 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.README.html +127 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +127 -0
- data/docs/js/app.js +292 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +67 -0
- data/docs/top-level-namespace.html +110 -0
- data/ext/brotli/brotli.c +20 -0
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/c/common/constants.h +13 -6
- data/vendor/brotli/c/{dec → common}/context.h +182 -172
- 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 +1 -1
- data/vendor/brotli/c/common/dictionary.h +4 -4
- data/vendor/brotli/c/common/platform.h +509 -0
- data/vendor/brotli/c/common/transform.c +235 -0
- data/vendor/brotli/c/common/transform.h +80 -0
- data/vendor/brotli/c/common/version.h +8 -1
- data/vendor/brotli/c/dec/bit_reader.c +1 -1
- data/vendor/brotli/c/dec/bit_reader.h +35 -86
- data/vendor/brotli/c/dec/decode.c +322 -205
- data/vendor/brotli/c/dec/huffman.c +35 -37
- data/vendor/brotli/c/dec/huffman.h +13 -9
- data/vendor/brotli/c/dec/prefix.h +3 -4
- data/vendor/brotli/c/dec/state.c +26 -34
- data/vendor/brotli/c/dec/state.h +34 -23
- data/vendor/brotli/c/enc/backward_references.c +25 -15
- data/vendor/brotli/c/enc/backward_references.h +5 -6
- data/vendor/brotli/c/enc/backward_references_hq.c +94 -68
- data/vendor/brotli/c/enc/backward_references_hq.h +22 -25
- data/vendor/brotli/c/enc/backward_references_inc.h +10 -10
- 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 +2 -3
- data/vendor/brotli/c/enc/block_splitter.h +1 -1
- data/vendor/brotli/c/enc/block_splitter_inc.h +11 -11
- data/vendor/brotli/c/enc/brotli_bit_stream.c +102 -101
- 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/command.h +40 -30
- 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 +101 -68
- data/vendor/brotli/c/enc/compress_fragment_two_pass.h +1 -1
- data/vendor/brotli/c/enc/dictionary_hash.c +1 -1
- data/vendor/brotli/c/enc/encode.c +262 -162
- data/vendor/brotli/c/enc/encoder_dict.c +32 -0
- data/vendor/brotli/c/enc/encoder_dict.h +41 -0
- data/vendor/brotli/c/enc/entropy_encode.c +14 -14
- data/vendor/brotli/c/enc/entropy_encode.h +5 -5
- data/vendor/brotli/c/enc/entropy_encode_static.h +3 -3
- data/vendor/brotli/c/enc/fast_log.h +4 -2
- data/vendor/brotli/c/enc/find_match_length.h +3 -3
- data/vendor/brotli/c/enc/hash.h +75 -24
- data/vendor/brotli/c/enc/hash_composite_inc.h +133 -0
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +9 -8
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +8 -8
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +8 -8
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +10 -9
- data/vendor/brotli/c/enc/hash_rolling_inc.h +215 -0
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +9 -8
- 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 +40 -1
- data/vendor/brotli/c/enc/metablock.c +163 -25
- data/vendor/brotli/c/enc/metablock.h +13 -8
- data/vendor/brotli/c/enc/metablock_inc.h +1 -1
- data/vendor/brotli/c/enc/params.h +44 -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 +15 -11
- 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 +20 -20
- data/vendor/brotli/c/enc/utf8_util.h +1 -1
- data/vendor/brotli/c/enc/write_bits.h +16 -21
- data/vendor/brotli/c/include/brotli/decode.h +13 -8
- data/vendor/brotli/c/include/brotli/encode.h +33 -8
- data/vendor/brotli/c/include/brotli/port.h +211 -83
- data/vendor/brotli/c/include/brotli/types.h +0 -7
- metadata +33 -12
- 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
|
@@ -6,110 +6,171 @@
|
|
|
6
6
|
|
|
7
7
|
/* Lookup table to map the previous two bytes to a context id.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
The context id for the signed context mode is calculated as:
|
|
88
|
-
|
|
89
|
-
context = (kContextLookup[512 + p1] << 3) | kContextLookup[512 + p2].
|
|
90
|
-
|
|
91
|
-
For any context modeling modes, the context ids can be calculated by |-ing
|
|
92
|
-
together two lookups from one table using context model dependent offsets:
|
|
93
|
-
|
|
94
|
-
context = kContextLookup[offset1 + p1] | kContextLookup[offset2 + p2].
|
|
95
|
-
|
|
96
|
-
where offset1 and offset2 are dependent on the context mode.
|
|
9
|
+
There are four different context modeling modes defined here:
|
|
10
|
+
CONTEXT_LSB6: context id is the least significant 6 bits of the last byte,
|
|
11
|
+
CONTEXT_MSB6: context id is the most significant 6 bits of the last byte,
|
|
12
|
+
CONTEXT_UTF8: second-order context model tuned for UTF8-encoded text,
|
|
13
|
+
CONTEXT_SIGNED: second-order context model tuned for signed integers.
|
|
14
|
+
|
|
15
|
+
If |p1| and |p2| are the previous two bytes, and |mode| is current context
|
|
16
|
+
mode, we calculate the context as:
|
|
17
|
+
|
|
18
|
+
context = ContextLut(mode)[p1] | ContextLut(mode)[p2 + 256].
|
|
19
|
+
|
|
20
|
+
For CONTEXT_UTF8 mode, if the previous two bytes are ASCII characters
|
|
21
|
+
(i.e. < 128), this will be equivalent to
|
|
22
|
+
|
|
23
|
+
context = 4 * context1(p1) + context2(p2),
|
|
24
|
+
|
|
25
|
+
where context1 is based on the previous byte in the following way:
|
|
26
|
+
|
|
27
|
+
0 : non-ASCII control
|
|
28
|
+
1 : \t, \n, \r
|
|
29
|
+
2 : space
|
|
30
|
+
3 : other punctuation
|
|
31
|
+
4 : " '
|
|
32
|
+
5 : %
|
|
33
|
+
6 : ( < [ {
|
|
34
|
+
7 : ) > ] }
|
|
35
|
+
8 : , ; :
|
|
36
|
+
9 : .
|
|
37
|
+
10 : =
|
|
38
|
+
11 : number
|
|
39
|
+
12 : upper-case vowel
|
|
40
|
+
13 : upper-case consonant
|
|
41
|
+
14 : lower-case vowel
|
|
42
|
+
15 : lower-case consonant
|
|
43
|
+
|
|
44
|
+
and context2 is based on the second last byte:
|
|
45
|
+
|
|
46
|
+
0 : control, space
|
|
47
|
+
1 : punctuation
|
|
48
|
+
2 : upper-case letter, number
|
|
49
|
+
3 : lower-case letter
|
|
50
|
+
|
|
51
|
+
If the last byte is ASCII, and the second last byte is not (in a valid UTF8
|
|
52
|
+
stream it will be a continuation byte, value between 128 and 191), the
|
|
53
|
+
context is the same as if the second last byte was an ASCII control or space.
|
|
54
|
+
|
|
55
|
+
If the last byte is a UTF8 lead byte (value >= 192), then the next byte will
|
|
56
|
+
be a continuation byte and the context id is 2 or 3 depending on the LSB of
|
|
57
|
+
the last byte and to a lesser extent on the second last byte if it is ASCII.
|
|
58
|
+
|
|
59
|
+
If the last byte is a UTF8 continuation byte, the second last byte can be:
|
|
60
|
+
- continuation byte: the next byte is probably ASCII or lead byte (assuming
|
|
61
|
+
4-byte UTF8 characters are rare) and the context id is 0 or 1.
|
|
62
|
+
- lead byte (192 - 207): next byte is ASCII or lead byte, context is 0 or 1
|
|
63
|
+
- lead byte (208 - 255): next byte is continuation byte, context is 2 or 3
|
|
64
|
+
|
|
65
|
+
The possible value combinations of the previous two bytes, the range of
|
|
66
|
+
context ids and the type of the next byte is summarized in the table below:
|
|
67
|
+
|
|
68
|
+
|--------\-----------------------------------------------------------------|
|
|
69
|
+
| \ Last byte |
|
|
70
|
+
| Second \---------------------------------------------------------------|
|
|
71
|
+
| last byte \ ASCII | cont. byte | lead byte |
|
|
72
|
+
| \ (0-127) | (128-191) | (192-) |
|
|
73
|
+
|=============|===================|=====================|==================|
|
|
74
|
+
| ASCII | next: ASCII/lead | not valid | next: cont. |
|
|
75
|
+
| (0-127) | context: 4 - 63 | | context: 2 - 3 |
|
|
76
|
+
|-------------|-------------------|---------------------|------------------|
|
|
77
|
+
| cont. byte | next: ASCII/lead | next: ASCII/lead | next: cont. |
|
|
78
|
+
| (128-191) | context: 4 - 63 | context: 0 - 1 | context: 2 - 3 |
|
|
79
|
+
|-------------|-------------------|---------------------|------------------|
|
|
80
|
+
| lead byte | not valid | next: ASCII/lead | not valid |
|
|
81
|
+
| (192-207) | | context: 0 - 1 | |
|
|
82
|
+
|-------------|-------------------|---------------------|------------------|
|
|
83
|
+
| lead byte | not valid | next: cont. | not valid |
|
|
84
|
+
| (208-) | | context: 2 - 3 | |
|
|
85
|
+
|-------------|-------------------|---------------------|------------------|
|
|
97
86
|
*/
|
|
98
87
|
|
|
99
|
-
#ifndef
|
|
100
|
-
#define
|
|
88
|
+
#ifndef BROTLI_COMMON_CONTEXT_H_
|
|
89
|
+
#define BROTLI_COMMON_CONTEXT_H_
|
|
101
90
|
|
|
102
91
|
#include <brotli/types.h>
|
|
103
92
|
|
|
104
|
-
enum ContextType {
|
|
93
|
+
typedef enum ContextType {
|
|
105
94
|
CONTEXT_LSB6 = 0,
|
|
106
95
|
CONTEXT_MSB6 = 1,
|
|
107
96
|
CONTEXT_UTF8 = 2,
|
|
108
97
|
CONTEXT_SIGNED = 3
|
|
109
|
-
};
|
|
98
|
+
} ContextType;
|
|
110
99
|
|
|
111
100
|
/* Common context lookup table for all context modes. */
|
|
112
|
-
static const uint8_t kContextLookup[
|
|
101
|
+
static const uint8_t kContextLookup[2048] = {
|
|
102
|
+
/* CONTEXT_LSB6, last byte. */
|
|
103
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
104
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
105
|
+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
106
|
+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
107
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
108
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
109
|
+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
110
|
+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
111
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
112
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
113
|
+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
114
|
+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
115
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
116
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
117
|
+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
118
|
+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
119
|
+
|
|
120
|
+
/* CONTEXT_LSB6, second last byte, */
|
|
121
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
122
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
123
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
124
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
125
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
126
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
127
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
128
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
129
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
130
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
131
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
132
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
133
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
134
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
135
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
136
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
137
|
+
|
|
138
|
+
/* CONTEXT_MSB6, last byte. */
|
|
139
|
+
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
|
|
140
|
+
4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
|
|
141
|
+
8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11,
|
|
142
|
+
12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15,
|
|
143
|
+
16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19,
|
|
144
|
+
20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
|
|
145
|
+
24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27,
|
|
146
|
+
28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31,
|
|
147
|
+
32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35,
|
|
148
|
+
36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39,
|
|
149
|
+
40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43,
|
|
150
|
+
44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47,
|
|
151
|
+
48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51,
|
|
152
|
+
52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55,
|
|
153
|
+
56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, 59,
|
|
154
|
+
60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63,
|
|
155
|
+
|
|
156
|
+
/* CONTEXT_MSB6, second last byte, */
|
|
157
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
158
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
159
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
160
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
161
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
162
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
163
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
164
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
165
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
166
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
167
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
168
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
169
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
170
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
171
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
172
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
173
|
+
|
|
113
174
|
/* CONTEXT_UTF8, last byte. */
|
|
114
175
|
/* ASCII range. */
|
|
115
176
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 0, 0,
|
|
@@ -130,6 +191,7 @@ static const uint8_t kContextLookup[1792] = {
|
|
|
130
191
|
2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
|
|
131
192
|
2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
|
|
132
193
|
2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
|
|
194
|
+
|
|
133
195
|
/* CONTEXT_UTF8 second last byte. */
|
|
134
196
|
/* ASCII range. */
|
|
135
197
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
@@ -150,23 +212,7 @@ static const uint8_t kContextLookup[1792] = {
|
|
|
150
212
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
151
213
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
152
214
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
153
|
-
|
|
154
|
-
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
155
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
156
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
157
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
158
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
159
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
160
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
161
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
162
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
163
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
164
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
165
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
166
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
167
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
168
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
169
|
-
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7,
|
|
215
|
+
|
|
170
216
|
/* CONTEXT_SIGNED, last byte, same as the above values shifted by 3 bits. */
|
|
171
217
|
0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
172
218
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
@@ -184,68 +230,32 @@ static const uint8_t kContextLookup[1792] = {
|
|
|
184
230
|
40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
|
|
185
231
|
40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
|
|
186
232
|
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 56,
|
|
187
|
-
/* CONTEXT_LSB6, last byte. */
|
|
188
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
189
|
-
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
190
|
-
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
191
|
-
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
192
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
193
|
-
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
194
|
-
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
195
|
-
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
196
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
197
|
-
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
198
|
-
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
199
|
-
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
200
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
201
|
-
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
202
|
-
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
203
|
-
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
204
|
-
/* CONTEXT_MSB6, last byte. */
|
|
205
|
-
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
|
|
206
|
-
4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
|
|
207
|
-
8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11,
|
|
208
|
-
12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15,
|
|
209
|
-
16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19,
|
|
210
|
-
20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
|
|
211
|
-
24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27,
|
|
212
|
-
28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31,
|
|
213
|
-
32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35,
|
|
214
|
-
36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39,
|
|
215
|
-
40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43,
|
|
216
|
-
44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47,
|
|
217
|
-
48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51,
|
|
218
|
-
52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55,
|
|
219
|
-
56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, 59,
|
|
220
|
-
60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63,
|
|
221
|
-
/* CONTEXT_{M,L}SB6, second last byte, */
|
|
222
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
223
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
224
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
225
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
226
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
227
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
228
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
229
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
230
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
231
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
232
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
233
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
234
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
235
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
236
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
237
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
238
|
-
};
|
|
239
233
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
234
|
+
/* CONTEXT_SIGNED, second last byte. */
|
|
235
|
+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
236
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
237
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
238
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
239
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
240
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
241
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
242
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
243
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
244
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
245
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
246
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
247
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
248
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
249
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
250
|
+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7,
|
|
249
251
|
};
|
|
250
252
|
|
|
251
|
-
|
|
253
|
+
typedef const uint8_t* ContextLut;
|
|
254
|
+
|
|
255
|
+
/* typeof(MODE) == ContextType; returns ContextLut */
|
|
256
|
+
#define BROTLI_CONTEXT_LUT(MODE) (&kContextLookup[(MODE) << 9])
|
|
257
|
+
|
|
258
|
+
/* typeof(LUT) == ContextLut */
|
|
259
|
+
#define BROTLI_CONTEXT(P1, P2, LUT) ((LUT)[P1] | ((LUT) + 256)[P2])
|
|
260
|
+
|
|
261
|
+
#endif /* BROTLI_COMMON_CONTEXT_H_ */
|
|
File without changes
|
|
Binary file
|
|
@@ -27,13 +27,13 @@ typedef struct BrotliDictionary {
|
|
|
27
27
|
* Dictionary consists of words with length of [4..24] bytes.
|
|
28
28
|
* Values at [0..3] and [25..31] indices should not be addressed.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
uint8_t size_bits_by_length[32];
|
|
31
31
|
|
|
32
32
|
/* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
|
|
33
|
-
|
|
33
|
+
uint32_t offsets_by_length[32];
|
|
34
34
|
|
|
35
35
|
/* assert(data_size == offsets_by_length[31]) */
|
|
36
|
-
|
|
36
|
+
size_t data_size;
|
|
37
37
|
|
|
38
38
|
/* Data array is not bound, and should obey to size_bits_by_length values.
|
|
39
39
|
Specified size matches default (RFC 7932) dictionary. Its size is
|
|
@@ -41,7 +41,7 @@ typedef struct BrotliDictionary {
|
|
|
41
41
|
const uint8_t* data;
|
|
42
42
|
} BrotliDictionary;
|
|
43
43
|
|
|
44
|
-
BROTLI_COMMON_API
|
|
44
|
+
BROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Sets dictionary data.
|
|
@@ -0,0 +1,509 @@
|
|
|
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_PORTABLE disables dangerous optimizations, like unaligned
|
|
16
|
+
read and overlapping memcpy; this reduces decompression speed by 5%
|
|
17
|
+
* BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
|
|
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
|
+
*/
|
|
22
|
+
|
|
23
|
+
#ifndef BROTLI_COMMON_PLATFORM_H_
|
|
24
|
+
#define BROTLI_COMMON_PLATFORM_H_
|
|
25
|
+
|
|
26
|
+
#include <string.h> /* memcpy */
|
|
27
|
+
#include <stdlib.h> /* malloc, free */
|
|
28
|
+
|
|
29
|
+
#include <brotli/port.h>
|
|
30
|
+
#include <brotli/types.h>
|
|
31
|
+
|
|
32
|
+
#if defined(OS_LINUX) || defined(OS_CYGWIN)
|
|
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 defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
|
|
45
|
+
#include <assert.h>
|
|
46
|
+
#include <stdio.h>
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
/* The following macros were borrowed from https://github.com/nemequ/hedley
|
|
50
|
+
* with permission of original author - Evan Nemerson <evan@nemerson.com> */
|
|
51
|
+
|
|
52
|
+
/* >>> >>> >>> hedley macros */
|
|
53
|
+
|
|
54
|
+
/* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
|
|
55
|
+
compilers.
|
|
56
|
+
|
|
57
|
+
To apply compiler hint, enclose the branching condition into macros, like this:
|
|
58
|
+
|
|
59
|
+
if (BROTLI_PREDICT_TRUE(zero == 0)) {
|
|
60
|
+
// main execution path
|
|
61
|
+
} else {
|
|
62
|
+
// compiler should place this code outside of main execution path
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
OR:
|
|
66
|
+
|
|
67
|
+
if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
|
|
68
|
+
// compiler should place this code outside of main execution path
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
*/
|
|
72
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_expect, 3, 0, 0) || \
|
|
73
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
74
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 12, 0) || \
|
|
75
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
76
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
77
|
+
BROTLI_TI_VERSION_CHECK(7, 3, 0) || \
|
|
78
|
+
BROTLI_TINYC_VERSION_CHECK(0, 9, 27)
|
|
79
|
+
#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
|
|
80
|
+
#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
|
|
81
|
+
#else
|
|
82
|
+
#define BROTLI_PREDICT_FALSE(x) (x)
|
|
83
|
+
#define BROTLI_PREDICT_TRUE(x) (x)
|
|
84
|
+
#endif
|
|
85
|
+
|
|
86
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
|
87
|
+
!defined(__cplusplus)
|
|
88
|
+
#define BROTLI_RESTRICT restrict
|
|
89
|
+
#elif BROTLI_GNUC_VERSION_CHECK(3, 1, 0) || \
|
|
90
|
+
BROTLI_MSVC_VERSION_CHECK(14, 0, 0) || \
|
|
91
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
92
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
93
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
94
|
+
BROTLI_PGI_VERSION_CHECK(17, 10, 0) || \
|
|
95
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
96
|
+
BROTLI_IAR_VERSION_CHECK(8, 0, 0) || \
|
|
97
|
+
(BROTLI_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus))
|
|
98
|
+
#define BROTLI_RESTRICT __restrict
|
|
99
|
+
#elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
|
|
100
|
+
#define BROTLI_RESTRICT _Restrict
|
|
101
|
+
#else
|
|
102
|
+
#define BROTLI_RESTRICT
|
|
103
|
+
#endif
|
|
104
|
+
|
|
105
|
+
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
|
|
106
|
+
(defined(__cplusplus) && (__cplusplus >= 199711L))
|
|
107
|
+
#define BROTLI_MAYBE_INLINE inline
|
|
108
|
+
#elif defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) || \
|
|
109
|
+
BROTLI_ARM_VERSION_CHECK(6, 2, 0)
|
|
110
|
+
#define BROTLI_MAYBE_INLINE __inline__
|
|
111
|
+
#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) || \
|
|
112
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || BROTLI_TI_VERSION_CHECK(8, 0, 0)
|
|
113
|
+
#define BROTLI_MAYBE_INLINE __inline
|
|
114
|
+
#else
|
|
115
|
+
#define BROTLI_MAYBE_INLINE
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(always_inline, 4, 0, 0) || \
|
|
119
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
120
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
|
121
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
122
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
123
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
124
|
+
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
|
|
125
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE __attribute__((__always_inline__))
|
|
126
|
+
#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
|
|
127
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE __forceinline
|
|
128
|
+
#elif BROTLI_TI_VERSION_CHECK(7, 0, 0) && defined(__cplusplus)
|
|
129
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
|
|
130
|
+
#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
|
|
131
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("inline=forced")
|
|
132
|
+
#else
|
|
133
|
+
#define BROTLI_INLINE BROTLI_MAYBE_INLINE
|
|
134
|
+
#endif
|
|
135
|
+
|
|
136
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(noinline, 4, 0, 0) || \
|
|
137
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
138
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
|
139
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
140
|
+
BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
|
|
141
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
142
|
+
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
|
|
143
|
+
#define BROTLI_NOINLINE __attribute__((__noinline__))
|
|
144
|
+
#elif BROTLI_MSVC_VERSION_CHECK(13, 10, 0)
|
|
145
|
+
#define BROTLI_NOINLINE __declspec(noinline)
|
|
146
|
+
#elif BROTLI_PGI_VERSION_CHECK(10, 2, 0)
|
|
147
|
+
#define BROTLI_NOINLINE _Pragma("noinline")
|
|
148
|
+
#elif BROTLI_TI_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
|
|
149
|
+
#define BROTLI_NOINLINE _Pragma("FUNC_CANNOT_INLINE;")
|
|
150
|
+
#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
|
|
151
|
+
#define BROTLI_NOINLINE _Pragma("inline=never")
|
|
152
|
+
#else
|
|
153
|
+
#define BROTLI_NOINLINE
|
|
154
|
+
#endif
|
|
155
|
+
|
|
156
|
+
/* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
|
|
157
|
+
#if !defined(BROTLI_INTERNAL)
|
|
158
|
+
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
159
|
+
#define BROTLI_INTERNAL
|
|
160
|
+
#elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
|
|
161
|
+
BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
|
|
162
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
|
|
163
|
+
BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
|
|
164
|
+
BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
|
|
165
|
+
BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
|
|
166
|
+
(BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
|
|
167
|
+
defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
|
|
168
|
+
#define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
|
|
169
|
+
#else
|
|
170
|
+
#define BROTLI_INTERNAL
|
|
171
|
+
#endif
|
|
172
|
+
#endif
|
|
173
|
+
|
|
174
|
+
/* <<< <<< <<< end of hedley macros. */
|
|
175
|
+
|
|
176
|
+
#if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \
|
|
177
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
178
|
+
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused))
|
|
179
|
+
#else
|
|
180
|
+
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
|
|
184
|
+
(defined(M_ARM) && (M_ARM == 7))
|
|
185
|
+
#define BROTLI_TARGET_ARMV7
|
|
186
|
+
#endif /* ARMv7 */
|
|
187
|
+
|
|
188
|
+
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \
|
|
189
|
+
defined(__aarch64__) || defined(__ARM64_ARCH_8__)
|
|
190
|
+
#define BROTLI_TARGET_ARMV8
|
|
191
|
+
#endif /* ARMv8 */
|
|
192
|
+
|
|
193
|
+
#if defined(__i386) || defined(_M_IX86)
|
|
194
|
+
#define BROTLI_TARGET_X86
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
#if defined(__x86_64__) || defined(_M_X64)
|
|
198
|
+
#define BROTLI_TARGET_X64
|
|
199
|
+
#endif
|
|
200
|
+
|
|
201
|
+
#if defined(__PPC64__)
|
|
202
|
+
#define BROTLI_TARGET_POWERPC64
|
|
203
|
+
#endif
|
|
204
|
+
|
|
205
|
+
#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
|
|
206
|
+
#define BROTLI_TARGET_RISCV64
|
|
207
|
+
#endif
|
|
208
|
+
|
|
209
|
+
#if defined(BROTLI_BUILD_64_BIT)
|
|
210
|
+
#define BROTLI_64_BITS 1
|
|
211
|
+
#elif defined(BROTLI_BUILD_32_BIT)
|
|
212
|
+
#define BROTLI_64_BITS 0
|
|
213
|
+
#elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8) || \
|
|
214
|
+
defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64)
|
|
215
|
+
#define BROTLI_64_BITS 1
|
|
216
|
+
#else
|
|
217
|
+
#define BROTLI_64_BITS 0
|
|
218
|
+
#endif
|
|
219
|
+
|
|
220
|
+
#if (BROTLI_64_BITS)
|
|
221
|
+
#define brotli_reg_t uint64_t
|
|
222
|
+
#else
|
|
223
|
+
#define brotli_reg_t uint32_t
|
|
224
|
+
#endif
|
|
225
|
+
|
|
226
|
+
#if defined(BROTLI_BUILD_BIG_ENDIAN)
|
|
227
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
228
|
+
#elif defined(BROTLI_BUILD_LITTLE_ENDIAN)
|
|
229
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
230
|
+
#elif defined(BROTLI_BUILD_ENDIAN_NEUTRAL)
|
|
231
|
+
/* Just break elif chain. */
|
|
232
|
+
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
|
233
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
234
|
+
#elif defined(_WIN32) || defined(BROTLI_TARGET_X64)
|
|
235
|
+
/* Win32 & x64 can currently always be assumed to be little endian */
|
|
236
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
237
|
+
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
|
238
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
239
|
+
#elif defined(BROTLI_X_BYTE_ORDER)
|
|
240
|
+
#if BROTLI_X_BYTE_ORDER == BROTLI_X_LITTLE_ENDIAN
|
|
241
|
+
#define BROTLI_LITTLE_ENDIAN 1
|
|
242
|
+
#elif BROTLI_X_BYTE_ORDER == BROTLI_X_BIG_ENDIAN
|
|
243
|
+
#define BROTLI_BIG_ENDIAN 1
|
|
244
|
+
#endif
|
|
245
|
+
#endif /* BROTLI_X_BYTE_ORDER */
|
|
246
|
+
|
|
247
|
+
#if !defined(BROTLI_LITTLE_ENDIAN)
|
|
248
|
+
#define BROTLI_LITTLE_ENDIAN 0
|
|
249
|
+
#endif
|
|
250
|
+
|
|
251
|
+
#if !defined(BROTLI_BIG_ENDIAN)
|
|
252
|
+
#define BROTLI_BIG_ENDIAN 0
|
|
253
|
+
#endif
|
|
254
|
+
|
|
255
|
+
#if defined(BROTLI_X_BYTE_ORDER)
|
|
256
|
+
#undef BROTLI_X_BYTE_ORDER
|
|
257
|
+
#undef BROTLI_X_LITTLE_ENDIAN
|
|
258
|
+
#undef BROTLI_X_BIG_ENDIAN
|
|
259
|
+
#endif
|
|
260
|
+
|
|
261
|
+
#if defined(BROTLI_BUILD_PORTABLE)
|
|
262
|
+
#define BROTLI_ALIGNED_READ (!!1)
|
|
263
|
+
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
|
|
264
|
+
defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8) || \
|
|
265
|
+
defined(BROTLI_TARGET_RISCV64)
|
|
266
|
+
/* Allow unaligned read only for white-listed CPUs. */
|
|
267
|
+
#define BROTLI_ALIGNED_READ (!!0)
|
|
268
|
+
#else
|
|
269
|
+
#define BROTLI_ALIGNED_READ (!!1)
|
|
270
|
+
#endif
|
|
271
|
+
|
|
272
|
+
#if BROTLI_ALIGNED_READ
|
|
273
|
+
/* Portable unaligned memory access: read / write values via memcpy. */
|
|
274
|
+
static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
|
|
275
|
+
uint16_t t;
|
|
276
|
+
memcpy(&t, p, sizeof t);
|
|
277
|
+
return t;
|
|
278
|
+
}
|
|
279
|
+
static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
|
|
280
|
+
uint32_t t;
|
|
281
|
+
memcpy(&t, p, sizeof t);
|
|
282
|
+
return t;
|
|
283
|
+
}
|
|
284
|
+
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
|
285
|
+
uint64_t t;
|
|
286
|
+
memcpy(&t, p, sizeof t);
|
|
287
|
+
return t;
|
|
288
|
+
}
|
|
289
|
+
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
|
290
|
+
memcpy(p, &v, sizeof v);
|
|
291
|
+
}
|
|
292
|
+
#else /* BROTLI_ALIGNED_READ */
|
|
293
|
+
/* Unaligned memory access is allowed: just cast pointer to requested type. */
|
|
294
|
+
static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
|
|
295
|
+
return *(const uint16_t*)p;
|
|
296
|
+
}
|
|
297
|
+
static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
|
|
298
|
+
return *(const uint32_t*)p;
|
|
299
|
+
}
|
|
300
|
+
#if (BROTLI_64_BITS)
|
|
301
|
+
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
|
302
|
+
return *(const uint64_t*)p;
|
|
303
|
+
}
|
|
304
|
+
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
|
305
|
+
*(uint64_t*)p = v;
|
|
306
|
+
}
|
|
307
|
+
#else /* BROTLI_64_BITS */
|
|
308
|
+
/* Avoid emitting LDRD / STRD, which require properly aligned address. */
|
|
309
|
+
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
|
|
310
|
+
const uint32_t* dwords = (const uint32_t*)p;
|
|
311
|
+
return dwords[0] | ((uint64_t)dwords[1] << 32);
|
|
312
|
+
}
|
|
313
|
+
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
|
|
314
|
+
uint32_t* dwords = (uint32_t *)p;
|
|
315
|
+
dwords[0] = (uint32_t)v;
|
|
316
|
+
dwords[1] = (uint32_t)(v >> 32);
|
|
317
|
+
}
|
|
318
|
+
#endif /* BROTLI_64_BITS */
|
|
319
|
+
#endif /* BROTLI_ALIGNED_READ */
|
|
320
|
+
|
|
321
|
+
#if BROTLI_LITTLE_ENDIAN
|
|
322
|
+
/* Straight endianness. Just read / write values. */
|
|
323
|
+
#define BROTLI_UNALIGNED_LOAD16LE BrotliUnalignedRead16
|
|
324
|
+
#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
|
|
325
|
+
#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
|
|
326
|
+
#define BROTLI_UNALIGNED_STORE64LE BrotliUnalignedWrite64
|
|
327
|
+
#elif BROTLI_BIG_ENDIAN /* BROTLI_LITTLE_ENDIAN */
|
|
328
|
+
/* Explain compiler to byte-swap values. */
|
|
329
|
+
#define BROTLI_BSWAP16_(V) ((uint16_t)( \
|
|
330
|
+
(((V) & 0xFFU) << 8) | \
|
|
331
|
+
(((V) >> 8) & 0xFFU)))
|
|
332
|
+
static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
|
|
333
|
+
uint16_t value = BrotliUnalignedRead16(p);
|
|
334
|
+
return BROTLI_BSWAP16_(value);
|
|
335
|
+
}
|
|
336
|
+
#define BROTLI_BSWAP32_(V) ( \
|
|
337
|
+
(((V) & 0xFFU) << 24) | (((V) & 0xFF00U) << 8) | \
|
|
338
|
+
(((V) >> 8) & 0xFF00U) | (((V) >> 24) & 0xFFU))
|
|
339
|
+
static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
|
|
340
|
+
uint32_t value = BrotliUnalignedRead32(p);
|
|
341
|
+
return BROTLI_BSWAP32_(value);
|
|
342
|
+
}
|
|
343
|
+
#define BROTLI_BSWAP64_(V) ( \
|
|
344
|
+
(((V) & 0xFFU) << 56) | (((V) & 0xFF00U) << 40) | \
|
|
345
|
+
(((V) & 0xFF0000U) << 24) | (((V) & 0xFF000000U) << 8) | \
|
|
346
|
+
(((V) >> 8) & 0xFF000000U) | (((V) >> 24) & 0xFF0000U) | \
|
|
347
|
+
(((V) >> 40) & 0xFF00U) | (((V) >> 56) & 0xFFU))
|
|
348
|
+
static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
|
|
349
|
+
uint64_t value = BrotliUnalignedRead64(p);
|
|
350
|
+
return BROTLI_BSWAP64_(value);
|
|
351
|
+
}
|
|
352
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
353
|
+
uint64_t value = BROTLI_BSWAP64_(v);
|
|
354
|
+
BrotliUnalignedWrite64(p, value);
|
|
355
|
+
}
|
|
356
|
+
#else /* BROTLI_LITTLE_ENDIAN */
|
|
357
|
+
/* Read / store values byte-wise; hopefully compiler will understand. */
|
|
358
|
+
static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
|
|
359
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
360
|
+
return (uint16_t)(in[0] | (in[1] << 8));
|
|
361
|
+
}
|
|
362
|
+
static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
|
|
363
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
364
|
+
uint32_t value = (uint32_t)(in[0]);
|
|
365
|
+
value |= (uint32_t)(in[1]) << 8;
|
|
366
|
+
value |= (uint32_t)(in[2]) << 16;
|
|
367
|
+
value |= (uint32_t)(in[3]) << 24;
|
|
368
|
+
return value;
|
|
369
|
+
}
|
|
370
|
+
static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
|
|
371
|
+
const uint8_t* in = (const uint8_t*)p;
|
|
372
|
+
uint64_t value = (uint64_t)(in[0]);
|
|
373
|
+
value |= (uint64_t)(in[1]) << 8;
|
|
374
|
+
value |= (uint64_t)(in[2]) << 16;
|
|
375
|
+
value |= (uint64_t)(in[3]) << 24;
|
|
376
|
+
value |= (uint64_t)(in[4]) << 32;
|
|
377
|
+
value |= (uint64_t)(in[5]) << 40;
|
|
378
|
+
value |= (uint64_t)(in[6]) << 48;
|
|
379
|
+
value |= (uint64_t)(in[7]) << 56;
|
|
380
|
+
return value;
|
|
381
|
+
}
|
|
382
|
+
static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
|
|
383
|
+
uint8_t* out = (uint8_t*)p;
|
|
384
|
+
out[0] = (uint8_t)v;
|
|
385
|
+
out[1] = (uint8_t)(v >> 8);
|
|
386
|
+
out[2] = (uint8_t)(v >> 16);
|
|
387
|
+
out[3] = (uint8_t)(v >> 24);
|
|
388
|
+
out[4] = (uint8_t)(v >> 32);
|
|
389
|
+
out[5] = (uint8_t)(v >> 40);
|
|
390
|
+
out[6] = (uint8_t)(v >> 48);
|
|
391
|
+
out[7] = (uint8_t)(v >> 56);
|
|
392
|
+
}
|
|
393
|
+
#endif /* BROTLI_LITTLE_ENDIAN */
|
|
394
|
+
|
|
395
|
+
/* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */
|
|
396
|
+
#if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \
|
|
397
|
+
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
|
398
|
+
#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
|
|
399
|
+
#else
|
|
400
|
+
#define BROTLI_IS_CONSTANT(x) (!!0)
|
|
401
|
+
#endif
|
|
402
|
+
|
|
403
|
+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
|
|
404
|
+
#define BROTLI_HAS_UBFX (!!1)
|
|
405
|
+
#else
|
|
406
|
+
#define BROTLI_HAS_UBFX (!!0)
|
|
407
|
+
#endif
|
|
408
|
+
|
|
409
|
+
#if defined(BROTLI_ENABLE_LOG)
|
|
410
|
+
#define BROTLI_DCHECK(x) assert(x)
|
|
411
|
+
#define BROTLI_LOG(x) printf x
|
|
412
|
+
#else
|
|
413
|
+
#define BROTLI_DCHECK(x)
|
|
414
|
+
#define BROTLI_LOG(x)
|
|
415
|
+
#endif
|
|
416
|
+
|
|
417
|
+
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
|
|
418
|
+
static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
|
|
419
|
+
fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
|
|
420
|
+
fflush(stderr);
|
|
421
|
+
}
|
|
422
|
+
#define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__)
|
|
423
|
+
#else
|
|
424
|
+
#define BROTLI_DUMP() (void)(0)
|
|
425
|
+
#endif
|
|
426
|
+
|
|
427
|
+
/* TODO: add appropriate icc/sunpro/arm/ibm/ti checks. */
|
|
428
|
+
#if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
|
|
429
|
+
!defined(BROTLI_BUILD_NO_RBIT)
|
|
430
|
+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
|
|
431
|
+
/* TODO: detect ARMv6T2 and enable this code for it. */
|
|
432
|
+
static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
|
|
433
|
+
brotli_reg_t output;
|
|
434
|
+
__asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
|
|
435
|
+
return output;
|
|
436
|
+
}
|
|
437
|
+
#define BROTLI_RBIT(x) BrotliRBit(x)
|
|
438
|
+
#endif /* armv7 / armv8 */
|
|
439
|
+
#endif /* gcc || clang */
|
|
440
|
+
#if !defined(BROTLI_RBIT)
|
|
441
|
+
static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }
|
|
442
|
+
#endif /* BROTLI_RBIT */
|
|
443
|
+
|
|
444
|
+
#define BROTLI_REPEAT(N, X) { \
|
|
445
|
+
if ((N & 1) != 0) {X;} \
|
|
446
|
+
if ((N & 2) != 0) {X; X;} \
|
|
447
|
+
if ((N & 4) != 0) {X; X; X; X;} \
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
#define BROTLI_UNUSED(X) (void)(X)
|
|
451
|
+
|
|
452
|
+
#define BROTLI_MIN_MAX(T) \
|
|
453
|
+
static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \
|
|
454
|
+
static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; }
|
|
455
|
+
BROTLI_MIN_MAX(double) BROTLI_MIN_MAX(float) BROTLI_MIN_MAX(int)
|
|
456
|
+
BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
|
|
457
|
+
#undef BROTLI_MIN_MAX
|
|
458
|
+
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
|
|
459
|
+
#define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B)))
|
|
460
|
+
|
|
461
|
+
#define BROTLI_SWAP(T, A, I, J) { \
|
|
462
|
+
T __brotli_swap_tmp = (A)[(I)]; \
|
|
463
|
+
(A)[(I)] = (A)[(J)]; \
|
|
464
|
+
(A)[(J)] = __brotli_swap_tmp; \
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/* Default brotli_alloc_func */
|
|
468
|
+
static void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
|
|
469
|
+
BROTLI_UNUSED(opaque);
|
|
470
|
+
return malloc(size);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/* Default brotli_free_func */
|
|
474
|
+
static void BrotliDefaultFreeFunc(void* opaque, void* address) {
|
|
475
|
+
BROTLI_UNUSED(opaque);
|
|
476
|
+
free(address);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
|
|
480
|
+
BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
|
|
481
|
+
BROTLI_UNUSED(&BrotliUnalignedRead16);
|
|
482
|
+
BROTLI_UNUSED(&BrotliUnalignedRead32);
|
|
483
|
+
BROTLI_UNUSED(&BrotliUnalignedRead64);
|
|
484
|
+
BROTLI_UNUSED(&BrotliUnalignedWrite64);
|
|
485
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
|
|
486
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
|
|
487
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
|
|
488
|
+
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
|
|
489
|
+
BROTLI_UNUSED(&BrotliRBit);
|
|
490
|
+
BROTLI_UNUSED(&brotli_min_double);
|
|
491
|
+
BROTLI_UNUSED(&brotli_max_double);
|
|
492
|
+
BROTLI_UNUSED(&brotli_min_float);
|
|
493
|
+
BROTLI_UNUSED(&brotli_max_float);
|
|
494
|
+
BROTLI_UNUSED(&brotli_min_int);
|
|
495
|
+
BROTLI_UNUSED(&brotli_max_int);
|
|
496
|
+
BROTLI_UNUSED(&brotli_min_size_t);
|
|
497
|
+
BROTLI_UNUSED(&brotli_max_size_t);
|
|
498
|
+
BROTLI_UNUSED(&brotli_min_uint32_t);
|
|
499
|
+
BROTLI_UNUSED(&brotli_max_uint32_t);
|
|
500
|
+
BROTLI_UNUSED(&brotli_min_uint8_t);
|
|
501
|
+
BROTLI_UNUSED(&brotli_max_uint8_t);
|
|
502
|
+
BROTLI_UNUSED(&BrotliDefaultAllocFunc);
|
|
503
|
+
BROTLI_UNUSED(&BrotliDefaultFreeFunc);
|
|
504
|
+
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
|
|
505
|
+
BROTLI_UNUSED(&BrotliDump);
|
|
506
|
+
#endif
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
#endif /* BROTLI_COMMON_PLATFORM_H_ */
|