# 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
}
/* 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;
/* functable init */
Z_INTERNAL Z_TLS struct functable_s functable = {
+ update_hash_stub,
insert_string_stub,
quick_insert_string_stub,
adler32_stub,
#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);
# 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