summaryrefslogtreecommitdiff
path: root/insert_string.c
diff options
context:
space:
mode:
authorNathan Moinvaziri <nathan@nathanm.com>2020-01-17 19:04:20 -0800
committerHans Kristian Rosbach <hk-github@circlestorm.org>2020-04-30 10:01:46 +0200
commit69bbb0d823771bc84ed1ba96381a91e06847c428 (patch)
treeb9f3732d273f20d898f03c5773635c7af6966aea /insert_string.c
parent42aa81beafa2ea14cd780a9acf3359a0a09ca44b (diff)
Standardize insert_string functionality across architectures. Added unaligned conditionally compiled code for insert_string and quick_insert_string. Unify sse42 crc32 assembly between insert_string and quick_insert_string. Modified quick_insert_string to work across architectures.
Diffstat (limited to 'insert_string.c')
-rw-r--r--insert_string.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/insert_string.c b/insert_string.c
new file mode 100644
index 0000000..4e4c628
--- /dev/null
+++ b/insert_string.c
@@ -0,0 +1,39 @@
+/* insert_string_c -- insert_string variant for c
+ *
+ * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ */
+
+#include "zbuild.h"
+#include "deflate.h"
+
+/* ===========================================================================
+ * 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.
+ */
+
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
+# define UPDATE_HASH(s, h, val) \
+ do {\
+ if (s->level < TRIGGER_LEVEL)\
+ h = (3483 * ((val) & 0xff) +\
+ 23081* (((val) >> 8) & 0xff) +\
+ 6954 * (((val) >> 16) & 0xff) +\
+ 20947* (((val) >> 24) & 0xff));\
+ else\
+ h = (25881* (((val)) & 0xff) +\
+ 24674* (((val) >> 8) & 0xff) +\
+ 25811* (((val) >> 16) & 0xff));\
+ } while (0)
+#else
+# define UPDATE_HASH(s, h, val)\
+ h = (s->ins_h = ((s->ins_h << s->hash_shift) ^ ((val) >> ((MIN_MATCH - 1) * 8))) & s->hash_mask)
+#endif
+
+#define INSERT_STRING insert_string_c
+#define QUICK_INSERT_STRING quick_insert_string_c
+
+#include "insert_string_tpl.h"