]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Simplify generic hash function using knuth's multiplicative hash.
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 1 May 2020 04:05:05 +0000 (21:05 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 24 May 2020 12:32:26 +0000 (14:32 +0200)
deflate.c
deflate.h
deflate_fast.c
deflate_medium.c
insert_string.c

index 939f47ed0c42c97abce3a8b7ca39b75cca54c576..6825f3efbf3d5432ca29d5e80d2bbc8515993dae 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -329,9 +329,6 @@ int ZEXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int level, int method,
 
     s->hash_size = 1 << s->hash_bits;
     s->hash_mask = s->hash_size - 1;
-#if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86)
-    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-#endif
 
 #ifdef X86_PCLMULQDQ_CRC
     window_padding = 8;
@@ -1204,7 +1201,6 @@ static void lm_init(deflate_state *s) {
     s->match_length = s->prev_length = MIN_MATCH-1;
     s->match_available = 0;
     s->match_start = 0;
-    s->ins_h = 0;
 }
 
 #ifdef ZLIB_DEBUG
@@ -1290,7 +1286,6 @@ void ZLIB_INTERNAL fill_window(deflate_state *s) {
         /* Initialize the hash value now that we have some input: */
         if (s->lookahead + s->insert >= MIN_MATCH) {
             unsigned int str = s->strstart - s->insert;
-            s->ins_h = s->window[str];
             if (str >= 1)
                 functable.quick_insert_string(s, str + 2 - MIN_MATCH);
 #if MIN_MATCH != 3
index 00a448cf674c87b9b72bc519844ec7edc66dc1a2..4d1f218857d41da48bc849a428a547a6b037ee75 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -147,20 +147,10 @@ typedef struct internal_state {
 
     Pos *head; /* Heads of the hash chains or NIL. */
 
-    unsigned int  ins_h;             /* hash index of string to be inserted */
     unsigned int  hash_size;         /* number of elements in hash table */
     unsigned int  hash_bits;         /* log2(hash_size) */
     unsigned int  hash_mask;         /* hash_size-1 */
 
-#if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86)
-    unsigned int  hash_shift;
-#endif
-    /* Number of bits by which ins_h must be shifted at each input
-     * step. It must be such that after MIN_MATCH steps, the oldest
-     * byte no longer takes part in the hash key, that is:
-     *   hash_shift * MIN_MATCH >= hash_bits
-     */
-
     long block_start;
     /* Window position at the beginning of the current output block. Gets
      * negative when the window is moved backwards.
index 12244fe73462de11d81284b8ef9296b91d51dac4..1910645360883b367707ca46a3c417f6234ac112 100644 (file)
@@ -74,7 +74,6 @@ ZLIB_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
             } else {
                 s->strstart += s->match_length;
                 s->match_length = 0;
-                s->ins_h = s->window[s->strstart];
 #if MIN_MATCH != 3
                 functable.insert_string(s, s->strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
 #else
index f58e49982f2e857502ea1bb7ea1fb9b1b9e55735..81b3ad78eaad3b241dd06e279ba5236514a9f161 100644 (file)
@@ -85,7 +85,6 @@ static void insert_match(deflate_state *s, struct match match) {
     } else {
         match.strstart += match.match_length;
         match.match_length = 0;
-        s->ins_h = s->window[match.strstart];
         if (match.strstart >= (MIN_MATCH - 2))
 #if MIN_MATCH != 3
             functable.insert_string(s, match.strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
index e9efd517f88709065ecbd14f686e9315573f40ae..774d18ada9efafa21c39d29086880ee2cec62350 100644 (file)
  *    previous key instead of complete recalculation each time.
  */
 
-#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
-#  define UPDATE_HASH(s, h, val) \
-    h = (3483  * ((val) & 0xff) +\
-         23081 * (((val) >> 8) & 0xff) +\
-         6954  * (((val) >> 16) & 0xff) +\
-         20947 * (((val) >> 24) & 0xff));
-#else
-#  define UPDATE_HASH(s, h, val)\
-    h = (s->ins_h = ((s->ins_h << s->hash_shift) ^ ((val) >> ((MIN_MATCH - 1) * 8))) & s->hash_mask)
-#endif
+#define UPDATE_HASH(s, h, val) \
+    h = ((val * 2654435761U) >> (32 - s->hash_bits));
 
 #define INSERT_STRING       insert_string_c
 #define QUICK_INSERT_STRING quick_insert_string_c