/src/zlib-ng/insert_string_tpl.h
Line  | Count  | Source  | 
1  |  | #ifndef INSERT_STRING_H_  | 
2  |  | #define INSERT_STRING_H_  | 
3  |  |  | 
4  |  | /* insert_string_tpl.h -- Private insert_string functions shared with more than  | 
5  |  |  *                        one insert string implementation  | 
6  |  |  *  | 
7  |  |  * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler  | 
8  |  |  *  | 
9  |  |  * Copyright (C) 2013 Intel Corporation. All rights reserved.  | 
10  |  |  * Authors:  | 
11  |  |  *  Wajdi Feghali   <wajdi.k.feghali@intel.com>  | 
12  |  |  *  Jim Guilford    <james.guilford@intel.com>  | 
13  |  |  *  Vinodh Gopal    <vinodh.gopal@intel.com>  | 
14  |  |  *  Erdinc Ozturk   <erdinc.ozturk@intel.com>  | 
15  |  |  *  Jim Kukunas     <james.t.kukunas@linux.intel.com>  | 
16  |  |  *  | 
17  |  |  * Portions are Copyright (C) 2016 12Sided Technology, LLC.  | 
18  |  |  * Author:  | 
19  |  |  *  Phil Vachon     <pvachon@12sidedtech.com>  | 
20  |  |  *  | 
21  |  |  * For conditions of distribution and use, see copyright notice in zlib.h  | 
22  |  |  *  | 
23  |  |  */  | 
24  |  |  | 
25  |  | #include "zmemory.h"  | 
26  |  |  | 
27  |  | #ifndef HASH_CALC_OFFSET  | 
28  | 882M  | #  define HASH_CALC_OFFSET 0  | 
29  |  | #endif  | 
30  |  | #ifndef HASH_CALC_MASK  | 
31  | 1.12G  | #  define HASH_CALC_MASK HASH_MASK  | 
32  |  | #endif  | 
33  |  | #ifndef HASH_CALC_READ  | 
34  |  | #  if BYTE_ORDER == LITTLE_ENDIAN  | 
35  |  | #    define HASH_CALC_READ \  | 
36  | 1.12G  |         val = zng_memread_4(strstart);  | 
37  |  | #  else  | 
38  |  | #    define HASH_CALC_READ \  | 
39  |  |         val = ZSWAP32(zng_memread_4(strstart));  | 
40  |  | #  endif  | 
41  |  | #endif  | 
42  |  |  | 
43  |  | /* ===========================================================================  | 
44  |  |  * Update a hash value with the given input byte  | 
45  |  |  * IN  assertion: all calls to UPDATE_HASH are made with consecutive  | 
46  |  |  *    input characters, so that a running hash key can be computed from the  | 
47  |  |  *    previous key instead of complete recalculation each time.  | 
48  |  |  */  | 
49  | 28.7M  | Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { | 
50  | 28.7M  |     HASH_CALC(h, val);  | 
51  | 28.7M  |     return h & HASH_CALC_MASK;  | 
52  | 28.7M  | } Unexecuted instantiation: update_hash Line  | Count  | Source  |  49  | 28.7M  | Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { |  50  | 28.7M  |     HASH_CALC(h, val);  |  51  | 28.7M  |     return h & HASH_CALC_MASK;  |  52  | 28.7M  | }  |  
  | 
53  |  |  | 
54  |  | /* ===========================================================================  | 
55  |  |  * Quick insert string str in the dictionary and set match_head to the previous head  | 
56  |  |  * of the hash chain (the most recent string with same hash key). Return  | 
57  |  |  * the previous length of the hash chain.  | 
58  |  |  */  | 
59  | 890M  | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { | 
60  | 890M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  | 
61  | 890M  |     uint32_t val, hm;  | 
62  | 890M  |     Pos head;  | 
63  |  |  | 
64  | 890M  |     HASH_CALC_VAR_INIT;  | 
65  | 890M  |     HASH_CALC_READ;  | 
66  | 890M  |     HASH_CALC(HASH_CALC_VAR, val);  | 
67  | 890M  |     HASH_CALC_VAR &= HASH_CALC_MASK;  | 
68  | 890M  |     hm = HASH_CALC_VAR;  | 
69  |  |  | 
70  | 890M  |     head = s->head[hm];  | 
71  | 890M  |     if (LIKELY(head != str)) { | 
72  | 744M  |         s->prev[str & s->w_mask] = head;  | 
73  | 744M  |         s->head[hm] = (Pos)str;  | 
74  | 744M  |     }  | 
75  | 890M  |     return head;  | 
76  | 890M  | } Line  | Count  | Source  |  59  | 859M  | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { |  60  | 859M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  |  61  | 859M  |     uint32_t val, hm;  |  62  | 859M  |     Pos head;  |  63  |  |  |  64  | 859M  |     HASH_CALC_VAR_INIT;  |  65  | 859M  |     HASH_CALC_READ;  |  66  | 859M  |     HASH_CALC(HASH_CALC_VAR, val);  |  67  | 859M  |     HASH_CALC_VAR &= HASH_CALC_MASK;  |  68  | 859M  |     hm = HASH_CALC_VAR;  |  69  |  |  |  70  | 859M  |     head = s->head[hm];  |  71  | 859M  |     if (LIKELY(head != str)) { |  72  | 713M  |         s->prev[str & s->w_mask] = head;  |  73  | 713M  |         s->head[hm] = (Pos)str;  |  74  | 713M  |     }  |  75  | 859M  |     return head;  |  76  | 859M  | }  |  
 Line  | Count  | Source  |  59  | 30.4M  | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { |  60  | 30.4M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  |  61  | 30.4M  |     uint32_t val, hm;  |  62  | 30.4M  |     Pos head;  |  63  |  |  |  64  | 30.4M  |     HASH_CALC_VAR_INIT;  |  65  | 30.4M  |     HASH_CALC_READ;  |  66  | 30.4M  |     HASH_CALC(HASH_CALC_VAR, val);  |  67  | 30.4M  |     HASH_CALC_VAR &= HASH_CALC_MASK;  |  68  | 30.4M  |     hm = HASH_CALC_VAR;  |  69  |  |  |  70  | 30.4M  |     head = s->head[hm];  |  71  | 30.4M  |     if (LIKELY(head != str)) { |  72  | 30.4M  |         s->prev[str & s->w_mask] = head;  |  73  | 30.4M  |         s->head[hm] = (Pos)str;  |  74  | 30.4M  |     }  |  75  | 30.4M  |     return head;  |  76  | 30.4M  | }  |  
  | 
77  |  |  | 
78  |  | /* ===========================================================================  | 
79  |  |  * Insert string str in the dictionary and set match_head to the previous head  | 
80  |  |  * of the hash chain (the most recent string with same hash key). Return  | 
81  |  |  * the previous length of the hash chain.  | 
82  |  |  * IN  assertion: all calls to INSERT_STRING are made with consecutive  | 
83  |  |  *    input characters and the first STD_MIN_MATCH bytes of str are valid  | 
84  |  |  *    (except for the last STD_MIN_MATCH-1 bytes of the input file).  | 
85  |  |  */  | 
86  | 27.5M  | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { | 
87  | 27.5M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  | 
88  | 27.5M  |     uint8_t *strend = strstart + count;  | 
89  |  |  | 
90  |  |     /* Local pointers to avoid indirection */  | 
91  | 27.5M  |     Pos *headp = s->head;  | 
92  | 27.5M  |     Pos *prevp = s->prev;  | 
93  | 27.5M  |     const unsigned int w_mask = s->w_mask;  | 
94  |  |  | 
95  | 747M  |     for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { | 
96  | 720M  |         uint32_t val, hm;  | 
97  |  |  | 
98  | 720M  |         HASH_CALC_VAR_INIT;  | 
99  | 720M  |         HASH_CALC_READ;  | 
100  | 720M  |         HASH_CALC(HASH_CALC_VAR, val);  | 
101  | 720M  |         HASH_CALC_VAR &= HASH_CALC_MASK;  | 
102  | 720M  |         hm = HASH_CALC_VAR;  | 
103  |  |  | 
104  | 720M  |         Pos head = headp[hm];  | 
105  | 720M  |         if (LIKELY(head != idx)) { | 
106  | 720M  |             prevp[idx & w_mask] = head;  | 
107  | 720M  |             headp[hm] = idx;  | 
108  | 720M  |         }  | 
109  | 720M  |     }  | 
110  | 27.5M  | } Line  | Count  | Source  |  86  | 22.7M  | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { |  87  | 22.7M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  |  88  | 22.7M  |     uint8_t *strend = strstart + count;  |  89  |  |  |  90  |  |     /* Local pointers to avoid indirection */  |  91  | 22.7M  |     Pos *headp = s->head;  |  92  | 22.7M  |     Pos *prevp = s->prev;  |  93  | 22.7M  |     const unsigned int w_mask = s->w_mask;  |  94  |  |  |  95  | 286M  |     for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { |  96  | 264M  |         uint32_t val, hm;  |  97  |  |  |  98  | 264M  |         HASH_CALC_VAR_INIT;  |  99  | 264M  |         HASH_CALC_READ;  |  100  | 264M  |         HASH_CALC(HASH_CALC_VAR, val);  |  101  | 264M  |         HASH_CALC_VAR &= HASH_CALC_MASK;  |  102  | 264M  |         hm = HASH_CALC_VAR;  |  103  |  |  |  104  | 264M  |         Pos head = headp[hm];  |  105  | 264M  |         if (LIKELY(head != idx)) { |  106  | 264M  |             prevp[idx & w_mask] = head;  |  107  | 264M  |             headp[hm] = idx;  |  108  | 264M  |         }  |  109  | 264M  |     }  |  110  | 22.7M  | }  |  
 Line  | Count  | Source  |  86  | 4.87M  | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { |  87  | 4.87M  |     uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;  |  88  | 4.87M  |     uint8_t *strend = strstart + count;  |  89  |  |  |  90  |  |     /* Local pointers to avoid indirection */  |  91  | 4.87M  |     Pos *headp = s->head;  |  92  | 4.87M  |     Pos *prevp = s->prev;  |  93  | 4.87M  |     const unsigned int w_mask = s->w_mask;  |  94  |  |  |  95  | 460M  |     for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { |  96  | 455M  |         uint32_t val, hm;  |  97  |  |  |  98  | 455M  |         HASH_CALC_VAR_INIT;  |  99  | 455M  |         HASH_CALC_READ;  |  100  | 455M  |         HASH_CALC(HASH_CALC_VAR, val);  |  101  | 455M  |         HASH_CALC_VAR &= HASH_CALC_MASK;  |  102  | 455M  |         hm = HASH_CALC_VAR;  |  103  |  |  |  104  | 455M  |         Pos head = headp[hm];  |  105  | 455M  |         if (LIKELY(head != idx)) { |  106  | 455M  |             prevp[idx & w_mask] = head;  |  107  | 455M  |             headp[hm] = idx;  |  108  | 455M  |         }  |  109  | 455M  |     }  |  110  | 4.87M  | }  |  
  | 
111  |  | #endif  |