4 * LZX compression routines, originally based on code written by Matthew T.
5 * Russotto (liblzxcomp), but heavily modified.
9 * Copyright (C) 2002 Matthew T. Russotto
10 * Copyright (C) 2012, 2013 Eric Biggers
12 * This file is part of wimlib, a library for working with WIM files.
14 * wimlib is free software; you can redistribute it and/or modify it under the
15 * terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 3 of the License, or (at your option)
19 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
20 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 * A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with wimlib; if not, see http://www.gnu.org/licenses/.
30 * This file provides lzx_compress(), a function to compress an in-memory buffer
31 * of data using LZX compression, as used in the WIM file format.
33 * Please see the comments in lzx-decompress.c for more information about this
36 * One thing to keep in mind is that there is no sliding window, since the
37 * window is always the entirety of a WIM chunk, which is at most WIM_CHUNK_SIZE
40 * The basic compression algorithm used here should be familiar if you are
41 * familiar with Huffman trees and with other LZ77 and Huffman-based formats
42 * such as DEFLATE. Otherwise it can be quite tricky to understand. Basically
43 * it is the following:
45 * - Preprocess the input data (LZX-specific)
46 * - Go through the input data and determine matches. This part is based on
47 * code from zlib, and a hash table of 3-character strings is used to
48 * accelerate the process of finding matches.
49 * - Build the Huffman trees based on the frequencies of symbols determined
50 * while recording matches.
51 * - Output the block header, including the Huffman trees; then output the
52 * compressed stream of matches and literal characters.
54 * It is possible for a WIM chunk to include multiple LZX blocks, since for some
55 * input data this will produce a better compression ratio (especially since
56 * each block can include new Huffman codes). However, producing multiple LZX
57 * blocks from one input chunk is not yet implemented.
66 /* Structure to contain the Huffman codes for the main, length, and aligned
69 u16 main_codewords[LZX_MAINTREE_NUM_SYMBOLS];
70 u8 main_lens[LZX_MAINTREE_NUM_SYMBOLS];
72 u16 len_codewords[LZX_LENTREE_NUM_SYMBOLS];
73 u8 len_lens[LZX_LENTREE_NUM_SYMBOLS];
75 u16 aligned_codewords[LZX_ALIGNEDTREE_NUM_SYMBOLS];
76 u8 aligned_lens[LZX_ALIGNEDTREE_NUM_SYMBOLS];
79 struct lzx_freq_tables {
80 freq_t main_freq_table[LZX_MAINTREE_NUM_SYMBOLS];
81 freq_t len_freq_table[LZX_LENTREE_NUM_SYMBOLS];
82 freq_t aligned_freq_table[LZX_ALIGNEDTREE_NUM_SYMBOLS];
85 /* Returns the LZX position slot that corresponds to a given formatted offset.
87 * Logically, this returns the smallest i such that
88 * formatted_offset >= lzx_position_base[i].
90 * The actual implementation below takes advantage of the regularity of the
91 * numbers in the lzx_position_base array to calculate the slot directly from
92 * the formatted offset without actually looking at the array.
94 static inline unsigned
95 lzx_get_position_slot(unsigned formatted_offset)
99 * Slots 36-49 (formatted_offset >= 262144) can be found by
100 * (formatted_offset/131072) + 34 == (formatted_offset >> 17) + 34;
101 * however, this check for formatted_offset >= 262144 is commented out
102 * because WIM chunks cannot be that large.
104 if (formatted_offset >= 262144) {
105 return (formatted_offset >> 17) + 34;
109 /* Note: this part here only works if:
111 * 2 <= formatted_offset < 655360
113 * It is < 655360 because the frequency of the position bases
114 * increases starting at the 655360 entry, and it is >= 2
115 * because the below calculation fails if the most significant
116 * bit is lower than the 2's place. */
117 wimlib_assert(formatted_offset >= 2 && formatted_offset < 655360);
118 unsigned mssb_idx = bsr32(formatted_offset);
119 return (mssb_idx << 1) |
120 ((formatted_offset >> (mssb_idx - 1)) & 1);
125 lzx_record_literal(u8 literal, void *__main_freq_tab)
127 freq_t *main_freq_tab = __main_freq_tab;
128 main_freq_tab[literal]++;
132 /* Constructs a match from an offset and a length, and updates the LRU queue and
133 * the frequency of symbols in the main, length, and aligned offset alphabets.
134 * The return value is a 32-bit number that provides the match in an
135 * intermediate representation documented below. */
137 lzx_record_match(unsigned match_offset, unsigned match_len,
138 void *__freq_tabs, void *__queue)
140 struct lzx_freq_tables *freq_tabs = __freq_tabs;
141 struct lru_queue *queue = __queue;
142 unsigned position_slot;
143 unsigned position_footer = 0;
148 unsigned adjusted_match_len;
150 wimlib_assert(match_len >= LZX_MIN_MATCH && match_len <= LZX_MAX_MATCH);
151 wimlib_assert(match_offset != 0);
153 /* If possible, encode this offset as a repeated offset. */
154 if (match_offset == queue->R0) {
156 } else if (match_offset == queue->R1) {
157 swap(queue->R0, queue->R1);
159 } else if (match_offset == queue->R2) {
160 swap(queue->R0, queue->R2);
163 /* Not a repeated offset. */
165 /* offsets of 0, 1, and 2 are reserved for the repeated offset
166 * codes, so non-repeated offsets must be encoded as 3+. The
167 * minimum offset is 1, so encode the offsets offset by 2. */
168 unsigned formatted_offset = match_offset + LZX_MIN_MATCH;
170 queue->R2 = queue->R1;
171 queue->R1 = queue->R0;
172 queue->R0 = match_offset;
174 /* The (now-formatted) offset will actually be encoded as a
175 * small position slot number that maps to a certain hard-coded
176 * offset (position base), followed by a number of extra bits---
177 * the position footer--- that are added to the position base to
178 * get the original formatted offset. */
180 position_slot = lzx_get_position_slot(formatted_offset);
181 position_footer = formatted_offset &
182 ((1 << lzx_get_num_extra_bits(position_slot)) - 1);
185 adjusted_match_len = match_len - LZX_MIN_MATCH;
187 /* Pack the position slot, position footer, and match length into an
188 * intermediate representation.
191 * ---- -----------------------------------------------------------
193 * 31 1 if a match, 0 if a literal.
195 * 30-25 position slot. This can be at most 50, so it will fit in 6
198 * 8-24 position footer. This is the offset of the real formatted
199 * offset from the position base. This can be at most 17 bits
200 * (since lzx_extra_bits[LZX_NUM_POSITION_SLOTS - 1] is 17).
202 * 0-7 length of match, offset by 2. This can be at most
203 * (LZX_MAX_MATCH - 2) == 255, so it will fit in 8 bits. */
205 (position_slot << 25) |
206 (position_footer << 8) |
207 (adjusted_match_len);
209 /* The match length must be at least 2, so let the adjusted match length
210 * be the match length minus 2.
212 * If it is less than 7, the adjusted match length is encoded as a 3-bit
213 * number offset by 2. Otherwise, the 3-bit length header is all 1's
214 * and the actual adjusted length is given as a symbol encoded with the
215 * length tree, offset by 7.
217 if (adjusted_match_len < LZX_NUM_PRIMARY_LENS) {
218 len_header = adjusted_match_len;
220 len_header = LZX_NUM_PRIMARY_LENS;
221 len_footer = adjusted_match_len - LZX_NUM_PRIMARY_LENS;
222 freq_tabs->len_freq_table[len_footer]++;
224 len_pos_header = (position_slot << 3) | len_header;
226 wimlib_assert(len_pos_header < LZX_MAINTREE_NUM_SYMBOLS - LZX_NUM_CHARS);
228 freq_tabs->main_freq_table[len_pos_header + LZX_NUM_CHARS]++;
231 * if (lzx_extra_bits[position_slot] >= 3) */
232 if (position_slot >= 8)
233 freq_tabs->aligned_freq_table[position_footer & 7]++;
239 * Writes a compressed literal match to the output.
241 * @out: The output bitstream.
242 * @block_type: The type of the block (LZX_BLOCKTYPE_ALIGNED or LZX_BLOCKTYPE_VERBATIM)
243 * @match: The match, encoded as a 32-bit number.
244 * @codes: Pointer to a structure that contains the codewords for the
245 * main, length, and aligned offset Huffman codes.
248 lzx_write_match(struct output_bitstream *out, int block_type,
249 u32 match, const struct lzx_codes *codes)
251 /* low 8 bits are the match length minus 2 */
252 unsigned match_len_minus_2 = match & 0xff;
253 /* Next 17 bits are the position footer */
254 unsigned position_footer = (match >> 8) & 0x1ffff; /* 17 bits */
255 /* Next 6 bits are the position slot. */
256 unsigned position_slot = (match >> 25) & 0x3f; /* 6 bits */
259 unsigned len_pos_header;
260 unsigned main_symbol;
261 unsigned num_extra_bits;
262 unsigned verbatim_bits;
263 unsigned aligned_bits;
266 /* If the match length is less than MIN_MATCH (= 2) +
267 * NUM_PRIMARY_LENS (= 7), the length header contains
268 * the match length minus MIN_MATCH, and there is no
271 * Otherwise, the length header contains
272 * NUM_PRIMARY_LENS, and the length footer contains
273 * the match length minus NUM_PRIMARY_LENS minus
275 if (match_len_minus_2 < LZX_NUM_PRIMARY_LENS) {
276 len_header = match_len_minus_2;
277 /* No length footer-- mark it with a special
279 len_footer = (unsigned)(-1);
281 len_header = LZX_NUM_PRIMARY_LENS;
282 len_footer = match_len_minus_2 - LZX_NUM_PRIMARY_LENS;
285 /* Combine the position slot with the length header into
286 * a single symbol that will be encoded with the main
288 len_pos_header = (position_slot << 3) | len_header;
290 /* The actual main symbol is offset by LZX_NUM_CHARS because
291 * values under LZX_NUM_CHARS are used to indicate a literal
292 * byte rather than a match. */
293 main_symbol = len_pos_header + LZX_NUM_CHARS;
295 /* Output main symbol. */
296 ret = bitstream_put_bits(out, codes->main_codewords[main_symbol],
297 codes->main_lens[main_symbol]);
301 /* If there is a length footer, output it using the
302 * length Huffman code. */
303 if (len_footer != (unsigned)(-1)) {
304 ret = bitstream_put_bits(out, codes->len_codewords[len_footer],
305 codes->len_lens[len_footer]);
310 wimlib_assert(position_slot < LZX_NUM_POSITION_SLOTS);
312 num_extra_bits = lzx_get_num_extra_bits(position_slot);
314 /* For aligned offset blocks with at least 3 extra bits, output the
315 * verbatim bits literally, then the aligned bits encoded using the
316 * aligned offset tree. Otherwise, only the verbatim bits need to be
318 if ((block_type == LZX_BLOCKTYPE_ALIGNED) && (num_extra_bits >= 3)) {
320 verbatim_bits = position_footer >> 3;
321 ret = bitstream_put_bits(out, verbatim_bits,
326 aligned_bits = (position_footer & 7);
327 ret = bitstream_put_bits(out,
328 codes->aligned_codewords[aligned_bits],
329 codes->aligned_lens[aligned_bits]);
333 /* verbatim bits is the same as the position
334 * footer, in this case. */
335 ret = bitstream_put_bits(out, position_footer, num_extra_bits);
343 * Writes all compressed literals in a block, both matches and literal bytes, to
344 * the output bitstream.
346 * @out: The output bitstream.
347 * @block_type: The type of the block (LZX_BLOCKTYPE_ALIGNED or LZX_BLOCKTYPE_VERBATIM)
348 * @match_tab[]: The array of matches that will be output. It has length
349 * of @num_compressed_literals.
350 * @num_compressed_literals: Number of compressed literals to be output.
351 * @codes: Pointer to a structure that contains the codewords for the
352 * main, length, and aligned offset Huffman codes.
355 lzx_write_compressed_literals(struct output_bitstream *ostream,
357 const u32 match_tab[],
358 unsigned num_compressed_literals,
359 const struct lzx_codes *codes)
365 for (i = 0; i < num_compressed_literals; i++) {
366 match = match_tab[i];
368 /* High bit of the match indicates whether the match is an
369 * actual match (1) or a literal uncompressed byte (0) */
370 if (match & 0x80000000) {
372 ret = lzx_write_match(ostream, block_type, match,
378 wimlib_assert(match < LZX_NUM_CHARS);
379 ret = bitstream_put_bits(ostream,
380 codes->main_codewords[match],
381 codes->main_lens[match]);
390 * Writes a compressed Huffman tree to the output, preceded by the pretree for
393 * The Huffman tree is represented in the output as a series of path lengths
394 * from which the canonical Huffman code can be reconstructed. The path lengths
395 * themselves are compressed using a separate Huffman code, the pretree, which
396 * consists of LZX_PRETREE_NUM_SYMBOLS (= 20) symbols that cover all possible code
397 * lengths, plus extra codes for repeated lengths. The path lengths of the
398 * pretree precede the path lengths of the larger code and are uncompressed,
399 * consisting of 20 entries of 4 bits each.
401 * @out: The bitstream for the compressed output.
402 * @lens: The code lengths for the Huffman tree, indexed by symbol.
403 * @num_symbols: The number of symbols in the code.
406 lzx_write_compressed_tree(struct output_bitstream *out,
407 const u8 lens[], unsigned num_symbols)
409 /* Frequencies of the length symbols, including the RLE symbols (NOT the
410 * actual lengths themselves). */
411 freq_t pretree_freqs[LZX_PRETREE_NUM_SYMBOLS];
412 u8 pretree_lens[LZX_PRETREE_NUM_SYMBOLS];
413 u16 pretree_codewords[LZX_PRETREE_NUM_SYMBOLS];
414 u8 output_syms[num_symbols * 2];
415 unsigned output_syms_idx;
416 unsigned cur_run_len;
419 unsigned additional_bits;
423 ZERO_ARRAY(pretree_freqs);
425 /* Since the code word lengths use a form of RLE encoding, the goal here
426 * is to find each run of identical lengths when going through them in
427 * symbol order (including runs of length 1). For each run, as many
428 * lengths are encoded using RLE as possible, and the rest are output
431 * output_syms[] will be filled in with the length symbols that will be
432 * output, including RLE codes, not yet encoded using the pre-tree.
434 * cur_run_len keeps track of how many code word lengths are in the
435 * current run of identical lengths.
439 for (i = 1; i <= num_symbols; i++) {
441 if (i != num_symbols && lens[i] == lens[i - 1]) {
442 /* Still in a run--- keep going. */
447 /* Run ended! Check if it is a run of zeroes or a run of
450 /* The symbol that was repeated in the run--- not to be confused
451 * with the length *of* the run (cur_run_len) */
452 len_in_run = lens[i - 1];
454 if (len_in_run == 0) {
455 /* A run of 0's. Encode it in as few length
456 * codes as we can. */
458 /* The magic length 18 indicates a run of 20 + n zeroes,
459 * where n is an uncompressed literal 5-bit integer that
460 * follows the magic length. */
461 while (cur_run_len >= 20) {
463 additional_bits = min(cur_run_len - 20, 0x1f);
465 output_syms[output_syms_idx++] = 18;
466 output_syms[output_syms_idx++] = additional_bits;
467 cur_run_len -= 20 + additional_bits;
470 /* The magic length 17 indicates a run of 4 + n zeroes,
471 * where n is an uncompressed literal 4-bit integer that
472 * follows the magic length. */
473 while (cur_run_len >= 4) {
474 additional_bits = min(cur_run_len - 4, 0xf);
476 output_syms[output_syms_idx++] = 17;
477 output_syms[output_syms_idx++] = additional_bits;
478 cur_run_len -= 4 + additional_bits;
483 /* A run of nonzero lengths. */
485 /* The magic length 19 indicates a run of 4 + n
486 * nonzeroes, where n is a literal bit that follows the
487 * magic length, and where the value of the lengths in
488 * the run is given by an extra length symbol, encoded
489 * with the pretree, that follows the literal bit.
491 * The extra length symbol is encoded as a difference
492 * from the length of the codeword for the first symbol
493 * in the run in the previous tree.
495 while (cur_run_len >= 4) {
496 additional_bits = (cur_run_len > 4);
497 delta = -(char)len_in_run;
501 pretree_freqs[(unsigned char)delta]++;
502 output_syms[output_syms_idx++] = 19;
503 output_syms[output_syms_idx++] = additional_bits;
504 output_syms[output_syms_idx++] = delta;
505 cur_run_len -= 4 + additional_bits;
509 /* Any remaining lengths in the run are outputted without RLE,
510 * as a difference from the length of that codeword in the
512 while (cur_run_len--) {
513 delta = -(char)len_in_run;
517 pretree_freqs[(unsigned char)delta]++;
518 output_syms[output_syms_idx++] = delta;
524 wimlib_assert(output_syms_idx < ARRAY_LEN(output_syms));
526 /* Build the pretree from the frequencies of the length symbols. */
528 make_canonical_huffman_code(LZX_PRETREE_NUM_SYMBOLS,
529 LZX_MAX_CODEWORD_LEN,
530 pretree_freqs, pretree_lens,
533 /* Write the lengths of the pretree codes to the output. */
534 for (i = 0; i < LZX_PRETREE_NUM_SYMBOLS; i++)
535 bitstream_put_bits(out, pretree_lens[i],
536 LZX_PRETREE_ELEMENT_SIZE);
538 /* Write the length symbols, encoded with the pretree, to the output. */
541 while (i < output_syms_idx) {
542 pretree_sym = output_syms[i++];
544 bitstream_put_bits(out, pretree_codewords[pretree_sym],
545 pretree_lens[pretree_sym]);
546 switch (pretree_sym) {
548 bitstream_put_bits(out, output_syms[i++], 4);
551 bitstream_put_bits(out, output_syms[i++], 5);
554 bitstream_put_bits(out, output_syms[i++], 1);
555 bitstream_put_bits(out,
556 pretree_codewords[output_syms[i]],
557 pretree_lens[output_syms[i]]);
567 /* Builds the canonical Huffman code for the main tree, the length tree, and the
568 * aligned offset tree. */
570 lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs,
571 struct lzx_codes *codes)
573 make_canonical_huffman_code(LZX_MAINTREE_NUM_SYMBOLS,
574 LZX_MAX_CODEWORD_LEN,
575 freq_tabs->main_freq_table,
577 codes->main_codewords);
579 make_canonical_huffman_code(LZX_LENTREE_NUM_SYMBOLS,
580 LZX_MAX_CODEWORD_LEN,
581 freq_tabs->len_freq_table,
583 codes->len_codewords);
585 make_canonical_huffman_code(LZX_ALIGNEDTREE_NUM_SYMBOLS, 8,
586 freq_tabs->aligned_freq_table,
588 codes->aligned_codewords);
592 do_call_insn_translation(u32 *call_insn_target, int input_pos,
598 rel_offset = le32_to_cpu(*call_insn_target);
599 if (rel_offset >= -input_pos && rel_offset < file_size) {
600 if (rel_offset < file_size - input_pos) {
601 /* "good translation" */
602 abs_offset = rel_offset + input_pos;
604 /* "compensating translation" */
605 abs_offset = rel_offset - file_size;
607 *call_insn_target = cpu_to_le32(abs_offset);
611 /* This is the reverse of undo_call_insn_preprocessing() in lzx-decompress.c.
612 * See the comment above that function for more information. */
614 do_call_insn_preprocessing(u8 uncompressed_data[], int uncompressed_data_len)
616 for (int i = 0; i < uncompressed_data_len - 10; i++) {
617 if (uncompressed_data[i] == 0xe8) {
618 do_call_insn_translation((u32*)&uncompressed_data[i + 1],
620 LZX_WIM_MAGIC_FILESIZE);
627 static const struct lz_params lzx_lz_params = {
629 /* LZX_MIN_MATCH == 2, but 2-character matches are rarely useful; the
630 * minimum match for compression is set to 3 instead. */
633 .max_match = LZX_MAX_MATCH,
634 .good_match = LZX_MAX_MATCH,
635 .nice_match = LZX_MAX_MATCH,
636 .max_chain_len = LZX_MAX_MATCH,
637 .max_lazy_match = LZX_MAX_MATCH,
642 * Performs LZX compression on a block of data.
644 * Please see the documentation for the 'compress_func_t' type in write.c for
645 * the exact behavior of this function and how to call it.
648 lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
649 void *compressed_data)
651 struct output_bitstream ostream;
652 u8 uncompressed_data[uncompressed_len + 8];
653 struct lzx_freq_tables freq_tabs;
654 struct lzx_codes codes;
655 u32 match_tab[uncompressed_len];
656 struct lru_queue queue;
657 unsigned num_matches;
658 unsigned compressed_len;
661 int block_type = LZX_BLOCKTYPE_ALIGNED;
663 wimlib_assert(uncompressed_len <= 32768);
665 if (uncompressed_len < 100)
668 memset(&freq_tabs, 0, sizeof(freq_tabs));
673 /* The input data must be preprocessed. To avoid changing the original
674 * input, copy it to a temporary buffer. */
675 memcpy(uncompressed_data, __uncompressed_data, uncompressed_len);
677 /* Before doing any actual compression, do the call instruction (0xe8
678 * byte) translation on the uncompressed data. */
679 do_call_insn_preprocessing(uncompressed_data, uncompressed_len);
681 /* Determine the sequence of matches and literals that will be output,
682 * and in the process, keep counts of the number of times each symbol
683 * will be output, so that the Huffman trees can be made. */
685 num_matches = lz_analyze_block(uncompressed_data, uncompressed_len,
686 match_tab, lzx_record_match,
687 lzx_record_literal, &freq_tabs,
688 &queue, freq_tabs.main_freq_table,
691 lzx_make_huffman_codes(&freq_tabs, &codes);
693 /* Initialize the output bitstream. */
694 init_output_bitstream(&ostream, compressed_data, uncompressed_len - 1);
696 /* The first three bits tell us what kind of block it is, and are one
697 * of the LZX_BLOCKTYPE_* values. */
698 bitstream_put_bits(&ostream, block_type, 3);
700 /* The next bit indicates whether the block size is the default (32768),
701 * indicated by a 1 bit, or whether the block size is given by the next
702 * 16 bits, indicated by a 0 bit. */
703 if (uncompressed_len == 32768) {
704 bitstream_put_bits(&ostream, 1, 1);
706 bitstream_put_bits(&ostream, 0, 1);
707 bitstream_put_bits(&ostream, uncompressed_len, 16);
710 /* Write out the aligned offset tree. Note that M$ lies and says that
711 * the aligned offset tree comes after the length tree, but that is
712 * wrong; it actually is before the main tree. */
713 if (block_type == LZX_BLOCKTYPE_ALIGNED)
714 for (i = 0; i < LZX_ALIGNEDTREE_NUM_SYMBOLS; i++)
715 bitstream_put_bits(&ostream, codes.aligned_lens[i],
716 LZX_ALIGNEDTREE_ELEMENT_SIZE);
718 /* Write the pre-tree and lengths for the first LZX_NUM_CHARS symbols in the
720 ret = lzx_write_compressed_tree(&ostream, codes.main_lens,
725 /* Write the pre-tree and symbols for the rest of the main tree. */
726 ret = lzx_write_compressed_tree(&ostream, codes.main_lens +
728 LZX_MAINTREE_NUM_SYMBOLS -
733 /* Write the pre-tree and symbols for the length tree. */
734 ret = lzx_write_compressed_tree(&ostream, codes.len_lens,
735 LZX_LENTREE_NUM_SYMBOLS);
739 /* Write the compressed literals. */
740 ret = lzx_write_compressed_literals(&ostream, block_type,
741 match_tab, num_matches, &codes);
745 ret = flush_output_bitstream(&ostream);
749 compressed_len = ostream.bit_output - (u8*)compressed_data;
751 #ifdef ENABLE_VERIFY_COMPRESSION
752 /* Verify that we really get the same thing back when decompressing. */
753 u8 buf[uncompressed_len];
754 ret = lzx_decompress(compressed_data, compressed_len, buf,
757 ERROR("lzx_compress(): Failed to decompress data we compressed");
761 for (i = 0; i < uncompressed_len; i++) {
762 if (buf[i] != *((u8*)__uncompressed_data + i)) {
763 ERROR("lzx_compress(): Data we compressed didn't "
764 "decompress to the original data (difference at "
765 "byte %u of %u)", i + 1, uncompressed_len);
770 return compressed_len;