mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 06:07:05 -06:00
Update to Fast LZMA2 1.0.0
This commit is contained in:
@@ -28,9 +28,13 @@ typedef U16 Probability;
|
||||
#define kNumMoveBits 5U
|
||||
#define kProbInitValue (kBitModelTotal >> 1U)
|
||||
#define kNumMoveReducingBits 4U
|
||||
#define kNumBitPriceShiftBits 4U
|
||||
#define kNumBitPriceShiftBits 5U
|
||||
#define kPriceTableSize (kBitModelTotal >> kNumMoveReducingBits)
|
||||
|
||||
extern const unsigned price_table[kBitModelTotal >> kNumMoveReducingBits];
|
||||
extern BYTE price_table[2][kPriceTableSize];
|
||||
#if 0
|
||||
void RC_printPriceTable();
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -43,22 +47,20 @@ typedef struct
|
||||
BYTE cache;
|
||||
} RangeEncoder;
|
||||
|
||||
void RangeEncReset(RangeEncoder* const rc);
|
||||
void RC_reset(RangeEncoder* const rc);
|
||||
|
||||
void SetOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer, size_t chunk_size);
|
||||
void RC_setOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer, size_t chunk_size);
|
||||
|
||||
void RangeEncReset(RangeEncoder* const rc);
|
||||
void FORCE_NOINLINE RC_shiftLow(RangeEncoder* const rc);
|
||||
|
||||
void ShiftLow(RangeEncoder* const rc);
|
||||
void RC_encodeBitTree(RangeEncoder* const rc, Probability *const probs, unsigned bit_count, unsigned symbol);
|
||||
|
||||
void EncodeBitTree(RangeEncoder* const rc, Probability *const probs, unsigned bit_count, unsigned symbol);
|
||||
void RC_encodeBitTreeReverse(RangeEncoder* const rc, Probability *const probs, unsigned bit_count, unsigned symbol);
|
||||
|
||||
void EncodeBitTreeReverse(RangeEncoder* const rc, Probability *const probs, unsigned bit_count, unsigned symbol);
|
||||
|
||||
void EncodeDirect(RangeEncoder* const rc, unsigned value, unsigned bit_count);
|
||||
void FORCE_NOINLINE RC_encodeDirect(RangeEncoder* const rc, unsigned value, unsigned bit_count);
|
||||
|
||||
HINT_INLINE
|
||||
void EncodeBit0(RangeEncoder* const rc, Probability *const rprob)
|
||||
void RC_encodeBit0(RangeEncoder* const rc, Probability *const rprob)
|
||||
{
|
||||
unsigned prob = *rprob;
|
||||
rc->range = (rc->range >> kNumBitModelTotalBits) * prob;
|
||||
@@ -66,12 +68,12 @@ void EncodeBit0(RangeEncoder* const rc, Probability *const rprob)
|
||||
*rprob = (Probability)prob;
|
||||
if (rc->range < kTopValue) {
|
||||
rc->range <<= 8;
|
||||
ShiftLow(rc);
|
||||
RC_shiftLow(rc);
|
||||
}
|
||||
}
|
||||
|
||||
HINT_INLINE
|
||||
void EncodeBit1(RangeEncoder* const rc, Probability *const rprob)
|
||||
void RC_encodeBit1(RangeEncoder* const rc, Probability *const rprob)
|
||||
{
|
||||
unsigned prob = *rprob;
|
||||
U32 new_bound = (rc->range >> kNumBitModelTotalBits) * prob;
|
||||
@@ -81,16 +83,16 @@ void EncodeBit1(RangeEncoder* const rc, Probability *const rprob)
|
||||
*rprob = (Probability)prob;
|
||||
if (rc->range < kTopValue) {
|
||||
rc->range <<= 8;
|
||||
ShiftLow(rc);
|
||||
RC_shiftLow(rc);
|
||||
}
|
||||
}
|
||||
|
||||
HINT_INLINE
|
||||
void EncodeBit(RangeEncoder* const rc, Probability *const rprob, unsigned const bit)
|
||||
void RC_encodeBit(RangeEncoder* const rc, Probability *const rprob, unsigned const bit)
|
||||
{
|
||||
unsigned prob = *rprob;
|
||||
if (bit != 0) {
|
||||
U32 new_bound = (rc->range >> kNumBitModelTotalBits) * prob;
|
||||
U32 const new_bound = (rc->range >> kNumBitModelTotalBits) * prob;
|
||||
rc->low += new_bound;
|
||||
rc->range -= new_bound;
|
||||
prob -= prob >> kNumMoveBits;
|
||||
@@ -102,52 +104,56 @@ void EncodeBit(RangeEncoder* const rc, Probability *const rprob, unsigned const
|
||||
*rprob = (Probability)prob;
|
||||
if (rc->range < kTopValue) {
|
||||
rc->range <<= 8;
|
||||
ShiftLow(rc);
|
||||
RC_shiftLow(rc);
|
||||
}
|
||||
}
|
||||
|
||||
#define GET_PRICE(rc, prob, symbol) \
|
||||
price_table[((prob) ^ ((-(int)(symbol)) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
|
||||
#define GET_PRICE(prob, symbol) \
|
||||
price_table[symbol][(prob) >> kNumMoveReducingBits]
|
||||
|
||||
#define GET_PRICE_0(rc, prob) price_table[(prob) >> kNumMoveReducingBits]
|
||||
#define GET_PRICE_0(prob) price_table[0][(prob) >> kNumMoveReducingBits]
|
||||
|
||||
#define GET_PRICE_1(rc, prob) price_table[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
|
||||
#define GET_PRICE_1(prob) price_table[1][(prob) >> kNumMoveReducingBits]
|
||||
|
||||
#define kMinLitPrice 8U
|
||||
|
||||
HINT_INLINE
|
||||
unsigned GetTreePrice(RangeEncoder* const rc, const Probability* const prob_table, unsigned const bit_count, size_t symbol)
|
||||
unsigned RC_getTreePrice(const Probability* const prob_table, unsigned bit_count, size_t symbol)
|
||||
{
|
||||
unsigned price = 0;
|
||||
symbol |= ((size_t)1 << bit_count);
|
||||
while (symbol != 1) {
|
||||
size_t next_symbol = symbol >> 1;
|
||||
symbol |= ((size_t)1 << bit_count);
|
||||
do {
|
||||
size_t const next_symbol = symbol >> 1;
|
||||
unsigned prob = prob_table[next_symbol];
|
||||
unsigned bit = (unsigned)symbol & 1;
|
||||
price += GET_PRICE(rc, prob, bit);
|
||||
size_t bit = symbol & 1;
|
||||
price += GET_PRICE(prob, bit);
|
||||
symbol = next_symbol;
|
||||
}
|
||||
} while (symbol != 1);
|
||||
return price;
|
||||
}
|
||||
|
||||
HINT_INLINE
|
||||
unsigned GetReverseTreePrice(RangeEncoder* const rc, const Probability* const prob_table, unsigned const bit_count, size_t symbol)
|
||||
unsigned RC_getReverseTreePrice(const Probability* const prob_table, unsigned bit_count, size_t symbol)
|
||||
{
|
||||
unsigned price = 0;
|
||||
size_t m = 1;
|
||||
for (unsigned i = bit_count; i != 0; --i) {
|
||||
unsigned prob = prob_table[m];
|
||||
unsigned bit = symbol & 1;
|
||||
symbol >>= 1;
|
||||
price += GET_PRICE(rc, prob, bit);
|
||||
m = (m << 1) | bit;
|
||||
}
|
||||
return price;
|
||||
unsigned prob = prob_table[1];
|
||||
size_t bit = symbol & 1;
|
||||
unsigned price = GET_PRICE(prob, bit);
|
||||
size_t m = 1;
|
||||
while (--bit_count != 0) {
|
||||
m = (m << 1) | bit;
|
||||
symbol >>= 1;
|
||||
prob = prob_table[m];
|
||||
bit = symbol & 1;
|
||||
price += GET_PRICE(prob, bit);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
HINT_INLINE
|
||||
void Flush(RangeEncoder* const rc)
|
||||
void RC_flush(RangeEncoder* const rc)
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
ShiftLow(rc);
|
||||
RC_shiftLow(rc);
|
||||
}
|
||||
|
||||
#if defined (__cplusplus)
|
||||
|
||||
Reference in New Issue
Block a user