]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
opt: removed static prices
authorYann Collet <cyan@fb.com>
Tue, 15 May 2018 01:04:08 +0000 (18:04 -0700)
committerYann Collet <cyan@fb.com>
Tue, 15 May 2018 01:04:08 +0000 (18:04 -0700)
after testing, it's actually always better to use dynamic prices
albeit initialised from dictionary.

lib/compress/zstd_compress_internal.h
lib/compress/zstd_opt.c

index 0f1830a5e691a28f507a88611a39388e15d7197c..d9edfc31c6f18e54f00d5a8b6dc8ef7e8fe1d321 100644 (file)
@@ -76,7 +76,7 @@ typedef struct {
     U32 rep[ZSTD_REP_NUM];
 } ZSTD_optimal_t;
 
-typedef enum { zop_dynamic=0, zop_predef, zop_static } ZSTD_OptPrice_e;
+typedef enum { zop_dynamic=0, zop_predef } ZSTD_OptPrice_e;
 
 typedef struct {
     /* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
index 76144f7303c0fdc713a277756e17f4d23f3e34ee..fa46816119341cded2a9b58d75a235f095a96247 100644 (file)
@@ -40,14 +40,9 @@ static void ZSTD_rescaleFreqs(optState_t* const optPtr,
 
         assert(optPtr->symbolCosts != NULL);
         if (optPtr->symbolCosts->hufCTable_repeatMode == HUF_repeat_valid) { /* huffman table presumed generated by dictionary */
-            if (srcSize <= 8192)   /* heuristic */
-                optPtr->priceType = zop_static;
-            else {
-                assert(optPtr->priceType == zop_dynamic);
-            }
+            optPtr->priceType = zop_dynamic;
 
             assert(optPtr->litFreq != NULL);
-            assert(optPtr->symbolCosts != NULL);
             optPtr->litSum = 0;
             {   unsigned lit;
                 for (lit=0; lit<=MaxLit; lit++) {
@@ -156,7 +151,7 @@ static void ZSTD_rescaleFreqs(optState_t* const optPtr,
 #if 1   /* approximation at bit level */
 #  define BITCOST_ACCURACY 0
 #  define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
-#  define BITCOST_SYMBOL(t,l,s)  ((void)l, FSE_getMaxNbBits(t,s)*BITCOST_MULTIPLIER)
+#  define BITCOST_SYMBOL(t,l,s)  ((void)(l), FSE_getMaxNbBits(t,s) * BITCOST_MULTIPLIER)
 #else   /* fractional bit accuracy */
 #  define BITCOST_ACCURACY 8
 #  define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
@@ -177,14 +172,6 @@ static U32 ZSTD_rawLiteralsCost(const BYTE* const literals, U32 const litLength,
 {
     if (litLength == 0) return 0;
     if (optPtr->priceType == zop_predef) return (litLength*6);  /* 6 bit per literal - no statistic used */
-    if (optPtr->priceType == zop_static) {
-        U32 u, cost;
-        assert(optPtr->symbolCosts != NULL);
-        assert(optPtr->symbolCosts->hufCTable_repeatMode == HUF_repeat_valid);
-        for (u=0, cost=0; u < litLength; u++)
-            cost += HUF_getNbBits(optPtr->symbolCosts->hufCTable, literals[u]);
-        return cost * BITCOST_MULTIPLIER;
-    }
 
     /* dynamic statistics */
     {   U32 u;
@@ -199,14 +186,6 @@ static U32 ZSTD_rawLiteralsCost(const BYTE* const literals, U32 const litLength,
  * cost of literalLength symbol */
 static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optPtr)
 {
-    if (optPtr->priceType == zop_static) {
-        U32 const llCode = ZSTD_LLcode(litLength);
-        FSE_CState_t cstate;
-        FSE_initCState(&cstate, optPtr->symbolCosts->litlengthCTable);
-        {   U32 const price = LL_bits[llCode]*BITCOST_MULTIPLIER + BITCOST_SYMBOL(cstate.symbolTT, cstate.stateLog, llCode);
-            DEBUGLOG(8, "ZSTD_litLengthPrice: ll=%u, bitCost=%.2f", litLength, (double)price / BITCOST_MULTIPLIER);
-            return price;
-    }   }
     if (optPtr->priceType == zop_predef) return ZSTD_highbit32((U32)litLength+1);
 
     /* dynamic statistics */
@@ -231,14 +210,6 @@ static U32 ZSTD_fullLiteralsCost(const BYTE* const literals, U32 const litLength
  * to provide a cost which is directly comparable to a match ending at same position */
 static int ZSTD_litLengthContribution(U32 const litLength, const optState_t* const optPtr)
 {
-    if (optPtr->priceType == zop_static) {
-        U32 const llCode = ZSTD_LLcode(litLength);
-        FSE_CState_t cstate;
-        FSE_initCState(&cstate, optPtr->symbolCosts->litlengthCTable);
-        return (int)(LL_bits[llCode] * BITCOST_MULTIPLIER)
-             + BITCOST_SYMBOL(cstate.symbolTT, cstate.stateLog, llCode)
-             - BITCOST_SYMBOL(cstate.symbolTT, cstate.stateLog, 0);
-    }
     if (optPtr->priceType >= zop_predef) return ZSTD_highbit32(litLength+1);
 
     /* dynamic statistics */
@@ -281,15 +252,6 @@ ZSTD_getMatchPrice(U32 const offset, U32 const matchLength,
     U32 const mlBase = matchLength - MINMATCH;
     assert(matchLength >= MINMATCH);
 
-    if (optPtr->priceType == zop_static) {
-        U32 const mlCode = ZSTD_MLcode(mlBase);
-        FSE_CState_t mlstate, offstate;
-        FSE_initCState(&mlstate, optPtr->symbolCosts->matchlengthCTable);
-        FSE_initCState(&offstate, optPtr->symbolCosts->offcodeCTable);
-        return BITCOST_SYMBOL(offstate.symbolTT, offstate.stateLog, offCode) + offCode*BITCOST_MULTIPLIER
-             + BITCOST_SYMBOL(mlstate.symbolTT, mlstate.stateLog, mlCode) + ML_bits[mlCode]*BITCOST_MULTIPLIER;
-    }
-
     if (optPtr->priceType == zop_predef)  /* fixed scheme, do not use statistics */
         return ZSTD_highbit32(mlBase+1) + 16 + offCode;