From: Nathan Moinvaziri Date: Tue, 15 Jun 2021 00:27:37 +0000 (-0700) Subject: Added update_hash to build hash incrementally. X-Git-Tag: 2.1.0-beta1~552 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5998d5b63211784bd8e44b2ba80ee63d2643f65c;p=thirdparty%2Fzlib-ng.git Added update_hash to build hash incrementally. --- diff --git a/functable.c b/functable.c index 32ab90ed3..8fc94c5c1 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 276c284a0..49d2f5d56 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 e2c840bb2..c116544f9 100644 --- a/insert_string_tpl.h +++ b/insert_string_tpl.h @@ -41,6 +41,18 @@ # endif #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