level tuning
This commit is contained in:
+75
-22
@@ -32,6 +32,24 @@
|
||||
*/
|
||||
|
||||
|
||||
/* *******************************************************
|
||||
* Compiler specifics
|
||||
*********************************************************/
|
||||
#ifdef _MSC_VER /* Visual Studio */
|
||||
# define FORCE_INLINE static __forceinline
|
||||
# include <intrin.h> /* For Visual 2005 */
|
||||
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
||||
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
|
||||
#else
|
||||
# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
# ifdef __GNUC__
|
||||
# define FORCE_INLINE static inline __attribute__((always_inline))
|
||||
# else
|
||||
# define FORCE_INLINE static inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* *************************************
|
||||
* Includes
|
||||
***************************************/
|
||||
@@ -93,14 +111,16 @@ static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
|
||||
ZSTD_HC_parameters params)
|
||||
{
|
||||
/* validate params */
|
||||
if (params.windowLog > ZSTD_HC_WINDOWLOG_MAX) params.windowLog = ZSTD_HC_WINDOWLOG_MAX;
|
||||
if (params.windowLog < ZSTD_HC_WINDOWLOG_MIN) params.windowLog = ZSTD_HC_WINDOWLOG_MIN;
|
||||
if (params.chainLog > params.windowLog) params.chainLog = params.windowLog; /* <= ZSTD_HC_CHAINLOG_MAX */
|
||||
if (params.chainLog < ZSTD_HC_CHAINLOG_MIN) params.chainLog = ZSTD_HC_CHAINLOG_MIN;
|
||||
if (params.hashLog > ZSTD_HC_HASHLOG_MAX) params.hashLog = ZSTD_HC_HASHLOG_MAX;
|
||||
if (params.hashLog < ZSTD_HC_HASHLOG_MIN) params.hashLog = ZSTD_HC_HASHLOG_MIN;
|
||||
if (params.searchLog > ZSTD_HC_SEARCHLOG_MAX) params.searchLog = ZSTD_HC_SEARCHLOG_MAX;
|
||||
if (params.searchLog < ZSTD_HC_SEARCHLOG_MIN) params.searchLog = ZSTD_HC_SEARCHLOG_MIN;
|
||||
if (params.windowLog > ZSTD_HC_WINDOWLOG_MAX) params.windowLog = ZSTD_HC_WINDOWLOG_MAX;
|
||||
if (params.windowLog < ZSTD_HC_WINDOWLOG_MIN) params.windowLog = ZSTD_HC_WINDOWLOG_MIN;
|
||||
if (params.chainLog > params.windowLog) params.chainLog = params.windowLog; /* <= ZSTD_HC_CHAINLOG_MAX */
|
||||
if (params.chainLog < ZSTD_HC_CHAINLOG_MIN) params.chainLog = ZSTD_HC_CHAINLOG_MIN;
|
||||
if (params.hashLog > ZSTD_HC_HASHLOG_MAX) params.hashLog = ZSTD_HC_HASHLOG_MAX;
|
||||
if (params.hashLog < ZSTD_HC_HASHLOG_MIN) params.hashLog = ZSTD_HC_HASHLOG_MIN;
|
||||
if (params.searchLog > ZSTD_HC_SEARCHLOG_MAX) params.searchLog = ZSTD_HC_SEARCHLOG_MAX;
|
||||
if (params.searchLog < ZSTD_HC_SEARCHLOG_MIN) params.searchLog = ZSTD_HC_SEARCHLOG_MIN;
|
||||
if (params.searchLength> ZSTD_HC_SEARCHLENGTH_MAX) params.searchLength = ZSTD_HC_SEARCHLENGTH_MAX;
|
||||
if (params.searchLength< ZSTD_HC_SEARCHLENGTH_MIN) params.searchLength = ZSTD_HC_SEARCHLENGTH_MIN;
|
||||
|
||||
/* reserve table memory */
|
||||
{
|
||||
@@ -138,25 +158,40 @@ static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
|
||||
|
||||
|
||||
/* *************************************
|
||||
* Local Macros
|
||||
* Inline functions and Macros
|
||||
***************************************/
|
||||
|
||||
#define KNUTH 2654435761U
|
||||
static U32 ZSTD_HC_hash(U32 u, U32 h) { return (u * KNUTH) >> (32-h) ; }
|
||||
static U32 ZSTD_HC_hashPtr(const void* ptr, U32 h) { return ZSTD_HC_hash(MEM_read32(ptr), h); }
|
||||
static const U32 prime4bytes = 2654435761U;
|
||||
static U32 ZSTD_HC_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32-h) ; }
|
||||
static size_t ZSTD_HC_hash4Ptr(const void* ptr, U32 h) { return ZSTD_HC_hash4(MEM_read32(ptr), h); }
|
||||
|
||||
//static const U64 prime5bytes = 889523592379ULL;
|
||||
//static U32 ZSTD_HC_hashPtr(const void* p, U32 h) { return (U32)((MEM_read64(p) * prime5bytes) << (64-40)) >> (64-h); }
|
||||
static const U64 prime5bytes = 889523592379ULL;
|
||||
static size_t ZSTD_HC_hash5(U64 u, U32 h) { return (size_t)((u * prime5bytes) << (64-40) >> (64-h)) ; }
|
||||
static size_t ZSTD_HC_hash5Ptr(const void* p, U32 h) { return ZSTD_HC_hash5(MEM_read64(p), h); }
|
||||
|
||||
static const U64 prime6bytes = 227718039650203ULL;
|
||||
static size_t ZSTD_HC_hash6(U64 u, U32 h) { return (size_t)((u * prime6bytes) << (64-48) >> (64-h)) ; }
|
||||
static size_t ZSTD_HC_hash6Ptr(const void* p, U32 h) { return ZSTD_HC_hash6(MEM_read64(p), h); }
|
||||
|
||||
static size_t ZSTD_HC_hashPtr(const void* p, U32 h, U32 mls)
|
||||
{
|
||||
switch(mls)
|
||||
{
|
||||
default:
|
||||
case 4: return ZSTD_HC_hash4Ptr(p,h);
|
||||
case 5: return ZSTD_HC_hash5Ptr(p,h);
|
||||
case 6: return ZSTD_HC_hash6Ptr(p,h);
|
||||
}
|
||||
}
|
||||
|
||||
#define NEXT_IN_CHAIN(d) chainTable[(d) & chainMask] /* flexible, CHAINSIZE dependent */
|
||||
|
||||
|
||||
|
||||
/* *************************************
|
||||
* HC Compression
|
||||
***************************************/
|
||||
/* Update chains up to ip (excluded) */
|
||||
static void ZSTD_HC_insert (ZSTD_HC_CCtx* zc, const BYTE* ip)
|
||||
static void ZSTD_HC_insert (ZSTD_HC_CCtx* zc, const BYTE* ip, U32 mls)
|
||||
{
|
||||
U32* const hashTable = zc->hashTable;
|
||||
const U32 hashLog = zc->params.hashLog;
|
||||
@@ -168,7 +203,7 @@ static void ZSTD_HC_insert (ZSTD_HC_CCtx* zc, const BYTE* ip)
|
||||
|
||||
while(idx < target)
|
||||
{
|
||||
U32 h = ZSTD_HC_hashPtr(base+idx, hashLog);
|
||||
size_t h = ZSTD_HC_hashPtr(base+idx, hashLog, mls);
|
||||
NEXT_IN_CHAIN(idx) = hashTable[h];
|
||||
hashTable[h] = idx;
|
||||
idx++;
|
||||
@@ -178,11 +213,12 @@ static void ZSTD_HC_insert (ZSTD_HC_CCtx* zc, const BYTE* ip)
|
||||
}
|
||||
|
||||
|
||||
static size_t ZSTD_HC_insertAndFindBestMatch (
|
||||
FORCE_INLINE /* inlining is important to hardwire a hot branch (template emulation) */
|
||||
size_t ZSTD_HC_insertAndFindBestMatch (
|
||||
ZSTD_HC_CCtx* zc, /* Index table will be updated */
|
||||
const BYTE* ip, const BYTE* const iLimit,
|
||||
const BYTE** matchpos,
|
||||
const U32 maxNbAttempts)
|
||||
const U32 maxNbAttempts, const U32 matchLengthSearch)
|
||||
{
|
||||
U32* const hashTable = zc->hashTable;
|
||||
const U32 hashLog = zc->params.hashLog;
|
||||
@@ -200,8 +236,8 @@ static size_t ZSTD_HC_insertAndFindBestMatch (
|
||||
size_t ml=0;
|
||||
|
||||
/* HC4 match finder */
|
||||
ZSTD_HC_insert(zc, ip);
|
||||
matchIndex = hashTable[ZSTD_HC_hashPtr(ip, hashLog)];
|
||||
ZSTD_HC_insert(zc, ip, matchLengthSearch);
|
||||
matchIndex = hashTable[ZSTD_HC_hashPtr(ip, hashLog, matchLengthSearch)];
|
||||
|
||||
while ((matchIndex>=lowLimit) && (nbAttempts))
|
||||
{
|
||||
@@ -239,6 +275,22 @@ static size_t ZSTD_HC_insertAndFindBestMatch (
|
||||
}
|
||||
|
||||
|
||||
static size_t ZSTD_HC_insertAndFindBestMatch_selectMLS (
|
||||
ZSTD_HC_CCtx* zc, /* Index table will be updated */
|
||||
const BYTE* ip, const BYTE* const iLimit,
|
||||
const BYTE** matchpos,
|
||||
const U32 maxNbAttempts, const U32 matchLengthSearch)
|
||||
{
|
||||
switch(matchLengthSearch)
|
||||
{
|
||||
default :
|
||||
case 4 : return ZSTD_HC_insertAndFindBestMatch(zc, ip, iLimit, matchpos, maxNbAttempts, 4);
|
||||
case 5 : return ZSTD_HC_insertAndFindBestMatch(zc, ip, iLimit, matchpos, maxNbAttempts, 5);
|
||||
case 6 : return ZSTD_HC_insertAndFindBestMatch(zc, ip, iLimit, matchpos, maxNbAttempts, 6);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||
{
|
||||
seqStore_t* seqStorePtr = &(ctx->seqStore);
|
||||
@@ -251,6 +303,7 @@ static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS
|
||||
|
||||
size_t offset_2=REPCODE_STARTVALUE, offset_1=REPCODE_STARTVALUE;
|
||||
const U32 maxSearches = 1 << ctx->params.searchLog;
|
||||
const U32 mls = ctx->params.searchLength;
|
||||
|
||||
/* init */
|
||||
ZSTD_resetSeqStore(seqStorePtr);
|
||||
@@ -289,7 +342,7 @@ static size_t ZSTD_HC_compressBlock(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstS
|
||||
|
||||
/* search */
|
||||
{
|
||||
size_t matchLength = ZSTD_HC_insertAndFindBestMatch(ctx, ip, iend, &match, maxSearches);
|
||||
size_t matchLength = ZSTD_HC_insertAndFindBestMatch_selectMLS(ctx, ip, iend, &match, maxSearches, mls);
|
||||
if (!matchLength) { ip++; continue; }
|
||||
/* store sequence */
|
||||
{
|
||||
|
||||
+34
-32
@@ -47,10 +47,11 @@ extern "C" {
|
||||
***************************************/
|
||||
typedef struct
|
||||
{
|
||||
U32 windowLog; /* largest match distance : impact decompression buffer size */
|
||||
U32 chainLog; /* full search distance : larger == more compression, slower, more memory*/
|
||||
U32 hashLog; /* dispatch table : larger == more memory, faster*/
|
||||
U32 searchLog; /* nb of searches : larger == more compression, slower*/
|
||||
U32 windowLog; /* largest match distance : impact decompression buffer size */
|
||||
U32 chainLog; /* full search distance : larger == more compression, slower, more memory*/
|
||||
U32 hashLog; /* dispatch table : larger == more memory, faster*/
|
||||
U32 searchLog; /* nb of searches : larger == more compression, slower*/
|
||||
U32 searchLength; /* size of matches : larger == faster decompression */
|
||||
} ZSTD_HC_parameters;
|
||||
|
||||
/* parameters boundaries */
|
||||
@@ -62,6 +63,8 @@ typedef struct
|
||||
#define ZSTD_HC_HASHLOG_MIN 4
|
||||
#define ZSTD_HC_SEARCHLOG_MAX (ZSTD_HC_CHAINLOG_MAX-1)
|
||||
#define ZSTD_HC_SEARCHLOG_MIN 1
|
||||
#define ZSTD_HC_SEARCHLENGTH_MAX 6
|
||||
#define ZSTD_HC_SEARCHLENGTH_MIN 4
|
||||
|
||||
|
||||
/* *************************************
|
||||
@@ -89,36 +92,35 @@ size_t ZSTD_HC_compressEnd(ZSTD_HC_CCtx* ctx, void* dst, size_t maxDstSize);
|
||||
#define ZSTD_HC_MAX_CLEVEL 26
|
||||
static const ZSTD_HC_parameters ZSTD_HC_defaultParameters[ZSTD_HC_MAX_CLEVEL+1] = {
|
||||
/* W, C, H, S */
|
||||
{ 18, 12, 14, 1 }, /* level 0 - never used */
|
||||
{ 18, 12, 14, 1 }, /* real level 1 - all levels below are +1 */
|
||||
{ 18, 12, 15, 2 }, /* level 1 */
|
||||
{ 19, 14, 16, 3 }, /* level 2 */
|
||||
{ 20, 18, 18, 3 }, /* level 3 */
|
||||
{ 20, 19, 19, 3 }, /* level 4 */
|
||||
{ 20, 19, 19, 4 }, /* level 5 */
|
||||
{ 20, 20, 19, 4 }, /* level 6 */
|
||||
{ 20, 19, 19, 5 }, /* level 7 */
|
||||
{ 20, 19, 19, 6 }, /* level 8 */
|
||||
{ 20, 20, 20, 6 }, /* level 9 */
|
||||
{ 21, 20, 21, 6 }, /* level 10 */
|
||||
{ 21, 20, 21, 7 }, /* level 11 */
|
||||
{ 21, 20, 22, 7 }, /* level 12 */
|
||||
{ 21, 21, 23, 7 }, /* level 13 */
|
||||
{ 21, 21, 23, 7 }, /* level 14 */
|
||||
{ 21, 21, 23, 8 }, /* level 15 */
|
||||
{ 21, 21, 23, 9 }, /* level 16 */
|
||||
{ 21, 21, 23, 9 }, /* level 17 */
|
||||
{ 21, 21, 23, 10 }, /* level 18 */
|
||||
{ 22, 22, 23, 9 }, /* level 19 */
|
||||
{ 22, 22, 23, 9 }, /* level 20 */
|
||||
{ 22, 22, 23, 10 }, /* level 21 */
|
||||
{ 22, 22, 23, 10 }, /* level 22 */
|
||||
{ 22, 22, 23, 11 }, /* level 23 */
|
||||
{ 22, 22, 23, 12 }, /* level 24 */
|
||||
{ 23, 23, 23, 11 }, /* level 25 */
|
||||
{ 18, 12, 14, 1, 4 }, /* level 0 - never used */
|
||||
{ 18, 12, 14, 1, 4 }, /* level 1 - in fact redirected towards zstd fast */
|
||||
{ 18, 12, 15, 2, 4 }, /* level 2 */
|
||||
{ 19, 14, 16, 3, 4 }, /* level 3 */
|
||||
{ 20, 15, 17, 4, 5 }, /* level 4 */
|
||||
{ 20, 17, 19, 4, 5 }, /* level 5 */
|
||||
{ 20, 19, 19, 4, 5 }, /* level 6 */
|
||||
{ 20, 19, 19, 5, 5 }, /* level 7 */
|
||||
{ 20, 20, 20, 5, 5 }, /* level 8 */
|
||||
{ 20, 20, 20, 6, 5 }, /* level 9 */
|
||||
{ 21, 21, 20, 5, 5 }, /* level 10 */
|
||||
{ 22, 21, 22, 6, 5 }, /* level 11 */
|
||||
{ 23, 21, 22, 6, 5 }, /* level 12 */
|
||||
{ 23, 21, 22, 7, 5 }, /* level 13 */
|
||||
{ 22, 22, 23, 7, 5 }, /* level 14 */
|
||||
{ 22, 22, 23, 7, 5 }, /* level 15 */
|
||||
{ 22, 22, 23, 8, 5 }, /* level 16 */
|
||||
{ 22, 22, 23, 8, 5 }, /* level 17 */
|
||||
{ 22, 22, 23, 9, 5 }, /* level 18 */
|
||||
{ 22, 22, 23, 9, 5 }, /* level 19 */
|
||||
{ 23, 23, 23, 9, 5 }, /* level 20 */
|
||||
{ 23, 23, 23, 9, 5 }, /* level 21 */
|
||||
{ 23, 23, 23, 10, 5 }, /* level 22 */
|
||||
{ 23, 23, 23, 10, 5 }, /* level 23 */
|
||||
{ 23, 23, 23, 11, 5 }, /* level 24 */
|
||||
{ 23, 23, 23, 12, 5 }, /* level 25 */
|
||||
{ 23, 23, 23, 13, 5 }, /* level 26 */ /* ZSTD_HC_MAX_CLEVEL */
|
||||
};
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user