Debian Codegraph @

c/enc/brotli_bit_stream.c

raw symbols SCIP
1 /* Copyright 2014 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 /* Brotli bit stream functions to support the low level format. There are no
8 compression algorithms here, just the right ordering of bits to match the
9 specs. */
10
11 #include "brotli_bit_stream.h"cxx . . $ `<file>/c/enc/brotli_bit_stream.h`/
12
13 #include "../common/constants.h"cxx . . $ `<file>/c/common/constants.h`/
14 #include "../common/context.h"cxx . . $ `<file>/c/common/context.h`/
15 #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/
16 #include "entropy_encode.h"cxx . . $ `<file>/c/enc/entropy_encode.h`/
17 #include "entropy_encode_static.h"cxx . . $ `<file>/c/enc/entropy_encode_static.h`/
18 #include "fast_log.h"cxx . . $ `<file>/c/enc/fast_log.h`/
19 #include "histogram.h"cxx . . $ `<file>/c/enc/histogram.h`/
20 #include "memory.h"cxx . . $ `<file>/c/enc/memory.h`/
21 #include "write_bits.h"cxx . . $ `<file>/c/enc/write_bits.h`/
22
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26
27 #define MAX_HUFFMAN_TREE_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:27:9`! (2 * BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`! + 1)
28 /* The maximum size of Huffman dictionary for distances assuming that
29 NPOSTFIX = 0 and NDIRECT = 0. */
30 #define MAX_SIMPLE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:30:9`! \
31 BROTLI_DISTANCE_ALPHABET_SIZEcxx . . $ `c/common/constants.h:67:9`!(0, 0, BROTLI_LARGE_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:48:9`!)
32 /* MAX_SIMPLE_DISTANCE_ALPHABET_SIZE == 140 */
33
34 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# BlockLengthPrefixCodecxx . . $ BlockLengthPrefixCode(2141b656ce2cc063).(uint32_tcxx . . $ uint32_t# len) {
35 uint32_tcxx . . $ uint32_t# code = (len >= 177) ? (len >= 753 ? 20 : 14) : (len >= 41 ? 7 : 0);
36 while (code < (BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`! - 1) &&
37 len >= _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[code + 1].offsetcxx . . $ $anonymous_type_f7176a257296a212_0#offset.) ++code;
38 return code;
39 }
40
41 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void GetBlockLengthPrefixCodecxx . . $ GetBlockLengthPrefixCode(50af972b7d743ab5).(uint32_tcxx . . $ uint32_t# len, size_t* code,
42 uint32_tcxx . . $ uint32_t#* n_extra, uint32_tcxx . . $ uint32_t#* extra) {
43 *code = BlockLengthPrefixCodecxx . . $ BlockLengthPrefixCode(2141b656ce2cc063).(len);
44 *n_extra = _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[*code].nbitscxx . . $ $anonymous_type_f7176a257296a212_0#nbits.;
45 *extra = len - _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[*code].offsetcxx . . $ $anonymous_type_f7176a257296a212_0#offset.;
46 }
47
48 typedef struct BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator# {
49 size_t last_typecxx . . $ BlockTypeCodeCalculator#last_type.;
50 size_t second_last_typecxx . . $ BlockTypeCodeCalculator#second_last_type.;
51 } BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator#;
52
53 static void InitBlockTypeCodeCalculatorcxx . . $ InitBlockTypeCodeCalculator(cab22f242aa0660).(BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator#* self) {
54 self->last_typecxx . . $ BlockTypeCodeCalculator#last_type. = 1;
55 self->second_last_typecxx . . $ BlockTypeCodeCalculator#second_last_type. = 0;
56 }
57
58 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t NextBlockTypeCodecxx . . $ NextBlockTypeCode(34f86ba8900bec54).(
59 BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator#* calculator, uint8_tcxx . . $ uint8_t# type) {
60 size_t type_code = (type == calculator->last_typecxx . . $ BlockTypeCodeCalculator#last_type. + 1) ? 1u :
61 (type == calculator->second_last_typecxx . . $ BlockTypeCodeCalculator#second_last_type.) ? 0u : type + 2u;
62 calculator->second_last_typecxx . . $ BlockTypeCodeCalculator#second_last_type. = calculator->last_typecxx . . $ BlockTypeCodeCalculator#last_type.;
63 calculator->last_typecxx . . $ BlockTypeCodeCalculator#last_type. = type;
64 return type_code;
65 }
66
67 /* |nibblesbits| represents the 2 bits to encode MNIBBLES (0-3)
68 REQUIRES: length > 0
69 REQUIRES: length <= (1 << 24) */
70 static void BrotliEncodeMlencxx . . $ BrotliEncodeMlen(eaa97de415f5906b).(size_t length, uint64_tcxx . . $ uint64_t#* bits,
71 size_t* numbits, uint64_tcxx . . $ uint64_t#* nibblesbits) {
72 size_t lg = (length == 1) ? 1 : Log2FloorNonZerocxx . . $ Log2FloorNonZero(ea88b852781e8a38).((uint32_tcxx . . $ uint32_t#)(length - 1)) + 1;
73 size_t mnibbles = (lg < 16 ? 16 : (lg + 3)) / 4;
74 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(length > 0);
75 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(length <= (1 << 24));
76 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(lg <= 24);
77 *nibblesbits = mnibbles - 4;
78 *numbits = mnibbles * 4;
79 *bits = length - 1;
80 }
81
82 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void StoreCommandExtracxx . . $ StoreCommandExtra(a760e33fec257342).(
83 const Commandcxx . . $ Command#* cmd, size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
84 uint32_tcxx . . $ uint32_t# copylen_code = CommandCopyLenCodecxx . . $ CommandCopyLenCode(4be527375b26559e).(cmd);
85 uint16_tcxx . . $ uint16_t# inscode = GetInsertLengthCodecxx . . $ GetInsertLengthCode(91f8ed6d6bcecca7).(cmd->insert_len_cxx . . $ Command#insert_len_.);
86 uint16_tcxx . . $ uint16_t# copycode = GetCopyLengthCodecxx . . $ GetCopyLengthCode(91f8ed6d6bcecca7).(copylen_code);
87 uint32_tcxx . . $ uint32_t# insnumextra = GetInsertExtracxx . . $ GetInsertExtra(909d59720f161188).(inscode);
88 uint64_tcxx . . $ uint64_t# insextraval = cmd->insert_len_cxx . . $ Command#insert_len_. - GetInsertBasecxx . . $ GetInsertBase(909d59720f161188).(inscode);
89 uint64_tcxx . . $ uint64_t# copyextraval = copylen_code - GetCopyBasecxx . . $ GetCopyBase(909d59720f161188).(copycode);
90 uint64_tcxx . . $ uint64_t# bits = (copyextraval << insnumextra) | insextraval;
91 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(
92 insnumextra + GetCopyExtracxx . . $ GetCopyExtra(909d59720f161188).(copycode), bits, storage_ix, storage);
93 }
94
95 /* Data structure that stores almost everything that is needed to encode each
96 block switch command. */
97 typedef struct BlockSplitCodecxx . . $ BlockSplitCode# {
98 BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator# type_code_calculatorcxx . . $ BlockSplitCode#type_code_calculator.;
99 uint8_tcxx . . $ uint8_t# type_depthscxx . . $ BlockSplitCode#type_depths.[BROTLI_MAX_BLOCK_TYPE_SYMBOLScxx . . $ `c/common/constants.h:29:9`!];
100 uint16_tcxx . . $ uint16_t# type_bitscxx . . $ BlockSplitCode#type_bits.[BROTLI_MAX_BLOCK_TYPE_SYMBOLScxx . . $ `c/common/constants.h:29:9`!];
101 uint8_tcxx . . $ uint8_t# length_depthscxx . . $ BlockSplitCode#length_depths.[BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!];
102 uint16_tcxx . . $ uint16_t# length_bitscxx . . $ BlockSplitCode#length_bits.[BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!];
103 } BlockSplitCodecxx . . $ BlockSplitCode#;
104
105 /* Stores a number between 0 and 255. */
106 static void StoreVarLenUint8cxx . . $ StoreVarLenUint8(b231ae860d85642).(size_t n, size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
107 if (n == 0) {
108 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 0, storage_ix, storage);
109 } else {
110 size_t nbits = Log2FloorNonZerocxx . . $ Log2FloorNonZero(ea88b852781e8a38).(n);
111 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage);
112 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(3, nbits, storage_ix, storage);
113 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(nbits, n - ((size_t)1 << nbits), storage_ix, storage);
114 }
115 }
116
117 /* Stores the compressed meta-block header.
118 REQUIRES: length > 0
119 REQUIRES: length <= (1 << 24) */
120 static void StoreCompressedMetaBlockHeadercxx . . $ StoreCompressedMetaBlockHeader(d9f88ecf16342029).(BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_final_block,
121 size_t length,
122 size_t* storage_ix,
123 uint8_tcxx . . $ uint8_t#* storage) {
124 uint64_tcxx . . $ uint64_t# lenbits;
125 size_t nlenbits;
126 uint64_tcxx . . $ uint64_t# nibblesbits;
127
128 /* Write ISLAST bit. */
129 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, (uint64_tcxx . . $ uint64_t#)is_final_block, storage_ix, storage);
130 /* Write ISEMPTY bit. */
131 if (is_final_block) {
132 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 0, storage_ix, storage);
133 }
134
135 BrotliEncodeMlencxx . . $ BrotliEncodeMlen(eaa97de415f5906b).(length, &lenbits, &nlenbits, &nibblesbits);
136 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, nibblesbits, storage_ix, storage);
137 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(nlenbits, lenbits, storage_ix, storage);
138
139 if (!is_final_block) {
140 /* Write ISUNCOMPRESSED bit. */
141 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 0, storage_ix, storage);
142 }
143 }
144
145 /* Stores the uncompressed meta-block header.
146 REQUIRES: length > 0
147 REQUIRES: length <= (1 << 24) */
148 static void BrotliStoreUncompressedMetaBlockHeadercxx . . $ BrotliStoreUncompressedMetaBlockHeader(b231ae860d85642).(size_t length,
149 size_t* storage_ix,
150 uint8_tcxx . . $ uint8_t#* storage) {
151 uint64_tcxx . . $ uint64_t# lenbits;
152 size_t nlenbits;
153 uint64_tcxx . . $ uint64_t# nibblesbits;
154
155 /* Write ISLAST bit.
156 Uncompressed block cannot be the last one, so set to 0. */
157 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 0, storage_ix, storage);
158 BrotliEncodeMlencxx . . $ BrotliEncodeMlen(eaa97de415f5906b).(length, &lenbits, &nlenbits, &nibblesbits);
159 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, nibblesbits, storage_ix, storage);
160 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(nlenbits, lenbits, storage_ix, storage);
161 /* Write ISUNCOMPRESSED bit. */
162 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage);
163 }
164
165 static void BrotliStoreHuffmanTreeOfHuffmanTreeToBitMaskcxx . . $ BrotliStoreHuffmanTreeOfHuffmanTreeToBitMask(f34768f3c7f08db8).(
166 const int num_codes, const uint8_tcxx . . $ uint8_t#* code_length_bitdepth,
167 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
168 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
169 uint8_tcxx . . $ uint8_t# kStorageOrder[BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!] = {
170 1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15
171 };
172 /* The bit lengths of the Huffman code over the code length alphabet
173 are compressed with the following static Huffman code:
174 Symbol Code
175 ------ ----
176 0 00
177 1 1110
178 2 110
179 3 01
180 4 10
181 5 1111 */
182 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
183 uint8_tcxx . . $ uint8_t# kHuffmanBitLengthHuffmanCodeSymbols[6] = {
184 0, 7, 3, 2, 1, 15
185 };
186 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
187 uint8_tcxx . . $ uint8_t# kHuffmanBitLengthHuffmanCodeBitLengths[6] = {
188 2, 4, 3, 2, 2, 4
189 };
190
191 size_t skip_some = 0; /* skips none. */
192
193 /* Throw away trailing zeros: */
194 size_t codes_to_store = BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!;
195 if (num_codes > 1) {
196 for (; codes_to_store > 0; --codes_to_store) {
197 if (code_length_bitdepth[kStorageOrder[codes_to_store - 1]] != 0) {
198 break;
199 }
200 }
201 }
202 if (code_length_bitdepth[kStorageOrder[0]] == 0 &&
203 code_length_bitdepth[kStorageOrder[1]] == 0) {
204 skip_some = 2; /* skips two. */
205 if (code_length_bitdepth[kStorageOrder[2]] == 0) {
206 skip_some = 3; /* skips three. */
207 }
208 }
209 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, skip_some, storage_ix, storage);
210 {
211 size_t i;
212 for (i = skip_some; i < codes_to_store; ++i) {
213 size_t l = code_length_bitdepth[kStorageOrder[i]];
214 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(kHuffmanBitLengthHuffmanCodeBitLengths[l],
215 kHuffmanBitLengthHuffmanCodeSymbols[l], storage_ix, storage);
216 }
217 }
218 }
219
220 static void BrotliStoreHuffmanTreeToBitMaskcxx . . $ BrotliStoreHuffmanTreeToBitMask(80b2e8abb1ded6d9).(
221 const size_t huffman_tree_size, const uint8_tcxx . . $ uint8_t#* huffman_tree,
222 const uint8_tcxx . . $ uint8_t#* huffman_tree_extra_bits, const uint8_tcxx . . $ uint8_t#* code_length_bitdepth,
223 const uint16_tcxx . . $ uint16_t#* code_length_bitdepth_symbols,
224 size_t* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! storage_ix, uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! storage) {
225 size_t i;
226 for (i = 0; i < huffman_tree_size; ++i) {
227 size_t ix = huffman_tree[i];
228 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(code_length_bitdepth[ix], code_length_bitdepth_symbols[ix],
229 storage_ix, storage);
230 /* Extra bits */
231 switch (ix) {
232 case BROTLI_REPEAT_PREVIOUS_CODE_LENGTHcxx . . $ `c/common/constants.h:32:9`!:
233 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, huffman_tree_extra_bits[i], storage_ix, storage);
234 break;
235 case BROTLI_REPEAT_ZERO_CODE_LENGTHcxx . . $ `c/common/constants.h:33:9`!:
236 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(3, huffman_tree_extra_bits[i], storage_ix, storage);
237 break;
238 }
239 }
240 }
241
242 static void StoreSimpleHuffmanTreecxx . . $ StoreSimpleHuffmanTree(2a52ca3e8f0fb285).(const uint8_tcxx . . $ uint8_t#* depths,
243 size_t symbols[4],
244 size_t num_symbols,
245 size_t max_bits,
246 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
247 /* value of 1 indicates a simple Huffman code */
248 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, 1, storage_ix, storage);
249 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, num_symbols - 1, storage_ix, storage); /* NSYM - 1 */
250
251 {
252 /* Sort */
253 size_t i;
254 for (i = 0; i < num_symbols; i++) {
255 size_t j;
256 for (j = i + 1; j < num_symbols; j++) {
257 if (depths[symbols[j]] < depths[symbols[i]]) {
258 BROTLI_SWAPcxx . . $ `c/common/platform.h:525:9`!(size_t, symbols, j, i);
259 }
260 }
261 }
262 }
263
264 if (num_symbols == 2) {
265 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
266 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
267 } else if (num_symbols == 3) {
268 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
269 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
270 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[2], storage_ix, storage);
271 } else {
272 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
273 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
274 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[2], storage_ix, storage);
275 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[3], storage_ix, storage);
276 /* tree-select */
277 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, depths[symbols[0]] == 1 ? 1 : 0, storage_ix, storage);
278 }
279 }
280
281 /* num = alphabet size
282 depths = symbol depths */
283 void BrotliStoreHuffmanTreecxx . . $ BrotliStoreHuffmanTree(1323badeb1d66257).(const uint8_tcxx . . $ uint8_t#* depths, size_t num,
284 HuffmanTreecxx . . $ HuffmanTree#* tree,
285 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
286 /* Write the Huffman tree into the brotli-representation.
287 The command alphabet is the largest, so this allocation will fit all
288 alphabets. */
289 /* TODO(eustas): fix me */
290 uint8_tcxx . . $ uint8_t# huffman_tree[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!];
291 uint8_tcxx . . $ uint8_t# huffman_tree_extra_bits[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!];
292 size_t huffman_tree_size = 0;
293 uint8_tcxx . . $ uint8_t# code_length_bitdepth[BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!] = { 0 };
294 uint16_tcxx . . $ uint16_t# code_length_bitdepth_symbols[BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!];
295 uint32_tcxx . . $ uint32_t# huffman_tree_histogram[BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!] = { 0 };
296 size_t i;
297 int num_codes = 0;
298 size_t code = 0;
299
300 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(num <= BROTLI_NUM_COMMAND_SYMBOLS);
301
302 BrotliWriteHuffmanTreecxx . . $ BrotliWriteHuffmanTree(33fe0f2ae1daff41).(depths, num, &huffman_tree_size, huffman_tree,
303 huffman_tree_extra_bits);
304
305 /* Calculate the statistics of the Huffman tree in brotli-representation. */
306 for (i = 0; i < huffman_tree_size; ++i) {
307 ++huffman_tree_histogram[huffman_tree[i]];
308 }
309
310 for (i = 0; i < BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!; ++i) {
311 if (huffman_tree_histogram[i]) {
312 if (num_codes == 0) {
313 code = i;
314 num_codes = 1;
315 } else if (num_codes == 1) {
316 num_codes = 2;
317 break;
318 }
319 }
320 }
321
322 /* Calculate another Huffman tree to use for compressing both the
323 earlier Huffman tree with. */
324 BrotliCreateHuffmanTreecxx . . $ BrotliCreateHuffmanTree(84acd5421a2fe552).(huffman_tree_histogram, BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!,
325 5, tree, code_length_bitdepth);
326 BrotliConvertBitDepthsToSymbolscxx . . $ BrotliConvertBitDepthsToSymbols(4b6fce73272d3f29).(code_length_bitdepth,
327 BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!,
328 code_length_bitdepth_symbols);
329
330 /* Now, we have all the data, let's start storing it */
331 BrotliStoreHuffmanTreeOfHuffmanTreeToBitMaskcxx . . $ BrotliStoreHuffmanTreeOfHuffmanTreeToBitMask(f34768f3c7f08db8).(num_codes, code_length_bitdepth,
332 storage_ix, storage);
333
334 if (num_codes == 1) {
335 code_length_bitdepth[code] = 0;
336 }
337
338 /* Store the real Huffman tree now. */
339 BrotliStoreHuffmanTreeToBitMaskcxx . . $ BrotliStoreHuffmanTreeToBitMask(80b2e8abb1ded6d9).(huffman_tree_size,
340 huffman_tree,
341 huffman_tree_extra_bits,
342 code_length_bitdepth,
343 code_length_bitdepth_symbols,
344 storage_ix, storage);
345 }
346
347 /* Builds a Huffman tree from histogram[0:length] into depth[0:length] and
348 bits[0:length] and stores the encoded tree to the bit stream. */
349 static void BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(const uint32_tcxx . . $ uint32_t#* histogram,
350 const size_t histogram_length,
351 const size_t alphabet_size,
352 HuffmanTreecxx . . $ HuffmanTree#* tree,
353 uint8_tcxx . . $ uint8_t#* depth,
354 uint16_tcxx . . $ uint16_t#* bits,
355 size_t* storage_ix,
356 uint8_tcxx . . $ uint8_t#* storage) {
357 size_t count = 0;
358 size_t s4[4] = { 0 };
359 size_t i;
360 size_t max_bits = 0;
361 for (i = 0; i < histogram_length; i++) {
362 if (histogram[i]) {
363 if (count < 4) {
364 s4[count] = i;
365 } else if (count > 4) {
366 break;
367 }
368 count++;
369 }
370 }
371
372 {
373 size_t max_bits_counter = alphabet_size - 1;
374 while (max_bits_counter) {
375 max_bits_counter >>= 1;
376 ++max_bits;
377 }
378 }
379
380 if (count <= 1) {
381 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(4, 1, storage_ix, storage);
382 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, s4[0], storage_ix, storage);
383 depth[s4[0]] = 0;
384 bits[s4[0]] = 0;
385 return;
386 }
387
388 memsetcxx . . $ memset(d1de1e4fb215f1c6).(depth, 0, histogram_length * sizeof(depth[0]));
389 BrotliCreateHuffmanTreecxx . . $ BrotliCreateHuffmanTree(84acd5421a2fe552).(histogram, histogram_length, 15, tree, depth);
390 BrotliConvertBitDepthsToSymbolscxx . . $ BrotliConvertBitDepthsToSymbols(4b6fce73272d3f29).(depth, histogram_length, bits);
391
392 if (count <= 4) {
393 StoreSimpleHuffmanTreecxx . . $ StoreSimpleHuffmanTree(2a52ca3e8f0fb285).(depth, s4, count, max_bits, storage_ix, storage);
394 } else {
395 BrotliStoreHuffmanTreecxx . . $ BrotliStoreHuffmanTree(1323badeb1d66257).(depth, histogram_length, tree, storage_ix, storage);
396 }
397 }
398
399 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SortHuffmanTreecxx . . $ SortHuffmanTree(eec631d624de5d70).(
400 const HuffmanTreecxx . . $ HuffmanTree#* v0, const HuffmanTreecxx . . $ HuffmanTree#* v1) {
401 return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(v0->total_count_ < v1->total_count_);
402 }
403
404 void BrotliBuildAndStoreHuffmanTreeFastcxx . . $ BrotliBuildAndStoreHuffmanTreeFast(e26f03fd0cc3b6c2).(HuffmanTreecxx . . $ HuffmanTree#* tree,
405 const uint32_tcxx . . $ uint32_t#* histogram,
406 const size_t histogram_total,
407 const size_t max_bits,
408 uint8_tcxx . . $ uint8_t#* depth, uint16_tcxx . . $ uint16_t#* bits,
409 size_t* storage_ix,
410 uint8_tcxx . . $ uint8_t#* storage) {
411 size_t count = 0;
412 size_t symbols[4] = { 0 };
413 size_t length = 0;
414 size_t total = histogram_total;
415 while (total != 0) {
416 if (histogram[length]) {
417 if (count < 4) {
418 symbols[count] = length;
419 }
420 ++count;
421 total -= histogram[length];
422 }
423 ++length;
424 }
425
426 if (count <= 1) {
427 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(4, 1, storage_ix, storage);
428 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
429 depth[symbols[0]] = 0;
430 bits[symbols[0]] = 0;
431 return;
432 }
433
434 memsetcxx . . $ memset(d1de1e4fb215f1c6).(depth, 0, length * sizeof(depth[0]));
435 {
436 uint32_tcxx . . $ uint32_t# count_limit;
437 for (count_limit = 1; ; count_limit *= 2) {
438 HuffmanTreecxx . . $ HuffmanTree#* node = tree;
439 size_t l;
440 for (l = length; l != 0;) {
441 --l;
442 if (histogram[l]) {
443 if (BROTLI_PREDICT_TRUEcxx . . $ `c/common/platform.h:73:9`!(histogram[l] >= count_limit)) {
444 InitHuffmanTreecxx . . $ InitHuffmanTree(e357aa9f8b4b4544).(node, histogram[l], -1, (int16_tcxx . . $ int16_t#)l);
445 } else {
446 InitHuffmanTreecxx . . $ InitHuffmanTree(e357aa9f8b4b4544).(node, count_limit, -1, (int16_tcxx . . $ int16_t#)l);
447 }
448 ++node;
449 }
450 }
451 {
452 const int n = (int)(node - tree);
453 HuffmanTreecxx . . $ HuffmanTree# sentinel;
454 int i = 0; /* Points to the next leaf node. */
455 int j = n + 1; /* Points to the next non-leaf node. */
456 int k;
457
458 SortHuffmanTreeItemscxx . . $ SortHuffmanTreeItems(391bcd312c3cedbf).(tree, (size_t)n, SortHuffmanTreecxx . . $ SortHuffmanTree(eec631d624de5d70).);
459 /* The nodes are:
460 [0, n): the sorted leaf nodes that we start with.
461 [n]: we add a sentinel here.
462 [n + 1, 2n): new parent nodes are added here, starting from
463 (n+1). These are naturally in ascending order.
464 [2n]: we add a sentinel at the end as well.
465 There will be (2n+1) elements at the end. */
466 InitHuffmanTreecxx . . $ InitHuffmanTree(e357aa9f8b4b4544).(&sentinel, BROTLI_UINT32_MAXcxx . . $ `c/include/brotli/types.h:59:9`!, -1, -1);
467 *node++ = sentinel;
468 *node++ = sentinel;
469
470 for (k = n - 1; k > 0; --k) {
471 int left, right;
472 if (tree[i].total_count_cxx . . $ HuffmanTree#total_count_. <= tree[j].total_count_cxx . . $ HuffmanTree#total_count_.) {
473 left = i;
474 ++i;
475 } else {
476 left = j;
477 ++j;
478 }
479 if (tree[i].total_count_cxx . . $ HuffmanTree#total_count_. <= tree[j].total_count_cxx . . $ HuffmanTree#total_count_.) {
480 right = i;
481 ++i;
482 } else {
483 right = j;
484 ++j;
485 }
486 /* The sentinel node becomes the parent node. */
487 node[-1].total_count_cxx . . $ HuffmanTree#total_count_. =
488 tree[left].total_count_cxx . . $ HuffmanTree#total_count_. + tree[right].total_count_cxx . . $ HuffmanTree#total_count_.;
489 node[-1].index_left_cxx . . $ HuffmanTree#index_left_. = (int16_tcxx . . $ int16_t#)left;
490 node[-1].index_right_or_value_cxx . . $ HuffmanTree#index_right_or_value_. = (int16_tcxx . . $ int16_t#)right;
491 /* Add back the last sentinel node. */
492 *node++ = sentinel;
493 }
494 if (BrotliSetDepthcxx . . $ BrotliSetDepth(ead3c68a25274c25).(2 * n - 1, tree, depth, 14)) {
495 /* We need to pack the Huffman tree in 14 bits. If this was not
496 successful, add fake entities to the lowest values and retry. */
497 break;
498 }
499 }
500 }
501 }
502 BrotliConvertBitDepthsToSymbolscxx . . $ BrotliConvertBitDepthsToSymbols(4b6fce73272d3f29).(depth, length, bits);
503 if (count <= 4) {
504 size_t i;
505 /* value of 1 indicates a simple Huffman code */
506 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, 1, storage_ix, storage);
507 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, count - 1, storage_ix, storage); /* NSYM - 1 */
508
509 /* Sort */
510 for (i = 0; i < count; i++) {
511 size_t j;
512 for (j = i + 1; j < count; j++) {
513 if (depth[symbols[j]] < depth[symbols[i]]) {
514 BROTLI_SWAPcxx . . $ `c/common/platform.h:525:9`!(size_t, symbols, j, i);
515 }
516 }
517 }
518
519 if (count == 2) {
520 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
521 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
522 } else if (count == 3) {
523 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
524 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
525 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[2], storage_ix, storage);
526 } else {
527 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[0], storage_ix, storage);
528 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[1], storage_ix, storage);
529 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[2], storage_ix, storage);
530 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(max_bits, symbols[3], storage_ix, storage);
531 /* tree-select */
532 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, depth[symbols[0]] == 1 ? 1 : 0, storage_ix, storage);
533 }
534 } else {
535 uint8_tcxx . . $ uint8_t# previous_value = 8;
536 size_t i;
537 /* Complex Huffman Tree */
538 StoreStaticCodeLengthCodecxx . . $ StoreStaticCodeLengthCode(9b31538093af6fc3).(storage_ix, storage);
539
540 /* Actual RLE coding. */
541 for (i = 0; i < length;) {
542 const uint8_tcxx . . $ uint8_t# value = depth[i];
543 size_t reps = 1;
544 size_t k;
545 for (k = i + 1; k < length && depth[k] == value; ++k) {
546 ++reps;
547 }
548 i += reps;
549 if (value == 0) {
550 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(kZeroRepsDepthcxx . . $ kZeroRepsDepth.[reps], kZeroRepsBitscxx . . $ kZeroRepsBits.[reps],
551 storage_ix, storage);
552 } else {
553 if (previous_value != value) {
554 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(kCodeLengthDepthcxx . . $ kCodeLengthDepth.[value], kCodeLengthBitscxx . . $ kCodeLengthBits.[value],
555 storage_ix, storage);
556 --reps;
557 }
558 if (reps < 3) {
559 while (reps != 0) {
560 reps--;
561 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(kCodeLengthDepthcxx . . $ kCodeLengthDepth.[value], kCodeLengthBitscxx . . $ kCodeLengthBits.[value],
562 storage_ix, storage);
563 }
564 } else {
565 reps -= 3;
566 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(kNonZeroRepsDepthcxx . . $ kNonZeroRepsDepth.[reps], kNonZeroRepsBitscxx . . $ kNonZeroRepsBits.[reps],
567 storage_ix, storage);
568 }
569 previous_value = value;
570 }
571 }
572 }
573 }
574
575 static size_t IndexOfcxx . . $ IndexOf(783fe6a271b8d539).(const uint8_tcxx . . $ uint8_t#* v, size_t v_size, uint8_tcxx . . $ uint8_t# value) {
576 size_t i = 0;
577 for (; i < v_size; ++i) {
578 if (v[i] == value) return i;
579 }
580 return i;
581 }
582
583 static void MoveToFrontcxx . . $ MoveToFront(6165b45f45ef689c).(uint8_tcxx . . $ uint8_t#* v, size_t index) {
584 uint8_tcxx . . $ uint8_t# value = v[index];
585 size_t i;
586 for (i = index; i != 0; --i) {
587 v[i] = v[i - 1];
588 }
589 v[0] = value;
590 }
591
592 static void MoveToFrontTransformcxx . . $ MoveToFrontTransform(d50db72f8ac3607d).(const uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! v_in,
593 const size_t v_size,
594 uint32_tcxx . . $ uint32_t#* v_out) {
595 size_t i;
596 uint8_tcxx . . $ uint8_t# mtf[256];
597 uint32_tcxx . . $ uint32_t# max_value;
598 if (v_size == 0) {
599 return;
600 }
601 max_value = v_in[0];
602 for (i = 1; i < v_size; ++i) {
603 if (v_in[i] > max_value) max_value = v_in[i];
604 }
605 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(max_value < 256u);
606 for (i = 0; i <= max_value; ++i) {
607 mtf[i] = (uint8_tcxx . . $ uint8_t#)i;
608 }
609 {
610 size_t mtf_size = max_value + 1;
611 for (i = 0; i < v_size; ++i) {
612 size_t index = IndexOfcxx . . $ IndexOf(783fe6a271b8d539).(mtf, mtf_size, (uint8_tcxx . . $ uint8_t#)v_in[i]);
613 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(index < mtf_size);
614 v_out[i] = (uint32_tcxx . . $ uint32_t#)index;
615 MoveToFrontcxx . . $ MoveToFront(6165b45f45ef689c).(mtf, index);
616 }
617 }
618 }
619
620 /* Finds runs of zeros in v[0..in_size) and replaces them with a prefix code of
621 the run length plus extra bits (lower 9 bits is the prefix code and the rest
622 are the extra bits). Non-zero values in v[] are shifted by
623 *max_length_prefix. Will not create prefix codes bigger than the initial
624 value of *max_run_length_prefix. The prefix code of run length L is simply
625 Log2Floor(L) and the number of extra bits is the same as the prefix code. */
626 static void RunLengthCodeZeroscxx . . $ RunLengthCodeZeros(69d620e0636b0923).(const size_t in_size,
627 uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! v, size_t* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! out_size,
628 uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! max_run_length_prefix) {
629 uint32_tcxx . . $ uint32_t# max_reps = 0;
630 size_t i;
631 uint32_tcxx . . $ uint32_t# max_prefix;
632 for (i = 0; i < in_size;) {
633 uint32_tcxx . . $ uint32_t# reps = 0;
634 for (; i < in_size && v[i] != 0; ++i) ;
635 for (; i < in_size && v[i] == 0; ++i) {
636 ++reps;
637 }
638 max_reps = BROTLI_MAXcxx . . $ `c/common/platform.h:523:9`!(uint32_t, reps, max_reps);
639 }
640 max_prefix = max_reps > 0 ? Log2FloorNonZerocxx . . $ Log2FloorNonZero(ea88b852781e8a38).(max_reps) : 0;
641 max_prefix = BROTLI_MINcxx . . $ `c/common/platform.h:522:9`!(uint32_t, max_prefix, *max_run_length_prefix);
642 *max_run_length_prefix = max_prefix;
643 *out_size = 0;
644 for (i = 0; i < in_size;) {
645 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(*out_size <= i);
646 if (v[i] != 0) {
647 v[*out_size] = v[i] + *max_run_length_prefix;
648 ++i;
649 ++(*out_size);
650 } else {
651 uint32_tcxx . . $ uint32_t# reps = 1;
652 size_t k;
653 for (k = i + 1; k < in_size && v[k] == 0; ++k) {
654 ++reps;
655 }
656 i += reps;
657 while (reps != 0) {
658 if (reps < (2u << max_prefix)) {
659 uint32_tcxx . . $ uint32_t# run_length_prefix = Log2FloorNonZerocxx . . $ Log2FloorNonZero(ea88b852781e8a38).(reps);
660 const uint32_tcxx . . $ uint32_t# extra_bits = reps - (1u << run_length_prefix);
661 v[*out_size] = run_length_prefix + (extra_bits << 9);
662 ++(*out_size);
663 break;
664 } else {
665 const uint32_tcxx . . $ uint32_t# extra_bits = (1u << max_prefix) - 1u;
666 v[*out_size] = max_prefix + (extra_bits << 9);
667 reps -= (2u << max_prefix) - 1u;
668 ++(*out_size);
669 }
670 }
671 }
672 }
673 }
674
675 #define SYMBOL_BITScxx . . $ `c/enc/brotli_bit_stream.c:675:9`! 9
676
677 typedef struct EncodeContextMapArenacxx . . $ EncodeContextMapArena# {
678 uint32_tcxx . . $ uint32_t# histogramcxx . . $ EncodeContextMapArena#histogram.[BROTLI_MAX_CONTEXT_MAP_SYMBOLScxx . . $ `c/common/constants.h:27:9`!];
679 uint8_tcxx . . $ uint8_t# depthscxx . . $ EncodeContextMapArena#depths.[BROTLI_MAX_CONTEXT_MAP_SYMBOLScxx . . $ `c/common/constants.h:27:9`!];
680 uint16_tcxx . . $ uint16_t# bitscxx . . $ EncodeContextMapArena#bits.[BROTLI_MAX_CONTEXT_MAP_SYMBOLScxx . . $ `c/common/constants.h:27:9`!];
681 } EncodeContextMapArenacxx . . $ EncodeContextMapArena#;
682
683 static void EncodeContextMapcxx . . $ EncodeContextMap(7f8ae2acc695ffdb).(MemoryManagercxx . . $ MemoryManager#* m,
684 EncodeContextMapArenacxx . . $ EncodeContextMapArena#* arena,
685 const uint32_tcxx . . $ uint32_t#* context_map,
686 size_t context_map_size,
687 size_t num_clusters,
688 HuffmanTreecxx . . $ HuffmanTree#* tree,
689 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
690 size_t i;
691 uint32_tcxx . . $ uint32_t#* rle_symbols;
692 uint32_tcxx . . $ uint32_t# max_run_length_prefix = 6;
693 size_t num_rle_symbols = 0;
694 uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const histogram = arena->histogramcxx . . $ EncodeContextMapArena#histogram.;
695 static const uint32_tcxx . . $ uint32_t# kSymbolMask = (1u << SYMBOL_BITScxx . . $ `c/enc/brotli_bit_stream.c:675:9`!) - 1u;
696 uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const depths = arena->depthscxx . . $ EncodeContextMapArena#depths.;
697 uint16_tcxx . . $ uint16_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const bits = arena->bitscxx . . $ EncodeContextMapArena#bits.;
698
699 StoreVarLenUint8cxx . . $ StoreVarLenUint8(b231ae860d85642).(num_clusters - 1, storage_ix, storage);
700
701 if (num_clusters == 1) {
702 return;
703 }
704
705 rle_symbols = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, uint32_t, context_map_size);
706 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(rle_symbols)) return;
707 MoveToFrontTransformcxx . . $ MoveToFrontTransform(d50db72f8ac3607d).(context_map, context_map_size, rle_symbols);
708 RunLengthCodeZeroscxx . . $ RunLengthCodeZeros(69d620e0636b0923).(context_map_size, rle_symbols,
709 &num_rle_symbols, &max_run_length_prefix);
710 memsetcxx . . $ memset(d1de1e4fb215f1c6).(histogram, 0, sizeof(arena->histogramcxx . . $ EncodeContextMapArena#histogram.));
711 for (i = 0; i < num_rle_symbols; ++i) {
712 ++histogram[rle_symbols[i] & kSymbolMask];
713 }
714 {
715 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! use_rle = TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(max_run_length_prefix > 0);
716 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, (uint64_tcxx . . $ uint64_t#)use_rle, storage_ix, storage);
717 if (use_rle) {
718 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(4, max_run_length_prefix - 1, storage_ix, storage);
719 }
720 }
721 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(histogram, num_clusters + max_run_length_prefix,
722 num_clusters + max_run_length_prefix,
723 tree, depths, bits, storage_ix, storage);
724 for (i = 0; i < num_rle_symbols; ++i) {
725 const uint32_tcxx . . $ uint32_t# rle_symbol = rle_symbols[i] & kSymbolMask;
726 const uint32_tcxx . . $ uint32_t# extra_bits_val = rle_symbols[i] >> SYMBOL_BITScxx . . $ `c/enc/brotli_bit_stream.c:675:9`!;
727 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(depths[rle_symbol], bits[rle_symbol], storage_ix, storage);
728 if (rle_symbol > 0 && rle_symbol <= max_run_length_prefix) {
729 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(rle_symbol, extra_bits_val, storage_ix, storage);
730 }
731 }
732 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage); /* use move-to-front */
733 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, rle_symbols);
734 }
735
736 /* Stores the block switch command with index block_ix to the bit stream. */
737 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void StoreBlockSwitchcxx . . $ StoreBlockSwitch(71e5abf1a65031be).(BlockSplitCodecxx . . $ BlockSplitCode#* code,
738 const uint32_tcxx . . $ uint32_t# block_len,
739 const uint8_tcxx . . $ uint8_t# block_type,
740 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_first_block,
741 size_t* storage_ix,
742 uint8_tcxx . . $ uint8_t#* storage) {
743 size_t typecode = NextBlockTypeCodecxx . . $ NextBlockTypeCode(34f86ba8900bec54).(&code->type_code_calculatorcxx . . $ BlockSplitCode#type_code_calculator., block_type);
744 size_t lencode;
745 uint32_tcxx . . $ uint32_t# len_nextra;
746 uint32_tcxx . . $ uint32_t# len_extra;
747 if (!is_first_block) {
748 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(code->type_depthscxx . . $ BlockSplitCode#type_depths.[typecode], code->type_bitscxx . . $ BlockSplitCode#type_bits.[typecode],
749 storage_ix, storage);
750 }
751 GetBlockLengthPrefixCodecxx . . $ GetBlockLengthPrefixCode(50af972b7d743ab5).(block_len, &lencode, &len_nextra, &len_extra);
752
753 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(code->length_depthscxx . . $ BlockSplitCode#length_depths.[lencode], code->length_bitscxx . . $ BlockSplitCode#length_bits.[lencode],
754 storage_ix, storage);
755 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(len_nextra, len_extra, storage_ix, storage);
756 }
757
758 /* Builds a BlockSplitCode data structure from the block split given by the
759 vector of block types and block lengths and stores it to the bit stream. */
760 static void BuildAndStoreBlockSplitCodecxx . . $ BuildAndStoreBlockSplitCode(a3094c294f34673f).(const uint8_tcxx . . $ uint8_t#* types,
761 const uint32_tcxx . . $ uint32_t#* lengths,
762 const size_t num_blocks,
763 const size_t num_types,
764 HuffmanTreecxx . . $ HuffmanTree#* tree,
765 BlockSplitCodecxx . . $ BlockSplitCode#* code,
766 size_t* storage_ix,
767 uint8_tcxx . . $ uint8_t#* storage) {
768 uint32_tcxx . . $ uint32_t# type_histo[BROTLI_MAX_BLOCK_TYPE_SYMBOLScxx . . $ `c/common/constants.h:29:9`!];
769 uint32_tcxx . . $ uint32_t# length_histo[BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!];
770 size_t i;
771 BlockTypeCodeCalculatorcxx . . $ BlockTypeCodeCalculator# type_code_calculator;
772 memsetcxx . . $ memset(d1de1e4fb215f1c6).(type_histo, 0, (num_types + 2) * sizeof(type_histo[0]));
773 memsetcxx . . $ memset(d1de1e4fb215f1c6).(length_histo, 0, sizeof(length_histo));
774 InitBlockTypeCodeCalculatorcxx . . $ InitBlockTypeCodeCalculator(cab22f242aa0660).(&type_code_calculator);
775 for (i = 0; i < num_blocks; ++i) {
776 size_t type_code = NextBlockTypeCodecxx . . $ NextBlockTypeCode(34f86ba8900bec54).(&type_code_calculator, types[i]);
777 if (i != 0) ++type_histo[type_code];
778 ++length_histo[BlockLengthPrefixCodecxx . . $ BlockLengthPrefixCode(2141b656ce2cc063).(lengths[i])];
779 }
780 StoreVarLenUint8cxx . . $ StoreVarLenUint8(b231ae860d85642).(num_types - 1, storage_ix, storage);
781 if (num_types > 1) { /* TODO(eustas): else? could StoreBlockSwitch occur? */
782 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(&type_histo[0], num_types + 2, num_types + 2, tree,
783 &code->type_depthscxx . . $ BlockSplitCode#type_depths.[0], &code->type_bitscxx . . $ BlockSplitCode#type_bits.[0],
784 storage_ix, storage);
785 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(&length_histo[0], BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!,
786 BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!,
787 tree, &code->length_depthscxx . . $ BlockSplitCode#length_depths.[0],
788 &code->length_bitscxx . . $ BlockSplitCode#length_bits.[0], storage_ix, storage);
789 StoreBlockSwitchcxx . . $ StoreBlockSwitch(71e5abf1a65031be).(code, lengths[0], types[0], 1, storage_ix, storage);
790 }
791 }
792
793 /* Stores a context map where the histogram type is always the block type. */
794 static void StoreTrivialContextMapcxx . . $ StoreTrivialContextMap(dfcabfa809fde42b).(EncodeContextMapArenacxx . . $ EncodeContextMapArena#* arena,
795 size_t num_types,
796 size_t context_bits,
797 HuffmanTreecxx . . $ HuffmanTree#* tree,
798 size_t* storage_ix,
799 uint8_tcxx . . $ uint8_t#* storage) {
800 StoreVarLenUint8cxx . . $ StoreVarLenUint8(b231ae860d85642).(num_types - 1, storage_ix, storage);
801 if (num_types > 1) {
802 size_t repeat_code = context_bits - 1u;
803 size_t repeat_bits = (1u << repeat_code) - 1u;
804 size_t alphabet_size = num_types + repeat_code;
805 uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const histogram = arena->histogramcxx . . $ EncodeContextMapArena#histogram.;
806 uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const depths = arena->depthscxx . . $ EncodeContextMapArena#depths.;
807 uint16_tcxx . . $ uint16_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! const bits = arena->bitscxx . . $ EncodeContextMapArena#bits.;
808 size_t i;
809 memsetcxx . . $ memset(d1de1e4fb215f1c6).(histogram, 0, alphabet_size * sizeof(histogram[0]));
810 /* Write RLEMAX. */
811 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage);
812 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(4, repeat_code - 1, storage_ix, storage);
813 histogram[repeat_code] = (uint32_tcxx . . $ uint32_t#)num_types;
814 histogram[0] = 1;
815 for (i = context_bits; i < alphabet_size; ++i) {
816 histogram[i] = 1;
817 }
818 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(histogram, alphabet_size, alphabet_size,
819 tree, depths, bits, storage_ix, storage);
820 for (i = 0; i < num_types; ++i) {
821 size_t code = (i == 0 ? 0 : i + context_bits - 1);
822 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(depths[code], bits[code], storage_ix, storage);
823 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(
824 depths[repeat_code], bits[repeat_code], storage_ix, storage);
825 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(repeat_code, repeat_bits, storage_ix, storage);
826 }
827 /* Write IMTF (inverse-move-to-front) bit. */
828 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage);
829 }
830 }
831
832 /* Manages the encoding of one block category (literal, command or distance). */
833 typedef struct BlockEncodercxx . . $ BlockEncoder# {
834 size_t histogram_length_cxx . . $ BlockEncoder#histogram_length_.;
835 size_t num_block_types_cxx . . $ BlockEncoder#num_block_types_.;
836 const uint8_tcxx . . $ uint8_t#* block_types_cxx . . $ BlockEncoder#block_types_.; /* Not owned. */
837 const uint32_tcxx . . $ uint32_t#* block_lengths_cxx . . $ BlockEncoder#block_lengths_.; /* Not owned. */
838 size_t num_blocks_cxx . . $ BlockEncoder#num_blocks_.;
839 BlockSplitCodecxx . . $ BlockSplitCode# block_split_code_cxx . . $ BlockEncoder#block_split_code_.;
840 size_t block_ix_cxx . . $ BlockEncoder#block_ix_.;
841 size_t block_len_cxx . . $ BlockEncoder#block_len_.;
842 size_t entropy_ix_cxx . . $ BlockEncoder#entropy_ix_.;
843 uint8_tcxx . . $ uint8_t#* depths_cxx . . $ BlockEncoder#depths_.;
844 uint16_tcxx . . $ uint16_t#* bits_cxx . . $ BlockEncoder#bits_.;
845 } BlockEncodercxx . . $ BlockEncoder#;
846
847 static void InitBlockEncodercxx . . $ InitBlockEncoder(e5d9793940ba882f).(BlockEncodercxx . . $ BlockEncoder#* self, size_t histogram_length,
848 size_t num_block_types, const uint8_tcxx . . $ uint8_t#* block_types,
849 const uint32_tcxx . . $ uint32_t#* block_lengths, const size_t num_blocks) {
850 self->histogram_length_cxx . . $ BlockEncoder#histogram_length_. = histogram_length;
851 self->num_block_types_cxx . . $ BlockEncoder#num_block_types_. = num_block_types;
852 self->block_types_cxx . . $ BlockEncoder#block_types_. = block_types;
853 self->block_lengths_cxx . . $ BlockEncoder#block_lengths_. = block_lengths;
854 self->num_blocks_cxx . . $ BlockEncoder#num_blocks_. = num_blocks;
855 InitBlockTypeCodeCalculatorcxx . . $ InitBlockTypeCodeCalculator(cab22f242aa0660).(&self->block_split_code_cxx . . $ BlockEncoder#block_split_code_..type_code_calculatorcxx . . $ BlockSplitCode#type_code_calculator.);
856 self->block_ix_cxx . . $ BlockEncoder#block_ix_. = 0;
857 self->block_len_cxx . . $ BlockEncoder#block_len_. = num_blocks == 0 ? 0 : block_lengths[0];
858 self->entropy_ix_cxx . . $ BlockEncoder#entropy_ix_. = 0;
859 self->depths_cxx . . $ BlockEncoder#depths_. = 0;
860 self->bits_cxx . . $ BlockEncoder#bits_. = 0;
861 }
862
863 static void CleanupBlockEncodercxx . . $ CleanupBlockEncoder(690ffe88600b21dc).(MemoryManagercxx . . $ MemoryManager#* m, BlockEncodercxx . . $ BlockEncoder#* self) {
864 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, self->depths_);
865 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, self->bits_);
866 }
867
868 /* Creates entropy codes of block lengths and block types and stores them
869 to the bit stream. */
870 static void BuildAndStoreBlockSwitchEntropyCodescxx . . $ BuildAndStoreBlockSwitchEntropyCodes(3189a39a6b33af50).(BlockEncodercxx . . $ BlockEncoder#* self,
871 HuffmanTreecxx . . $ HuffmanTree#* tree, size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
872 BuildAndStoreBlockSplitCodecxx . . $ BuildAndStoreBlockSplitCode(a3094c294f34673f).(self->block_types_cxx . . $ BlockEncoder#block_types_., self->block_lengths_cxx . . $ BlockEncoder#block_lengths_.,
873 self->num_blocks_cxx . . $ BlockEncoder#num_blocks_., self->num_block_types_cxx . . $ BlockEncoder#num_block_types_., tree, &self->block_split_code_cxx . . $ BlockEncoder#block_split_code_.,
874 storage_ix, storage);
875 }
876
877 /* Stores the next symbol with the entropy code of the current block type.
878 Updates the block type and block length at block boundaries. */
879 static void StoreSymbolcxx . . $ StoreSymbol(4931bffe13b6e5f0).(BlockEncodercxx . . $ BlockEncoder#* self, size_t symbol, size_t* storage_ix,
880 uint8_tcxx . . $ uint8_t#* storage) {
881 if (self->block_len_cxx . . $ BlockEncoder#block_len_. == 0) {
882 size_t block_ix = ++self->block_ix_cxx . . $ BlockEncoder#block_ix_.;
883 uint32_tcxx . . $ uint32_t# block_len = self->block_lengths_cxx . . $ BlockEncoder#block_lengths_.[block_ix];
884 uint8_tcxx . . $ uint8_t# block_type = self->block_types_cxx . . $ BlockEncoder#block_types_.[block_ix];
885 self->block_len_cxx . . $ BlockEncoder#block_len_. = block_len;
886 self->entropy_ix_cxx . . $ BlockEncoder#entropy_ix_. = block_type * self->histogram_length_cxx . . $ BlockEncoder#histogram_length_.;
887 StoreBlockSwitchcxx . . $ StoreBlockSwitch(71e5abf1a65031be).(&self->block_split_code_cxx . . $ BlockEncoder#block_split_code_., block_len, block_type, 0,
888 storage_ix, storage);
889 }
890 --self->block_len_cxx . . $ BlockEncoder#block_len_.;
891 {
892 size_t ix = self->entropy_ix_cxx . . $ BlockEncoder#entropy_ix_. + symbol;
893 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(self->depths_cxx . . $ BlockEncoder#depths_.[ix], self->bits_cxx . . $ BlockEncoder#bits_.[ix], storage_ix, storage);
894 }
895 }
896
897 /* Stores the next symbol with the entropy code of the current block type and
898 context value.
899 Updates the block type and block length at block boundaries. */
900 static void StoreSymbolWithContextcxx . . $ StoreSymbolWithContext(8950e3ec9e8be7ea).(BlockEncodercxx . . $ BlockEncoder#* self, size_t symbol,
901 size_t context, const uint32_tcxx . . $ uint32_t#* context_map, size_t* storage_ix,
902 uint8_tcxx . . $ uint8_t#* storage, const size_t context_bits) {
903 if (self->block_len_cxx . . $ BlockEncoder#block_len_. == 0) {
904 size_t block_ix = ++self->block_ix_cxx . . $ BlockEncoder#block_ix_.;
905 uint32_tcxx . . $ uint32_t# block_len = self->block_lengths_cxx . . $ BlockEncoder#block_lengths_.[block_ix];
906 uint8_tcxx . . $ uint8_t# block_type = self->block_types_cxx . . $ BlockEncoder#block_types_.[block_ix];
907 self->block_len_cxx . . $ BlockEncoder#block_len_. = block_len;
908 self->entropy_ix_cxx . . $ BlockEncoder#entropy_ix_. = (size_t)block_type << context_bits;
909 StoreBlockSwitchcxx . . $ StoreBlockSwitch(71e5abf1a65031be).(&self->block_split_code_cxx . . $ BlockEncoder#block_split_code_., block_len, block_type, 0,
910 storage_ix, storage);
911 }
912 --self->block_len_cxx . . $ BlockEncoder#block_len_.;
913 {
914 size_t histo_ix = context_map[self->entropy_ix_cxx . . $ BlockEncoder#entropy_ix_. + context];
915 size_t ix = histo_ix * self->histogram_length_cxx . . $ BlockEncoder#histogram_length_. + symbol;
916 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(self->depths_cxx . . $ BlockEncoder#depths_.[ix], self->bits_cxx . . $ BlockEncoder#bits_.[ix], storage_ix, storage);
917 }
918 }
919
920 #define FNcxx . . $ `c/enc/brotli_bit_stream.c:920:9`!(X) X ## Literal
921 /* NOLINTNEXTLINE(build/include) */
922 #include "block_encoder_inc.h"cxx . . $ `<file>/c/enc/block_encoder_inc.h`/
923 #undef FNcxx . . $ `c/enc/brotli_bit_stream.c:920:9`!
924
925 #define FNcxx . . $ `c/enc/brotli_bit_stream.c:925:9`!(X) X ## Command
926 /* NOLINTNEXTLINE(build/include) */
927 #include "block_encoder_inc.h"cxx . . $ `<file>/c/enc/block_encoder_inc.h`/
928 #undef FNcxx . . $ `c/enc/brotli_bit_stream.c:925:9`!
929
930 #define FNcxx . . $ `c/enc/brotli_bit_stream.c:930:9`!(X) X ## Distance
931 /* NOLINTNEXTLINE(build/include) */
932 #include "block_encoder_inc.h"cxx . . $ `<file>/c/enc/block_encoder_inc.h`/
933 #undef FNcxx . . $ `c/enc/brotli_bit_stream.c:930:9`!
934
935 static void JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
936 *storage_ix = (*storage_ix + 7u) & ~7u;
937 storage[*storage_ix >> 3] = 0;
938 }
939
940 typedef struct StoreMetablockArenacxx . . $ StoreMetablockArena# {
941 BlockEncodercxx . . $ BlockEncoder# literal_enccxx . . $ StoreMetablockArena#literal_enc.;
942 BlockEncodercxx . . $ BlockEncoder# command_enccxx . . $ StoreMetablockArena#command_enc.;
943 BlockEncodercxx . . $ BlockEncoder# distance_enccxx . . $ StoreMetablockArena#distance_enc.;
944 EncodeContextMapArenacxx . . $ EncodeContextMapArena# context_map_arenacxx . . $ StoreMetablockArena#context_map_arena.;
945 } StoreMetablockArenacxx . . $ StoreMetablockArena#;
946
947 void BrotliStoreMetaBlockcxx . . $ BrotliStoreMetaBlock(11e6213aa12964a7).(MemoryManagercxx . . $ MemoryManager#* m,
948 const uint8_tcxx . . $ uint8_t#* input, size_t start_pos, size_t length, size_t mask,
949 uint8_tcxx . . $ uint8_t# prev_byte, uint8_tcxx . . $ uint8_t# prev_byte2, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_last,
950 const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, ContextTypecxx . . $ ContextType# literal_context_mode,
951 const Commandcxx . . $ Command#* commands, size_t n_commands, const MetaBlockSplitcxx . . $ MetaBlockSplit#* mb,
952 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
953
954 size_t pos = start_pos;
955 size_t i;
956 uint32_tcxx . . $ uint32_t# num_distance_symbols = params->distcxx . . $ BrotliEncoderParams#dist..alphabet_size_maxcxx . . $ BrotliDistanceParams#alphabet_size_max.;
957 uint32_tcxx . . $ uint32_t# num_effective_distance_symbols = params->distcxx . . $ BrotliEncoderParams#dist..alphabet_size_limitcxx . . $ BrotliDistanceParams#alphabet_size_limit.;
958 HuffmanTreecxx . . $ HuffmanTree#* tree;
959 ContextLutcxx . . $ ContextLut# literal_context_lut = BROTLI_CONTEXT_LUTcxx . . $ `c/common/context.h:107:9`!(literal_context_mode);
960 StoreMetablockArenacxx . . $ StoreMetablockArena#* arena = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
961 BlockEncodercxx . . $ BlockEncoder#* literal_enc = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
962 BlockEncodercxx . . $ BlockEncoder#* command_enc = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
963 BlockEncodercxx . . $ BlockEncoder#* distance_enc = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
964 const BrotliDistanceParamscxx . . $ BrotliDistanceParams#* dist = &params->distcxx . . $ BrotliEncoderParams#dist.;
965 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(
966 num_effective_distance_symbols <= BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS);
967
968 StoreCompressedMetaBlockHeadercxx . . $ StoreCompressedMetaBlockHeader(d9f88ecf16342029).(is_last, length, storage_ix, storage);
969
970 tree = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, HuffmanTree, MAX_HUFFMAN_TREE_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:27:9`!);
971 arena = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, StoreMetablockArena, 1);
972 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(tree) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(arena)) return;
973 literal_enc = &arena->literal_enccxx . . $ StoreMetablockArena#literal_enc.;
974 command_enc = &arena->command_enccxx . . $ StoreMetablockArena#command_enc.;
975 distance_enc = &arena->distance_enccxx . . $ StoreMetablockArena#distance_enc.;
976 InitBlockEncodercxx . . $ InitBlockEncoder(e5d9793940ba882f).(literal_enc, BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!,
977 mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types., mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..typescxx . . $ BlockSplit#types.,
978 mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..lengthscxx . . $ BlockSplit#lengths., mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_blockscxx . . $ BlockSplit#num_blocks.);
979 InitBlockEncodercxx . . $ InitBlockEncoder(e5d9793940ba882f).(command_enc, BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!,
980 mb->command_splitcxx . . $ MetaBlockSplit#command_split..num_typescxx . . $ BlockSplit#num_types., mb->command_splitcxx . . $ MetaBlockSplit#command_split..typescxx . . $ BlockSplit#types.,
981 mb->command_splitcxx . . $ MetaBlockSplit#command_split..lengthscxx . . $ BlockSplit#lengths., mb->command_splitcxx . . $ MetaBlockSplit#command_split..num_blockscxx . . $ BlockSplit#num_blocks.);
982 InitBlockEncodercxx . . $ InitBlockEncoder(e5d9793940ba882f).(distance_enc, num_effective_distance_symbols,
983 mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..num_typescxx . . $ BlockSplit#num_types., mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..typescxx . . $ BlockSplit#types.,
984 mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..lengthscxx . . $ BlockSplit#lengths., mb->distance_splitcxx . . $ MetaBlockSplit#distance_split..num_blockscxx . . $ BlockSplit#num_blocks.);
985
986 BuildAndStoreBlockSwitchEntropyCodescxx . . $ BuildAndStoreBlockSwitchEntropyCodes(3189a39a6b33af50).(literal_enc, tree, storage_ix, storage);
987 BuildAndStoreBlockSwitchEntropyCodescxx . . $ BuildAndStoreBlockSwitchEntropyCodes(3189a39a6b33af50).(command_enc, tree, storage_ix, storage);
988 BuildAndStoreBlockSwitchEntropyCodescxx . . $ BuildAndStoreBlockSwitchEntropyCodes(3189a39a6b33af50).(distance_enc, tree, storage_ix, storage);
989
990 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, dist->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits., storage_ix, storage);
991 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(
992 4, dist->num_direct_distance_codescxx . . $ BrotliDistanceParams#num_direct_distance_codes. >> dist->distance_postfix_bitscxx . . $ BrotliDistanceParams#distance_postfix_bits.,
993 storage_ix, storage);
994 for (i = 0; i < mb->literal_splitcxx . . $ MetaBlockSplit#literal_split..num_typescxx . . $ BlockSplit#num_types.; ++i) {
995 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(2, literal_context_mode, storage_ix, storage);
996 }
997
998 if (mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size. == 0) {
999 StoreTrivialContextMapcxx . . $ StoreTrivialContextMap(dfcabfa809fde42b).(
1000 &arena->context_map_arenacxx . . $ StoreMetablockArena#context_map_arena., mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size.,
1001 BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!, tree, storage_ix, storage);
1002 } else {
1003 EncodeContextMapcxx . . $ EncodeContextMap(7f8ae2acc695ffdb).(m, &arena->context_map_arenacxx . . $ StoreMetablockArena#context_map_arena.,
1004 mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map., mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size.,
1005 mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size., tree, storage_ix, storage);
1006 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return;
1007 }
1008
1009 if (mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size. == 0) {
1010 StoreTrivialContextMapcxx . . $ StoreTrivialContextMap(dfcabfa809fde42b).(
1011 &arena->context_map_arenacxx . . $ StoreMetablockArena#context_map_arena., mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size.,
1012 BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!, tree, storage_ix, storage);
1013 } else {
1014 EncodeContextMapcxx . . $ EncodeContextMap(7f8ae2acc695ffdb).(m, &arena->context_map_arenacxx . . $ StoreMetablockArena#context_map_arena.,
1015 mb->distance_context_mapcxx . . $ MetaBlockSplit#distance_context_map., mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size.,
1016 mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size., tree, storage_ix, storage);
1017 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return;
1018 }
1019
1020 BuildAndStoreEntropyCodesLiteral(m, literal_enc, mb->literal_histogramscxx . . $ MetaBlockSplit#literal_histograms.,
1021 mb->literal_histograms_sizecxx . . $ MetaBlockSplit#literal_histograms_size., BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!, tree,
1022 storage_ix, storage);
1023 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return;
1024 BuildAndStoreEntropyCodesCommandcxx . . $ BuildAndStoreEntropyCodesCommand(b942cb532a249f31).(m, command_enc, mb->command_histogramscxx . . $ MetaBlockSplit#command_histograms.,
1025 mb->command_histograms_sizecxx . . $ MetaBlockSplit#command_histograms_size., BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, tree,
1026 storage_ix, storage);
1027 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return;
1028 BuildAndStoreEntropyCodesDistance(m, distance_enc, mb->distance_histogramscxx . . $ MetaBlockSplit#distance_histograms.,
1029 mb->distance_histograms_sizecxx . . $ MetaBlockSplit#distance_histograms_size., num_distance_symbols, tree,
1030 storage_ix, storage);
1031 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m)) return;
1032 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, tree);
1033
1034 for (i = 0; i < n_commands; ++i) {
1035 const Commandcxx . . $ Command# cmd = commands[i];
1036 size_t cmd_code = cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_.;
1037 StoreSymbolcxx . . $ StoreSymbol(4931bffe13b6e5f0).(command_enc, cmd_code, storage_ix, storage);
1038 StoreCommandExtracxx . . $ StoreCommandExtra(a760e33fec257342).(&cmd, storage_ix, storage);
1039 if (mb->literal_context_map_sizecxx . . $ MetaBlockSplit#literal_context_map_size. == 0) {
1040 size_t j;
1041 for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) {
1042 StoreSymbolcxx . . $ StoreSymbol(4931bffe13b6e5f0).(literal_enc, input[pos & mask], storage_ix, storage);
1043 ++pos;
1044 }
1045 } else {
1046 size_t j;
1047 for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) {
1048 size_t context =
1049 BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(prev_byte, prev_byte2, literal_context_lut);
1050 uint8_tcxx . . $ uint8_t# literal = input[pos & mask];
1051 StoreSymbolWithContextcxx . . $ StoreSymbolWithContext(8950e3ec9e8be7ea).(literal_enc, literal, context,
1052 mb->literal_context_mapcxx . . $ MetaBlockSplit#literal_context_map., storage_ix, storage,
1053 BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!);
1054 prev_byte2 = prev_byte;
1055 prev_byte = literal;
1056 ++pos;
1057 }
1058 }
1059 pos += CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd);
1060 if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd)) {
1061 prev_byte2 = input[(pos - 2) & mask];
1062 prev_byte = input[(pos - 1) & mask];
1063 if (cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) {
1064 size_t dist_code = cmd.dist_prefix_cxx . . $ Command#dist_prefix_. & 0x3FF;
1065 uint32_tcxx . . $ uint32_t# distnumextra = cmd.dist_prefix_cxx . . $ Command#dist_prefix_. >> 10;
1066 uint64_tcxx . . $ uint64_t# distextra = cmd.dist_extra_cxx . . $ Command#dist_extra_.;
1067 if (mb->distance_context_map_sizecxx . . $ MetaBlockSplit#distance_context_map_size. == 0) {
1068 StoreSymbolcxx . . $ StoreSymbol(4931bffe13b6e5f0).(distance_enc, dist_code, storage_ix, storage);
1069 } else {
1070 size_t context = CommandDistanceContextcxx . . $ CommandDistanceContext(4be527375b26559e).(&cmd);
1071 StoreSymbolWithContextcxx . . $ StoreSymbolWithContext(8950e3ec9e8be7ea).(distance_enc, dist_code, context,
1072 mb->distance_context_mapcxx . . $ MetaBlockSplit#distance_context_map., storage_ix, storage,
1073 BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!);
1074 }
1075 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(distnumextra, distextra, storage_ix, storage);
1076 }
1077 }
1078 }
1079 CleanupBlockEncodercxx . . $ CleanupBlockEncoder(690ffe88600b21dc).(m, distance_enc);
1080 CleanupBlockEncodercxx . . $ CleanupBlockEncoder(690ffe88600b21dc).(m, command_enc);
1081 CleanupBlockEncodercxx . . $ CleanupBlockEncoder(690ffe88600b21dc).(m, literal_enc);
1082 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, arena);
1083 if (is_last) {
1084 JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(storage_ix, storage);
1085 }
1086 }
1087
1088 static void BuildHistogramscxx . . $ BuildHistograms(43f7d619c3724f07).(const uint8_tcxx . . $ uint8_t#* input,
1089 size_t start_pos,
1090 size_t mask,
1091 const Commandcxx . . $ Command#* commands,
1092 size_t n_commands,
1093 HistogramLiteral* lit_histo,
1094 HistogramCommandcxx . . $ HistogramCommand#* cmd_histo,
1095 HistogramDistance* dist_histo) {
1096 size_t pos = start_pos;
1097 size_t i;
1098 for (i = 0; i < n_commands; ++i) {
1099 const Commandcxx . . $ Command# cmd = commands[i];
1100 size_t j;
1101 HistogramAddCommandcxx . . $ HistogramAddCommand(88d2326d13a10ae).(cmd_histo, cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_.);
1102 for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) {
1103 HistogramAddLiteral(lit_histo, input[pos & mask]);
1104 ++pos;
1105 }
1106 pos += CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd);
1107 if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd) && cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) {
1108 HistogramAddDistance(dist_histo, cmd.dist_prefix_cxx . . $ Command#dist_prefix_. & 0x3FF);
1109 }
1110 }
1111 }
1112
1113 static void StoreDataWithHuffmanCodescxx . . $ StoreDataWithHuffmanCodes(8eb5a15484fd4870).(const uint8_tcxx . . $ uint8_t#* input,
1114 size_t start_pos,
1115 size_t mask,
1116 const Commandcxx . . $ Command#* commands,
1117 size_t n_commands,
1118 const uint8_tcxx . . $ uint8_t#* lit_depth,
1119 const uint16_tcxx . . $ uint16_t#* lit_bits,
1120 const uint8_tcxx . . $ uint8_t#* cmd_depth,
1121 const uint16_tcxx . . $ uint16_t#* cmd_bits,
1122 const uint8_tcxx . . $ uint8_t#* dist_depth,
1123 const uint16_tcxx . . $ uint16_t#* dist_bits,
1124 size_t* storage_ix,
1125 uint8_tcxx . . $ uint8_t#* storage) {
1126 size_t pos = start_pos;
1127 size_t i;
1128 for (i = 0; i < n_commands; ++i) {
1129 const Commandcxx . . $ Command# cmd = commands[i];
1130 const size_t cmd_code = cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_.;
1131 size_t j;
1132 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(
1133 cmd_depth[cmd_code], cmd_bits[cmd_code], storage_ix, storage);
1134 StoreCommandExtracxx . . $ StoreCommandExtra(a760e33fec257342).(&cmd, storage_ix, storage);
1135 for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) {
1136 const uint8_tcxx . . $ uint8_t# literal = input[pos & mask];
1137 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(
1138 lit_depth[literal], lit_bits[literal], storage_ix, storage);
1139 ++pos;
1140 }
1141 pos += CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd);
1142 if (CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd) && cmd.cmd_prefix_cxx . . $ Command#cmd_prefix_. >= 128) {
1143 const size_t dist_code = cmd.dist_prefix_cxx . . $ Command#dist_prefix_. & 0x3FF;
1144 const uint32_tcxx . . $ uint32_t# distnumextra = cmd.dist_prefix_cxx . . $ Command#dist_prefix_. >> 10;
1145 const uint32_tcxx . . $ uint32_t# distextra = cmd.dist_extra_cxx . . $ Command#dist_extra_.;
1146 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(dist_depth[dist_code], dist_bits[dist_code],
1147 storage_ix, storage);
1148 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(distnumextra, distextra, storage_ix, storage);
1149 }
1150 }
1151 }
1152
1153 /* TODO(eustas): pull alloc/dealloc to caller? */
1154 typedef struct MetablockArenacxx . . $ MetablockArena# {
1155 HistogramLiteral lit_histocxx . . $ MetablockArena#lit_histo.;
1156 HistogramCommandcxx . . $ HistogramCommand# cmd_histocxx . . $ MetablockArena#cmd_histo.;
1157 HistogramDistance dist_histocxx . . $ MetablockArena#dist_histo.;
1158 /* TODO(eustas): merge bits and depth? */
1159 uint8_tcxx . . $ uint8_t# lit_depthcxx . . $ MetablockArena#lit_depth.[BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!];
1160 uint16_tcxx . . $ uint16_t# lit_bitscxx . . $ MetablockArena#lit_bits.[BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!];
1161 uint8_tcxx . . $ uint8_t# cmd_depthcxx . . $ MetablockArena#cmd_depth.[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!];
1162 uint16_tcxx . . $ uint16_t# cmd_bitscxx . . $ MetablockArena#cmd_bits.[BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!];
1163 uint8_tcxx . . $ uint8_t# dist_depthcxx . . $ MetablockArena#dist_depth.[MAX_SIMPLE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:30:9`!];
1164 uint16_tcxx . . $ uint16_t# dist_bitscxx . . $ MetablockArena#dist_bits.[MAX_SIMPLE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:30:9`!];
1165 HuffmanTreecxx . . $ HuffmanTree# treecxx . . $ MetablockArena#tree.[MAX_HUFFMAN_TREE_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:27:9`!];
1166 } MetablockArenacxx . . $ MetablockArena#;
1167
1168 void BrotliStoreMetaBlockTrivialcxx . . $ BrotliStoreMetaBlockTrivial(2106f843caf9bd5).(MemoryManagercxx . . $ MemoryManager#* m,
1169 const uint8_tcxx . . $ uint8_t#* input, size_t start_pos, size_t length, size_t mask,
1170 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_last, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params,
1171 const Commandcxx . . $ Command#* commands, size_t n_commands,
1172 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
1173 MetablockArenacxx . . $ MetablockArena#* arena = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, MetablockArena, 1);
1174 uint32_tcxx . . $ uint32_t# num_distance_symbols = params->distcxx . . $ BrotliEncoderParams#dist..alphabet_size_maxcxx . . $ BrotliDistanceParams#alphabet_size_max.;
1175 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(arena)) return;
1176
1177 StoreCompressedMetaBlockHeadercxx . . $ StoreCompressedMetaBlockHeader(d9f88ecf16342029).(is_last, length, storage_ix, storage);
1178
1179 HistogramClearLiteral(&arena->lit_histocxx . . $ MetablockArena#lit_histo.);
1180 HistogramClearCommandcxx . . $ HistogramClearCommand(730c5dcbf8320cd6).(&arena->cmd_histocxx . . $ MetablockArena#cmd_histo.);
1181 HistogramClearDistance(&arena->dist_histocxx . . $ MetablockArena#dist_histo.);
1182
1183 BuildHistogramscxx . . $ BuildHistograms(43f7d619c3724f07).(input, start_pos, mask, commands, n_commands,
1184 &arena->lit_histocxx . . $ MetablockArena#lit_histo., &arena->cmd_histocxx . . $ MetablockArena#cmd_histo., &arena->dist_histocxx . . $ MetablockArena#dist_histo.);
1185
1186 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(13, 0, storage_ix, storage);
1187
1188 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(arena->lit_histocxx . . $ MetablockArena#lit_histo..data_, BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!,
1189 BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!, arena->treecxx . . $ MetablockArena#tree.,
1190 arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1191 storage_ix, storage);
1192 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(arena->cmd_histocxx . . $ MetablockArena#cmd_histo..data_cxx . . $ HistogramCommand#data_., BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!,
1193 BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, arena->treecxx . . $ MetablockArena#tree.,
1194 arena->cmd_depthcxx . . $ MetablockArena#cmd_depth., arena->cmd_bitscxx . . $ MetablockArena#cmd_bits.,
1195 storage_ix, storage);
1196 BuildAndStoreHuffmanTreecxx . . $ BuildAndStoreHuffmanTree(a115412a92217ef9).(arena->dist_histocxx . . $ MetablockArena#dist_histo..data_,
1197 MAX_SIMPLE_DISTANCE_ALPHABET_SIZEcxx . . $ `c/enc/brotli_bit_stream.c:30:9`!,
1198 num_distance_symbols, arena->treecxx . . $ MetablockArena#tree.,
1199 arena->dist_depthcxx . . $ MetablockArena#dist_depth., arena->dist_bitscxx . . $ MetablockArena#dist_bits.,
1200 storage_ix, storage);
1201 StoreDataWithHuffmanCodescxx . . $ StoreDataWithHuffmanCodes(8eb5a15484fd4870).(input, start_pos, mask, commands,
1202 n_commands, arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1203 arena->cmd_depthcxx . . $ MetablockArena#cmd_depth., arena->cmd_bitscxx . . $ MetablockArena#cmd_bits.,
1204 arena->dist_depthcxx . . $ MetablockArena#dist_depth., arena->dist_bitscxx . . $ MetablockArena#dist_bits.,
1205 storage_ix, storage);
1206 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, arena);
1207 if (is_last) {
1208 JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(storage_ix, storage);
1209 }
1210 }
1211
1212 void BrotliStoreMetaBlockFastcxx . . $ BrotliStoreMetaBlockFast(2106f843caf9bd5).(MemoryManagercxx . . $ MemoryManager#* m,
1213 const uint8_tcxx . . $ uint8_t#* input, size_t start_pos, size_t length, size_t mask,
1214 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_last, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params,
1215 const Commandcxx . . $ Command#* commands, size_t n_commands,
1216 size_t* storage_ix, uint8_tcxx . . $ uint8_t#* storage) {
1217 MetablockArenacxx . . $ MetablockArena#* arena = BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(m, MetablockArena, 1);
1218 uint32_tcxx . . $ uint32_t# num_distance_symbols = params->distcxx . . $ BrotliEncoderParams#dist..alphabet_size_maxcxx . . $ BrotliDistanceParams#alphabet_size_max.;
1219 uint32_tcxx . . $ uint32_t# distance_alphabet_bits =
1220 Log2FloorNonZerocxx . . $ Log2FloorNonZero(ea88b852781e8a38).(num_distance_symbols - 1) + 1;
1221 if (BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(m) || BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(arena)) return;
1222
1223 StoreCompressedMetaBlockHeadercxx . . $ StoreCompressedMetaBlockHeader(d9f88ecf16342029).(is_last, length, storage_ix, storage);
1224
1225 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(13, 0, storage_ix, storage);
1226
1227 if (n_commands <= 128) {
1228 uint32_tcxx . . $ uint32_t# histogram[BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!] = { 0 };
1229 size_t pos = start_pos;
1230 size_t num_literals = 0;
1231 size_t i;
1232 for (i = 0; i < n_commands; ++i) {
1233 const Commandcxx . . $ Command# cmd = commands[i];
1234 size_t j;
1235 for (j = cmd.insert_len_cxx . . $ Command#insert_len_.; j != 0; --j) {
1236 ++histogram[input[pos & mask]];
1237 ++pos;
1238 }
1239 num_literals += cmd.insert_len_cxx . . $ Command#insert_len_.;
1240 pos += CommandCopyLencxx . . $ CommandCopyLen(4be527375b26559e).(&cmd);
1241 }
1242 BrotliBuildAndStoreHuffmanTreeFastcxx . . $ BrotliBuildAndStoreHuffmanTreeFast(e26f03fd0cc3b6c2).(arena->treecxx . . $ MetablockArena#tree., histogram, num_literals,
1243 /* max_bits = */ 8,
1244 arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1245 storage_ix, storage);
1246 StoreStaticCommandHuffmanTreecxx . . $ StoreStaticCommandHuffmanTree(9b31538093af6fc3).(storage_ix, storage);
1247 StoreStaticDistanceHuffmanTreecxx . . $ StoreStaticDistanceHuffmanTree(9b31538093af6fc3).(storage_ix, storage);
1248 StoreDataWithHuffmanCodescxx . . $ StoreDataWithHuffmanCodes(8eb5a15484fd4870).(input, start_pos, mask, commands,
1249 n_commands, arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1250 kStaticCommandCodeDepthcxx . . $ kStaticCommandCodeDepth.,
1251 kStaticCommandCodeBitscxx . . $ kStaticCommandCodeBits.,
1252 kStaticDistanceCodeDepthcxx . . $ kStaticDistanceCodeDepth.,
1253 kStaticDistanceCodeBitscxx . . $ kStaticDistanceCodeBits.,
1254 storage_ix, storage);
1255 } else {
1256 HistogramClearLiteral(&arena->lit_histocxx . . $ MetablockArena#lit_histo.);
1257 HistogramClearCommandcxx . . $ HistogramClearCommand(730c5dcbf8320cd6).(&arena->cmd_histocxx . . $ MetablockArena#cmd_histo.);
1258 HistogramClearDistance(&arena->dist_histocxx . . $ MetablockArena#dist_histo.);
1259 BuildHistogramscxx . . $ BuildHistograms(43f7d619c3724f07).(input, start_pos, mask, commands, n_commands,
1260 &arena->lit_histocxx . . $ MetablockArena#lit_histo., &arena->cmd_histocxx . . $ MetablockArena#cmd_histo., &arena->dist_histocxx . . $ MetablockArena#dist_histo.);
1261 BrotliBuildAndStoreHuffmanTreeFastcxx . . $ BrotliBuildAndStoreHuffmanTreeFast(e26f03fd0cc3b6c2).(arena->treecxx . . $ MetablockArena#tree., arena->lit_histocxx . . $ MetablockArena#lit_histo..data_,
1262 arena->lit_histocxx . . $ MetablockArena#lit_histo..total_count_,
1263 /* max_bits = */ 8,
1264 arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1265 storage_ix, storage);
1266 BrotliBuildAndStoreHuffmanTreeFastcxx . . $ BrotliBuildAndStoreHuffmanTreeFast(e26f03fd0cc3b6c2).(arena->treecxx . . $ MetablockArena#tree., arena->cmd_histocxx . . $ MetablockArena#cmd_histo..data_cxx . . $ HistogramCommand#data_.,
1267 arena->cmd_histocxx . . $ MetablockArena#cmd_histo..total_count_cxx . . $ HistogramCommand#total_count_.,
1268 /* max_bits = */ 10,
1269 arena->cmd_depthcxx . . $ MetablockArena#cmd_depth., arena->cmd_bitscxx . . $ MetablockArena#cmd_bits.,
1270 storage_ix, storage);
1271 BrotliBuildAndStoreHuffmanTreeFastcxx . . $ BrotliBuildAndStoreHuffmanTreeFast(e26f03fd0cc3b6c2).(arena->treecxx . . $ MetablockArena#tree., arena->dist_histocxx . . $ MetablockArena#dist_histo..data_,
1272 arena->dist_histocxx . . $ MetablockArena#dist_histo..total_count_,
1273 /* max_bits = */
1274 distance_alphabet_bits,
1275 arena->dist_depthcxx . . $ MetablockArena#dist_depth., arena->dist_bitscxx . . $ MetablockArena#dist_bits.,
1276 storage_ix, storage);
1277 StoreDataWithHuffmanCodescxx . . $ StoreDataWithHuffmanCodes(8eb5a15484fd4870).(input, start_pos, mask, commands,
1278 n_commands, arena->lit_depthcxx . . $ MetablockArena#lit_depth., arena->lit_bitscxx . . $ MetablockArena#lit_bits.,
1279 arena->cmd_depthcxx . . $ MetablockArena#cmd_depth., arena->cmd_bitscxx . . $ MetablockArena#cmd_bits.,
1280 arena->dist_depthcxx . . $ MetablockArena#dist_depth., arena->dist_bitscxx . . $ MetablockArena#dist_bits.,
1281 storage_ix, storage);
1282 }
1283
1284 BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(m, arena);
1285
1286 if (is_last) {
1287 JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(storage_ix, storage);
1288 }
1289 }
1290
1291 /* This is for storing uncompressed blocks (simple raw storage of
1292 bytes-as-bytes). */
1293 void BrotliStoreUncompressedMetaBlockcxx . . $ BrotliStoreUncompressedMetaBlock(caa85e592c9f70c8).(BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! is_final_block,
1294 const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! input,
1295 size_t position, size_t mask,
1296 size_t len,
1297 size_t* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! storage_ix,
1298 uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! storage) {
1299 size_t masked_pos = position & mask;
1300 BrotliStoreUncompressedMetaBlockHeadercxx . . $ BrotliStoreUncompressedMetaBlockHeader(b231ae860d85642).(len, storage_ix, storage);
1301 JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(storage_ix, storage);
1302
1303 if (masked_pos + len > mask + 1) {
1304 size_t len1 = mask + 1 - masked_pos;
1305 memcpycxx . . $ memcpy(cc817cb175f282d).(&storage[*storage_ix >> 3], &input[masked_pos], len1);
1306 *storage_ix += len1 << 3;
1307 len -= len1;
1308 masked_pos = 0;
1309 }
1310 memcpycxx . . $ memcpy(cc817cb175f282d).(&storage[*storage_ix >> 3], &input[masked_pos], len);
1311 *storage_ix += len << 3;
1312
1313 /* We need to clear the next 4 bytes to continue to be
1314 compatible with BrotliWriteBits. */
1315 BrotliWriteBitsPrepareStoragecxx . . $ BrotliWriteBitsPrepareStorage(4bd8c2d29d55dbfc).(*storage_ix, storage);
1316
1317 /* Since the uncompressed block itself may not be the final block, add an
1318 empty one after this. */
1319 if (is_final_block) {
1320 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage); /* islast */
1321 BrotliWriteBitscxx . . $ BrotliWriteBits(f2a8a55e979e8751).(1, 1, storage_ix, storage); /* isempty */
1322 JumpToByteBoundarycxx . . $ JumpToByteBoundary(9b31538093af6fc3).(storage_ix, storage);
1323 }
1324 }
1325
1326 #if defined(BROTLI_TEST)
1327 void BrotliGetBlockLengthPrefixCodeForTest(uint32_t len, size_t* code,
1328 uint32_t* n_extra, uint32_t* extra);
1329 void BrotliGetBlockLengthPrefixCodeForTest(uint32_t len, size_t* code,
1330 uint32_t* n_extra, uint32_t* extra) {
1331 GetBlockLengthPrefixCode(len, code, n_extra, extra);
1332 }
1333 #endif
1334
1335 #if defined(__cplusplus) || defined(c_plusplus)
1336 } /* extern "C" */
1337 #endif