unsigned u;
if (srcSize <= 1024) optPtr->priceType = zop_predef;
assert(optPtr->symbolCosts != NULL);
- if (0 && optPtr->symbolCosts->hufCTable_repeatMode == HUF_repeat_valid) { /* huffman table presumed generated by dictionary */
+ if (optPtr->symbolCosts->hufCTable_repeatMode == HUF_repeat_valid) { /* huffman table presumed generated by dictionary */
optPtr->priceType = zop_static;
}
* cost of literalLength symbol */
static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optPtr)
{
+ if (optPtr->priceType == zop_static) {
+ U32 const llCode = ZSTD_LLcode(litLength);
+ FSE_CState_t cstate;
+ FSE_initCState(&cstate, optPtr->symbolCosts->litlengthCTable);
+ return LL_bits[llCode] + FSE_getMaxNbBits(cstate.symbolTT, llCode);
+ }
if (optPtr->priceType == zop_predef) return ZSTD_highbit32((U32)litLength+1);
/* literal Length */
{ U32 const llCode = ZSTD_LLcode(litLength);
- U32 const price = LL_bits[llCode] + optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[llCode]+1);
- return price;
+ return LL_bits[llCode] + optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[llCode]+1);
}
}
* 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)
{
- if (optPtr->priceType == zop_predef) return ZSTD_highbit32(litLength+1);
+ if (optPtr->priceType == zop_static) {
+ U32 const llCode = ZSTD_LLcode(litLength);
+ FSE_CState_t cstate;
+ FSE_initCState(&cstate, optPtr->symbolCosts->litlengthCTable);
+ return (int)(LL_bits[llCode] + FSE_getMaxNbBits(cstate.symbolTT, llCode)) - FSE_getMaxNbBits(cstate.symbolTT, 0);
+ }
+ if (optPtr->priceType >= zop_predef) return ZSTD_highbit32(litLength+1);
/* literal Length */
{ U32 const llCode = ZSTD_LLcode(litLength);
U32 const mlBase = matchLength - MINMATCH;
assert(matchLength >= MINMATCH);
+ if (optPtr->priceType == zop_static) {
+ U32 const mlCode = ZSTD_MLcode(mlBase);
+ FSE_CState_t mlstate, offstate;
+ FSE_initCState(&mlstate, optPtr->symbolCosts->matchlengthCTable);
+ FSE_initCState(&offstate, optPtr->symbolCosts->offcodeCTable);
+ return FSE_getMaxNbBits(offstate.symbolTT, offCode) + offCode
+ + FSE_getMaxNbBits(mlstate.symbolTT, mlCode) + ML_bits[mlCode];
+ }
+
if (optPtr->priceType == zop_predef) /* fixed scheme, do not use statistics */
return ZSTD_highbit32(mlBase+1) + 16 + offCode;