slightly improved weight calculation
translating into a tiny compression ratio improvement
This commit is contained in:
@@ -1977,7 +1977,7 @@ static void ZSTD_storeLastLiterals(seqStore_t* seqStorePtr,
|
|||||||
seqStorePtr->lit += lastLLSize;
|
seqStorePtr->lit += lastLLSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZSTD_resetSeqStore(seqStore_t* ssPtr)
|
void ZSTD_resetSeqStore(seqStore_t* ssPtr)
|
||||||
{
|
{
|
||||||
ssPtr->lit = ssPtr->litStart;
|
ssPtr->lit = ssPtr->litStart;
|
||||||
ssPtr->sequences = ssPtr->sequencesStart;
|
ssPtr->sequences = ssPtr->sequencesStart;
|
||||||
|
|||||||
@@ -80,12 +80,12 @@ typedef enum { zop_dynamic=0, zop_predef } ZSTD_OptPrice_e;
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
|
/* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
|
||||||
U32* litFreq; /* table of literals statistics, of size 256 */
|
U32* litFreq; /* table of literals statistics, of size 256 */
|
||||||
U32* litLengthFreq; /* table of litLength statistics, of size (MaxLL+1) */
|
U32* litLengthFreq; /* table of litLength statistics, of size (MaxLL+1) */
|
||||||
U32* matchLengthFreq; /* table of matchLength statistics, of size (MaxML+1) */
|
U32* matchLengthFreq; /* table of matchLength statistics, of size (MaxML+1) */
|
||||||
U32* offCodeFreq; /* table of offCode statistics, of size (MaxOff+1) */
|
U32* offCodeFreq; /* table of offCode statistics, of size (MaxOff+1) */
|
||||||
ZSTD_match_t* matchTable; /* list of found matches, of size ZSTD_OPT_NUM+1 */
|
ZSTD_match_t* matchTable; /* list of found matches, of size ZSTD_OPT_NUM+1 */
|
||||||
ZSTD_optimal_t* priceTable; /* All positions tracked by optimal parser, of size ZSTD_OPT_NUM+1 */
|
ZSTD_optimal_t* priceTable; /* All positions tracked by optimal parser, of size ZSTD_OPT_NUM+1 */
|
||||||
|
|
||||||
U32 litSum; /* nb of literals */
|
U32 litSum; /* nb of literals */
|
||||||
U32 litLengthSum; /* nb of litLength codes */
|
U32 litLengthSum; /* nb of litLength codes */
|
||||||
@@ -658,6 +658,8 @@ size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs,
|
|||||||
const ZSTD_CDict* cdict,
|
const ZSTD_CDict* cdict,
|
||||||
ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
|
ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
|
||||||
|
|
||||||
|
void ZSTD_resetSeqStore(seqStore_t* ssPtr);
|
||||||
|
|
||||||
/*! ZSTD_compressStream_generic() :
|
/*! ZSTD_compressStream_generic() :
|
||||||
* Private use only. To be called from zstdmt_compress.c in single-thread mode. */
|
* Private use only. To be called from zstdmt_compress.c in single-thread mode. */
|
||||||
size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
||||||
|
|||||||
@@ -25,29 +25,29 @@
|
|||||||
# define BITCOST_ACCURACY 0
|
# define BITCOST_ACCURACY 0
|
||||||
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
||||||
# define WEIGHT(stat) ((void)opt, ZSTD_bitWeight(stat))
|
# define WEIGHT(stat) ((void)opt, ZSTD_bitWeight(stat))
|
||||||
#elif 0 /* fractional bit accuracy */
|
#elif 1 /* fractional bit accuracy */
|
||||||
# define BITCOST_ACCURACY 8
|
# define BITCOST_ACCURACY 8
|
||||||
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
||||||
# define WEIGHT(stat,opt) ((void)opt, ZSTD_fracWeight(stat))
|
# define WEIGHT(stat,opt) ((void)opt, ZSTD_fracWeight(stat))
|
||||||
#else /* opt==approx, ultra==accurate */
|
#else /* opt==approx, ultra==accurate */
|
||||||
# define BITCOST_ACCURACY 8
|
# define BITCOST_ACCURACY 8
|
||||||
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
# define BITCOST_MULTIPLIER (1 << BITCOST_ACCURACY)
|
||||||
# define WEIGHT(stat,opt) (opt ? ZSTD_fracWeight(stat) : ZSTD_bitWeight(stat) )
|
# define WEIGHT(stat,opt) (opt ? ZSTD_fracWeight(stat) : ZSTD_bitWeight(stat))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MEM_STATIC U32 ZSTD_bitWeight(U32 stat)
|
MEM_STATIC U32 ZSTD_bitWeight(U32 stat)
|
||||||
{
|
{
|
||||||
return (ZSTD_highbit32((stat)+1) * BITCOST_MULTIPLIER);
|
return (ZSTD_highbit32(stat+1) * BITCOST_MULTIPLIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC U32 ZSTD_fracWeight(U32 stat)
|
MEM_STATIC U32 ZSTD_fracWeight(U32 rawStat)
|
||||||
{
|
{
|
||||||
U32 const hb = stat ? ZSTD_highbit32(stat) : 0;
|
U32 const stat = rawStat + 1;
|
||||||
|
U32 const hb = ZSTD_highbit32(stat);
|
||||||
U32 const BWeight = hb * BITCOST_MULTIPLIER;
|
U32 const BWeight = hb * BITCOST_MULTIPLIER;
|
||||||
U32 const FWeight = (stat << BITCOST_ACCURACY) >> hb;
|
U32 const FWeight = (stat << BITCOST_ACCURACY) >> hb;
|
||||||
U32 const weight = BWeight + FWeight;
|
U32 const weight = BWeight + FWeight;
|
||||||
assert(hb + BITCOST_ACCURACY < 31);
|
assert(hb + BITCOST_ACCURACY < 31);
|
||||||
DEBUGLOG(2, "stat=%u, hb=%u, weight=%u", stat, hb, weight)
|
|
||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user