only declare debug functions in debug mode
parent
5db717af10
commit
e9dd923fa4
|
@ -1164,7 +1164,9 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|||
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* dst, size_t dstSize,
|
||||
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
||||
const void* src, size_t srcSize);
|
||||
</b><p> Compress an array of ZSTD_Sequence, generated from the original source buffer, into dst.
|
||||
</b><p> Compress an array of ZSTD_Sequence, associted with @src buffer, into dst.
|
||||
@src contains the entire input (not just the literals).
|
||||
If @srcSize > sum(sequence.length), the remaining bytes are considered all literals
|
||||
If a dictionary is included, then the cctx should reference the dict. (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.)
|
||||
The entire source is compressed into a single frame.
|
||||
|
||||
|
|
|
@ -42,13 +42,67 @@
|
|||
|
||||
|
||||
/* **************************************************************
|
||||
* Utils
|
||||
* Required declarations
|
||||
****************************************************************/
|
||||
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue)
|
||||
typedef struct nodeElt_s {
|
||||
U32 count;
|
||||
U16 parent;
|
||||
BYTE byte;
|
||||
BYTE nbBits;
|
||||
} nodeElt;
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* Debug Traces
|
||||
****************************************************************/
|
||||
|
||||
#if DEBUGLEVEL >= 2
|
||||
|
||||
static size_t showU32(const U32* arr, size_t size)
|
||||
{
|
||||
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 1);
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", arr[u]); (void)arr;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t HUF_getNbBits(HUF_CElt elt);
|
||||
|
||||
static size_t showCTableBits(const HUF_CElt* ctable, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %zu", HUF_getNbBits(ctable[u])); (void)ctable;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
|
||||
}
|
||||
|
||||
static size_t showHNodeSymbols(const nodeElt* hnode, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", hnode[u].byte); (void)hnode;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t showHNodeBits(const nodeElt* hnode, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", hnode[u].nbBits); (void)hnode;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* *******************************************************
|
||||
* HUF : Huffman block compression
|
||||
|
@ -140,7 +194,7 @@ static size_t HUF_getNbBitsFast(HUF_CElt elt)
|
|||
|
||||
static size_t HUF_getValue(HUF_CElt elt)
|
||||
{
|
||||
return elt & ~0xFF;
|
||||
return elt & ~(size_t)0xFF;
|
||||
}
|
||||
|
||||
static size_t HUF_getValueFast(HUF_CElt elt)
|
||||
|
@ -278,13 +332,6 @@ U32 HUF_getNbBitsFromCTable(HUF_CElt const* CTable, U32 symbolValue)
|
|||
}
|
||||
|
||||
|
||||
typedef struct nodeElt_s {
|
||||
U32 count;
|
||||
U16 parent;
|
||||
BYTE byte;
|
||||
BYTE nbBits;
|
||||
} nodeElt;
|
||||
|
||||
/**
|
||||
* HUF_setMaxHeight():
|
||||
* Try to enforce @targetNbBits on the Huffman tree described in @huffNode.
|
||||
|
@ -586,7 +633,7 @@ static void HUF_sort(nodeElt huffNode[], const unsigned count[], U32 const maxSy
|
|||
|
||||
/* Sort each bucket. */
|
||||
for (n = RANK_POSITION_DISTINCT_COUNT_CUTOFF; n < RANK_POSITION_TABLE_SIZE - 1; ++n) {
|
||||
U32 const bucketSize = rankPosition[n].curr-rankPosition[n].base;
|
||||
int const bucketSize = rankPosition[n].curr - rankPosition[n].base;
|
||||
U32 const bucketStartIdx = rankPosition[n].base;
|
||||
if (bucketSize > 1) {
|
||||
assert(bucketStartIdx < maxSymbolValue1);
|
||||
|
@ -598,27 +645,6 @@ static void HUF_sort(nodeElt huffNode[], const unsigned count[], U32 const maxSy
|
|||
}
|
||||
|
||||
|
||||
static size_t showHNodeSymbols(const nodeElt* hnode, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", hnode[u].byte); (void)hnode;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t showHNodeBits(const nodeElt* hnode, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", hnode[u].nbBits); (void)hnode;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
/** HUF_buildCTable_wksp() :
|
||||
* Same as HUF_buildCTable(), but using externally allocated scratch buffer.
|
||||
* `workSpace` must be aligned on 4-bytes boundaries, and be at least as large as sizeof(HUF_buildCTable_wksp_tables).
|
||||
|
@ -666,7 +692,7 @@ static int HUF_buildTree(nodeElt* huffNode, U32 maxSymbolValue)
|
|||
for (n=0; n<=nonNullRank; n++)
|
||||
huffNode[n].nbBits = huffNode[ huffNode[n].parent ].nbBits + 1;
|
||||
|
||||
DEBUGLOG(6, "Initial distribution of bits completed (%zu sorted symbols)", showHNodeBits(huffNode, maxSymbolValue+1)); (void)showHNodeBits;
|
||||
DEBUGLOG(6, "Initial distribution of bits completed (%zu sorted symbols)", showHNodeBits(huffNode, maxSymbolValue+1));
|
||||
|
||||
return nonNullRank;
|
||||
}
|
||||
|
@ -739,7 +765,7 @@ HUF_buildCTable_wksp(HUF_CElt* CTable, const unsigned* count, U32 maxSymbolValue
|
|||
|
||||
/* sort, decreasing order */
|
||||
HUF_sort(huffNode, count, maxSymbolValue, wksp_tables->rankPosition);
|
||||
DEBUGLOG(6, "sorted symbols completed (%zu symbols)", showHNodeSymbols(huffNode, maxSymbolValue+1)); (void)showHNodeSymbols;
|
||||
DEBUGLOG(6, "sorted symbols completed (%zu symbols)", showHNodeSymbols(huffNode, maxSymbolValue+1));
|
||||
|
||||
/* build tree */
|
||||
nonNullRank = HUF_buildTree(huffNode, maxSymbolValue);
|
||||
|
@ -943,7 +969,7 @@ static size_t HUF_closeCStream(HUF_CStream_t* bitC)
|
|||
{
|
||||
size_t const nbBits = bitC->bitPos[0] & 0xFF;
|
||||
if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
|
||||
return (bitC->ptr - bitC->startPtr) + (nbBits > 0);
|
||||
return (size_t)(bitC->ptr - bitC->startPtr) + (nbBits > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1214,28 +1240,12 @@ static size_t HUF_compressCTable_internal(
|
|||
return (size_t)(op-ostart);
|
||||
}
|
||||
|
||||
static size_t showU32(const U32* arr, size_t size)
|
||||
|
||||
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %u", arr[u]); (void)arr;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 1);
|
||||
}
|
||||
|
||||
static size_t showCTableBits(const HUF_CElt* ctable, size_t size)
|
||||
{
|
||||
size_t u;
|
||||
for (u=0; u<size; u++) {
|
||||
RAWLOG(6, " %zu", HUF_getNbBits(ctable[u])); (void)ctable;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return size;
|
||||
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned count[HUF_SYMBOLVALUE_MAX + 1];
|
||||
HUF_CElt CTable[HUF_CTABLE_SIZE_ST(HUF_SYMBOLVALUE_MAX)];
|
||||
|
@ -1307,7 +1317,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|||
if (largest == srcSize) { *ostart = ((const BYTE*)src)[0]; return 1; } /* single symbol, rle */
|
||||
if (largest <= (srcSize >> 7)+4) return 0; /* heuristic : probably not compressible enough */
|
||||
}
|
||||
DEBUGLOG(6, "histogram detail completed (%zu symbols)", showU32(table->count, maxSymbolValue+1)); (void)showU32;
|
||||
DEBUGLOG(6, "histogram detail completed (%zu symbols)", showU32(table->count, maxSymbolValue+1));
|
||||
|
||||
/* Check validity of previous table */
|
||||
if ( repeat
|
||||
|
@ -1329,7 +1339,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|||
&table->wksps.buildCTable_wksp, sizeof(table->wksps.buildCTable_wksp));
|
||||
CHECK_F(maxBits);
|
||||
huffLog = (U32)maxBits;
|
||||
DEBUGLOG(6, "bit distribution completed (%zu symbols)", showCTableBits(table->CTable + 1, maxSymbolValue+1)); (void)showCTableBits;
|
||||
DEBUGLOG(6, "bit distribution completed (%zu symbols)", showCTableBits(table->CTable + 1, maxSymbolValue+1));
|
||||
}
|
||||
/* Zero unused symbols in CTable, so we can check it for validity */
|
||||
{
|
||||
|
|
|
@ -713,7 +713,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|||
}
|
||||
# endif
|
||||
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
return (__builtin_ctzll((U64)val) >> 3);
|
||||
return (unsigned)(__builtin_ctzll((U64)val) >> 3);
|
||||
# else
|
||||
static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2,
|
||||
0, 3, 1, 3, 1, 4, 2, 7,
|
||||
|
@ -736,7 +736,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|||
__assume(0);
|
||||
}
|
||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
||||
return (__builtin_ctz((U32)val) >> 3);
|
||||
return (unsigned)(__builtin_ctz((U32)val) >> 3);
|
||||
# else
|
||||
static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0,
|
||||
3, 2, 2, 1, 3, 2, 0, 1,
|
||||
|
@ -761,7 +761,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|||
}
|
||||
# endif
|
||||
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
return (__builtin_clzll(val) >> 3);
|
||||
return (unsigned)(__builtin_clzll(val) >> 3);
|
||||
# else
|
||||
unsigned r;
|
||||
const unsigned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */
|
||||
|
@ -781,7 +781,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|||
__assume(0);
|
||||
}
|
||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
||||
return (__builtin_clz((U32)val) >> 3);
|
||||
return (unsigned)(__builtin_clz((U32)val) >> 3);
|
||||
# else
|
||||
unsigned r;
|
||||
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
|
||||
|
|
|
@ -13,6 +13,29 @@
|
|||
***************************************/
|
||||
#include "zstd_compress_literals.h"
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* Debug Traces
|
||||
****************************************************************/
|
||||
#if DEBUGLEVEL >= 2
|
||||
|
||||
static size_t showHexa(const void* src, size_t srcSize)
|
||||
{
|
||||
const BYTE* const ip = (const BYTE*)src;
|
||||
size_t u;
|
||||
for (u=0; u<srcSize; u++) {
|
||||
RAWLOG(6, " %02X", ip[u]); (void)ip;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return srcSize;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* Literals compression - special cases
|
||||
****************************************************************/
|
||||
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
||||
{
|
||||
BYTE* const ostart = (BYTE*)dst;
|
||||
|
@ -67,17 +90,6 @@ size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void*
|
|||
return flSize+1;
|
||||
}
|
||||
|
||||
static size_t showHexa(const void* src, size_t srcSize)
|
||||
{
|
||||
const BYTE* const ip = (const BYTE*)src;
|
||||
size_t u;
|
||||
for (u=0; u<srcSize; u++) {
|
||||
RAWLOG(6, " %02X", ip[u]); (void)ip;
|
||||
}
|
||||
RAWLOG(6, " \n");
|
||||
return srcSize;
|
||||
}
|
||||
|
||||
size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
||||
ZSTD_hufCTables_t* nextHuf,
|
||||
ZSTD_strategy strategy, int disableLiteralCompression,
|
||||
|
@ -97,7 +109,7 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|||
DEBUGLOG(5,"ZSTD_compressLiterals (disableLiteralCompression=%i srcSize=%u)",
|
||||
disableLiteralCompression, (U32)srcSize);
|
||||
|
||||
DEBUGLOG(6, "Completed literals listing (%zu bytes)", showHexa(src, srcSize)); (void)showHexa;
|
||||
DEBUGLOG(6, "Completed literals listing (%zu bytes)", showHexa(src, srcSize));
|
||||
|
||||
/* Prepare nextEntropy assuming reusing the existing table */
|
||||
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
||||
|
@ -150,7 +162,7 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|||
switch(lhSize)
|
||||
{
|
||||
case 3: /* 2 - 2 - 10 - 10 */
|
||||
{ U32 const lhc = hType + ((!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14);
|
||||
{ U32 const lhc = hType + ((U32)(!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14);
|
||||
MEM_writeLE24(ostart, lhc);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp* ws) {
|
|||
assert(ws->tableValidEnd >= ws->objectEnd);
|
||||
assert(ws->tableValidEnd <= ws->allocStart);
|
||||
if (ws->tableValidEnd < ws->tableEnd) {
|
||||
ZSTD_memset(ws->tableValidEnd, 0, (BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd);
|
||||
ZSTD_memset(ws->tableValidEnd, 0, (size_t)((BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd));
|
||||
}
|
||||
ZSTD_cwksp_mark_tables_clean(ws);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue