]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/rangecoder/price_table_init.c
Use 28 MiB as memory usage limit for encoding in test_compress.sh.
[icculus/xz.git] / src / liblzma / rangecoder / price_table_init.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       price_table_init.c
4 /// \brief      Static initializations for the range encoder's prices array
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 #ifdef HAVE_CONFIG_H
22 #       include "range_encoder.h"
23 #endif
24
25
26 uint32_t lzma_rc_prices[RC_PRICE_TABLE_SIZE];
27
28
29 extern void
30 lzma_rc_init(void)
31 {
32         for (uint32_t i = (UINT32_C(1) << RC_MOVE_REDUCING_BITS) / 2;
33                         i < RC_BIT_MODEL_TOTAL;
34                         i += (UINT32_C(1) << RC_MOVE_REDUCING_BITS)) {
35                 const uint32_t cycles_bits = RC_BIT_PRICE_SHIFT_BITS;
36                 uint32_t w = i;
37                 uint32_t bit_count = 0;
38
39                 for (uint32_t j = 0; j < cycles_bits; ++j) {
40                         w *= w;
41                         bit_count <<= 1;
42
43                         while (w >= (UINT32_C(1) << 16)) {
44                                 w >>= 1;
45                                 ++bit_count;
46                         }
47                 }
48
49                 lzma_rc_prices[i >> RC_MOVE_REDUCING_BITS]
50                                 = (RC_BIT_MODEL_TOTAL_BITS << cycles_bits)
51                                 - 15 - bit_count;
52         }
53
54         return;
55 }