From: Yann Collet Date: Sun, 20 Mar 2016 23:39:19 +0000 (+0100) Subject: support default LL distribution X-Git-Tag: v0.6.0^2~17^2~28^2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c62b7dfc8d692171762b77ec598fb9fd7d54655;p=thirdparty%2Fzstd.git support default LL distribution --- diff --git a/lib/fse.c b/lib/fse.c index 291e64192..dabe28307 100644 --- a/lib/fse.c +++ b/lib/fse.c @@ -145,21 +145,18 @@ static U32 FSE_tableStep(U32 tableSize) { return (tableSize>>1) + (tableSize>>3) size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog) { - const unsigned tableSize = 1 << tableLog; - const unsigned tableMask = tableSize - 1; + U32 const tableSize = 1 << tableLog; + U32 const tableMask = tableSize - 1; void* const ptr = ct; U16* const tableU16 = ( (U16*) ptr) + 2; void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableLog ? tableSize>>1 : 1) ; FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT); - const unsigned step = FSE_tableStep(tableSize); - unsigned cumul[FSE_MAX_SYMBOL_VALUE+2]; - U32 position = 0; + U32 const step = FSE_tableStep(tableSize); + U32 cumul[FSE_MAX_SYMBOL_VALUE+2]; FSE_FUNCTION_TYPE tableSymbol[FSE_MAX_TABLESIZE]; /* memset() is not necessary, even if static analyzer complain about it */ U32 highThreshold = tableSize-1; - unsigned symbol; - unsigned i; - /* header */ + /* CTable header */ tableU16[-2] = (U16) tableLog; tableU16[-1] = (U16) maxSymbolValue; @@ -167,42 +164,44 @@ size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */ /* symbol start positions */ - cumul[0] = 0; - for (i=1; i<=maxSymbolValue+1; i++) { - if (normalizedCounter[i-1]==-1) { /* Low proba symbol */ - cumul[i] = cumul[i-1] + 1; - tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(i-1); - } else { - cumul[i] = cumul[i-1] + normalizedCounter[i-1]; - } } - cumul[maxSymbolValue+1] = tableSize+1; + { U32 u; + cumul[0] = 0; + for (u=1; u<=maxSymbolValue+1; u++) { + if (normalizedCounter[u-1]==-1) { /* Low proba symbol */ + cumul[u] = cumul[u-1] + 1; + tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1); + } else { + cumul[u] = cumul[u-1] + normalizedCounter[u-1]; + } } + cumul[maxSymbolValue+1] = tableSize+1; + } /* Spread symbols */ - for (symbol=0; symbol<=maxSymbolValue; symbol++) { - int nbOccurences; - for (nbOccurences=0; nbOccurences highThreshold) position = (position + step) & tableMask; /* Low proba area */ - } } - - if (position!=0) return ERROR(GENERIC); /* Must have gone through all positions */ + { U32 position = 0; + U32 symbol; + for (symbol=0; symbol<=maxSymbolValue; symbol++) { + int nbOccurences; + for (nbOccurences=0; nbOccurences highThreshold) position = (position + step) & tableMask; /* Low proba area */ + } } + if (position!=0) return ERROR(GENERIC); /* Must have gone through all positions */ + } /* Build table */ - for (i=0; i highThreshold) position = (position + step) & tableMask; /* lowprob area */ - } } - - if (position!=0) return ERROR(GENERIC); /* position must reach all cells once, otherwise normalizedCounter is incorrect */ + { U32 position = 0; + for (s=0; s<=maxSymbolValue; s++) { + int i; + for (i=0; i highThreshold) position = (position + step) & tableMask; /* lowprob area */ + } } + if (position!=0) return ERROR(GENERIC); /* position must reach all cells once, otherwise normalizedCounter is incorrect */ + } /* Build Decoding table */ - { - U32 i; - for (i=0; i>= 2; } - { - short const max = (short)((2*threshold-1)-remaining); + { short const max = (short)((2*threshold-1)-remaining); short count; if ((bitStream & (threshold-1)) < (U32)max) { diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 937cce85a..c4cd79527 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -655,7 +655,7 @@ static const BYTE deltaCode = 18; /* CTable for Literal Lengths */ #if 1 - { U32 max = 36; + { U32 max = 35; size_t const mostFrequent = FSE_countFast(count, &max, llCodeTable, nbSeq); if ((mostFrequent == nbSeq) && (nbSeq > 2)) { *op++ = llCodeTable[0]; @@ -664,7 +664,13 @@ static const BYTE deltaCode = 18; } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { LLtype = FSE_ENCODING_STATIC; } else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (LLbits-1)))) { - FSE_buildCTable_raw(CTable_LitLength, LLbits); + static const S16 LL_defaultNorm[36] = { 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 1, 1, 1, 1, + 1, 1, 1, 1 }; + static const U32 LL_defaultNormLog = 6; + FSE_buildCTable(CTable_LitLength, LL_defaultNorm, 35, LL_defaultNormLog); LLtype = FSE_ENCODING_RAW; } else { size_t NCountSize; diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index 887348294..3a6887e90 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -325,7 +325,7 @@ size_t ZSTD_getFrameParams(ZSTD_frameParams* fparamsPtr, const void* src, size_t * @return : 0 if success, or an error code, which can be tested using ZSTD_isError() */ static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx* zc, const void* src, size_t srcSize) { - size_t result = ZSTD_getFrameParams(&(zc->fParams), src, srcSize); + size_t const result = ZSTD_getFrameParams(&(zc->fParams), src, srcSize); if ((MEM_32bits()) && (zc->fParams.windowLog > 25)) return ERROR(frameParameter_unsupportedBy32bits); return result; } diff --git a/programs/bench.c b/programs/bench.c index 7acfcca36..2ee3c4172 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -282,6 +282,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, testNb, displayName, (U32)srcSize, (U32)cSize, ratio, (double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC) ); + (void)crcCheck; (void)fastestD; (void)crcOrig; /* unused when decompression disabled */ #if 0 /* Decompression */ memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */