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