From 4a981f79374077ea8b896ea7a3fd3ee187f7d2d0 Mon Sep 17 00:00:00 2001 From: inikep Date: Tue, 23 Feb 2016 19:08:20 +0100 Subject: [PATCH] improved ZSTD_GETPRICE --- lib/zstd_internal.h | 2 +- lib/zstd_opt.h | 12 ++++-------- lib/zstd_opt_internal.h | 10 +++++++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index c575f463..c3874e4e 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -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 /* for debug */ #endif diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h index 4169f874..cfd17e5a 100644 --- a/lib/zstd_opt.h +++ b/lib/zstd_opt.h @@ -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<litSum + seqStorePtr->matchSum)) + (matchLength==0); - return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum<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; } } diff --git a/lib/zstd_opt_internal.h b/lib/zstd_opt_internal.h index e9ca5f2e..c23d5d74 100644 --- a/lib/zstd_opt_internal.h +++ b/lib/zstd_opt_internal.h @@ -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<litSum = (1<offCodeSum = (1<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++)