RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / C / 7zip / Compress / RangeCoder / RangeCoderBit.cpp
blob8d273c8f9353e01441c79509f5fc84dbdd7c5eaf
1 // Compress/RangeCoder/RangeCoderBit.cpp
3 #include "StdAfx.h"
5 #include "RangeCoderBit.h"
7 namespace NCompress {
8 namespace NRangeCoder {
10 UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
11 static CPriceTables g_PriceTables;
13 CPriceTables::CPriceTables() { Init(); }
15 void CPriceTables::Init()
17 const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
18 for(int i = kNumBits - 1; i >= 0; i--)
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));
28 // simplest: bad solution
29 for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
30 ProbPrices[i] = kBitPrice;
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);
44 // experimental, slow, solution:
45 for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
47 const int kCyclesBits = 5;
48 const UInt32 kCycles = (1 << kCyclesBits);
50 UInt32 range = UInt32(-1);
51 UInt32 bitCount = 0;
52 for (UInt32 j = 0; j < kCycles; j++)
54 range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
55 range *= i;
56 while(range < (1 << 31))
58 range <<= 1;
59 bitCount++;
62 bitCount <<= kNumBitPriceShiftBits;
63 range -= (1 << 31);
64 for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)
66 range <<= 1;
67 if (range > (1 << 31))
69 bitCount += (1 << k);
70 range -= (1 << 31);
73 ProbPrices[i] = (bitCount
74 // + (1 << (kCyclesBits - 1))
75 ) >> kCyclesBits;