]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
improved ZSTD_GETPRICE
authorinikep <inikep@gmail.com>
Tue, 23 Feb 2016 18:08:20 +0000 (19:08 +0100)
committerinikep <inikep@gmail.com>
Tue, 23 Feb 2016 18:08:20 +0000 (19:08 +0100)
lib/zstd_internal.h
lib/zstd_opt.h
lib/zstd_opt_internal.h

index c575f4631cf2d2a9f9fe46613f7d53e06987705f..c3874e4eb33c8ae4e8d36b3119e84bbdc46f765e 100644 (file)
@@ -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
index 4169f874d676166c2e6c103cef2c5e2a292f5bfc..cfd17e5ac50f39cce5d3f1d6a1035f611cf9dd7c 100644 (file)
@@ -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;
     }
 }
 
index e9ca5f2e0b5df1d6c9972de062fdae0d8fb1fba0..c23d5d7401dc340b0d04d6132273a0f0181231ce 100644 (file)
@@ -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++)