19 U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
39 DEBUGLOG(5,
"Raw literals: %u -> %u", (
U32)srcSize, (
U32)(srcSize + flSize));
40 return srcSize + flSize;
46 U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
65 ostart[flSize] = *(
const BYTE*)
src;
66 DEBUGLOG(5,
"RLE literals: %u -> %u", (
U32)srcSize, (
U32)flSize + 1);
73 void*
dst,
size_t dstCapacity,
74 const void*
src,
size_t srcSize,
75 void* entropyWorkspace,
size_t entropyWorkspaceSize,
79 size_t const lhSize = 3 + (srcSize >= 1
KB) + (srcSize >= 16
KB);
81 U32 singleStream = srcSize < 256;
85 DEBUGLOG(5,
"ZSTD_compressLiterals (disableLiteralCompression=%i srcSize=%u)",
86 disableLiteralCompression, (
U32)srcSize);
89 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
91 if (disableLiteralCompression)
95# define COMPRESS_LITERALS_SIZE_MIN 63
100 RETURN_ERROR_IF(dstCapacity < lhSize+1, dstSize_tooSmall,
"not enough space for compression");
102 int const preferRepeat = strategy <
ZSTD_lazy ? srcSize <= 1024 : 0;
103 if (
repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
104 cLitSize = singleStream ?
106 ostart+lhSize, dstCapacity-lhSize,
src, srcSize,
107 HUF_SYMBOLVALUE_MAX, HUF_TABLELOG_DEFAULT, entropyWorkspace, entropyWorkspaceSize,
108 (HUF_CElt*)nextHuf->
CTable, &
repeat, preferRepeat, bmi2) :
110 ostart+lhSize, dstCapacity-lhSize,
src, srcSize,
111 HUF_SYMBOLVALUE_MAX, HUF_TABLELOG_DEFAULT, entropyWorkspace, entropyWorkspaceSize,
112 (HUF_CElt*)nextHuf->
CTable, &
repeat, preferRepeat, bmi2);
113 if (
repeat != HUF_repeat_none) {
115 DEBUGLOG(5,
"Reusing previous huffman table");
120 if ((cLitSize==0) | (cLitSize >= srcSize - minGain) |
ERR_isError(cLitSize)) {
121 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
125 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
138 {
U32 const lhc = hType + ((!singleStream) << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<14);
143 {
U32 const lhc = hType + (2 << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<18);
148 {
U32 const lhc = hType + (3 << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<22);
150 ostart[4] = (
BYTE)(cLitSize >> 10);
156 DEBUGLOG(5,
"Compressed literals: %u -> %u", (
U32)srcSize, (
U32)(lhSize+cLitSize));
157 return lhSize+cLitSize;
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
MEM_STATIC void MEM_writeLE24(void *memPtr, U32 val)
ERR_STATIC unsigned ERR_isError(size_t code)
size_t HUF_compress4X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
size_t HUF_compress1X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
#define memcpy(s1, s2, n)
U32 CTable[HUF_CTABLE_SIZE_U32(255)]
MEM_STATIC size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
size_t ZSTD_noCompressLiterals(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_compressLiterals(ZSTD_hufCTables_t const *prevHuf, ZSTD_hufCTables_t *nextHuf, ZSTD_strategy strategy, int disableLiteralCompression, void *dst, size_t dstCapacity, const void *src, size_t srcSize, void *entropyWorkspace, size_t entropyWorkspaceSize, const int bmi2)
#define COMPRESS_LITERALS_SIZE_MIN
size_t ZSTD_compressRleLiteralsBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define RETURN_ERROR_IF(cond, err,...)