From: Yann Collet Date: Tue, 15 May 2018 01:04:08 +0000 (-0700) Subject: opt: removed static prices X-Git-Tag: v1.3.5~3^2~41^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c26df0e137e69d5a8834c0b0cc178c84a8d4ac6;p=thirdparty%2Fzstd.git opt: removed static prices after testing, it's actually always better to use dynamic prices albeit initialised from dictionary. --- diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index 0f1830a5e..d9edfc31c 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -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() */ diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 76144f730..fa4681611 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -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;