improved ZSTD_GETPRICE
This commit is contained in:
parent
e0010e9baf
commit
4a981f7937
@ -50,7 +50,7 @@
|
||||
/*-*************************************
|
||||
* Common constants
|
||||
***************************************/
|
||||
#define ZSTD_OPT_DEBUG 3 // 1 = tableID=0; 3 = print block stats; 5 = check encoded sequences; 9 = full logs
|
||||
#define ZSTD_OPT_DEBUG 0 // 1 = tableID=0; 3 = print block stats; 5 = check encoded sequences; 9 = full logs
|
||||
#if ZSTD_OPT_DEBUG > 0
|
||||
#include <stdio.h> /* for debug */
|
||||
#endif
|
||||
|
@ -44,21 +44,17 @@ FORCE_INLINE U32 ZSTD_GETPRICE(seqStore_t* seqStorePtr, U32 litLength, const BYT
|
||||
matchLength -= MINMATCHOPT;
|
||||
price += ((matchLength >= MaxML)<<3) + ((matchLength >= 255+MaxML)<<4) + ((matchLength>=(1<<15))<<3);
|
||||
if (matchLength >= MaxML) matchLength = MaxML;
|
||||
price += ZSTD_highbit(seqStorePtr->matchLengthSum) - ZSTD_highbit(seqStorePtr->matchLengthFreq[matchLength]);
|
||||
price += ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ZSTD_highbit(seqStorePtr->matchLengthSum) - ZSTD_highbit(seqStorePtr->matchLengthFreq[matchLength]);
|
||||
|
||||
#define ZSTD_PRICE_MULT 2
|
||||
switch (seqStorePtr->priceFunc)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
if (!litLength) return price + 1 + ((seqStorePtr->litSum<<ZSTD_PRICE_MULT) / (seqStorePtr->litSum + seqStorePtr->matchSum)) + (matchLength==0);
|
||||
return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum<<ZSTD_PRICE_MULT) / (seqStorePtr->litSum + seqStorePtr->matchSum)) + (matchLength==0);
|
||||
return price + ((seqStorePtr->litSum>>4) / seqStorePtr->litLengthSum);
|
||||
case 1:
|
||||
if (!litLength) return price + 1 + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + (matchLength==0);
|
||||
return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + (matchLength==0);
|
||||
return price + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum));
|
||||
case 2:
|
||||
if (!litLength) return price + 1;
|
||||
return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals);
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
#define ZSTD_OPT_NUM (1<<12)
|
||||
#define ZSTD_FREQ_START 1
|
||||
#define ZSTD_FREQ_STEP 1
|
||||
#define ZSTD_FREQ_DIV 5
|
||||
#define ZSTD_FREQ_DIV 4
|
||||
|
||||
/*- Debug -*/
|
||||
#if defined(ZSTD_OPT_DEBUG) && ZSTD_OPT_DEBUG>=9
|
||||
@ -81,7 +81,8 @@ MEM_STATIC void ZSTD_rescaleFreqs(seqStore_t* ssPtr)
|
||||
ssPtr->litLengthSum = (1<<LLbits);
|
||||
ssPtr->litSum = (1<<Litbits);
|
||||
ssPtr->offCodeSum = (1<<Offbits);
|
||||
|
||||
ssPtr->matchSum = 0;
|
||||
|
||||
for (u=0; u<=MaxLit; u++)
|
||||
ssPtr->litFreq[u] = 1;
|
||||
for (u=0; u<=MaxLL; u++)
|
||||
@ -94,8 +95,8 @@ MEM_STATIC void ZSTD_rescaleFreqs(seqStore_t* ssPtr)
|
||||
ssPtr->matchLengthSum = 0;
|
||||
ssPtr->litLengthSum = 0;
|
||||
ssPtr->litSum = 0;
|
||||
ssPtr->matchSum = 0;
|
||||
ssPtr->offCodeSum = 0;
|
||||
ssPtr->matchSum = 0;
|
||||
|
||||
for (u=0; u<=MaxLit; u++) {
|
||||
ssPtr->litFreq[u] = ZSTD_FREQ_START + (ssPtr->litFreq[u]>>ZSTD_FREQ_DIV);
|
||||
@ -150,6 +151,9 @@ FORCE_INLINE U32 ZSTD_getLiteralPrice(seqStore_t* seqStorePtr, U32 litLength, co
|
||||
{
|
||||
U32 price, u;
|
||||
|
||||
if (litLength == 0)
|
||||
return ZSTD_highbit(seqStorePtr->litLengthSum) - ZSTD_highbit(seqStorePtr->litLengthFreq[0]);
|
||||
|
||||
/* literals */
|
||||
price = litLength * ZSTD_highbit(seqStorePtr->litSum);
|
||||
for (u=0; u < litLength; u++)
|
||||
|
Loading…
Reference in New Issue
Block a user