c55b40
--- a/configure
c55b40
+++ b/configure
c55b40
@@ -115,6 +115,7 @@
e6944d
       echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
e6944d
       echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
e6944d
       echo '    [--dfltcc]' | tee -a configure.log
c55b40
+      echo '    [--simd-slide-hash]' | tee -a configure.log
e6944d
         exit 0 ;;
e6944d
     -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
e6944d
     -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
c55b40
@@ -144,6 +145,11 @@
e6944d
 	    PIC_OBJC="$PIC_OBJC dfltcc.lo"
e6944d
       shift
e6944d
       ;; 
c55b40
+    --simd-slide-hash)
c55b40
+	    OBJC="$OBJC slide_avx2.o slide_sse.o"
c55b40
+	    PIC_OBJC="$PIC_OBJC slide_avx2.lo slide_sse.lo"
02ff96
+      shift
02ff96
+      ;; 
e6944d
     *)
e6944d
       echo "unknown option: $1" | tee -a configure.log
e6944d
       echo "$0 --help for help" | tee -a configure.log
c55b40
--- a/Makefile.in
c55b40
+++ b/Makefile.in
c55b40
@@ -152,6 +152,22 @@
e6944d
 	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/dfltcc.o $(SRCDIR)contrib/s390/dfltcc.c
e6944d
 	-@mv objs/dfltcc.o $@
e6944d
 
e6944d
+slide_sse.o: $(SRCDIR)slide_sse.c
e6944d
+	$(CC) $(CFLAGS) $(ZINC) -msse2 -c -o $@ $(SRCDIR)slide_sse.c
e6944d
+
e6944d
+slide_sse.lo: $(SRCDIR)slide_sse.c
e6944d
+	-@mkdir objs 2>/dev/null || test -d objs
e6944d
+	$(CC) $(SFLAGS) $(ZINC) -DPIC -msse2 -c -o objs/slide_sse.o $(SRCDIR)slide_sse.c
e6944d
+	-@mv objs/slide_sse.o $@
e6944d
+
02ff96
+slide_avx2.o: $(SRCDIR)slide_avx2.c
02ff96
+	$(CC) $(CFLAGS) $(ZINC) -mavx2 -c -o $@ $(SRCDIR)slide_avx2.c
02ff96
+
02ff96
+slide_avx2.lo: $(SRCDIR)slide_avx2.c
02ff96
+	-@mkdir objs 2>/dev/null || test -d objs
02ff96
+	$(CC) $(SFLAGS) $(ZINC) -DPIC -mavx2 -c -o objs/slide_avx2.o $(SRCDIR)slide_avx2.c
02ff96
+	-@mv objs/slide_avx2.o $@
02ff96
+
c55b40
 crc32_test.o: $(SRCDIR)test/crc32_test.c $(SRCDIR)zlib.h zconf.h
c55b40
 	$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/crc32_test.c
e6944d
 
e6944d
--- /dev/null
e6944d
+++ b/slide_sse.c
02ff96
@@ -0,0 +1,47 @@
e6944d
+/*
e6944d
+ * SSE optimized hash slide
e6944d
+ *
e6944d
+ * Copyright (C) 2017 Intel Corporation
e6944d
+ * Authors:
e6944d
+ *   Arjan van de Ven	<arjan@linux.intel.com>
e6944d
+ *   Jim Kukunas	<james.t.kukunas@linux.intel.com>
e6944d
+ *
e6944d
+ * For conditions of distribution and use, see copyright notice in zlib.h
e6944d
+ */
e6944d
+#include "deflate.h"
e6944d
+#include <immintrin.h>
e6944d
+
e6944d
+void slide_hash_sse(deflate_state *s)
e6944d
+{
e6944d
+    unsigned n;
e6944d
+    Posf *p;
e6944d
+    uInt wsize = s->w_size;
e6944d
+    z_const __m128i xmm_wsize = _mm_set1_epi16(s->w_size);
e6944d
+
e6944d
+    n = s->hash_size;
e6944d
+    p = &s->head[n] - 8;
e6944d
+    do {
e6944d
+        __m128i value, result;
e6944d
+
e6944d
+	value = _mm_loadu_si128((__m128i *)p);
e6944d
+	result= _mm_subs_epu16(value, xmm_wsize);
e6944d
+	_mm_storeu_si128((__m128i *)p, result);
e6944d
+	p -= 8;
e6944d
+	n -= 8;
e6944d
+    } while (n > 0);
e6944d
+
e6944d
+#ifndef FASTEST
e6944d
+    n = wsize;
e6944d
+    p = &s->prev[n] - 8;
e6944d
+    do {
e6944d
+        __m128i value, result;
e6944d
+
e6944d
+	value = _mm_loadu_si128((__m128i *)p);
e6944d
+	result= _mm_subs_epu16(value, xmm_wsize);
e6944d
+	_mm_storeu_si128((__m128i *)p, result);
e6944d
+
e6944d
+	p -= 8;
e6944d
+	n -= 8;
e6944d
+    } while (n > 0);
e6944d
+#endif
e6944d
+}
02ff96
--- /dev/null
02ff96
+++ b/slide_avx2.c
02ff96
@@ -0,0 +1,44 @@
02ff96
+/*
02ff96
+ * AVX2 optimized hash slide
02ff96
+ *
02ff96
+ * Copyright (C) 2020 Intel Corporation
02ff96
+ *
02ff96
+ * For conditions of distribution and use, see copyright notice in zlib.h
02ff96
+ */
02ff96
+#include "deflate.h"
02ff96
+#include <immintrin.h>
02ff96
+
02ff96
+void slide_hash_avx2(deflate_state *s)
02ff96
+{
02ff96
+    unsigned n;
02ff96
+    Posf *p;
02ff96
+    uInt wsize = s->w_size;
02ff96
+    z_const __m256i ymm_wsize = _mm256_set1_epi16(s->w_size);
02ff96
+
02ff96
+    n = s->hash_size;
02ff96
+    p = &s->head[n] - 16;
02ff96
+    do {
02ff96
+        __m256i value, result;
e6944d
+
02ff96
+        value = _mm256_loadu_si256((__m256i *)p);
02ff96
+        result= _mm256_subs_epu16(value, ymm_wsize);
02ff96
+        _mm256_storeu_si256((__m256i *)p, result);
02ff96
+        p -= 16;
02ff96
+        n -= 16;
02ff96
+    } while (n > 0);
02ff96
+
02ff96
+#ifndef FASTEST
02ff96
+    n = wsize;
02ff96
+    p = &s->prev[n] - 16;
02ff96
+    do {
02ff96
+        __m256i value, result;
e6944d
+
02ff96
+        value = _mm256_loadu_si256((__m256i *)p);
02ff96
+        result= _mm256_subs_epu16(value, ymm_wsize);
02ff96
+        _mm256_storeu_si256((__m256i *)p, result);
02ff96
+
02ff96
+        p -= 16;
02ff96
+        n -= 16;
02ff96
+    } while (n > 0);
02ff96
+#endif
02ff96
+}
c55b40
--- a/deflate.c
c55b40
+++ b/deflate.c
c55b40
@@ -90,6 +90,9 @@
c55b40
 
c55b40
 local int deflateStateCheck      OF((z_streamp strm));
c55b40
 local void slide_hash     OF((deflate_state *s));
c55b40
+local void slide_hash_c     OF((deflate_state *s));
c55b40
+extern void slide_hash_sse     (deflate_state *s);
c55b40
+extern void slide_hash_avx2     (deflate_state *s);
c55b40
 local void fill_window    OF((deflate_state *s));
c55b40
 local block_state deflate_stored OF((deflate_state *s, int flush));
c55b40
 local block_state deflate_fast   OF((deflate_state *s, int flush));
c55b40
@@ -212,7 +215,7 @@
c55b40
  * bit values at the expense of memory usage). We slide even when level == 0 to
c55b40
  * keep the hash table consistent if we switch back to level > 0 later.
c55b40
  */
c55b40
-local void slide_hash(s)
c55b40
+local void slide_hash_c(s)
c55b40
     deflate_state *s;
c55b40
 {
c55b40
     unsigned n, m;
c55b40
@@ -238,6 +241,13 @@
c55b40
 #endif
c55b40
 }
c55b40
 
c55b40
+local void slide_hash(deflate_state *s) {
c55b40
+    #ifdef AVX2_SLIDE
c55b40
+        slide_hash_avx2(s);
c55b40
+    #endif
c55b40
+        slide_hash_sse(s);
c55b40
+}
c55b40
+
c55b40
 /* ========================================================================= */
c55b40
 int ZEXPORT deflateInit_(strm, level, version, stream_size)
c55b40
     z_streamp strm;