]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
hashLog3 added to ZSTD_CCtx
authorinikep <inikep@gmail.com>
Wed, 23 Mar 2016 14:53:38 +0000 (15:53 +0100)
committerinikep <inikep@gmail.com>
Wed, 23 Mar 2016 14:53:38 +0000 (15:53 +0100)
lib/zstd_compress.c
lib/zstd_decompress.c
lib/zstd_internal.h
lib/zstd_opt.h
lib/zstd_static.h
programs/bench.c

index 28a7a1c3c6f0963187ddf8947eda4488d53fc464..2e62ec2c41a45a37f9bb31c90625e097e2dcf33a 100644 (file)
@@ -96,6 +96,7 @@ struct ZSTD_CCtx_s
     U32   lowLimit;         /* below that point, no more data */
     U32   nextToUpdate;     /* index from which to continue dictionary update */
     U32   nextToUpdate3;    /* index from which to continue dictionary update */
+    U32   hashLog3;         /* dispatch table : larger == faster, more memory */
     U32   loadedDictEnd;
     U32   stage;
     ZSTD_parameters params;
@@ -187,7 +188,7 @@ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc,
     const size_t tokenSpace = blockSize + 8*maxNbSeq;
     const size_t contentSize = (params.strategy == ZSTD_fast) ? 0 : (1 << params.contentLog);
     const size_t hSize = 1 << params.hashLog;
-    const size_t h3Size = (params.searchLength==3) ? (1 << HASHLOG3) : 0;
+    const size_t h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0;
     const size_t tableSpace = (contentSize + hSize + h3Size) * sizeof(U32);
 
     /* Check if workSpace is large enough, alloc a new one if needed */
@@ -252,12 +253,13 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx)
 {
     if (srcCCtx->stage!=0) return ERROR(stage_wrong);
 
+    dstCCtx->hashLog3 = srcCCtx->hashLog3; /* must be before ZSTD_resetCCtx_advanced */
     ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params);
 
     /* copy tables */
     {   const size_t contentSize = (srcCCtx->params.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->params.contentLog);
         const size_t hSize = 1 << srcCCtx->params.hashLog;
-        const size_t h3Size = (srcCCtx->params.searchLength == 3) ? (1 << HASHLOG3) : 0;
+        const size_t h3Size = (srcCCtx->hashLog3) ? 1 << srcCCtx->hashLog3 : 0;
         const size_t tableSpace = (contentSize + hSize + h3Size) * sizeof(U32);
         memcpy(dstCCtx->workSpace, srcCCtx->workSpace, tableSpace);
     }
@@ -310,7 +312,7 @@ static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue)
     { const U32 contentSize = (zc->params.strategy == ZSTD_fast) ? 0 : (1 << zc->params.contentLog);
       ZSTD_reduceTable(zc->contentTable, contentSize, reducerValue); }
 
-    { const U32 h3Size = (zc->params.searchLength == 3) ? (1 << HASHLOG3) : 0;
+    { const U32 h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0;
       ZSTD_reduceTable(zc->hashTable3, h3Size, reducerValue); }
 }
 
@@ -2185,7 +2187,11 @@ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* zc,
                              const void* dict, size_t dictSize,
                                    ZSTD_parameters params)
 {
+//    printf("windowLog=%d hashLog=%d\n", params.windowLog, params.hashLog);
     ZSTD_validateParams(&params);
+    zc->hashLog3 = (params.searchLength==3) ? ZSTD_HASHLOG3 : 0;
+//    if (zc->hashLog3 > params.windowLog) zc->hashLog3 = params.windowLog;
+//    printf("windowLog=%d hashLog=%d hashLog3=%d \n", params.windowLog, params.hashLog, zc->hashLog3);
 
     { size_t const errorCode = ZSTD_resetCCtx_advanced(zc, params);
     if (ZSTD_isError(errorCode)) return errorCode; }
index c90b885527e8c63d367bb18403281cbb0017ff9c..ef99175e8f85995b605c6528dd83588a33708b23 100644 (file)
@@ -149,7 +149,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
     dctx->hufTableX4[0] = HufLog;
     dctx->flagStaticTables = 0;
     dctx->fParams.mml = MINMATCH; /* overwritten by frame but forces ZSTD_btopt to MINMATCH in block mode */
-    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBegin searchLength=%d\n", dctx->base, dctx->params.searchLength);
+    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBegin searchLength=%d\n", dctx->base, dctx->fParams.mml);
     return 0;
 }
 
@@ -845,7 +845,7 @@ static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
 
     if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong);
 
-    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBlock_internal searchLength=%d\n", dctx->base, dctx->params.searchLength);
+    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBlock_internal searchLength=%d\n", dctx->base, dctx->fParams.mml);
 
     /* Decode literals sub-block */
     litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize);
@@ -953,7 +953,7 @@ size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
                                  const void* dict, size_t dictSize)
 {
     ZSTD_decompressBegin_usingDict(dctx, dict, dictSize);
-    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBegin_usingDict searchLength=%d\n", dctx->base, dctx->params.searchLength);
+    ZSTD_LOG_BLOCK("%p: ZSTD_decompressBegin_usingDict searchLength=%d\n", dctx->base, dctx->fParams.mml);
     ZSTD_checkContinuity(dctx, dst);
     return ZSTD_decompressFrame(dctx, dst, dstCapacity, src, srcSize);
 }
index ba350c4f69e1bb2d67d86d423714f0b6182018a1..3b68654e371bb7288e7821fdf577c74db1fb44d4 100644 (file)
@@ -51,9 +51,7 @@
 *  Common constants
 ***************************************/
 #define ZSTD_OPT_DEBUG 0     // 1 = tableID=0;  3 = price func tests;  5 = check encoded sequences;  9 = full logs
-#if defined(ZSTD_OPT_DEBUG) && ZSTD_OPT_DEBUG>0
-    #include <stdio.h>
-#endif
+#include <stdio.h>
 #if defined(ZSTD_OPT_DEBUG) && ZSTD_OPT_DEBUG>=9
     #define ZSTD_LOG_PARSER(...) printf(__VA_ARGS__)
     #define ZSTD_LOG_ENCODE(...) printf(__VA_ARGS__)
@@ -99,7 +97,6 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
 
 #define MINMATCH 4
 #define REPCODE_STARTVALUE 1
-#define HASHLOG3 17
 
 #define Litbits  8
 #define MLbits   7
index b8c9d67a57a7a6885aa59999deda967f7595138d..e20379c111dec6251ad8033628b0c8b36ecbab22 100644 (file)
@@ -196,17 +196,18 @@ MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const B
 static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_CCtx* zc, const BYTE* ip)
 {
     U32* const hashTable3  = zc->hashTable3;
+    U32 const hashLog3  = zc->hashLog3;
     const BYTE* const base = zc->base;
     const U32 target = (U32)(ip - base);
     U32 idx = zc->nextToUpdate3;
 
     while(idx < target) {
-        hashTable3[ZSTD_hash3Ptr(base+idx, HASHLOG3)] = idx;
+        hashTable3[ZSTD_hash3Ptr(base+idx, hashLog3)] = idx;
         idx++;
     }
 
     zc->nextToUpdate3 = target;
-    return hashTable3[ZSTD_hash3Ptr(ip, HASHLOG3)];
+    return hashTable3[ZSTD_hash3Ptr(ip, hashLog3)];
 }
 
 
index 4ae771fdeb4e3a1627599c6ae79591643545fb3e..d41bc841ff02f6687901dc89b8137efd2b56041a 100644 (file)
@@ -63,6 +63,7 @@ extern "C" {
 #define ZSTD_CONTENTLOG_MIN     4
 #define ZSTD_HASHLOG_MAX       28
 #define ZSTD_HASHLOG_MIN       12
+#define ZSTD_HASHLOG3          17
 #define ZSTD_SEARCHLOG_MAX    (ZSTD_CONTENTLOG_MAX-1)
 #define ZSTD_SEARCHLOG_MIN      1
 #define ZSTD_SEARCHLENGTH_MAX   7
index 84380400d255cf46f07893ef0cdd1bc16d0866b8..d3e9c1f1df68c1030c035ed0e448481dde550829 100644 (file)
@@ -288,7 +288,15 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
 
             for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
                 U32 blockNb;
+#if 0
                 ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
+#else
+                ZSTD_parameters params = ZSTD_getParams(cLevel, dictBufferSize ? dictBufferSize : blockSize);
+           //     printf("cLevel=%d dictBufferSize=%d srcSize=%d params.srcSize=%d \n", cLevel, (int)dictBufferSize, (int)blockTable[0].srcSize, (int)params.srcSize);
+                params.srcSize = 0;
+                ZSTD_compressBegin_advanced(refCtx, dictBuffer, dictBufferSize, params);
+#endif
+
                 for (blockNb=0; blockNb<nbBlocks; blockNb++) {
                     size_t const rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
                                         blockTable[blockNb].cPtr,  blockTable[blockNb].cRoom,