From 5f49578be7f0d21b4a6c734f9b827d7cbad2b7c1 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 4 Mar 2020 16:12:16 -0800 Subject: [PATCH 1/3] [opt] Don't recompute initial literals price --- lib/compress/zstd_opt.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 2e50fca6f..44a13ddb7 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -270,19 +270,6 @@ static int ZSTD_litLengthContribution(U32 const litLength, const optState_t* con } } -/* ZSTD_literalsContribution() : - * creates a fake cost for the literals part of a sequence - * which can be compared to the ending cost of a match - * should a new match start at this position */ -static int ZSTD_literalsContribution(const BYTE* const literals, U32 const litLength, - const optState_t* const optPtr, - int optLevel) -{ - int const contribution = (int)ZSTD_rawLiteralsCost(literals, litLength, optPtr, optLevel) - + ZSTD_litLengthContribution(litLength, optPtr, optLevel); - return contribution; -} - /* ZSTD_getMatchPrice() : * Provides the cost of the match part (offset + matchLength) of a sequence * Must be combined with ZSTD_fullLiteralsCost() to get the full cost of a sequence. @@ -894,7 +881,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, { U32 i ; for (i=0; i immediate encoding */ { U32 const maxML = matches[nbMatches-1].len; From 610171ed86b947431796ec58854a673c674f6602 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 4 Mar 2020 16:29:19 -0800 Subject: [PATCH 2/3] [opt] Explain why we don't include literals price --- lib/compress/zstd_opt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 44a13ddb7..896365fc8 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -881,6 +881,11 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, { U32 i ; for (i=0; i immediate encoding */ From c6caa2d04ed505e78a3135e36ecfff7cc3a0306c Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 4 Mar 2020 16:35:26 -0800 Subject: [PATCH 3/3] [opt] Delete ZSTD_litLengthContribution --- lib/compress/zstd_opt.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 896365fc8..3caa4a1c3 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -249,27 +249,6 @@ static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optP } } -/* ZSTD_litLengthContribution() : - * @return ( cost(litlength) - cost(0) ) - * this value can then be added to rawLiteralsCost() - * 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, int optLevel) -{ - if (optPtr->priceType >= zop_predef) return (int)WEIGHT(litLength, optLevel); - - /* dynamic statistics */ - { U32 const llCode = ZSTD_LLcode(litLength); - int const contribution = (int)(LL_bits[llCode] * BITCOST_MULTIPLIER) - + (int)WEIGHT(optPtr->litLengthFreq[0], optLevel) /* note: log2litLengthSum cancel out */ - - (int)WEIGHT(optPtr->litLengthFreq[llCode], optLevel); -#if 1 - return contribution; -#else - return MAX(0, contribution); /* sometimes better, sometimes not ... */ -#endif - } -} - /* ZSTD_getMatchPrice() : * Provides the cost of the match part (offset + matchLength) of a sequence * Must be combined with ZSTD_fullLiteralsCost() to get the full cost of a sequence.