diff options
| author | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2025-12-11 20:34:05 +0100 |
|---|---|---|
| committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2025-12-22 22:58:06 +0100 |
| commit | 2f632a11a4f20dc4fa257f3df7276eda8dc7b178 (patch) | |
| tree | 323657507b5a49e3c8c32036dc50fa6a1a1f04ee | |
| parent | 60879ac4cc75bd9da5387dded4854c9fe2bc2c70 (diff) | |
| download | Project-Tick-2f632a11a4f20dc4fa257f3df7276eda8dc7b178.tar.gz Project-Tick-2f632a11a4f20dc4fa257f3df7276eda8dc7b178.zip | |
Use uint32_t for hash_head in update_hash/insert_string
| -rw-r--r-- | deflate.h | 2 | ||||
| -rw-r--r-- | deflate_fast.c | 4 | ||||
| -rw-r--r-- | deflate_medium.c | 4 | ||||
| -rw-r--r-- | deflate_p.h | 2 | ||||
| -rw-r--r-- | deflate_quick.c | 4 | ||||
| -rw-r--r-- | deflate_rle.c | 2 | ||||
| -rw-r--r-- | deflate_slow.c | 8 | ||||
| -rw-r--r-- | insert_string_tpl.h | 24 | ||||
| -rw-r--r-- | test/benchmarks/benchmark_insert_string.cc | 4 |
9 files changed, 26 insertions, 28 deletions
@@ -196,7 +196,7 @@ struct ALIGNED_(64) internal_state { */ unsigned int match_length; /* length of best match */ - Pos prev_match; /* previous match */ + uint32_t prev_match; /* previous match */ int match_available; /* set if previous match exists */ unsigned int strstart; /* start of string to insert */ unsigned int match_start; /* start of matching string */ diff --git a/deflate_fast.c b/deflate_fast.c index b13a31d727..1f3909c77a 100644 --- a/deflate_fast.c +++ b/deflate_fast.c @@ -49,7 +49,7 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { #else uint32_t str_val = ZSWAP32(zng_memread_4(window + s->strstart)); #endif - Pos hash_head = quick_insert_value(s, s->strstart, str_val); + uint32_t hash_head = quick_insert_value(s, s->strstart, str_val); int64_t dist = (int64_t)s->strstart - hash_head; lc = (uint8_t)str_val; @@ -71,7 +71,7 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { if (match_len >= WANT_MIN_MATCH) { Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t"); - check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); + check_match(s, s->strstart, s->match_start, match_len); bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); diff --git a/deflate_medium.c b/deflate_medium.c index 2f5893c872..3849beeb99 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -173,7 +173,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) { memset(&next_match, 0, sizeof(struct match)); for (;;) { - Pos hash_head = 0; /* head of the hash chain */ + uint32_t hash_head = 0; /* head of the hash chain */ int bflush = 0; /* set if current block must be flushed */ int64_t dist; @@ -219,7 +219,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) { * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - current_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, (uint32_t)hash_head); + current_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, hash_head); current_match.match_start = (uint16_t)s->match_start; if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH)) current_match.match_length = 1; diff --git a/deflate_p.h b/deflate_p.h index f9c635b1ee..81b715bc5d 100644 --- a/deflate_p.h +++ b/deflate_p.h @@ -18,7 +18,7 @@ /* =========================================================================== * Check that the match at match_start is indeed a match. */ -static inline void check_match(deflate_state *s, Pos start, Pos match, int length) { +static inline void check_match(deflate_state *s, uint32_t start, uint32_t match, int length) { /* check that the match length is valid*/ if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) { fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); diff --git a/deflate_quick.c b/deflate_quick.c index 940b93b7fa..a191070d21 100644 --- a/deflate_quick.c +++ b/deflate_quick.c @@ -93,7 +93,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { #else uint32_t str_val = ZSWAP32(zng_memread_4(window + s->strstart)); #endif - Pos hash_head = quick_insert_value(s, s->strstart, str_val); + uint32_t hash_head = quick_insert_value(s, s->strstart, str_val); int64_t dist = (int64_t)s->strstart - hash_head; lc = (uint8_t)str_val; @@ -115,7 +115,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { Assert(match_len <= STD_MAX_MATCH, "match too long"); Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); - check_match(s, (Pos)s->strstart, hash_head, match_len); + check_match(s, s->strstart, hash_head, match_len); zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); s->lookahead -= match_len; diff --git a/deflate_rle.c b/deflate_rle.c index 9e39810483..e468bc6b6e 100644 --- a/deflate_rle.c +++ b/deflate_rle.c @@ -57,7 +57,7 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) { /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ if (match_len >= STD_MIN_MATCH) { Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); - check_match(s, (Pos)s->strstart, (Pos)(s->strstart - 1), match_len); + check_match(s, s->strstart, s->strstart - 1, match_len); bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); diff --git a/deflate_slow.c b/deflate_slow.c index 0567f7148b..96274e0469 100644 --- a/deflate_slow.c +++ b/deflate_slow.c @@ -49,7 +49,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { /* Insert the string window[strstart .. strstart+2] in the * dictionary, and set hash_head to the head of the hash chain: */ - Pos hash_head = 0; + uint32_t hash_head = 0; if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) { if (level >= 9) hash_head = quick_insert_string_roll(s, s->strstart); @@ -59,7 +59,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { /* Find the longest match, discarding those <= prev_length. */ - s->prev_match = (Pos)s->match_start; + s->prev_match = s->match_start; uint32_t match_len = STD_MIN_MATCH - 1; int64_t dist = (int64_t)s->strstart - hash_head; @@ -68,7 +68,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - match_len = longest_match(s, (uint32_t)hash_head); + match_len = longest_match(s, hash_head); /* longest_match() sets match_start */ if (match_len <= 5 && (s->strategy == Z_FILTERED)) { @@ -86,7 +86,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { /* Do not insert strings in hash table beyond this. */ Assert((s->strstart-1) <= UINT16_MAX, "strstart-1 should fit in uint16_t"); - check_match(s, (Pos)(s->strstart - 1), s->prev_match, s->prev_length); + check_match(s, s->strstart - 1, s->prev_match, s->prev_length); bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); diff --git a/insert_string_tpl.h b/insert_string_tpl.h index e507fb5917..8084054864 100644 --- a/insert_string_tpl.h +++ b/insert_string_tpl.h @@ -45,9 +45,8 @@ Z_FORCEINLINE static uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { * to the previous head of the hash chain (the most recent string with same hash key). * Return the previous length of the hash chain. */ -Z_FORCEINLINE static Pos QUICK_INSERT_VALUE(deflate_state *const s, uint32_t str, uint32_t val) { - uint32_t hm; - Pos head; +Z_FORCEINLINE static uint32_t QUICK_INSERT_VALUE(deflate_state *const s, uint32_t str, uint32_t val) { + uint32_t hm, head; HASH_CALC_VAR_INIT; HASH_CALC(HASH_CALC_VAR, val); @@ -56,7 +55,7 @@ Z_FORCEINLINE static Pos QUICK_INSERT_VALUE(deflate_state *const s, uint32_t str head = s->head[hm]; if (LIKELY(head != str)) { - s->prev[str & W_MASK(s)] = head; + s->prev[str & W_MASK(s)] = (Pos)head; s->head[hm] = (Pos)str; } return head; @@ -67,10 +66,9 @@ Z_FORCEINLINE static Pos QUICK_INSERT_VALUE(deflate_state *const s, uint32_t str * of the hash chain (the most recent string with same hash key). Return * the previous length of the hash chain. */ -Z_FORCEINLINE static Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { +Z_FORCEINLINE static uint32_t QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; - uint32_t val, hm; - Pos head; + uint32_t val, hm, head; HASH_CALC_VAR_INIT; HASH_CALC_READ; @@ -80,7 +78,7 @@ Z_FORCEINLINE static Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t st head = s->head[hm]; if (LIKELY(head != str)) { - s->prev[str & W_MASK(s)] = head; + s->prev[str & W_MASK(s)] = (Pos)head; s->head[hm] = (Pos)str; } return head; @@ -103,8 +101,8 @@ Z_FORCEINLINE static void INSERT_STRING(deflate_state *const s, uint32_t str, ui Pos *prevp = s->prev; const unsigned int w_mask = W_MASK(s); - for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { - uint32_t val, hm; + for (uint32_t idx = str; strstart < strend; idx++, strstart++) { + uint32_t val, hm, head; HASH_CALC_VAR_INIT; HASH_CALC_READ; @@ -112,10 +110,10 @@ Z_FORCEINLINE static void INSERT_STRING(deflate_state *const s, uint32_t str, ui HASH_CALC_VAR &= HASH_CALC_MASK; hm = HASH_CALC_VAR; - Pos head = headp[hm]; + head = headp[hm]; if (LIKELY(head != idx)) { - prevp[idx & w_mask] = head; - headp[hm] = idx; + prevp[idx & w_mask] = (Pos)head; + headp[hm] = (Pos)idx; } } } diff --git a/test/benchmarks/benchmark_insert_string.cc b/test/benchmarks/benchmark_insert_string.cc index b28e13ba7b..4bff1fda20 100644 --- a/test/benchmarks/benchmark_insert_string.cc +++ b/test/benchmarks/benchmark_insert_string.cc @@ -20,7 +20,7 @@ extern "C" { #define MAX_WSIZE 32768 #define TEST_WINDOW_SIZE (MAX_WSIZE * 2) -typedef Pos (* quick_insert_string_cb)(deflate_state *const s, uint32_t str); +typedef uint32_t (* quick_insert_string_cb)(deflate_state *const s, uint32_t str); // Base class with common setup/teardown for both insert_string benchmarks class insert_string_base: public benchmark::Fixture { @@ -141,7 +141,7 @@ public: // Benchmark quick_insert_string (single insertions) for (uint32_t i = 0; i < count; i++) { - Pos result = quick_insert_func(s, start_pos + i); + uint32_t result = quick_insert_func(s, start_pos + i); benchmark::DoNotOptimize(result); } } |
