From: inikep Date: Wed, 3 Feb 2016 17:47:30 +0000 (+0100) Subject: ZSTD_updatePrice X-Git-Tag: v0.5.1^2~3^2~58^2~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bfcfc7bb09510f90f1351e58524af11ea292f93;p=thirdparty%2Fzstd.git ZSTD_updatePrice --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index d88bac8ca..4b345c4aa 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -88,6 +88,14 @@ typedef struct { BYTE* matchLength; BYTE* dumpsStart; BYTE* dumps; + BYTE* matchLengthFreq; + BYTE* litLengthFreq; + BYTE* litFreq; + BYTE* offCodeFreq; + U32 matchLengthSum; + U32 litLengthSum; + U32 litSum; + U32 offCodeSum; } seqStore_t; static void ZSTD_resetSeqStore(seqStore_t* ssPtr) @@ -97,6 +105,16 @@ static void ZSTD_resetSeqStore(seqStore_t* ssPtr) ssPtr->litLength = ssPtr->litLengthStart; ssPtr->matchLength = ssPtr->matchLengthStart; ssPtr->dumps = ssPtr->dumpsStart; + + ssPtr->matchLengthSum = (1<litLengthSum = (1<litSum = (1<offCodeSum = (1<litFreq, 1, (1<litLengthFreq, 1, (1<matchLengthFreq, 1, (1<offCodeFreq, 1, (1<workSpaceSize < neededSpace) { free(zc->workSpace); zc->workSpace = malloc(neededSpace); @@ -213,6 +231,12 @@ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc, zc->seqStore.litLengthStart = zc->seqStore.litStart + blockSize; zc->seqStore.matchLengthStart = zc->seqStore.litLengthStart + (blockSize>>2); zc->seqStore.dumpsStart = zc->seqStore.matchLengthStart + (blockSize>>2); + zc->seqStore.litFreq = zc->seqStore.dumpsStart + (blockSize>>2); + zc->seqStore.litLengthFreq = zc->seqStore.litFreq + (1<seqStore.matchLengthFreq = zc->seqStore.litLengthFreq + (1<seqStore.offCodeFreq = zc->seqStore.matchLengthFreq + (1<seqStore.XXX = zc->seqStore.offCodeFreq + (1<hbSize = 0; zc->stage = 0; zc->loadedDictEnd = 0; diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index d3f989cd2..f2af062f7 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -83,6 +83,7 @@ static const size_t ZSTD_frameHeaderSize_min = 5; #define MINMATCH 4 #define REPCODE_STARTVALUE 1 +#define Litbits 8 #define MLbits 7 #define LLbits 6 #define Offbits 5 diff --git a/lib/zstd_opt.c b/lib/zstd_opt.c index ebd33835a..454be470d 100644 --- a/lib/zstd_opt.c +++ b/lib/zstd_opt.c @@ -64,7 +64,7 @@ FORCE_INLINE U32 LZ5HC_get_price(U32 litlen, U32 offset, U32 mlen) return lit_cost + match_cost; } -MEM_STATIC size_t ZSTD_getPrice(seqStore_t* seqStorePtr, size_t litLength, const BYTE* literals, size_t offsetCode, size_t matchCode) +MEM_STATIC size_t ZSTD_updatePrice(seqStore_t* seqStorePtr, size_t litLength, const BYTE* literals, size_t offsetCode, size_t matchCode) { #if 0 static const BYTE* g_start = NULL; @@ -76,13 +76,14 @@ MEM_STATIC size_t ZSTD_getPrice(seqStore_t* seqStorePtr, size_t litLength, const size_t price = 0; /* literals */ - seqStorePtr->lit += litLength; - + // seqStorePtr->lit += litLength; + printf("litSum=%d litLengthSum=%d matchLengthSum=%d offCodeSum=%d\n", seqStorePtr->litSum, seqStorePtr->litLengthSum, seqStorePtr->matchLengthSum, seqStorePtr->offCodeSum); + /* literal Length */ if (litLength >= MaxLL) { *(seqStorePtr->litLength++) = MaxLL; if (litLength<255 + MaxLL) price += 8; else price += 32; - } + } else *(seqStorePtr->litLength++) = (BYTE)litLength; /* match offset */ @@ -969,6 +970,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set } #endif + ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH); ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH); anchor = ip = ip + mlen; }