Annotation of elwix/tools/oldlzma/SRC/7zip/Compress/RangeCoder/RangeCoderBit.cpp, revision 1.1.1.1
1.1 misho 1: // Compress/RangeCoder/RangeCoderBit.cpp
2:
3: #include "StdAfx.h"
4:
5: #include "RangeCoderBit.h"
6:
7: namespace NCompress {
8: namespace NRangeCoder {
9:
10: UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
11: static CPriceTables g_PriceTables;
12:
13: CPriceTables::CPriceTables() { Init(); }
14:
15: void CPriceTables::Init()
16: {
17: const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
18: for(int i = kNumBits - 1; i >= 0; i--)
19: {
20: UInt32 start = 1 << (kNumBits - i - 1);
21: UInt32 end = 1 << (kNumBits - i);
22: for (UInt32 j = start; j < end; j++)
23: ProbPrices[j] = (i << kNumBitPriceShiftBits) +
24: (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
25: }
26:
27: /*
28: // simplest: bad solution
29: for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
30: ProbPrices[i] = kBitPrice;
31: */
32:
33: /*
34: const double kDummyMultMid = (1.0 / kBitPrice) / 2;
35: const double kDummyMultMid = 0;
36: // float solution
37: double ln2 = log(double(2));
38: double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));
39: for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
40: ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);
41: */
42:
43: /*
44: // experimental, slow, solution:
45: for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
46: {
47: const int kCyclesBits = 5;
48: const UInt32 kCycles = (1 << kCyclesBits);
49:
50: UInt32 range = UInt32(-1);
51: UInt32 bitCount = 0;
52: for (UInt32 j = 0; j < kCycles; j++)
53: {
54: range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
55: range *= i;
56: while(range < (1 << 31))
57: {
58: range <<= 1;
59: bitCount++;
60: }
61: }
62: bitCount <<= kNumBitPriceShiftBits;
63: range -= (1 << 31);
64: for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)
65: {
66: range <<= 1;
67: if (range > (1 << 31))
68: {
69: bitCount += (1 << k);
70: range -= (1 << 31);
71: }
72: }
73: ProbPrices[i] = (bitCount
74: // + (1 << (kCyclesBits - 1))
75: ) >> kCyclesBits;
76: }
77: */
78: }
79:
80: }}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>