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