446cf2
commit c22e4c2a1431c5e77bf4288d35bf7629f2f093aa
446cf2
Author: H.J. Lu <hjl.tools@gmail.com>
446cf2
Date:   Mon Dec 3 05:54:43 2018 -0800
446cf2
446cf2
    x86: Extend CPUID support in struct cpu_features
446cf2
    
446cf2
    Extend CPUID support for all feature bits from CPUID.  Add a new macro,
446cf2
    CPU_FEATURE_USABLE, which can be used to check if a feature is usable at
446cf2
    run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE.
446cf2
    
446cf2
    Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and
446cf2
    COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them.
446cf2
    
446cf2
    Tested on i686 and x86-64 as well as using build-many-glibcs.py with
446cf2
    x86 targets.
446cf2
    
446cf2
            * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for
446cf2
            cpu_features_basic.
446cf2
            (__cache_sysconf): Likewise.
446cf2
            (init_cacheinfo): Likewise.
446cf2
            * sysdeps/x86/cpu-features.c (get_extended_indeces): Also
446cf2
            populate COMMON_CPUID_INDEX_80000007 and
446cf2
            COMMON_CPUID_INDEX_80000008.
446cf2
            (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1.
446cf2
            Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if
446cf2
            XSAVEC is available.  Set the bit_arch_XXX_Usable bits.
446cf2
            (init_cpu_features): Use _Static_assert on
446cf2
            index_arch_Fast_Unaligned_Load.
446cf2
            __get_cpuid_registers and __get_arch_feature.  Updated for
446cf2
            cpu_features_basic.  Set stepping in cpu_features.
446cf2
            * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum.
446cf2
            (FEATURE_INDEX_2): New.
446cf2
            (FEATURE_INDEX_MAX): Changed to enum.
446cf2
            (COMMON_CPUID_INDEX_D_ECX_1): New.
446cf2
            (COMMON_CPUID_INDEX_80000007): Likewise.
446cf2
            (COMMON_CPUID_INDEX_80000008): Likewise.
446cf2
            (cpuid_registers): Likewise.
446cf2
            (cpu_features_basic): Likewise.
446cf2
            (CPU_FEATURE_USABLE): Likewise.
446cf2
            (bit_arch_XXX_Usable): Likewise.
446cf2
            (cpu_features): Use cpuid_registers and cpu_features_basic.
446cf2
            (bit_arch_XXX): Reweritten.
446cf2
            (bit_cpu_XXX): Likewise.
446cf2
            (index_cpu_XXX): Likewise.
446cf2
            (reg_XXX): Likewise.
446cf2
            * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and
446cf2
            <support/check.h>.
446cf2
            (CHECK_CPU_FEATURE): New.
446cf2
            (CHECK_CPU_FEATURE_USABLE): Likewise.
446cf2
            (cpu_kinds): Likewise.
446cf2
            (do_test): Print vendor, family, model and stepping.  Check
446cf2
            HAS_CPU_FEATURE and CPU_FEATURE_USABLE.
446cf2
            (TEST_FUNCTION): Removed.
446cf2
            Include <support/test-driver.c> instead of
446cf2
            "../../test-skeleton.c".
446cf2
            * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount):
446cf2
            Check POPCNT instead of POPCOUNT.
446cf2
            * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
446cf2
446cf2
Backport difference: Adjustments to previous cache sizing
446cf2
backports (which happened later upstream).
446cf2
446cf2
diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
446cf2
index 57c36d030a76c8b2..f1125f30223f5ca3 100644
446cf2
--- a/sysdeps/x86/cacheinfo.c
446cf2
+++ b/sysdeps/x86/cacheinfo.c
446cf2
@@ -205,8 +205,8 @@ intel_check_word (int name, unsigned int value, bool *has_level_2,
446cf2
 	      /* Intel reused this value.  For family 15, model 6 it
446cf2
 		 specifies the 3rd level cache.  Otherwise the 2nd
446cf2
 		 level cache.  */
446cf2
-	      unsigned int family = cpu_features->family;
446cf2
-	      unsigned int model = cpu_features->model;
446cf2
+	      unsigned int family = cpu_features->basic.family;
446cf2
+	      unsigned int model = cpu_features->basic.model;
446cf2
 
446cf2
 	      if (family == 15 && model == 6)
446cf2
 		{
446cf2
@@ -258,7 +258,7 @@ intel_check_word (int name, unsigned int value, bool *has_level_2,
446cf2
 static long int __attribute__ ((noinline))
446cf2
 handle_intel (int name, const struct cpu_features *cpu_features)
446cf2
 {
446cf2
-  unsigned int maxidx = cpu_features->max_cpuid;
446cf2
+  unsigned int maxidx = cpu_features->basic.max_cpuid;
446cf2
 
446cf2
   /* Return -1 for older CPUs.  */
446cf2
   if (maxidx < 2)
446cf2
@@ -443,10 +443,10 @@ __cache_sysconf (int name)
446cf2
 {
446cf2
   const struct cpu_features *cpu_features = __get_cpu_features ();
446cf2
 
446cf2
-  if (cpu_features->kind == arch_kind_intel)
446cf2
+  if (cpu_features->basic.kind == arch_kind_intel)
446cf2
     return handle_intel (name, cpu_features);
446cf2
 
446cf2
-  if (cpu_features->kind == arch_kind_amd)
446cf2
+  if (cpu_features->basic.kind == arch_kind_amd)
446cf2
     return handle_amd (name);
446cf2
 
446cf2
   // XXX Fill in more vendors.
446cf2
@@ -497,9 +497,9 @@ init_cacheinfo (void)
446cf2
   unsigned int level;
446cf2
   unsigned int threads = 0;
446cf2
   const struct cpu_features *cpu_features = __get_cpu_features ();
446cf2
-  int max_cpuid = cpu_features->max_cpuid;
446cf2
+  int max_cpuid = cpu_features->basic.max_cpuid;
446cf2
 
446cf2
-  if (cpu_features->kind == arch_kind_intel)
446cf2
+  if (cpu_features->basic.kind == arch_kind_intel)
446cf2
     {
446cf2
       data = handle_intel (_SC_LEVEL1_DCACHE_SIZE, cpu_features);
446cf2
 
446cf2
@@ -538,8 +538,8 @@ init_cacheinfo (void)
446cf2
 	     highest cache level.  */
446cf2
 	  if (max_cpuid >= 4)
446cf2
 	    {
446cf2
-	      unsigned int family = cpu_features->family;
446cf2
-	      unsigned int model = cpu_features->model;
446cf2
+	      unsigned int family = cpu_features->basic.family;
446cf2
+	      unsigned int model = cpu_features->basic.model;
446cf2
 
446cf2
 	      int i = 0;
446cf2
 
446cf2
@@ -700,7 +700,7 @@ intel_bug_no_cache_info:
446cf2
 	  shared += core;
446cf2
 	}
446cf2
     }
446cf2
-  else if (cpu_features->kind == arch_kind_amd)
446cf2
+  else if (cpu_features->basic.kind == arch_kind_amd)
446cf2
     {
446cf2
       data   = handle_amd (_SC_LEVEL1_DCACHE_SIZE);
446cf2
       long int core = handle_amd (_SC_LEVEL2_CACHE_SIZE);
446cf2
@@ -722,7 +722,7 @@ intel_bug_no_cache_info:
446cf2
 	      threads = 1 << ((ecx >> 12) & 0x0f);
446cf2
 	    }
446cf2
 
446cf2
-	  if (threads == 0 || cpu_features->family >= 0x17)
446cf2
+	  if (threads == 0 || cpu_features->basic.family >= 0x17)
446cf2
 	    {
446cf2
 	      /* If APIC ID width is not available, use logical
446cf2
 		 processor count.  */
446cf2
@@ -738,7 +738,7 @@ intel_bug_no_cache_info:
446cf2
 	    shared /= threads;
446cf2
 
446cf2
 	  /* Get shared cache per ccx for Zen architectures.  */
446cf2
-	  if (cpu_features->family >= 0x17)
446cf2
+	  if (cpu_features->basic.family >= 0x17)
446cf2
 	    {
446cf2
 	      unsigned int eax;
446cf2
 
446cf2
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
446cf2
index 3b268efbce627e6c..3a02a9c7d08f9603 100644
446cf2
--- a/sysdeps/x86/cpu-features.c
446cf2
+++ b/sysdeps/x86/cpu-features.c
446cf2
@@ -52,7 +52,18 @@ get_extended_indices (struct cpu_features *cpu_features)
446cf2
 	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
446cf2
 	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
446cf2
 	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
446cf2
-
446cf2
+  if (eax >= 0x80000007)
446cf2
+    __cpuid (0x80000007,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000007].eax,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000007].ebx,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000007].ecx,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000007].edx);
446cf2
+  if (eax >= 0x80000008)
446cf2
+    __cpuid (0x80000008,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000008].eax,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000008].ebx,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000008].ecx,
446cf2
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000008].edx);
446cf2
 }
446cf2
 
446cf2
 static void
446cf2
@@ -78,13 +89,20 @@ get_common_indices (struct cpu_features *cpu_features,
446cf2
 	}
446cf2
     }
446cf2
 
446cf2
-  if (cpu_features->max_cpuid >= 7)
446cf2
+  if (cpu_features->basic.max_cpuid >= 7)
446cf2
     __cpuid_count (7, 0,
446cf2
 		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].eax,
446cf2
 		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].ebx,
446cf2
 		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].ecx,
446cf2
 		   cpu_features->cpuid[COMMON_CPUID_INDEX_7].edx);
446cf2
 
446cf2
+  if (cpu_features->basic.max_cpuid >= 0xd)
446cf2
+    __cpuid_count (0xd, 1,
446cf2
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_D_ECX_1].eax,
446cf2
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_D_ECX_1].ebx,
446cf2
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_D_ECX_1].ecx,
446cf2
+		   cpu_features->cpuid[COMMON_CPUID_INDEX_D_ECX_1].edx);
446cf2
+
446cf2
   /* Can we call xgetbv?  */
446cf2
   if (CPU_FEATURES_CPU_P (cpu_features, OSXSAVE))
446cf2
     {
446cf2
@@ -116,6 +134,18 @@ get_common_indices (struct cpu_features *cpu_features,
446cf2
 	      if (CPU_FEATURES_CPU_P (cpu_features, FMA))
446cf2
 		cpu_features->feature[index_arch_FMA_Usable]
446cf2
 		  |= bit_arch_FMA_Usable;
446cf2
+	      /* Determine if VAES is usable.  */
446cf2
+	      if (CPU_FEATURES_CPU_P (cpu_features, VAES))
446cf2
+		cpu_features->feature[index_arch_VAES_Usable]
446cf2
+		  |= bit_arch_VAES_Usable;
446cf2
+	      /* Determine if VPCLMULQDQ is usable.  */
446cf2
+	      if (CPU_FEATURES_CPU_P (cpu_features, VPCLMULQDQ))
446cf2
+		cpu_features->feature[index_arch_VPCLMULQDQ_Usable]
446cf2
+		  |= bit_arch_VPCLMULQDQ_Usable;
446cf2
+	      /* Determine if XOP is usable.  */
446cf2
+	      if (CPU_FEATURES_CPU_P (cpu_features, XOP))
446cf2
+		cpu_features->feature[index_arch_XOP_Usable]
446cf2
+		  |= bit_arch_XOP_Usable;
446cf2
 	    }
446cf2
 
446cf2
 	  /* Check if OPMASK state, upper 256-bit of ZMM0-ZMM15 and
446cf2
@@ -129,17 +159,69 @@ get_common_indices (struct cpu_features *cpu_features,
446cf2
 		{
446cf2
 		  cpu_features->feature[index_arch_AVX512F_Usable]
446cf2
 		    |= bit_arch_AVX512F_Usable;
446cf2
+		  /* Determine if AVX512CD is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512CD))
446cf2
+		    cpu_features->feature[index_arch_AVX512CD_Usable]
446cf2
+		      |= bit_arch_AVX512CD_Usable;
446cf2
+		  /* Determine if AVX512ER is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512ER))
446cf2
+		    cpu_features->feature[index_arch_AVX512ER_Usable]
446cf2
+		      |= bit_arch_AVX512ER_Usable;
446cf2
+		  /* Determine if AVX512PF is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512PF))
446cf2
+		    cpu_features->feature[index_arch_AVX512PF_Usable]
446cf2
+		      |= bit_arch_AVX512PF_Usable;
446cf2
+		  /* Determine if AVX512VL is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512VL))
446cf2
+		    cpu_features->feature[index_arch_AVX512VL_Usable]
446cf2
+		      |= bit_arch_AVX512VL_Usable;
446cf2
 		  /* Determine if AVX512DQ is usable.  */
446cf2
 		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512DQ))
446cf2
 		    cpu_features->feature[index_arch_AVX512DQ_Usable]
446cf2
 		      |= bit_arch_AVX512DQ_Usable;
446cf2
+		  /* Determine if AVX512BW is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512BW))
446cf2
+		    cpu_features->feature[index_arch_AVX512BW_Usable]
446cf2
+		      |= bit_arch_AVX512BW_Usable;
446cf2
+		  /* Determine if AVX512_4FMAPS is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_4FMAPS))
446cf2
+		    cpu_features->feature[index_arch_AVX512_4FMAPS_Usable]
446cf2
+		      |= bit_arch_AVX512_4FMAPS_Usable;
446cf2
+		  /* Determine if AVX512_4VNNIW is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_4VNNIW))
446cf2
+		    cpu_features->feature[index_arch_AVX512_4VNNIW_Usable]
446cf2
+		      |= bit_arch_AVX512_4VNNIW_Usable;
446cf2
+		  /* Determine if AVX512_BITALG is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_BITALG))
446cf2
+		    cpu_features->feature[index_arch_AVX512_BITALG_Usable]
446cf2
+		      |= bit_arch_AVX512_BITALG_Usable;
446cf2
+		  /* Determine if AVX512_IFMA is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_IFMA))
446cf2
+		    cpu_features->feature[index_arch_AVX512_IFMA_Usable]
446cf2
+		      |= bit_arch_AVX512_IFMA_Usable;
446cf2
+		  /* Determine if AVX512_VBMI is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_VBMI))
446cf2
+		    cpu_features->feature[index_arch_AVX512_VBMI_Usable]
446cf2
+		      |= bit_arch_AVX512_VBMI_Usable;
446cf2
+		  /* Determine if AVX512_VBMI2 is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_VBMI2))
446cf2
+		    cpu_features->feature[index_arch_AVX512_VBMI2_Usable]
446cf2
+		      |= bit_arch_AVX512_VBMI2_Usable;
446cf2
+		  /* Determine if is AVX512_VNNI usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_VNNI))
446cf2
+		    cpu_features->feature[index_arch_AVX512_VNNI_Usable]
446cf2
+		      |= bit_arch_AVX512_VNNI_Usable;
446cf2
+		  /* Determine if AVX512_VPOPCNTDQ is usable.  */
446cf2
+		  if (CPU_FEATURES_CPU_P (cpu_features, AVX512_VPOPCNTDQ))
446cf2
+		    cpu_features->feature[index_arch_AVX512_VPOPCNTDQ_Usable]
446cf2
+		      |= bit_arch_AVX512_VPOPCNTDQ_Usable;
446cf2
 		}
446cf2
 	    }
446cf2
 	}
446cf2
 
446cf2
       /* For _dl_runtime_resolve, set xsave_state_size to xsave area
446cf2
 	 size + integer register save size and align it to 64 bytes.  */
446cf2
-      if (cpu_features->max_cpuid >= 0xd)
446cf2
+      if (cpu_features->basic.max_cpuid >= 0xd)
446cf2
 	{
446cf2
 	  unsigned int eax, ebx, ecx, edx;
446cf2
 
446cf2
@@ -154,10 +236,8 @@ get_common_indices (struct cpu_features *cpu_features,
446cf2
 	      cpu_features->xsave_state_full_size
446cf2
 		= xsave_state_full_size;
446cf2
 
446cf2
-	      __cpuid_count (0xd, 1, eax, ebx, ecx, edx);
446cf2
-
446cf2
 	      /* Check if XSAVEC is available.  */
446cf2
-	      if ((eax & (1 << 1)) != 0)
446cf2
+	      if (CPU_FEATURES_CPU_P (cpu_features, XSAVEC))
446cf2
 		{
446cf2
 		  unsigned int xstate_comp_offsets[32];
446cf2
 		  unsigned int xstate_comp_sizes[32];
446cf2
@@ -209,12 +289,25 @@ get_common_indices (struct cpu_features *cpu_features,
446cf2
     }
446cf2
 }
446cf2
 
446cf2
+_Static_assert (((index_arch_Fast_Unaligned_Load
446cf2
+		  == index_arch_Fast_Unaligned_Copy)
446cf2
+		 && (index_arch_Fast_Unaligned_Load
446cf2
+		     == index_arch_Prefer_PMINUB_for_stringop)
446cf2
+		 && (index_arch_Fast_Unaligned_Load
446cf2
+		     == index_arch_Slow_SSE4_2)
446cf2
+		 && (index_arch_Fast_Unaligned_Load
446cf2
+		     == index_arch_Fast_Rep_String)
446cf2
+		 && (index_arch_Fast_Unaligned_Load
446cf2
+		     == index_arch_Fast_Copy_Backward)),
446cf2
+		"Incorrect index_arch_Fast_Unaligned_Load");
446cf2
+
446cf2
 static inline void
446cf2
 init_cpu_features (struct cpu_features *cpu_features)
446cf2
 {
446cf2
   unsigned int ebx, ecx, edx;
446cf2
   unsigned int family = 0;
446cf2
   unsigned int model = 0;
446cf2
+  unsigned int stepping = 0;
446cf2
   enum cpu_features_kind kind;
446cf2
 
446cf2
 #if !HAS_CPUID
446cf2
@@ -225,12 +318,12 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
     }
446cf2
 #endif
446cf2
 
446cf2
-  __cpuid (0, cpu_features->max_cpuid, ebx, ecx, edx);
446cf2
+  __cpuid (0, cpu_features->basic.max_cpuid, ebx, ecx, edx);
446cf2
 
446cf2
   /* This spells out "GenuineIntel".  */
446cf2
   if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
446cf2
     {
446cf2
-      unsigned int extended_model, stepping;
446cf2
+      unsigned int extended_model;
446cf2
 
446cf2
       kind = arch_kind_intel;
446cf2
 
446cf2
@@ -269,15 +362,6 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
 	    case 0x5d:
446cf2
 	      /* Unaligned load versions are faster than SSSE3
446cf2
 		 on Silvermont.  */
446cf2
-#if index_arch_Fast_Unaligned_Load != index_arch_Prefer_PMINUB_for_stringop
446cf2
-# error index_arch_Fast_Unaligned_Load != index_arch_Prefer_PMINUB_for_stringop
446cf2
-#endif
446cf2
-#if index_arch_Fast_Unaligned_Load != index_arch_Slow_SSE4_2
446cf2
-# error index_arch_Fast_Unaligned_Load != index_arch_Slow_SSE4_2
446cf2
-#endif
446cf2
-#if index_arch_Fast_Unaligned_Load != index_arch_Fast_Unaligned_Copy
446cf2
-# error index_arch_Fast_Unaligned_Load != index_arch_Fast_Unaligned_Copy
446cf2
-#endif
446cf2
 	      cpu_features->feature[index_arch_Fast_Unaligned_Load]
446cf2
 		|= (bit_arch_Fast_Unaligned_Load
446cf2
 		    | bit_arch_Fast_Unaligned_Copy
446cf2
@@ -300,15 +384,6 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
 	    case 0x2f:
446cf2
 	      /* Rep string instructions, unaligned load, unaligned copy,
446cf2
 		 and pminub are fast on Intel Core i3, i5 and i7.  */
446cf2
-#if index_arch_Fast_Rep_String != index_arch_Fast_Unaligned_Load
446cf2
-# error index_arch_Fast_Rep_String != index_arch_Fast_Unaligned_Load
446cf2
-#endif
446cf2
-#if index_arch_Fast_Rep_String != index_arch_Prefer_PMINUB_for_stringop
446cf2
-# error index_arch_Fast_Rep_String != index_arch_Prefer_PMINUB_for_stringop
446cf2
-#endif
446cf2
-#if index_arch_Fast_Rep_String != index_arch_Fast_Unaligned_Copy
446cf2
-# error index_arch_Fast_Rep_String != index_arch_Fast_Unaligned_Copy
446cf2
-#endif
446cf2
 	      cpu_features->feature[index_arch_Fast_Rep_String]
446cf2
 		|= (bit_arch_Fast_Rep_String
446cf2
 		    | bit_arch_Fast_Unaligned_Load
446cf2
@@ -352,7 +427,7 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
   /* This spells out "AuthenticAMD".  */
446cf2
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
446cf2
     {
446cf2
-      unsigned int extended_model, stepping;
446cf2
+      unsigned int extended_model;
446cf2
 
446cf2
       kind = arch_kind_amd;
446cf2
 
446cf2
@@ -374,9 +449,6 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
 
446cf2
       if (family == 0x15)
446cf2
 	{
446cf2
-#if index_arch_Fast_Unaligned_Load != index_arch_Fast_Copy_Backward
446cf2
-# error index_arch_Fast_Unaligned_Load != index_arch_Fast_Copy_Backward
446cf2
-#endif
446cf2
 	  /* "Excavator"   */
446cf2
 	  if (model >= 0x60 && model <= 0x7f)
446cf2
 	  {
446cf2
@@ -408,9 +480,10 @@ init_cpu_features (struct cpu_features *cpu_features)
446cf2
 no_cpuid:
446cf2
 #endif
446cf2
 
446cf2
-  cpu_features->family = family;
446cf2
-  cpu_features->model = model;
446cf2
-  cpu_features->kind = kind;
446cf2
+  cpu_features->basic.kind = kind;
446cf2
+  cpu_features->basic.family = family;
446cf2
+  cpu_features->basic.model = model;
446cf2
+  cpu_features->basic.stepping = stepping;
446cf2
 
446cf2
 #if HAVE_TUNABLES
446cf2
   TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps));
446cf2
@@ -431,7 +504,7 @@ no_cpuid:
446cf2
 
446cf2
 #ifdef __x86_64__
446cf2
   GLRO(dl_hwcap) = HWCAP_X86_64;
446cf2
-  if (cpu_features->kind == arch_kind_intel)
446cf2
+  if (cpu_features->basic.kind == arch_kind_intel)
446cf2
     {
446cf2
       const char *platform = NULL;
446cf2
 
446cf2
diff --git a/sysdeps/x86/cpu-features.h b/sysdeps/x86/cpu-features.h
446cf2
index fb22d7b9d6226a92..4917182e99a8ee90 100644
446cf2
--- a/sysdeps/x86/cpu-features.h
446cf2
+++ b/sysdeps/x86/cpu-features.h
446cf2
@@ -18,108 +18,58 @@
446cf2
 #ifndef cpu_features_h
446cf2
 #define cpu_features_h
446cf2
 
446cf2
-#define bit_arch_Fast_Rep_String		(1 << 0)
446cf2
-#define bit_arch_Fast_Copy_Backward		(1 << 1)
446cf2
-#define bit_arch_Slow_BSF			(1 << 2)
446cf2
-#define bit_arch_Fast_Unaligned_Load		(1 << 4)
446cf2
-#define bit_arch_Prefer_PMINUB_for_stringop	(1 << 5)
446cf2
-#define bit_arch_AVX_Usable			(1 << 6)
446cf2
-#define bit_arch_FMA_Usable			(1 << 7)
446cf2
-#define bit_arch_FMA4_Usable			(1 << 8)
446cf2
-#define bit_arch_Slow_SSE4_2			(1 << 9)
446cf2
-#define bit_arch_AVX2_Usable			(1 << 10)
446cf2
-#define bit_arch_AVX_Fast_Unaligned_Load	(1 << 11)
446cf2
-#define bit_arch_AVX512F_Usable			(1 << 12)
446cf2
-#define bit_arch_AVX512DQ_Usable		(1 << 13)
446cf2
-#define bit_arch_I586				(1 << 14)
446cf2
-#define bit_arch_I686				(1 << 15)
446cf2
-#define bit_arch_Prefer_MAP_32BIT_EXEC		(1 << 16)
446cf2
-#define bit_arch_Prefer_No_VZEROUPPER		(1 << 17)
446cf2
-#define bit_arch_Fast_Unaligned_Copy		(1 << 18)
446cf2
-#define bit_arch_Prefer_ERMS			(1 << 19)
446cf2
-#define bit_arch_Prefer_No_AVX512		(1 << 20)
446cf2
-#define bit_arch_MathVec_Prefer_No_AVX512	(1 << 21)
446cf2
-#define bit_arch_XSAVEC_Usable			(1 << 22)
446cf2
-#define bit_arch_Prefer_FSRM			(1 << 23)
446cf2
-
446cf2
-/* CPUID Feature flags.  */
446cf2
-
446cf2
-/* COMMON_CPUID_INDEX_1.  */
446cf2
-#define bit_cpu_CX8		(1 << 8)
446cf2
-#define bit_cpu_CMOV		(1 << 15)
446cf2
-#define bit_cpu_SSE		(1 << 25)
446cf2
-#define bit_cpu_SSE2		(1 << 26)
446cf2
-#define bit_cpu_SSSE3		(1 << 9)
446cf2
-#define bit_cpu_SSE4_1		(1 << 19)
446cf2
-#define bit_cpu_SSE4_2		(1 << 20)
446cf2
-#define bit_cpu_OSXSAVE		(1 << 27)
446cf2
-#define bit_cpu_AVX		(1 << 28)
446cf2
-#define bit_cpu_POPCOUNT	(1 << 23)
446cf2
-#define bit_cpu_FMA		(1 << 12)
446cf2
-#define bit_cpu_FMA4		(1 << 16)
446cf2
-#define bit_cpu_HTT		(1 << 28)
446cf2
-#define bit_cpu_LZCNT		(1 << 5)
446cf2
-#define bit_cpu_MOVBE		(1 << 22)
446cf2
-#define bit_cpu_POPCNT		(1 << 23)
446cf2
-
446cf2
-/* COMMON_CPUID_INDEX_7.  */
446cf2
-#define bit_cpu_BMI1		(1 << 3)
446cf2
-#define bit_cpu_BMI2		(1 << 8)
446cf2
-#define bit_cpu_ERMS		(1 << 9)
446cf2
-#define bit_cpu_RTM		(1 << 11)
446cf2
-#define bit_cpu_AVX2		(1 << 5)
446cf2
-#define bit_cpu_AVX512F		(1 << 16)
446cf2
-#define bit_cpu_AVX512DQ	(1 << 17)
446cf2
-#define bit_cpu_AVX512PF	(1 << 26)
446cf2
-#define bit_cpu_AVX512ER	(1 << 27)
446cf2
-#define bit_cpu_AVX512CD	(1 << 28)
446cf2
-#define bit_cpu_AVX512BW	(1 << 30)
446cf2
-#define bit_cpu_AVX512VL	(1u << 31)
446cf2
-#define bit_cpu_IBT		(1u << 20)
446cf2
-#define bit_cpu_SHSTK		(1u << 7)
446cf2
-#define bit_cpu_FSRM		(1 << 4)
446cf2
-
446cf2
-/* XCR0 Feature flags.  */
446cf2
-#define bit_XMM_state		(1 << 1)
446cf2
-#define bit_YMM_state		(1 << 2)
446cf2
-#define bit_Opmask_state	(1 << 5)
446cf2
-#define bit_ZMM0_15_state	(1 << 6)
446cf2
-#define bit_ZMM16_31_state	(1 << 7)
446cf2
+enum
446cf2
+{
446cf2
+  /* The integer bit array index for the first set of internal feature
446cf2
+     bits.  */
446cf2
+  FEATURE_INDEX_1 = 0,
446cf2
+  FEATURE_INDEX_2,
446cf2
+  /* The current maximum size of the feature integer bit array.  */
446cf2
+  FEATURE_INDEX_MAX
446cf2
+};
446cf2
 
446cf2
-/* The integer bit array index for the first set of internal feature bits.  */
446cf2
-#define FEATURE_INDEX_1 0
446cf2
+enum
446cf2
+{
446cf2
+  COMMON_CPUID_INDEX_1 = 0,
446cf2
+  COMMON_CPUID_INDEX_7,
446cf2
+  COMMON_CPUID_INDEX_80000001,
446cf2
+  COMMON_CPUID_INDEX_D_ECX_1,
446cf2
+  COMMON_CPUID_INDEX_80000007,
446cf2
+  COMMON_CPUID_INDEX_80000008,
446cf2
+  /* Keep the following line at the end.  */
446cf2
+  COMMON_CPUID_INDEX_MAX
446cf2
+};
446cf2
 
446cf2
-/* The current maximum size of the feature integer bit array.  */
446cf2
-#define FEATURE_INDEX_MAX 1
446cf2
+struct cpuid_registers
446cf2
+{
446cf2
+  unsigned int eax;
446cf2
+  unsigned int ebx;
446cf2
+  unsigned int ecx;
446cf2
+  unsigned int edx;
446cf2
+};
446cf2
 
446cf2
-enum
446cf2
-  {
446cf2
-    COMMON_CPUID_INDEX_1 = 0,
446cf2
-    COMMON_CPUID_INDEX_7,
446cf2
-    COMMON_CPUID_INDEX_80000001,
446cf2
-    /* Keep the following line at the end.  */
446cf2
-    COMMON_CPUID_INDEX_MAX
446cf2
-  };
446cf2
+enum cpu_features_kind
446cf2
+{
446cf2
+  arch_kind_unknown = 0,
446cf2
+  arch_kind_intel,
446cf2
+  arch_kind_amd,
446cf2
+  arch_kind_other
446cf2
+};
446cf2
 
446cf2
-struct cpu_features
446cf2
+struct cpu_features_basic
446cf2
 {
446cf2
-  enum cpu_features_kind
446cf2
-    {
446cf2
-      arch_kind_unknown = 0,
446cf2
-      arch_kind_intel,
446cf2
-      arch_kind_amd,
446cf2
-      arch_kind_other
446cf2
-    } kind;
446cf2
+  enum cpu_features_kind kind;
446cf2
   int max_cpuid;
446cf2
-  struct cpuid_registers
446cf2
-  {
446cf2
-    unsigned int eax;
446cf2
-    unsigned int ebx;
446cf2
-    unsigned int ecx;
446cf2
-    unsigned int edx;
446cf2
-  } cpuid[COMMON_CPUID_INDEX_MAX];
446cf2
   unsigned int family;
446cf2
   unsigned int model;
446cf2
+  unsigned int stepping;
446cf2
+};
446cf2
+
446cf2
+struct cpu_features
446cf2
+{
446cf2
+  struct cpuid_registers cpuid[COMMON_CPUID_INDEX_MAX];
446cf2
+  unsigned int feature[FEATURE_INDEX_MAX];
446cf2
+  struct cpu_features_basic basic;
446cf2
   /* The state size for XSAVEC or XSAVE.  The type must be unsigned long
446cf2
      int so that we use
446cf2
 
446cf2
@@ -132,7 +82,6 @@ struct cpu_features
446cf2
      GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC_Usable
446cf2
    */
446cf2
   unsigned int xsave_state_full_size;
446cf2
-  unsigned int feature[FEATURE_INDEX_MAX];
446cf2
   /* Data cache size for use in memory and string routines, typically
446cf2
      L1 size.  */
446cf2
   unsigned long int data_cache_size;
446cf2
@@ -148,112 +97,838 @@ struct cpu_features
446cf2
 extern const struct cpu_features *__get_cpu_features (void)
446cf2
      __attribute__ ((const));
446cf2
 
446cf2
-# if defined (_LIBC) && !IS_IN (nonlib)
446cf2
-/* Unused for x86.  */
446cf2
-#  define INIT_ARCH()
446cf2
-#  define __get_cpu_features()	(&GLRO(dl_x86_cpu_features))
446cf2
-# endif
446cf2
-
446cf2
-
446cf2
 /* Only used directly in cpu-features.c.  */
446cf2
 # define CPU_FEATURES_CPU_P(ptr, name) \
446cf2
   ((ptr->cpuid[index_cpu_##name].reg_##name & (bit_cpu_##name)) != 0)
446cf2
 # define CPU_FEATURES_ARCH_P(ptr, name) \
446cf2
   ((ptr->feature[index_arch_##name] & (bit_arch_##name)) != 0)
446cf2
 
446cf2
-/* HAS_* evaluates to true if we may use the feature at runtime.  */
446cf2
-# define HAS_CPU_FEATURE(name) \
446cf2
-   CPU_FEATURES_CPU_P (__get_cpu_features (), name)
446cf2
+/* HAS_CPU_FEATURE evaluates to true if CPU supports the feature.  */
446cf2
+#define HAS_CPU_FEATURE(name) \
446cf2
+  CPU_FEATURES_CPU_P (__get_cpu_features (), name)
446cf2
+/* HAS_ARCH_FEATURE evaluates to true if we may use the feature at
446cf2
+   runtime.  */
446cf2
 # define HAS_ARCH_FEATURE(name) \
446cf2
-   CPU_FEATURES_ARCH_P (__get_cpu_features (), name)
446cf2
-
446cf2
-# define index_cpu_CX8		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_CMOV		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_SSE		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_SSE2		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_SSSE3	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_SSE4_1	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_SSE4_2	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_AVX		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_AVX2		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512F	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512DQ	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512PF	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512ER	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512CD	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512BW	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_AVX512VL	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_ERMS		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_RTM		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_FMA		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_FMA4		COMMON_CPUID_INDEX_80000001
446cf2
-# define index_cpu_POPCOUNT	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_OSXSAVE	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_HTT		COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_BMI1		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_BMI2		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_LZCNT	COMMON_CPUID_INDEX_80000001
446cf2
-# define index_cpu_MOVBE	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_POPCNT	COMMON_CPUID_INDEX_1
446cf2
-# define index_cpu_IBT		COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_SHSTK	COMMON_CPUID_INDEX_7
446cf2
-# define index_cpu_FSRM		COMMON_CPUID_INDEX_7
446cf2
-
446cf2
-# define reg_CX8		edx
446cf2
-# define reg_CMOV		edx
446cf2
-# define reg_SSE		edx
446cf2
-# define reg_SSE2		edx
446cf2
-# define reg_SSSE3		ecx
446cf2
-# define reg_SSE4_1		ecx
446cf2
-# define reg_SSE4_2		ecx
446cf2
-# define reg_AVX		ecx
446cf2
-# define reg_AVX2		ebx
446cf2
-# define reg_AVX512F		ebx
446cf2
-# define reg_AVX512DQ		ebx
446cf2
-# define reg_AVX512PF		ebx
446cf2
-# define reg_AVX512ER		ebx
446cf2
-# define reg_AVX512CD		ebx
446cf2
-# define reg_AVX512BW		ebx
446cf2
-# define reg_AVX512VL		ebx
446cf2
-# define reg_ERMS		ebx
446cf2
-# define reg_RTM		ebx
446cf2
-# define reg_FMA		ecx
446cf2
-# define reg_FMA4		ecx
446cf2
-# define reg_POPCOUNT		ecx
446cf2
-# define reg_OSXSAVE		ecx
446cf2
-# define reg_HTT		edx
446cf2
-# define reg_BMI1		ebx
446cf2
-# define reg_BMI2		ebx
446cf2
-# define reg_LZCNT		ecx
446cf2
-# define reg_MOVBE		ecx
446cf2
-# define reg_POPCNT		ecx
446cf2
-# define reg_IBT		edx
446cf2
-# define reg_SHSTK		ecx
446cf2
-# define reg_FSRM		edx
446cf2
-
446cf2
-# define index_arch_Fast_Rep_String	FEATURE_INDEX_1
446cf2
-# define index_arch_Fast_Copy_Backward	FEATURE_INDEX_1
446cf2
-# define index_arch_Slow_BSF		FEATURE_INDEX_1
446cf2
-# define index_arch_Fast_Unaligned_Load	FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_PMINUB_for_stringop FEATURE_INDEX_1
446cf2
-# define index_arch_AVX_Usable		FEATURE_INDEX_1
446cf2
-# define index_arch_FMA_Usable		FEATURE_INDEX_1
446cf2
-# define index_arch_FMA4_Usable		FEATURE_INDEX_1
446cf2
-# define index_arch_Slow_SSE4_2		FEATURE_INDEX_1
446cf2
-# define index_arch_AVX2_Usable		FEATURE_INDEX_1
446cf2
-# define index_arch_AVX_Fast_Unaligned_Load FEATURE_INDEX_1
446cf2
-# define index_arch_AVX512F_Usable	FEATURE_INDEX_1
446cf2
-# define index_arch_AVX512DQ_Usable	FEATURE_INDEX_1
446cf2
-# define index_arch_I586		FEATURE_INDEX_1
446cf2
-# define index_arch_I686		FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_MAP_32BIT_EXEC FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_No_VZEROUPPER FEATURE_INDEX_1
446cf2
-# define index_arch_Fast_Unaligned_Copy	FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_ERMS		FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_No_AVX512	FEATURE_INDEX_1
446cf2
-# define index_arch_MathVec_Prefer_No_AVX512 FEATURE_INDEX_1
446cf2
-# define index_arch_XSAVEC_Usable	FEATURE_INDEX_1
446cf2
-# define index_arch_Prefer_FSRM		FEATURE_INDEX_1
446cf2
+  CPU_FEATURES_ARCH_P (__get_cpu_features (), name)
446cf2
+/* CPU_FEATURE_USABLE evaluates to true if the feature is usable.  */
446cf2
+#define CPU_FEATURE_USABLE(name)				\
446cf2
+  ((need_arch_feature_##name && HAS_ARCH_FEATURE (name##_Usable))	\
446cf2
+   || (!need_arch_feature_##name && HAS_CPU_FEATURE(name)))
446cf2
+
446cf2
+/* Architecture features.  */
446cf2
+
446cf2
+/* FEATURE_INDEX_1.  */
446cf2
+#define bit_arch_AVX_Usable			(1u << 0)
446cf2
+#define bit_arch_AVX2_Usable			(1u << 1)
446cf2
+#define bit_arch_AVX512F_Usable			(1u << 2)
446cf2
+#define bit_arch_AVX512CD_Usable		(1u << 3)
446cf2
+#define bit_arch_AVX512ER_Usable		(1u << 4)
446cf2
+#define bit_arch_AVX512PF_Usable		(1u << 5)
446cf2
+#define bit_arch_AVX512VL_Usable		(1u << 6)
446cf2
+#define bit_arch_AVX512DQ_Usable		(1u << 7)
446cf2
+#define bit_arch_AVX512BW_Usable		(1u << 8)
446cf2
+#define bit_arch_AVX512_4FMAPS_Usable		(1u << 9)
446cf2
+#define bit_arch_AVX512_4VNNIW_Usable		(1u << 10)
446cf2
+#define bit_arch_AVX512_BITALG_Usable		(1u << 11)
446cf2
+#define bit_arch_AVX512_IFMA_Usable		(1u << 12)
446cf2
+#define bit_arch_AVX512_VBMI_Usable		(1u << 13)
446cf2
+#define bit_arch_AVX512_VBMI2_Usable		(1u << 14)
446cf2
+#define bit_arch_AVX512_VNNI_Usable		(1u << 15)
446cf2
+#define bit_arch_AVX512_VPOPCNTDQ_Usable	(1u << 16)
446cf2
+#define bit_arch_FMA_Usable			(1u << 17)
446cf2
+#define bit_arch_FMA4_Usable			(1u << 18)
446cf2
+#define bit_arch_VAES_Usable			(1u << 19)
446cf2
+#define bit_arch_VPCLMULQDQ_Usable		(1u << 20)
446cf2
+#define bit_arch_XOP_Usable			(1u << 21)
446cf2
+#define bit_arch_XSAVEC_Usable			(1u << 22)
446cf2
+
446cf2
+#define index_arch_AVX_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_AVX2_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512F_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512CD_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512ER_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512PF_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512VL_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512BW_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512DQ_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_4FMAPS_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_4VNNIW_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_BITALG_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_IFMA_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_VBMI_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_VBMI2_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_VNNI_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AVX512_VPOPCNTDQ_Usable	FEATURE_INDEX_1
446cf2
+#define index_arch_FMA_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_FMA4_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_VAES_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_VPCLMULQDQ_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_XOP_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_XSAVEC_Usable		FEATURE_INDEX_1
446cf2
+
446cf2
+/* Unused.  Compiler will optimize them out.  */
446cf2
+#define bit_arch_SSE3_Usable			(1u << 0)
446cf2
+#define bit_arch_PCLMULQDQ_Usable		(1u << 0)
446cf2
+#define bit_arch_SSSE3_Usable			(1u << 0)
446cf2
+#define bit_arch_CMPXCHG16B_Usable		(1u << 0)
446cf2
+#define bit_arch_SSE4_1_Usable			(1u << 0)
446cf2
+#define bit_arch_SSE4_2_Usable			(1u << 0)
446cf2
+#define bit_arch_MOVBE_Usable			(1u << 0)
446cf2
+#define bit_arch_POPCNT_Usable			(1u << 0)
446cf2
+#define bit_arch_AES_Usable			(1u << 0)
446cf2
+#define bit_arch_XSAVE_Usable			(1u << 0)
446cf2
+#define bit_arch_OSXSAVE_Usable			(1u << 0)
446cf2
+#define bit_arch_F16C_Usable			(1u << 0)
446cf2
+#define bit_arch_RDRAND_Usable			(1u << 0)
446cf2
+#define bit_arch_FPU_Usable			(1u << 0)
446cf2
+#define bit_arch_TSC_Usable			(1u << 0)
446cf2
+#define bit_arch_MSR_Usable			(1u << 0)
446cf2
+#define bit_arch_CX8_Usable			(1u << 0)
446cf2
+#define bit_arch_SEP_Usable			(1u << 0)
446cf2
+#define bit_arch_CMOV_Usable			(1u << 0)
446cf2
+#define bit_arch_CLFSH_Usable			(1u << 0)
446cf2
+#define bit_arch_MMX_Usable			(1u << 0)
446cf2
+#define bit_arch_FXSR_Usable			(1u << 0)
446cf2
+#define bit_arch_SSE_Usable			(1u << 0)
446cf2
+#define bit_arch_SSE2_Usable			(1u << 0)
446cf2
+#define bit_arch_FSGSBASE_Usable		(1u << 0)
446cf2
+#define bit_arch_BMI1_Usable			(1u << 0)
446cf2
+#define bit_arch_HLE_Usable			(1u << 0)
446cf2
+#define bit_arch_BMI2_Usable			(1u << 0)
446cf2
+#define bit_arch_ERMS_Usable			(1u << 0)
446cf2
+#define bit_arch_RTM_Usable			(1u << 0)
446cf2
+#define bit_arch_RDSEED_Usable			(1u << 0)
446cf2
+#define bit_arch_ADX_Usable			(1u << 0)
446cf2
+#define bit_arch_CLFLUSHOPT_Usable		(1u << 0)
446cf2
+#define bit_arch_CLWB_Usable			(1u << 0)
446cf2
+#define bit_arch_SHA_Usable			(1u << 0)
446cf2
+#define bit_arch_PREFETCHWT1_Usable		(1u << 0)
446cf2
+#define bit_arch_GFNI_Usable			(1u << 0)
446cf2
+#define bit_arch_RDPID_Usable			(1u << 0)
446cf2
+#define bit_arch_CLDEMOTE_Usable		(1u << 0)
446cf2
+#define bit_arch_MOVDIRI_Usable			(1u << 0)
446cf2
+#define bit_arch_MOVDIR64B_Usable		(1u << 0)
446cf2
+#define bit_arch_FSRM_Usable			(1u << 0)
446cf2
+#define bit_arch_LAHF64_SAHF64_Usable		(1u << 0)
446cf2
+#define bit_arch_SVM_Usable			(1u << 0)
446cf2
+#define bit_arch_LZCNT_Usable			(1u << 0)
446cf2
+#define bit_arch_SSE4A_Usable			(1u << 0)
446cf2
+#define bit_arch_PREFETCHW_Usable		(1u << 0)
446cf2
+#define bit_arch_TBM_Usable			(1u << 0)
446cf2
+#define bit_arch_SYSCALL_SYSRET_Usable		(1u << 0)
446cf2
+#define bit_arch_RDTSCP_Usable			(1u << 0)
446cf2
+#define bit_arch_XSAVEOPT_Usable		(1u << 0)
446cf2
+#define bit_arch_XGETBV_ECX_1_Usable		(1u << 0)
446cf2
+#define bit_arch_XSAVES_Usable			(1u << 0)
446cf2
+#define bit_arch_INVARIANT_TSC_Usable		(1u << 0)
446cf2
+#define bit_arch_WBNOINVD_Usable		(1u << 0)
446cf2
+
446cf2
+/* Unused.  Compiler will optimize them out.  */
446cf2
+#define index_arch_SSE3_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_PCLMULQDQ_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_SSSE3_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CMPXCHG16B_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_SSE4_1_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_SSE4_2_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_MOVBE_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_POPCNT_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_AES_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_XSAVE_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_OSXSAVE_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_F16C_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_RDRAND_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_FPU_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_TSC_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_MSR_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CX8_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SEP_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CMOV_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CLFSH_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_MMX_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_FXSR_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SSE_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SSE2_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_FSGSBASE_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_BMI1_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_HLE_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_BMI2_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_ERMS_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_RTM_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_RDSEED_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_ADX_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CLFLUSHOPT_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_CLWB_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SHA_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_PREFETCHWT1_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_GFNI_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_RDPID_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_CLDEMOTE_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_MOVDIRI_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_MOVDIR64B_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_FSRM_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_LAHF64_SAHF64_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_LZCNT_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SSE4A_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_PREFETCHW_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_TBM_Usable			FEATURE_INDEX_1
446cf2
+#define index_arch_SYSCALL_SYSRET_Usable	FEATURE_INDEX_1
446cf2
+#define index_arch_RDTSCP_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_XSAVEOPT_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_XGETBV_ECX_1_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_XSAVES_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_INVARIANT_TSC_Usable		FEATURE_INDEX_1
446cf2
+#define index_arch_WBNOINVD_Usable		FEATURE_INDEX_1
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_1.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define	need_arch_feature_SSE3			0
446cf2
+#define	need_arch_feature_PCLMULQDQ		0
446cf2
+#define need_arch_feature_SSSE3			0
446cf2
+#define need_arch_feature_FMA			1
446cf2
+#define need_arch_feature_CMPXCHG16B		0
446cf2
+#define need_arch_feature_SSE4_1		0
446cf2
+#define need_arch_feature_SSE4_2		0
446cf2
+#define need_arch_feature_MOVBE			0
446cf2
+#define need_arch_feature_POPCNT		0
446cf2
+#define need_arch_feature_AES			0
446cf2
+#define need_arch_feature_XSAVE			0
446cf2
+#define need_arch_feature_OSXSAVE		0
446cf2
+#define need_arch_feature_AVX			1
446cf2
+#define need_arch_feature_F16C			0
446cf2
+#define need_arch_feature_RDRAND		0
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define need_arch_feature_FPU			0
446cf2
+#define need_arch_feature_TSC			0
446cf2
+#define need_arch_feature_MSR			0
446cf2
+#define need_arch_feature_CX8			0
446cf2
+#define need_arch_feature_SEP			0
446cf2
+#define need_arch_feature_CMOV			0
446cf2
+#define need_arch_feature_CLFSH			0
446cf2
+#define need_arch_feature_MMX			0
446cf2
+#define need_arch_feature_FXSR			0
446cf2
+#define need_arch_feature_SSE			0
446cf2
+#define need_arch_feature_SSE2			0
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_7.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define need_arch_feature_FSGSBASE		0
446cf2
+#define need_arch_feature_BMI1			0
446cf2
+#define need_arch_feature_HLE			0
446cf2
+#define need_arch_feature_AVX2			1
446cf2
+#define need_arch_feature_BMI2			0
446cf2
+#define need_arch_feature_ERMS			0
446cf2
+#define need_arch_feature_RTM			0
446cf2
+#define need_arch_feature_AVX512F		1
446cf2
+#define need_arch_feature_AVX512DQ		1
446cf2
+#define need_arch_feature_RDSEED		0
446cf2
+#define need_arch_feature_ADX			0
446cf2
+#define need_arch_feature_AVX512_IFMA		1
446cf2
+#define need_arch_feature_CLFLUSHOPT		0
446cf2
+#define need_arch_feature_CLWB			0
446cf2
+#define need_arch_feature_AVX512PF		1
446cf2
+#define need_arch_feature_AVX512ER		1
446cf2
+#define need_arch_feature_AVX512CD		1
446cf2
+#define need_arch_feature_SHA			0
446cf2
+#define need_arch_feature_AVX512BW		1
446cf2
+#define need_arch_feature_AVX512VL		1
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define need_arch_feature_PREFETCHWT1		0
446cf2
+#define need_arch_feature_AVX512_VBMI		1
446cf2
+#define need_arch_feature_AVX512_VBMI2		1
446cf2
+#define need_arch_feature_GFNI			0
446cf2
+#define need_arch_feature_VAES			1
446cf2
+#define need_arch_feature_VPCLMULQDQ		1
446cf2
+#define need_arch_feature_AVX512_VNNI		1
446cf2
+#define need_arch_feature_AVX512_BITALG		1
446cf2
+#define need_arch_feature_AVX512_VPOPCNTDQ	1
446cf2
+#define need_arch_feature_RDPID			0
446cf2
+#define need_arch_feature_CLDEMOTE		0
446cf2
+#define need_arch_feature_MOVDIRI		0
446cf2
+#define need_arch_feature_MOVDIR64B		0
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define need_arch_feature_AVX512_4VNNIW		1
446cf2
+#define need_arch_feature_AVX512_4FMAPS		1
446cf2
+#define need_arch_feature_FSRM			0
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000001.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define need_arch_feature_LAHF64_SAHF64		0
446cf2
+#define need_arch_feature_LZCNT			0
446cf2
+#define need_arch_feature_SSE4A			0
446cf2
+#define need_arch_feature_PREFETCHW		0
446cf2
+#define need_arch_feature_XOP			1
446cf2
+#define need_arch_feature_FMA4			1
446cf2
+#define need_arch_feature_TBM			0
446cf2
+#define need_arch_feature_SYSCALL_SYSRET	0
446cf2
+#define need_arch_feature_RDTSCP		0
446cf2
+#define need_arch_feature_XSAVEOPT		0
446cf2
+#define need_arch_feature_XSAVEC		1
446cf2
+#define need_arch_feature_XGETBV_ECX_1		0
446cf2
+#define need_arch_feature_XSAVES		0
446cf2
+#define need_arch_feature_INVARIANT_TSC		0
446cf2
+#define need_arch_feature_WBNOINVD		0
446cf2
+
446cf2
+/* CPU features.  */
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_1.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define bit_cpu_SSE3		(1u << 0)
446cf2
+#define bit_cpu_PCLMULQDQ	(1u << 1)
446cf2
+#define bit_cpu_DTES64		(1u << 2)
446cf2
+#define bit_cpu_MONITOR		(1u << 3)
446cf2
+#define bit_cpu_DS_CPL		(1u << 4)
446cf2
+#define bit_cpu_VMX		(1u << 5)
446cf2
+#define bit_cpu_SMX		(1u << 6)
446cf2
+#define bit_cpu_EST		(1u << 7)
446cf2
+#define bit_cpu_TM2		(1u << 8)
446cf2
+#define bit_cpu_SSSE3		(1u << 9)
446cf2
+#define bit_cpu_CNXT_ID		(1u << 10)
446cf2
+#define bit_cpu_SDBG		(1u << 11)
446cf2
+#define bit_cpu_FMA		(1u << 12)
446cf2
+#define bit_cpu_CMPXCHG16B	(1u << 13)
446cf2
+#define bit_cpu_XTPRUPDCTRL	(1u << 14)
446cf2
+#define bit_cpu_PDCM		(1u << 15)
446cf2
+#define bit_cpu_PCID		(1u << 17)
446cf2
+#define bit_cpu_DCA		(1u << 18)
446cf2
+#define bit_cpu_SSE4_1		(1u << 19)
446cf2
+#define bit_cpu_SSE4_2		(1u << 20)
446cf2
+#define bit_cpu_X2APIC		(1u << 21)
446cf2
+#define bit_cpu_MOVBE		(1u << 22)
446cf2
+#define bit_cpu_POPCNT		(1u << 23)
446cf2
+#define bit_cpu_TSC_DEADLINE	(1u << 24)
446cf2
+#define bit_cpu_AES		(1u << 25)
446cf2
+#define bit_cpu_XSAVE		(1u << 26)
446cf2
+#define bit_cpu_OSXSAVE		(1u << 27)
446cf2
+#define bit_cpu_AVX		(1u << 28)
446cf2
+#define bit_cpu_F16C		(1u << 29)
446cf2
+#define bit_cpu_RDRAND		(1u << 30)
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define bit_cpu_FPU		(1u << 0)
446cf2
+#define bit_cpu_VME		(1u << 1)
446cf2
+#define bit_cpu_DE		(1u << 2)
446cf2
+#define bit_cpu_PSE		(1u << 3)
446cf2
+#define bit_cpu_TSC		(1u << 4)
446cf2
+#define bit_cpu_MSR		(1u << 5)
446cf2
+#define bit_cpu_PAE		(1u << 6)
446cf2
+#define bit_cpu_MCE		(1u << 7)
446cf2
+#define bit_cpu_CX8		(1u << 8)
446cf2
+#define bit_cpu_APIC		(1u << 9)
446cf2
+#define bit_cpu_SEP		(1u << 11)
446cf2
+#define bit_cpu_MTRR		(1u << 12)
446cf2
+#define bit_cpu_PGE		(1u << 13)
446cf2
+#define bit_cpu_MCA		(1u << 14)
446cf2
+#define bit_cpu_CMOV		(1u << 15)
446cf2
+#define bit_cpu_PAT		(1u << 16)
446cf2
+#define bit_cpu_PSE_36		(1u << 17)
446cf2
+#define bit_cpu_PSN		(1u << 18)
446cf2
+#define bit_cpu_CLFSH		(1u << 20)
446cf2
+#define bit_cpu_DS		(1u << 21)
446cf2
+#define bit_cpu_ACPI		(1u << 22)
446cf2
+#define bit_cpu_MMX		(1u << 23)
446cf2
+#define bit_cpu_FXSR		(1u << 24)
446cf2
+#define bit_cpu_SSE		(1u << 25)
446cf2
+#define bit_cpu_SSE2		(1u << 26)
446cf2
+#define bit_cpu_SS		(1u << 27)
446cf2
+#define bit_cpu_HTT		(1u << 28)
446cf2
+#define bit_cpu_TM		(1u << 29)
446cf2
+#define bit_cpu_PBE		(1u << 31)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_7.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define bit_cpu_FSGSBASE	(1u << 0)
446cf2
+#define bit_cpu_TSC_ADJUST	(1u << 1)
446cf2
+#define bit_cpu_SGX		(1u << 2)
446cf2
+#define bit_cpu_BMI1		(1u << 3)
446cf2
+#define bit_cpu_HLE		(1u << 4)
446cf2
+#define bit_cpu_AVX2		(1u << 5)
446cf2
+#define bit_cpu_SMEP		(1u << 7)
446cf2
+#define bit_cpu_BMI2		(1u << 8)
446cf2
+#define bit_cpu_ERMS		(1u << 9)
446cf2
+#define bit_cpu_INVPCID		(1u << 10)
446cf2
+#define bit_cpu_RTM		(1u << 11)
446cf2
+#define bit_cpu_PQM		(1u << 12)
446cf2
+#define bit_cpu_MPX		(1u << 14)
446cf2
+#define bit_cpu_PQE		(1u << 15)
446cf2
+#define bit_cpu_AVX512F		(1u << 16)
446cf2
+#define bit_cpu_AVX512DQ	(1u << 17)
446cf2
+#define bit_cpu_RDSEED		(1u << 18)
446cf2
+#define bit_cpu_ADX		(1u << 19)
446cf2
+#define bit_cpu_SMAP		(1u << 20)
446cf2
+#define bit_cpu_AVX512_IFMA	(1u << 21)
446cf2
+#define bit_cpu_CLFLUSHOPT	(1u << 22)
446cf2
+#define bit_cpu_CLWB		(1u << 24)
446cf2
+#define bit_cpu_TRACE		(1u << 25)
446cf2
+#define bit_cpu_AVX512PF	(1u << 26)
446cf2
+#define bit_cpu_AVX512ER	(1u << 27)
446cf2
+#define bit_cpu_AVX512CD	(1u << 28)
446cf2
+#define bit_cpu_SHA		(1u << 29)
446cf2
+#define bit_cpu_AVX512BW	(1u << 30)
446cf2
+#define bit_cpu_AVX512VL	(1u << 31)
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define bit_cpu_PREFETCHWT1	(1u << 0)
446cf2
+#define bit_cpu_AVX512_VBMI	(1u << 1)
446cf2
+#define bit_cpu_UMIP		(1u << 2)
446cf2
+#define bit_cpu_PKU		(1u << 3)
446cf2
+#define bit_cpu_OSPKE		(1u << 4)
446cf2
+#define bit_cpu_WAITPKG		(1u << 5)
446cf2
+#define bit_cpu_AVX512_VBMI2	(1u << 6)
446cf2
+#define bit_cpu_SHSTK		(1u << 7)
446cf2
+#define bit_cpu_GFNI		(1u << 8)
446cf2
+#define bit_cpu_VAES		(1u << 9)
446cf2
+#define bit_cpu_VPCLMULQDQ	(1u << 10)
446cf2
+#define bit_cpu_AVX512_VNNI	(1u << 11)
446cf2
+#define bit_cpu_AVX512_BITALG	(1u << 12)
446cf2
+#define bit_cpu_AVX512_VPOPCNTDQ (1u << 14)
446cf2
+#define bit_cpu_RDPID		(1u << 22)
446cf2
+#define bit_cpu_CLDEMOTE	(1u << 25)
446cf2
+#define bit_cpu_MOVDIRI		(1u << 27)
446cf2
+#define bit_cpu_MOVDIR64B	(1u << 28)
446cf2
+#define bit_cpu_SGX_LC		(1u << 30)
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define bit_cpu_AVX512_4VNNIW	(1u << 2)
446cf2
+#define bit_cpu_AVX512_4FMAPS	(1u << 3)
446cf2
+#define bit_cpu_FSRM		(1u << 4)
446cf2
+#define bit_cpu_PCONFIG		(1u << 18)
446cf2
+#define bit_cpu_IBT		(1u << 20)
446cf2
+#define bit_cpu_IBRS_IBPB	(1u << 26)
446cf2
+#define bit_cpu_STIBP		(1u << 27)
446cf2
+#define bit_cpu_CAPABILITIES	(1u << 29)
446cf2
+#define bit_cpu_SSBD		(1u << 31)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000001.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define bit_cpu_LAHF64_SAHF64	(1u << 0)
446cf2
+#define bit_cpu_SVM		(1u << 2)
446cf2
+#define bit_cpu_LZCNT		(1u << 5)
446cf2
+#define bit_cpu_SSE4A		(1u << 6)
446cf2
+#define bit_cpu_PREFETCHW	(1u << 8)
446cf2
+#define bit_cpu_XOP		(1u << 11)
446cf2
+#define bit_cpu_LWP		(1u << 15)
446cf2
+#define bit_cpu_FMA4		(1u << 16)
446cf2
+#define bit_cpu_TBM		(1u << 21)
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define bit_cpu_SYSCALL_SYSRET	(1u << 11)
446cf2
+#define bit_cpu_NX		(1u << 20)
446cf2
+#define bit_cpu_PAGE1GB		(1u << 26)
446cf2
+#define bit_cpu_RDTSCP		(1u << 27)
446cf2
+#define bit_cpu_LM		(1u << 29)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_D_ECX_1.  */
446cf2
+
446cf2
+/* EAX.  */
446cf2
+#define bit_cpu_XSAVEOPT	(1u << 0)
446cf2
+#define bit_cpu_XSAVEC		(1u << 1)
446cf2
+#define bit_cpu_XGETBV_ECX_1	(1u << 2)
446cf2
+#define bit_cpu_XSAVES		(1u << 3)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000007.  */
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define bit_cpu_INVARIANT_TSC	(1u << 8)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000008.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define bit_cpu_WBNOINVD	(1u << 9)
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_1.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define index_cpu_SSE3		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PCLMULQDQ	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_DTES64	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MONITOR	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_DS_CPL	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_VMX		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SMX		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_EST		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_TM2		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SSSE3		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_CNXT_ID	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SDBG		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_FMA		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_CMPXCHG16B	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_XTPRUPDCTRL	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PDCM		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PCID		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_DCA		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SSE4_1	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SSE4_2	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_X2APIC	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MOVBE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_POPCNT	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_TSC_DEADLINE	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_AES		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_XSAVE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_OSXSAVE	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_AVX		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_F16C		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_RDRAND	COMMON_CPUID_INDEX_1
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define index_cpu_FPU		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_VME		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_DE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PSE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_TSC		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MSR		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PAE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MCE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_CX8		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_APIC		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SEP		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MTRR		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PGE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MCA		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_CMOV		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PAT		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PSE_36	COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PSN		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_CLFSH		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_DS		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_ACPI		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_MMX		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_FXSR		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SSE		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SSE2		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_SS		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_HTT		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_TM		COMMON_CPUID_INDEX_1
446cf2
+#define index_cpu_PBE		COMMON_CPUID_INDEX_1
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_7.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define index_cpu_FSGSBASE	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_TSC_ADJUST	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SGX		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_BMI1		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_HLE		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX2		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SMEP		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_BMI2		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_ERMS		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_INVPCID	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_RTM		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_PQM		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_MPX		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_PQE		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512F	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512DQ	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_RDSEED	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_ADX		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SMAP		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_IFMA	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_CLFLUSHOPT	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_CLWB		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_TRACE		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512PF	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512ER	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512CD	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SHA		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512BW	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512VL	COMMON_CPUID_INDEX_7
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define index_cpu_PREFETCHWT1	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_VBMI	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_UMIP		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_PKU		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_OSPKE		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_WAITPKG	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_VBMI2	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SHSTK		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_GFNI		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_VAES		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_VPCLMULQDQ	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_VNNI	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_BITALG COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_VPOPCNTDQ COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_RDPID		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_CLDEMOTE	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_MOVDIRI	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_MOVDIR64B	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SGX_LC	COMMON_CPUID_INDEX_7
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define index_cpu_AVX512_4VNNIW COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_AVX512_4FMAPS	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_FSRM		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_PCONFIG	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_IBT		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_IBRS_IBPB	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_STIBP		COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_CAPABILITIES	COMMON_CPUID_INDEX_7
446cf2
+#define index_cpu_SSBD		COMMON_CPUID_INDEX_7
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000001.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define index_cpu_LAHF64_SAHF64 COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_SVM		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_LZCNT		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_SSE4A		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_PREFETCHW	COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_XOP		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_LWP		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_FMA4		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_TBM		COMMON_CPUID_INDEX_80000001
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define index_cpu_SYSCALL_SYSRET COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_NX		COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_PAGE1GB	COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_RDTSCP	COMMON_CPUID_INDEX_80000001
446cf2
+#define index_cpu_LM		COMMON_CPUID_INDEX_80000001
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_D_ECX_1.  */
446cf2
+
446cf2
+/* EAX.  */
446cf2
+#define index_cpu_XSAVEOPT	COMMON_CPUID_INDEX_D_ECX_1
446cf2
+#define index_cpu_XSAVEC	COMMON_CPUID_INDEX_D_ECX_1
446cf2
+#define index_cpu_XGETBV_ECX_1	COMMON_CPUID_INDEX_D_ECX_1
446cf2
+#define index_cpu_XSAVES	COMMON_CPUID_INDEX_D_ECX_1
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000007.  */
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define index_cpu_INVARIANT_TSC	COMMON_CPUID_INDEX_80000007
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000008.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define index_cpu_WBNOINVD	COMMON_CPUID_INDEX_80000008
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_1.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define reg_SSE3		ecx
446cf2
+#define reg_PCLMULQDQ		ecx
446cf2
+#define reg_DTES64		ecx
446cf2
+#define reg_MONITOR		ecx
446cf2
+#define reg_DS_CPL		ecx
446cf2
+#define reg_VMX			ecx
446cf2
+#define reg_SMX			ecx
446cf2
+#define reg_EST			ecx
446cf2
+#define reg_TM2			ecx
446cf2
+#define reg_SSSE3		ecx
446cf2
+#define reg_CNXT_ID		ecx
446cf2
+#define reg_SDBG		ecx
446cf2
+#define reg_FMA			ecx
446cf2
+#define reg_CMPXCHG16B		ecx
446cf2
+#define reg_XTPRUPDCTRL		ecx
446cf2
+#define reg_PDCM		ecx
446cf2
+#define reg_PCID		ecx
446cf2
+#define reg_DCA			ecx
446cf2
+#define reg_SSE4_1		ecx
446cf2
+#define reg_SSE4_2		ecx
446cf2
+#define reg_X2APIC		ecx
446cf2
+#define reg_MOVBE		ecx
446cf2
+#define reg_POPCNT		ecx
446cf2
+#define reg_TSC_DEADLINE	ecx
446cf2
+#define reg_AES			ecx
446cf2
+#define reg_XSAVE		ecx
446cf2
+#define reg_OSXSAVE		ecx
446cf2
+#define reg_AVX			ecx
446cf2
+#define reg_F16C		ecx
446cf2
+#define reg_RDRAND		ecx
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define reg_FPU			edx
446cf2
+#define reg_VME			edx
446cf2
+#define reg_DE			edx
446cf2
+#define reg_PSE			edx
446cf2
+#define reg_TSC			edx
446cf2
+#define reg_MSR			edx
446cf2
+#define reg_PAE			edx
446cf2
+#define reg_MCE			edx
446cf2
+#define reg_CX8			edx
446cf2
+#define reg_APIC		edx
446cf2
+#define reg_SEP			edx
446cf2
+#define reg_MTRR		edx
446cf2
+#define reg_PGE			edx
446cf2
+#define reg_MCA			edx
446cf2
+#define reg_CMOV		edx
446cf2
+#define reg_PAT			edx
446cf2
+#define reg_PSE_36		edx
446cf2
+#define reg_PSN			edx
446cf2
+#define reg_CLFSH		edx
446cf2
+#define reg_DS			edx
446cf2
+#define reg_ACPI		edx
446cf2
+#define reg_MMX			edx
446cf2
+#define reg_FXSR		edx
446cf2
+#define reg_SSE			edx
446cf2
+#define reg_SSE2		edx
446cf2
+#define reg_SS			edx
446cf2
+#define reg_HTT			edx
446cf2
+#define reg_TM			edx
446cf2
+#define reg_PBE			edx
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_7.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define reg_FSGSBASE		ebx
446cf2
+#define reg_TSC_ADJUST		ebx
446cf2
+#define reg_SGX			ebx
446cf2
+#define reg_BMI1		ebx
446cf2
+#define reg_HLE			ebx
446cf2
+#define reg_BMI2		ebx
446cf2
+#define reg_AVX2		ebx
446cf2
+#define reg_SMEP		ebx
446cf2
+#define reg_ERMS		ebx
446cf2
+#define reg_INVPCID		ebx
446cf2
+#define reg_RTM			ebx
446cf2
+#define reg_PQM			ebx
446cf2
+#define reg_MPX			ebx
446cf2
+#define reg_PQE			ebx
446cf2
+#define reg_AVX512F		ebx
446cf2
+#define reg_AVX512DQ		ebx
446cf2
+#define reg_RDSEED		ebx
446cf2
+#define reg_ADX			ebx
446cf2
+#define reg_SMAP		ebx
446cf2
+#define reg_AVX512_IFMA		ebx
446cf2
+#define reg_CLFLUSHOPT		ebx
446cf2
+#define reg_CLWB		ebx
446cf2
+#define reg_TRACE		ebx
446cf2
+#define reg_AVX512PF		ebx
446cf2
+#define reg_AVX512ER		ebx
446cf2
+#define reg_AVX512CD		ebx
446cf2
+#define reg_SHA			ebx
446cf2
+#define reg_AVX512BW		ebx
446cf2
+#define reg_AVX512VL		ebx
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define reg_PREFETCHWT1		ecx
446cf2
+#define reg_AVX512_VBMI		ecx
446cf2
+#define reg_UMIP		ecx
446cf2
+#define reg_PKU			ecx
446cf2
+#define reg_OSPKE		ecx
446cf2
+#define reg_WAITPKG		ecx
446cf2
+#define reg_AVX512_VBMI2	ecx
446cf2
+#define reg_SHSTK		ecx
446cf2
+#define reg_GFNI		ecx
446cf2
+#define reg_VAES		ecx
446cf2
+#define reg_VPCLMULQDQ		ecx
446cf2
+#define reg_AVX512_VNNI		ecx
446cf2
+#define reg_AVX512_BITALG	ecx
446cf2
+#define reg_AVX512_VPOPCNTDQ	ecx
446cf2
+#define reg_RDPID		ecx
446cf2
+#define reg_CLDEMOTE		ecx
446cf2
+#define reg_MOVDIRI		ecx
446cf2
+#define reg_MOVDIR64B		ecx
446cf2
+#define reg_SGX_LC		ecx
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define reg_AVX512_4VNNIW	edx
446cf2
+#define reg_AVX512_4FMAPS	edx
446cf2
+#define reg_FSRM		edx
446cf2
+#define reg_PCONFIG		edx
446cf2
+#define reg_IBT			edx
446cf2
+#define reg_IBRS_IBPB		edx
446cf2
+#define reg_STIBP		edx
446cf2
+#define reg_CAPABILITIES	edx
446cf2
+#define reg_SSBD		edx
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000001.  */
446cf2
+
446cf2
+/* ECX.  */
446cf2
+#define reg_LAHF64_SAHF64	ecx
446cf2
+#define reg_SVM			ecx
446cf2
+#define reg_LZCNT		ecx
446cf2
+#define reg_SSE4A		ecx
446cf2
+#define reg_PREFETCHW		ecx
446cf2
+#define reg_XOP			ecx
446cf2
+#define reg_LWP			ecx
446cf2
+#define reg_FMA4		ecx
446cf2
+#define reg_TBM			ecx
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define reg_SYSCALL_SYSRET	edx
446cf2
+#define reg_NX			edx
446cf2
+#define reg_PAGE1GB		edx
446cf2
+#define reg_RDTSCP		edx
446cf2
+#define reg_LM			edx
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_D_ECX_1.  */
446cf2
+
446cf2
+/* EAX.  */
446cf2
+#define reg_XSAVEOPT		eax
446cf2
+#define reg_XSAVEC		eax
446cf2
+#define reg_XGETBV_ECX_1	eax
446cf2
+#define reg_XSAVES		eax
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000007.  */
446cf2
+
446cf2
+/* EDX.  */
446cf2
+#define reg_INVARIANT_TSC	edx
446cf2
+
446cf2
+/* COMMON_CPUID_INDEX_80000008.  */
446cf2
+
446cf2
+/* EBX.  */
446cf2
+#define reg_WBNOINVD		ebx
446cf2
+
446cf2
+/* FEATURE_INDEX_2.  */
446cf2
+#define bit_arch_I586				(1u << 0)
446cf2
+#define bit_arch_I686				(1u << 1)
446cf2
+#define bit_arch_Fast_Rep_String		(1u << 2)
446cf2
+#define bit_arch_Fast_Copy_Backward		(1u << 3)
446cf2
+#define bit_arch_Fast_Unaligned_Load		(1u << 4)
446cf2
+#define bit_arch_Fast_Unaligned_Copy		(1u << 5)
446cf2
+#define bit_arch_Slow_BSF			(1u << 6)
446cf2
+#define bit_arch_Slow_SSE4_2			(1u << 7)
446cf2
+#define bit_arch_AVX_Fast_Unaligned_Load	(1u << 8)
446cf2
+#define bit_arch_Prefer_MAP_32BIT_EXEC		(1u << 9)
446cf2
+#define bit_arch_Prefer_PMINUB_for_stringop	(1u << 10)
446cf2
+#define bit_arch_Prefer_No_VZEROUPPER		(1u << 11)
446cf2
+#define bit_arch_Prefer_ERMS			(1u << 12)
446cf2
+#define bit_arch_Prefer_FSRM			(1u << 13)
446cf2
+#define bit_arch_Prefer_No_AVX512		(1u << 14)
446cf2
+#define bit_arch_MathVec_Prefer_No_AVX512	(1u << 15)
446cf2
+
446cf2
+#define index_arch_Fast_Rep_String		FEATURE_INDEX_2
446cf2
+#define index_arch_Fast_Copy_Backward		FEATURE_INDEX_2
446cf2
+#define index_arch_Slow_BSF			FEATURE_INDEX_2
446cf2
+#define index_arch_Fast_Unaligned_Load		FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_PMINUB_for_stringop 	FEATURE_INDEX_2
446cf2
+#define index_arch_Fast_Unaligned_Copy		FEATURE_INDEX_2
446cf2
+#define index_arch_I586				FEATURE_INDEX_2
446cf2
+#define index_arch_I686				FEATURE_INDEX_2
446cf2
+#define index_arch_Slow_SSE4_2			FEATURE_INDEX_2
446cf2
+#define index_arch_AVX_Fast_Unaligned_Load	FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_MAP_32BIT_EXEC	FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_No_VZEROUPPER		FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_ERMS			FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_No_AVX512		FEATURE_INDEX_2
446cf2
+#define index_arch_MathVec_Prefer_No_AVX512	FEATURE_INDEX_2
446cf2
+#define index_arch_Prefer_FSRM			FEATURE_INDEX_2
446cf2
+
446cf2
+/* XCR0 Feature flags.  */
446cf2
+#define bit_XMM_state		(1u << 1)
446cf2
+#define bit_YMM_state		(1u << 2)
446cf2
+#define bit_Opmask_state	(1u << 5)
446cf2
+#define bit_ZMM0_15_state	(1u << 6)
446cf2
+#define bit_ZMM16_31_state	(1u << 7)
446cf2
+
446cf2
+# if defined (_LIBC) && !IS_IN (nonlib)
446cf2
+/* Unused for x86.  */
446cf2
+#  define INIT_ARCH()
446cf2
+#  define __get_cpu_features()	(&GLRO(dl_x86_cpu_features))
446cf2
+#  define x86_get_cpuid_registers(i) \
446cf2
+       (&(GLRO(dl_x86_cpu_features).cpuid[i]))
446cf2
+# endif
446cf2
 
446cf2
 #ifdef __x86_64__
446cf2
 # define HAS_CPUID 1
446cf2
diff --git a/sysdeps/x86/tst-get-cpu-features.c b/sysdeps/x86/tst-get-cpu-features.c
446cf2
index b2fac197dac7708e..64a7fd6157242bdd 100644
446cf2
--- a/sysdeps/x86/tst-get-cpu-features.c
446cf2
+++ b/sysdeps/x86/tst-get-cpu-features.c
446cf2
@@ -17,15 +17,271 @@
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
 #include <stdlib.h>
446cf2
+#include <stdio.h>
446cf2
 #include <cpu-features.h>
446cf2
+#include <support/check.h>
446cf2
+
446cf2
+#define CHECK_CPU_FEATURE(name)		\
446cf2
+  {					\
446cf2
+    if (HAS_CPU_FEATURE (name))		\
446cf2
+      printf ("  " #name "\n");		\
446cf2
+  }
446cf2
+
446cf2
+#define CHECK_CPU_FEATURE_USABLE(name)	\
446cf2
+  {					\
446cf2
+    if (CPU_FEATURE_USABLE(name))	\
446cf2
+      printf ("  " #name "\n");		\
446cf2
+  }
446cf2
+
446cf2
+static const char * const cpu_kinds[] =
446cf2
+{
446cf2
+  "Unknown",
446cf2
+  "Intel",
446cf2
+  "AMD",
446cf2
+  "Other",
446cf2
+};
446cf2
 
446cf2
 static int
446cf2
 do_test (void)
446cf2
 {
446cf2
-  if (__get_cpu_features ()->kind == arch_kind_unknown)
446cf2
-    abort ();
446cf2
+  const struct cpu_features *cpu_features = __get_cpu_features ();
446cf2
+
446cf2
+  switch (cpu_features->basic.kind)
446cf2
+    {
446cf2
+    case arch_kind_intel:
446cf2
+    case arch_kind_amd:
446cf2
+    case arch_kind_other:
446cf2
+      printf ("Vendor: %s\n", cpu_kinds[cpu_features->basic.kind]);
446cf2
+      printf ("Family: 0x%x\n", cpu_features->basic.family);
446cf2
+      printf ("Model: 0x%x\n", cpu_features->basic.model);
446cf2
+      printf ("Stepping: 0x%x\n", cpu_features->basic.stepping);
446cf2
+      break;
446cf2
+
446cf2
+    default:
446cf2
+      abort ();
446cf2
+    }
446cf2
+
446cf2
+#ifdef __SSE2__
446cf2
+  TEST_VERIFY_EXIT (HAS_CPU_FEATURE (SSE2));
446cf2
+#endif
446cf2
+
446cf2
+  printf ("CPU features:\n");
446cf2
+  CHECK_CPU_FEATURE (SSE3);
446cf2
+  CHECK_CPU_FEATURE (PCLMULQDQ);
446cf2
+  CHECK_CPU_FEATURE (DTES64);
446cf2
+  CHECK_CPU_FEATURE (MONITOR);
446cf2
+  CHECK_CPU_FEATURE (DS_CPL);
446cf2
+  CHECK_CPU_FEATURE (VMX);
446cf2
+  CHECK_CPU_FEATURE (SMX);
446cf2
+  CHECK_CPU_FEATURE (EST);
446cf2
+  CHECK_CPU_FEATURE (TM2);
446cf2
+  CHECK_CPU_FEATURE (SSSE3);
446cf2
+  CHECK_CPU_FEATURE (CNXT_ID);
446cf2
+  CHECK_CPU_FEATURE (SDBG);
446cf2
+  CHECK_CPU_FEATURE (FMA);
446cf2
+  CHECK_CPU_FEATURE (CMPXCHG16B);
446cf2
+  CHECK_CPU_FEATURE (XTPRUPDCTRL);
446cf2
+  CHECK_CPU_FEATURE (PDCM);
446cf2
+  CHECK_CPU_FEATURE (PCID);
446cf2
+  CHECK_CPU_FEATURE (DCA);
446cf2
+  CHECK_CPU_FEATURE (SSE4_1);
446cf2
+  CHECK_CPU_FEATURE (SSE4_2);
446cf2
+  CHECK_CPU_FEATURE (X2APIC);
446cf2
+  CHECK_CPU_FEATURE (MOVBE);
446cf2
+  CHECK_CPU_FEATURE (POPCNT);
446cf2
+  CHECK_CPU_FEATURE (TSC_DEADLINE);
446cf2
+  CHECK_CPU_FEATURE (AES);
446cf2
+  CHECK_CPU_FEATURE (XSAVE);
446cf2
+  CHECK_CPU_FEATURE (OSXSAVE);
446cf2
+  CHECK_CPU_FEATURE (AVX);
446cf2
+  CHECK_CPU_FEATURE (F16C);
446cf2
+  CHECK_CPU_FEATURE (RDRAND);
446cf2
+  CHECK_CPU_FEATURE (FPU);
446cf2
+  CHECK_CPU_FEATURE (VME);
446cf2
+  CHECK_CPU_FEATURE (DE);
446cf2
+  CHECK_CPU_FEATURE (PSE);
446cf2
+  CHECK_CPU_FEATURE (TSC);
446cf2
+  CHECK_CPU_FEATURE (MSR);
446cf2
+  CHECK_CPU_FEATURE (PAE);
446cf2
+  CHECK_CPU_FEATURE (MCE);
446cf2
+  CHECK_CPU_FEATURE (CX8);
446cf2
+  CHECK_CPU_FEATURE (APIC);
446cf2
+  CHECK_CPU_FEATURE (SEP);
446cf2
+  CHECK_CPU_FEATURE (MTRR);
446cf2
+  CHECK_CPU_FEATURE (PGE);
446cf2
+  CHECK_CPU_FEATURE (MCA);
446cf2
+  CHECK_CPU_FEATURE (CMOV);
446cf2
+  CHECK_CPU_FEATURE (PAT);
446cf2
+  CHECK_CPU_FEATURE (PSE_36);
446cf2
+  CHECK_CPU_FEATURE (PSN);
446cf2
+  CHECK_CPU_FEATURE (CLFSH);
446cf2
+  CHECK_CPU_FEATURE (DS);
446cf2
+  CHECK_CPU_FEATURE (ACPI);
446cf2
+  CHECK_CPU_FEATURE (MMX);
446cf2
+  CHECK_CPU_FEATURE (FXSR);
446cf2
+  CHECK_CPU_FEATURE (SSE);
446cf2
+  CHECK_CPU_FEATURE (SSE2);
446cf2
+  CHECK_CPU_FEATURE (SS);
446cf2
+  CHECK_CPU_FEATURE (HTT);
446cf2
+  CHECK_CPU_FEATURE (TM);
446cf2
+  CHECK_CPU_FEATURE (PBE);
446cf2
+  CHECK_CPU_FEATURE (FSGSBASE);
446cf2
+  CHECK_CPU_FEATURE (TSC_ADJUST);
446cf2
+  CHECK_CPU_FEATURE (SGX);
446cf2
+  CHECK_CPU_FEATURE (BMI1);
446cf2
+  CHECK_CPU_FEATURE (HLE);
446cf2
+  CHECK_CPU_FEATURE (AVX2);
446cf2
+  CHECK_CPU_FEATURE (SMEP);
446cf2
+  CHECK_CPU_FEATURE (BMI2);
446cf2
+  CHECK_CPU_FEATURE (ERMS);
446cf2
+  CHECK_CPU_FEATURE (INVPCID);
446cf2
+  CHECK_CPU_FEATURE (RTM);
446cf2
+  CHECK_CPU_FEATURE (PQM);
446cf2
+  CHECK_CPU_FEATURE (MPX);
446cf2
+  CHECK_CPU_FEATURE (PQE);
446cf2
+  CHECK_CPU_FEATURE (AVX512F);
446cf2
+  CHECK_CPU_FEATURE (AVX512DQ);
446cf2
+  CHECK_CPU_FEATURE (RDSEED);
446cf2
+  CHECK_CPU_FEATURE (ADX);
446cf2
+  CHECK_CPU_FEATURE (SMAP);
446cf2
+  CHECK_CPU_FEATURE (AVX512_IFMA);
446cf2
+  CHECK_CPU_FEATURE (CLFLUSHOPT);
446cf2
+  CHECK_CPU_FEATURE (CLWB);
446cf2
+  CHECK_CPU_FEATURE (TRACE);
446cf2
+  CHECK_CPU_FEATURE (AVX512PF);
446cf2
+  CHECK_CPU_FEATURE (AVX512ER);
446cf2
+  CHECK_CPU_FEATURE (AVX512CD);
446cf2
+  CHECK_CPU_FEATURE (SHA);
446cf2
+  CHECK_CPU_FEATURE (AVX512BW);
446cf2
+  CHECK_CPU_FEATURE (AVX512VL);
446cf2
+  CHECK_CPU_FEATURE (PREFETCHWT1);
446cf2
+  CHECK_CPU_FEATURE (AVX512_VBMI);
446cf2
+  CHECK_CPU_FEATURE (UMIP);
446cf2
+  CHECK_CPU_FEATURE (PKU);
446cf2
+  CHECK_CPU_FEATURE (OSPKE);
446cf2
+  CHECK_CPU_FEATURE (WAITPKG);
446cf2
+  CHECK_CPU_FEATURE (AVX512_VBMI2);
446cf2
+  CHECK_CPU_FEATURE (SHSTK);
446cf2
+  CHECK_CPU_FEATURE (GFNI);
446cf2
+  CHECK_CPU_FEATURE (VAES);
446cf2
+  CHECK_CPU_FEATURE (VPCLMULQDQ);
446cf2
+  CHECK_CPU_FEATURE (AVX512_VNNI);
446cf2
+  CHECK_CPU_FEATURE (AVX512_BITALG);
446cf2
+  CHECK_CPU_FEATURE (AVX512_VPOPCNTDQ);
446cf2
+  CHECK_CPU_FEATURE (RDPID);
446cf2
+  CHECK_CPU_FEATURE (CLDEMOTE);
446cf2
+  CHECK_CPU_FEATURE (MOVDIRI);
446cf2
+  CHECK_CPU_FEATURE (MOVDIR64B);
446cf2
+  CHECK_CPU_FEATURE (SGX_LC);
446cf2
+  CHECK_CPU_FEATURE (AVX512_4VNNIW);
446cf2
+  CHECK_CPU_FEATURE (AVX512_4FMAPS);
446cf2
+  CHECK_CPU_FEATURE (FSRM);
446cf2
+  CHECK_CPU_FEATURE (PCONFIG);
446cf2
+  CHECK_CPU_FEATURE (IBT);
446cf2
+  CHECK_CPU_FEATURE (IBRS_IBPB);
446cf2
+  CHECK_CPU_FEATURE (STIBP);
446cf2
+  CHECK_CPU_FEATURE (CAPABILITIES);
446cf2
+  CHECK_CPU_FEATURE (SSBD);
446cf2
+  CHECK_CPU_FEATURE (LAHF64_SAHF64);
446cf2
+  CHECK_CPU_FEATURE (SVM);
446cf2
+  CHECK_CPU_FEATURE (LZCNT);
446cf2
+  CHECK_CPU_FEATURE (SSE4A);
446cf2
+  CHECK_CPU_FEATURE (PREFETCHW);
446cf2
+  CHECK_CPU_FEATURE (XOP);
446cf2
+  CHECK_CPU_FEATURE (LWP);
446cf2
+  CHECK_CPU_FEATURE (FMA4);
446cf2
+  CHECK_CPU_FEATURE (TBM);
446cf2
+  CHECK_CPU_FEATURE (SYSCALL_SYSRET);
446cf2
+  CHECK_CPU_FEATURE (NX);
446cf2
+  CHECK_CPU_FEATURE (PAGE1GB);
446cf2
+  CHECK_CPU_FEATURE (RDTSCP);
446cf2
+  CHECK_CPU_FEATURE (LM);
446cf2
+  CHECK_CPU_FEATURE (XSAVEOPT);
446cf2
+  CHECK_CPU_FEATURE (XSAVEC);
446cf2
+  CHECK_CPU_FEATURE (XGETBV_ECX_1);
446cf2
+  CHECK_CPU_FEATURE (XSAVES);
446cf2
+  CHECK_CPU_FEATURE (INVARIANT_TSC);
446cf2
+  CHECK_CPU_FEATURE (WBNOINVD);
446cf2
+
446cf2
+  printf ("Usable CPU features:\n");
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE3);
446cf2
+  CHECK_CPU_FEATURE_USABLE (PCLMULQDQ);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSSE3);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FMA);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CMPXCHG16B);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE4_1);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE4_2);
446cf2
+  CHECK_CPU_FEATURE_USABLE (MOVBE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (POPCNT);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AES);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XSAVE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (OSXSAVE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX);
446cf2
+  CHECK_CPU_FEATURE_USABLE (F16C);
446cf2
+  CHECK_CPU_FEATURE_USABLE (RDRAND);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FPU);
446cf2
+  CHECK_CPU_FEATURE_USABLE (TSC);
446cf2
+  CHECK_CPU_FEATURE_USABLE (MSR);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CX8);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SEP);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CMOV);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CLFSH);
446cf2
+  CHECK_CPU_FEATURE_USABLE (MMX);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FXSR);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE2);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FSGSBASE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (BMI1);
446cf2
+  CHECK_CPU_FEATURE_USABLE (HLE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX2);
446cf2
+  CHECK_CPU_FEATURE_USABLE (BMI2);
446cf2
+  CHECK_CPU_FEATURE_USABLE (ERMS);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512F);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512DQ);
446cf2
+  CHECK_CPU_FEATURE_USABLE (RDSEED);
446cf2
+  CHECK_CPU_FEATURE_USABLE (ADX);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_IFMA);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CLFLUSHOPT);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CLWB);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512PF);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512ER);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512CD);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SHA);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512BW);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512VL);
446cf2
+  CHECK_CPU_FEATURE_USABLE (PREFETCHWT1);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_VBMI);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_VBMI2);
446cf2
+  CHECK_CPU_FEATURE_USABLE (GFNI);
446cf2
+  CHECK_CPU_FEATURE_USABLE (VAES);
446cf2
+  CHECK_CPU_FEATURE_USABLE (VPCLMULQDQ);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_VNNI);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_BITALG);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_VPOPCNTDQ);
446cf2
+  CHECK_CPU_FEATURE_USABLE (RDPID);
446cf2
+  CHECK_CPU_FEATURE_USABLE (CLDEMOTE);
446cf2
+  CHECK_CPU_FEATURE_USABLE (MOVDIRI);
446cf2
+  CHECK_CPU_FEATURE_USABLE (MOVDIR64B);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_4VNNIW);
446cf2
+  CHECK_CPU_FEATURE_USABLE (AVX512_4FMAPS);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FSRM);
446cf2
+  CHECK_CPU_FEATURE_USABLE (LAHF64_SAHF64);
446cf2
+  CHECK_CPU_FEATURE_USABLE (LZCNT);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SSE4A);
446cf2
+  CHECK_CPU_FEATURE_USABLE (PREFETCHW);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XOP);
446cf2
+  CHECK_CPU_FEATURE_USABLE (FMA4);
446cf2
+  CHECK_CPU_FEATURE_USABLE (TBM);
446cf2
+  CHECK_CPU_FEATURE_USABLE (SYSCALL_SYSRET);
446cf2
+  CHECK_CPU_FEATURE_USABLE (RDTSCP);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XSAVEOPT);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XSAVEC);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XGETBV_ECX_1);
446cf2
+  CHECK_CPU_FEATURE_USABLE (XSAVES);
446cf2
+  CHECK_CPU_FEATURE_USABLE (INVARIANT_TSC);
446cf2
+  CHECK_CPU_FEATURE_USABLE (WBNOINVD);
446cf2
+
446cf2
   return 0;
446cf2
 }
446cf2
 
446cf2
-#define TEST_FUNCTION do_test ()
446cf2
-#include "../../test-skeleton.c"
446cf2
+#include <support/test-driver.c>
446cf2
diff --git a/sysdeps/x86_64/multiarch/sched_cpucount.c b/sysdeps/x86_64/multiarch/sched_cpucount.c
446cf2
index d10d74ae21e05d47..7949119dcdb5a94b 100644
446cf2
--- a/sysdeps/x86_64/multiarch/sched_cpucount.c
446cf2
+++ b/sysdeps/x86_64/multiarch/sched_cpucount.c
446cf2
@@ -33,4 +33,4 @@
446cf2
 #undef __sched_cpucount
446cf2
 
446cf2
 libc_ifunc (__sched_cpucount,
446cf2
-	    HAS_CPU_FEATURE (POPCOUNT) ? popcount_cpucount : generic_cpucount);
446cf2
+	    HAS_CPU_FEATURE (POPCNT) ? popcount_cpucount : generic_cpucount);
446cf2
diff --git a/sysdeps/x86_64/multiarch/test-multiarch.c b/sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
index aa872f27dbe7ea2f..417147c3d5f325a5 100644
446cf2
--- a/sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
+++ b/sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
@@ -85,8 +85,8 @@ do_test (int argc, char **argv)
446cf2
 		       , "HAS_CPU_FEATURE (SSE4_1)");
446cf2
   fails += check_proc ("ssse3", HAS_CPU_FEATURE (SSSE3),
446cf2
 		       "HAS_CPU_FEATURE (SSSE3)");
446cf2
-  fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCOUNT),
446cf2
-		       "HAS_CPU_FEATURE (POPCOUNT)");
446cf2
+  fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCNT),
446cf2
+		       "HAS_CPU_FEATURE (POPCNT)");
446cf2
 
446cf2
   printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
446cf2