bca718
commit 72276d6e8843db6df5971b06787f0a5e39bda138
bca718
Author: Andrew Senkevich <andrew.senkevich@intel.com>
bca718
Date:   Sat Jan 16 00:49:45 2016 +0300
bca718
bca718
    Added memcpy/memmove family optimized with AVX512 for KNL hardware.
bca718
bca718
    Added AVX512 implementations of memcpy, mempcpy, memmove, memcpy_chk,
bca718
    mempcpy_chk, memmove_chk.
bca718
    It shows average improvement more than 30% over AVX versions on KNL
bca718
    hardware (performance results in the thread
bca718
    <https://sourceware.org/ml/libc-alpha/2016-01/msg00258.html>).
bca718
bca718
        * sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Added new files.
bca718
        * sysdeps/x86_64/multiarch/ifunc-impl-list.c: Added new tests.
bca718
        * sysdeps/x86_64/multiarch/memcpy-avx512-no-vzeroupper.S: New file.
bca718
        * sysdeps/x86_64/multiarch/mempcpy-avx512-no-vzeroupper.S: Likewise.
bca718
        * sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S: Likewise.
bca718
        * sysdeps/x86_64/multiarch/memcpy.S: Added new IFUNC branch.
bca718
        * sysdeps/x86_64/multiarch/memcpy_chk.S: Likewise.
bca718
        * sysdeps/x86_64/multiarch/memmove.c: Likewise.
bca718
        * sysdeps/x86_64/multiarch/memmove_chk.c: Likewise.
bca718
        * sysdeps/x86_64/multiarch/mempcpy.S: Likewise.
bca718
        * sysdeps/x86_64/multiarch/mempcpy_chk.S: Likewise.
bca718
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/Makefile
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
bca718
@@ -17,7 +17,8 @@ sysdep_routines += strncat-c stpncpy-c s
bca718
 		   strcat-ssse3 strncat-ssse3 strlen-sse2-pminub \
bca718
 		   strnlen-sse2-no-bsf strrchr-sse2-no-bsf strchr-sse2-no-bsf \
bca718
 		   memcmp-ssse3 strstr-sse2-unaligned \
bca718
-		   memset-avx512-no-vzeroupper
bca718
+		   memset-avx512-no-vzeroupper memcpy-avx512-no-vzeroupper \
bca718
+		   mempcpy-avx512-no-vzeroupper memmove-avx512-no-vzeroupper
bca718
 ifeq (yes,$(config-cflags-sse4))
bca718
 sysdep_routines += strcspn-c strpbrk-c strspn-c strstr-c strcasestr-c varshift
bca718
 CFLAGS-varshift.c += -msse4
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-impl-list.c
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/ifunc-impl-list.c
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-impl-list.c
bca718
@@ -24,7 +24,7 @@
bca718
 #include "init-arch.h"
bca718
 
bca718
 /* Maximum number of IFUNC implementations.  */
bca718
-#define MAX_IFUNC	4
bca718
+#define MAX_IFUNC	5
bca718
 
bca718
 /* Fill ARRAY of MAX elements with IFUNC implementations for function
bca718
    NAME supported on target machine and return the number of valid
bca718
@@ -46,8 +46,11 @@ __libc_ifunc_impl_list (const char *name
bca718
 			      __memcmp_ssse3)
bca718
 	      IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_sse2))
bca718
 
bca718
-  /* Support sysdeps/x86_64/multiarch/memmove_chk.S.  */
bca718
+  /* Support sysdeps/x86_64/multiarch/memmove_chk.c.  */
bca718
   IFUNC_IMPL (i, name, __memmove_chk,
bca718
+	      IFUNC_IMPL_ADD (array, i, __memmove_chk,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __memmove_chk_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, __memmove_chk, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __memmove_chk_ssse3_back)
bca718
 	      IFUNC_IMPL_ADD (array, i, __memmove_chk, HAS_CPU_FEATURE (SSSE3),
bca718
@@ -57,6 +60,9 @@ __libc_ifunc_impl_list (const char *name
bca718
 
bca718
   /* Support sysdeps/x86_64/multiarch/memmove.S.  */
bca718
   IFUNC_IMPL (i, name, memmove,
bca718
+	      IFUNC_IMPL_ADD (array, i, memmove,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __memmove_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, memmove, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __memmove_ssse3_back)
bca718
 	      IFUNC_IMPL_ADD (array, i, memmove, HAS_CPU_FEATURE (SSSE3),
bca718
@@ -263,6 +269,9 @@ __libc_ifunc_impl_list (const char *name
bca718
 #ifdef SHARED
bca718
   /* Support sysdeps/x86_64/multiarch/memcpy_chk.S.  */
bca718
   IFUNC_IMPL (i, name, __memcpy_chk,
bca718
+	      IFUNC_IMPL_ADD (array, i, __memcpy_chk,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __memcpy_chk_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, __memcpy_chk, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __memcpy_chk_ssse3_back)
bca718
 	      IFUNC_IMPL_ADD (array, i, __memcpy_chk, HAS_CPU_FEATURE (SSSE3),
bca718
@@ -274,11 +283,18 @@ __libc_ifunc_impl_list (const char *name
bca718
   IFUNC_IMPL (i, name, memcpy,
bca718
 	      IFUNC_IMPL_ADD (array, i, memcpy, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __memcpy_ssse3_back)
bca718
-	      IFUNC_IMPL_ADD (array, i, memcpy, HAS_CPU_FEATURE (SSSE3), __memcpy_ssse3)
bca718
+	      IFUNC_IMPL_ADD (array, i, memcpy, HAS_CPU_FEATURE (SSSE3),
bca718
+			      __memcpy_ssse3)
bca718
+	      IFUNC_IMPL_ADD (array, i, memcpy,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __memcpy_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_sse2))
bca718
 
bca718
   /* Support sysdeps/x86_64/multiarch/mempcpy_chk.S.  */
bca718
   IFUNC_IMPL (i, name, __mempcpy_chk,
bca718
+	      IFUNC_IMPL_ADD (array, i, __mempcpy_chk,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __mempcpy_chk_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, __mempcpy_chk, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __mempcpy_chk_ssse3_back)
bca718
 	      IFUNC_IMPL_ADD (array, i, __mempcpy_chk, HAS_CPU_FEATURE (SSSE3),
bca718
@@ -288,6 +304,9 @@ __libc_ifunc_impl_list (const char *name
bca718
 
bca718
   /* Support sysdeps/x86_64/multiarch/mempcpy.S.  */
bca718
   IFUNC_IMPL (i, name, mempcpy,
bca718
+	      IFUNC_IMPL_ADD (array, i, mempcpy,
bca718
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
bca718
+			      __mempcpy_avx512_no_vzeroupper)
bca718
 	      IFUNC_IMPL_ADD (array, i, mempcpy, HAS_CPU_FEATURE (SSSE3),
bca718
 			      __mempcpy_ssse3_back)
bca718
 	      IFUNC_IMPL_ADD (array, i, mempcpy, HAS_CPU_FEATURE (SSSE3),
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy-avx512-no-vzeroupper.S
bca718
===================================================================
bca718
--- /dev/null
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy-avx512-no-vzeroupper.S
bca718
@@ -0,0 +1,408 @@
bca718
+/* memcpy optimized with AVX512 for KNL hardware.
bca718
+   Copyright (C) 2016 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#include <sysdep.h>
bca718
+
bca718
+#if defined HAVE_AVX512_ASM_SUPPORT && IS_IN (libc) \
bca718
+    && (defined SHARED \
bca718
+	|| defined USE_AS_MEMMOVE \
bca718
+	|| !defined USE_MULTIARCH)
bca718
+
bca718
+#include "asm-syntax.h"
bca718
+#ifndef MEMCPY
bca718
+# define MEMCPY		__memcpy_avx512_no_vzeroupper
bca718
+# define MEMCPY_CHK	__memcpy_chk_avx512_no_vzeroupper
bca718
+#endif
bca718
+
bca718
+	.section .text,"ax",@progbits
bca718
+#if !defined USE_AS_BCOPY
bca718
+ENTRY (MEMCPY_CHK)
bca718
+	cmpq	%rdx, %rcx
bca718
+	jb	HIDDEN_JUMPTARGET (__chk_fail)
bca718
+END (MEMCPY_CHK)
bca718
+#endif
bca718
+
bca718
+ENTRY (MEMCPY)
bca718
+	mov	%rdi, %rax
bca718
+#ifdef USE_AS_MEMPCPY
bca718
+	add	%rdx, %rax
bca718
+#endif
bca718
+	lea	(%rsi, %rdx), %rcx
bca718
+	lea	(%rdi, %rdx), %r9
bca718
+	cmp	$512, %rdx
bca718
+	ja	L(512bytesormore)
bca718
+
bca718
+L(check):
bca718
+	cmp	$16, %rdx
bca718
+	jbe	L(less_16bytes)
bca718
+	cmp	$256, %rdx
bca718
+	jb	L(less_256bytes)
bca718
+	vmovups	(%rsi), %zmm0
bca718
+	vmovups 0x40(%rsi), %zmm1
bca718
+	vmovups 0x80(%rsi), %zmm2
bca718
+	vmovups 0xC0(%rsi), %zmm3
bca718
+	vmovups	-0x100(%rcx), %zmm4
bca718
+	vmovups -0xC0(%rcx), %zmm5
bca718
+	vmovups -0x80(%rcx), %zmm6
bca718
+	vmovups -0x40(%rcx), %zmm7
bca718
+	vmovups %zmm0, (%rdi)
bca718
+	vmovups %zmm1, 0x40(%rdi)
bca718
+	vmovups %zmm2, 0x80(%rdi)
bca718
+	vmovups %zmm3, 0xC0(%rdi)
bca718
+	vmovups	%zmm4, -0x100(%r9)
bca718
+	vmovups %zmm5, -0xC0(%r9)
bca718
+	vmovups %zmm6, -0x80(%r9)
bca718
+	vmovups %zmm7, -0x40(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_256bytes):
bca718
+	cmp	$128, %dl
bca718
+	jb	L(less_128bytes)
bca718
+	vmovups	(%rsi), %zmm0
bca718
+	vmovups 0x40(%rsi), %zmm1
bca718
+	vmovups -0x80(%rcx), %zmm2
bca718
+	vmovups -0x40(%rcx), %zmm3
bca718
+	vmovups	%zmm0, (%rdi)
bca718
+	vmovups %zmm1, 0x40(%rdi)
bca718
+	vmovups %zmm2, -0x80(%r9)
bca718
+	vmovups %zmm3, -0x40(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_128bytes):
bca718
+	cmp	$64, %dl
bca718
+	jb	L(less_64bytes)
bca718
+	vmovdqu (%rsi), %ymm0
bca718
+	vmovdqu 0x20(%rsi), %ymm1
bca718
+	vmovdqu -0x40(%rcx), %ymm2
bca718
+	vmovdqu -0x20(%rcx), %ymm3
bca718
+	vmovdqu %ymm0, (%rdi)
bca718
+	vmovdqu %ymm1, 0x20(%rdi)
bca718
+	vmovdqu %ymm2, -0x40(%r9)
bca718
+	vmovdqu %ymm3, -0x20(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_64bytes):
bca718
+	cmp	$32, %dl
bca718
+	jb	L(less_32bytes)
bca718
+	vmovdqu	(%rsi), %ymm0
bca718
+	vmovdqu -0x20(%rcx), %ymm1
bca718
+	vmovdqu	%ymm0, (%rdi)
bca718
+	vmovdqu	%ymm1, -0x20(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_32bytes):
bca718
+	vmovdqu (%rsi), %xmm0
bca718
+	vmovdqu -0x10(%rcx), %xmm1
bca718
+	vmovdqu %xmm0, (%rdi)
bca718
+	vmovdqu %xmm1, -0x10(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_16bytes):
bca718
+	cmp	$8, %dl
bca718
+	jb	L(less_8bytes)
bca718
+	movq	(%rsi), %rsi
bca718
+	movq	-0x8(%rcx), %rcx
bca718
+	movq	%rsi, (%rdi)
bca718
+	movq	%rcx, -0x8(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_8bytes):
bca718
+	cmp	$4, %dl
bca718
+	jb	L(less_4bytes)
bca718
+	mov	(%rsi), %esi
bca718
+	mov	-0x4(%rcx), %ecx
bca718
+	mov	%esi, (%rdi)
bca718
+	mov	%ecx, -0x4(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_4bytes):
bca718
+	cmp	$2, %dl
bca718
+	jb	L(less_2bytes)
bca718
+	mov	(%rsi), %si
bca718
+	mov	-0x2(%rcx), %cx
bca718
+	mov	%si, (%rdi)
bca718
+	mov	%cx, -0x2(%r9)
bca718
+	ret
bca718
+
bca718
+L(less_2bytes):
bca718
+	cmp	$1, %dl
bca718
+	jb	L(less_1bytes)
bca718
+	mov	(%rsi), %cl
bca718
+	mov	%cl, (%rdi)
bca718
+L(less_1bytes):
bca718
+	ret
bca718
+
bca718
+L(512bytesormore):
bca718
+#ifdef SHARED_CACHE_SIZE_HALF
bca718
+	mov	$SHARED_CACHE_SIZE_HALF, %r8
bca718
+#else
bca718
+	mov	__x86_64_shared_cache_size_half(%rip), %r8
bca718
+#endif
bca718
+	cmp	%r8, %rdx
bca718
+	jae	L(preloop_large)
bca718
+	cmp	$1024, %rdx
bca718
+	ja	L(1024bytesormore)
bca718
+	prefetcht1 (%rsi)
bca718
+	prefetcht1 0x40(%rsi)
bca718
+	prefetcht1 0x80(%rsi)
bca718
+	prefetcht1 0xC0(%rsi)
bca718
+	prefetcht1 0x100(%rsi)
bca718
+	prefetcht1 0x140(%rsi)
bca718
+	prefetcht1 0x180(%rsi)
bca718
+	prefetcht1 0x1C0(%rsi)
bca718
+	prefetcht1 -0x200(%rcx)
bca718
+	prefetcht1 -0x1C0(%rcx)
bca718
+	prefetcht1 -0x180(%rcx)
bca718
+	prefetcht1 -0x140(%rcx)
bca718
+	prefetcht1 -0x100(%rcx)
bca718
+	prefetcht1 -0xC0(%rcx)
bca718
+	prefetcht1 -0x80(%rcx)
bca718
+	prefetcht1 -0x40(%rcx)
bca718
+	vmovups	(%rsi), %zmm0
bca718
+	vmovups 0x40(%rsi), %zmm1
bca718
+	vmovups 0x80(%rsi), %zmm2
bca718
+	vmovups 0xC0(%rsi), %zmm3
bca718
+	vmovups	0x100(%rsi), %zmm4
bca718
+	vmovups 0x140(%rsi), %zmm5
bca718
+	vmovups 0x180(%rsi), %zmm6
bca718
+	vmovups 0x1C0(%rsi), %zmm7
bca718
+	vmovups	-0x200(%rcx), %zmm8
bca718
+	vmovups -0x1C0(%rcx), %zmm9
bca718
+	vmovups -0x180(%rcx), %zmm10
bca718
+	vmovups -0x140(%rcx), %zmm11
bca718
+	vmovups	-0x100(%rcx), %zmm12
bca718
+	vmovups -0xC0(%rcx), %zmm13
bca718
+	vmovups -0x80(%rcx), %zmm14
bca718
+	vmovups -0x40(%rcx), %zmm15
bca718
+	vmovups %zmm0, (%rdi)
bca718
+	vmovups %zmm1, 0x40(%rdi)
bca718
+	vmovups %zmm2, 0x80(%rdi)
bca718
+	vmovups %zmm3, 0xC0(%rdi)
bca718
+	vmovups %zmm4, 0x100(%rdi)
bca718
+	vmovups %zmm5, 0x140(%rdi)
bca718
+	vmovups %zmm6, 0x180(%rdi)
bca718
+	vmovups %zmm7, 0x1C0(%rdi)
bca718
+	vmovups	%zmm8, -0x200(%r9)
bca718
+	vmovups %zmm9, -0x1C0(%r9)
bca718
+	vmovups %zmm10, -0x180(%r9)
bca718
+	vmovups %zmm11, -0x140(%r9)
bca718
+	vmovups	%zmm12, -0x100(%r9)
bca718
+	vmovups %zmm13, -0xC0(%r9)
bca718
+	vmovups %zmm14, -0x80(%r9)
bca718
+	vmovups %zmm15, -0x40(%r9)
bca718
+	ret
bca718
+
bca718
+L(1024bytesormore):
bca718
+	cmp	%rsi, %rdi
bca718
+	ja	L(1024bytesormore_bkw)
bca718
+	sub	$512, %r9
bca718
+	vmovups -0x200(%rcx), %zmm8
bca718
+	vmovups -0x1C0(%rcx), %zmm9
bca718
+	vmovups -0x180(%rcx), %zmm10
bca718
+	vmovups -0x140(%rcx), %zmm11
bca718
+	vmovups	-0x100(%rcx), %zmm12
bca718
+	vmovups -0xC0(%rcx), %zmm13
bca718
+	vmovups -0x80(%rcx), %zmm14
bca718
+	vmovups -0x40(%rcx), %zmm15
bca718
+	prefetcht1 (%rsi)
bca718
+	prefetcht1 0x40(%rsi)
bca718
+	prefetcht1 0x80(%rsi)
bca718
+	prefetcht1 0xC0(%rsi)
bca718
+	prefetcht1 0x100(%rsi)
bca718
+	prefetcht1 0x140(%rsi)
bca718
+	prefetcht1 0x180(%rsi)
bca718
+	prefetcht1 0x1C0(%rsi)
bca718
+
bca718
+/* Loop with unaligned memory access.  */
bca718
+L(gobble_512bytes_loop):
bca718
+	vmovups	(%rsi), %zmm0
bca718
+	vmovups 0x40(%rsi), %zmm1
bca718
+	vmovups 0x80(%rsi), %zmm2
bca718
+	vmovups 0xC0(%rsi), %zmm3
bca718
+	vmovups	0x100(%rsi), %zmm4
bca718
+	vmovups 0x140(%rsi), %zmm5
bca718
+	vmovups 0x180(%rsi), %zmm6
bca718
+	vmovups 0x1C0(%rsi), %zmm7
bca718
+	add	$512, %rsi
bca718
+	prefetcht1 (%rsi)
bca718
+	prefetcht1 0x40(%rsi)
bca718
+	prefetcht1 0x80(%rsi)
bca718
+	prefetcht1 0xC0(%rsi)
bca718
+	prefetcht1 0x100(%rsi)
bca718
+	prefetcht1 0x140(%rsi)
bca718
+	prefetcht1 0x180(%rsi)
bca718
+	prefetcht1 0x1C0(%rsi)
bca718
+	vmovups	%zmm0, (%rdi)
bca718
+	vmovups %zmm1, 0x40(%rdi)
bca718
+	vmovups %zmm2, 0x80(%rdi)
bca718
+	vmovups %zmm3, 0xC0(%rdi)
bca718
+	vmovups	%zmm4, 0x100(%rdi)
bca718
+	vmovups %zmm5, 0x140(%rdi)
bca718
+	vmovups %zmm6, 0x180(%rdi)
bca718
+	vmovups %zmm7, 0x1C0(%rdi)
bca718
+	add	$512, %rdi
bca718
+	cmp	%r9, %rdi
bca718
+	jb	L(gobble_512bytes_loop)
bca718
+	vmovups %zmm8, (%r9)
bca718
+	vmovups %zmm9, 0x40(%r9)
bca718
+	vmovups %zmm10, 0x80(%r9)
bca718
+	vmovups %zmm11, 0xC0(%r9)
bca718
+	vmovups %zmm12, 0x100(%r9)
bca718
+	vmovups %zmm13, 0x140(%r9)
bca718
+	vmovups %zmm14, 0x180(%r9)
bca718
+	vmovups %zmm15, 0x1C0(%r9)
bca718
+	ret
bca718
+
bca718
+L(1024bytesormore_bkw):
bca718
+	add	$512, %rdi
bca718
+	vmovups	0x1C0(%rsi), %zmm8
bca718
+	vmovups 0x180(%rsi), %zmm9
bca718
+	vmovups 0x140(%rsi), %zmm10
bca718
+	vmovups 0x100(%rsi), %zmm11
bca718
+	vmovups	0xC0(%rsi), %zmm12
bca718
+	vmovups 0x80(%rsi), %zmm13
bca718
+	vmovups 0x40(%rsi), %zmm14
bca718
+	vmovups (%rsi), %zmm15
bca718
+	prefetcht1 -0x40(%rcx)
bca718
+	prefetcht1 -0x80(%rcx)
bca718
+	prefetcht1 -0xC0(%rcx)
bca718
+	prefetcht1 -0x100(%rcx)
bca718
+	prefetcht1 -0x140(%rcx)
bca718
+	prefetcht1 -0x180(%rcx)
bca718
+	prefetcht1 -0x1C0(%rcx)
bca718
+	prefetcht1 -0x200(%rcx)
bca718
+
bca718
+/* Backward loop with unaligned memory access.  */
bca718
+L(gobble_512bytes_loop_bkw):
bca718
+	vmovups -0x40(%rcx), %zmm0
bca718
+	vmovups -0x80(%rcx), %zmm1
bca718
+	vmovups -0xC0(%rcx), %zmm2
bca718
+	vmovups	-0x100(%rcx), %zmm3
bca718
+	vmovups -0x140(%rcx), %zmm4
bca718
+	vmovups -0x180(%rcx), %zmm5
bca718
+	vmovups -0x1C0(%rcx), %zmm6
bca718
+	vmovups	-0x200(%rcx), %zmm7
bca718
+	sub	$512, %rcx
bca718
+	prefetcht1 -0x40(%rcx)
bca718
+	prefetcht1 -0x80(%rcx)
bca718
+	prefetcht1 -0xC0(%rcx)
bca718
+	prefetcht1 -0x100(%rcx)
bca718
+	prefetcht1 -0x140(%rcx)
bca718
+	prefetcht1 -0x180(%rcx)
bca718
+	prefetcht1 -0x1C0(%rcx)
bca718
+	prefetcht1 -0x200(%rcx)
bca718
+	vmovups %zmm0, -0x40(%r9)
bca718
+	vmovups %zmm1, -0x80(%r9)
bca718
+	vmovups %zmm2, -0xC0(%r9)
bca718
+	vmovups	%zmm3, -0x100(%r9)
bca718
+	vmovups %zmm4, -0x140(%r9)
bca718
+	vmovups %zmm5, -0x180(%r9)
bca718
+	vmovups %zmm6, -0x1C0(%r9)
bca718
+	vmovups	%zmm7, -0x200(%r9)
bca718
+	sub	$512, %r9
bca718
+	cmp	%rdi, %r9
bca718
+	ja	L(gobble_512bytes_loop_bkw)
bca718
+	vmovups %zmm8, -0x40(%rdi)
bca718
+	vmovups %zmm9, -0x80(%rdi)
bca718
+	vmovups %zmm10, -0xC0(%rdi)
bca718
+	vmovups %zmm11, -0x100(%rdi)
bca718
+	vmovups %zmm12, -0x140(%rdi)
bca718
+	vmovups %zmm13, -0x180(%rdi)
bca718
+	vmovups %zmm14, -0x1C0(%rdi)
bca718
+	vmovups %zmm15, -0x200(%rdi)
bca718
+	ret
bca718
+
bca718
+L(preloop_large):
bca718
+	cmp	%rsi, %rdi
bca718
+	ja	L(preloop_large_bkw)
bca718
+	vmovups	(%rsi), %zmm4
bca718
+	vmovups	0x40(%rsi), %zmm5
bca718
+
bca718
+/* Align destination for access with non-temporal stores in the loop.  */
bca718
+	mov	%rdi, %r8
bca718
+	and	$-0x80, %rdi
bca718
+	add	$0x80, %rdi
bca718
+	sub	%rdi, %r8
bca718
+	sub	%r8, %rsi
bca718
+	add	%r8, %rdx
bca718
+L(gobble_256bytes_nt_loop):
bca718
+	prefetcht1 0x200(%rsi)
bca718
+	prefetcht1 0x240(%rsi)
bca718
+	prefetcht1 0x280(%rsi)
bca718
+	prefetcht1 0x2C0(%rsi)
bca718
+	prefetcht1 0x300(%rsi)
bca718
+	prefetcht1 0x340(%rsi)
bca718
+	prefetcht1 0x380(%rsi)
bca718
+	prefetcht1 0x3C0(%rsi)
bca718
+	vmovdqu64 (%rsi), %zmm0
bca718
+	vmovdqu64 0x40(%rsi), %zmm1
bca718
+	vmovdqu64 0x80(%rsi), %zmm2
bca718
+	vmovdqu64 0xC0(%rsi), %zmm3
bca718
+	vmovntdq %zmm0, (%rdi)
bca718
+	vmovntdq %zmm1, 0x40(%rdi)
bca718
+	vmovntdq %zmm2, 0x80(%rdi)
bca718
+	vmovntdq %zmm3, 0xC0(%rdi)
bca718
+	sub	$256, %rdx
bca718
+	add	$256, %rsi
bca718
+	add	$256, %rdi
bca718
+	cmp	$256, %rdx
bca718
+	ja	L(gobble_256bytes_nt_loop)
bca718
+	sfence
bca718
+	vmovups	%zmm4, (%rax)
bca718
+	vmovups	%zmm5, 0x40(%rax)
bca718
+	jmp	L(check)
bca718
+
bca718
+L(preloop_large_bkw):
bca718
+	vmovups -0x80(%rcx), %zmm4
bca718
+	vmovups -0x40(%rcx), %zmm5
bca718
+
bca718
+/* Align end of destination for access with non-temporal stores.  */
bca718
+	mov	%r9, %r8
bca718
+	and	$-0x80, %r9
bca718
+	sub	%r9, %r8
bca718
+	sub	%r8, %rcx
bca718
+	sub	%r8, %rdx
bca718
+	add	%r9, %r8
bca718
+L(gobble_256bytes_nt_loop_bkw):
bca718
+	prefetcht1 -0x400(%rcx)
bca718
+	prefetcht1 -0x3C0(%rcx)
bca718
+	prefetcht1 -0x380(%rcx)
bca718
+	prefetcht1 -0x340(%rcx)
bca718
+	prefetcht1 -0x300(%rcx)
bca718
+	prefetcht1 -0x2C0(%rcx)
bca718
+	prefetcht1 -0x280(%rcx)
bca718
+	prefetcht1 -0x240(%rcx)
bca718
+	vmovdqu64 -0x100(%rcx), %zmm0
bca718
+	vmovdqu64 -0xC0(%rcx), %zmm1
bca718
+	vmovdqu64 -0x80(%rcx), %zmm2
bca718
+	vmovdqu64 -0x40(%rcx), %zmm3
bca718
+	vmovntdq %zmm0,	-0x100(%r9)
bca718
+	vmovntdq %zmm1,	-0xC0(%r9)
bca718
+	vmovntdq %zmm2,	-0x80(%r9)
bca718
+	vmovntdq %zmm3,	-0x40(%r9)
bca718
+	sub	$256, %rdx
bca718
+	sub	$256, %rcx
bca718
+	sub	$256, %r9
bca718
+	cmp	$256, %rdx
bca718
+	ja	L(gobble_256bytes_nt_loop_bkw)
bca718
+	sfence
bca718
+	vmovups	%zmm4, -0x80(%r8)
bca718
+	vmovups	%zmm5, -0x40(%r8)
bca718
+	jmp	L(check)
bca718
+END (MEMCPY)
bca718
+#endif
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy.S
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memcpy.S
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy.S
bca718
@@ -30,7 +30,15 @@
bca718
 ENTRY(__new_memcpy)
bca718
 	.type	__new_memcpy, @gnu_indirect_function
bca718
 	LOAD_RTLD_GLOBAL_RO_RDX
bca718
-	leaq	__memcpy_sse2(%rip), %rax
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	jz	1f
bca718
+	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+	jz	1f
bca718
+	leaq    __memcpy_avx512_no_vzeroupper(%rip), %rax
bca718
+	ret
bca718
+#endif
bca718
+1:	leaq	__memcpy_sse2(%rip), %rax
bca718
 	HAS_CPU_FEATURE (SSSE3)
bca718
 	jz	2f
bca718
 	leaq	__memcpy_ssse3(%rip), %rax
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy_chk.S
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memcpy_chk.S
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memcpy_chk.S
bca718
@@ -30,7 +30,15 @@
bca718
 ENTRY(__memcpy_chk)
bca718
 	.type	__memcpy_chk, @gnu_indirect_function
bca718
 	LOAD_RTLD_GLOBAL_RO_RDX
bca718
-	leaq	__memcpy_chk_sse2(%rip), %rax
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	jz      1f
bca718
+#	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+#	jz      1f
bca718
+	leaq    __memcpy_avx512_no_vzeroupper(%rip), %rax
bca718
+	ret
bca718
+#endif
bca718
+1:	leaq	__memcpy_chk_sse2(%rip), %rax
bca718
 	HAS_CPU_FEATURE (SSSE3)
bca718
 	jz	2f
bca718
 	leaq	__memcpy_chk_ssse3(%rip), %rax
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S
bca718
===================================================================
bca718
--- /dev/null
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S
bca718
@@ -0,0 +1,22 @@
bca718
+/* memmove optimized with AVX512 for KNL hardware.
bca718
+   Copyright (C) 2016 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define USE_AS_MEMMOVE
bca718
+#define MEMCPY		__memmove_avx512_no_vzeroupper
bca718
+#define MEMCPY_CHK	__memmove_chk_avx512_no_vzeroupper
bca718
+#include "memcpy-avx512-no-vzeroupper.S"
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove.c
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memmove.c
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove.c
bca718
@@ -35,6 +35,9 @@
bca718
 extern __typeof (__redirect_memmove) __memmove_sse2 attribute_hidden;
bca718
 extern __typeof (__redirect_memmove) __memmove_ssse3 attribute_hidden;
bca718
 extern __typeof (__redirect_memmove) __memmove_ssse3_back attribute_hidden;
bca718
+# ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+extern __typeof (__redirect_memmove) __memmove_avx512_no_vzeroupper attribute_hidden;
bca718
+# endif
bca718
 #endif
bca718
 
bca718
 #include "string/memmove.c"
bca718
@@ -47,10 +50,16 @@ extern __typeof (__redirect_memmove) __m
bca718
    ifunc symbol properly.  */
bca718
 extern __typeof (__redirect_memmove) __libc_memmove;
bca718
 libc_ifunc (__libc_memmove,
bca718
-	    HAS_CPU_FEATURE (SSSE3)
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	    HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	      && HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+	    ? __memmove_avx512_no_vzeroupper
bca718
+	    :
bca718
+#endif
bca718
+	    (HAS_CPU_FEATURE (SSSE3)
bca718
 	    ? (HAS_ARCH_FEATURE (Fast_Copy_Backward)
bca718
 	       ? __memmove_ssse3_back : __memmove_ssse3)
bca718
-	    : __memmove_sse2)
bca718
+	    : __memmove_sse2))
bca718
 
bca718
 strong_alias (__libc_memmove, memmove)
bca718
 
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove_chk.c
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memmove_chk.c
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memmove_chk.c
bca718
@@ -25,11 +25,20 @@
bca718
 extern __typeof (__memmove_chk) __memmove_chk_sse2 attribute_hidden;
bca718
 extern __typeof (__memmove_chk) __memmove_chk_ssse3 attribute_hidden;
bca718
 extern __typeof (__memmove_chk) __memmove_chk_ssse3_back attribute_hidden;
bca718
+# ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+extern __typeof (__memmove_chk) __memmove_chk_avx512_no_vzeroupper attribute_hidden;
bca718
+# endif
bca718
 
bca718
 #include "debug/memmove_chk.c"
bca718
 
bca718
 libc_ifunc (__memmove_chk,
bca718
-	    HAS_CPU_FEATURE (SSSE3)
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	    HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	      && HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+	    ? __memmove_chk_avx512_no_vzeroupper
bca718
+	    :
bca718
+#endif
bca718
+	    (HAS_CPU_FEATURE (SSSE3)
bca718
 	    ? (HAS_ARCH_FEATURE (Fast_Copy_Backward)
bca718
 	       ? __memmove_chk_ssse3_back : __memmove_chk_ssse3)
bca718
-	    : __memmove_chk_sse2);
bca718
+	    : __memmove_chk_sse2));
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy-avx512-no-vzeroupper.S
bca718
===================================================================
bca718
--- /dev/null
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy-avx512-no-vzeroupper.S
bca718
@@ -0,0 +1,22 @@
bca718
+/* mempcpy optimized with AVX512 for KNL hardware.
bca718
+   Copyright (C) 2016 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define USE_AS_MEMPCPY
bca718
+#define MEMCPY		__mempcpy_avx512_no_vzeroupper
bca718
+#define MEMCPY_CHK	__mempcpy_chk_avx512_no_vzeroupper
bca718
+#include "memcpy-avx512-no-vzeroupper.S"
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy.S
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/mempcpy.S
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy.S
bca718
@@ -28,7 +28,15 @@
bca718
 ENTRY(__mempcpy)
bca718
 	.type	__mempcpy, @gnu_indirect_function
bca718
 	LOAD_RTLD_GLOBAL_RO_RDX
bca718
-	leaq	__mempcpy_sse2(%rip), %rax
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	jz	1f
bca718
+	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+	jz	1f
bca718
+	leaq    __mempcpy_avx512_no_vzeroupper(%rip), %rax
bca718
+	ret
bca718
+#endif
bca718
+1:	leaq	__mempcpy_sse2(%rip), %rax
bca718
 	HAS_CPU_FEATURE (SSSE3)
bca718
 	jz	2f
bca718
 	leaq	__mempcpy_ssse3(%rip), %rax
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy_chk.S
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/mempcpy_chk.S
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/mempcpy_chk.S
bca718
@@ -30,7 +30,15 @@
bca718
 ENTRY(__mempcpy_chk)
bca718
 	.type	__mempcpy_chk, @gnu_indirect_function
bca718
 	LOAD_RTLD_GLOBAL_RO_RDX
bca718
-	leaq	__mempcpy_chk_sse2(%rip), %rax
bca718
+#ifdef HAVE_AVX512_ASM_SUPPORT
bca718
+	HAS_ARCH_FEATURE (AVX512F_Usable)
bca718
+	jz	1f
bca718
+	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
bca718
+	jz	1f
bca718
+	leaq    __mempcpy_chk_avx512_no_vzeroupper(%rip), %rax
bca718
+	ret
bca718
+#endif
bca718
+1:	leaq	__mempcpy_chk_sse2(%rip), %rax
bca718
 	HAS_CPU_FEATURE (SSSE3)
bca718
 	jz	2f
bca718
 	leaq	__mempcpy_chk_ssse3(%rip), %rax