]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
introduced ZSTD_REP_MOVE and ZSTD_REP_INIT
authorinikep <inikep@gmail.com>
Fri, 18 Mar 2016 10:03:43 +0000 (11:03 +0100)
committerinikep <inikep@gmail.com>
Fri, 18 Mar 2016 10:03:43 +0000 (11:03 +0100)
lib/zstd_compress.c
lib/zstd_decompress.c
lib/zstd_internal.h
lib/zstd_opt.h

index 6f74d1d3cf88539ca8b142995401624db9dd7a2a..7c8570345fd5f53d2b2e13d5476e2f186a654e96 100644 (file)
@@ -993,7 +993,7 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* zc,
             offset_2 = offset_1;
             offset_1 = offset;
 
-            ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_NUM - 1, mlCode);
+            ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mlCode);
         }
 
         /* match found */
@@ -1105,7 +1105,7 @@ static void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
                 offset = current - matchIndex;
                 offset_2 = offset_1;
                 offset_1 = offset;
-                ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_NUM - 1, mlCode);
+                ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mlCode);
         }   }
 
         /* found a match : store it */
@@ -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+1];
-    for (int i=0; i<ZSTD_REP_NUM+1; i++)
+    U32 rep[ZSTD_REP_INIT];
+    for (int i=0; i<ZSTD_REP_INIT; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ZSTD_resetSeqStore(seqStorePtr);
@@ -1598,7 +1598,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
             size_t offsetFound = 99999999;
             size_t ml2 = searchMax(ctx, ip, iend, &offsetFound, maxSearches, mls);
             if (ml2 > matchLength)
-                matchLength = ml2, start = ip, offset=offsetFound + (ZSTD_REP_NUM - 1);
+                matchLength = ml2, start = ip, offset=offsetFound + ZSTD_REP_MOVE;
         }
 
         if (matchLength < MINMATCH) {
@@ -1624,7 +1624,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
                 int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
                 int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 4);
                 if ((ml2 >= MINMATCH) && (gain2 > gain1)) {
-                    matchLength = ml2, offset = offset2 + (ZSTD_REP_NUM - 1), start = ip;
+                    matchLength = ml2, offset = offset2 + ZSTD_REP_MOVE, start = ip;
                     continue;   /* search a better one */
             }   }
 
@@ -1645,7 +1645,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
                     int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
                     int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
                     if ((ml2 >= MINMATCH) && (gain2 > gain1)) {
-                        matchLength = ml2, offset = offset2 + (ZSTD_REP_NUM - 1), start = ip;
+                        matchLength = ml2, offset = offset2 + ZSTD_REP_MOVE, start = ip;
                         continue;
             }   }   }
             break;  /* nothing found : store previous solution */
@@ -1653,7 +1653,7 @@ void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
 
         /* catch up */
         if (offset >= ZSTD_REP_NUM) {
-            while ((start>anchor) && (start>base+offset-(ZSTD_REP_NUM-1)) && (start[-1] == start[-1-offset+(ZSTD_REP_NUM-1)]))   /* only search for offset within prefix */
+            while ((start>anchor) && (start>base+offset-ZSTD_REP_MOVE) && (start[-1] == start[-1-offset+ZSTD_REP_MOVE]))   /* only search for offset within prefix */
                 { start--; matchLength++; }
         }
 
@@ -1666,7 +1666,7 @@ _storeSequence:
                 rep[3] = rep[2];
                 rep[2] = rep[1];
                 rep[1] = rep[0];
-                rep[0] = offset - (ZSTD_REP_NUM - 1);
+                rep[0] = offset - ZSTD_REP_MOVE;
 #else
                 if (kSlotNew < 3)
                     rep[3] = rep[2];
@@ -1674,7 +1674,7 @@ _storeSequence:
                     rep[2] = rep[1];
                 if (kSlotNew < 1)
                     rep[1] = rep[0];               
-                rep[kSlotNew] = offset - (ZSTD_REP_NUM - 1);
+                rep[kSlotNew] = offset - ZSTD_REP_MOVE;
 #endif
             } else {
                 if (offset != 0) {
@@ -1691,7 +1691,7 @@ _storeSequence:
             }
 #else
             if (offset >= ZSTD_REP_NUM) {
-                rep[1] = rep[0]; rep[0] = offset - (ZSTD_REP_NUM - 1);
+                rep[1] = rep[0]; rep[0] = offset - ZSTD_REP_MOVE;
             }
 #endif
             size_t litLength = start - anchor;
@@ -1764,8 +1764,8 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx,
     printf("ZSTD_compressBlock_lazy_extDict_generic reps not implemented!\n"); exit(1);
 
     /* init */
-    U32 rep[ZSTD_REP_NUM];
-    for (int i=0; i<ZSTD_REP_NUM; i++)
+    U32 rep[ZSTD_REP_INIT];
+    for (int i=0; i<ZSTD_REP_INIT; i++)
         rep[i]=REPCODE_STARTVALUE;
     ZSTD_resetSeqStore(seqStorePtr);
     if ((ip - prefixStart) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
@@ -1795,7 +1795,7 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx,
             size_t offsetFound = 99999999;
             size_t ml2 = searchMax(ctx, ip, iend, &offsetFound, maxSearches, mls);
             if (ml2 > matchLength)
-                matchLength = ml2, start = ip, offset=offsetFound + (ZSTD_REP_NUM - 1);
+                matchLength = ml2, start = ip, offset=offsetFound + ZSTD_REP_MOVE;
         }
 
          if (matchLength < MINMATCH) {
@@ -1831,7 +1831,7 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx,
                 int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
                 int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 4);
                 if ((ml2 >= MINMATCH) && (gain2 > gain1)) {
-                    matchLength = ml2, offset = offset2 + (ZSTD_REP_NUM - 1), start = ip;
+                    matchLength = ml2, offset = offset2 + ZSTD_REP_MOVE, start = ip;
                     continue;   /* search a better one */
             }   }
 
@@ -1862,7 +1862,7 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx,
                     int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
                     int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
                     if ((ml2 >= MINMATCH) && (gain2 > gain1)) {
-                        matchLength = ml2, offset = offset2 + (ZSTD_REP_NUM - 1), start = ip;
+                        matchLength = ml2, offset = offset2 + ZSTD_REP_MOVE, start = ip;
                         continue;
             }   }   }
             break;  /* nothing found : store previous solution */
@@ -1870,11 +1870,11 @@ void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx,
 
         /* catch up */
         if (offset >= ZSTD_REP_NUM) {
-            U32 matchIndex = (U32)((start-base) - (offset - (ZSTD_REP_NUM - 1)));
+            U32 matchIndex = (U32)((start-base) - (offset - ZSTD_REP_MOVE));
             const BYTE* match = (matchIndex < dictLimit) ? dictBase + matchIndex : base + matchIndex;
             const BYTE* const mStart = (matchIndex < dictLimit) ? dictStart : prefixStart;
             while ((start>anchor) && (match>mStart) && (start[-1] == match[-1])) { start--; match--; matchLength++; }  /* catch up */
-            rep[1] = rep[0]; rep[0] = offset - (ZSTD_REP_NUM - 1);
+            rep[1] = rep[0]; rep[0] = offset - ZSTD_REP_MOVE;
         }
 
         /* store sequence */
index 6e0e39b78f3881ddea375120a689a46f97281b2c..201e6751695de0ebfc61aea8aa2111335aa8f470 100644 (file)
@@ -615,7 +615,7 @@ typedef struct {
     FSE_DState_t stateLL;
     FSE_DState_t stateOffb;
     FSE_DState_t stateML;
-    size_t prevOffset[ZSTD_REP_NUM];
+    size_t prevOffset[ZSTD_REP_INIT];
     const BYTE* dumps;
     const BYTE* dumpsEnd;
 } seqState_t;
@@ -672,13 +672,13 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
             else
                 offset = seqState->prevOffset[0];
         } else {
-            offset -= ZSTD_REP_NUM - 1;
-#if 0
+            offset -= ZSTD_REP_MOVE;
+    #if 0
             seqState->prevOffset[3] = seqState->prevOffset[2];
             seqState->prevOffset[2] = seqState->prevOffset[1];
             seqState->prevOffset[1] = seqState->prevOffset[0];
             seqState->prevOffset[0] = offset;
-#else
+    #else
             if (kSlotNew < 3)
                 seqState->prevOffset[3] = seqState->prevOffset[2];
             if (kSlotNew < 2)
@@ -686,11 +686,25 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState, const U32 mls)
             if (kSlotNew < 1)
                 seqState->prevOffset[1] = seqState->prevOffset[0];               
             seqState->prevOffset[kSlotNew] = offset;
-#endif
+    #endif
         }
-#else
+#else // ZSTD_REP_NUM == 1
+    #if 0
         if (offsetCode==0) offset = litLength ? seq->offset : seqState->prevOffset[0];   /* repcode, cmove */
+        else offset -= ZSTD_REP_MOVE;
         if (offsetCode | !litLength) seqState->prevOffset[0] = seq->offset;   /* cmove */
+    #else
+        if (offsetCode==0) {
+            if (!litLength) {
+                offset = seqState->prevOffset[0];   /* repcode, cmove */
+                seqState->prevOffset[0] = seq->offset;   /* cmove */
+            } else
+                offset = seq->offset;   /* repcode, cmove */
+        } else {
+            seqState->prevOffset[0] = seq->offset;   /* cmove */
+            offset -= ZSTD_REP_MOVE;
+        }
+    #endif
 #endif
         FSE_decodeSymbol(&(seqState->stateOffb), &(seqState->DStream));    /* update */
 //    printf("offsetCode=%d nbBits=%d offset=%d\n", offsetCode, nbBits, (int)offset); fflush(stdout);
@@ -845,7 +859,7 @@ static size_t ZSTD_decompressSequences(
         sequence.offset = REPCODE_STARTVALUE;
         seqState.dumps = dumps;
         seqState.dumpsEnd = dumps + dumpsLength;
-        for (int i=0; i<ZSTD_REP_NUM; i++)
+        for (int i=0; i<ZSTD_REP_INIT; i++)
             seqState.prevOffset[i] = REPCODE_STARTVALUE;
         errorCode = BIT_initDStream(&(seqState.DStream), ip, iend-ip);
         if (ERR_isError(errorCode)) return ERROR(corruption_detected);
index 208bf5048b4bc92ceb64b535b4ed4564ae549253..43179c57001188a4f4b4ecf465c16934d4e5ea2f 100644 (file)
 
 #define ZSTD_OPT_NUM    (1<<12)
 #define ZSTD_DICT_MAGIC  0xEC30A435
-#define ZSTD_REP_NUM    4
+#if 1
+    #define ZSTD_REP_NUM    4
+    #define ZSTD_REP_INIT   4
+    #define ZSTD_REP_MOVE  (ZSTD_REP_NUM-1)
+#else
+    #define ZSTD_REP_NUM    1
+    #define ZSTD_REP_INIT   2
+    #define ZSTD_REP_MOVE  (ZSTD_REP_NUM-1)
+#endif
 
 #define KB *(1 <<10)
 #define MB *(1 <<20)
index 692af92c90d6c34d0e5f991b255275fa75b36324..5567b44a5eca249ff2c098de866911453dc4ced3 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+1];
-    for (int i=0; i<ZSTD_REP_NUM+1; i++)
+    U32 rep[ZSTD_REP_INIT];
+    for (int i=0; i<ZSTD_REP_INIT; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ctx->nextToUpdate3 = ctx->nextToUpdate;
@@ -688,7 +688,7 @@ _storeSequence:   /* cur, last_pos, best_mlen, best_off have to be set */
 #endif
 
             ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen-minMatch);
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset ? offset + ZSTD_REP_NUM - 1 : 0, mlen-minMatch);
+            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset ? offset + ZSTD_REP_MOVE : 0, mlen-minMatch);
             anchor = ip = ip + mlen;
         }   /* for (cur=0; cur < last_pos; ) */
 
@@ -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+1];
-    for (int i=0; i<ZSTD_REP_NUM+1; i++)
+    U32 rep[ZSTD_REP_INIT];
+    for (int i=0; i<ZSTD_REP_INIT; i++)
         rep[i]=REPCODE_STARTVALUE;
 
     ctx->nextToUpdate3 = ctx->nextToUpdate;
@@ -1036,7 +1036,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
 #endif
 
             ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen-minMatch);
-            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset ? offset + ZSTD_REP_NUM - 1 : 0, mlen-minMatch);
+            ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset ? offset + ZSTD_REP_MOVE : 0, mlen-minMatch);
             anchor = ip = ip + mlen;
         }