ce426f
We add back Prefer_SSE_for_memop since we still need it for all of the
ce426f
existing era implementations for RHEL 7.3. To remove it would require
ce426f
a more wholesale backport of optmized routines.
ce426f
ce426f
commit e2e4f56056adddc3c1efe676b40a4b4f2453103b
ce426f
Author: H.J. Lu <hjl.tools@gmail.com>
ce426f
Date:   Thu Aug 13 03:37:47 2015 -0700
ce426f
ce426f
    Add _dl_x86_cpu_features to rtld_global
ce426f
    
ce426f
    This patch adds _dl_x86_cpu_features to rtld_global in x86 ld.so
ce426f
    and initializes it early before __libc_start_main is called so that
ce426f
    cpu_features is always available when it is used and we can avoid
ce426f
    calling __init_cpu_features in IFUNC selectors.
ce426f
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/dl-machine.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/dl-machine.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/dl-machine.h
ce426f
@@ -25,6 +25,7 @@
ce426f
 #include <sysdep.h>
ce426f
 #include <tls.h>
ce426f
 #include <dl-tlsdesc.h>
ce426f
+#include <cpu-features.c>
ce426f
 
ce426f
 /* Return nonzero iff ELF header is compatible with the running host.  */
ce426f
 static inline int __attribute__ ((unused))
ce426f
@@ -266,6 +267,8 @@ dl_platform_init (void)
ce426f
   if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
ce426f
     /* Avoid an empty string which would disturb us.  */
ce426f
     GLRO(dl_platform) = NULL;
ce426f
+
ce426f
+  init_cpu_features (&GLRO(dl_x86_cpu_features));
ce426f
 }
ce426f
 
ce426f
 static inline Elf32_Addr
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/dl-procinfo.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/dl-procinfo.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/dl-procinfo.c
ce426f
@@ -43,6 +43,22 @@
ce426f
 # define PROCINFO_CLASS
ce426f
 #endif
ce426f
 
ce426f
+#if !IS_IN (ldconfig)
ce426f
+# if !defined PROCINFO_DECL && defined SHARED
ce426f
+  ._dl_x86_cpu_features
ce426f
+# else
ce426f
+PROCINFO_CLASS struct cpu_features _dl_x86_cpu_features
ce426f
+# endif
ce426f
+# ifndef PROCINFO_DECL
ce426f
+= { }
ce426f
+# endif
ce426f
+# if !defined SHARED || defined PROCINFO_DECL
ce426f
+;
ce426f
+# else
ce426f
+,
ce426f
+# endif
ce426f
+#endif
ce426f
+
ce426f
 #if !defined PROCINFO_DECL && defined SHARED
ce426f
   ._dl_x86_cap_flags
ce426f
 #else
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/i686/cacheinfo.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/i686/cacheinfo.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/i686/cacheinfo.c
ce426f
@@ -8,6 +8,5 @@
ce426f
 #define __x86_64_raw_shared_cache_size_half __x86_raw_shared_cache_size_half
ce426f
 
ce426f
 #define DISABLE_PREFETCHW
ce426f
-#define DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
 
ce426f
 #include <sysdeps/x86_64/cacheinfo.c>
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/i686/multiarch/Makefile
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/i686/multiarch/Makefile
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/i686/multiarch/Makefile
ce426f
@@ -1,5 +1,4 @@
ce426f
 ifeq ($(subdir),csu)
ce426f
-aux += init-arch
ce426f
 tests += test-multiarch
ce426f
 gen-as-const-headers += ifunc-defines.sym
ce426f
 endif
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/i686/multiarch/Versions
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/i686/multiarch/Versions
ce426f
+++ /dev/null
ce426f
@@ -1,5 +0,0 @@
ce426f
-libc {
ce426f
-  GLIBC_PRIVATE {
ce426f
-    __get_cpu_features;
ce426f
-  }
ce426f
-}
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/i686/multiarch/ifunc-defines.sym
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/i686/multiarch/ifunc-defines.sym
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/i686/multiarch/ifunc-defines.sym
ce426f
@@ -4,7 +4,6 @@
ce426f
 --
ce426f
 
ce426f
 CPU_FEATURES_SIZE	sizeof (struct cpu_features)
ce426f
-KIND_OFFSET		offsetof (struct cpu_features, kind)
ce426f
 CPUID_OFFSET		offsetof (struct cpu_features, cpuid)
ce426f
 CPUID_SIZE		sizeof (struct cpuid_registers)
ce426f
 CPUID_EAX_OFFSET	offsetof (struct cpuid_registers, eax)
ce426f
Index: glibc-2.17-c758a686/sysdeps/i386/ldsodefs.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/i386/ldsodefs.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/i386/ldsodefs.h
ce426f
@@ -20,6 +20,7 @@
ce426f
 #define	_I386_LDSODEFS_H	1
ce426f
 
ce426f
 #include <elf.h>
ce426f
+#include <cpu-features.h>
ce426f
 
ce426f
 struct La_i86_regs;
ce426f
 struct La_i86_retval;
ce426f
Index: glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c
ce426f
@@ -1,5 +1,5 @@
ce426f
 #if IS_IN (ldconfig)
ce426f
 # include <sysdeps/i386/dl-procinfo.c>
ce426f
 #else
ce426f
-# include <sysdeps/generic/dl-procinfo.c>
ce426f
+# include <sysdeps/x86_64/dl-procinfo.c>
ce426f
 #endif
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/Makefile
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86/Makefile
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/Makefile
ce426f
@@ -7,3 +7,14 @@ $(objpfx)tst-xmmymmzmm.out: ../sysdeps/x
ce426f
 	@echo "Checking ld.so for SSE register use.  This will take a few seconds..."
ce426f
 	$(SHELL) $< $(objpfx) '$(NM)' '$(OBJDUMP)' '$(READELF)' > $@
ce426f
 endif
ce426f
+
ce426f
+ifeq ($(subdir),csu)
ce426f
+gen-as-const-headers += cpu-features-offsets.sym rtld-global-offsets.sym
ce426f
+endif
ce426f
+
ce426f
+ifeq ($(subdir),elf)
ce426f
+sysdep-dl-routines += dl-get-cpu-features
ce426f
+
ce426f
+tests += tst-get-cpu-features
ce426f
+tests-static += tst-get-cpu-features-static
ce426f
+endif
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/Versions
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/Versions
ce426f
@@ -0,0 +1,5 @@
ce426f
+ld {
ce426f
+  GLIBC_PRIVATE {
ce426f
+    __get_cpu_features;
ce426f
+  }
ce426f
+}
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features-offsets.sym
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features-offsets.sym
ce426f
@@ -0,0 +1,7 @@
ce426f
+#define SHARED 1
ce426f
+
ce426f
+#include <ldsodefs.h>
ce426f
+
ce426f
+#define rtld_global_ro_offsetof(mem) offsetof (struct rtld_global_ro, mem)
ce426f
+
ce426f
+RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET rtld_global_ro_offsetof (_dl_x86_cpu_features)
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
ce426f
@@ -0,0 +1,213 @@
ce426f
+/* Initialize CPU feature data.
ce426f
+   This file is part of the GNU C Library.
ce426f
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <cpuid.h>
ce426f
+#include <cpu-features.h>
ce426f
+
ce426f
+static inline void
ce426f
+get_common_indeces (struct cpu_features *cpu_features,
ce426f
+		    unsigned int *family, unsigned int *model)
ce426f
+{
ce426f
+  unsigned int eax;
ce426f
+  __cpuid (1, eax, cpu_features->cpuid[COMMON_CPUID_INDEX_1].ebx,
ce426f
+	   cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx,
ce426f
+	   cpu_features->cpuid[COMMON_CPUID_INDEX_1].edx);
ce426f
+  GLRO(dl_x86_cpu_features).cpuid[COMMON_CPUID_INDEX_1].eax = eax;
ce426f
+  *family = (eax >> 8) & 0x0f;
ce426f
+  *model = (eax >> 4) & 0x0f;
ce426f
+}
ce426f
+
ce426f
+static inline void
ce426f
+init_cpu_features (struct cpu_features *cpu_features)
ce426f
+{
ce426f
+  unsigned int ebx, ecx, edx;
ce426f
+  unsigned int family = 0;
ce426f
+  unsigned int model = 0;
ce426f
+  enum cpu_features_kind kind;
ce426f
+
ce426f
+  __cpuid (0, cpu_features->max_cpuid, ebx, ecx, edx);
ce426f
+
ce426f
+  /* This spells out "GenuineIntel".  */
ce426f
+  if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
ce426f
+    {
ce426f
+      kind = arch_kind_intel;
ce426f
+
ce426f
+      get_common_indeces (cpu_features, &family, &model);
ce426f
+
ce426f
+      /* Intel processors prefer SSE instruction for memory/string
ce426f
+        routines if they are available.  */
ce426f
+      cpu_features->feature[index_Prefer_SSE_for_memop]
ce426f
+        |= bit_Prefer_SSE_for_memop;
ce426f
+
ce426f
+      unsigned int eax = cpu_features->cpuid[COMMON_CPUID_INDEX_1].eax;
ce426f
+      unsigned int extended_family = (eax >> 20) & 0xff;
ce426f
+      unsigned int extended_model = (eax >> 12) & 0xf0;
ce426f
+      if (family == 0x0f)
ce426f
+	{
ce426f
+	  family += extended_family;
ce426f
+	  model += extended_model;
ce426f
+	}
ce426f
+      else if (family == 0x06)
ce426f
+	{
ce426f
+	  ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
+	  model += extended_model;
ce426f
+	  switch (model)
ce426f
+	    {
ce426f
+	    case 0x1c:
ce426f
+	    case 0x26:
ce426f
+	      /* BSF is slow on Atom.  */
ce426f
+	      cpu_features->feature[index_Slow_BSF] |= bit_Slow_BSF;
ce426f
+	      break;
ce426f
+
ce426f
+	    case 0x37:
ce426f
+	    case 0x4a:
ce426f
+	    case 0x4d:
ce426f
+	    case 0x5a:
ce426f
+	    case 0x5d:
ce426f
+	      /* Unaligned load versions are faster than SSSE3
ce426f
+		 on Silvermont.  */
ce426f
+#if index_Fast_Unaligned_Load != index_Prefer_PMINUB_for_stringop
ce426f
+# error index_Fast_Unaligned_Load != index_Prefer_PMINUB_for_stringop
ce426f
+#endif
ce426f
+#if index_Fast_Unaligned_Load != index_Slow_SSE4_2
ce426f
+# error index_Fast_Unaligned_Load != index_Slow_SSE4_2
ce426f
+#endif
ce426f
+	      cpu_features->feature[index_Fast_Unaligned_Load]
ce426f
+		|= (bit_Fast_Unaligned_Load
ce426f
+		    | bit_Prefer_PMINUB_for_stringop
ce426f
+		    | bit_Slow_SSE4_2);
ce426f
+	      break;
ce426f
+
ce426f
+	    default:
ce426f
+	      /* Unknown family 0x06 processors.  Assuming this is one
ce426f
+		 of Core i3/i5/i7 processors if AVX is available.  */
ce426f
+	      if ((ecx & bit_AVX) == 0)
ce426f
+		break;
ce426f
+
ce426f
+	    case 0x1a:
ce426f
+	    case 0x1e:
ce426f
+	    case 0x1f:
ce426f
+	    case 0x25:
ce426f
+	    case 0x2c:
ce426f
+	    case 0x2e:
ce426f
+	    case 0x2f:
ce426f
+	      /* Rep string instructions, copy backward, unaligned loads
ce426f
+		 and pminub are fast on Intel Core i3, i5 and i7.  */
ce426f
+#if index_Fast_Rep_String != index_Fast_Copy_Backward
ce426f
+# error index_Fast_Rep_String != index_Fast_Copy_Backward
ce426f
+#endif
ce426f
+#if index_Fast_Rep_String != index_Fast_Unaligned_Load
ce426f
+# error index_Fast_Rep_String != index_Fast_Unaligned_Load
ce426f
+#endif
ce426f
+#if index_Fast_Rep_String != index_Prefer_PMINUB_for_stringop
ce426f
+# error index_Fast_Rep_String != index_Prefer_PMINUB_for_stringop
ce426f
+#endif
ce426f
+	      cpu_features->feature[index_Fast_Rep_String]
ce426f
+		|= (bit_Fast_Rep_String
ce426f
+		    | bit_Fast_Copy_Backward
ce426f
+		    | bit_Fast_Unaligned_Load
ce426f
+		    | bit_Prefer_PMINUB_for_stringop);
ce426f
+	      break;
ce426f
+	    }
ce426f
+	}
ce426f
+    }
ce426f
+  /* This spells out "AuthenticAMD".  */
ce426f
+  else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
ce426f
+    {
ce426f
+      kind = arch_kind_amd;
ce426f
+
ce426f
+      get_common_indeces (cpu_features, &family, &model);
ce426f
+
ce426f
+      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
+
ce426f
+      /* AMD processors prefer SSE instructions for memory/string routines
ce426f
+        if they are available, otherwise they prefer integer instructions.  */
ce426f
+      if ((ecx & 0x200))
ce426f
+	cpu_features->feature[index_Prefer_SSE_for_memop]
ce426f
+	  |= bit_Prefer_SSE_for_memop;
ce426f
+
ce426f
+      unsigned int eax;
ce426f
+      __cpuid (0x80000000, eax, ebx, ecx, edx);
ce426f
+      if (eax >= 0x80000001)
ce426f
+	__cpuid (0x80000001,
ce426f
+		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
ce426f
+		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
ce426f
+		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
ce426f
+		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
ce426f
+    }
ce426f
+  else
ce426f
+    kind = arch_kind_other;
ce426f
+
ce426f
+  if (cpu_features->max_cpuid >= 7)
ce426f
+    __cpuid_count (7, 0,
ce426f
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].eax,
ce426f
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].ebx,
ce426f
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].ecx,
ce426f
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].edx);
ce426f
+
ce426f
+  /* Can we call xgetbv?  */
ce426f
+  if (HAS_CPU_FEATURE (OSXSAVE))
ce426f
+    {
ce426f
+      unsigned int xcrlow;
ce426f
+      unsigned int xcrhigh;
ce426f
+      asm ("xgetbv" : "=a" (xcrlow), "=d" (xcrhigh) : "c" (0));
ce426f
+      /* Is YMM and XMM state usable?  */
ce426f
+      if ((xcrlow & (bit_YMM_state | bit_XMM_state)) ==
ce426f
+	  (bit_YMM_state | bit_XMM_state))
ce426f
+	{
ce426f
+	  /* Determine if AVX is usable.  */
ce426f
+	  if (HAS_CPU_FEATURE (AVX))
ce426f
+	    cpu_features->feature[index_AVX_Usable] |= bit_AVX_Usable;
ce426f
+#if index_AVX2_Usable != index_AVX_Fast_Unaligned_Load
ce426f
+# error index_AVX2_Usable != index_AVX_Fast_Unaligned_Load
ce426f
+#endif
ce426f
+	  /* Determine if AVX2 is usable.  Unaligned load with 256-bit
ce426f
+	     AVX registers are faster on processors with AVX2.  */
ce426f
+	  if (HAS_CPU_FEATURE (AVX2))
ce426f
+	    cpu_features->feature[index_AVX2_Usable]
ce426f
+	      |= bit_AVX2_Usable | bit_AVX_Fast_Unaligned_Load;
ce426f
+	  /* Check if OPMASK state, upper 256-bit of ZMM0-ZMM15 and
ce426f
+	     ZMM16-ZMM31 state are enabled.  */
ce426f
+	  if ((xcrlow & (bit_Opmask_state | bit_ZMM0_15_state
ce426f
+			 | bit_ZMM16_31_state)) ==
ce426f
+	      (bit_Opmask_state | bit_ZMM0_15_state | bit_ZMM16_31_state))
ce426f
+	    {
ce426f
+	      /* Determine if AVX512F is usable.  */
ce426f
+	      if (HAS_CPU_FEATURE (AVX512F))
ce426f
+		{
ce426f
+		  cpu_features->feature[index_AVX512F_Usable]
ce426f
+		    |= bit_AVX512F_Usable;
ce426f
+		  /* Determine if AVX512DQ is usable.  */
ce426f
+		  if (HAS_CPU_FEATURE (AVX512DQ))
ce426f
+		    cpu_features->feature[index_AVX512DQ_Usable]
ce426f
+		      |= bit_AVX512DQ_Usable;
ce426f
+		}
ce426f
+	    }
ce426f
+	  /* Determine if FMA is usable.  */
ce426f
+	  if (HAS_CPU_FEATURE (FMA))
ce426f
+	    cpu_features->feature[index_FMA_Usable] |= bit_FMA_Usable;
ce426f
+	  /* Determine if FMA4 is usable.  */
ce426f
+	  if (HAS_CPU_FEATURE (FMA4))
ce426f
+	    cpu_features->feature[index_FMA4_Usable] |= bit_FMA4_Usable;
ce426f
+	}
ce426f
+    }
ce426f
+
ce426f
+  cpu_features->family = family;
ce426f
+  cpu_features->model = model;
ce426f
+  cpu_features->kind = kind;
ce426f
+}
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
ce426f
@@ -0,0 +1,273 @@
ce426f
+/* This file is part of the GNU C Library.
ce426f
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#ifndef cpu_features_h
ce426f
+#define cpu_features_h
ce426f
+
ce426f
+#define bit_Fast_Rep_String		(1 << 0)
ce426f
+#define bit_Fast_Copy_Backward		(1 << 1)
ce426f
+#define bit_Slow_BSF			(1 << 2)
ce426f
+#define bit_Prefer_SSE_for_memop	(1 << 3)
ce426f
+#define bit_Fast_Unaligned_Load		(1 << 4)
ce426f
+#define bit_Prefer_PMINUB_for_stringop	(1 << 5)
ce426f
+#define bit_AVX_Usable			(1 << 6)
ce426f
+#define bit_FMA_Usable			(1 << 7)
ce426f
+#define bit_FMA4_Usable			(1 << 8)
ce426f
+#define bit_Slow_SSE4_2			(1 << 9)
ce426f
+#define bit_AVX2_Usable			(1 << 10)
ce426f
+#define bit_AVX_Fast_Unaligned_Load	(1 << 11)
ce426f
+#define bit_AVX512F_Usable		(1 << 12)
ce426f
+#define bit_AVX512DQ_Usable		(1 << 13)
ce426f
+
ce426f
+/* CPUID Feature flags.  */
ce426f
+
ce426f
+/* COMMON_CPUID_INDEX_1.  */
ce426f
+#define bit_SSE2	(1 << 26)
ce426f
+#define bit_SSSE3	(1 << 9)
ce426f
+#define bit_SSE4_1	(1 << 19)
ce426f
+#define bit_SSE4_2	(1 << 20)
ce426f
+#define bit_OSXSAVE	(1 << 27)
ce426f
+#define bit_AVX		(1 << 28)
ce426f
+#define bit_POPCOUNT	(1 << 23)
ce426f
+#define bit_FMA		(1 << 12)
ce426f
+#define bit_FMA4	(1 << 16)
ce426f
+
ce426f
+/* COMMON_CPUID_INDEX_7.  */
ce426f
+#define bit_RTM		(1 << 11)
ce426f
+#define bit_AVX2	(1 << 5)
ce426f
+#define bit_AVX512F	(1 << 16)
ce426f
+#define bit_AVX512DQ	(1 << 17)
ce426f
+
ce426f
+/* XCR0 Feature flags.  */
ce426f
+#define bit_XMM_state  (1 << 1)
ce426f
+#define bit_YMM_state  (2 << 1)
ce426f
+#define bit_Opmask_state	(1 << 5)
ce426f
+#define bit_ZMM0_15_state	(1 << 6)
ce426f
+#define bit_ZMM16_31_state	(1 << 7)
ce426f
+
ce426f
+/* The integer bit array index for the first set of internal feature bits.  */
ce426f
+#define FEATURE_INDEX_1 0
ce426f
+
ce426f
+/* The current maximum size of the feature integer bit array.  */
ce426f
+#define FEATURE_INDEX_MAX 1
ce426f
+
ce426f
+#ifdef	__ASSEMBLER__
ce426f
+
ce426f
+# include <ifunc-defines.h>
ce426f
+# include <rtld-global-offsets.h>
ce426f
+
ce426f
+# define index_SSE2	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
ce426f
+# define index_SSSE3	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
+# define index_SSE4_1	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
+# define index_SSE4_2	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
+# define index_AVX	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
+# define index_AVX2	COMMON_CPUID_INDEX_7*CPUID_SIZE+CPUID_EBX_OFFSET
ce426f
+
ce426f
+# define index_Fast_Rep_String		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Fast_Copy_Backward	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Slow_BSF			FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Prefer_SSE_for_memop	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Fast_Unaligned_Load	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_AVX_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_FMA_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_FMA4_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_Slow_SSE4_2		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_AVX2_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_AVX_Fast_Unaligned_Load	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_AVX512F_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+# define index_AVX512DQ_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
+
ce426f
+# if defined (_LIBC) && !IS_IN (nonlib)
ce426f
+#  ifdef __x86_64__
ce426f
+#   ifdef SHARED
ce426f
+#    if IS_IN (rtld)
ce426f
+#     define LOAD_RTLD_GLOBAL_RO_RDX
ce426f
+#     define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), _rtld_local_ro+offset+(index_##name)(%rip)
ce426f
+#    else
ce426f
+#      define LOAD_RTLD_GLOBAL_RO_RDX \
ce426f
+  mov _rtld_global_ro@GOTPCREL(%rip), %RDX_LP
ce426f
+#     define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), \
ce426f
+	RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET+offset+(index_##name)(%rdx)
ce426f
+#    endif
ce426f
+#   else /* SHARED */
ce426f
+#    define LOAD_RTLD_GLOBAL_RO_RDX
ce426f
+#    define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), _dl_x86_cpu_features+offset+(index_##name)(%rip)
ce426f
+#   endif /* !SHARED */
ce426f
+#  else  /* __x86_64__ */
ce426f
+#   ifdef SHARED
ce426f
+#    define LOAD_FUNC_GOT_EAX(func) \
ce426f
+  leal func@GOTOFF(%edx), %eax
ce426f
+#    if IS_IN (rtld)
ce426f
+#    define LOAD_GOT_AND_RTLD_GLOBAL_RO \
ce426f
+  LOAD_PIC_REG(dx)
ce426f
+#     define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), offset+(index_##name)+_rtld_local_ro@GOTOFF(%edx)
ce426f
+#    else
ce426f
+#     define LOAD_GOT_AND_RTLD_GLOBAL_RO \
ce426f
+  LOAD_PIC_REG(dx); \
ce426f
+  mov _rtld_global_ro@GOT(%edx), %ecx
ce426f
+#     define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), \
ce426f
+	RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET+offset+(index_##name)(%ecx)
ce426f
+#    endif
ce426f
+#   else  /* SHARED */
ce426f
+#    define LOAD_FUNC_GOT_EAX(func) \
ce426f
+  leal func, %eax
ce426f
+#    define LOAD_GOT_AND_RTLD_GLOBAL_RO
ce426f
+#    define HAS_FEATURE(offset, name) \
ce426f
+  testl $(bit_##name), _dl_x86_cpu_features+offset+(index_##name)
ce426f
+#   endif /* !SHARED */
ce426f
+#  endif /* !__x86_64__ */
ce426f
+# else /* _LIBC && !nonlib */
ce426f
+#  error "Sorry, <cpu-features.h> is unimplemented for assembler"
ce426f
+# endif /* !_LIBC || nonlib */
ce426f
+
ce426f
+/* HAS_* evaluates to true if we may use the feature at runtime.  */
ce426f
+# define HAS_CPU_FEATURE(name)	HAS_FEATURE (CPUID_OFFSET, name)
ce426f
+# define HAS_ARCH_FEATURE(name) HAS_FEATURE (FEATURE_OFFSET, name)
ce426f
+
ce426f
+#else	/* __ASSEMBLER__ */
ce426f
+
ce426f
+# include <sys/param.h>
ce426f
+# include <sys/types.h>
ce426f
+# include <sysdep.h>
ce426f
+# include <stdbool.h>
ce426f
+
ce426f
+/* Ugly hack to make it possible to select a strstr and strcasestr
ce426f
+   implementation that avoids using the stack for 16-byte aligned
ce426f
+   SSE temporaries.  Doing so makes it possible to call the functions
ce426f
+   with a stack that's not 16-byte aligned as can happen, for example,
ce426f
+   as a result of compiling the functions' callers with the GCC
ce426f
+   -mpreferred-stack-boubdary=2 or =3 option, or with the ICC
ce426f
+   -falign-stack=assume-4-byte option.  See rhbz 1150282 for details.
ce426f
+
ce426f
+   The ifunc selector uses the unaligned version by default if this
ce426f
+   file exists and is accessible.  */
ce426f
+# define ENABLE_STRSTR_UNALIGNED_PATHNAME \
ce426f
+    "/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned"
ce426f
+
ce426f
+static bool __attribute__ ((unused))
ce426f
+use_unaligned_strstr (void)
ce426f
+{
ce426f
+  struct stat unaligned_strstr_etc_sysconfig_file;
ce426f
+
ce426f
+  /* TLS may not have been set up yet, so avoid using stat since it tries to
ce426f
+     set errno.  */
ce426f
+  return INTERNAL_SYSCALL (stat, , 2,
ce426f
+			   ENABLE_STRSTR_UNALIGNED_PATHNAME,
ce426f
+			   &unaligned_strstr_etc_sysconfig_file) == 0;
ce426f
+}
ce426f
+
ce426f
+enum
ce426f
+  {
ce426f
+    COMMON_CPUID_INDEX_1 = 0,
ce426f
+    COMMON_CPUID_INDEX_7,
ce426f
+    COMMON_CPUID_INDEX_80000001,	/* for AMD */
ce426f
+    /* Keep the following line at the end.  */
ce426f
+    COMMON_CPUID_INDEX_MAX
ce426f
+  };
ce426f
+
ce426f
+struct cpu_features
ce426f
+{
ce426f
+  enum cpu_features_kind
ce426f
+    {
ce426f
+      arch_kind_unknown = 0,
ce426f
+      arch_kind_intel,
ce426f
+      arch_kind_amd,
ce426f
+      arch_kind_other
ce426f
+    } kind;
ce426f
+  int max_cpuid;
ce426f
+  struct cpuid_registers
ce426f
+  {
ce426f
+    unsigned int eax;
ce426f
+    unsigned int ebx;
ce426f
+    unsigned int ecx;
ce426f
+    unsigned int edx;
ce426f
+  } cpuid[COMMON_CPUID_INDEX_MAX];
ce426f
+  unsigned int family;
ce426f
+  unsigned int model;
ce426f
+  unsigned int feature[FEATURE_INDEX_MAX];
ce426f
+};
ce426f
+
ce426f
+/* Used from outside of glibc to get access to the CPU features
ce426f
+   structure.  */
ce426f
+extern const struct cpu_features *__get_cpu_features (void)
ce426f
+     __attribute__ ((const));
ce426f
+
ce426f
+# if defined (_LIBC) && !IS_IN (nonlib)
ce426f
+/* Unused for x86.  */
ce426f
+#  define INIT_ARCH()
ce426f
+#  define __get_cpu_features()	(&GLRO(dl_x86_cpu_features))
ce426f
+# endif
ce426f
+
ce426f
+
ce426f
+/* HAS_* evaluates to true if we may use the feature at runtime.  */
ce426f
+# define HAS_CPU_FEATURE(name) \
ce426f
+  ((__get_cpu_features ()->cpuid[index_##name].reg_##name & (bit_##name)) != 0)
ce426f
+# define HAS_ARCH_FEATURE(name) \
ce426f
+  ((__get_cpu_features ()->feature[index_##name] & (bit_##name)) != 0)
ce426f
+
ce426f
+# define index_SSE2		COMMON_CPUID_INDEX_1
ce426f
+# define index_SSSE3		COMMON_CPUID_INDEX_1
ce426f
+# define index_SSE4_1		COMMON_CPUID_INDEX_1
ce426f
+# define index_SSE4_2		COMMON_CPUID_INDEX_1
ce426f
+# define index_AVX		COMMON_CPUID_INDEX_1
ce426f
+# define index_AVX2		COMMON_CPUID_INDEX_7
ce426f
+# define index_AVX512F		COMMON_CPUID_INDEX_7
ce426f
+# define index_AVX512DQ		COMMON_CPUID_INDEX_7
ce426f
+# define index_RTM		COMMON_CPUID_INDEX_7
ce426f
+# define index_FMA		COMMON_CPUID_INDEX_1
ce426f
+# define index_FMA4		COMMON_CPUID_INDEX_80000001
ce426f
+# define index_POPCOUNT		COMMON_CPUID_INDEX_1
ce426f
+# define index_OSXSAVE		COMMON_CPUID_INDEX_1
ce426f
+
ce426f
+# define reg_SSE2		edx
ce426f
+# define reg_SSSE3		ecx
ce426f
+# define reg_SSE4_1		ecx
ce426f
+# define reg_SSE4_2		ecx
ce426f
+# define reg_AVX		ecx
ce426f
+# define reg_AVX2		ebx
ce426f
+# define reg_AVX512F		ebx
ce426f
+# define reg_AVX512DQ		ebx
ce426f
+# define reg_RTM		ebx
ce426f
+# define reg_FMA		ecx
ce426f
+# define reg_FMA4		ecx
ce426f
+# define reg_POPCOUNT		ecx
ce426f
+# define reg_OSXSAVE		ecx
ce426f
+
ce426f
+# define index_Fast_Rep_String		FEATURE_INDEX_1
ce426f
+# define index_Fast_Copy_Backward	FEATURE_INDEX_1
ce426f
+# define index_Slow_BSF			FEATURE_INDEX_1
ce426f
+# define index_Prefer_SSE_for_memop	FEATURE_INDEX_1
ce426f
+# define index_Fast_Unaligned_Load	FEATURE_INDEX_1
ce426f
+# define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1
ce426f
+# define index_AVX_Usable		FEATURE_INDEX_1
ce426f
+# define index_FMA_Usable		FEATURE_INDEX_1
ce426f
+# define index_FMA4_Usable		FEATURE_INDEX_1
ce426f
+# define index_Slow_SSE4_2		FEATURE_INDEX_1
ce426f
+# define index_AVX2_Usable		FEATURE_INDEX_1
ce426f
+# define index_AVX_Fast_Unaligned_Load	FEATURE_INDEX_1
ce426f
+# define index_AVX512F_Usable		FEATURE_INDEX_1
ce426f
+# define index_AVX512DQ_Usable		FEATURE_INDEX_1
ce426f
+
ce426f
+#endif	/* !__ASSEMBLER__ */
ce426f
+
ce426f
+#endif  /* cpu_features_h */
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/dl-get-cpu-features.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/dl-get-cpu-features.c
ce426f
@@ -0,0 +1,27 @@
ce426f
+/* This file is part of the GNU C Library.
ce426f
+   Copyright (C) 2015 Free Software Foundation, Inc.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+
ce426f
+#include <ldsodefs.h>
ce426f
+
ce426f
+#undef __get_cpu_features
ce426f
+
ce426f
+const struct cpu_features *
ce426f
+__get_cpu_features (void)
ce426f
+{
ce426f
+  return &GLRO(dl_x86_cpu_features);
ce426f
+}
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/libc-start.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/libc-start.c
ce426f
@@ -0,0 +1,41 @@
ce426f
+/* Copyright (C) 2015 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#ifdef SHARED
ce426f
+# include <csu/libc-start.c>
ce426f
+# else
ce426f
+/* The main work is done in the generic function.  */
ce426f
+# define LIBC_START_DISABLE_INLINE
ce426f
+# define LIBC_START_MAIN generic_start_main
ce426f
+# include <csu/libc-start.c>
ce426f
+# include <cpu-features.h>
ce426f
+# include <cpu-features.c>
ce426f
+
ce426f
+extern struct cpu_features _dl_x86_cpu_features;
ce426f
+
ce426f
+int
ce426f
+__libc_start_main (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
ce426f
+		   int argc, char **argv,
ce426f
+		   __typeof (main) init,
ce426f
+		   void (*fini) (void),
ce426f
+		   void (*rtld_fini) (void), void *stack_end)
ce426f
+{
ce426f
+  init_cpu_features (&_dl_x86_cpu_features);
ce426f
+  return generic_start_main (main, argc, argv, init, fini, rtld_fini,
ce426f
+			     stack_end);
ce426f
+}
ce426f
+#endif
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/rtld-global-offsets.sym
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/rtld-global-offsets.sym
ce426f
@@ -0,0 +1,7 @@
ce426f
+#define SHARED 1
ce426f
+
ce426f
+#include <ldsodefs.h>
ce426f
+
ce426f
+#define rtld_global_ro_offsetof(mem) offsetof (struct rtld_global_ro, mem)
ce426f
+
ce426f
+RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET rtld_global_ro_offsetof (_dl_x86_cpu_features)
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/tst-get-cpu-features-static.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/tst-get-cpu-features-static.c
ce426f
@@ -0,0 +1 @@
ce426f
+#include "tst-get-cpu-features.c"
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86/tst-get-cpu-features.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86/tst-get-cpu-features.c
ce426f
@@ -0,0 +1,31 @@
ce426f
+/* Test case for x86 __get_cpu_features interface
ce426f
+   Copyright (C) 2015 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <stdlib.h>
ce426f
+#include <cpu-features.h>
ce426f
+
ce426f
+static int
ce426f
+do_test (void)
ce426f
+{
ce426f
+  if (__get_cpu_features ()->kind == arch_kind_unknown)
ce426f
+    abort ();
ce426f
+  return 0;
ce426f
+}
ce426f
+
ce426f
+#define TEST_FUNCTION do_test ()
ce426f
+#include "../../test-skeleton.c"
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/cacheinfo.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/cacheinfo.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/cacheinfo.c
ce426f
@@ -21,40 +21,11 @@
ce426f
 #include <stdlib.h>
ce426f
 #include <unistd.h>
ce426f
 #include <cpuid.h>
ce426f
+#include "multiarch/init-arch.h"
ce426f
 
ce426f
-#ifndef __cpuid_count
ce426f
-/* FIXME: Provide __cpuid_count if it isn't defined.  Copied from gcc
ce426f
-   4.4.0.  Remove this if gcc 4.4 is the minimum requirement.  */
ce426f
-# if defined(__i386__) && defined(__PIC__)
ce426f
-/* %ebx may be the PIC register.  */
ce426f
-#  define __cpuid_count(level, count, a, b, c, d)		\
ce426f
-  __asm__ ("xchg{l}\t{%%}ebx, %1\n\t"			\
ce426f
-	   "cpuid\n\t"					\
ce426f
-	   "xchg{l}\t{%%}ebx, %1\n\t"			\
ce426f
-	   : "=a" (a), "=r" (b), "=c" (c), "=d" (d)	\
ce426f
-	   : "0" (level), "2" (count))
ce426f
-# else
ce426f
-#  define __cpuid_count(level, count, a, b, c, d)		\
ce426f
-  __asm__ ("cpuid\n\t"					\
ce426f
-	   : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
ce426f
-	   : "0" (level), "2" (count))
ce426f
-# endif
ce426f
-#endif
ce426f
-
ce426f
-#ifdef USE_MULTIARCH
ce426f
-# include "multiarch/init-arch.h"
ce426f
-
ce426f
-# define is_intel __cpu_features.kind == arch_kind_intel
ce426f
-# define is_amd __cpu_features.kind == arch_kind_amd
ce426f
-# define max_cpuid __cpu_features.max_cpuid
ce426f
-#else
ce426f
-  /* This spells out "GenuineIntel".  */
ce426f
-# define is_intel \
ce426f
-  ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69
ce426f
-  /* This spells out "AuthenticAMD".  */
ce426f
-# define is_amd \
ce426f
-  ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65
ce426f
-#endif
ce426f
+#define is_intel GLRO(dl_x86_cpu_features).kind == arch_kind_intel
ce426f
+#define is_amd GLRO(dl_x86_cpu_features).kind == arch_kind_amd
ce426f
+#define max_cpuid GLRO(dl_x86_cpu_features).max_cpuid
ce426f
 
ce426f
 static const struct intel_02_cache_info
ce426f
 {
ce426f
@@ -237,21 +208,8 @@ intel_check_word (int name, unsigned int
ce426f
 	      /* Intel reused this value.  For family 15, model 6 it
ce426f
 		 specifies the 3rd level cache.  Otherwise the 2nd
ce426f
 		 level cache.  */
ce426f
-	      unsigned int family;
ce426f
-	      unsigned int model;
ce426f
-#ifdef USE_MULTIARCH
ce426f
-	      family = __cpu_features.family;
ce426f
-	      model = __cpu_features.model;
ce426f
-#else
ce426f
-	      unsigned int eax;
ce426f
-	      unsigned int ebx;
ce426f
-	      unsigned int ecx;
ce426f
-	      unsigned int edx;
ce426f
-	      __cpuid (1, eax, ebx, ecx, edx);
ce426f
-
ce426f
-	      family = ((eax >> 20) & 0xff) + ((eax >> 8) & 0xf);
ce426f
-	      model = (((eax >>16) & 0xf) << 4) + ((eax >> 4) & 0xf);
ce426f
-#endif
ce426f
+	      unsigned int family = GLRO(dl_x86_cpu_features).family;
ce426f
+	      unsigned int model = GLRO(dl_x86_cpu_features).model;
ce426f
 
ce426f
 	      if (family == 15 && model == 6)
ce426f
 		{
ce426f
@@ -478,18 +436,6 @@ long int
ce426f
 attribute_hidden
ce426f
 __cache_sysconf (int name)
ce426f
 {
ce426f
-#ifdef USE_MULTIARCH
ce426f
-  if (__cpu_features.kind == arch_kind_unknown)
ce426f
-    __init_cpu_features ();
ce426f
-#else
ce426f
-  /* Find out what brand of processor.  */
ce426f
-  unsigned int max_cpuid;
ce426f
-  unsigned int ebx;
ce426f
-  unsigned int ecx;
ce426f
-  unsigned int edx;
ce426f
-  __cpuid (0, max_cpuid, ebx, ecx, edx);
ce426f
-#endif
ce426f
-
ce426f
   if (is_intel)
ce426f
     return handle_intel (name, max_cpuid);
ce426f
 
ce426f
@@ -525,18 +471,6 @@ long int __x86_64_raw_shared_cache_size
ce426f
 int __x86_64_prefetchw attribute_hidden;
ce426f
 #endif
ce426f
 
ce426f
-#ifndef DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
-/* Instructions preferred for memory and string routines.
ce426f
-
ce426f
-  0: Regular instructions
ce426f
-  1: MMX instructions
ce426f
-  2: SSE2 instructions
ce426f
-  3: SSSE3 instructions
ce426f
-
ce426f
-  */
ce426f
-int __x86_64_preferred_memory_instruction attribute_hidden;
ce426f
-#endif
ce426f
-
ce426f
 
ce426f
 static void
ce426f
 __attribute__((constructor))
ce426f
@@ -553,14 +487,6 @@ init_cacheinfo (void)
ce426f
   unsigned int level;
ce426f
   unsigned int threads = 0;
ce426f
 
ce426f
-#ifdef USE_MULTIARCH
ce426f
-  if (__cpu_features.kind == arch_kind_unknown)
ce426f
-    __init_cpu_features ();
ce426f
-#else
ce426f
-  int max_cpuid;
ce426f
-  __cpuid (0, max_cpuid, ebx, ecx, edx);
ce426f
-#endif
ce426f
-
ce426f
   if (is_intel)
ce426f
     {
ce426f
       data = handle_intel (_SC_LEVEL1_DCACHE_SIZE, max_cpuid);
ce426f
@@ -576,34 +502,13 @@ init_cacheinfo (void)
ce426f
 	  shared = handle_intel (_SC_LEVEL2_CACHE_SIZE, max_cpuid);
ce426f
 	}
ce426f
 
ce426f
-      unsigned int ebx_1;
ce426f
-
ce426f
-#ifdef USE_MULTIARCH
ce426f
-      eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
ce426f
-      ebx_1 = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx;
ce426f
-      ecx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
-      edx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx;
ce426f
-#else
ce426f
-      __cpuid (1, eax, ebx_1, ecx, edx);
ce426f
-#endif
ce426f
-
ce426f
-      unsigned int family = (eax >> 8) & 0x0f;
ce426f
-      unsigned int model = (eax >> 4) & 0x0f;
ce426f
-      unsigned int extended_model = (eax >> 12) & 0xf0;
ce426f
-
ce426f
-#ifndef DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
-      /* Intel prefers SSSE3 instructions for memory/string routines
ce426f
-	 if they are available.  */
ce426f
-      if ((ecx & 0x200))
ce426f
-	__x86_64_preferred_memory_instruction = 3;
ce426f
-      else
ce426f
-	__x86_64_preferred_memory_instruction = 2;
ce426f
-#endif
ce426f
-
ce426f
       /* Figure out the number of logical threads that share the
ce426f
 	 highest cache level.  */
ce426f
       if (max_cpuid >= 4)
ce426f
 	{
ce426f
+	  unsigned int family = GLRO(dl_x86_cpu_features).family;
ce426f
+	  unsigned int model = GLRO(dl_x86_cpu_features).model;
ce426f
+
ce426f
 	  int i = 0;
ce426f
 
ce426f
 	  /* Query until desired cache level is enumerated.  */
ce426f
@@ -655,7 +560,6 @@ init_cacheinfo (void)
ce426f
 	  threads += 1;
ce426f
 	  if (threads > 2 && level == 2 && family == 6)
ce426f
 	    {
ce426f
-	      model += extended_model;
ce426f
 	      switch (model)
ce426f
 		{
ce426f
 		case 0x57:
ce426f
@@ -678,7 +582,9 @@ init_cacheinfo (void)
ce426f
 	intel_bug_no_cache_info:
ce426f
 	  /* Assume that all logical threads share the highest cache level.  */
ce426f
 
ce426f
-	  threads = (ebx_1 >> 16) & 0xff;
ce426f
+	  threads
ce426f
+	    = ((GLRO(dl_x86_cpu_features).cpuid[COMMON_CPUID_INDEX_1].ebx
ce426f
+		>> 16) & 0xff);
ce426f
 	}
ce426f
 
ce426f
       /* Cap usage of highest cache level to the number of supported
ce426f
@@ -693,25 +599,6 @@ init_cacheinfo (void)
ce426f
       long int core = handle_amd (_SC_LEVEL2_CACHE_SIZE);
ce426f
       shared = handle_amd (_SC_LEVEL3_CACHE_SIZE);
ce426f
 
ce426f
-#ifndef DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
-# ifdef USE_MULTIARCH
ce426f
-      eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
ce426f
-      ebx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx;
ce426f
-      ecx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
-      edx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx;
ce426f
-# else
ce426f
-      __cpuid (1, eax, ebx, ecx, edx);
ce426f
-# endif
ce426f
-
ce426f
-      /* AMD prefers SSSE3 instructions for memory/string routines
ce426f
-	 if they are avaiable, otherwise it prefers integer
ce426f
-	 instructions.  */
ce426f
-      if ((ecx & 0x200))
ce426f
-	__x86_64_preferred_memory_instruction = 3;
ce426f
-      else
ce426f
-	__x86_64_preferred_memory_instruction = 0;
ce426f
-#endif
ce426f
-
ce426f
       /* Get maximum extended function. */
ce426f
       __cpuid (0x80000000, max_cpuid_ex, ebx, ecx, edx);
ce426f
 
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/dl-machine.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/dl-machine.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/dl-machine.h
ce426f
@@ -26,6 +26,7 @@
ce426f
 #include <sysdep.h>
ce426f
 #include <tls.h>
ce426f
 #include <dl-tlsdesc.h>
ce426f
+#include <cpu-features.c>
ce426f
 
ce426f
 /* Return nonzero iff ELF header is compatible with the running host.  */
ce426f
 static inline int __attribute__ ((unused))
ce426f
@@ -200,6 +201,8 @@ dl_platform_init (void)
ce426f
   if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
ce426f
     /* Avoid an empty string which would disturb us.  */
ce426f
     GLRO(dl_platform) = NULL;
ce426f
+
ce426f
+  init_cpu_features (&GLRO(dl_x86_cpu_features));
ce426f
 }
ce426f
 
ce426f
 static inline ElfW(Addr)
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/dl-procinfo.c
ce426f
===================================================================
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/dl-procinfo.c
ce426f
@@ -0,0 +1,57 @@
ce426f
+/* Data for x86-64 version of processor capability information.
ce426f
+   Copyright (C) 2015 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+/* If anything should be added here check whether the size of each string
ce426f
+   is still ok with the given array size.
ce426f
+
ce426f
+   All the #ifdefs in the definitions are quite irritating but
ce426f
+   necessary if we want to avoid duplicating the information.  There
ce426f
+   are three different modes:
ce426f
+
ce426f
+   - PROCINFO_DECL is defined.  This means we are only interested in
ce426f
+     declarations.
ce426f
+
ce426f
+   - PROCINFO_DECL is not defined:
ce426f
+
ce426f
+     + if SHARED is defined the file is included in an array
ce426f
+       initializer.  The .element = { ... } syntax is needed.
ce426f
+
ce426f
+     + if SHARED is not defined a normal array initialization is
ce426f
+       needed.
ce426f
+  */
ce426f
+
ce426f
+#ifndef PROCINFO_CLASS
ce426f
+# define PROCINFO_CLASS
ce426f
+#endif
ce426f
+
ce426f
+#if !defined PROCINFO_DECL && defined SHARED
ce426f
+  ._dl_x86_cpu_features
ce426f
+#else
ce426f
+PROCINFO_CLASS struct cpu_features _dl_x86_cpu_features
ce426f
+#endif
ce426f
+#ifndef PROCINFO_DECL
ce426f
+= { }
ce426f
+#endif
ce426f
+#if !defined SHARED || defined PROCINFO_DECL
ce426f
+;
ce426f
+#else
ce426f
+,
ce426f
+#endif
ce426f
+
ce426f
+#undef PROCINFO_DECL
ce426f
+#undef PROCINFO_CLASS
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/ldsodefs.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/ldsodefs.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/ldsodefs.h
ce426f
@@ -20,6 +20,7 @@
ce426f
 #define	_X86_64_LDSODEFS_H	1
ce426f
 
ce426f
 #include <elf.h>
ce426f
+#include <cpu-features.h>
ce426f
 
ce426f
 struct La_x86_64_regs;
ce426f
 struct La_x86_64_retval;
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/Makefile
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Makefile
ce426f
@@ -1,5 +1,4 @@
ce426f
 ifeq ($(subdir),csu)
ce426f
-aux += init-arch
ce426f
 tests += test-multiarch
ce426f
 gen-as-const-headers += ifunc-defines.sym
ce426f
 endif
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/Versions
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/Versions
ce426f
+++ /dev/null
ce426f
@@ -1,5 +0,0 @@
ce426f
-libc {
ce426f
-  GLIBC_PRIVATE {
ce426f
-    __get_cpu_features;
ce426f
-  }
ce426f
-}
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/cacheinfo.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/cacheinfo.c
ce426f
+++ /dev/null
ce426f
@@ -1,2 +0,0 @@
ce426f
-#define DISABLE_PREFERRED_MEMORY_INSTRUCTION
ce426f
-#include "../cacheinfo.c"
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-defines.sym
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/ifunc-defines.sym
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/ifunc-defines.sym
ce426f
@@ -4,7 +4,6 @@
ce426f
 --
ce426f
 
ce426f
 CPU_FEATURES_SIZE	sizeof (struct cpu_features)
ce426f
-KIND_OFFSET		offsetof (struct cpu_features, kind)
ce426f
 CPUID_OFFSET		offsetof (struct cpu_features, cpuid)
ce426f
 CPUID_SIZE		sizeof (struct cpuid_registers)
ce426f
 CPUID_EAX_OFFSET	offsetof (struct cpuid_registers, eax)
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/init-arch.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/init-arch.c
ce426f
+++ /dev/null
ce426f
@@ -1,183 +0,0 @@
ce426f
-/* Initialize CPU feature data.
ce426f
-   This file is part of the GNU C Library.
ce426f
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
ce426f
-   Contributed by Ulrich Drepper <drepper@redhat.com>.
ce426f
-
ce426f
-   The GNU C Library is free software; you can redistribute it and/or
ce426f
-   modify it under the terms of the GNU Lesser General Public
ce426f
-   License as published by the Free Software Foundation; either
ce426f
-   version 2.1 of the License, or (at your option) any later version.
ce426f
-
ce426f
-   The GNU C Library is distributed in the hope that it will be useful,
ce426f
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
-   Lesser General Public License for more details.
ce426f
-
ce426f
-   You should have received a copy of the GNU Lesser General Public
ce426f
-   License along with the GNU C Library; if not, see
ce426f
-   <http://www.gnu.org/licenses/>.  */
ce426f
-
ce426f
-#include <atomic.h>
ce426f
-#include <cpuid.h>
ce426f
-#include "init-arch.h"
ce426f
-
ce426f
-
ce426f
-struct cpu_features __cpu_features attribute_hidden;
ce426f
-
ce426f
-
ce426f
-static void
ce426f
-get_common_indeces (unsigned int *family, unsigned int *model)
ce426f
-{
ce426f
-  __cpuid (1, __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax,
ce426f
-	   __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ebx,
ce426f
-	   __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx,
ce426f
-	   __cpu_features.cpuid[COMMON_CPUID_INDEX_1].edx);
ce426f
-
ce426f
-  unsigned int eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
ce426f
-  *family = (eax >> 8) & 0x0f;
ce426f
-  *model = (eax >> 4) & 0x0f;
ce426f
-}
ce426f
-
ce426f
-
ce426f
-void
ce426f
-__init_cpu_features (void)
ce426f
-{
ce426f
-  unsigned int ebx;
ce426f
-  unsigned int ecx;
ce426f
-  unsigned int edx;
ce426f
-  unsigned int family = 0;
ce426f
-  unsigned int model = 0;
ce426f
-  enum cpu_features_kind kind;
ce426f
-
ce426f
-  __cpuid (0, __cpu_features.max_cpuid, ebx, ecx, edx);
ce426f
-
ce426f
-  /* This spells out "GenuineIntel".  */
ce426f
-  if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
ce426f
-    {
ce426f
-      kind = arch_kind_intel;
ce426f
-
ce426f
-      get_common_indeces (&family, &model);
ce426f
-
ce426f
-      /* Intel processors prefer SSE instruction for memory/string
ce426f
-	 routines if they are available.  */
ce426f
-      __cpu_features.feature[index_Prefer_SSE_for_memop]
ce426f
-	|= bit_Prefer_SSE_for_memop;
ce426f
-
ce426f
-      unsigned int eax = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].eax;
ce426f
-      unsigned int extended_family = (eax >> 20) & 0xff;
ce426f
-      unsigned int extended_model = (eax >> 12) & 0xf0;
ce426f
-      if (family == 0x0f)
ce426f
-	{
ce426f
-	  family += extended_family;
ce426f
-	  model += extended_model;
ce426f
-	}
ce426f
-      else if (family == 0x06)
ce426f
-	{
ce426f
-	  ecx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
-	  model += extended_model;
ce426f
-	  switch (model)
ce426f
-	    {
ce426f
-	    case 0x1c:
ce426f
-	    case 0x26:
ce426f
-	      /* BSF is slow on Atom.  */
ce426f
-	      __cpu_features.feature[index_Slow_BSF] |= bit_Slow_BSF;
ce426f
-	      break;
ce426f
-
ce426f
-	    default:
ce426f
-	      /* Unknown family 0x06 processors.  Assuming this is one
ce426f
-		 of Core i3/i5/i7 processors if AVX is available.  */
ce426f
-	      if ((ecx & bit_AVX) == 0)
ce426f
-		break;
ce426f
-
ce426f
-	    case 0x1a:
ce426f
-	    case 0x1e:
ce426f
-	    case 0x1f:
ce426f
-	    case 0x25:
ce426f
-	    case 0x2c:
ce426f
-	    case 0x2e:
ce426f
-	    case 0x2f:
ce426f
-	      /* Rep string instructions, copy backward, unaligned loads
ce426f
-		 and pminub are fast on Intel Core i3, i5 and i7.  */
ce426f
-#if index_Fast_Rep_String != index_Fast_Copy_Backward
ce426f
-# error index_Fast_Rep_String != index_Fast_Copy_Backward
ce426f
-#endif
ce426f
-#if index_Fast_Rep_String != index_Fast_Unaligned_Load
ce426f
-# error index_Fast_Rep_String != index_Fast_Unaligned_Load
ce426f
-#endif
ce426f
-#if index_Fast_Rep_String != index_Prefer_PMINUB_for_stringop
ce426f
-# error index_Fast_Rep_String != index_Prefer_PMINUB_for_stringop
ce426f
-#endif
ce426f
-	      __cpu_features.feature[index_Fast_Rep_String]
ce426f
-		|= (bit_Fast_Rep_String
ce426f
-		    | bit_Fast_Copy_Backward
ce426f
-		    | bit_Fast_Unaligned_Load
ce426f
-		    | bit_Prefer_PMINUB_for_stringop);
ce426f
-	      break;
ce426f
-	    }
ce426f
-	}
ce426f
-    }
ce426f
-  /* This spells out "AuthenticAMD".  */
ce426f
-  else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
ce426f
-    {
ce426f
-      kind = arch_kind_amd;
ce426f
-
ce426f
-      get_common_indeces (&family, &model);
ce426f
-
ce426f
-      ecx = __cpu_features.cpuid[COMMON_CPUID_INDEX_1].ecx;
ce426f
-
ce426f
-      /* AMD processors prefer SSE instructions for memory/string routines
ce426f
-	 if they are available, otherwise they prefer integer instructions.  */
ce426f
-      if ((ecx & 0x200))
ce426f
-	__cpu_features.feature[index_Prefer_SSE_for_memop]
ce426f
-	  |= bit_Prefer_SSE_for_memop;
ce426f
-
ce426f
-      unsigned int eax;
ce426f
-      __cpuid (0x80000000, eax, ebx, ecx, edx);
ce426f
-      if (eax >= 0x80000001)
ce426f
-	__cpuid (0x80000001,
ce426f
-		 __cpu_features.cpuid[COMMON_CPUID_INDEX_80000001].eax,
ce426f
-		 __cpu_features.cpuid[COMMON_CPUID_INDEX_80000001].ebx,
ce426f
-		 __cpu_features.cpuid[COMMON_CPUID_INDEX_80000001].ecx,
ce426f
-		 __cpu_features.cpuid[COMMON_CPUID_INDEX_80000001].edx);
ce426f
-    }
ce426f
-  else
ce426f
-    kind = arch_kind_other;
ce426f
-
ce426f
-  /* Can we call xgetbv?  */
ce426f
-  if (CPUID_OSXSAVE)
ce426f
-    {
ce426f
-      unsigned int xcrlow;
ce426f
-      unsigned int xcrhigh;
ce426f
-      asm ("xgetbv" : "=a" (xcrlow), "=d" (xcrhigh) : "c" (0));
ce426f
-      /* Is YMM and XMM state usable?  */
ce426f
-      if ((xcrlow & (bit_YMM_state | bit_XMM_state)) ==
ce426f
-	  (bit_YMM_state | bit_XMM_state))
ce426f
-	{
ce426f
-	  /* Determine if AVX is usable.  */
ce426f
-	  if (CPUID_AVX)
ce426f
-	    __cpu_features.feature[index_AVX_Usable] |= bit_AVX_Usable;
ce426f
-	  /* Determine if FMA is usable.  */
ce426f
-	  if (CPUID_FMA)
ce426f
-	    __cpu_features.feature[index_FMA_Usable] |= bit_FMA_Usable;
ce426f
-	  /* Determine if FMA4 is usable.  */
ce426f
-	  if (CPUID_FMA4)
ce426f
-	    __cpu_features.feature[index_FMA4_Usable] |= bit_FMA4_Usable;
ce426f
-	}
ce426f
-    }
ce426f
-
ce426f
-  __cpu_features.family = family;
ce426f
-  __cpu_features.model = model;
ce426f
-  atomic_write_barrier ();
ce426f
-  __cpu_features.kind = kind;
ce426f
-}
ce426f
-
ce426f
-#undef __get_cpu_features
ce426f
-
ce426f
-const struct cpu_features *
ce426f
-__get_cpu_features (void)
ce426f
-{
ce426f
-  if (__cpu_features.kind == arch_kind_unknown)
ce426f
-    __init_cpu_features ();
ce426f
-
ce426f
-  return &__cpu_features;
ce426f
-}
ce426f
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/init-arch.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/init-arch.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/init-arch.h
ce426f
@@ -15,183 +15,8 @@
ce426f
    License along with the GNU C Library; if not, see
ce426f
    <http://www.gnu.org/licenses/>.  */
ce426f
 
ce426f
-#define bit_Fast_Rep_String		(1 << 0)
ce426f
-#define bit_Fast_Copy_Backward		(1 << 1)
ce426f
-#define bit_Slow_BSF			(1 << 2)
ce426f
-#define bit_Prefer_SSE_for_memop	(1 << 3)
ce426f
-#define bit_Fast_Unaligned_Load		(1 << 4)
ce426f
-#define bit_Prefer_PMINUB_for_stringop	(1 << 5)
ce426f
-#define bit_AVX_Usable			(1 << 6)
ce426f
-#define bit_FMA_Usable			(1 << 7)
ce426f
-#define bit_FMA4_Usable			(1 << 8)
ce426f
-
ce426f
-/* CPUID Feature flags.  */
ce426f
-#define bit_SSE2	(1 << 26)
ce426f
-#define bit_SSSE3	(1 << 9)
ce426f
-#define bit_SSE4_1	(1 << 19)
ce426f
-#define bit_SSE4_2	(1 << 20)
ce426f
-#define bit_OSXSAVE	(1 << 27)
ce426f
-#define bit_AVX		(1 << 28)
ce426f
-#define bit_POPCOUNT	(1 << 23)
ce426f
-#define bit_FMA		(1 << 12)
ce426f
-#define bit_FMA4	(1 << 16)
ce426f
-
ce426f
-/* XCR0 Feature flags.  */
ce426f
-#define bit_XMM_state  (1 << 1)
ce426f
-#define bit_YMM_state  (2 << 1)
ce426f
-
ce426f
-#ifdef	__ASSEMBLER__
ce426f
-
ce426f
-# include <ifunc-defines.h>
ce426f
-
ce426f
-# define index_SSE2	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_EDX_OFFSET
ce426f
-# define index_SSSE3	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
-# define index_SSE4_1	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
-# define index_SSE4_2	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
-# define index_AVX	COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET
ce426f
-
ce426f
-# define index_Fast_Rep_String		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_Fast_Copy_Backward	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_Slow_BSF			FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_Prefer_SSE_for_memop	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_Fast_Unaligned_Load	FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_AVX_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_FMA_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-# define index_FMA4_Usable		FEATURE_INDEX_1*FEATURE_SIZE
ce426f
-
ce426f
-#else	/* __ASSEMBLER__ */
ce426f
-
ce426f
-# include <sys/param.h>
ce426f
-# include <sys/types.h>
ce426f
-# include <sysdep.h>
ce426f
-# include <stdbool.h>
ce426f
-
ce426f
-/* Ugly hack to make it possible to select a strstr and strcasestr
ce426f
-   implementation that avoids using the stack for 16-byte aligned
ce426f
-   SSE temporaries.  Doing so makes it possible to call the functions
ce426f
-   with a stack that's not 16-byte aligned as can happen, for example,
ce426f
-   as a result of compiling the functions' callers with the GCC
ce426f
-   -mpreferred-stack-boubdary=2 or =3 option, or with the ICC
ce426f
-   -falign-stack=assume-4-byte option.  See rhbz 1150282 for details.
ce426f
-
ce426f
-   The ifunc selector uses the unaligned version by default if this
ce426f
-   file exists and is accessible.  */
ce426f
-# define ENABLE_STRSTR_UNALIGNED_PATHNAME \
ce426f
-    "/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned"
ce426f
-
ce426f
-static bool __attribute__ ((unused))
ce426f
-use_unaligned_strstr (void)
ce426f
-{
ce426f
-  struct stat unaligned_strstr_etc_sysconfig_file;
ce426f
-
ce426f
-  /* TLS may not have been set up yet, so avoid using stat since it tries to
ce426f
-     set errno.  */
ce426f
-  return INTERNAL_SYSCALL (stat, , 2,
ce426f
-                           ENABLE_STRSTR_UNALIGNED_PATHNAME,
ce426f
-                           &unaligned_strstr_etc_sysconfig_file) == 0;
ce426f
-}
ce426f
-
ce426f
-enum
ce426f
-  {
ce426f
-    COMMON_CPUID_INDEX_1 = 0,
ce426f
-    COMMON_CPUID_INDEX_80000001,	/* for AMD */
ce426f
-    /* Keep the following line at the end.  */
ce426f
-    COMMON_CPUID_INDEX_MAX
ce426f
-  };
ce426f
-
ce426f
-enum
ce426f
-  {
ce426f
-    FEATURE_INDEX_1 = 0,
ce426f
-    /* Keep the following line at the end.  */
ce426f
-    FEATURE_INDEX_MAX
ce426f
-  };
ce426f
-
ce426f
-extern struct cpu_features
ce426f
-{
ce426f
-  enum cpu_features_kind
ce426f
-    {
ce426f
-      arch_kind_unknown = 0,
ce426f
-      arch_kind_intel,
ce426f
-      arch_kind_amd,
ce426f
-      arch_kind_other
ce426f
-    } kind;
ce426f
-  int max_cpuid;
ce426f
-  struct cpuid_registers
ce426f
-  {
ce426f
-    unsigned int eax;
ce426f
-    unsigned int ebx;
ce426f
-    unsigned int ecx;
ce426f
-    unsigned int edx;
ce426f
-  } cpuid[COMMON_CPUID_INDEX_MAX];
ce426f
-  unsigned int family;
ce426f
-  unsigned int model;
ce426f
-  unsigned int feature[FEATURE_INDEX_MAX];
ce426f
-} __cpu_features attribute_hidden;
ce426f
-
ce426f
-
ce426f
-extern void __init_cpu_features (void) attribute_hidden;
ce426f
-# define INIT_ARCH() \
ce426f
-  do							\
ce426f
-    if (__cpu_features.kind == arch_kind_unknown)	\
ce426f
-      __init_cpu_features ();				\
ce426f
-  while (0)
ce426f
-
ce426f
-/* Used from outside libc.so to get access to the CPU features structure.  */
ce426f
-extern const struct cpu_features *__get_cpu_features (void)
ce426f
-     __attribute__ ((const));
ce426f
-
ce426f
-# if IS_IN (libc)
ce426f
-#  define __get_cpu_features()	(&__cpu_features)
ce426f
-# endif
ce426f
-
ce426f
-# define HAS_CPU_FEATURE(idx, reg, bit) \
ce426f
-  ((__get_cpu_features ()->cpuid[idx].reg & (bit)) != 0)
ce426f
-
ce426f
-/* Following are the feature tests used throughout libc.  */
ce426f
-
ce426f
-/* CPUID_* evaluates to true if the feature flag is enabled.
ce426f
-   We always use &__cpu_features because the HAS_CPUID_* macros
ce426f
-   are called only within __init_cpu_features, where we can't
ce426f
-   call __get_cpu_features without infinite recursion.  */
ce426f
-# define HAS_CPUID_FLAG(idx, reg, bit) \
ce426f
-  (((&__cpu_features)->cpuid[idx].reg & (bit)) != 0)
ce426f
-
ce426f
-# define CPUID_OSXSAVE \
ce426f
-  HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_OSXSAVE)
ce426f
-# define CPUID_AVX \
ce426f
-  HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_AVX)
ce426f
-# define CPUID_FMA \
ce426f
-  HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_FMA)
ce426f
-# define CPUID_FMA4 \
ce426f
-  HAS_CPUID_FLAG (COMMON_CPUID_INDEX_80000001, ecx, bit_FMA4)
ce426f
-
ce426f
-/* HAS_* evaluates to true if we may use the feature at runtime.  */
ce426f
-# define HAS_SSE2	HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, edx, bit_SSE2)
ce426f
-# define HAS_POPCOUNT	HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_POPCOUNT)
ce426f
-# define HAS_SSSE3	HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSSE3)
ce426f
-# define HAS_SSE4_1	HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_1)
ce426f
-# define HAS_SSE4_2	HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_2)
ce426f
-
ce426f
-# define index_Fast_Rep_String		FEATURE_INDEX_1
ce426f
-# define index_Fast_Copy_Backward	FEATURE_INDEX_1
ce426f
-# define index_Slow_BSF			FEATURE_INDEX_1
ce426f
-# define index_Prefer_SSE_for_memop	FEATURE_INDEX_1
ce426f
-# define index_Fast_Unaligned_Load	FEATURE_INDEX_1
ce426f
-# define index_AVX_Usable		FEATURE_INDEX_1
ce426f
-# define index_FMA_Usable		FEATURE_INDEX_1
ce426f
-# define index_FMA4_Usable		FEATURE_INDEX_1
ce426f
-
ce426f
-# define HAS_ARCH_FEATURE(name) \
ce426f
-  ((__get_cpu_features ()->feature[index_##name] & (bit_##name)) != 0)
ce426f
-
ce426f
-# define HAS_FAST_REP_STRING		HAS_ARCH_FEATURE (Fast_Rep_String)
ce426f
-# define HAS_FAST_COPY_BACKWARD		HAS_ARCH_FEATURE (Fast_Copy_Backward)
ce426f
-# define HAS_SLOW_BSF			HAS_ARCH_FEATURE (Slow_BSF)
ce426f
-# define HAS_PREFER_SSE_FOR_MEMOP	HAS_ARCH_FEATURE (Prefer_SSE_for_memop)
ce426f
-# define HAS_FAST_UNALIGNED_LOAD	HAS_ARCH_FEATURE (Fast_Unaligned_Load)
ce426f
-# define HAS_AVX			HAS_ARCH_FEATURE (AVX_Usable)
ce426f
-# define HAS_FMA			HAS_ARCH_FEATURE (FMA_Usable)
ce426f
-# define HAS_FMA4			HAS_ARCH_FEATURE (FMA4_Usable)
ce426f
-
ce426f
-#endif	/* __ASSEMBLER__ */
ce426f
+#ifdef  __ASSEMBLER__
ce426f
+# include <cpu-features.h>
ce426f
+#else
ce426f
+# include <ldsodefs.h>
ce426f
+#endif