/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 | 3.24M | # define HASH_CALC_OFFSET 0 |
29 | | #endif |
30 | | #ifndef HASH_CALC_MASK |
31 | 9.24M | # 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 | 9.24M | 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 | 5.16M | Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { |
50 | 5.16M | HASH_CALC(h, val); |
51 | 5.16M | return h & HASH_CALC_MASK; |
52 | 5.16M | } Unexecuted instantiation: update_hash Line | Count | Source | 49 | 5.16M | Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { | 50 | 5.16M | HASH_CALC(h, val); | 51 | 5.16M | return h & HASH_CALC_MASK; | 52 | 5.16M | } |
|
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 | 5.29M | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { |
60 | 5.29M | Pos head; |
61 | 5.29M | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; |
62 | 5.29M | uint32_t val, hm; |
63 | | |
64 | 5.29M | HASH_CALC_VAR_INIT; |
65 | 5.29M | HASH_CALC_READ; |
66 | 5.29M | HASH_CALC(HASH_CALC_VAR, val); |
67 | 5.29M | HASH_CALC_VAR &= HASH_CALC_MASK; |
68 | 5.29M | hm = HASH_CALC_VAR; |
69 | | |
70 | 5.29M | head = s->head[hm]; |
71 | 5.29M | if (LIKELY(head != str)) { |
72 | 5.28M | s->prev[str & s->w_mask] = head; |
73 | 5.28M | s->head[hm] = (Pos)str; |
74 | 5.28M | } |
75 | 5.29M | return head; |
76 | 5.29M | } Line | Count | Source | 59 | 3.01M | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { | 60 | 3.01M | Pos head; | 61 | 3.01M | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; | 62 | 3.01M | uint32_t val, hm; | 63 | | | 64 | 3.01M | HASH_CALC_VAR_INIT; | 65 | 3.01M | HASH_CALC_READ; | 66 | 3.01M | HASH_CALC(HASH_CALC_VAR, val); | 67 | 3.01M | HASH_CALC_VAR &= HASH_CALC_MASK; | 68 | 3.01M | hm = HASH_CALC_VAR; | 69 | | | 70 | 3.01M | head = s->head[hm]; | 71 | 3.01M | if (LIKELY(head != str)) { | 72 | 3.00M | s->prev[str & s->w_mask] = head; | 73 | 3.00M | s->head[hm] = (Pos)str; | 74 | 3.00M | } | 75 | 3.01M | return head; | 76 | 3.01M | } |
Line | Count | Source | 59 | 2.28M | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { | 60 | 2.28M | Pos head; | 61 | 2.28M | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; | 62 | 2.28M | uint32_t val, hm; | 63 | | | 64 | 2.28M | HASH_CALC_VAR_INIT; | 65 | 2.28M | HASH_CALC_READ; | 66 | 2.28M | HASH_CALC(HASH_CALC_VAR, val); | 67 | 2.28M | HASH_CALC_VAR &= HASH_CALC_MASK; | 68 | 2.28M | hm = HASH_CALC_VAR; | 69 | | | 70 | 2.28M | head = s->head[hm]; | 71 | 2.28M | if (LIKELY(head != str)) { | 72 | 2.28M | s->prev[str & s->w_mask] = head; | 73 | 2.28M | s->head[hm] = (Pos)str; | 74 | 2.28M | } | 75 | 2.28M | return head; | 76 | 2.28M | } |
|
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 | 501k | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { |
87 | 501k | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; |
88 | 501k | uint8_t *strend = strstart + count; |
89 | | |
90 | 11.2M | for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { |
91 | 10.7M | uint32_t val, hm; |
92 | | |
93 | 10.7M | HASH_CALC_VAR_INIT; |
94 | 10.7M | HASH_CALC_READ; |
95 | 10.7M | HASH_CALC(HASH_CALC_VAR, val); |
96 | 10.7M | HASH_CALC_VAR &= HASH_CALC_MASK; |
97 | 10.7M | hm = HASH_CALC_VAR; |
98 | | |
99 | 10.7M | Pos head = s->head[hm]; |
100 | 10.7M | if (LIKELY(head != idx)) { |
101 | 10.7M | s->prev[idx & s->w_mask] = head; |
102 | 10.7M | s->head[hm] = idx; |
103 | 10.7M | } |
104 | 10.7M | } |
105 | 501k | } Line | Count | Source | 86 | 236k | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { | 87 | 236k | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; | 88 | 236k | uint8_t *strend = strstart + count; | 89 | | | 90 | 6.46M | for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { | 91 | 6.22M | uint32_t val, hm; | 92 | | | 93 | 6.22M | HASH_CALC_VAR_INIT; | 94 | 6.22M | HASH_CALC_READ; | 95 | 6.22M | HASH_CALC(HASH_CALC_VAR, val); | 96 | 6.22M | HASH_CALC_VAR &= HASH_CALC_MASK; | 97 | 6.22M | hm = HASH_CALC_VAR; | 98 | | | 99 | 6.22M | Pos head = s->head[hm]; | 100 | 6.22M | if (LIKELY(head != idx)) { | 101 | 6.22M | s->prev[idx & s->w_mask] = head; | 102 | 6.22M | s->head[hm] = idx; | 103 | 6.22M | } | 104 | 6.22M | } | 105 | 236k | } |
Line | Count | Source | 86 | 264k | Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { | 87 | 264k | uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; | 88 | 264k | uint8_t *strend = strstart + count; | 89 | | | 90 | 4.80M | for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { | 91 | 4.54M | uint32_t val, hm; | 92 | | | 93 | 4.54M | HASH_CALC_VAR_INIT; | 94 | 4.54M | HASH_CALC_READ; | 95 | 4.54M | HASH_CALC(HASH_CALC_VAR, val); | 96 | 4.54M | HASH_CALC_VAR &= HASH_CALC_MASK; | 97 | 4.54M | hm = HASH_CALC_VAR; | 98 | | | 99 | 4.54M | Pos head = s->head[hm]; | 100 | 4.54M | if (LIKELY(head != idx)) { | 101 | 4.53M | s->prev[idx & s->w_mask] = head; | 102 | 4.53M | s->head[hm] = idx; | 103 | 4.53M | } | 104 | 4.54M | } | 105 | 264k | } |
|
106 | | #endif |