about summary refs log tree commit diff
path: root/sysdeps/x86_64/dl-trampoline.S
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-08-23 09:09:32 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-04-20 07:55:19 -0700
commit83037ea1d9e84b1b44ed307f01cbb5eeac24e22d (patch)
tree4652bca0dcfdbdcf1334bf42befdc9681dbb56cf /sysdeps/x86_64/dl-trampoline.S
parent0be74c5c7cb239e4884d1ee0fd48c746a0bd1a65 (diff)
downloadglibc-83037ea1d9e84b1b44ed307f01cbb5eeac24e22d.tar.gz
glibc-83037ea1d9e84b1b44ed307f01cbb5eeac24e22d.tar.xz
glibc-83037ea1d9e84b1b44ed307f01cbb5eeac24e22d.zip
X86-64: Add _dl_runtime_resolve_avx[512]_{opt|slow} [BZ #20508]
There is transition penalty when SSE instructions are mixed with 256-bit
AVX or 512-bit AVX512 load instructions.  Since _dl_runtime_resolve_avx
and _dl_runtime_profile_avx512 save/restore 256-bit YMM/512-bit ZMM
registers, there is transition penalty when SSE instructions are used
with lazy binding on AVX and AVX512 processors.

To avoid SSE transition penalty, if only the lower 128 bits of the first
8 vector registers are non-zero, we can preserve %xmm0 - %xmm7 registers
with the zero upper bits.

For AVX and AVX512 processors which support XGETBV with ECX == 1, we can
use XGETBV with ECX == 1 to check if the upper 128 bits of YMM registers
or the upper 256 bits of ZMM registers are zero.  We can restore only the
non-zero portion of vector registers with AVX/AVX512 load instructions
which will zero-extend upper bits of vector registers.

This patch adds _dl_runtime_resolve_sse_vex which saves and restores
XMM registers with 128-bit AVX store/load instructions.  It is used to
preserve YMM/ZMM registers when only the lower 128 bits are non-zero.
_dl_runtime_resolve_avx_opt and _dl_runtime_resolve_avx512_opt are added
and used on AVX/AVX512 processors supporting XGETBV with ECX == 1 so
that we store and load only the non-zero portion of vector registers.
This avoids SSE transition penalty caused by _dl_runtime_resolve_avx and
_dl_runtime_profile_avx512 when only the lower 128 bits of vector
registers are used.

_dl_runtime_resolve_avx_slow is added and used for AVX processors which
don't support XGETBV with ECX == 1.  Since there is no SSE transition
penalty on AVX512 processors which don't support XGETBV with ECX == 1,
_dl_runtime_resolve_avx512_slow isn't provided.

	[BZ #20495]
	[BZ #20508]
	* sysdeps/x86/cpu-features.c (init_cpu_features): For Intel
	processors, set Use_dl_runtime_resolve_slow and set
	Use_dl_runtime_resolve_opt if XGETBV suports ECX == 1.
	* sysdeps/x86/cpu-features.h (bit_Use_dl_runtime_resolve_opt):
	New.
	(bit_Use_dl_runtime_resolve_slow): Likewise.
	(index_Use_dl_runtime_resolve_opt): Likewise.
	(index_Use_dl_runtime_resolve_slow): Likewise.
	* sysdeps/x86_64/dl-machine.h (elf_machine_runtime_setup): Use
	_dl_runtime_resolve_avx512_opt and _dl_runtime_resolve_avx_opt
	if Use_dl_runtime_resolve_opt is set.  Use
	_dl_runtime_resolve_slow if Use_dl_runtime_resolve_slow is set.
	* sysdeps/x86_64/dl-trampoline.S: Include <cpu-features.h>.
	(_dl_runtime_resolve_opt): New.  Defined for AVX and AVX512.
	(_dl_runtime_resolve): Add one for _dl_runtime_resolve_sse_vex.
	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_avx_slow):
	New.
	(_dl_runtime_resolve_opt): Likewise.
	(_dl_runtime_profile): Define only if _dl_runtime_profile is
	defined.

(cherry picked from commit fb0f7a6755c1bfaec38f490fbfcaa39a66ee3604)
Diffstat (limited to 'sysdeps/x86_64/dl-trampoline.S')
-rw-r--r--sysdeps/x86_64/dl-trampoline.S22
1 files changed, 22 insertions, 0 deletions
diff --git a/sysdeps/x86_64/dl-trampoline.S b/sysdeps/x86_64/dl-trampoline.S
index 39b8771aa7..3f812b89c0 100644
--- a/sysdeps/x86_64/dl-trampoline.S
+++ b/sysdeps/x86_64/dl-trampoline.S
@@ -18,6 +18,7 @@
 
 #include <config.h>
 #include <sysdep.h>
+#include <cpu-features.h>
 #include <link-defines.h>
 
 #ifndef DL_STACK_ALIGNMENT
@@ -87,9 +88,11 @@
 # endif
 # define VEC(i)			zmm##i
 # define _dl_runtime_resolve	_dl_runtime_resolve_avx512
+# define _dl_runtime_resolve_opt _dl_runtime_resolve_avx512_opt
 # define _dl_runtime_profile	_dl_runtime_profile_avx512
 # include "dl-trampoline.h"
 # undef _dl_runtime_resolve
+# undef _dl_runtime_resolve_opt
 # undef _dl_runtime_profile
 # undef VEC
 # undef VMOV
@@ -98,6 +101,8 @@
 #else
 strong_alias (_dl_runtime_resolve_avx, _dl_runtime_resolve_avx512)
 	.hidden _dl_runtime_resolve_avx512
+strong_alias (_dl_runtime_resolve_avx_opt, _dl_runtime_resolve_avx512_opt)
+	.hidden _dl_runtime_resolve_avx512_opt
 strong_alias (_dl_runtime_profile_avx, _dl_runtime_profile_avx512)
 	.hidden _dl_runtime_profile_avx512
 #endif
@@ -111,9 +116,11 @@ strong_alias (_dl_runtime_profile_avx, _dl_runtime_profile_avx512)
 #endif
 #define VEC(i)			ymm##i
 #define _dl_runtime_resolve	_dl_runtime_resolve_avx
+#define _dl_runtime_resolve_opt	_dl_runtime_resolve_avx_opt
 #define _dl_runtime_profile	_dl_runtime_profile_avx
 #include "dl-trampoline.h"
 #undef _dl_runtime_resolve
+#undef _dl_runtime_resolve_opt
 #undef _dl_runtime_profile
 #undef VEC
 #undef VMOV
@@ -133,3 +140,18 @@ strong_alias (_dl_runtime_profile_avx, _dl_runtime_profile_avx512)
 #define _dl_runtime_profile	_dl_runtime_profile_sse
 #undef RESTORE_AVX
 #include "dl-trampoline.h"
+#undef _dl_runtime_resolve
+#undef _dl_runtime_profile
+#undef VMOV
+#undef VMOVA
+
+/* Used by _dl_runtime_resolve_avx_opt/_dl_runtime_resolve_avx512_opt
+   to preserve the full vector registers with zero upper bits.  */
+#define VMOVA			vmovdqa
+#if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT
+# define VMOV			vmovdqa
+#else
+# define VMOV			vmovdqu
+#endif
+#define _dl_runtime_resolve	_dl_runtime_resolve_sse_vex
+#include "dl-trampoline.h"