]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
support for ZSTD_REP_NUM == 1 and ZSTD_REP_NUM == 4
authorinikep <inikep@gmail.com>
Thu, 17 Mar 2016 10:21:00 +0000 (11:21 +0100)
committerinikep <inikep@gmail.com>
Thu, 17 Mar 2016 10:21:00 +0000 (11:21 +0100)
lib/zstd_compress.c
lib/zstd_decompress.c
lib/zstd_opt.h
programs/bench.c

index 967ecc065ae44f1f4c5291cdfa1571d73aa01280..f9022cc86786570b2bcaa5894be7129da38198c7 100644 (file)
@@ -1092,7 +1092,7 @@ static void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
             const BYTE* repMatchEnd = repIndex < dictLimit ? dictEnd : iend;
             mlCode = ZSTD_count_2segments(ip+1+MINMATCH, repMatch+MINMATCH, iend, repMatchEnd, lowPrefixPtr);
             ip++;
-            ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset, mlCode);
+            ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, 0, mlCode);
         } else {
             if ( (matchIndex < lowLimit) ||
                  (MEM_read32(match) != MEM_read32(ip)) )
@@ -1563,8 +1563,8 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
     searchMax_f searchMax = searchMethod ? ZSTD_BtFindBestMatch_selectMLS : ZSTD_HcFindBestMatch_selectMLS;
 
     /* init */
-    U32 rep[ZSTD_REP_NUM];
-    for (int i=0; i<ZSTD_REP_NUM; i++)
+    U32 rep[ZSTD_REP_NUM+1];
+    for (int i=0; i<ZSTD_REP_NUM+1; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ZSTD_resetSeqStore(seqStorePtr);
@@ -1586,8 +1586,8 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
                 if (depth==0) goto _storeSequence;
             } else {                   
                 size_t mlRep = ZSTD_count(ip+1+MINMATCH, ip+1+MINMATCH-rep[i], iend) + MINMATCH;
-                int gain2 = (int)(mlRep * 3 - (i+1));
-                int gain1 = (int)(matchLength*3 - (offset+1) + 1);
+                int gain2 = (int)(mlRep * 3 /*- ZSTD_highbit((U32)i+1)*/);
+                int gain1 = (int)(matchLength*3 - /*ZSTD_highbit((U32)offset+1)*/ + 1);
                 if (gain2 > gain1)
                     matchLength = mlRep, offset = i;
             }
@@ -1660,6 +1660,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
         /* store sequence */
 _storeSequence:
         {
+#if ZSTD_REP_NUM == 4
             if (offset >= ZSTD_REP_NUM) {
                 rep[3] = rep[2];
                 rep[2] = rep[1];
@@ -1676,6 +1677,11 @@ _storeSequence:
                     rep[0] = temp;
                 }
             }
+#else
+            if (offset >= ZSTD_REP_NUM) {
+                rep[1] = rep[0]; rep[0] = offset - (ZSTD_REP_NUM - 1);
+            }
+#endif
             size_t litLength = start - anchor;
             ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, matchLength-MINMATCH);
             anchor = ip = start + matchLength;
index 4f7ba6d76ccb77a1fce397ebd6d74b34e42509df..305f9b90fa50adc7d0ed5f560153c35f7574337e 100644 (file)
@@ -632,6 +632,9 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
 
     /* Literal length */
     litLength = FSE_peakSymbol(&(seqState->stateLL));
+#if 0 //ZSTD_REP_NUM == 1
+    size_t prevOffset = litLength ? seq->offset : seqState->prevOffset[0];
+#endif
     if (litLength == MaxLL) {
         U32 add = *dumps++;
         if (add < 255) litLength += add;
@@ -654,6 +657,7 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
         if (offsetCode==0) nbBits = 0;   /* cmove */
         offset = offsetPrefix[offsetCode] + BIT_readBits(&(seqState->DStream), nbBits);
         if (MEM_32bits()) BIT_reloadDStream(&(seqState->DStream));
+#if ZSTD_REP_NUM == 4
         if (offsetCode==0) {
             if (!litLength) {
                 offset = seqState->prevOffset[1];
@@ -675,7 +679,16 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
                 seqState->prevOffset[2] = seqState->prevOffset[1];
                 seqState->prevOffset[1] = seq->offset;   /* cmove */
             }
-        } 
+        }
+#else
+#if 0
+        if (offsetCode==0) offset = prevOffset;   /* repcode, cmove */
+        if (offsetCode | !litLength) seqState->prevOffset[0] = seq->offset;   /* cmove */
+#else
+        if (offsetCode==0) offset = litLength ? seq->offset : seqState->prevOffset[0];   /* repcode, cmove */
+        if (offsetCode | !litLength) seqState->prevOffset[0] = seq->offset;   /* cmove */
+#endif
+#endif
         FSE_decodeSymbol(&(seqState->stateOffb), &(seqState->DStream));    /* update */
 //    printf("offsetCode=%d nbBits=%d offset=%d\n", offsetCode, nbBits, (int)offset); fflush(stdout);
     }
index 0648a2aeb48a79a9d6f928ba32e2bc77c04eb270..692af92c90d6c34d0e5f991b255275fa75b36324 100644 (file)
@@ -420,8 +420,8 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
     U32 cur, match_num, last_pos, litlen, price;
 
     /* init */
-    U32 rep[ZSTD_REP_NUM];
-    for (int i=0; i<ZSTD_REP_NUM; i++)
+    U32 rep[ZSTD_REP_NUM+1];
+    for (int i=0; i<ZSTD_REP_NUM+1; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ctx->nextToUpdate3 = ctx->nextToUpdate;
@@ -748,8 +748,8 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
     U32 cur, match_num, last_pos, litlen, price;
 
     /* init */
-    U32 rep[ZSTD_REP_NUM];
-    for (int i=0; i<ZSTD_REP_NUM; i++)
+    U32 rep[ZSTD_REP_NUM+1];
+    for (int i=0; i<ZSTD_REP_NUM+1; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ctx->nextToUpdate3 = ctx->nextToUpdate;
index fd4f9b54718045b274eed31d412ebe7e6f039de6..0499cc3c923d462079edb4c10a2cf9b1dbbd29e6 100644 (file)
@@ -280,7 +280,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
     }   }   }
 
     /* warmimg up memory */
-    int timeloop = additionalParam; //2500;
+    int timeloop = additionalParam ? additionalParam : 2500;
     ZSTD_setAdditionalParam(refCtx, additionalParam);
     RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);