]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Added update_hash to build hash incrementally.
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 15 Jun 2021 00:27:37 +0000 (17:27 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 25 Jun 2021 18:09:14 +0000 (20:09 +0200)
functable.c
functable.h
insert_string_tpl.h

index 32ab90ed3aecccc6206f2d4f50a9570bc6bf33dd..8fc94c5c11fd53491465f54b144eac09c0864b81 100644 (file)
 #  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,
index 276c284a092d131e06eb595d2734681f6f79a229..49d2f5d569e0c56a224cd37537e6855099741c33 100644 (file)
@@ -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);
index e2c840bb2d21be9a6f707f52593c063e268c06c9..c116544f9de0ecb5738b6509d3966a21652f0d1c 100644 (file)
 #  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