Lines Matching defs:optPtr

66 static int ZSTD_compressedLiterals(optState_t const* const optPtr)
68 return optPtr->literalCompressionMode != ZSTD_ps_disable;
71 static void ZSTD_setBasePrices(optState_t* optPtr, int optLevel)
73 if (ZSTD_compressedLiterals(optPtr))
74 optPtr->litSumBasePrice = WEIGHT(optPtr->litSum, optLevel);
75 optPtr->litLengthSumBasePrice = WEIGHT(optPtr->litLengthSum, optLevel);
76 optPtr->matchLengthSumBasePrice = WEIGHT(optPtr->matchLengthSum, optLevel);
77 optPtr->offCodeSumBasePrice = WEIGHT(optPtr->offCodeSum, optLevel);
117 * if first block (detected by optPtr->litLengthSum == 0) : init statistics
124 ZSTD_rescaleFreqs(optState_t* const optPtr,
128 int const compressedLiterals = ZSTD_compressedLiterals(optPtr);
130 optPtr->priceType = zop_dynamic;
132 if (optPtr->litLengthSum == 0) { /* first block : init */
135 optPtr->priceType = zop_predef;
138 assert(optPtr->symbolCosts != NULL);
139 if (optPtr->symbolCosts->huf.repeatMode == HUF_repeat_valid) {
141 optPtr->priceType = zop_dynamic;
145 assert(optPtr->litFreq != NULL);
146 optPtr->litSum = 0;
149 U32 const bitCost = HUF_getNbBitsFromCTable(optPtr->symbolCosts->huf.CTable, lit);
151 optPtr->litFreq[lit] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
152 optPtr->litSum += optPtr->litFreq[lit];
157 FSE_initCState(&llstate, optPtr->symbolCosts->fse.litlengthCTable);
158 optPtr->litLengthSum = 0;
163 optPtr->litLengthFreq[ll] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
164 optPtr->litLengthSum += optPtr->litLengthFreq[ll];
169 FSE_initCState(&mlstate, optPtr->symbolCosts->fse.matchlengthCTable);
170 optPtr->matchLengthSum = 0;
175 optPtr->matchLengthFreq[ml] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
176 optPtr->matchLengthSum += optPtr->matchLengthFreq[ml];
181 FSE_initCState(&ofstate, optPtr->symbolCosts->fse.offcodeCTable);
182 optPtr->offCodeSum = 0;
187 optPtr->offCodeFreq[of] = bitCost ? 1 << (scaleLog-bitCost) : 1 /*minimum to calculate cost*/;
188 optPtr->offCodeSum += optPtr->offCodeFreq[of];
193 assert(optPtr->litFreq != NULL);
196 HIST_count_simple(optPtr->litFreq, &lit, src, srcSize); /* use raw first block to init statistics */
197 optPtr->litSum = ZSTD_downscaleStats(optPtr->litFreq, MaxLit, 8);
207 ZSTD_memcpy(optPtr->litLengthFreq, baseLLfreqs, sizeof(baseLLfreqs));
208 optPtr->litLengthSum = sum_u32(baseLLfreqs, MaxLL+1);
213 optPtr->matchLengthFreq[ml] = 1;
215 optPtr->matchLengthSum = MaxML+1;
223 ZSTD_memcpy(optPtr->offCodeFreq, baseOFCfreqs, sizeof(baseOFCfreqs));
224 optPtr->offCodeSum = sum_u32(baseOFCfreqs, MaxOff+1);
233 optPtr->litSum = ZSTD_scaleStats(optPtr->litFreq, MaxLit, 12);
234 optPtr->litLengthSum = ZSTD_scaleStats(optPtr->litLengthFreq, MaxLL, 11);
235 optPtr->matchLengthSum = ZSTD_scaleStats(optPtr->matchLengthFreq, MaxML, 11);
236 optPtr->offCodeSum = ZSTD_scaleStats(optPtr->offCodeFreq, MaxOff, 11);
239 ZSTD_setBasePrices(optPtr, optLevel);
246 const optState_t* const optPtr,
251 if (!ZSTD_compressedLiterals(optPtr))
254 if (optPtr->priceType == zop_predef)
258 { U32 price = litLength * optPtr->litSumBasePrice;
261 assert(WEIGHT(optPtr->litFreq[literals[u]], optLevel) <= optPtr->litSumBasePrice); /* literal cost should never be negative */
262 price -= WEIGHT(optPtr->litFreq[literals[u]], optLevel);
270 static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optPtr, int optLevel)
273 if (optPtr->priceType == zop_predef)
281 return BITCOST_MULTIPLIER + ZSTD_litLengthPrice(ZSTD_BLOCKSIZE_MAX - 1, optPtr, optLevel);
286 + optPtr->litLengthSumBasePrice
287 - WEIGHT(optPtr->litLengthFreq[llCode], optLevel);
300 const optState_t* const optPtr,
308 if (optPtr->priceType == zop_predef) /* fixed scheme, do not use statistics */
312 price = (offCode * BITCOST_MULTIPLIER) + (optPtr->offCodeSumBasePrice - WEIGHT(optPtr->offCodeFreq[offCode], optLevel));
318 price += (ML_bits[mlCode] * BITCOST_MULTIPLIER) + (optPtr->matchLengthSumBasePrice - WEIGHT(optPtr->matchLengthFreq[mlCode], optLevel));
329 static void ZSTD_updateStats(optState_t* const optPtr,
334 if (ZSTD_compressedLiterals(optPtr)) {
337 optPtr->litFreq[literals[u]] += ZSTD_LITFREQ_ADD;
338 optPtr->litSum += litLength*ZSTD_LITFREQ_ADD;
343 optPtr->litLengthFreq[llCode]++;
344 optPtr->litLengthSum++;
350 optPtr->offCodeFreq[offCode]++;
351 optPtr->offCodeSum++;
357 optPtr->matchLengthFreq[mlCode]++;
358 optPtr->matchLengthSum++;