summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Moinvaziri <nathan@nathanm.com>2021-06-14 17:27:37 -0700
committerHans Kristian Rosbach <hk-github@circlestorm.org>2021-06-25 20:09:14 +0200
commit5998d5b63211784bd8e44b2ba80ee63d2643f65c (patch)
tree734d8a6c9b0d54793f8e11c54e8669016b7b50b5
parent694878996926ba75373d62c9a8011c1b01a1cb0b (diff)
downloadProject-Tick-5998d5b63211784bd8e44b2ba80ee63d2643f65c.tar.gz
Project-Tick-5998d5b63211784bd8e44b2ba80ee63d2643f65c.zip
Added update_hash to build hash incrementally.
-rw-r--r--functable.c28
-rw-r--r--functable.h5
-rw-r--r--insert_string_tpl.h12
3 files changed, 42 insertions, 3 deletions
diff --git a/functable.c b/functable.c
index 32ab90ed3a..8fc94c5c11 100644
--- a/functable.c
+++ b/functable.c
@@ -14,6 +14,14 @@
# include "fallback_builtins.h"
#endif
+/* update_hash */
+extern uint32_t update_hash_c(deflate_state *const s, uint32_t h, uint32_t val);
+#ifdef X86_SSE42_CRC_HASH
+extern uint32_t update_hash_sse4(deflate_state *const s, uint32_t h, uint32_t val);
+#elif defined(ARM_ACLE_CRC_HASH)
+extern uint32_t update_hash_acle(deflate_state *const s, uint32_t h, uint32_t val);
+#endif
+
/* insert_string */
extern void insert_string_c(deflate_state *const s, const uint32_t str, uint32_t count);
#ifdef X86_SSE42_CRC_HASH
@@ -152,7 +160,24 @@ Z_INTERNAL void cpu_check_features(void)
}
/* stub functions */
-Z_INTERNAL void insert_string_stub(deflate_state *const s, const uint32_t str, uint32_t count) {
+Z_INTERNAL uint32_t update_hash_stub(deflate_state *const s, uint32_t h, uint32_t val) {
+ // Initialize default
+
+ functable.update_hash = &update_hash_c;
+ cpu_check_features();
+
+#ifdef X86_SSE42_CRC_HASH
+ if (x86_cpu_has_sse42)
+ functable.update_hash = &update_hash_sse4;
+#elif defined(ARM_ACLE_CRC_HASH)
+ if (arm_cpu_has_crc32)
+ functable.update_hash = &update_hash_acle;
+#endif
+
+ return functable.update_hash(s, h, val);
+}
+
+Z_INTERNAL void insert_string_stub(deflate_state *const s, uint32_t str, uint32_t count) {
// Initialize default
functable.insert_string = &insert_string_c;
@@ -451,6 +476,7 @@ Z_INTERNAL uint32_t longest_match_stub(deflate_state *const s, Pos cur_match) {
/* functable init */
Z_INTERNAL Z_TLS struct functable_s functable = {
+ update_hash_stub,
insert_string_stub,
quick_insert_string_stub,
adler32_stub,
diff --git a/functable.h b/functable.h
index 276c284a09..49d2f5d569 100644
--- a/functable.h
+++ b/functable.h
@@ -9,8 +9,9 @@
#include "deflate.h"
struct functable_s {
- void (* insert_string) (deflate_state *const s, const uint32_t str, uint32_t count);
- Pos (* quick_insert_string)(deflate_state *const s, const uint32_t str);
+ uint32_t (* update_hash) (deflate_state *const s, uint32_t h, uint32_t val);
+ void (* insert_string) (deflate_state *const s, uint32_t str, uint32_t count);
+ Pos (* quick_insert_string)(deflate_state *const s, uint32_t str);
uint32_t (* adler32) (uint32_t adler, const unsigned char *buf, size_t len);
uint32_t (* crc32) (uint32_t crc, const unsigned char *buf, uint64_t len);
void (* slide_hash) (deflate_state *s);
diff --git a/insert_string_tpl.h b/insert_string_tpl.h
index e2c840bb2d..c116544f9d 100644
--- a/insert_string_tpl.h
+++ b/insert_string_tpl.h
@@ -42,6 +42,18 @@
#endif
/* ===========================================================================
+ * Update a hash value with the given input byte
+ * IN assertion: all calls to to UPDATE_HASH are made with consecutive
+ * input characters, so that a running hash key can be computed from the
+ * previous key instead of complete recalculation each time.
+ */
+Z_INTERNAL uint32_t UPDATE_HASH(deflate_state *const s, uint32_t h, uint32_t val) {
+ (void)s;
+ HASH_CALC(s, h, val);
+ return h & HASH_CALC_MASK;
+}
+
+/* ===========================================================================
* Quick insert string str in the dictionary and set match_head to the previous head
* of the hash chain (the most recent string with same hash key). Return
* the previous length of the hash chain.