]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_encoder.c
Move some LZMA2 constants to lzma2_encoder.h so that they
[icculus/xz.git] / src / liblzma / lzma / lzma_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       lzma_encoder.c
4 /// \brief      LZMA encoder
5 //
6 //  Copyright (C) 1999-2006 Igor Pavlov
7 //  Copyright (C) 2007 Lasse Collin
8 //
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Lesser General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2.1 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Lesser General Public License for more details.
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 #include "lzma2_encoder.h"
22 #include "lzma_encoder_private.h"
23 #include "fastpos.h"
24
25
26 /////////////
27 // Literal //
28 /////////////
29
30 static inline void
31 literal_matched(lzma_range_encoder *rc, probability *subcoder,
32                 uint32_t match_byte, uint32_t symbol)
33 {
34         uint32_t offset = 0x100;
35         symbol += UINT32_C(1) << 8;
36
37         do {
38                 match_byte <<= 1;
39                 const uint32_t match_bit = match_byte & offset;
40                 const uint32_t subcoder_index
41                                 = offset + match_bit + (symbol >> 8);
42                 const uint32_t bit = (symbol >> 7) & 1;
43                 rc_bit(rc, &subcoder[subcoder_index], bit);
44
45                 symbol <<= 1;
46                 offset &= ~(match_byte ^ symbol);
47
48         } while (symbol < (UINT32_C(1) << 16));
49 }
50
51
52 static inline void
53 literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
54 {
55         // Locate the literal byte to be encoded and the subcoder.
56         const uint8_t cur_byte = mf->buffer[
57                         mf->read_pos - mf->read_ahead];
58         probability *subcoder = literal_subcoder(coder->literal,
59                         coder->literal_context_bits, coder->literal_pos_mask,
60                         position, mf->buffer[mf->read_pos - mf->read_ahead - 1]);
61
62         if (is_literal_state(coder->state)) {
63                 // Previous LZMA-symbol was a literal. Encode a normal
64                 // literal without a match byte.
65                 rc_bittree(&coder->rc, subcoder, 8, cur_byte);
66         } else {
67                 // Previous LZMA-symbol was a match. Use the last byte of
68                 // the match as a "match byte". That is, compare the bits
69                 // of the current literal and the match byte.
70                 const uint8_t match_byte = mf->buffer[
71                                 mf->read_pos - coder->reps[0] - 1
72                                 - mf->read_ahead];
73                 literal_matched(&coder->rc, subcoder, match_byte, cur_byte);
74         }
75
76         update_literal(coder->state);
77 }
78
79
80 //////////////////
81 // Match length //
82 //////////////////
83
84 static void
85 length_update_prices(lzma_length_encoder *lc, const uint32_t pos_state)
86 {
87         const uint32_t table_size = lc->table_size;
88         lc->counters[pos_state] = table_size;
89
90         const uint32_t a0 = rc_bit_0_price(lc->choice);
91         const uint32_t a1 = rc_bit_1_price(lc->choice);
92         const uint32_t b0 = a1 + rc_bit_0_price(lc->choice2);
93         const uint32_t b1 = a1 + rc_bit_1_price(lc->choice2);
94         uint32_t *const prices = lc->prices[pos_state];
95
96         uint32_t i;
97         for (i = 0; i < table_size && i < LEN_LOW_SYMBOLS; ++i)
98                 prices[i] = a0 + rc_bittree_price(lc->low[pos_state],
99                                 LEN_LOW_BITS, i);
100
101         for (; i < table_size && i < LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; ++i)
102                 prices[i] = b0 + rc_bittree_price(lc->mid[pos_state],
103                                 LEN_MID_BITS, i - LEN_LOW_SYMBOLS);
104
105         for (; i < table_size; ++i)
106                 prices[i] = b1 + rc_bittree_price(lc->high, LEN_HIGH_BITS,
107                                 i - LEN_LOW_SYMBOLS - LEN_MID_SYMBOLS);
108
109         return;
110 }
111
112
113 static inline void
114 length(lzma_range_encoder *rc, lzma_length_encoder *lc,
115                 const uint32_t pos_state, uint32_t len, const bool fast_mode)
116 {
117         assert(len <= MATCH_LEN_MAX);
118         len -= MATCH_LEN_MIN;
119
120         if (len < LEN_LOW_SYMBOLS) {
121                 rc_bit(rc, &lc->choice, 0);
122                 rc_bittree(rc, lc->low[pos_state], LEN_LOW_BITS, len);
123         } else {
124                 rc_bit(rc, &lc->choice, 1);
125                 len -= LEN_LOW_SYMBOLS;
126
127                 if (len < LEN_MID_SYMBOLS) {
128                         rc_bit(rc, &lc->choice2, 0);
129                         rc_bittree(rc, lc->mid[pos_state], LEN_MID_BITS, len);
130                 } else {
131                         rc_bit(rc, &lc->choice2, 1);
132                         len -= LEN_MID_SYMBOLS;
133                         rc_bittree(rc, lc->high, LEN_HIGH_BITS, len);
134                 }
135         }
136
137         // Only getoptimum uses the prices so don't update the table when
138         // in fast mode.
139         if (!fast_mode)
140                 if (--lc->counters[pos_state] == 0)
141                         length_update_prices(lc, pos_state);
142 }
143
144
145 ///////////
146 // Match //
147 ///////////
148
149 static inline void
150 match(lzma_coder *coder, const uint32_t pos_state,
151                 const uint32_t distance, const uint32_t len)
152 {
153         update_match(coder->state);
154
155         length(&coder->rc, &coder->match_len_encoder, pos_state, len,
156                         coder->fast_mode);
157
158         const uint32_t pos_slot = get_pos_slot(distance);
159         const uint32_t len_to_pos_state = get_len_to_pos_state(len);
160         rc_bittree(&coder->rc, coder->pos_slot[len_to_pos_state],
161                         POS_SLOT_BITS, pos_slot);
162
163         if (pos_slot >= START_POS_MODEL_INDEX) {
164                 const uint32_t footer_bits = (pos_slot >> 1) - 1;
165                 const uint32_t base = (2 | (pos_slot & 1)) << footer_bits;
166                 const uint32_t pos_reduced = distance - base;
167
168                 if (pos_slot < END_POS_MODEL_INDEX) {
169                         // Careful here: base - pos_slot - 1 can be -1, but
170                         // rc_bittree_reverse starts at probs[1], not probs[0].
171                         rc_bittree_reverse(&coder->rc,
172                                 coder->pos_special + base - pos_slot - 1,
173                                 footer_bits, pos_reduced);
174                 } else {
175                         rc_direct(&coder->rc, pos_reduced >> ALIGN_BITS,
176                                         footer_bits - ALIGN_BITS);
177                         rc_bittree_reverse(
178                                         &coder->rc, coder->pos_align,
179                                         ALIGN_BITS, pos_reduced & ALIGN_MASK);
180                         ++coder->align_price_count;
181                 }
182         }
183
184         coder->reps[3] = coder->reps[2];
185         coder->reps[2] = coder->reps[1];
186         coder->reps[1] = coder->reps[0];
187         coder->reps[0] = distance;
188         ++coder->match_price_count;
189 }
190
191
192 ////////////////////
193 // Repeated match //
194 ////////////////////
195
196 static inline void
197 rep_match(lzma_coder *coder, const uint32_t pos_state,
198                 const uint32_t rep, const uint32_t len)
199 {
200         if (rep == 0) {
201                 rc_bit(&coder->rc, &coder->is_rep0[coder->state], 0);
202                 rc_bit(&coder->rc,
203                                 &coder->is_rep0_long[coder->state][pos_state],
204                                 len != 1);
205         } else {
206                 const uint32_t distance = coder->reps[rep];
207                 rc_bit(&coder->rc, &coder->is_rep0[coder->state], 1);
208
209                 if (rep == 1) {
210                         rc_bit(&coder->rc, &coder->is_rep1[coder->state], 0);
211                 } else {
212                         rc_bit(&coder->rc, &coder->is_rep1[coder->state], 1);
213                         rc_bit(&coder->rc, &coder->is_rep2[coder->state],
214                                         rep - 2);
215
216                         if (rep == 3)
217                                 coder->reps[3] = coder->reps[2];
218
219                         coder->reps[2] = coder->reps[1];
220                 }
221
222                 coder->reps[1] = coder->reps[0];
223                 coder->reps[0] = distance;
224         }
225
226         if (len == 1) {
227                 update_short_rep(coder->state);
228         } else {
229                 length(&coder->rc, &coder->rep_len_encoder, pos_state, len,
230                                 coder->fast_mode);
231                 update_long_rep(coder->state);
232         }
233 }
234
235
236 //////////
237 // Main //
238 //////////
239
240 static void
241 encode_symbol(lzma_coder *coder, lzma_mf *mf,
242                 uint32_t back, uint32_t len, uint32_t position)
243 {
244         const uint32_t pos_state = position & coder->pos_mask;
245
246         if (back == UINT32_MAX) {
247                 // Literal i.e. eight-bit byte
248                 assert(len == 1);
249                 rc_bit(&coder->rc,
250                                 &coder->is_match[coder->state][pos_state], 0);
251                 literal(coder, mf, position);
252         } else {
253                 // Some type of match
254                 rc_bit(&coder->rc,
255                         &coder->is_match[coder->state][pos_state], 1);
256
257                 if (back < REP_DISTANCES) {
258                         // It's a repeated match i.e. the same distance
259                         // has been used earlier.
260                         rc_bit(&coder->rc, &coder->is_rep[coder->state], 1);
261                         rep_match(coder, pos_state, back, len);
262                 } else {
263                         // Normal match
264                         rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
265                         match(coder, pos_state, back - REP_DISTANCES, len);
266                 }
267         }
268
269         assert(mf->read_ahead >= len);
270         mf->read_ahead -= len;
271 }
272
273
274 static bool
275 encode_init(lzma_coder *coder, lzma_mf *mf)
276 {
277         if (mf->read_pos == mf->read_limit) {
278                 if (mf->action == LZMA_RUN)
279                         return false; // We cannot do anything.
280
281                 // We are finishing (we cannot get here when flushing).
282                 assert(mf->write_pos == mf->read_pos);
283                 assert(mf->action == LZMA_FINISH);
284         } else {
285                 // Do the actual initialization. The first LZMA symbol must
286                 // always be a literal.
287                 mf_skip(mf, 1);
288                 mf->read_ahead = 0;
289                 rc_bit(&coder->rc, &coder->is_match[0][0], 0);
290                 rc_bittree(&coder->rc, coder->literal[0], 8, mf->buffer[0]);
291         }
292
293         // Initialization is done (except if empty file).
294         coder->is_initialized = true;
295
296         return true;
297 }
298
299
300 static void
301 encode_eopm(lzma_coder *coder, uint32_t position)
302 {
303         const uint32_t pos_state = position & coder->pos_mask;
304         rc_bit(&coder->rc, &coder->is_match[coder->state][pos_state], 1);
305         rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
306         match(coder, pos_state, UINT32_MAX, MATCH_LEN_MIN);
307 }
308
309
310 /// Number of bytes that a single encoding loop in lzma_lzma_encode() can
311 /// consume from the dictionary. This limit comes from lzma_lzma_optimum()
312 /// and may need to be updated if that function is significantly modified.
313 #define LOOP_INPUT_MAX (OPTS + 1)
314
315
316 extern lzma_ret
317 lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
318                 uint8_t *restrict out, size_t *restrict out_pos,
319                 size_t out_size, uint32_t limit)
320 {
321         // Initialize the stream if no data has been encoded yet.
322         if (!coder->is_initialized && !encode_init(coder, mf))
323                 return LZMA_OK;
324
325         // Get the lowest bits of the uncompressed offset from the LZ layer.
326         uint32_t position = mf_position(mf);
327
328         while (true) {
329                 // Encode pending bits, if any. Calling this before encoding
330                 // the next symbol is needed only with plain LZMA, since
331                 // LZMA2 always provides big enough buffer to flush
332                 // everything out from the range encoder. For the same reason,
333                 // rc_encode() never returns true when this function is used
334                 // as part of LZMA2 encoder.
335                 if (rc_encode(&coder->rc, out, out_pos, out_size)) {
336                         assert(limit == UINT32_MAX);
337                         return LZMA_OK;
338                 }
339
340                 // With LZMA2 we need to take care that compressed size of
341                 // a chunk doesn't get too big.
342                 // TODO
343                 if (limit != UINT32_MAX
344                                 && (mf->read_pos - mf->read_ahead >= limit
345                                         || *out_pos + rc_pending(&coder->rc)
346                                                 >= LZMA2_CHUNK_MAX
347                                                         - LOOP_INPUT_MAX))
348                         break;
349
350                 // Check that there is some input to process.
351                 if (mf->read_pos >= mf->read_limit) {
352                         if (mf->action == LZMA_RUN)
353                                 return LZMA_OK;
354
355                         if (mf->read_ahead == 0)
356                                 break;
357                 }
358
359                 // Get optimal match (repeat position and length).
360                 // Value ranges for pos:
361                 //   - [0, REP_DISTANCES): repeated match
362                 //   - [REP_DISTANCES, UINT32_MAX):
363                 //     match at (pos - REP_DISTANCES)
364                 //   - UINT32_MAX: not a match but a literal
365                 // Value ranges for len:
366                 //   - [MATCH_LEN_MIN, MATCH_LEN_MAX]
367                 uint32_t len;
368                 uint32_t back;
369
370                 if (coder->fast_mode)
371                         lzma_lzma_optimum_fast(coder, mf, &back, &len);
372                 else
373                         lzma_lzma_optimum_normal(
374                                         coder, mf, &back, &len, position);
375
376                 encode_symbol(coder, mf, back, len, position);
377
378                 position += len;
379         }
380
381         if (!coder->is_flushed) {
382                 coder->is_flushed = true;
383
384                 // We don't support encoding plain LZMA streams without EOPM,
385                 // and LZMA2 doesn't use EOPM at LZMA level.
386                 if (limit == UINT32_MAX)
387                         encode_eopm(coder, position);
388
389                 // Flush the remaining bytes from the range encoder.
390                 rc_flush(&coder->rc);
391
392                 // Copy the remaining bytes to the output buffer. If there
393                 // isn't enough output space, we will copy out the remaining
394                 // bytes on the next call to this function by using
395                 // the rc_encode() call in the encoding loop above.
396                 if (rc_encode(&coder->rc, out, out_pos, out_size)) {
397                         assert(limit == UINT32_MAX);
398                         return LZMA_OK;
399                 }
400         }
401
402         // Make it ready for the next LZMA2 chunk.
403         coder->is_flushed = false;
404
405         return LZMA_STREAM_END;
406 }
407
408
409 static lzma_ret
410 lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
411                 uint8_t *restrict out, size_t *restrict out_pos,
412                 size_t out_size)
413 {
414         // Plain LZMA has no support for sync-flushing.
415         if (unlikely(mf->action == LZMA_SYNC_FLUSH))
416                 return LZMA_OPTIONS_ERROR;
417
418         return lzma_lzma_encode(coder, mf, out, out_pos, out_size, UINT32_MAX);
419 }
420
421
422 ////////////////////
423 // Initialization //
424 ////////////////////
425
426 static bool
427 is_options_valid(const lzma_options_lzma *options)
428 {
429         // Validate some of the options. LZ encoder validates nice_len too
430         // but we need a valid value here earlier.
431         return is_lclppb_valid(options)
432                         && options->nice_len >= MATCH_LEN_MIN
433                         && options->nice_len <= MATCH_LEN_MAX
434                         && (options->mode == LZMA_MODE_FAST
435                                 || options->mode == LZMA_MODE_NORMAL);
436 }
437
438
439 static void
440 set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options)
441 {
442         // LZ encoder initialization does the validation for these so we
443         // don't need to validate here.
444         lz_options->before_size = OPTS;
445         lz_options->dict_size = options->dict_size;
446         lz_options->after_size = LOOP_INPUT_MAX;
447         lz_options->match_len_max = MATCH_LEN_MAX;
448         lz_options->nice_len = options->nice_len;
449         lz_options->match_finder = options->mf;
450         lz_options->depth = options->depth;
451         lz_options->preset_dict = options->preset_dict;
452         lz_options->preset_dict_size = options->preset_dict_size;
453         return;
454 }
455
456
457 static void
458 length_encoder_reset(lzma_length_encoder *lencoder,
459                 const uint32_t num_pos_states, const bool fast_mode)
460 {
461         bit_reset(lencoder->choice);
462         bit_reset(lencoder->choice2);
463
464         for (size_t pos_state = 0; pos_state < num_pos_states; ++pos_state) {
465                 bittree_reset(lencoder->low[pos_state], LEN_LOW_BITS);
466                 bittree_reset(lencoder->mid[pos_state], LEN_MID_BITS);
467         }
468
469         bittree_reset(lencoder->high, LEN_HIGH_BITS);
470
471         if (!fast_mode)
472                 for (size_t pos_state = 0; pos_state < num_pos_states;
473                                 ++pos_state)
474                         length_update_prices(lencoder, pos_state);
475
476         return;
477 }
478
479
480 extern lzma_ret
481 lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
482 {
483         if (!is_options_valid(options))
484                 return LZMA_OPTIONS_ERROR;
485
486         coder->pos_mask = (1U << options->pb) - 1;
487         coder->literal_context_bits = options->lc;
488         coder->literal_pos_mask = (1U << options->lp) - 1;
489
490         // Range coder
491         rc_reset(&coder->rc);
492
493         // State
494         coder->state = 0;
495         for (size_t i = 0; i < REP_DISTANCES; ++i)
496                 coder->reps[i] = 0;
497
498         literal_init(coder->literal, options->lc, options->lp);
499
500         // Bit encoders
501         for (size_t i = 0; i < STATES; ++i) {
502                 for (size_t j = 0; j <= coder->pos_mask; ++j) {
503                         bit_reset(coder->is_match[i][j]);
504                         bit_reset(coder->is_rep0_long[i][j]);
505                 }
506
507                 bit_reset(coder->is_rep[i]);
508                 bit_reset(coder->is_rep0[i]);
509                 bit_reset(coder->is_rep1[i]);
510                 bit_reset(coder->is_rep2[i]);
511         }
512
513         for (size_t i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
514                 bit_reset(coder->pos_special[i]);
515
516         // Bit tree encoders
517         for (size_t i = 0; i < LEN_TO_POS_STATES; ++i)
518                 bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
519
520         bittree_reset(coder->pos_align, ALIGN_BITS);
521
522         // Length encoders
523         length_encoder_reset(&coder->match_len_encoder,
524                         1U << options->pb, coder->fast_mode);
525
526         length_encoder_reset(&coder->rep_len_encoder,
527                         1U << options->pb, coder->fast_mode);
528
529         // Price counts are incremented every time appropriate probabilities
530         // are changed. price counts are set to zero when the price tables
531         // are updated, which is done when the appropriate price counts have
532         // big enough value, and lzma_mf.read_ahead == 0 which happens at
533         // least every OPTS (a few thousand) possible price count increments.
534         //
535         // By resetting price counts to UINT32_MAX / 2, we make sure that the
536         // price tables will be initialized before they will be used (since
537         // the value is definitely big enough), and that it is OK to increment
538         // price counts without risk of integer overflow (since UINT32_MAX / 2
539         // is small enough). The current code doesn't increment price counts
540         // before initializing price tables, but it maybe done in future if
541         // we add support for saving the state between LZMA2 chunks.
542         coder->match_price_count = UINT32_MAX / 2;
543         coder->align_price_count = UINT32_MAX / 2;
544
545         coder->opts_end_index = 0;
546         coder->opts_current_index = 0;
547
548         return LZMA_OK;
549 }
550
551
552 extern lzma_ret
553 lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
554                 const lzma_options_lzma *options, lzma_lz_options *lz_options)
555 {
556         // Allocate lzma_coder if it wasn't already allocated.
557         if (*coder_ptr == NULL) {
558                 *coder_ptr = lzma_alloc(sizeof(lzma_coder), allocator);
559                 if (*coder_ptr == NULL)
560                         return LZMA_MEM_ERROR;
561         }
562
563         lzma_coder *coder = *coder_ptr;
564
565         // Set compression mode. We haven't validates the options yet,
566         // but it's OK here, since nothing bad happens with invalid
567         // options in the code below, and they will get rejected by
568         // lzma_lzma_encoder_reset() call at the end of this function.
569         switch (options->mode) {
570                 case LZMA_MODE_FAST:
571                         coder->fast_mode = true;
572                         break;
573
574                 case LZMA_MODE_NORMAL: {
575                         coder->fast_mode = false;
576
577                         // Set dist_table_size.
578                         // Round the dictionary size up to next 2^n.
579                         uint32_t log_size = 0;
580                         while ((UINT32_C(1) << log_size) < options->dict_size)
581                                 ++log_size;
582
583                         coder->dist_table_size = log_size * 2;
584
585                         // Length encoders' price table size
586                         coder->match_len_encoder.table_size
587                                 = options->nice_len + 1 - MATCH_LEN_MIN;
588                         coder->rep_len_encoder.table_size
589                                 = options->nice_len + 1 - MATCH_LEN_MIN;
590                         break;
591                 }
592
593                 default:
594                         return LZMA_OPTIONS_ERROR;
595         }
596
597         coder->is_initialized = false;
598         coder->is_flushed = false;
599
600         set_lz_options(lz_options, options);
601
602         return lzma_lzma_encoder_reset(coder, options);
603 }
604
605
606 static lzma_ret
607 lzma_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
608                 const void *options, lzma_lz_options *lz_options)
609 {
610         lz->code = &lzma_encode;
611         return lzma_lzma_encoder_create(
612                         &lz->coder, allocator, options, lz_options);
613 }
614
615
616 extern lzma_ret
617 lzma_lzma_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
618                 const lzma_filter_info *filters)
619 {
620         return lzma_lz_encoder_init(
621                         next, allocator, filters, &lzma_encoder_init);
622 }
623
624
625 extern uint64_t
626 lzma_lzma_encoder_memusage(const void *options)
627 {
628         if (!is_options_valid(options))
629                 return UINT64_MAX;
630
631         lzma_lz_options lz_options;
632         set_lz_options(&lz_options, options);
633
634         const uint64_t lz_memusage = lzma_lz_encoder_memusage(&lz_options);
635         if (lz_memusage == UINT64_MAX)
636                 return UINT64_MAX;
637
638         return (uint64_t)(sizeof(lzma_coder)) + lz_memusage;
639 }
640
641
642 extern bool
643 lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
644 {
645         if (!is_lclppb_valid(options))
646                 return true;
647
648         *byte = (options->pb * 5 + options->lp) * 9 + options->lc;
649         assert(*byte <= (4 * 5 + 4) * 9 + 8);
650
651         return false;
652 }
653
654
655 #ifdef HAVE_ENCODER_LZMA1
656 extern lzma_ret
657 lzma_lzma_props_encode(const void *options, uint8_t *out)
658 {
659         const lzma_options_lzma *const opt = options;
660
661         if (lzma_lzma_lclppb_encode(opt, out))
662                 return LZMA_PROG_ERROR;
663
664         integer_write_32(out + 1, opt->dict_size);
665
666         return LZMA_OK;
667 }
668 #endif
669
670
671 extern LZMA_API lzma_bool
672 lzma_mode_is_supported(lzma_mode mode)
673 {
674         return mode == LZMA_MODE_FAST || mode == LZMA_MODE_NORMAL;
675 }