446cf2
commit 9620398097de3981c1adf5233e2b3478d36bc1b3
446cf2
Author: H.J. Lu <hjl.tools@gmail.com>
446cf2
Date:   Mon Jun 29 18:30:54 2020 -0700
446cf2
446cf2
    x86: Install <sys/platform/x86.h> [BZ #26124]
446cf2
    
446cf2
    Install <sys/platform/x86.h> so that programmers can do
446cf2
    
446cf2
     #if __has_include(<sys/platform/x86.h>)
446cf2
     #include <sys/platform/x86.h>
446cf2
     #endif
446cf2
     ...
446cf2
    
446cf2
       if (CPU_FEATURE_USABLE (SSE2))
446cf2
     ...
446cf2
       if (CPU_FEATURE_USABLE (AVX2))
446cf2
     ...
446cf2
    
446cf2
    <sys/platform/x86.h> exports only:
446cf2
    
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
      COMMON_CPUID_INDEX_7_ECX_1,
446cf2
      /* Keep the following line at the end.  */
446cf2
      COMMON_CPUID_INDEX_MAX
446cf2
    };
446cf2
    
446cf2
    struct cpuid_features
446cf2
    {
446cf2
      struct cpuid_registers cpuid;
446cf2
      struct cpuid_registers usable;
446cf2
    };
446cf2
    
446cf2
    struct cpu_features
446cf2
    {
446cf2
      struct cpu_features_basic basic;
446cf2
      struct cpuid_features features[COMMON_CPUID_INDEX_MAX];
446cf2
    };
446cf2
    
446cf2
    /* Get a pointer to the CPU features structure.  */
446cf2
    extern const struct cpu_features *__x86_get_cpu_features
446cf2
      (unsigned int max) __attribute__ ((const));
446cf2
    
446cf2
    Since all feature checks are done through macros, programs compiled with
446cf2
    a newer <sys/platform/x86.h> are compatible with the older glibc binaries
446cf2
    as long as the layout of struct cpu_features is identical.  The features
446cf2
    array can be expanded with backward binary compatibility for both .o and
446cf2
    .so files.  When COMMON_CPUID_INDEX_MAX is increased to support new
446cf2
    processor features, __x86_get_cpu_features in the older glibc binaries
446cf2
    returns NULL and HAS_CPU_FEATURE/CPU_FEATURE_USABLE return false on the
446cf2
    new processor feature.  No new symbol version is neeeded.
446cf2
    
446cf2
    Both CPU_FEATURE_USABLE and HAS_CPU_FEATURE are provided.  HAS_CPU_FEATURE
446cf2
    can be used to identify processor features.
446cf2
    
446cf2
    Note: Although GCC has __builtin_cpu_supports, it only supports a subset
446cf2
    of <sys/platform/x86.h> and it is equivalent to CPU_FEATURE_USABLE.  It
446cf2
    doesn't support HAS_CPU_FEATURE.
446cf2
446cf2
Conflicts:
446cf2
	sysdeps/x86/sys/platform/x86.h
446cf2
	sysdeps/x86/tst-get-cpu-features.c
446cf2
	sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
	  (Copyright year, URL differences.)
446cf2
446cf2
Downstream changes: Do not install <sys/platform/x86.h>,
446cf2
and use a GLIBC_PRIVATE symbol for __x86_get_cpu_features.
446cf2
446cf2
diff --git a/manual/platform.texi b/manual/platform.texi
446cf2
index 504addc956086820..2c145acdc3564cbb 100644
446cf2
--- a/manual/platform.texi
446cf2
+++ b/manual/platform.texi
446cf2
@@ -7,6 +7,7 @@
446cf2
 @menu
446cf2
 * PowerPC::           Facilities Specific to the PowerPC Architecture
446cf2
 * RISC-V::            Facilities Specific to the RISC-V Architecture
446cf2
+* X86::               Facilities Specific to the X86 Architecture
446cf2
 @end menu
446cf2
 
446cf2
 @node PowerPC
446cf2
@@ -134,3 +135,519 @@ all threads in the current process.  Setting the
446cf2
 ordering on only the current thread is necessary.  All other flag bits are
446cf2
 reserved.
446cf2
 @end deftypefun
446cf2
+
446cf2
+@node X86
446cf2
+@appendixsec X86-specific Facilities
446cf2
+
446cf2
+Facilities specific to X86 that are not specific to a particular
446cf2
+operating system are declared in @file{sys/platform/x86.h}.
446cf2
+
446cf2
+@deftypefun {const struct cpu_features *} __x86_get_cpu_features (unsigned int @var{max})
446cf2
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
446cf2
+Return a pointer to x86 CPU feature structure used by query macros for x86
446cf2
+CPU features.  If @var{max} exceeds @code{COMMON_CPUID_INDEX_MAX} which
446cf2
+is the limit of the CPUID leaves supported by @Theglibc{}, the function
446cf2
+returns @code{NULL}, indicating that the queried processor feature is
446cf2
+unsupported by @Theglibc{} run-time.
446cf2
+@end deftypefun
446cf2
+
446cf2
+@deftypefn Macro int HAS_CPU_FEATURE (@var{name})
446cf2
+This macro returns a nonzero value (true) if the processor has the feature
446cf2
+@var{name}.
446cf2
+@end deftypefn
446cf2
+
446cf2
+@deftypefn Macro int CPU_FEATURE_USABLE (@var{name})
446cf2
+This macro returns a nonzero value (true) if the processor has the feature
446cf2
+@var{name} and the feature is supported by the operating system.
446cf2
+@end deftypefn
446cf2
+
446cf2
+The supported processor features are:
446cf2
+
446cf2
+@itemize @bullet
446cf2
+
446cf2
+@item
446cf2
+@code{ACPI} -- Thermal Monitor and Software Controlled Clock Facilities.
446cf2
+
446cf2
+@item
446cf2
+@code{ADX} -- ADX instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{APIC} -- APIC On-Chip.
446cf2
+
446cf2
+@item
446cf2
+@code{AES} -- The AES instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AMX_BF16} -- Tile computational operations on bfloat16 numbers.
446cf2
+
446cf2
+@item
446cf2
+@code{AMX_INT8} -- Tile computational operations on 8-bit numbers.
446cf2
+
446cf2
+@item
446cf2
+@code{AMX_TILE} -- Tile architecture.
446cf2
+
446cf2
+@item
446cf2
+@code{ARCH_CAPABILITIES} -- IA32_ARCH_CAPABILITIES MSR.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX} -- The AVX instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX2} -- The AVX2 instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_4FMAPS} -- The AVX512_4FMAPS instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_4VNNIW} -- The AVX512_4VNNIW instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_BF16} -- The AVX512_BF16 instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_BITALG} -- The AVX512_BITALG instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_IFMA} -- The AVX512_IFMA instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_VBMI} -- The AVX512_VBMI instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_VBMI2} -- The AVX512_VBMI2 instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_VNNI} -- The AVX512_VNNI instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_VP2INTERSECT} -- The AVX512_VP2INTERSECT instruction
446cf2
+extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512_VPOPCNTDQ} -- The AVX512_VPOPCNTDQ instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512BW} -- The AVX512BW instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512CD} -- The AVX512CD instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512ER} -- The AVX512ER instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512DQ} -- The AVX512DQ instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512F} -- The AVX512F instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512PF} -- The AVX512PF instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{AVX512VL} -- The AVX512VL instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{BMI1} -- BMI1 instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{BMI2} -- BMI2 instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{CLDEMOTE} -- CLDEMOTE instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{CLFLUSHOPT} -- CLFLUSHOPT instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{CLFSH} -- CLFLUSH instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{CLWB} -- CLWB instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{CMOV} -- Conditional Move instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{CMPXCHG16B} -- CMPXCHG16B instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{CNXT_ID} -- L1 Context ID.
446cf2
+
446cf2
+@item
446cf2
+@code{CORE_CAPABILITIES} -- IA32_CORE_CAPABILITIES MSR.
446cf2
+
446cf2
+@item
446cf2
+@code{CX8} -- CMPXCHG8B instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{DCA} -- Data prefetch from a memory mapped device.
446cf2
+
446cf2
+@item
446cf2
+@code{DE} -- Debugging Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{DEPR_FPU_CS_DS} -- Deprecates FPU CS and FPU DS values.
446cf2
+
446cf2
+@item
446cf2
+@code{DS} -- Debug Store.
446cf2
+
446cf2
+@item
446cf2
+@code{DS_CPL} -- CPL Qualified Debug Store.
446cf2
+
446cf2
+@item
446cf2
+@code{DTES64} -- 64-bit DS Area.
446cf2
+
446cf2
+@item
446cf2
+@code{EIST} -- Enhanced Intel SpeedStep technology.
446cf2
+
446cf2
+@item
446cf2
+@code{ENQCMD} -- Enqueue Stores instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{ERMS} -- Enhanced REP MOVSB/STOSB.
446cf2
+
446cf2
+@item
446cf2
+@code{F16C} -- 16-bit floating-point conversion instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{FMA} -- FMA extensions using YMM state.
446cf2
+
446cf2
+@item
446cf2
+@code{FMA4} -- FMA4 instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{FPU} -- X87 Floating Point Unit On-Chip.
446cf2
+
446cf2
+@item
446cf2
+@code{FSGSBASE} -- RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{FSRM} -- Fast Short REP MOV.
446cf2
+
446cf2
+@item
446cf2
+@code{FXSR} -- FXSAVE and FXRSTOR instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{GFNI} -- GFNI instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{HLE} -- HLE instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{HTT} -- Max APIC IDs reserved field is Valid.
446cf2
+
446cf2
+@item
446cf2
+@code{HYBRID} -- Hybrid processor.
446cf2
+
446cf2
+@item
446cf2
+@code{IBRS_IBPB} -- Indirect branch restricted speculation (IBRS) and
446cf2
+the indirect branch predictor barrier (IBPB).
446cf2
+
446cf2
+@item
446cf2
+@code{IBT} -- Intel Indirect Branch Tracking instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{INVARIANT_TSC} -- Invariant TSC.
446cf2
+
446cf2
+@item
446cf2
+@code{INVPCID} -- INVPCID instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{L1D_FLUSH} -- IA32_FLUSH_CMD MSR.
446cf2
+
446cf2
+@item
446cf2
+@code{LAHF64_SAHF64} -- LAHF/SAHF available in 64-bit mode.
446cf2
+
446cf2
+@item
446cf2
+@code{LM} -- Long mode.
446cf2
+
446cf2
+@item
446cf2
+@code{LWP} -- Lightweight profiling.
446cf2
+
446cf2
+@item
446cf2
+@code{LZCNT} -- LZCNT instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{MCA} -- Machine Check Architecture.
446cf2
+
446cf2
+@item
446cf2
+@code{MCE} -- Machine Check Exception.
446cf2
+
446cf2
+@item
446cf2
+@code{MD_CLEAR} -- MD_CLEAR.
446cf2
+
446cf2
+@item
446cf2
+@code{MMX} -- Intel MMX Technology.
446cf2
+
446cf2
+@item
446cf2
+@code{MONITOR} --  MONITOR/MWAIT instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{MOVBE} -- MOVBE instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{MOVDIRI} -- MOVDIRI instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{MOVDIR64B} -- MOVDIR64B instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{MPX} -- Intel Memory Protection Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{MSR} -- Model Specific Registers RDMSR and WRMSR instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{MTRR} -- Memory Type Range Registers.
446cf2
+
446cf2
+@item
446cf2
+@code{NX} -- No-execute page protection.
446cf2
+
446cf2
+@item
446cf2
+@code{OSPKE} -- OS has set CR4.PKE to enable protection keys.
446cf2
+
446cf2
+@item
446cf2
+@code{OSXSAVE} -- The OS has set CR4.OSXSAVE[bit 18] to enable
446cf2
+XSETBV/XGETBV instructions to access XCR0 and to support processor
446cf2
+extended state management using XSAVE/XRSTOR.
446cf2
+
446cf2
+@item
446cf2
+@code{PAE} -- Physical Address Extension.
446cf2
+
446cf2
+@item
446cf2
+@code{PAGE1GB} -- 1-GByte page.
446cf2
+
446cf2
+@item
446cf2
+@code{PAT} -- Page Attribute Table.
446cf2
+
446cf2
+@item
446cf2
+@code{PBE} -- Pending Break Enable.
446cf2
+
446cf2
+@item
446cf2
+@code{PCID} -- Process-context identifiers.
446cf2
+
446cf2
+@item
446cf2
+@code{PCLMULQDQ} -- PCLMULQDQ instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{PCONFIG} -- PCONFIG instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{PDCM} -- Perfmon and Debug Capability.
446cf2
+
446cf2
+@item
446cf2
+@code{PGE} -- Page Global Bit.
446cf2
+
446cf2
+@item
446cf2
+@code{PKS} -- Protection keys for supervisor-mode pages.
446cf2
+
446cf2
+@item
446cf2
+@code{PKU} -- Protection keys for user-mode pages.
446cf2
+
446cf2
+@item
446cf2
+@code{POPCNT} -- POPCNT instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{PREFETCHW} -- PREFETCHW instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{PREFETCHWT1} -- PREFETCHWT1 instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{PSE} -- Page Size Extension.
446cf2
+
446cf2
+@item
446cf2
+@code{PSE_36} -- 36-Bit Page Size Extension.
446cf2
+
446cf2
+@item
446cf2
+@code{PSN} -- Processor Serial Number.
446cf2
+
446cf2
+@item
446cf2
+@code{RDPID} -- RDPID instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{RDRAND} -- RDRAND instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{RDSEED} -- RDSEED instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{RDT_A} -- Intel Resource Director Technology (Intel RDT) Allocation
446cf2
+capability.
446cf2
+
446cf2
+@item
446cf2
+@code{RDT_M} -- Intel Resource Director Technology (Intel RDT) Monitoring
446cf2
+capability.
446cf2
+
446cf2
+@item
446cf2
+@code{RDTSCP} -- RDTSCP instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{RTM} -- RTM instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SDBG} -- IA32_DEBUG_INTERFACE MSR for silicon debug.
446cf2
+
446cf2
+@item
446cf2
+@code{SEP} -- SYSENTER and SYSEXIT instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{SERIALIZE} -- SERIALIZE instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{SGX} -- Intel Software Guard Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SGX_LC} -- SGX Launch Configuration.
446cf2
+
446cf2
+@item
446cf2
+@code{SHA} -- SHA instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SHSTK} -- Intel Shadow Stack instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SMAP} -- Supervisor-Mode Access Prevention.
446cf2
+
446cf2
+@item
446cf2
+@code{SMEP} -- Supervisor-Mode Execution Prevention.
446cf2
+
446cf2
+@item
446cf2
+@code{SMX} -- Safer Mode Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SS} -- Self Snoop.
446cf2
+
446cf2
+@item
446cf2
+@code{SSBD} -- Speculative Store Bypass Disable (SSBD).
446cf2
+
446cf2
+@item
446cf2
+@code{SSE} -- Streaming SIMD Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SSE2} -- Streaming SIMD Extensions 2.
446cf2
+
446cf2
+@item
446cf2
+@code{SSE3} -- Streaming SIMD Extensions 3.
446cf2
+
446cf2
+@item
446cf2
+@code{SSE4_1} -- Streaming SIMD Extensions 4.1.
446cf2
+
446cf2
+@item
446cf2
+@code{SSE4_2} -- Streaming SIMD Extensions 4.2.
446cf2
+
446cf2
+@item
446cf2
+@code{SSE4A} -- SSE4A instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{SSSE3} -- Supplemental Streaming SIMD Extensions 3.
446cf2
+
446cf2
+@item
446cf2
+@code{STIBP} -- Single thread indirect branch predictors (STIBP).
446cf2
+
446cf2
+@item
446cf2
+@code{SVM} -- Secure Virtual Machine.
446cf2
+
446cf2
+@item
446cf2
+@code{SYSCALL_SYSRET} -- SYSCALL/SYSRET instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{TBM} -- Trailing bit manipulation instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{TM} -- Thermal Monitor.
446cf2
+
446cf2
+@item
446cf2
+@code{TM2} -- Thermal Monitor 2.
446cf2
+
446cf2
+@item
446cf2
+@code{TRACE} -- Intel Processor Trace.
446cf2
+
446cf2
+@item
446cf2
+@code{TSC} -- Time Stamp Counter.  RDTSC instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{TSC_ADJUST} -- IA32_TSC_ADJUST MSR.
446cf2
+
446cf2
+@item
446cf2
+@code{TSC_DEADLINE} -- Local APIC timer supports one-shot operation
446cf2
+using a TSC deadline value.
446cf2
+
446cf2
+@item
446cf2
+@code{TSXLDTRK} -- TSXLDTRK instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{UMIP} -- User-mode instruction prevention.
446cf2
+
446cf2
+@item
446cf2
+@code{VAES} -- VAES instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{VME} -- Virtual 8086 Mode Enhancements.
446cf2
+
446cf2
+@item
446cf2
+@code{VMX} -- Virtual Machine Extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{VPCLMULQDQ} -- VPCLMULQDQ instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{WAITPKG} -- WAITPKG instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{WBNOINVD} -- WBINVD/WBNOINVD instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{X2APIC} -- x2APIC.
446cf2
+
446cf2
+@item
446cf2
+@code{XFD} -- Extended Feature Disable (XFD).
446cf2
+
446cf2
+@item
446cf2
+@code{XGETBV_ECX_1} -- XGETBV with ECX = 1.
446cf2
+
446cf2
+@item
446cf2
+@code{XOP} -- XOP instruction extensions.
446cf2
+
446cf2
+@item
446cf2
+@code{XSAVE} -- The XSAVE/XRSTOR processor extended states feature, the
446cf2
+XSETBV/XGETBV instructions, and XCR0.
446cf2
+
446cf2
+@item
446cf2
+@code{XSAVEC} -- XSAVEC instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{XSAVEOPT} -- XSAVEOPT instruction.
446cf2
+
446cf2
+@item
446cf2
+@code{XSAVES} -- XSAVES/XRSTORS instructions.
446cf2
+
446cf2
+@item
446cf2
+@code{XTPRUPDCTRL} -- xTPR Update Control.
446cf2
+
446cf2
+@end itemize
446cf2
+
446cf2
+You could query if a processor supports @code{AVX} with:
446cf2
+
446cf2
+@smallexample
446cf2
+#include <sys/platform/x86.h>
446cf2
+
446cf2
+int
446cf2
+support_avx (void)
446cf2
+@{
446cf2
+  return HAS_CPU_FEATURE (AVX);
446cf2
+@}
446cf2
+@end smallexample
446cf2
+
446cf2
+and if @code{AVX} is usable with:
446cf2
+
446cf2
+@smallexample
446cf2
+#include <sys/platform/x86.h>
446cf2
+
446cf2
+int
446cf2
+usable_avx (void)
446cf2
+@{
446cf2
+  return CPU_FEATURE_USABLE (AVX);
446cf2
+@}
446cf2
+@end smallexample
446cf2
diff --git a/sysdeps/i386/i686/multiarch/Makefile b/sysdeps/i386/i686/multiarch/Makefile
446cf2
index bf75a9947fe013a3..c4897922d710d37e 100644
446cf2
--- a/sysdeps/i386/i686/multiarch/Makefile
446cf2
+++ b/sysdeps/i386/i686/multiarch/Makefile
446cf2
@@ -1,7 +1,3 @@
446cf2
-ifeq ($(subdir),csu)
446cf2
-tests += test-multiarch
446cf2
-endif
446cf2
-
446cf2
 ifeq ($(subdir),string)
446cf2
 gen-as-const-headers += locale-defines.sym
446cf2
 sysdep_routines += bzero-sse2 memset-sse2 memcpy-ssse3 mempcpy-ssse3 \
446cf2
diff --git a/sysdeps/i386/i686/multiarch/test-multiarch.c b/sysdeps/i386/i686/multiarch/test-multiarch.c
446cf2
deleted file mode 100644
446cf2
index 593cfec2735fb5b0..0000000000000000
446cf2
--- a/sysdeps/i386/i686/multiarch/test-multiarch.c
446cf2
+++ /dev/null
446cf2
@@ -1 +0,0 @@
446cf2
-#include <sysdeps/x86_64/multiarch/test-multiarch.c>
446cf2
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
446cf2
index 962bbcb07eba1259..59e928e9d08d3229 100644
446cf2
--- a/sysdeps/x86/Makefile
446cf2
+++ b/sysdeps/x86/Makefile
446cf2
@@ -5,7 +5,8 @@ endif
446cf2
 ifeq ($(subdir),elf)
446cf2
 sysdep-dl-routines += dl-get-cpu-features
446cf2
 
446cf2
-tests += tst-get-cpu-features tst-get-cpu-features-static
446cf2
+tests += tst-get-cpu-features tst-get-cpu-features-static \
446cf2
+	 tst-cpu-features-cpuinfo tst-cpu-features-supports
446cf2
 tests-static += tst-get-cpu-features-static
446cf2
 endif
446cf2
 
446cf2
diff --git a/sysdeps/x86/Versions b/sysdeps/x86/Versions
446cf2
index e02923708e160881..df70e602192053c0 100644
446cf2
--- a/sysdeps/x86/Versions
446cf2
+++ b/sysdeps/x86/Versions
446cf2
@@ -1,5 +1,5 @@
446cf2
 ld {
446cf2
   GLIBC_PRIVATE {
446cf2
-    __get_cpu_features;
446cf2
+    __x86_get_cpu_features;
446cf2
   }
446cf2
 }
446cf2
diff --git a/sysdeps/x86/dl-get-cpu-features.c b/sysdeps/x86/dl-get-cpu-features.c
446cf2
index 49593f19c64ad0bb..2aba0d167129b336 100644
446cf2
--- a/sysdeps/x86/dl-get-cpu-features.c
446cf2
+++ b/sysdeps/x86/dl-get-cpu-features.c
446cf2
@@ -18,10 +18,12 @@
446cf2
 
446cf2
 #include <ldsodefs.h>
446cf2
 
446cf2
-#undef __get_cpu_features
446cf2
+#undef __x86_get_cpu_features
446cf2
 
446cf2
 const struct cpu_features *
446cf2
-__get_cpu_features (void)
446cf2
+__x86_get_cpu_features (unsigned int max)
446cf2
 {
446cf2
+  if (max > COMMON_CPUID_INDEX_MAX)
446cf2
+    return NULL;
446cf2
   return &GLRO(dl_x86_cpu_features);
446cf2
 }
446cf2
diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h
446cf2
new file mode 100644
446cf2
index 0000000000000000..dcf29b6fe8578078
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/x86/include/cpu-features.h
446cf2
@@ -0,0 +1,183 @@
446cf2
+/* Data structure for x86 CPU features.
446cf2
+   Copyright (C) 2020 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <https://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#ifndef	_PRIVATE_CPU_FEATURES_H
446cf2
+#define	_PRIVATE_CPU_FEATURES_H	1
446cf2
+
446cf2
+#ifdef _CPU_FEATURES_H
446cf2
+# error this should be impossible
446cf2
+#endif
446cf2
+
446cf2
+#ifndef _ISOMAC
446cf2
+/* Get most of the contents from the public header, but we define a
446cf2
+   different `struct cpu_features' type for private use.  */
446cf2
+# define cpu_features		cpu_features_public
446cf2
+# define __x86_get_cpu_features	__x86_get_cpu_features_public
446cf2
+#endif
446cf2
+
446cf2
+#include <sysdeps/x86/sys/platform/x86.h>
446cf2
+
446cf2
+#ifndef _ISOMAC
446cf2
+
446cf2
+# undef	cpu_features
446cf2
+# undef __x86_get_cpu_features
446cf2
+# define __get_cpu_features()	__x86_get_cpu_features (0)
446cf2
+
446cf2
+enum
446cf2
+{
446cf2
+  /* The integer bit array index for the first set of preferred feature
446cf2
+     bits.  */
446cf2
+  PREFERRED_FEATURE_INDEX_1 = 0,
446cf2
+  /* The current maximum size of the feature integer bit array.  */
446cf2
+  PREFERRED_FEATURE_INDEX_MAX
446cf2
+};
446cf2
+
446cf2
+/* Only used directly in cpu-features.c.  */
446cf2
+# define CPU_FEATURE_SET(ptr, name) \
446cf2
+  ptr->features[index_cpu_##name].usable.reg_##name |= bit_cpu_##name;
446cf2
+# define CPU_FEATURE_UNSET(ptr, name) \
446cf2
+  ptr->features[index_cpu_##name].usable.reg_##name &= ~bit_cpu_##name;
446cf2
+# define CPU_FEATURE_SET_USABLE(ptr, name) \
446cf2
+  ptr->features[index_cpu_##name].usable.reg_##name \
446cf2
+     |= ptr->features[index_cpu_##name].cpuid.reg_##name & bit_cpu_##name;
446cf2
+# define CPU_FEATURE_PREFERRED_P(ptr, name) \
446cf2
+  ((ptr->preferred[index_arch_##name] & bit_arch_##name) != 0)
446cf2
+# define CPU_FEATURE_CPU_P(ptr, name) \
446cf2
+  CPU_FEATURE_CHECK_P (ptr, name, cpuid)
446cf2
+
446cf2
+/* HAS_CPU_FEATURE evaluates to true if CPU supports the feature.  */
446cf2
+# undef HAS_CPU_FEATURE
446cf2
+# define HAS_CPU_FEATURE(name) \
446cf2
+  CPU_FEATURE_CPU_P (__x86_get_cpu_features (0), name)
446cf2
+/* CPU_FEATURE_USABLE evaluates to true if the feature is usable.  */
446cf2
+# undef CPU_FEATURE_USABLE
446cf2
+# define CPU_FEATURE_USABLE(name) \
446cf2
+  CPU_FEATURE_USABLE_P (__x86_get_cpu_features (0), name)
446cf2
+/* CPU_FEATURE_PREFER evaluates to true if we prefer the feature at
446cf2
+   runtime.  */
446cf2
+# define CPU_FEATURE_PREFERRED(name) \
446cf2
+  CPU_FEATURE_PREFERRED_P(__get_cpu_features (), name)
446cf2
+
446cf2
+# define CPU_FEATURES_CPU_P(ptr, name) \
446cf2
+  CPU_FEATURE_CPU_P (ptr, name)
446cf2
+# define CPU_FEATURES_ARCH_P(ptr, name) \
446cf2
+  CPU_FEATURE_PREFERRED_P (ptr, name)
446cf2
+# define HAS_ARCH_FEATURE(name) \
446cf2
+  CPU_FEATURE_PREFERRED (name)
446cf2
+
446cf2
+/* PREFERRED_FEATURE_INDEX_1.  */
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		PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Fast_Copy_Backward		PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Slow_BSF			PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Fast_Unaligned_Load		PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_PMINUB_for_stringop 	PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Fast_Unaligned_Copy		PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_I586			PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_I686			PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Slow_SSE4_2			PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_AVX_Fast_Unaligned_Load	PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_MAP_32BIT_EXEC	PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_No_VZEROUPPER	PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_ERMS			PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_No_AVX512		PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_MathVec_Prefer_No_AVX512	PREFERRED_FEATURE_INDEX_1
446cf2
+# define index_arch_Prefer_FSRM			PREFERRED_FEATURE_INDEX_1
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
+# define bit_XTILECFG_state	(1u << 17)
446cf2
+# define bit_XTILEDATA_state	(1u << 18)
446cf2
+
446cf2
+struct cpu_features
446cf2
+{
446cf2
+  struct cpu_features_basic basic;
446cf2
+  struct cpuid_features features[COMMON_CPUID_INDEX_MAX];
446cf2
+  unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX];
446cf2
+  /* The state size for XSAVEC or XSAVE.  The type must be unsigned long
446cf2
+     int so that we use
446cf2
+
446cf2
+	sub xsave_state_size_offset(%rip) %RSP_LP
446cf2
+
446cf2
+     in _dl_runtime_resolve.  */
446cf2
+  unsigned long int xsave_state_size;
446cf2
+  /* The full state size for XSAVE when XSAVEC is disabled by
446cf2
+
446cf2
+     GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC
446cf2
+   */
446cf2
+  unsigned int xsave_state_full_size;
446cf2
+  /* Data cache size for use in memory and string routines, typically
446cf2
+     L1 size.  */
446cf2
+  unsigned long int data_cache_size;
446cf2
+  /* Shared cache size for use in memory and string routines, typically
446cf2
+     L2 or L3 size.  */
446cf2
+  unsigned long int shared_cache_size;
446cf2
+  /* Threshold to use non temporal store.  */
446cf2
+  unsigned long int non_temporal_threshold;
446cf2
+  /* Threshold to use "rep movsb".  */
446cf2
+  unsigned long int rep_movsb_threshold;
446cf2
+  /* Threshold to use "rep stosb".  */
446cf2
+  unsigned long int rep_stosb_threshold;
446cf2
+};
446cf2
+
446cf2
+# if defined (_LIBC) && !IS_IN (nonlib)
446cf2
+/* Unused for x86.  */
446cf2
+#  define INIT_ARCH()
446cf2
+#  define __x86_get_cpu_features(max) (&GLRO(dl_x86_cpu_features))
446cf2
+# endif
446cf2
+
446cf2
+# ifdef __x86_64__
446cf2
+#  define HAS_CPUID 1
446cf2
+# elif (defined __i586__ || defined __pentium__	\
446cf2
+	|| defined __geode__ || defined __k6__)
446cf2
+#  define HAS_CPUID 1
446cf2
+#  define HAS_I586 1
446cf2
+#  define HAS_I686 HAS_ARCH_FEATURE (I686)
446cf2
+# elif defined __i486__
446cf2
+#  define HAS_CPUID 0
446cf2
+#  define HAS_I586 HAS_ARCH_FEATURE (I586)
446cf2
+#  define HAS_I686 HAS_ARCH_FEATURE (I686)
446cf2
+# else
446cf2
+#  define HAS_CPUID 1
446cf2
+#  define HAS_I586 1
446cf2
+#  define HAS_I686 1
446cf2
+# endif
446cf2
+
446cf2
+#endif /* !_ISOMAC */
446cf2
+
446cf2
+#endif /* include/cpu-features.h */
446cf2
diff --git a/sysdeps/x86/cpu-features.h b/sysdeps/x86/sys/platform/x86.h
446cf2
similarity index 81%
446cf2
rename from sysdeps/x86/cpu-features.h
446cf2
rename to sysdeps/x86/sys/platform/x86.h
446cf2
index 3b401d441b8d370a..ebc5f6fc16cb8104 100644
446cf2
--- a/sysdeps/x86/cpu-features.h
446cf2
+++ b/sysdeps/x86/sys/platform/x86.h
446cf2
@@ -1,5 +1,6 @@
446cf2
-/* This file is part of the GNU C Library.
446cf2
-   Copyright (C) 2008-2018 Free Software Foundation, Inc.
446cf2
+/* Data structure for x86 CPU features.
446cf2
+   This file is part of the GNU C Library.
446cf2
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
    modify it under the terms of the GNU Lesser General Public
446cf2
@@ -15,17 +16,8 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
-#ifndef cpu_features_h
446cf2
-#define cpu_features_h
446cf2
-
446cf2
-enum
446cf2
-{
446cf2
-  /* The integer bit array index for the first set of preferred feature
446cf2
-     bits.  */
446cf2
-  PREFERRED_FEATURE_INDEX_1 = 0,
446cf2
-  /* The current maximum size of the feature integer bit array.  */
446cf2
-  PREFERRED_FEATURE_INDEX_MAX
446cf2
-};
446cf2
+#ifndef _SYS_PLATFORM_X86_H
446cf2
+#define _SYS_PLATFORM_X86_H
446cf2
 
446cf2
 enum
446cf2
 {
446cf2
@@ -76,73 +68,32 @@ struct cpu_features
446cf2
 {
446cf2
   struct cpu_features_basic basic;
446cf2
   struct cpuid_features features[COMMON_CPUID_INDEX_MAX];
446cf2
-  unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX];
446cf2
-  /* The state size for XSAVEC or XSAVE.  The type must be unsigned long
446cf2
-     int so that we use
446cf2
-
446cf2
-	sub xsave_state_size_offset(%rip) %RSP_LP
446cf2
-
446cf2
-     in _dl_runtime_resolve.  */
446cf2
-  unsigned long int xsave_state_size;
446cf2
-  /* The full state size for XSAVE when XSAVEC is disabled by
446cf2
-
446cf2
-     GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC
446cf2
-   */
446cf2
-  unsigned int xsave_state_full_size;
446cf2
-  /* Data cache size for use in memory and string routines, typically
446cf2
-     L1 size.  */
446cf2
-  unsigned long int data_cache_size;
446cf2
-  /* Shared cache size for use in memory and string routines, typically
446cf2
-     L2 or L3 size.  */
446cf2
-  unsigned long int shared_cache_size;
446cf2
-  /* Threshold to use non temporal store.  */
446cf2
-  unsigned long int non_temporal_threshold;
446cf2
-  /* Threshold to use "rep movsb".  */
446cf2
-  unsigned long int rep_movsb_threshold;
446cf2
-  /* Threshold to use "rep stosb".  */
446cf2
-  unsigned long int rep_stosb_threshold;
446cf2
 };
446cf2
 
446cf2
-/* Used from outside of glibc to get access to the CPU features
446cf2
-   structure.  */
446cf2
-extern const struct cpu_features *__get_cpu_features (void)
446cf2
+/* Get a pointer to the CPU features structure.  */
446cf2
+extern const struct cpu_features *__x86_get_cpu_features (unsigned int)
446cf2
      __attribute__ ((const));
446cf2
 
446cf2
-/* Only used directly in cpu-features.c.  */
446cf2
 #define CPU_FEATURE_CHECK_P(ptr, name, check) \
446cf2
   ((ptr->features[index_cpu_##name].check.reg_##name \
446cf2
     & bit_cpu_##name) != 0)
446cf2
-#define CPU_FEATURE_SET(ptr, name) \
446cf2
-  ptr->features[index_cpu_##name].usable.reg_##name |= bit_cpu_##name;
446cf2
-#define CPU_FEATURE_UNSET(ptr, name) \
446cf2
-  ptr->features[index_cpu_##name].usable.reg_##name &= ~bit_cpu_##name;
446cf2
-#define CPU_FEATURE_SET_USABLE(ptr, name) \
446cf2
-  ptr->features[index_cpu_##name].usable.reg_##name \
446cf2
-     |= ptr->features[index_cpu_##name].cpuid.reg_##name & bit_cpu_##name;
446cf2
-#define CPU_FEATURE_PREFERRED_P(ptr, name) \
446cf2
-  ((ptr->preferred[index_arch_##name] & bit_arch_##name) != 0)
446cf2
 #define CPU_FEATURE_CPU_P(ptr, name) \
446cf2
   CPU_FEATURE_CHECK_P (ptr, name, cpuid)
446cf2
 #define CPU_FEATURE_USABLE_P(ptr, name) \
446cf2
   CPU_FEATURE_CHECK_P (ptr, name, usable)
446cf2
 
446cf2
 /* HAS_CPU_FEATURE evaluates to true if CPU supports the feature.  */
446cf2
-#define HAS_CPU_FEATURE(name) \
446cf2
-  CPU_FEATURE_CPU_P (__get_cpu_features (), name)
446cf2
+#define HAS_CPU_FEATURE(name)					\
446cf2
+  (__extension__						\
446cf2
+   ({ const struct cpu_features *__ptr =			\
446cf2
+	__x86_get_cpu_features (COMMON_CPUID_INDEX_MAX);	\
446cf2
+      __ptr && CPU_FEATURE_CPU_P (__ptr, name); }))
446cf2
 /* CPU_FEATURE_USABLE evaluates to true if the feature is usable.  */
446cf2
-#define CPU_FEATURE_USABLE(name) \
446cf2
-  CPU_FEATURE_USABLE_P (__get_cpu_features (), name)
446cf2
-/* CPU_FEATURE_PREFER evaluates to true if we prefer the feature at
446cf2
-   runtime.  */
446cf2
-#define CPU_FEATURE_PREFERRED(name) \
446cf2
-  CPU_FEATURE_PREFERRED_P(__get_cpu_features (), name)
446cf2
-
446cf2
-#define CPU_FEATURES_CPU_P(ptr, name) \
446cf2
-  CPU_FEATURE_CPU_P (ptr, name)
446cf2
-#define CPU_FEATURES_ARCH_P(ptr, name) \
446cf2
-  CPU_FEATURE_PREFERRED_P (ptr, name)
446cf2
-#define HAS_ARCH_FEATURE(name) \
446cf2
-  CPU_FEATURE_PREFERRED (name)
446cf2
+#define CPU_FEATURE_USABLE(name)				\
446cf2
+  (__extension__						\
446cf2
+   ({ const struct cpu_features *__ptr =			\
446cf2
+	__x86_get_cpu_features (COMMON_CPUID_INDEX_MAX);	\
446cf2
+      __ptr && CPU_FEATURE_USABLE_P (__ptr, name); }))
446cf2
 
446cf2
 /* CPU features.  */
446cf2
 
446cf2
@@ -787,71 +738,4 @@ extern const struct cpu_features *__get_cpu_features (void)
446cf2
 /* EAX.  */
446cf2
 #define reg_AVX512_BF16		eax
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		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Fast_Copy_Backward		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Slow_BSF			PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Fast_Unaligned_Load		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_PMINUB_for_stringop 	PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Fast_Unaligned_Copy		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_I586				PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_I686				PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Slow_SSE4_2			PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_AVX_Fast_Unaligned_Load	PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_MAP_32BIT_EXEC	PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_No_VZEROUPPER		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_ERMS			PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_No_AVX512		PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_MathVec_Prefer_No_AVX512	PREFERRED_FEATURE_INDEX_1
446cf2
-#define index_arch_Prefer_FSRM			PREFERRED_FEATURE_INDEX_1
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
-#define bit_XTILECFG_state	(1u << 17)
446cf2
-#define bit_XTILEDATA_state	(1u << 18)
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
-#ifdef __x86_64__
446cf2
-# define HAS_CPUID 1
446cf2
-#elif (defined __i586__ || defined __pentium__	\
446cf2
-       || defined __geode__ || defined __k6__)
446cf2
-# define HAS_CPUID 1
446cf2
-# define HAS_I586 1
446cf2
-# define HAS_I686 HAS_ARCH_FEATURE (I686)
446cf2
-#elif defined __i486__
446cf2
-# define HAS_CPUID 0
446cf2
-# define HAS_I586 HAS_ARCH_FEATURE (I586)
446cf2
-# define HAS_I686 HAS_ARCH_FEATURE (I686)
446cf2
-#else
446cf2
-# define HAS_CPUID 1
446cf2
-# define HAS_I586 1
446cf2
-# define HAS_I686 1
446cf2
-#endif
446cf2
-
446cf2
-#endif  /* cpu_features_h */
446cf2
+#endif  /* _SYS_PLATFORM_X86_H */
446cf2
diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
446cf2
new file mode 100644
446cf2
index 0000000000000000..96277284d15a0690
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
446cf2
@@ -0,0 +1,250 @@
446cf2
+/* Test CPU feature data against /proc/cpuinfo.
446cf2
+   This file is part of the GNU C Library.
446cf2
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <https://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#include <sys/platform/x86.h>
446cf2
+#include <stdio.h>
446cf2
+#include <stdlib.h>
446cf2
+#include <string.h>
446cf2
+
446cf2
+static char *cpu_flags;
446cf2
+
446cf2
+/* Search for flags in /proc/cpuinfo and store line
446cf2
+   in cpu_flags.  */
446cf2
+void
446cf2
+get_cpuinfo (void)
446cf2
+{
446cf2
+  FILE *f;
446cf2
+  char *line = NULL;
446cf2
+  size_t len = 0;
446cf2
+  ssize_t read;
446cf2
+
446cf2
+  f = fopen ("/proc/cpuinfo", "r");
446cf2
+  if (f == NULL)
446cf2
+    {
446cf2
+      printf ("cannot open /proc/cpuinfo\n");
446cf2
+      exit (1);
446cf2
+    }
446cf2
+
446cf2
+  while ((read = getline (&line, &len, f)) != -1)
446cf2
+    {
446cf2
+      if (strncmp (line, "flags", 5) == 0)
446cf2
+       {
446cf2
+         cpu_flags = strdup (line);
446cf2
+         break;
446cf2
+       }
446cf2
+    }
446cf2
+  fclose (f);
446cf2
+  free (line);
446cf2
+}
446cf2
+
446cf2
+int
446cf2
+check_proc (const char *proc_name, int flag, int usable, const char *name)
446cf2
+{
446cf2
+  int found = 0;
446cf2
+
446cf2
+  printf ("Checking %s:\n", name);
446cf2
+  if (!usable)
446cf2
+    {
446cf2
+      printf ("  %s: insufficient usable info, skipped\n", name);
446cf2
+      return 0;
446cf2
+    }
446cf2
+  printf ("  %s: %d\n", name, flag);
446cf2
+  if (strstr (cpu_flags, proc_name) != NULL)
446cf2
+    found = 1;
446cf2
+  printf ("  cpuinfo (%s): %d\n", proc_name, found);
446cf2
+
446cf2
+  if (found != flag)
446cf2
+    printf (" *** failure ***\n");
446cf2
+
446cf2
+  return (found != flag);
446cf2
+}
446cf2
+
446cf2
+#define CHECK_PROC(str, name) \
446cf2
+  check_proc (#str, HAS_CPU_FEATURE (name), CPU_FEATURE_USABLE (name), \
446cf2
+	      "HAS_CPU_FEATURE (" #name ")");
446cf2
+
446cf2
+static int
446cf2
+do_test (int argc, char **argv)
446cf2
+{
446cf2
+  int fails = 0;
446cf2
+
446cf2
+  get_cpuinfo ();
446cf2
+  fails += CHECK_PROC (acpi, ACPI);
446cf2
+  fails += CHECK_PROC (adx, ADX);
446cf2
+  fails += CHECK_PROC (apic, APIC);
446cf2
+  fails += CHECK_PROC (aes, AES);
446cf2
+  fails += CHECK_PROC (amx_bf16, AMX_BF16);
446cf2
+  fails += CHECK_PROC (amx_int8, AMX_INT8);
446cf2
+  fails += CHECK_PROC (amx_tile, AMX_TILE);
446cf2
+  fails += CHECK_PROC (arch_capabilities, ARCH_CAPABILITIES);
446cf2
+  fails += CHECK_PROC (avx, AVX);
446cf2
+  fails += CHECK_PROC (avx2, AVX2);
446cf2
+  fails += CHECK_PROC (avx512_4fmaps, AVX512_4FMAPS);
446cf2
+  fails += CHECK_PROC (avx512_4vnniw, AVX512_4VNNIW);
446cf2
+  fails += CHECK_PROC (avx512_bf16, AVX512_BF16);
446cf2
+  fails += CHECK_PROC (avx512_bitalg, AVX512_BITALG);
446cf2
+  fails += CHECK_PROC (avx512ifma, AVX512_IFMA);
446cf2
+  fails += CHECK_PROC (avx512_vbmi, AVX512_VBMI);
446cf2
+  fails += CHECK_PROC (avx512_vbmi2, AVX512_VBMI2);
446cf2
+  fails += CHECK_PROC (avx512_vnni, AVX512_VNNI);
446cf2
+  fails += CHECK_PROC (avx512_vp2intersect, AVX512_VP2INTERSECT);
446cf2
+  fails += CHECK_PROC (avx512_vpopcntdq, AVX512_VPOPCNTDQ);
446cf2
+  fails += CHECK_PROC (avx512bw, AVX512BW);
446cf2
+  fails += CHECK_PROC (avx512cd, AVX512CD);
446cf2
+  fails += CHECK_PROC (avx512er, AVX512ER);
446cf2
+  fails += CHECK_PROC (avx512dq, AVX512DQ);
446cf2
+  fails += CHECK_PROC (avx512f, AVX512F);
446cf2
+  fails += CHECK_PROC (avx512pf, AVX512PF);
446cf2
+  fails += CHECK_PROC (avx512vl, AVX512VL);
446cf2
+  fails += CHECK_PROC (bmi1, BMI1);
446cf2
+  fails += CHECK_PROC (bmi2, BMI2);
446cf2
+  fails += CHECK_PROC (cldemote, CLDEMOTE);
446cf2
+  fails += CHECK_PROC (clflushopt, CLFLUSHOPT);
446cf2
+  fails += CHECK_PROC (clflush, CLFSH);
446cf2
+  fails += CHECK_PROC (clwb, CLWB);
446cf2
+  fails += CHECK_PROC (cmov, CMOV);
446cf2
+  fails += CHECK_PROC (cx16, CMPXCHG16B);
446cf2
+  fails += CHECK_PROC (cnxt_id, CNXT_ID);
446cf2
+  fails += CHECK_PROC (core_capabilities, CORE_CAPABILITIES);
446cf2
+  fails += CHECK_PROC (cx8, CX8);
446cf2
+  fails += CHECK_PROC (dca, DCA);
446cf2
+  fails += CHECK_PROC (de, DE);
446cf2
+  fails += CHECK_PROC (zero_fcs_fds, DEPR_FPU_CS_DS);
446cf2
+  fails += CHECK_PROC (ds, DS);
446cf2
+  fails += CHECK_PROC (ds_cpl, DS_CPL);
446cf2
+  fails += CHECK_PROC (dtes64, DTES64);
446cf2
+  fails += CHECK_PROC (est, EIST);
446cf2
+  fails += CHECK_PROC (enqcmd, ENQCMD);
446cf2
+  fails += CHECK_PROC (erms, ERMS);
446cf2
+  fails += CHECK_PROC (f16c, F16C);
446cf2
+  fails += CHECK_PROC (fma, FMA);
446cf2
+  fails += CHECK_PROC (fma4, FMA4);
446cf2
+  fails += CHECK_PROC (fpu, FPU);
446cf2
+  fails += CHECK_PROC (fsgsbase, FSGSBASE);
446cf2
+  fails += CHECK_PROC (fsrm, FSRM);
446cf2
+  fails += CHECK_PROC (fxsr, FXSR);
446cf2
+  fails += CHECK_PROC (gfni, GFNI);
446cf2
+  fails += CHECK_PROC (hle, HLE);
446cf2
+  fails += CHECK_PROC (ht, HTT);
446cf2
+  fails += CHECK_PROC (hybrid, HYBRID);
446cf2
+  fails += CHECK_PROC (ibrs, IBRS_IBPB);
446cf2
+  fails += CHECK_PROC (ibt, IBT);
446cf2
+  fails += CHECK_PROC (invariant_tsc, INVARIANT_TSC);
446cf2
+  fails += CHECK_PROC (invpcid, INVPCID);
446cf2
+  fails += CHECK_PROC (flush_l1d, L1D_FLUSH);
446cf2
+  fails += CHECK_PROC (lahf_lm, LAHF64_SAHF64);
446cf2
+  fails += CHECK_PROC (lm, LM);
446cf2
+  fails += CHECK_PROC (lwp, LWP);
446cf2
+  fails += CHECK_PROC (abm, LZCNT);
446cf2
+  fails += CHECK_PROC (mca, MCA);
446cf2
+  fails += CHECK_PROC (mce, MCE);
446cf2
+  fails += CHECK_PROC (md_clear, MD_CLEAR);
446cf2
+  fails += CHECK_PROC (mmx, MMX);
446cf2
+  fails += CHECK_PROC (monitor, MONITOR);
446cf2
+  fails += CHECK_PROC (movbe, MOVBE);
446cf2
+  fails += CHECK_PROC (movdiri, MOVDIRI);
446cf2
+  fails += CHECK_PROC (movdir64b, MOVDIR64B);
446cf2
+  fails += CHECK_PROC (mpx, MPX);
446cf2
+  fails += CHECK_PROC (msr, MSR);
446cf2
+  fails += CHECK_PROC (mtrr, MTRR);
446cf2
+  fails += CHECK_PROC (nx, NX);
446cf2
+  fails += CHECK_PROC (ospke, OSPKE);
446cf2
+#if 0
446cf2
+  /* NB: /proc/cpuinfo doesn't report this feature.  */
446cf2
+  fails += CHECK_PROC (osxsave, OSXSAVE);
446cf2
+#endif
446cf2
+  fails += CHECK_PROC (pae, PAE);
446cf2
+  fails += CHECK_PROC (pdpe1gb, PAGE1GB);
446cf2
+  fails += CHECK_PROC (pat, PAT);
446cf2
+  fails += CHECK_PROC (pbe, PBE);
446cf2
+  fails += CHECK_PROC (pcid, PCID);
446cf2
+  fails += CHECK_PROC (pclmulqdq, PCLMULQDQ);
446cf2
+  fails += CHECK_PROC (pconfig, PCONFIG);
446cf2
+  fails += CHECK_PROC (pdcm, PDCM);
446cf2
+  fails += CHECK_PROC (pge, PGE);
446cf2
+  fails += CHECK_PROC (pks, PKS);
446cf2
+  fails += CHECK_PROC (pku, PKU);
446cf2
+  fails += CHECK_PROC (popcnt, POPCNT);
446cf2
+  fails += CHECK_PROC (3dnowprefetch, PREFETCHW);
446cf2
+  fails += CHECK_PROC (prefetchwt1, PREFETCHWT1);
446cf2
+  fails += CHECK_PROC (pse, PSE);
446cf2
+  fails += CHECK_PROC (pse36, PSE_36);
446cf2
+  fails += CHECK_PROC (psn, PSN);
446cf2
+  fails += CHECK_PROC (rdpid, RDPID);
446cf2
+  fails += CHECK_PROC (rdrand, RDRAND);
446cf2
+  fails += CHECK_PROC (rdseed, RDSEED);
446cf2
+  fails += CHECK_PROC (rdt_a, RDT_A);
446cf2
+  fails += CHECK_PROC (cqm, RDT_M);
446cf2
+  fails += CHECK_PROC (rdtscp, RDTSCP);
446cf2
+  fails += CHECK_PROC (rtm, RTM);
446cf2
+  fails += CHECK_PROC (sdbg, SDBG);
446cf2
+  fails += CHECK_PROC (sep, SEP);
446cf2
+  fails += CHECK_PROC (serialize, SERIALIZE);
446cf2
+  fails += CHECK_PROC (sgx, SGX);
446cf2
+  fails += CHECK_PROC (sgx_lc, SGX_LC);
446cf2
+  fails += CHECK_PROC (sha_ni, SHA);
446cf2
+  fails += CHECK_PROC (shstk, SHSTK);
446cf2
+  fails += CHECK_PROC (smap, SMAP);
446cf2
+  fails += CHECK_PROC (smep, SMEP);
446cf2
+  fails += CHECK_PROC (smx, SMX);
446cf2
+  fails += CHECK_PROC (ss, SS);
446cf2
+  fails += CHECK_PROC (ssbd, SSBD);
446cf2
+  fails += CHECK_PROC (sse, SSE);
446cf2
+  fails += CHECK_PROC (sse2, SSE2);
446cf2
+  fails += CHECK_PROC (sse3, SSE3);
446cf2
+  fails += CHECK_PROC (sse4_1, SSE4_1);
446cf2
+  fails += CHECK_PROC (sse4_2, SSE4_2);
446cf2
+  fails += CHECK_PROC (sse4a, SSE4A);
446cf2
+  fails += CHECK_PROC (ssse3, SSSE3);
446cf2
+  fails += CHECK_PROC (stibp, STIBP);
446cf2
+  fails += CHECK_PROC (svm, SVM);
446cf2
+#ifdef __x86_64__
446cf2
+  /* NB: SYSCALL_SYSRET is 64-bit only.  */
446cf2
+  fails += CHECK_PROC (syscall, SYSCALL_SYSRET);
446cf2
+#endif
446cf2
+  fails += CHECK_PROC (tbm, TBM);
446cf2
+  fails += CHECK_PROC (tm, TM);
446cf2
+  fails += CHECK_PROC (tm2, TM2);
446cf2
+  fails += CHECK_PROC (intel_pt, TRACE);
446cf2
+  fails += CHECK_PROC (tsc, TSC);
446cf2
+  fails += CHECK_PROC (tsc_adjust, TSC_ADJUST);
446cf2
+  fails += CHECK_PROC (tsc_deadline, TSC_DEADLINE);
446cf2
+  fails += CHECK_PROC (tsxldtrk, TSXLDTRK);
446cf2
+  fails += CHECK_PROC (umip, UMIP);
446cf2
+  fails += CHECK_PROC (vaes, VAES);
446cf2
+  fails += CHECK_PROC (vme, VME);
446cf2
+  fails += CHECK_PROC (vmx, VMX);
446cf2
+  fails += CHECK_PROC (vpclmulqdq, VPCLMULQDQ);
446cf2
+  fails += CHECK_PROC (waitpkg, WAITPKG);
446cf2
+  fails += CHECK_PROC (wbnoinvd, WBNOINVD);
446cf2
+  fails += CHECK_PROC (x2apic, X2APIC);
446cf2
+  fails += CHECK_PROC (xfd, XFD);
446cf2
+  fails += CHECK_PROC (xgetbv1, XGETBV_ECX_1);
446cf2
+  fails += CHECK_PROC (xop, XOP);
446cf2
+  fails += CHECK_PROC (xsave, XSAVE);
446cf2
+  fails += CHECK_PROC (xsavec, XSAVEC);
446cf2
+  fails += CHECK_PROC (xsaveopt, XSAVEOPT);
446cf2
+  fails += CHECK_PROC (xsaves, XSAVES);
446cf2
+  fails += CHECK_PROC (xtpr, XTPRUPDCTRL);
446cf2
+
446cf2
+  printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
446cf2
+
446cf2
+  return (fails != 0);
446cf2
+}
446cf2
+
446cf2
+#include "../../../test-skeleton.c"
446cf2
diff --git a/sysdeps/x86/tst-cpu-features-supports.c b/sysdeps/x86/tst-cpu-features-supports.c
446cf2
new file mode 100644
446cf2
index 0000000000000000..bf881b531f4bc2ed
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/x86/tst-cpu-features-supports.c
446cf2
@@ -0,0 +1,192 @@
446cf2
+/* Test CPU feature data against __builtin_cpu_supports.
446cf2
+   This file is part of the GNU C Library.
446cf2
+   Copyright (C) 2020 Free Software Foundation, Inc.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <https://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#include <sys/platform/x86.h>
446cf2
+#include <stdio.h>
446cf2
+
446cf2
+int
446cf2
+check_supports (int supports, int usable, const char *supports_name,
446cf2
+		const char *name)
446cf2
+{
446cf2
+  printf ("Checking %s:\n", name);
446cf2
+  printf ("  %s: %d\n", name, usable);
446cf2
+  printf ("  __builtin_cpu_supports (%s): %d\n",
446cf2
+	  supports_name, supports);
446cf2
+
446cf2
+  if ((supports != 0) != (usable != 0))
446cf2
+    {
446cf2
+      printf (" *** failure ***\n");
446cf2
+      return 1;
446cf2
+    }
446cf2
+
446cf2
+  return 0;
446cf2
+}
446cf2
+
446cf2
+#define CHECK_SUPPORTS(str, name) \
446cf2
+  check_supports (__builtin_cpu_supports (#str), \
446cf2
+		  CPU_FEATURE_USABLE (name), \
446cf2
+		  #str, "HAS_CPU_FEATURE (" #name ")");
446cf2
+
446cf2
+static int
446cf2
+do_test (int argc, char **argv)
446cf2
+{
446cf2
+  int fails = 0;
446cf2
+
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (adx, ADX);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (6, 0)
446cf2
+  fails += CHECK_SUPPORTS (aes, AES);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 1)
446cf2
+  fails += CHECK_SUPPORTS (amx_bf16, AMX_BF16);
446cf2
+  fails += CHECK_SUPPORTS (amx_int8, AMX_INT8);
446cf2
+  fails += CHECK_SUPPORTS (amx_tile, AMX_TILE);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (avx, AVX);
446cf2
+  fails += CHECK_SUPPORTS (avx2, AVX2);
446cf2
+#if __GNUC_PREREQ (7, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx5124fmaps, AVX512_4FMAPS);
446cf2
+  fails += CHECK_SUPPORTS (avx5124vnniw, AVX512_4VNNIW);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (10, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512bf16, AVX512_BF16);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (8, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512bitalg, AVX512_BITALG);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (6, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512ifma, AVX512_IFMA);
446cf2
+  fails += CHECK_SUPPORTS (avx512vbmi, AVX512_VBMI);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (8, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512vbmi2, AVX512_VBMI2);
446cf2
+  fails += CHECK_SUPPORTS (avx512vnni, AVX512_VNNI);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (10, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512vp2intersect, AVX512_VP2INTERSECT);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (7, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512vpopcntdq, AVX512_VPOPCNTDQ);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (6, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512bw, AVX512BW);
446cf2
+  fails += CHECK_SUPPORTS (avx512cd, AVX512CD);
446cf2
+  fails += CHECK_SUPPORTS (avx512er, AVX512ER);
446cf2
+  fails += CHECK_SUPPORTS (avx512dq, AVX512DQ);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (5, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512f, AVX512F);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (6, 0)
446cf2
+  fails += CHECK_SUPPORTS (avx512pf, AVX512PF);
446cf2
+  fails += CHECK_SUPPORTS (avx512vl, AVX512VL);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (5, 0)
446cf2
+  fails += CHECK_SUPPORTS (bmi, BMI1);
446cf2
+  fails += CHECK_SUPPORTS (bmi2, BMI2);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (cldemote, CLDEMOTE);
446cf2
+  fails += CHECK_SUPPORTS (clflushopt, CLFLUSHOPT);
446cf2
+  fails += CHECK_SUPPORTS (clwb, CLWB);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (cmov, CMOV);
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (cmpxchg16b, CMPXCHG16B);
446cf2
+  fails += CHECK_SUPPORTS (cmpxchg8b, CX8);
446cf2
+  fails += CHECK_SUPPORTS (enqcmd, ENQCMD);
446cf2
+  fails += CHECK_SUPPORTS (f16c, F16C);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (4, 9)
446cf2
+  fails += CHECK_SUPPORTS (fma, FMA);
446cf2
+  fails += CHECK_SUPPORTS (fma4, FMA4);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (fsgsbase, FSGSBASE);
446cf2
+  fails += CHECK_SUPPORTS (fxsave, FXSR);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (8, 0)
446cf2
+  fails += CHECK_SUPPORTS (gfni, GFNI);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (hle, HLE);
446cf2
+  fails += CHECK_SUPPORTS (ibt, IBT);
446cf2
+  fails += CHECK_SUPPORTS (lahf_lm, LAHF64_SAHF64);
446cf2
+  fails += CHECK_SUPPORTS (lm, LM);
446cf2
+  fails += CHECK_SUPPORTS (lwp, LWP);
446cf2
+  fails += CHECK_SUPPORTS (lzcnt, LZCNT);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (mmx, MMX);
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (movbe, MOVBE);
446cf2
+  fails += CHECK_SUPPORTS (movdiri, MOVDIRI);
446cf2
+  fails += CHECK_SUPPORTS (movdir64b, MOVDIR64B);
446cf2
+  fails += CHECK_SUPPORTS (osxsave, OSXSAVE);
446cf2
+  fails += CHECK_SUPPORTS (pconfig, PCONFIG);
446cf2
+  fails += CHECK_SUPPORTS (pku, PKU);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (popcnt, POPCNT);
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (prefetchwt1, PREFETCHWT1);
446cf2
+  fails += CHECK_SUPPORTS (rdpid, RDPID);
446cf2
+  fails += CHECK_SUPPORTS (rdrnd, RDRAND);
446cf2
+  fails += CHECK_SUPPORTS (rdseed, RDSEED);
446cf2
+  fails += CHECK_SUPPORTS (rtm, RTM);
446cf2
+  fails += CHECK_SUPPORTS (serialize, SERIALIZE);
446cf2
+  fails += CHECK_SUPPORTS (sha, SHA);
446cf2
+  fails += CHECK_SUPPORTS (shstk, SHSTK);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (sse, SSE);
446cf2
+  fails += CHECK_SUPPORTS (sse2, SSE2);
446cf2
+  fails += CHECK_SUPPORTS (sse3, SSE3);
446cf2
+  fails += CHECK_SUPPORTS (sse4.1, SSE4_1);
446cf2
+  fails += CHECK_SUPPORTS (sse4.2, SSE4_2);
446cf2
+#if __GNUC_PREREQ (4, 9)
446cf2
+  fails += CHECK_SUPPORTS (sse4a, SSE4A);
446cf2
+#endif
446cf2
+  fails += CHECK_SUPPORTS (ssse3, SSSE3);
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (tbm, TBM);
446cf2
+  fails += CHECK_SUPPORTS (tsxldtrk, TSXLDTRK);
446cf2
+  fails += CHECK_SUPPORTS (vaes, VAES);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (8, 0)
446cf2
+  fails += CHECK_SUPPORTS (vpclmulqdq, VPCLMULQDQ);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (waitpkg, WAITPKG);
446cf2
+  fails += CHECK_SUPPORTS (wbnoinvd, WBNOINVD);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (4, 9)
446cf2
+  fails += CHECK_SUPPORTS (xop, XOP);
446cf2
+#endif
446cf2
+#if __GNUC_PREREQ (11, 0)
446cf2
+  fails += CHECK_SUPPORTS (xsave, XSAVE);
446cf2
+  fails += CHECK_SUPPORTS (xsavec, XSAVEC);
446cf2
+  fails += CHECK_SUPPORTS (xsaveopt, XSAVEOPT);
446cf2
+  fails += CHECK_SUPPORTS (xsaves, XSAVES);
446cf2
+#endif
446cf2
+
446cf2
+  printf ("%d differences between __builtin_cpu_supports and glibc code.\n",
446cf2
+	  fails);
446cf2
+
446cf2
+  return (fails != 0);
446cf2
+}
446cf2
+
446cf2
+#include "../../../test-skeleton.c"
446cf2
diff --git a/sysdeps/x86/tst-get-cpu-features.c b/sysdeps/x86/tst-get-cpu-features.c
446cf2
index 582b125a2dad3f21..95e0d33f6c7eeace 100644
446cf2
--- a/sysdeps/x86/tst-get-cpu-features.c
446cf2
+++ b/sysdeps/x86/tst-get-cpu-features.c
446cf2
@@ -1,5 +1,5 @@
446cf2
-/* Test case for x86 __get_cpu_features interface
446cf2
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
446cf2
+/* Test case for __x86_get_cpu_features interface
446cf2
+   Copyright (C) 2015-2020 Free Software Foundation, Inc.
446cf2
    This file is part of the GNU C Library.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
@@ -18,7 +18,7 @@
446cf2
 
446cf2
 #include <stdlib.h>
446cf2
 #include <stdio.h>
446cf2
-#include <cpu-features.h>
446cf2
+#include <sys/platform/x86.h>
446cf2
 #include <support/check.h>
446cf2
 
446cf2
 #define CHECK_CPU_FEATURE(name)		\
446cf2
@@ -44,7 +44,7 @@ static const char * const cpu_kinds[] =
446cf2
 static int
446cf2
 do_test (void)
446cf2
 {
446cf2
-  const struct cpu_features *cpu_features = __get_cpu_features ();
446cf2
+  const struct cpu_features *cpu_features = __x86_get_cpu_features (0);
446cf2
 
446cf2
   switch (cpu_features->basic.kind)
446cf2
     {
446cf2
diff --git a/sysdeps/x86_64/fpu/math-tests-arch.h b/sysdeps/x86_64/fpu/math-tests-arch.h
446cf2
index 61955d70863321fd..c908eac6b4fff16d 100644
446cf2
--- a/sysdeps/x86_64/fpu/math-tests-arch.h
446cf2
+++ b/sysdeps/x86_64/fpu/math-tests-arch.h
446cf2
@@ -16,7 +16,7 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
-#include <cpu-features.h>
446cf2
+#include <sys/platform/x86.h>
446cf2
 
446cf2
 #if defined REQUIRE_AVX
446cf2
 
446cf2
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
446cf2
index 395e432c092ca17c..9477538af46787a5 100644
446cf2
--- a/sysdeps/x86_64/multiarch/Makefile
446cf2
+++ b/sysdeps/x86_64/multiarch/Makefile
446cf2
@@ -1,7 +1,3 @@
446cf2
-ifeq ($(subdir),csu)
446cf2
-tests += test-multiarch
446cf2
-endif
446cf2
-
446cf2
 ifeq ($(subdir),string)
446cf2
 
446cf2
 sysdep_routines += strncat-c stpncpy-c strncpy-c \
446cf2
diff --git a/sysdeps/x86_64/multiarch/test-multiarch.c b/sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
deleted file mode 100644
446cf2
index cc2ea56a6753402d..0000000000000000
446cf2
--- a/sysdeps/x86_64/multiarch/test-multiarch.c
446cf2
+++ /dev/null
446cf2
@@ -1,96 +0,0 @@
446cf2
-/* Test CPU feature data.
446cf2
-   This file is part of the GNU C Library.
446cf2
-   Copyright (C) 2012-2018 Free Software Foundation, Inc.
446cf2
-
446cf2
-   The GNU C Library is free software; you can redistribute it and/or
446cf2
-   modify it under the terms of the GNU Lesser General Public
446cf2
-   License as published by the Free Software Foundation; either
446cf2
-   version 2.1 of the License, or (at your option) any later version.
446cf2
-
446cf2
-   The GNU C Library is distributed in the hope that it will be useful,
446cf2
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
-   Lesser General Public License for more details.
446cf2
-
446cf2
-   You should have received a copy of the GNU Lesser General Public
446cf2
-   License along with the GNU C Library; if not, see
446cf2
-   <http://www.gnu.org/licenses/>.  */
446cf2
-
446cf2
-#include <cpu-features.h>
446cf2
-#include <stdio.h>
446cf2
-#include <stdlib.h>
446cf2
-#include <string.h>
446cf2
-
446cf2
-static char *cpu_flags;
446cf2
-
446cf2
-/* Search for flags in /proc/cpuinfo and store line
446cf2
-   in cpu_flags.  */
446cf2
-void
446cf2
-get_cpuinfo (void)
446cf2
-{
446cf2
-  FILE *f;
446cf2
-  char *line = NULL;
446cf2
-  size_t len = 0;
446cf2
-  ssize_t read;
446cf2
-
446cf2
-  f = fopen ("/proc/cpuinfo", "r");
446cf2
-  if (f == NULL)
446cf2
-    {
446cf2
-      printf ("cannot open /proc/cpuinfo\n");
446cf2
-      exit (1);
446cf2
-    }
446cf2
-
446cf2
-  while ((read = getline (&line, &len, f)) != -1)
446cf2
-    {
446cf2
-      if (strncmp (line, "flags", 5) == 0)
446cf2
-       {
446cf2
-         cpu_flags = strdup (line);
446cf2
-         break;
446cf2
-       }
446cf2
-    }
446cf2
-  fclose (f);
446cf2
-  free (line);
446cf2
-}
446cf2
-
446cf2
-int
446cf2
-check_proc (const char *proc_name, int flag, const char *name)
446cf2
-{
446cf2
-  int found = 0;
446cf2
-
446cf2
-  printf ("Checking %s:\n", name);
446cf2
-  printf ("  init-arch %d\n", flag);
446cf2
-  if (strstr (cpu_flags, proc_name) != NULL)
446cf2
-    found = 1;
446cf2
-  printf ("  cpuinfo (%s) %d\n", proc_name, found);
446cf2
-
446cf2
-  if (found != flag)
446cf2
-    printf (" *** failure ***\n");
446cf2
-
446cf2
-  return (found != flag);
446cf2
-}
446cf2
-
446cf2
-static int
446cf2
-do_test (int argc, char **argv)
446cf2
-{
446cf2
-  int fails;
446cf2
-
446cf2
-  get_cpuinfo ();
446cf2
-  fails = check_proc ("avx", CPU_FEATURE_USABLE (AVX),
446cf2
-		      "CPU_FEATURE_USABLE (AVX)");
446cf2
-  fails += check_proc ("fma4", CPU_FEATURE_USABLE (FMA4),
446cf2
-		       "CPU_FEATURE_USABLE (FMA4)");
446cf2
-  fails += check_proc ("sse4_2", CPU_FEATURE_USABLE (SSE4_2),
446cf2
-		       "CPU_FEATURE_USABLE (SSE4_2)");
446cf2
-  fails += check_proc ("sse4_1", CPU_FEATURE_USABLE (SSE4_1)
446cf2
-		       , "CPU_FEATURE_USABLE (SSE4_1)");
446cf2
-  fails += check_proc ("ssse3", CPU_FEATURE_USABLE (SSSE3),
446cf2
-		       "CPU_FEATURE_USABLE (SSSE3)");
446cf2
-  fails += check_proc ("popcnt", CPU_FEATURE_USABLE (POPCNT),
446cf2
-		       "CPU_FEATURE_USABLE (POPCNT)");
446cf2
-
446cf2
-  printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
446cf2
-
446cf2
-  return (fails != 0);
446cf2
-}
446cf2
-
446cf2
-#include "../../../test-skeleton.c"