MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ZSTD_encodeSequences_body

Function ZSTD_encodeSequences_body

freebsd/contrib/openzfs/module/zstd/lib/zstd.c:11521–11613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11519}
11520
11521FORCE_INLINE_TEMPLATE size_t
11522ZSTD_encodeSequences_body(
11523 void* dst, size_t dstCapacity,
11524 FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable,
11525 FSE_CTable const* CTable_OffsetBits, BYTE const* ofCodeTable,
11526 FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
11527 seqDef const* sequences, size_t nbSeq, int longOffsets)
11528{
11529 BIT_CStream_t blockStream;
11530 FSE_CState_t stateMatchLength;
11531 FSE_CState_t stateOffsetBits;
11532 FSE_CState_t stateLitLength;
11533
11534 RETURN_ERROR_IF(
11535 ERR_isError(BIT_initCStream(&blockStream, dst, dstCapacity)),
11536 dstSize_tooSmall, "not enough space remaining");
11537 DEBUGLOG(6, "available space for bitstream : %i (dstCapacity=%u)",
11538 (int)(blockStream.endPtr - blockStream.startPtr),
11539 (unsigned)dstCapacity);
11540
11541 /* first symbols */
11542 FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq-1]);
11543 FSE_initCState2(&stateOffsetBits, CTable_OffsetBits, ofCodeTable[nbSeq-1]);
11544 FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]);
11545 BIT_addBits(&blockStream, sequences[nbSeq-1].litLength, LL_bits[llCodeTable[nbSeq-1]]);
11546 if (MEM_32bits()) BIT_flushBits(&blockStream);
11547 BIT_addBits(&blockStream, sequences[nbSeq-1].matchLength, ML_bits[mlCodeTable[nbSeq-1]]);
11548 if (MEM_32bits()) BIT_flushBits(&blockStream);
11549 if (longOffsets) {
11550 U32 const ofBits = ofCodeTable[nbSeq-1];
11551 unsigned const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
11552 if (extraBits) {
11553 BIT_addBits(&blockStream, sequences[nbSeq-1].offset, extraBits);
11554 BIT_flushBits(&blockStream);
11555 }
11556 BIT_addBits(&blockStream, sequences[nbSeq-1].offset >> extraBits,
11557 ofBits - extraBits);
11558 } else {
11559 BIT_addBits(&blockStream, sequences[nbSeq-1].offset, ofCodeTable[nbSeq-1]);
11560 }
11561 BIT_flushBits(&blockStream);
11562
11563 { size_t n;
11564 for (n=nbSeq-2 ; n<nbSeq ; n--) { /* intentional underflow */
11565 BYTE const llCode = llCodeTable[n];
11566 BYTE const ofCode = ofCodeTable[n];
11567 BYTE const mlCode = mlCodeTable[n];
11568 U32 const llBits = LL_bits[llCode];
11569 U32 const ofBits = ofCode;
11570 U32 const mlBits = ML_bits[mlCode];
11571 DEBUGLOG(6, "encoding: litlen:%2u - matchlen:%2u - offCode:%7u",
11572 (unsigned)sequences[n].litLength,
11573 (unsigned)sequences[n].matchLength + MINMATCH,
11574 (unsigned)sequences[n].offset);
11575 /* 32b*/ /* 64b*/
11576 /* (7)*/ /* (7)*/
11577 FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */
11578 FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode); /* 24 */ /* 24 */

Callers 2

Calls 9

ERR_isErrorFunction · 0.70
BIT_initCStreamFunction · 0.70
FSE_initCState2Function · 0.70
BIT_addBitsFunction · 0.70
MEM_32bitsFunction · 0.70
BIT_flushBitsFunction · 0.70
FSE_encodeSymbolFunction · 0.70
FSE_flushCStateFunction · 0.70
BIT_closeCStreamFunction · 0.70

Tested by

no test coverage detected