]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Replace hash_bits, hash_size and hash_mask with defines.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 21 Aug 2020 13:53:30 +0000 (15:53 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 23 Aug 2020 07:57:45 +0000 (09:57 +0200)
arch/arm/slide_neon.c
arch/power/slide_hash_power8.c
arch/x86/slide_avx.c
arch/x86/slide_sse.c
deflate.c
deflate.h
insert_string.c
insert_string_tpl.h
match_tpl.h

index b5b4fdf0a571dd7fe60fcc3d20eeca56b852d944..e5bea64f069da4da1c69aed182a04d69ea544d79 100644 (file)
@@ -46,7 +46,7 @@ static inline void slide_hash_chain(Pos *table, unsigned int entries, uint16_t w
 ZLIB_INTERNAL void slide_hash_neon(deflate_state *s) {
     unsigned int wsize = s->w_size;
 
-    slide_hash_chain(s->head, s->hash_size, wsize);
+    slide_hash_chain(s->head, HASH_SIZE, wsize);
     slide_hash_chain(s->prev, wsize, wsize);
 }
 #endif
index b869307a09c8f2645b26460fc1694acb4fac32cb..8bd79dfa8afda7161529a1bc38e8a31bace090b4 100644 (file)
@@ -48,7 +48,7 @@ void ZLIB_INTERNAL slide_hash_power8(deflate_state *s) {
     unsigned int n;
     Pos *p;
 
-    n = s->hash_size;
+    n = HASH_SIZE;
     p = &s->head[n];
     slide_hash_power8_loop(s,n,p);
 
index 6083dc7d6146879e4a1dd1cadbbdf6707e7cd592..42ba91214451be5f8c82d41b0f451fe3d485830a 100644 (file)
@@ -20,7 +20,7 @@ ZLIB_INTERNAL void slide_hash_avx2(deflate_state *s) {
     uint16_t wsize = (uint16_t)s->w_size;
     const __m256i zmm_wsize = _mm256_set1_epi16(wsize);
 
-    n = s->hash_size;
+    n = HASH_SIZE;
     p = &s->head[n] - 16;
     do {
         __m256i value, result;
index f57a7d33e3f1dcfc19ee9df61a02f0c6379ba428..7ae79a828bb40cfb7f9fe1072a630ff7c635098f 100644 (file)
@@ -19,7 +19,7 @@ ZLIB_INTERNAL void slide_hash_sse2(deflate_state *s) {
     uint16_t wsize = (uint16_t)s->w_size;
     const __m128i xmm_wsize = _mm_set1_epi16(wsize);
 
-    n = s->hash_size;
+    n = HASH_SIZE;
     p = &s->head[n] - 8;
     do {
         __m128i value, result;
index 2a7fd1e4424ba6bc25d18a361592f4efbf778d5a..a7d9a5a09f5594be90b15f5c8877ed81e45244bc 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -180,12 +180,10 @@ static const config configuration_table[10] = {
 
 
 /* ===========================================================================
- * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
- * prev[] will be initialized on the fly.
+ * Initialize the hash table. prev[] will be initialized on the fly.
  */
 #define CLEAR_HASH(s) do {                                                                \
-    s->head[s->hash_size - 1] = NIL;                                                      \
-    memset((unsigned char *)s->head, 0, (unsigned)(s->hash_size - 1) * sizeof(*s->head)); \
+    memset((unsigned char *)s->head, 0, HASH_SIZE * sizeof(*s->head)); \
   } while (0)
 
 /* ===========================================================================
@@ -194,11 +192,11 @@ static const config configuration_table[10] = {
  * keep the hash table consistent if we switch back to level > 0 later.
  */
 ZLIB_INTERNAL void slide_hash_c(deflate_state *s) {
-    unsigned n;
     Pos *p;
+    unsigned n;
     unsigned int wsize = s->w_size;
 
-    n = s->hash_size;
+    n = HASH_SIZE;
     p = &s->head[n];
 #ifdef NOT_TWEAK_COMPILER
     do {
@@ -322,16 +320,6 @@ int32_t ZEXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int3
     s->w_size = 1 << s->w_bits;
     s->w_mask = s->w_size - 1;
 
-#ifdef X86_SSE42_CRC_HASH
-    if (x86_cpu_has_sse42)
-        s->hash_bits = (unsigned int)15;
-    else
-#endif
-        s->hash_bits = (unsigned int)memLevel + 7;
-
-    s->hash_size = 1 << s->hash_bits;
-    s->hash_mask = s->hash_size - 1;
-
 #ifdef X86_PCLMULQDQ_CRC
     window_padding = 8;
 #endif
@@ -339,7 +327,7 @@ int32_t ZEXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int3
     s->window = (unsigned char *) ZALLOC_WINDOW(strm, s->w_size + window_padding, 2*sizeof(unsigned char));
     s->prev   = (Pos *)  ZALLOC(strm, s->w_size, sizeof(Pos));
     memset(s->prev, 0, s->w_size * sizeof(Pos));
-    s->head   = (Pos *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
+    s->head   = (Pos *)  ZALLOC(strm, HASH_SIZE, sizeof(Pos));
 
     s->high_water = 0;      /* nothing written to s->window yet */
 
@@ -738,7 +726,7 @@ unsigned long ZEXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
 
     /* if not default parameters, return conservative bound */
     if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) ||  /* hook for IBM Z DFLTCC */
-            s->w_bits != 15 || s->hash_bits != 8 + 7)
+            s->w_bits != 15 || HASH_BITS < 15)
         return complen + wraplen;
 
     /* default settings: return tight bound for that case */
@@ -1133,7 +1121,7 @@ int32_t ZEXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sour
 
     ds->window = (unsigned char *) ZALLOC_WINDOW(dest, ds->w_size + window_padding, 2*sizeof(unsigned char));
     ds->prev   = (Pos *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
-    ds->head   = (Pos *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
+    ds->head   = (Pos *)  ZALLOC(dest, HASH_SIZE, sizeof(Pos));
     ds->pending_buf = (unsigned char *) ZALLOC(dest, ds->lit_bufsize, 4);
 
     if (ds->window == NULL || ds->prev == NULL || ds->head == NULL || ds->pending_buf == NULL) {
@@ -1143,7 +1131,7 @@ int32_t ZEXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sour
 
     memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(unsigned char));
     memcpy((void *)ds->prev, (void *)ss->prev, ds->w_size * sizeof(Pos));
-    memcpy((void *)ds->head, (void *)ss->head, ds->hash_size * sizeof(Pos));
+    memcpy((void *)ds->head, (void *)ss->head, HASH_SIZE * sizeof(Pos));
     memcpy(ds->pending_buf, ss->pending_buf, (unsigned int)ds->pending_buf_size);
 
     ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
index 93f7b5b70a5b0e1fb0933a1327c77b36181e0280..f9db02bbdf8ccf8600b47d36bc31efe07678e85b 100644 (file)
--- a/deflate.h
+++ b/deflate.h
 #define FINISH_STATE 666    /* stream complete */
 /* Stream status */
 
+#define HASH_BITS 15        /* log2(HASH_SIZE) */
+#define HASH_SIZE 32768     /* number of elements in hash table */
+#define HASH_MASK 0x7FFF    /* HASH_SIZE-1 */
+
 
 /* Data structure describing a single value and its code string. */
 typedef struct ct_data_s {
@@ -146,10 +150,6 @@ typedef struct internal_state {
 
     Pos *head; /* Heads of the hash chains or NIL. */
 
-    unsigned int  hash_size;         /* number of elements in hash table */
-    unsigned int  hash_bits;         /* log2(hash_size) */
-    unsigned int  hash_mask;         /* hash_size-1 */
-
     long block_start;
     /* Window position at the beginning of the current output block. Gets
      * negative when the window is moved backwards.
index 2bf4d716e6afe7d669f2519dcf0645ae8feb6316..7233668143d1217bf654ee4299a21fbf463396ee 100644 (file)
@@ -15,7 +15,7 @@
  *    previous key instead of complete recalculation each time.
  */
 #define UPDATE_HASH(s, h, val) \
-    h = ((val * 2654435761U) >> (32 - s->hash_bits));
+    h = ((val * 2654435761U) >> (32 - HASH_BITS));
 
 #define INSERT_STRING       insert_string_c
 #define QUICK_INSERT_STRING quick_insert_string_c
index d667231c9861ea29f0a0392fe6206e0890c3435a..17a42b2d3970a754854bf3279d197d254a14cab2 100644 (file)
@@ -42,7 +42,7 @@ ZLIB_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str
 #endif
 
     UPDATE_HASH(s, h, val);
-    hm = h & s->hash_mask;
+    hm = h & HASH_MASK;
 
     head = s->head[hm];
     if (LIKELY(head != str)) {
@@ -63,7 +63,6 @@ ZLIB_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str
 ZLIB_INTERNAL void INSERT_STRING(deflate_state *const s, const uint32_t str, uint32_t count) {
     uint8_t *strstart = s->window + str;
     uint8_t *strend = strstart + count - 1; /* last position */
-    uint32_t hash_mask = s->hash_mask;
 
     for (Pos idx = str; strstart <= strend; idx++, strstart++) {
         uint32_t val, hm, h = 0;
@@ -78,7 +77,7 @@ ZLIB_INTERNAL void INSERT_STRING(deflate_state *const s, const uint32_t str, uin
 #endif
 
         UPDATE_HASH(s, h, val);
-        hm = h & hash_mask;
+        hm = h & HASH_MASK;
 
         Pos head = s->head[hm];
         if (LIKELY(head != idx)) {
index 49ee292b61fc5725e5e430d29cbca0d6d83d697e..b853b2a3158e77edf6efd3d7bb8f532694572d54 100644 (file)
@@ -53,10 +53,9 @@ ZLIB_INTERNAL int32_t LONGEST_MATCH(deflate_state *const s, Pos cur_match) {
     return best_len;
 
     /*
-     * The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple
-     * of 16. It is easy to get rid of this optimization if necessary.
+     * The code is optimized for MAX_MATCH-2 multiple of 16.
      */
-    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+    Assert(MAX_MATCH == 258, "Code too clever");
 
     best_len = s->prev_length ? s->prev_length : 1;