22 0, 2048, 1792, 1642, 1536, 1453, 1386, 1329, 1280, 1236, 1197, 1162,
23 1130, 1100, 1073, 1047, 1024, 1001, 980, 960, 941, 923, 906, 889,
24 874, 859, 844, 830, 817, 804, 791, 779, 768, 756, 745, 734,
25 724, 714, 704, 694, 685, 676, 667, 658, 650, 642, 633, 626,
26 618, 610, 603, 595, 588, 581, 574, 567, 561, 554, 548, 542,
27 535, 529, 523, 517, 512, 506, 500, 495, 489, 484, 478, 473,
28 468, 463, 458, 453, 448, 443, 438, 434, 429, 424, 420, 415,
29 411, 407, 402, 398, 394, 390, 386, 382, 377, 373, 370, 366,
30 362, 358, 354, 350, 347, 343, 339, 336, 332, 329, 325, 322,
31 318, 315, 311, 308, 305, 302, 298, 295, 292, 289, 286, 282,
32 279, 276, 273, 270, 267, 264, 261, 258, 256, 253, 250, 247,
33 244, 241, 239, 236, 233, 230, 228, 225, 222, 220, 217, 215,
34 212, 209, 207, 204, 202, 199, 197, 194, 192, 190, 187, 185,
35 182, 180, 178, 175, 173, 171, 168, 166, 164, 162, 159, 157,
36 155, 153, 151, 149, 146, 144, 142, 140, 138, 136, 134, 132,
37 130, 128, 126, 123, 121, 119, 117, 115, 114, 112, 110, 108,
38 106, 104, 102, 100, 98, 96, 94, 93, 91, 89, 87, 85,
39 83, 82, 80, 78, 76, 74, 73, 71, 69, 67, 66, 64,
40 62, 61, 59, 57, 55, 54, 52, 50, 49, 47, 46, 44,
41 42, 41, 39, 37, 36, 34, 33, 31, 30, 28, 26, 25,
42 23, 22, 20, 19, 17, 16, 14, 13, 11, 10, 8, 7,
50 return maxSymbolValue;
58 size_t const nbSeq,
unsigned const FSELog)
60 BYTE wksp[FSE_NCOUNTBOUND];
75 for (
s = 0;
s <=
max; ++
s) {
91 unsigned const*
count,
94 unsigned const kAccuracyLog = 8;
100 DEBUGLOG(5,
"Repeat FSE_CTable has maxSymbolValue %u < %u",
102 return ERROR(GENERIC);
104 for (
s = 0;
s <=
max; ++
s) {
105 unsigned const tableLog =
cstate.stateLog;
106 unsigned const badCost = (tableLog + 1) << kAccuracyLog;
107 unsigned const bitCost = FSE_bitCost(
cstate.symbolTT, tableLog,
s, kAccuracyLog);
110 if (bitCost >= badCost) {
111 DEBUGLOG(5,
"Repeat FSE_CTable has Prob[%u] == 0",
s);
112 return ERROR(GENERIC);
116 return cost >> kAccuracyLog;
125 unsigned const*
count,
unsigned const max)
127 unsigned const shift = 8 - accuracyLog;
131 for (
s = 0;
s <=
max; ++
s) {
132 unsigned const normAcc = (
norm[
s] != -1) ? (
unsigned)
norm[
s] : 1;
133 unsigned const norm256 = normAcc <<
shift;
143 FSE_repeat* repeatMode,
unsigned const*
count,
unsigned const max,
144 size_t const mostFrequent,
size_t nbSeq,
unsigned const FSELog,
146 short const* defaultNorm,
U32 defaultNormLog,
151 if (mostFrequent == nbSeq) {
152 *repeatMode = FSE_repeat_none;
153 if (isDefaultAllowed && nbSeq <= 2) {
165 if (isDefaultAllowed) {
166 size_t const staticFse_nbSeq_max = 1000;
167 size_t const mult = 10 - strategy;
168 size_t const baseLog = 3;
169 size_t const dynamicFse_nbSeq_min = (((
size_t)1 << defaultNormLog) * mult) >> baseLog;
170 assert(defaultNormLog >= 5 && defaultNormLog <= 6);
171 assert(mult <= 9 && mult >= 7);
172 if ( (*repeatMode == FSE_repeat_valid)
173 && (nbSeq < staticFse_nbSeq_max) ) {
177 if ( (nbSeq < dynamicFse_nbSeq_min)
178 || (mostFrequent < (nbSeq >> (defaultNormLog-1))) ) {
186 *repeatMode = FSE_repeat_none;
196 if (isDefaultAllowed) {
202 DEBUGLOG(5,
"Estimated bit costs: basic=%u\trepeat=%u\tcompressed=%u",
203 (
unsigned)basicCost, (
unsigned)repeatCost, (
unsigned)compressedCost);
204 if (basicCost <= repeatCost && basicCost <= compressedCost) {
207 *repeatMode = FSE_repeat_none;
210 if (repeatCost <= compressedCost) {
215 assert(compressedCost < basicCost && compressedCost < repeatCost);
217 DEBUGLOG(5,
"Selected set_compressed");
218 *repeatMode = FSE_repeat_check;
226 const BYTE* codeTable,
size_t nbSeq,
227 const S16* defaultNorm,
U32 defaultNormLog,
U32 defaultMax,
228 const FSE_CTable* prevCTable,
size_t prevCTableSize,
229 void* entropyWorkspace,
size_t entropyWorkspaceSize)
232 const BYTE*
const oend =
op + dstCapacity;
233 DEBUGLOG(6,
"ZSTD_buildCTable (dstCapacity=%u)", (
unsigned)dstCapacity);
242 memcpy(nextCTable, prevCTable, prevCTableSize);
249 size_t nbSeq_1 = nbSeq;
251 if (
count[codeTable[nbSeq-1]] > 1) {
252 count[codeTable[nbSeq-1]]--;
269 void*
dst,
size_t dstCapacity,
276 FSE_CState_t stateMatchLength;
277 FSE_CState_t stateOffsetBits;
278 FSE_CState_t stateLitLength;
282 dstSize_tooSmall,
"not enough space remaining");
283 DEBUGLOG(6,
"available space for bitstream : %i (dstCapacity=%u)",
285 (
unsigned)dstCapacity);
288 FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq-1]);
289 FSE_initCState2(&stateOffsetBits, CTable_OffsetBits, ofCodeTable[nbSeq-1]);
290 FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]);
296 U32 const ofBits = ofCodeTable[nbSeq-1];
310 for (
n=nbSeq-2 ;
n<nbSeq ;
n--) {
311 BYTE const llCode = llCodeTable[
n];
312 BYTE const ofCode = ofCodeTable[
n];
313 BYTE const mlCode = mlCodeTable[
n];
315 U32 const ofBits = ofCode;
317 DEBUGLOG(6,
"encoding: litlen:%2u - matchlen:%2u - offCode:%7u",
323 FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode);
324 FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode);
326 FSE_encodeSymbol(&blockStream, &stateLitLength, llCode);
345 DEBUGLOG(7,
"remaining space : %i", (
int)(blockStream.
endPtr - blockStream.
ptr));
348 DEBUGLOG(6,
"ZSTD_encodeSequences: flushing ML state with %u bits", stateMatchLength.stateLog);
349 FSE_flushCState(&blockStream, &stateMatchLength);
350 DEBUGLOG(6,
"ZSTD_encodeSequences: flushing Off state with %u bits", stateOffsetBits.stateLog);
351 FSE_flushCState(&blockStream, &stateOffsetBits);
352 DEBUGLOG(6,
"ZSTD_encodeSequences: flushing LL state with %u bits", stateLitLength.stateLog);
353 FSE_flushCState(&blockStream, &stateLitLength);
363 void*
dst,
size_t dstCapacity,
370 CTable_MatchLength, mlCodeTable,
371 CTable_OffsetBits, ofCodeTable,
372 CTable_LitLength, llCodeTable,
380ZSTD_encodeSequences_bmi2(
381 void*
dst,
size_t dstCapacity,
388 CTable_MatchLength, mlCodeTable,
389 CTable_OffsetBits, ofCodeTable,
390 CTable_LitLength, llCodeTable,
397 void*
dst,
size_t dstCapacity,
403 DEBUGLOG(5,
"ZSTD_encodeSequences: dstCapacity = %u", (
unsigned)dstCapacity);
406 return ZSTD_encodeSequences_bmi2(
dst, dstCapacity,
407 CTable_MatchLength, mlCodeTable,
408 CTable_OffsetBits, ofCodeTable,
409 CTable_LitLength, llCodeTable,
415 CTable_MatchLength, mlCodeTable,
416 CTable_OffsetBits, ofCodeTable,
417 CTable_LitLength, llCodeTable,
#define RETURN_ERROR(StatusCode)
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t *bitC)
MEM_STATIC void BIT_flushBits(BIT_CStream_t *bitC)
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t *bitC, void *dstBuffer, size_t dstCapacity)
MEM_STATIC void BIT_addBits(BIT_CStream_t *bitC, size_t value, unsigned nbBits)
#define STREAM_ACCUMULATOR_MIN
static _Locale_mask_t ctable[256]
#define TARGET_ATTRIBUTE(target)
MEM_STATIC unsigned MEM_32bits(void)
MEM_STATIC U16 MEM_read16(const void *memPtr)
ERR_STATIC unsigned ERR_isError(size_t code)
FSE_PUBLIC_API size_t FSE_writeNCount(void *buffer, size_t bufferSize, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API size_t FSE_normalizeCount(short *normalizedCounter, unsigned tableLog, const unsigned *count, size_t srcSize, unsigned maxSymbolValue)
FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue)
size_t FSE_buildCTable_wksp(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize)
size_t FSE_buildCTable_rle(FSE_CTable *ct, BYTE symbolValue)
GLuint GLuint GLsizei GLenum type
GLuint GLuint GLsizei count
#define memcpy(s1, s2, n)
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define FORCE_INLINE_TEMPLATE
static size_t ZSTD_encodeSequences_default(void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets)
size_t ZSTD_crossEntropyCost(short const *norm, unsigned accuracyLog, unsigned const *count, unsigned const max)
static size_t ZSTD_entropyCost(unsigned const *count, unsigned const max, size_t const total)
static unsigned const kInverseProbabilityLog256[256]
FORCE_INLINE_TEMPLATE size_t ZSTD_encodeSequences_body(void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets)
static size_t ZSTD_NCountCost(unsigned const *count, unsigned const max, size_t const nbSeq, unsigned const FSELog)
size_t ZSTD_fseBitCost(FSE_CTable const *ctable, unsigned const *count, unsigned const max)
size_t ZSTD_buildCTable(void *dst, size_t dstCapacity, FSE_CTable *nextCTable, U32 FSELog, symbolEncodingType_e type, unsigned *count, U32 max, const BYTE *codeTable, size_t nbSeq, const S16 *defaultNorm, U32 defaultNormLog, U32 defaultMax, const FSE_CTable *prevCTable, size_t prevCTableSize, void *entropyWorkspace, size_t entropyWorkspaceSize)
symbolEncodingType_e ZSTD_selectEncodingType(FSE_repeat *repeatMode, unsigned const *count, unsigned const max, size_t const mostFrequent, size_t nbSeq, unsigned const FSELog, FSE_CTable const *prevCTable, short const *defaultNorm, U32 defaultNormLog, ZSTD_defaultPolicy_e const isDefaultAllowed, ZSTD_strategy const strategy)
size_t ZSTD_encodeSequences(void *dst, size_t dstCapacity, FSE_CTable const *CTable_MatchLength, BYTE const *mlCodeTable, FSE_CTable const *CTable_OffsetBits, BYTE const *ofCodeTable, FSE_CTable const *CTable_LitLength, BYTE const *llCodeTable, seqDef const *sequences, size_t nbSeq, int longOffsets, int bmi2)
static unsigned ZSTD_getFSEMaxSymbolValue(FSE_CTable const *ctable)
#define FORWARD_IF_ERROR(err,...)
#define RETURN_ERROR_IF(cond, err,...)
static const U32 ML_bits[MaxML+1]
static const U32 LL_bits[MaxLL+1]
#define ZSTD_STATIC_ASSERT(c)