arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1298526-0.patch

147e83
commit 83d776f979342f923b5c3d2a5b43afab841c6086
147e83
Author: Andrew Senkevich <andrew.senkevich@intel.com>
147e83
Date:   Sat Dec 19 02:47:28 2015 +0300
147e83
147e83
    Added memset optimized with AVX512 for KNL hardware.
147e83
    
147e83
    It shows improvement up to 28% over AVX2 memset (performance results
147e83
    attached at <https://sourceware.org/ml/libc-alpha/2015-12/msg00052.html>).
147e83
    
147e83
        * sysdeps/x86_64/multiarch/memset-avx512-no-vzeroupper.S: New file.
147e83
        * sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Added new file.
147e83
        * sysdeps/x86_64/multiarch/ifunc-impl-list.c: Added new tests.
147e83
        * sysdeps/x86_64/multiarch/memset.S: Added new IFUNC branch.
147e83
        * sysdeps/x86_64/multiarch/memset_chk.S: Likewise.
147e83
        * sysdeps/x86/cpu-features.h (bit_Prefer_No_VZEROUPPER,
147e83
        index_Prefer_No_VZEROUPPER): New.
147e83
        * sysdeps/x86/cpu-features.c (init_cpu_features): Set the
147e83
        Prefer_No_VZEROUPPER for Knights Landing.
147e83
147e83
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86/cpu-features.c
147e83
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
147e83
@@ -76,6 +76,8 @@ init_cpu_features (struct cpu_features *
147e83
 
147e83
 	    case 0x57:
147e83
 	      /* Knights Landing.  Enable Silvermont optimizations.  */
147e83
+	      cpu_features->feature[index_Prefer_No_VZEROUPPER]
147e83
+		|= bit_Prefer_No_VZEROUPPER;
147e83
 
147e83
 	    case 0x37:
147e83
 	    case 0x4a:
147e83
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86/cpu-features.h
147e83
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
147e83
@@ -33,6 +33,7 @@
147e83
 #define bit_AVX512F_Usable		(1 << 12)
147e83
 #define bit_AVX512DQ_Usable		(1 << 13)
147e83
 #define bit_Prefer_MAP_32BIT_EXEC	(1 << 16)
147e83
+#define bit_Prefer_No_VZEROUPPER	(1 << 17)
147e83
 
147e83
 /* CPUID Feature flags.  */
147e83
 
147e83
@@ -93,6 +94,7 @@
147e83
 # define index_AVX512F_Usable		FEATURE_INDEX_1*FEATURE_SIZE
147e83
 # define index_AVX512DQ_Usable		FEATURE_INDEX_1*FEATURE_SIZE
147e83
 # define index_Prefer_MAP_32BIT_EXEC	FEATURE_INDEX_1*FEATURE_SIZE
147e83
+# define index_Prefer_No_VZEROUPPER	FEATURE_INDEX_1*FEATURE_SIZE
147e83
 
147e83
 # if defined (_LIBC) && !IS_IN (nonlib)
147e83
 #  ifdef __x86_64__
147e83
@@ -270,6 +272,7 @@ extern const struct cpu_features *__get_
147e83
 # define index_AVX512F_Usable		FEATURE_INDEX_1
147e83
 # define index_AVX512DQ_Usable		FEATURE_INDEX_1
147e83
 # define index_Prefer_MAP_32BIT_EXEC	FEATURE_INDEX_1
147e83
+# define index_Prefer_No_VZEROUPPER     FEATURE_INDEX_1
147e83
 
147e83
 #endif	/* !__ASSEMBLER__ */
147e83
 
147e83
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/Makefile
147e83
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
147e83
@@ -16,7 +16,8 @@ sysdep_routines += strncat-c stpncpy-c s
147e83
 		   strcat-sse2-unaligned strncat-sse2-unaligned \
147e83
 		   strcat-ssse3 strncat-ssse3 strlen-sse2-pminub \
147e83
 		   strnlen-sse2-no-bsf strrchr-sse2-no-bsf strchr-sse2-no-bsf \
147e83
-		   memcmp-ssse3 strstr-sse2-unaligned
147e83
+		   memcmp-ssse3 strstr-sse2-unaligned \
147e83
+		   memset-avx512-no-vzeroupper
147e83
 ifeq (yes,$(config-cflags-sse4))
147e83
 sysdep_routines += strcspn-c strpbrk-c strspn-c strstr-c strcasestr-c varshift
147e83
 CFLAGS-varshift.c += -msse4
147e83
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-impl-list.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/ifunc-impl-list.c
147e83
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-impl-list.c
147e83
@@ -20,6 +20,7 @@
147e83
 #include <string.h>
147e83
 #include <wchar.h>
147e83
 #include <ifunc-impl-list.h>
147e83
+#include <sysdep.h>
147e83
 #include "init-arch.h"
147e83
 
147e83
 /* Maximum number of IFUNC implementations.  */
147e83
@@ -66,12 +67,24 @@ __libc_ifunc_impl_list (const char *name
147e83
   IFUNC_IMPL (i, name, __memset_chk,
147e83
 	      IFUNC_IMPL_ADD (array, i, __memset_chk, 1, __memset_chk_sse2)
147e83
 	      IFUNC_IMPL_ADD (array, i, __memset_chk, 1,
147e83
-			      __memset_chk_x86_64))
147e83
+			      __memset_chk_x86_64)
147e83
+#ifdef HAVE_AVX512_ASM_SUPPORT
147e83
+	      IFUNC_IMPL_ADD (array, i, __memset_chk,
147e83
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
147e83
+			      __memset_chk_avx512_no_vzeroupper)
147e83
+#endif
147e83
+	      )
147e83
 
147e83
   /* Support sysdeps/x86_64/multiarch/memset.S.  */
147e83
   IFUNC_IMPL (i, name, memset,
147e83
 	      IFUNC_IMPL_ADD (array, i, memset, 1, __memset_sse2)
147e83
-	      IFUNC_IMPL_ADD (array, i, memset, 1, __memset_x86_64))
147e83
+	      IFUNC_IMPL_ADD (array, i, memset, 1, __memset_x86_64)
147e83
+#ifdef HAVE_AVX512_ASM_SUPPORT
147e83
+	      IFUNC_IMPL_ADD (array, i, memset,
147e83
+			      HAS_ARCH_FEATURE (AVX512F_Usable),
147e83
+			      __memset_avx512_no_vzeroupper)
147e83
+#endif
147e83
+	     )
147e83
 
147e83
   /* Support sysdeps/x86_64/multiarch/rawmemchr.S.  */
147e83
   IFUNC_IMPL (i, name, rawmemchr,
147e83
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset-avx512-no-vzeroupper.S
147e83
===================================================================
147e83
--- /dev/null
147e83
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset-avx512-no-vzeroupper.S
147e83
@@ -0,0 +1,194 @@
147e83
+/* memset optimized with AVX512 for KNL hardware.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#if defined HAVE_AVX512_ASM_SUPPORT && IS_IN (libc)
147e83
+
147e83
+#include "asm-syntax.h"
147e83
+#ifndef MEMSET
147e83
+# define MEMSET __memset_avx512_no_vzeroupper
147e83
+# define MEMSET_CHK __memset_chk_avx512_no_vzeroupper
147e83
+#endif
147e83
+
147e83
+	.section .text,"ax",@progbits
147e83
+#if defined PIC
147e83
+ENTRY (MEMSET_CHK)
147e83
+	cmpq	%rdx, %rcx
147e83
+	jb	HIDDEN_JUMPTARGET (__chk_fail)
147e83
+END (MEMSET_CHK)
147e83
+#endif
147e83
+
147e83
+ENTRY (MEMSET)
147e83
+	vpxor	%xmm0, %xmm0, %xmm0
147e83
+	vmovd	%esi, %xmm1
147e83
+	lea	(%rdi, %rdx), %rsi
147e83
+	mov	%rdi, %rax
147e83
+	vpshufb	%xmm0, %xmm1, %xmm0
147e83
+	cmp	$16, %rdx
147e83
+	jb	L(less_16bytes)
147e83
+	cmp	$512, %rdx
147e83
+	vbroadcastss	%xmm0, %zmm2
147e83
+	ja	L(512bytesormore)
147e83
+	cmp	$256, %rdx
147e83
+	jb	L(less_256bytes)
147e83
+	vmovups	%zmm2, (%rdi)
147e83
+	vmovups %zmm2, 0x40(%rdi)
147e83
+	vmovups %zmm2, 0x80(%rdi)
147e83
+	vmovups %zmm2, 0xC0(%rdi)
147e83
+	vmovups %zmm2, -0x100(%rsi)
147e83
+	vmovups %zmm2, -0xC0(%rsi)
147e83
+	vmovups %zmm2, -0x80(%rsi)
147e83
+	vmovups %zmm2, -0x40(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_256bytes):
147e83
+	cmp	$128, %dl
147e83
+	jb	L(less_128bytes)
147e83
+	vmovups	%zmm2, (%rdi)
147e83
+	vmovups %zmm2, 0x40(%rdi)
147e83
+	vmovups %zmm2, -0x80(%rsi)
147e83
+	vmovups %zmm2, -0x40(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_128bytes):
147e83
+	cmp	$64, %dl
147e83
+	jb	L(less_64bytes)
147e83
+	vmovups	%zmm2, (%rdi)
147e83
+	vmovups	%zmm2, -0x40(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_64bytes):
147e83
+	cmp	$32, %dl
147e83
+	jb	L(less_32bytes)
147e83
+	vmovdqu	%ymm2, (%rdi)
147e83
+	vmovdqu %ymm2, -0x20(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_32bytes):
147e83
+	vmovdqu %xmm0, (%rdi)
147e83
+	vmovdqu %xmm0, -0x10(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_16bytes):
147e83
+	cmp	$8, %dl
147e83
+	jb	L(less_8bytes)
147e83
+	vmovq	%xmm0, (%rdi)
147e83
+	vmovq	%xmm0, -0x08(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_8bytes):
147e83
+	vmovd	%xmm0, %ecx
147e83
+	cmp	$4, %dl
147e83
+	jb	L(less_4bytes)
147e83
+	mov	%ecx, (%rdi)
147e83
+	mov	%ecx, -0x04(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_4bytes):
147e83
+	cmp	$2, %dl
147e83
+	jb	L(less_2bytes)
147e83
+	mov	%cx, (%rdi)
147e83
+	mov	%cx, -0x02(%rsi)
147e83
+	ret
147e83
+
147e83
+L(less_2bytes):
147e83
+	cmp	$1, %dl
147e83
+	jb	L(less_1bytes)
147e83
+	mov	%cl, (%rdi)
147e83
+L(less_1bytes):
147e83
+	ret
147e83
+
147e83
+L(512bytesormore):
147e83
+	mov	__x86_64_shared_cache_size_half(%rip), %rcx
147e83
+	cmp	%rcx, %rdx
147e83
+	ja	L(preloop_large)
147e83
+	cmp	$1024, %rdx
147e83
+	ja	L(1024bytesormore)
147e83
+
147e83
+	vmovups	%zmm2, (%rdi)
147e83
+	vmovups	%zmm2, 0x40(%rdi)
147e83
+	vmovups	%zmm2, 0x80(%rdi)
147e83
+	vmovups	%zmm2, 0xC0(%rdi)
147e83
+	vmovups	%zmm2, 0x100(%rdi)
147e83
+	vmovups	%zmm2, 0x140(%rdi)
147e83
+	vmovups	%zmm2, 0x180(%rdi)
147e83
+	vmovups	%zmm2, 0x1C0(%rdi)
147e83
+	vmovups %zmm2, -0x200(%rsi)
147e83
+	vmovups %zmm2, -0x1C0(%rsi)
147e83
+	vmovups %zmm2, -0x180(%rsi)
147e83
+	vmovups %zmm2, -0x140(%rsi)
147e83
+	vmovups %zmm2, -0x100(%rsi)
147e83
+	vmovups %zmm2, -0xC0(%rsi)
147e83
+	vmovups %zmm2, -0x80(%rsi)
147e83
+	vmovups %zmm2, -0x40(%rsi)
147e83
+	ret
147e83
+
147e83
+/* Align on 64 and loop with aligned stores.  */
147e83
+L(1024bytesormore):
147e83
+	sub	$0x100, %rsi
147e83
+	vmovups	%zmm2, (%rax)
147e83
+	and	$-0x40, %rdi
147e83
+	add	$0x40, %rdi
147e83
+
147e83
+L(gobble_256bytes_loop):
147e83
+	vmovaps	%zmm2, (%rdi)
147e83
+	vmovaps	%zmm2, 0x40(%rdi)
147e83
+	vmovaps	%zmm2, 0x80(%rdi)
147e83
+	vmovaps	%zmm2, 0xC0(%rdi)
147e83
+	add	$0x100, %rdi
147e83
+	cmp	%rsi, %rdi
147e83
+	jb	L(gobble_256bytes_loop)
147e83
+	vmovups %zmm2, (%rsi)
147e83
+	vmovups %zmm2, 0x40(%rsi)
147e83
+	vmovups %zmm2, 0x80(%rsi)
147e83
+	vmovups %zmm2, 0xC0(%rsi)
147e83
+	ret
147e83
+
147e83
+/* Align on 128 and loop with non-temporal stores.  */
147e83
+L(preloop_large):
147e83
+	and	$-0x80, %rdi
147e83
+	add	$0x80, %rdi
147e83
+	vmovups	%zmm2, (%rax)
147e83
+	vmovups	%zmm2, 0x40(%rax)
147e83
+	sub	$0x200, %rsi
147e83
+
147e83
+L(gobble_512bytes_nt_loop):
147e83
+	vmovntdq %zmm2, (%rdi)
147e83
+	vmovntdq %zmm2, 0x40(%rdi)
147e83
+	vmovntdq %zmm2, 0x80(%rdi)
147e83
+	vmovntdq %zmm2, 0xC0(%rdi)
147e83
+	vmovntdq %zmm2, 0x100(%rdi)
147e83
+	vmovntdq %zmm2, 0x140(%rdi)
147e83
+	vmovntdq %zmm2, 0x180(%rdi)
147e83
+	vmovntdq %zmm2, 0x1C0(%rdi)
147e83
+	add	$0x200, %rdi
147e83
+	cmp	%rsi, %rdi
147e83
+	jb	L(gobble_512bytes_nt_loop)
147e83
+	sfence
147e83
+	vmovups %zmm2, (%rsi)
147e83
+	vmovups %zmm2, 0x40(%rsi)
147e83
+	vmovups %zmm2, 0x80(%rsi)
147e83
+	vmovups %zmm2, 0xC0(%rsi)
147e83
+	vmovups	%zmm2, 0x100(%rsi)
147e83
+	vmovups	%zmm2, 0x140(%rsi)
147e83
+	vmovups	%zmm2, 0x180(%rsi)
147e83
+	vmovups	%zmm2, 0x1C0(%rsi)
147e83
+	ret
147e83
+END (MEMSET)
147e83
+#endif
147e83
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset.S
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memset.S
147e83
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset.S
147e83
@@ -29,6 +29,13 @@ ENTRY(memset)
147e83
 	HAS_ARCH_FEATURE (Prefer_SSE_for_memop)
147e83
 	jz	2f
147e83
 	leaq	__memset_sse2(%rip), %rax
147e83
+#ifdef HAVE_AVX512_ASM_SUPPORT
147e83
+	HAS_ARCH_FEATURE (AVX512F_Usable)
147e83
+	jz	2f
147e83
+	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
147e83
+	jz	2f
147e83
+	leaq	__memset_avx512_no_vzeroupper(%rip), %rax
147e83
+#endif
147e83
 2:	ret
147e83
 END(memset)
147e83
 
147e83
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset_chk.S
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/memset_chk.S
147e83
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/memset_chk.S
147e83
@@ -30,6 +30,13 @@ ENTRY(__memset_chk)
147e83
 	HAS_ARCH_FEATURE (Prefer_SSE_for_memop)
147e83
 	jz	2f
147e83
 	leaq	__memset_chk_sse2(%rip), %rax
147e83
+#ifdef HAVE_AVX512_ASM_SUPPORT
147e83
+	HAS_ARCH_FEATURE (AVX512F_Usable)
147e83
+	jz	2f
147e83
+	HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
147e83
+	jz	2f
147e83
+	leaq	__memset_chk_avx512_no_vzeroupper(%rip), %rax
147e83
+#endif
147e83
 2:	ret
147e83
 END(__memset_chk)
147e83