]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added support for MINMATCH=3 on big endian architecture
authorinikep <inikep@gmail.com>
Mon, 7 Mar 2016 09:07:08 +0000 (10:07 +0100)
committerinikep <inikep@gmail.com>
Mon, 7 Mar 2016 09:07:08 +0000 (10:07 +0100)
changed ZSTD_HASHLOG3_MIN to 2 (4 bytes for MINMACH > 3)

lib/mem.h
lib/zstd_compress.c
lib/zstd_opt.h
lib/zstd_static.h

index a369033b1f5c9fe283d95fa4e7a1ade5bb109b04..ceafd57b48bdfe14812c67c5fca0a6427d5db1fd 100644 (file)
--- a/lib/mem.h
+++ b/lib/mem.h
@@ -187,17 +187,6 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
 
 #endif /* MEM_FORCE_MEMORY_ACCESS */
 
-
-MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
-{
-    switch (length)
-    {
-    default :
-    case 4 : return MEM_read32(memPtr);
-    case 3 : return MEM_read32(memPtr)<<8;
-    }
-}
-
 MEM_STATIC U16 MEM_readLE16(const void* memPtr)
 {
     if (MEM_isLittleEndian())
@@ -286,6 +275,20 @@ MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val)
         MEM_writeLE64(memPtr, (U64)val);
 }
 
+ /* function safe only for comparisons */
+MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
+{
+    switch (length)
+    {
+    default :
+    case 4 : return MEM_read32(memPtr);
+    case 3 : if (MEM_isLittleEndian())
+                return MEM_read32(memPtr)<<8;
+             else
+                return MEM_read32(memPtr)>>8;
+    }
+}
+
 #if defined (__cplusplus)
 }
 #endif
index e24016c7a9b11907cb568896aefa78224dea4e60..87e8e72ee2f3df3e06aef3bacabc2d256defac2d 100644 (file)
@@ -876,7 +876,7 @@ static size_t ZSTD_count_2segments(const BYTE* ip, const BYTE* match, const BYTE
 ***************************************/
 static const U32 prime3bytes = 506832829U;
 static U32    ZSTD_hash3(U32 u, U32 h) { return ((u << (32-24)) * prime3bytes)  >> (32-h) ; }
-static size_t ZSTD_hash3Ptr(const void* ptr, U32 h) { return ZSTD_hash3(MEM_read32(ptr), h); }
+static size_t ZSTD_hash3Ptr(const void* ptr, U32 h) { return ZSTD_hash3(MEM_readLE32(ptr), h); }
 
 static const U32 prime4bytes = 2654435761U;
 static U32    ZSTD_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32-h) ; }
index c6205089fa62e1e168e89db89ceae25acfab0340..0c4a80f77c69cb2e5d063cece2b66a64afdb144c 100644 (file)
@@ -335,10 +335,9 @@ static U32 ZSTD_BtGetAllMatches (
 
 static U32 ZSTD_BtGetAllMatches_selectMLS (
                         ZSTD_CCtx* zc,   /* Index table will be updated */
-                        const BYTE* ip, const BYTE* const iLowLimit, const BYTE* const iHighLimit,
+                        const BYTE* ip, const BYTE* const iHighLimit,
                         const U32 maxNbAttempts, const U32 matchLengthSearch, ZSTD_match_t* matches)
 {
-    (void)iLowLimit;  /* unused */
     switch(matchLengthSearch)
     {
     default :
@@ -363,10 +362,9 @@ static U32 ZSTD_BtGetAllMatches_extDict (
 
 static U32 ZSTD_BtGetAllMatches_selectMLS_extDict (
                         ZSTD_CCtx* zc,   /* Index table will be updated */
-                        const BYTE* ip, const BYTE* const iLowLimit, const BYTE* const iHighLimit,
+                        const BYTE* ip, const BYTE* const iHighLimit,
                         const U32 maxNbAttempts, const U32 matchLengthSearch, ZSTD_match_t* matches)
 {
-    (void)iLowLimit;
     switch(matchLengthSearch)
     {
     default :
@@ -447,7 +445,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
             } while (mlen >= minMatch);
         }
 
-        match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, ip, ip, iend, maxSearches, mls, matches); /* first search (depth 0) */
+        match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, ip, iend, maxSearches, mls, matches); /* first search (depth 0) */
 
         ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
         if (!last_pos && !match_num) { ip++; continue; }
@@ -567,7 +565,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
                 } while (mlen >= minMatch);
             }
 
-            match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, inr, ip, iend, maxSearches, mls, matches);
+            match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, inr, iend, maxSearches, mls, matches);
             ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
 
             if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
@@ -779,7 +777,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
 
        best_mlen = (last_pos) ? last_pos : minMatch;
 
-       match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, ip, ip, iend, maxSearches, mls, matches);  /* first search (depth 0) */
+       match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, ip, iend, maxSearches, mls, matches);  /* first search (depth 0) */
 
        ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
        if (!last_pos && !match_num) { ip++; continue; }
@@ -909,7 +907,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
 
             best_mlen = (best_mlen > minMatch) ? best_mlen : minMatch;
 
-            match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, inr, ip, iend, maxSearches, mls, matches);
+            match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, inr, iend, maxSearches, mls, matches);
             ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
 
             if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
index fa285ad4c19400bb5dce640cdc8fd96cbf8bdbf1..0effaa7ce4907b29e78c25aad9ed48111dcc9c3a 100644 (file)
@@ -65,7 +65,7 @@ extern "C" {
 #define ZSTD_HASHLOG_MAX 28
 #define ZSTD_HASHLOG_MIN 12
 #define ZSTD_HASHLOG3_MAX 24
-#define ZSTD_HASHLOG3_MIN 12
+#define ZSTD_HASHLOG3_MIN 2
 #define ZSTD_SEARCHLOG_MAX (ZSTD_CONTENTLOG_MAX-1)
 #define ZSTD_SEARCHLOG_MIN 1
 #define ZSTD_SEARCHLENGTH_MAX 7