mirror of
https://github.com/facebook/zstd.git
synced 2025-10-18 00:03:50 -04:00
more accurate gain function
This commit is contained in:
parent
ee55628c9d
commit
02137f8c42
@ -37,26 +37,26 @@
|
|||||||
FORCE_INLINE U32 ZSTD_GETPRICE(seqStore_t* seqStorePtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength)
|
FORCE_INLINE U32 ZSTD_GETPRICE(seqStore_t* seqStorePtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength)
|
||||||
{
|
{
|
||||||
/* offset */
|
/* offset */
|
||||||
BYTE offCode = offset ? (BYTE)ZSTD_highbit(offset) + 1 : 0;
|
BYTE offCode = offset ? (BYTE)ZSTD_highbit(offset+1) + 1 : 0;
|
||||||
U32 price = offCode + ZSTD_highbit(seqStorePtr->offCodeSum) - ZSTD_highbit(seqStorePtr->offCodeFreq[offCode]);
|
U32 price = (offCode-1) + (!offCode) + ZSTD_highbit(seqStorePtr->offCodeSum+1) - ZSTD_highbit(seqStorePtr->offCodeFreq[offCode]+1);
|
||||||
|
|
||||||
/* match Length */
|
/* match Length */
|
||||||
matchLength -= MINMATCHOPT;
|
matchLength -= MINMATCHOPT;
|
||||||
price += ((matchLength >= MaxML)<<3) + ((matchLength >= 255+MaxML)<<4) + ((matchLength>=(1<<15))<<3);
|
price += ((matchLength >= MaxML)<<3) + ((matchLength >= 255+MaxML)<<4) + ((matchLength>=(1<<15))<<3);
|
||||||
if (matchLength >= MaxML) matchLength = MaxML;
|
if (matchLength >= MaxML) matchLength = MaxML;
|
||||||
price += ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ZSTD_highbit(seqStorePtr->matchLengthSum) - ZSTD_highbit(seqStorePtr->matchLengthFreq[matchLength]);
|
price += ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ZSTD_highbit(seqStorePtr->matchLengthSum+1) - ZSTD_highbit(seqStorePtr->matchLengthFreq[matchLength]+1);
|
||||||
|
|
||||||
switch (seqStorePtr->priceFunc)
|
switch (seqStorePtr->priceFunc)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case 0:
|
case 0:
|
||||||
return price + seqStorePtr->factor + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum));
|
return 1 + price + seqStorePtr->factor + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum));
|
||||||
case 1:
|
case 1:
|
||||||
return price + seqStorePtr->factor + ((seqStorePtr->factor2) ? ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum)) : 0);
|
return 1 + price + seqStorePtr->factor + ((seqStorePtr->factor2) ? ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum)) : 0);
|
||||||
case 2:
|
case 2:
|
||||||
return price + seqStorePtr->factor + ((seqStorePtr->factor2) ? ((seqStorePtr->litSum>>4) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum)) : 0);
|
return 1 + price + seqStorePtr->factor + ((seqStorePtr->factor2) ? ((seqStorePtr->litSum>>4) / seqStorePtr->litLengthSum) + ((seqStorePtr->litSum<<1) / (seqStorePtr->litSum + seqStorePtr->matchSum)) : 0);
|
||||||
case 3:
|
case 3:
|
||||||
return price;
|
return 1 + price;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
#define ZSTD_LOG_TRY_PRICE(...) printf(__VA_ARGS__)
|
#define ZSTD_LOG_TRY_PRICE(...) printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define ZSTD_LOG_PARSER(...)
|
#define ZSTD_LOG_PARSER(...)
|
||||||
#define ZSTD_LOG_ENCODE(...)
|
#define ZSTD_LOG_ENCODE(...) // printf(__VA_ARGS__)
|
||||||
#define ZSTD_LOG_TRY_PRICE(...)
|
#define ZSTD_LOG_TRY_PRICE(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const B
|
|||||||
|
|
||||||
/* match offset */
|
/* match offset */
|
||||||
seqStorePtr->offCodeSum += ZSTD_FREQ_STEP;
|
seqStorePtr->offCodeSum += ZSTD_FREQ_STEP;
|
||||||
BYTE offCode = offset ? (BYTE)ZSTD_highbit(offset) + 1 : 0;
|
BYTE offCode = offset ? (BYTE)ZSTD_highbit(offset+1) + 1 : 0;
|
||||||
seqStorePtr->offCodeFreq[offCode] += ZSTD_FREQ_STEP;
|
seqStorePtr->offCodeFreq[offCode] += ZSTD_FREQ_STEP;
|
||||||
|
|
||||||
/* match Length */
|
/* match Length */
|
||||||
@ -152,17 +152,17 @@ FORCE_INLINE U32 ZSTD_getLiteralPrice(seqStore_t* seqStorePtr, U32 litLength, co
|
|||||||
U32 price, u;
|
U32 price, u;
|
||||||
|
|
||||||
if (litLength == 0)
|
if (litLength == 0)
|
||||||
return ZSTD_highbit(seqStorePtr->litLengthSum) - ZSTD_highbit(seqStorePtr->litLengthFreq[0]);
|
return ZSTD_highbit(seqStorePtr->litLengthSum+1) - ZSTD_highbit(seqStorePtr->litLengthFreq[0]+1);
|
||||||
|
|
||||||
/* literals */
|
/* literals */
|
||||||
price = litLength * ZSTD_highbit(seqStorePtr->litSum);
|
price = litLength * ZSTD_highbit(seqStorePtr->litSum+1);
|
||||||
for (u=0; u < litLength; u++)
|
for (u=0; u < litLength; u++)
|
||||||
price -= ZSTD_highbit(seqStorePtr->litFreq[literals[u]]);
|
price -= ZSTD_highbit(seqStorePtr->litFreq[literals[u]]+1);
|
||||||
|
|
||||||
/* literal Length */
|
/* literal Length */
|
||||||
price += ((litLength >= MaxLL)<<3) + ((litLength >= 255+MaxLL)<<4) + ((litLength>=(1<<15))<<3);
|
price += ((litLength >= MaxLL)<<3) + ((litLength >= 255+MaxLL)<<4) + ((litLength>=(1<<15))<<3);
|
||||||
if (litLength >= MaxLL) litLength = MaxLL;
|
if (litLength >= MaxLL) litLength = MaxLL;
|
||||||
price += ZSTD_highbit(seqStorePtr->litLengthSum) - ZSTD_highbit(seqStorePtr->litLengthFreq[litLength]);
|
price += ZSTD_highbit(seqStorePtr->litLengthSum+1) - ZSTD_highbit(seqStorePtr->litLengthFreq[litLength]+1);
|
||||||
|
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user