Compare commits

...
23 Commits
Author SHA1 Message Date
Yann Collet dc1af5f7b8 Merge pull request #72 from Cyan4973/dev
Dev
2015-11-10 11:17:57 +01:00
Yann Collet 530918b409 level tuning 2015-11-10 10:52:58 +01:00
Yann Collet b7d6e8f6bc fixed Visual warning 2015-11-09 18:20:39 +01:00
Yann Collet 9f432926b4 fileio can use small blocks params 2015-11-09 17:42:17 +01:00
Yann Collet 43e0cd512a small blocks params 2015-11-09 16:38:17 +01:00
Yann Collet 5027945f9f update CSpeed graph 2015-11-09 12:56:06 +01:00
Yann Collet 42e9bed1ea Merge pull request #70 from Cyan4973/dev
Dev
2015-11-09 12:50:27 +01:00
Yann Collet 7ccff59cb3 fold fast stats 2015-11-09 12:07:44 +01:00
Yann Collet 6d2c9e6c62 generic param table 2015-11-09 11:39:48 +01:00
Yann Collet 4baee50728 fix bug 2015-11-09 03:19:33 +01:00
Yann Collet d1ade5a61d fix 32-bits mode 2015-11-08 15:49:20 +01:00
Yann Collet e9eba608c2 simplified bt 2015-11-08 15:08:03 +01:00
Yann Collet d61ddd03ec pg display CL-compatible params 2015-11-08 14:45:38 +01:00
Yann Collet 4c7aae3a36 fuzzer tests more HC levels 2015-11-08 14:24:59 +01:00
Yann Collet 31d00ba4b3 fix bt bug 2015-11-08 14:11:29 +01:00
Yann Collet 72a8e751f4 level tuning 2015-11-07 22:24:46 +01:00
Yann Collet f48e35c206 minor bt improvements 2015-11-07 01:13:31 +01:00
Yann Collet a81d9ac42d minor bt CSpeed 2015-11-06 19:03:59 +01:00
Yann Collet 628065cf98 revert 2015-11-06 18:44:54 +01:00
Yann Collet 9b8e453713 minor CRatio improvement 2015-11-06 18:28:02 +01:00
Yann Collet 47cfa9a985 minor CRatio improvement 2015-11-06 17:13:46 +01:00
Yann Collet eb283710dd minor greedy CRatio improvement 2015-11-06 16:33:11 +01:00
Yann Collet fc2afcfa64 small Cspeed increase 2015-11-06 15:40:14 +01:00
13 changed files with 200 additions and 97 deletions
+1 -1
View File
@@ -32,7 +32,7 @@
# ################################################################ # ################################################################
# Version number # Version number
export VERSION := 0.3.4 export VERSION := 0.3.6
PRGDIR = programs PRGDIR = programs
ZSTDDIR = lib ZSTDDIR = lib
+6
View File
@@ -1,3 +1,9 @@
v0.3.6
small blocks params
v0.3.5
minor generic compression improvements
v0.3.4 v0.3.4
Faster fast cLevels Faster fast cLevels
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

+1 -1
View File
@@ -48,7 +48,7 @@ extern "C" {
***************************************/ ***************************************/
#define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */ #define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */
#define ZSTD_VERSION_MINOR 3 /* for new (non-breaking) interface capabilities */ #define ZSTD_VERSION_MINOR 3 /* for new (non-breaking) interface capabilities */
#define ZSTD_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */ #define ZSTD_VERSION_RELEASE 6 /* for tweaks, bug-fixes, or development */
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
unsigned ZSTD_versionNumber (void); unsigned ZSTD_versionNumber (void);
+8
View File
@@ -226,6 +226,14 @@ static const U32 g_searchStrength = 8;
*/ */
MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const BYTE* literals, size_t offsetCode, size_t matchCode) MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const BYTE* literals, size_t offsetCode, size_t matchCode)
{ {
#if 0
static const BYTE* g_start = NULL;
if (g_start==NULL) g_start = literals;
if (literals - g_start == 8695)
printf("pos %6u : %3u literals & match %3u bytes at distance %6u \n",
(U32)(literals - g_start), (U32)litLength, (U32)matchCode+4, (U32)offsetCode);
#endif
/* copy Literals */ /* copy Literals */
ZSTD_wildcopy(seqStorePtr->lit, literals, litLength); ZSTD_wildcopy(seqStorePtr->lit, literals, litLength);
seqStorePtr->lit += litLength; seqStorePtr->lit += litLength;
+74 -42
View File
@@ -111,7 +111,7 @@ size_t ZSTD_HC_freeCCtx(ZSTD_HC_CCtx* cctx)
/** ZSTD_HC_validateParams /** ZSTD_HC_validateParams
correct params value to remain within authorized range correct params value to remain within authorized range
optimize for srcSize if srcSize > 0 */ optimize for srcSize if srcSize > 0 */
void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, size_t srcSize) void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, U64 srcSizeHint)
{ {
const U32 btPlus = (params->strategy == ZSTD_HC_btlazy2); const U32 btPlus = (params->strategy == ZSTD_HC_btlazy2);
@@ -120,9 +120,9 @@ void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, size_t srcSize)
if (params->windowLog < ZSTD_HC_WINDOWLOG_MIN) params->windowLog = ZSTD_HC_WINDOWLOG_MIN; if (params->windowLog < ZSTD_HC_WINDOWLOG_MIN) params->windowLog = ZSTD_HC_WINDOWLOG_MIN;
/* correct params, to use less memory */ /* correct params, to use less memory */
if (srcSize > 0) if ((srcSizeHint > 0) && (srcSizeHint < (1<<ZSTD_HC_WINDOWLOG_MAX)))
{ {
U32 srcLog = ZSTD_highbit((U32)srcSize-1) + 1; U32 srcLog = ZSTD_highbit((U32)srcSizeHint-1) + 1;
if (params->windowLog > srcLog) params->windowLog = srcLog; if (params->windowLog > srcLog) params->windowLog = srcLog;
} }
@@ -139,9 +139,10 @@ void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, size_t srcSize)
static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc, static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
ZSTD_HC_parameters params) ZSTD_HC_parameters params,
U64 srcSizeHint)
{ {
ZSTD_HC_validateParams(&params, 0); ZSTD_HC_validateParams(&params, srcSizeHint);
/* reserve table memory */ /* reserve table memory */
{ {
@@ -161,7 +162,7 @@ static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
zc->seqStore.buffer = (void*) (zc->contentTable + ((size_t)1 << contentLog)); zc->seqStore.buffer = (void*) (zc->contentTable + ((size_t)1 << contentLog));
} }
zc->nextToUpdate = 0; zc->nextToUpdate = 1;
zc->end = NULL; zc->end = NULL;
zc->base = NULL; zc->base = NULL;
zc->dictBase = NULL; zc->dictBase = NULL;
@@ -316,7 +317,7 @@ size_t ZSTD_HC_compressBlock_fast(ZSTD_HC_CCtx* ctx,
***************************************/ ***************************************/
/** ZSTD_HC_insertBt1 : add one ptr to tree /** ZSTD_HC_insertBt1 : add one ptr to tree
@ip : assumed <= iend-8 */ @ip : assumed <= iend-8 */
static void ZSTD_HC_insertBt1(ZSTD_HC_CCtx* zc, const BYTE* const ip, const U32 mls, const BYTE* const iend, U32 nbCompares) static U32 ZSTD_HC_insertBt1(ZSTD_HC_CCtx* zc, const BYTE* const ip, const U32 mls, const BYTE* const iend, U32 nbCompares)
{ {
U32* const hashTable = zc->hashTable; U32* const hashTable = zc->hashTable;
const U32 hashLog = zc->params.hashLog; const U32 hashLog = zc->params.hashLog;
@@ -327,7 +328,8 @@ static void ZSTD_HC_insertBt1(ZSTD_HC_CCtx* zc, const BYTE* const ip, const U32
U32 matchIndex = hashTable[h]; U32 matchIndex = hashTable[h];
size_t commonLengthSmaller=0, commonLengthLarger=0; size_t commonLengthSmaller=0, commonLengthLarger=0;
const BYTE* const base = zc->base; const BYTE* const base = zc->base;
const U32 current = (U32)(ip-base); const BYTE* match = base + matchIndex;
U32 current = (U32)(ip-base);
const U32 btLow = btMask >= current ? 0 : current - btMask; const U32 btLow = btMask >= current ? 0 : current - btMask;
U32* smallerPtr = bt + 2*(current&btMask); U32* smallerPtr = bt + 2*(current&btMask);
U32* largerPtr = bt + 2*(current&btMask) + 1; U32* largerPtr = bt + 2*(current&btMask) + 1;
@@ -335,14 +337,21 @@ static void ZSTD_HC_insertBt1(ZSTD_HC_CCtx* zc, const BYTE* const ip, const U32
const U32 windowSize = 1 << zc->params.windowLog; const U32 windowSize = 1 << zc->params.windowLog;
const U32 windowLow = windowSize >= current ? 0 : current - windowSize; const U32 windowLow = windowSize >= current ? 0 : current - windowSize;
hashTable[h] = (U32)(ip-base); /* Update Hash Table */ if ((current-matchIndex == 1) /* RLE */
&& MEM_read64(match) == MEM_read64(ip))
{
size_t rleLength = ZSTD_count(ip+sizeof(size_t), match+sizeof(size_t), iend) + sizeof(size_t);
return (U32)(rleLength - mls);
}
hashTable[h] = (U32)(ip - base); /* Update Hash Table */
while (nbCompares-- && (matchIndex > windowLow)) while (nbCompares-- && (matchIndex > windowLow))
{ {
U32* nextPtr = bt + 2*(matchIndex & btMask); U32* nextPtr = bt + 2*(matchIndex & btMask);
const BYTE* match = base + matchIndex;
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
match = base + matchIndex;
matchLength += ZSTD_count(ip+matchLength, match+matchLength, iend); matchLength += ZSTD_count(ip+matchLength, match+matchLength, iend);
if (ip+matchLength == iend) /* equal : no way to know if inf or sup */ if (ip+matchLength == iend) /* equal : no way to know if inf or sup */
@@ -369,6 +378,7 @@ static void ZSTD_HC_insertBt1(ZSTD_HC_CCtx* zc, const BYTE* const ip, const U32
} }
*smallerPtr = *largerPtr = 0; *smallerPtr = *largerPtr = 0;
return 1;
} }
@@ -412,7 +422,7 @@ size_t ZSTD_HC_insertBtAndFindBestMatch (
if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit(current-matchIndex+1) - ZSTD_highbit((U32)offsetPtr[0]+1)) ) if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit(current-matchIndex+1) - ZSTD_highbit((U32)offsetPtr[0]+1)) )
bestLength = matchLength, *offsetPtr = current - matchIndex; bestLength = matchLength, *offsetPtr = current - matchIndex;
if (ip+matchLength == iend) /* equal : no way to know if inf or sup */ if (ip+matchLength == iend) /* equal : no way to know if inf or sup */
break; /* drop, next to null, to guarantee consistency (is there a way to do better ?) */ break; /* just drop, to guarantee consistency (miss a little bit of compression) */
} }
if (match[matchLength] < ip[matchLength]) if (match[matchLength] < ip[matchLength])
@@ -420,41 +430,41 @@ size_t ZSTD_HC_insertBtAndFindBestMatch (
/* match is smaller than current */ /* match is smaller than current */
*smallerPtr = matchIndex; /* update smaller idx */ *smallerPtr = matchIndex; /* update smaller idx */
commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */ commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */
if (matchIndex <= btLow) { smallerPtr=&dummy32; break; } /* beyond tree size, stop the search */
smallerPtr = nextPtr+1; /* new "smaller" => larger of match */ smallerPtr = nextPtr+1; /* new "smaller" => larger of match */
matchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to current) */ if (matchIndex <= btLow) smallerPtr=&dummy32; /* beyond tree size, stop the search */
matchIndex = (matchIndex <= btLow) ? windowLow : nextPtr[1];
} }
else else
{ {
/* match is larger than current */ /* match is larger than current */
*largerPtr = matchIndex; *largerPtr = matchIndex;
commonLengthLarger = matchLength; commonLengthLarger = matchLength;
if (matchIndex <= btLow) { largerPtr=&dummy32; break; } /* beyond tree size, stop the search */
largerPtr = nextPtr; largerPtr = nextPtr;
matchIndex = nextPtr[0]; if (matchIndex <= btLow) largerPtr=&dummy32; /* beyond tree size, stop the search */
matchIndex = (matchIndex <= btLow) ? windowLow : nextPtr[0];
} }
} }
*smallerPtr = *largerPtr = 0; *smallerPtr = *largerPtr = 0;
zc->nextToUpdate = current+1; /* current has been inserted */ zc->nextToUpdate = current+1; /* current has been inserted */
if (bestLength < MINMATCH) return 0;
return bestLength; return bestLength;
} }
static void ZSTD_HC_updateTree(ZSTD_HC_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls) static const BYTE* ZSTD_HC_updateTree(ZSTD_HC_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls)
{ {
const BYTE* const base = zc->base; const BYTE* const base = zc->base;
const U32 target = (U32)(ip - base); const U32 target = (U32)(ip - base);
U32 idx = zc->nextToUpdate; U32 idx = zc->nextToUpdate;
//size_t dummy; //size_t dummy;
for( ; idx < target ; idx++) for( ; idx < target ; )
ZSTD_HC_insertBt1(zc, base+idx, mls, iend, nbCompares); idx += ZSTD_HC_insertBt1(zc, base+idx, mls, iend, nbCompares);
//ZSTD_HC_insertBtAndFindBestMatch(zc, base+idx, iend, &dummy, nbCompares, mls); //ZSTD_HC_insertBtAndFindBestMatch(zc, base+idx, iend, &dummy, nbCompares, mls);
zc->nextToUpdate = target; zc->nextToUpdate = idx;
return base + idx;
} }
@@ -466,7 +476,13 @@ size_t ZSTD_HC_BtFindBestMatch (
size_t* offsetPtr, size_t* offsetPtr,
const U32 maxNbAttempts, const U32 mls) const U32 maxNbAttempts, const U32 mls)
{ {
ZSTD_HC_updateTree(zc, ip, iLimit, maxNbAttempts, mls); const BYTE* nextToUpdate = ZSTD_HC_updateTree(zc, ip, iLimit, maxNbAttempts, mls);
if (nextToUpdate > ip)
{
/* RLE data */
*offsetPtr = 1;
return ZSTD_count(ip, ip-1, iLimit);
}
return ZSTD_HC_insertBtAndFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, mls); return ZSTD_HC_insertBtAndFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, mls);
} }
@@ -546,22 +562,21 @@ size_t ZSTD_HC_HcFindBestMatch (
if (matchIndex >= dictLimit) if (matchIndex >= dictLimit)
{ {
match = base + matchIndex; match = base + matchIndex;
if ( (match[ml] == ip[ml]) if (match[ml] == ip[ml]) /* potentially better */
&& (MEM_read32(match) == MEM_read32(ip)) ) /* ensures minimum match of 4 */
{ {
const size_t mlt = ZSTD_count(ip+MINMATCH, match+MINMATCH, iLimit) + MINMATCH; const size_t mlt = ZSTD_count(ip, match, iLimit);
if (mlt > ml) if (mlt > ml)
//if (((int)(4*mlt) - (int)ZSTD_highbit((U32)(ip-match)+1)) > ((int)(4*ml) - (int)ZSTD_highbit((U32)((*offsetPtr)+1)))) //if (((int)(4*mlt) - (int)ZSTD_highbit((U32)(ip-match)+1)) > ((int)(4*ml) - (int)ZSTD_highbit((U32)((*offsetPtr)+1))))
{ {
ml = mlt; *offsetPtr = ip-match; ml = mlt; *offsetPtr = ip-match;
if (ip+ml >= iLimit) break; if (ip+mlt >= iLimit) break;
} }
} }
} }
else else
{ {
match = dictBase + matchIndex; match = dictBase + matchIndex;
if (MEM_read32(match) == MEM_read32(ip)) if (MEM_read32(match) == MEM_read32(ip)) /* beware of end of dict */
{ {
size_t mlt; size_t mlt;
const BYTE* vLimit = ip + (dictLimit - matchIndex); const BYTE* vLimit = ip + (dictLimit - matchIndex);
@@ -647,7 +662,11 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
offset_2 = offset_1; offset_2 = offset_1;
matchLength = searchMax(ctx, ip, iend, &offset, maxSearches, mls); matchLength = searchMax(ctx, ip, iend, &offset, maxSearches, mls);
if (!matchLength) { ip++; continue; } if (matchLength < MINMATCH)
{
ip += ((ip-anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */
continue;
}
/* let's try to find a better solution */ /* let's try to find a better solution */
start = ip; start = ip;
@@ -660,7 +679,7 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH; size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
int gain2 = (int)(ml2 * 3); int gain2 = (int)(ml2 * 3);
int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 1); int gain1 = (int)(matchLength*3 - ZSTD_highbit((U32)offset+1) + 1);
if (gain2 > gain1) if ((ml2 >= MINMATCH) && (gain2 > gain1))
matchLength = ml2, offset = 0, start = ip; matchLength = ml2, offset = 0, start = ip;
} }
{ {
@@ -668,7 +687,7 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls);
int gain2 = (int)(ml2*(3+deep) - ZSTD_highbit((U32)offset2+1)); /* raw approx */ int gain2 = (int)(ml2*(3+deep) - ZSTD_highbit((U32)offset2+1)); /* raw approx */
int gain1 = (int)(matchLength*(3+deep) - ZSTD_highbit((U32)offset+1) + (3+deep)); int gain1 = (int)(matchLength*(3+deep) - ZSTD_highbit((U32)offset+1) + (3+deep));
if (gain2 > gain1) if ((ml2 >= MINMATCH) && (gain2 > gain1))
{ {
matchLength = ml2, offset = offset2, start = ip; matchLength = ml2, offset = offset2, start = ip;
continue; /* search a better one */ continue; /* search a better one */
@@ -684,7 +703,7 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH; size_t ml2 = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_1, iend) + MINMATCH;
int gain2 = (int)(ml2 * 4); int gain2 = (int)(ml2 * 4);
int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 1); int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 1);
if (gain2 > gain1) if ((ml2 >= MINMATCH) && (gain2 > gain1))
matchLength = ml2, offset = 0, start = ip; matchLength = ml2, offset = 0, start = ip;
} }
{ {
@@ -692,7 +711,7 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls);
int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1)); /* raw approx */ int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1)); /* raw approx */
int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7); int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
if (gain2 > gain1) if ((ml2 >= MINMATCH) && (gain2 > gain1))
{ {
matchLength = ml2, offset = offset2, start = ip; matchLength = ml2, offset = offset2, start = ip;
continue; continue;
@@ -702,13 +721,19 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
break; /* nothing found : store previous solution */ break; /* nothing found : store previous solution */
} }
/* catch up */
if (offset)
{
while ((start>anchor) && (start>ctx->base+offset) && (start[-1] == start[-1-offset]))
{ start--; matchLength++; }
}
/* store sequence */ /* store sequence */
{ {
size_t litLength = start - anchor; size_t litLength = start - anchor;
if (offset) offset_1 = offset; if (offset) offset_1 = offset;
ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH); ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH);
ip = start + matchLength; anchor = ip = start + matchLength;
anchor = ip;
} }
} }
@@ -793,8 +818,12 @@ size_t ZSTD_HC_compressBlock_greedy(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS
{ {
size_t offset=999999; size_t offset=999999;
size_t matchLength = ZSTD_HC_HcFindBestMatch_selectMLS(ctx, ip, iend, &offset, maxSearches, mls); size_t matchLength = ZSTD_HC_HcFindBestMatch_selectMLS(ctx, ip, iend, &offset, maxSearches, mls);
if (!matchLength) { ip++; continue; } if (matchLength < MINMATCH)
while ((ip>anchor) && (ip-offset>ctx->base) && (ip[-1] == ip[-1-offset])) { ip--; } /* catch up */ {
ip += ((ip-anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */
continue;
}
while ((ip>anchor) && (ip-offset>ctx->base) && (ip[-1] == ip[-1-offset])) { ip--; matchLength++; } /* catch up */
/* store sequence */ /* store sequence */
{ {
size_t litLength = ip-anchor; size_t litLength = ip-anchor;
@@ -902,7 +931,7 @@ size_t ZSTD_HC_compressContinue (ZSTD_HC_CCtx* ctxPtr,
if (ip != ctxPtr->end) if (ip != ctxPtr->end)
{ {
if (ctxPtr->end != NULL) if (ctxPtr->end != NULL)
ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params); ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params, srcSize);
ctxPtr->base = ip; ctxPtr->base = ip;
} }
@@ -913,22 +942,24 @@ size_t ZSTD_HC_compressContinue (ZSTD_HC_CCtx* ctxPtr,
size_t ZSTD_HC_compressBegin_advanced(ZSTD_HC_CCtx* ctx, size_t ZSTD_HC_compressBegin_advanced(ZSTD_HC_CCtx* ctx,
void* dst, size_t maxDstSize, void* dst, size_t maxDstSize,
const ZSTD_HC_parameters params) const ZSTD_HC_parameters params,
U64 srcSizeHint)
{ {
size_t errorCode; size_t errorCode;
if (maxDstSize < 4) return ERROR(dstSize_tooSmall); if (maxDstSize < 4) return ERROR(dstSize_tooSmall);
errorCode = ZSTD_HC_resetCCtx_advanced(ctx, params); errorCode = ZSTD_HC_resetCCtx_advanced(ctx, params, srcSizeHint);
if (ZSTD_isError(errorCode)) return errorCode; if (ZSTD_isError(errorCode)) return errorCode;
MEM_writeLE32(dst, ZSTD_magicNumber); /* Write Header */ MEM_writeLE32(dst, ZSTD_magicNumber); /* Write Header */
return 4; return 4;
} }
size_t ZSTD_HC_compressBegin(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, int compressionLevel) size_t ZSTD_HC_compressBegin(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, int compressionLevel, U64 srcSizeHint)
{ {
int tableID = ((srcSizeHint-1) > 128 KB); /* intentional underflow for 0 */
if (compressionLevel<=0) compressionLevel = 1; if (compressionLevel<=0) compressionLevel = 1;
if (compressionLevel > ZSTD_HC_MAX_CLEVEL) compressionLevel = ZSTD_HC_MAX_CLEVEL; if (compressionLevel > ZSTD_HC_MAX_CLEVEL) compressionLevel = ZSTD_HC_MAX_CLEVEL;
return ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, ZSTD_HC_defaultParameters[compressionLevel]); return ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, ZSTD_HC_defaultParameters[tableID][compressionLevel], srcSizeHint);
} }
@@ -966,7 +997,7 @@ size_t ZSTD_HC_compress_advanced (ZSTD_HC_CCtx* ctx,
} }
/* Header */ /* Header */
oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params); oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params, srcSize);
if(ZSTD_isError(oSize)) return oSize; if(ZSTD_isError(oSize)) return oSize;
op += oSize; op += oSize;
maxDstSize -= oSize; maxDstSize -= oSize;
@@ -988,9 +1019,10 @@ size_t ZSTD_HC_compress_advanced (ZSTD_HC_CCtx* ctx,
size_t ZSTD_HC_compressCCtx (ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel) size_t ZSTD_HC_compressCCtx (ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel)
{ {
const int tableID = (srcSize > 128 KB);
if (compressionLevel<=1) return ZSTD_compress(dst, maxDstSize, src, srcSize); /* fast mode */ if (compressionLevel<=1) return ZSTD_compress(dst, maxDstSize, src, srcSize); /* fast mode */
if (compressionLevel > ZSTD_HC_MAX_CLEVEL) compressionLevel = ZSTD_HC_MAX_CLEVEL; if (compressionLevel > ZSTD_HC_MAX_CLEVEL) compressionLevel = ZSTD_HC_MAX_CLEVEL;
return ZSTD_HC_compress_advanced(ctx, dst, maxDstSize, src, srcSize, ZSTD_HC_defaultParameters[compressionLevel]); return ZSTD_HC_compress_advanced(ctx, dst, maxDstSize, src, srcSize, ZSTD_HC_defaultParameters[tableID][compressionLevel]);
} }
size_t ZSTD_HC_compress(void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel) size_t ZSTD_HC_compress(void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel)
+37 -12
View File
@@ -83,14 +83,14 @@ size_t ZSTD_HC_compress_advanced (ZSTD_HC_CCtx* ctx,
/** ZSTD_HC_validateParams /** ZSTD_HC_validateParams
correct params value to remain within authorized range correct params value to remain within authorized range
optimize for srcSize if srcSize > 0 */ srcSizeHint value is optional, select 0 if not known */
void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, size_t srcSize); void ZSTD_HC_validateParams(ZSTD_HC_parameters* params, U64 srcSizeHint);
/* ************************************* /* *************************************
* Streaming functions * Streaming functions
***************************************/ ***************************************/
size_t ZSTD_HC_compressBegin(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, int compressionLevel); size_t ZSTD_HC_compressBegin(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, int compressionLevel, U64 srcSizeHint);
size_t ZSTD_HC_compressContinue(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); size_t ZSTD_HC_compressContinue(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);
size_t ZSTD_HC_compressEnd(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize); size_t ZSTD_HC_compressEnd(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize);
@@ -99,33 +99,58 @@ size_t ZSTD_HC_compressEnd(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize);
* Pre-defined compression levels * Pre-defined compression levels
***************************************/ ***************************************/
#define ZSTD_HC_MAX_CLEVEL 20 #define ZSTD_HC_MAX_CLEVEL 20
static const ZSTD_HC_parameters ZSTD_HC_defaultParameters[ZSTD_HC_MAX_CLEVEL+1] = { static const ZSTD_HC_parameters ZSTD_HC_defaultParameters[2][ZSTD_HC_MAX_CLEVEL+1] = {
{ /* for <= 128 KB */
/* W, C, H, S, L, strat */
{ 17, 12, 12, 1, 4, ZSTD_HC_fast }, /* level 0 - never used */
{ 17, 12, 13, 1, 6, ZSTD_HC_fast }, /* level 1 */
{ 17, 15, 16, 1, 5, ZSTD_HC_fast }, /* level 2 */
{ 17, 16, 17, 1, 5, ZSTD_HC_fast }, /* level 3 */
{ 17, 13, 15, 2, 4, ZSTD_HC_greedy }, /* level 4 */
{ 17, 15, 17, 3, 4, ZSTD_HC_greedy }, /* level 5 */
{ 17, 14, 17, 3, 4, ZSTD_HC_lazy }, /* level 6 */
{ 17, 16, 17, 4, 4, ZSTD_HC_lazy }, /* level 7 */
{ 17, 16, 17, 4, 4, ZSTD_HC_lazy2 }, /* level 8 */
{ 17, 17, 16, 5, 4, ZSTD_HC_lazy2 }, /* level 9 */
{ 17, 17, 16, 6, 4, ZSTD_HC_lazy2 }, /* level 10 */
{ 17, 17, 16, 7, 4, ZSTD_HC_lazy2 }, /* level 11 */
{ 17, 17, 16, 8, 4, ZSTD_HC_lazy2 }, /* level 12 */
{ 17, 18, 16, 4, 4, ZSTD_HC_btlazy2 }, /* level 13 */
{ 17, 18, 16, 5, 4, ZSTD_HC_btlazy2 }, /* level 14 */
{ 17, 18, 16, 6, 4, ZSTD_HC_btlazy2 }, /* level 15 */
{ 17, 18, 16, 7, 4, ZSTD_HC_btlazy2 }, /* level 16 */
{ 17, 18, 16, 8, 4, ZSTD_HC_btlazy2 }, /* level 17 */
{ 17, 18, 16, 9, 4, ZSTD_HC_btlazy2 }, /* level 18 */
{ 17, 18, 16, 10, 4, ZSTD_HC_btlazy2 }, /* level 19 */
{ 17, 18, 18, 12, 4, ZSTD_HC_btlazy2 }, /* level 20 */
},
{ /* for > 128 KB */
/* W, C, H, S, L, strat */ /* W, C, H, S, L, strat */
{ 18, 12, 12, 1, 4, ZSTD_HC_fast }, /* level 0 - never used */ { 18, 12, 12, 1, 4, ZSTD_HC_fast }, /* level 0 - never used */
{ 18, 14, 14, 1, 7, ZSTD_HC_fast }, /* level 1 - in fact redirected towards zstd fast */ { 18, 14, 14, 1, 7, ZSTD_HC_fast }, /* level 1 - in fact redirected towards zstd fast */
{ 19, 15, 16, 1, 6, ZSTD_HC_fast }, /* level 2 */ { 19, 15, 16, 1, 6, ZSTD_HC_fast }, /* level 2 */
{ 20, 18, 20, 1, 6, ZSTD_HC_fast }, /* level 3 */ { 20, 18, 20, 1, 6, ZSTD_HC_fast }, /* level 3 */
{ 21, 19, 21, 1, 6, ZSTD_HC_fast }, /* level 4 */ { 21, 19, 21, 1, 6, ZSTD_HC_fast }, /* level 4 */
{ 19, 14, 19, 2, 5, ZSTD_HC_greedy }, /* level 5 */ { 20, 13, 18, 5, 5, ZSTD_HC_greedy }, /* level 5 */
{ 20, 17, 19, 3, 5, ZSTD_HC_greedy }, /* level 6 */ { 20, 17, 19, 3, 5, ZSTD_HC_greedy }, /* level 6 */
{ 21, 17, 20, 3, 5, ZSTD_HC_lazy }, /* level 7 */ { 21, 17, 20, 3, 5, ZSTD_HC_lazy }, /* level 7 */
{ 21, 19, 20, 3, 5, ZSTD_HC_lazy }, /* level 8 */ { 21, 19, 20, 3, 5, ZSTD_HC_lazy }, /* level 8 */
{ 21, 19, 20, 4, 5, ZSTD_HC_lazy }, /* level 9 */ { 21, 20, 20, 3, 5, ZSTD_HC_lazy2 }, /* level 9 */
{ 21, 19, 20, 5, 5, ZSTD_HC_lazy }, /* level 10 */ { 21, 19, 20, 4, 5, ZSTD_HC_lazy2 }, /* level 10 */
{ 21, 20, 20, 5, 5, ZSTD_HC_lazy }, /* level 11 */ { 22, 20, 22, 4, 5, ZSTD_HC_lazy2 }, /* level 11 */
{ 22, 20, 22, 5, 5, ZSTD_HC_lazy2 }, /* level 12 */ { 22, 20, 22, 5, 5, ZSTD_HC_lazy2 }, /* level 12 */
{ 22, 21, 22, 5, 5, ZSTD_HC_lazy2 }, /* level 13 */ { 22, 21, 22, 5, 5, ZSTD_HC_lazy2 }, /* level 13 */
{ 22, 22, 23, 5, 5, ZSTD_HC_lazy2 }, /* level 14 */ { 22, 22, 23, 5, 5, ZSTD_HC_lazy2 }, /* level 14 */
{ 22, 21, 22, 6, 5, ZSTD_HC_lazy2 }, /* level 15 */ { 23, 23, 23, 5, 5, ZSTD_HC_lazy2 }, /* level 15 */
{ 22, 21, 22, 4, 5, ZSTD_HC_btlazy2 }, /* level 16 */ { 23, 21, 22, 5, 5, ZSTD_HC_btlazy2 }, /* level 16 */
{ 23, 23, 23, 4, 5, ZSTD_HC_btlazy2 }, /* level 17 */ { 23, 24, 23, 4, 5, ZSTD_HC_btlazy2 }, /* level 17 */
{ 25, 24, 23, 5, 5, ZSTD_HC_btlazy2 }, /* level 18 */ { 25, 24, 23, 5, 5, ZSTD_HC_btlazy2 }, /* level 18 */
{ 25, 26, 23, 5, 5, ZSTD_HC_btlazy2 }, /* level 19 */ { 25, 26, 23, 5, 5, ZSTD_HC_btlazy2 }, /* level 19 */
{ 26, 27, 24, 6, 5, ZSTD_HC_btlazy2 }, /* level 20 */ { 26, 27, 24, 6, 5, ZSTD_HC_btlazy2 }, /* level 20 */
}
}; };
#if defined (__cplusplus) #if defined (__cplusplus)
} }
#endif #endif
+1 -1
View File
@@ -30,7 +30,7 @@
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode # fullbench32: Same as fullbench, but forced to compile in 32-bits mode
# ########################################################################## # ##########################################################################
VERSION?= 0.3.4 VERSION?= 0.3.6
DESTDIR?= DESTDIR?=
PREFIX ?= /usr/local PREFIX ?= /usr/local
+1 -1
View File
@@ -380,7 +380,7 @@ static int BMK_benchMem(void* srcBuffer, size_t srcSize, const char* fileName, i
} }
static U64 BMK_GetFileSize(char* infilename) static U64 BMK_GetFileSize(const char* infilename)
{ {
int r; int r;
#if defined(_MSC_VER) #if defined(_MSC_VER)
+36 -12
View File
@@ -36,7 +36,7 @@
/**LEGACY_SUPPORT : /**LEGACY_SUPPORT :
* decompressor can decode older formats (starting from Zstd 0.1+) */ * decompressor can decode older formats (starting from Zstd 0.1+) */
# define ZSTD_LEGACY_SUPPORT 1 # define ZSTD_LEGACY_SUPPORT 1
#endif // ZSTD_LEGACY_SUPPORT #endif
/* ************************************* /* *************************************
@@ -58,11 +58,13 @@
/* ************************************* /* *************************************
* Includes * Includes
***************************************/ ***************************************/
#include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */ #include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */
#include <stdlib.h> /* malloc, free */ #include <stdlib.h> /* malloc, free */
#include <string.h> /* strcmp, strlen */ #include <string.h> /* strcmp, strlen */
#include <time.h> /* clock */ #include <time.h> /* clock */
#include <errno.h> /* errno */ #include <errno.h> /* errno */
#include <sys/types.h> /* stat64 */
#include <sys/stat.h> /* stat64 */
#include "mem.h" #include "mem.h"
#include "fileio.h" #include "fileio.h"
#include "zstd_static.h" #include "zstd_static.h"
@@ -91,6 +93,10 @@
# define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) # define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
#endif #endif
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
/* ************************************* /* *************************************
* Constants * Constants
@@ -215,19 +221,35 @@ static void FIO_getFileHandles(FILE** pfinput, FILE** pfoutput, const char* inpu
if ( *pfoutput==0) EXM_THROW(13, "Pb opening dst : %s", output_filename); if ( *pfoutput==0) EXM_THROW(13, "Pb opening dst : %s", output_filename);
} }
static U64 FIO_getFileSize(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0;
return (U64)statbuf.st_size;
}
typedef void* (*FIO_createC) (void); typedef void* (*FIO_createC) (void);
static void* local_ZSTD_createCCtx(void) { return (void*) ZSTD_createCCtx(); } static void* local_ZSTD_createCCtx(void) { return (void*) ZSTD_createCCtx(); }
static void* local_ZSTD_HC_createCCtx(void) { return (void*) ZSTD_HC_createCCtx(); } static void* local_ZSTD_HC_createCCtx(void) { return (void*) ZSTD_HC_createCCtx(); }
typedef size_t (*FIO_initC) (void* ctx, void* dst, size_t maxDstSize, int cLevel); typedef size_t (*FIO_initC) (void* ctx, void* dst, size_t maxDstSize, int cLevel, U64 srcSizeHint);
static size_t local_ZSTD_compressBegin (void* ctx, void* dst, size_t maxDstSize, int cLevel) static size_t local_ZSTD_compressBegin (void* ctx, void* dst, size_t maxDstSize, int cLevel, U64 srcSizeHint)
{ {
(void)cLevel; (void)cLevel; (void)srcSizeHint;
return ZSTD_compressBegin((ZSTD_CCtx*)ctx, dst, maxDstSize); return ZSTD_compressBegin((ZSTD_CCtx*)ctx, dst, maxDstSize);
} }
static size_t local_ZSTD_HC_compressBegin (void* ctx, void* dst, size_t maxDstSize, int cLevel) static size_t local_ZSTD_HC_compressBegin (void* ctx, void* dst, size_t maxDstSize, int cLevel, U64 srcSizeHint)
{ {
return ZSTD_HC_compressBegin((ZSTD_HC_CCtx*)ctx, dst, maxDstSize, cLevel); return ZSTD_HC_compressBegin((ZSTD_HC_CCtx*)ctx, dst, maxDstSize, cLevel, srcSizeHint);
} }
typedef size_t (*FIO_continueC) (void* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); typedef size_t (*FIO_continueC) (void* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);
@@ -294,6 +316,7 @@ unsigned long long FIO_compressFilename(const char* output_filename, const char*
freeC = local_ZSTD_HC_freeCCtx; freeC = local_ZSTD_HC_freeCCtx;
} }
FIO_getFileHandles(&finput, &foutput, input_filename, output_filename); FIO_getFileHandles(&finput, &foutput, input_filename, output_filename);
filesize = FIO_getFileSize(input_filename);
/* Allocate Memory */ /* Allocate Memory */
ctx = createC(); ctx = createC();
@@ -304,12 +327,13 @@ unsigned long long FIO_compressFilename(const char* output_filename, const char*
inEnd = inBuff + inBuffSize; inEnd = inBuff + inBuffSize;
/* Write Frame Header */ /* Write Frame Header */
cSize = initC(ctx, outBuff, outBuffSize, cLevel); cSize = initC(ctx, outBuff, outBuffSize, cLevel, filesize);
if (ZSTD_isError(cSize)) EXM_THROW(22, "Compression error : cannot create frame header"); if (ZSTD_isError(cSize)) EXM_THROW(22, "Compression error : cannot create frame header");
sizeCheck = fwrite(outBuff, 1, cSize, foutput); sizeCheck = fwrite(outBuff, 1, cSize, foutput);
if (sizeCheck!=cSize) EXM_THROW(23, "Write error : cannot write header into %s", output_filename); if (sizeCheck!=cSize) EXM_THROW(23, "Write error : cannot write header into %s", output_filename);
compressedfilesize += cSize; compressedfilesize += cSize;
filesize = 0;
/* Main compression loop */ /* Main compression loop */
while (1) while (1)
+5 -8
View File
@@ -297,7 +297,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
{ {
size_t sampleSize, sampleStart; size_t sampleSize, sampleStart;
size_t cSize, dSize, dSupSize; size_t cSize, dSize, dSupSize;
U32 sampleSizeLog, buffNb; U32 sampleSizeLog, buffNb, cLevelMod;
U64 crcOrig, crcDest; U64 crcOrig, crcDest;
int cLevel; int cLevel;
@@ -328,13 +328,10 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize); sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize);
crcOrig = XXH64(srcBuffer + sampleStart, sampleSize, 0); crcOrig = XXH64(srcBuffer + sampleStart, sampleSize, 0);
/* compression test */
/* covered by HC cLevel 1
cSize = ZSTD_compressCCtx(ctx, cBuffer, cBufferSize, srcBuffer + sampleStart, sampleSize);
CHECK(ZSTD_isError(cSize), "ZSTD_compress failed"); */
/* HC compression test */ /* HC compression test */
cLevel = (FUZ_rand(&lseed) & 3) +1; #define MAX(a,b) ((a)>(b)?(a):(b))
cLevelMod = MAX(1, 38 - (int)(MAX(9, sampleSizeLog) * 2)); /* use high compression levels with small samples, for speed */
cLevel = (FUZ_rand(&lseed) % cLevelMod) +1;
cSize = ZSTD_HC_compressCCtx(hcctx, cBuffer, cBufferSize, srcBuffer + sampleStart, sampleSize, cLevel); cSize = ZSTD_HC_compressCCtx(hcctx, cBuffer, cBufferSize, srcBuffer + sampleStart, sampleSize, cLevel);
CHECK(ZSTD_isError(cSize), "ZSTD_HC_compressCCtx failed"); CHECK(ZSTD_isError(cSize), "ZSTD_HC_compressCCtx failed");
@@ -358,7 +355,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
dSize = ZSTD_decompress(dstBuffer, sampleSize + dSupSize, cBuffer, cSize); dSize = ZSTD_decompress(dstBuffer, sampleSize + dSupSize, cBuffer, cSize);
CHECK(dSize != sampleSize, "ZSTD_decompress failed (%s) (srcSize : %u ; cSize : %u)", ZSTD_getErrorName(dSize), (U32)sampleSize, (U32)cSize); CHECK(dSize != sampleSize, "ZSTD_decompress failed (%s) (srcSize : %u ; cSize : %u)", ZSTD_getErrorName(dSize), (U32)sampleSize, (U32)cSize);
crcDest = XXH64(dstBuffer, sampleSize, 0); crcDest = XXH64(dstBuffer, sampleSize, 0);
CHECK(crcOrig != crcDest, "dstBuffer corrupted (pos %u / %u)", (U32)findDiff(srcBuffer+sampleStart, dstBuffer, sampleSize), (U32)sampleSize); CHECK(crcOrig != crcDest, "decompression result corrupted (pos %u / %u)", (U32)findDiff(srcBuffer+sampleStart, dstBuffer, sampleSize), (U32)sampleSize);
/* truncated src decompression test */ /* truncated src decompression test */
{ {
+29 -18
View File
@@ -122,7 +122,7 @@ static U32 g_rand = 1;
static U32 g_singleRun = 0; static U32 g_singleRun = 0;
static U32 g_target = 0; static U32 g_target = 0;
static U32 g_noSeed = 0; static U32 g_noSeed = 0;
static const ZSTD_HC_parameters* g_seedParams = ZSTD_HC_defaultParameters; static const ZSTD_HC_parameters* g_seedParams = ZSTD_HC_defaultParameters[0];
static ZSTD_HC_parameters g_params = { 0, 0, 0, 0, 0, ZSTD_HC_greedy }; static ZSTD_HC_parameters g_params = { 0, 0, 0, 0, 0, ZSTD_HC_greedy };
void BMK_SetNbIterations(int nbLoops) void BMK_SetNbIterations(int nbLoops)
@@ -289,7 +289,7 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr,
U64 crcOrig; U64 crcOrig;
/* Memory allocation & restrictions */ /* Memory allocation & restrictions */
snprintf(name, 30, "W%02uC%02uH%02uS%02uL%1ust%1u", Wlog, Clog, Hlog, Slog, Slength, strat); snprintf(name, 30, "Sw%02uc%02uh%02us%02ul%1ut%1u", Wlog, Clog, Hlog, Slog, Slength, strat);
if (!compressedBuffer || !resultBuffer || !blockTable) if (!compressedBuffer || !resultBuffer || !blockTable)
{ {
DISPLAY("\nError: not enough memory!\n"); DISPLAY("\nError: not enough memory!\n");
@@ -579,24 +579,30 @@ static int BMK_seed(winnerInfo_t* winners, const ZSTD_HC_parameters params,
return better; return better;
} }
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
static BYTE g_alreadyTested[ZSTD_HC_WINDOWLOG_MAX+1-ZSTD_HC_WINDOWLOG_MIN] /* nullified useless params, to ensure count stats */
[ZSTD_HC_CONTENTLOG_MAX+1-ZSTD_HC_CONTENTLOG_MIN] static ZSTD_HC_parameters* sanitizeParams(ZSTD_HC_parameters params)
[ZSTD_HC_HASHLOG_MAX+1-ZSTD_HC_HASHLOG_MIN] {
[ZSTD_HC_SEARCHLOG_MAX+1-ZSTD_HC_SEARCHLOG_MIN] g_params = params;
[ZSTD_HC_SEARCHLENGTH_MAX+1-ZSTD_HC_SEARCHLENGTH_MIN] if (params.strategy == ZSTD_HC_fast)
[ZSTD_HC_btlazy2+1 /* strategy */ ] = {}; /* init to zero */ {
g_params.contentLog = 0;
g_params.searchLog = 0;
}
return &g_params;
}
#define PARAMTABLELOG 25
#define PARAMTABLESIZE (1<<PARAMTABLELOG)
#define PARAMTABLEMASK (PARAMTABLESIZE-1)
static BYTE g_alreadyTested[PARAMTABLESIZE] = {0}; /* init to zero */
#define NB_TESTS_PLAYED(p) \ #define NB_TESTS_PLAYED(p) \
g_alreadyTested[p.windowLog-ZSTD_HC_WINDOWLOG_MIN] \ g_alreadyTested[(XXH64(sanitizeParams(p), sizeof(p), 0) >> 3) & PARAMTABLEMASK]
[p.contentLog-ZSTD_HC_CONTENTLOG_MIN] \
[p.hashLog-ZSTD_HC_HASHLOG_MIN] \
[p.searchLog-ZSTD_HC_SEARCHLOG_MIN] \
[p.searchLength-ZSTD_HC_SEARCHLENGTH_MIN] \
[(U32)p.strategy]
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
static void playAround(FILE* f, winnerInfo_t* winners, static void playAround(FILE* f, winnerInfo_t* winners,
ZSTD_HC_parameters params, ZSTD_HC_parameters params,
const void* srcBuffer, size_t srcSize, const void* srcBuffer, size_t srcSize,
@@ -697,12 +703,13 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
int i; int i;
const char* rfName = "grillResults.txt"; const char* rfName = "grillResults.txt";
FILE* f; FILE* f;
const U32 srcLog = BMK_highbit((U32)( (g_blockSize ? g_blockSize : srcSize) -1))+1; const size_t blockSize = g_blockSize ? g_blockSize : srcSize;
const U32 srcLog = BMK_highbit((U32)(blockSize-1))+1;
if (g_singleRun) if (g_singleRun)
{ {
BMK_result_t testResult; BMK_result_t testResult;
ZSTD_HC_validateParams(&g_params, g_blockSize ? g_blockSize : srcSize); ZSTD_HC_validateParams(&g_params, blockSize);
BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, g_params); BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, g_params);
DISPLAY("\n"); DISPLAY("\n");
return; return;
@@ -719,12 +726,13 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
{ {
/* baseline config for level 1 */ /* baseline config for level 1 */
BMK_result_t testResult; BMK_result_t testResult;
params.windowLog = MIN(srcLog, 18); params.windowLog = 18;
params.hashLog = 14; params.hashLog = 14;
params.contentLog = 1; params.contentLog = 1;
params.searchLog = 1; params.searchLog = 1;
params.searchLength = 7; params.searchLength = 7;
params.strategy = ZSTD_HC_fast; params.strategy = ZSTD_HC_fast;
ZSTD_HC_validateParams(&params, blockSize);
BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, params); BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, params);
g_cSpeedTarget[1] = (testResult.cSpeed * 15) >> 4; g_cSpeedTarget[1] = (testResult.cSpeed * 15) >> 4;
} }
@@ -735,7 +743,9 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
/* populate initial solution */ /* populate initial solution */
{ {
const int tableID = (blockSize > 128 KB);
const int maxSeeds = g_noSeed ? 1 : ZSTD_HC_MAX_CLEVEL; const int maxSeeds = g_noSeed ? 1 : ZSTD_HC_MAX_CLEVEL;
g_seedParams = ZSTD_HC_defaultParameters[tableID];
for (i=1; i<=maxSeeds; i++) for (i=1; i<=maxSeeds; i++)
{ {
const U32 btPlus = (params.strategy == ZSTD_HC_btlazy2); const U32 btPlus = (params.strategy == ZSTD_HC_btlazy2);
@@ -1031,6 +1041,7 @@ int main(int argc, char** argv)
if (*argument=='K') g_blockSize<<=10, argument++; /* allows using KB notation */ if (*argument=='K') g_blockSize<<=10, argument++; /* allows using KB notation */
if (*argument=='M') g_blockSize<<=20, argument++; if (*argument=='M') g_blockSize<<=20, argument++;
if (*argument=='B') argument++; if (*argument=='B') argument++;
DISPLAY("using %u KB block size \n", g_blockSize>>10);
} }
break; break;
+1 -1
View File
@@ -70,7 +70,7 @@
**************************************/ **************************************/
#define COMPRESSOR_NAME "zstd command line interface" #define COMPRESSOR_NAME "zstd command line interface"
#ifndef ZSTD_VERSION #ifndef ZSTD_VERSION
# define ZSTD_VERSION "v0.3.4" # define ZSTD_VERSION "v0.3.6"
#endif #endif
#define AUTHOR "Yann Collet" #define AUTHOR "Yann Collet"
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), ZSTD_VERSION, AUTHOR, __DATE__ #define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), ZSTD_VERSION, AUTHOR, __DATE__