diff options
Diffstat (limited to 'CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp')
-rwxr-xr-x | CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp | 72 |
1 files changed, 14 insertions, 58 deletions
diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp index 8e4c4d3a..9a7c0a05 100755 --- a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp +++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp @@ -7,74 +7,30 @@ namespace NCompress { namespace NRangeCoder { -UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; -static CPriceTables g_PriceTables; - -CPriceTables::CPriceTables() { Init(); } +UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; -void CPriceTables::Init() +struct CPriceTables { CPriceTables() { - const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); - for(int i = kNumBits - 1; i >= 0; i--) - { - UInt32 start = 1 << (kNumBits - i - 1); - UInt32 end = 1 << (kNumBits - i); - for (UInt32 j = start; j < end; j++) - ProbPrices[j] = (i << kNumBitPriceShiftBits) + - (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); - } - - /* - // simplest: bad solution - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) - ProbPrices[i] = kBitPrice; - */ - - /* - const double kDummyMultMid = (1.0 / kBitPrice) / 2; - const double kDummyMultMid = 0; - // float solution - double ln2 = log(double(2)); - double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits)); - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) - ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice); - */ - - /* - // experimental, slow, solution: - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) + for (UInt32 i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits)) { - const int kCyclesBits = 5; - const UInt32 kCycles = (1 << kCyclesBits); - - UInt32 range = UInt32(-1); + const int kCyclesBits = kNumBitPriceShiftBits; + UInt32 w = i; UInt32 bitCount = 0; - for (UInt32 j = 0; j < kCycles; j++) + for (int j = 0; j < kCyclesBits; j++) { - range >>= (kNumBitModelTotalBits - kNumMoveReducingBits); - range *= i; - while(range < (1 << 31)) + w = w * w; + bitCount <<= 1; + while (w >= ((UInt32)1 << 16)) { - range <<= 1; + w >>= 1; bitCount++; } } - bitCount <<= kNumBitPriceShiftBits; - range -= (1 << 31); - for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--) - { - range <<= 1; - if (range > (1 << 31)) - { - bitCount += (1 << k); - range -= (1 << 31); - } - } - ProbPrices[i] = (bitCount - // + (1 << (kCyclesBits - 1)) - ) >> kCyclesBits; + ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount); } - */ } +}; + +static CPriceTables g_PriceTables; }} |