glibc/sysdeps/x86/tst-get-cpu-features.c

411 lines
15 KiB
C
Raw Normal View History

<sys/platform/x86.h>: Remove the C preprocessor magic In <sys/platform/x86.h>, define CPU features as enum instead of using the C preprocessor magic to make it easier to wrap this functionality in other languages. Move the C preprocessor magic to internal header for better GCC codegen when more than one features are checked in a single expression as in x86-64 dl-hwcaps-subdirs.c. 1. Rename COMMON_CPUID_INDEX_XXX to CPUID_INDEX_XXX. 2. Move CPUID_INDEX_MAX to sysdeps/x86/include/cpu-features.h. 3. Remove struct cpu_features and __x86_get_cpu_features from <sys/platform/x86.h>. 4. Add __x86_get_cpuid_feature_leaf to <sys/platform/x86.h> and put it in libc. 5. Make __get_cpu_features() private to glibc. 6. Replace __x86_get_cpu_features(N) with __get_cpu_features(). 7. Add _dl_x86_get_cpu_features to GLIBC_PRIVATE. 8. Use a single enum index for each CPU feature detection. 9. Pass the CPUID feature leaf to __x86_get_cpuid_feature_leaf. 10. Return zero struct cpuid_feature for the older glibc binary with a smaller CPUID_INDEX_MAX [BZ #27104]. 11. Inside glibc, use the C preprocessor magic so that cpu_features data can be loaded just once leading to more compact code for glibc. 256 bits are used for each CPUID leaf. Some leaves only contain a few features. We can add exceptions to such leaves. But it will increase code sizes and it is harder to provide backward/forward compatibilities when new features are added to such leaves in the future. When new leaves are added, _rtld_global_ro offsets will change which leads to race condition during in-place updates. We may avoid in-place updates by 1. Rename the old glibc. 2. Install the new glibc. 3. Remove the old glibc. NB: A function, __x86_get_cpuid_feature_leaf , is used to avoid the copy relocation issue with IFUNC resolver as shown in IFUNC resolver tests.
2020-12-25 15:30:46 +00:00
/* Test case for <sys/platform/x86.h> interface
Copyright (C) 2015-2024 Free Software Foundation, Inc.
Add _dl_x86_cpu_features to rtld_global This patch adds _dl_x86_cpu_features to rtld_global in x86 ld.so and initializes it early before __libc_start_main is called so that cpu_features is always available when it is used and we can avoid calling __init_cpu_features in IFUNC selectors. * sysdeps/i386/dl-machine.h: Include <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/i386/dl-procinfo.c (_dl_x86_cpu_features): New. * sysdeps/i386/i686/cacheinfo.c (DISABLE_PREFERRED_MEMORY_INSTRUCTION): Removed. * sysdeps/i386/i686/multiarch/Makefile (aux): Remove init-arch. * sysdeps/i386/i686/multiarch/Versions: Removed. * sysdeps/i386/i686/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/i386/ldsodefs.h: Include <cpu-features.h>. * sysdeps/unix/sysv/linux/x86/Makefile (libpthread-sysdep_routines): Remove init-arch. * sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c: Include <sysdeps/x86_64/dl-procinfo.c> instead of sysdeps/generic/dl-procinfo.c>. * sysdeps/x86/Makefile [$(subdir) == csu] (gen-as-const-headers): Add cpu-features-offsets.sym and rtld-global-offsets.sym. [$(subdir) == elf] (sysdep-dl-routines): Add dl-get-cpu-features. [$(subdir) == elf] (tests): Add tst-get-cpu-features. [$(subdir) == elf] (tests-static): Add tst-get-cpu-features-static. * sysdeps/x86/Versions: New file. * sysdeps/x86/cpu-features-offsets.sym: Likewise. * sysdeps/x86/cpu-features.c: Likewise. * sysdeps/x86/cpu-features.h: Likewise. * sysdeps/x86/dl-get-cpu-features.c: Likewise. * sysdeps/x86/libc-start.c: Likewise. * sysdeps/x86/rtld-global-offsets.sym: Likewise. * sysdeps/x86/tst-get-cpu-features-static.c: Likewise. * sysdeps/x86/tst-get-cpu-features.c: Likewise. * sysdeps/x86_64/dl-procinfo.c: Likewise. * sysdeps/x86_64/cacheinfo.c (__cpuid_count): Removed. Assume USE_MULTIARCH is defined and don't check it. (is_intel): Replace __cpu_features with GLRO(dl_x86_cpu_features). (is_amd): Likewise. (max_cpuid): Likewise. (intel_check_word): Likewise. (__cache_sysconf): Don't call __init_cpu_features. (__x86_preferred_memory_instruction): Removed. (init_cacheinfo): Don't call __init_cpu_features. Replace __cpu_features with GLRO(dl_x86_cpu_features). * sysdeps/x86_64/dl-machine.h: <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/x86_64/ldsodefs.h: Include <cpu-features.h>. * sysdeps/x86_64/multiarch/Makefile (aux): Remove init-arch. * sysdeps/x86_64/multiarch/Versions: Removed. * sysdeps/x86_64/multiarch/cacheinfo.c: Likewise. * sysdeps/x86_64/multiarch/init-arch.c: Likewise. * sysdeps/x86_64/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/x86_64/multiarch/init-arch.h: Rewrite.
2015-08-13 10:37:47 +00:00
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
Prefer https to http for gnu.org and fsf.org URLs Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
<https://www.gnu.org/licenses/>. */
Add _dl_x86_cpu_features to rtld_global This patch adds _dl_x86_cpu_features to rtld_global in x86 ld.so and initializes it early before __libc_start_main is called so that cpu_features is always available when it is used and we can avoid calling __init_cpu_features in IFUNC selectors. * sysdeps/i386/dl-machine.h: Include <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/i386/dl-procinfo.c (_dl_x86_cpu_features): New. * sysdeps/i386/i686/cacheinfo.c (DISABLE_PREFERRED_MEMORY_INSTRUCTION): Removed. * sysdeps/i386/i686/multiarch/Makefile (aux): Remove init-arch. * sysdeps/i386/i686/multiarch/Versions: Removed. * sysdeps/i386/i686/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/i386/ldsodefs.h: Include <cpu-features.h>. * sysdeps/unix/sysv/linux/x86/Makefile (libpthread-sysdep_routines): Remove init-arch. * sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c: Include <sysdeps/x86_64/dl-procinfo.c> instead of sysdeps/generic/dl-procinfo.c>. * sysdeps/x86/Makefile [$(subdir) == csu] (gen-as-const-headers): Add cpu-features-offsets.sym and rtld-global-offsets.sym. [$(subdir) == elf] (sysdep-dl-routines): Add dl-get-cpu-features. [$(subdir) == elf] (tests): Add tst-get-cpu-features. [$(subdir) == elf] (tests-static): Add tst-get-cpu-features-static. * sysdeps/x86/Versions: New file. * sysdeps/x86/cpu-features-offsets.sym: Likewise. * sysdeps/x86/cpu-features.c: Likewise. * sysdeps/x86/cpu-features.h: Likewise. * sysdeps/x86/dl-get-cpu-features.c: Likewise. * sysdeps/x86/libc-start.c: Likewise. * sysdeps/x86/rtld-global-offsets.sym: Likewise. * sysdeps/x86/tst-get-cpu-features-static.c: Likewise. * sysdeps/x86/tst-get-cpu-features.c: Likewise. * sysdeps/x86_64/dl-procinfo.c: Likewise. * sysdeps/x86_64/cacheinfo.c (__cpuid_count): Removed. Assume USE_MULTIARCH is defined and don't check it. (is_intel): Replace __cpu_features with GLRO(dl_x86_cpu_features). (is_amd): Likewise. (max_cpuid): Likewise. (intel_check_word): Likewise. (__cache_sysconf): Don't call __init_cpu_features. (__x86_preferred_memory_instruction): Removed. (init_cacheinfo): Don't call __init_cpu_features. Replace __cpu_features with GLRO(dl_x86_cpu_features). * sysdeps/x86_64/dl-machine.h: <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/x86_64/ldsodefs.h: Include <cpu-features.h>. * sysdeps/x86_64/multiarch/Makefile (aux): Remove init-arch. * sysdeps/x86_64/multiarch/Versions: Removed. * sysdeps/x86_64/multiarch/cacheinfo.c: Likewise. * sysdeps/x86_64/multiarch/init-arch.c: Likewise. * sysdeps/x86_64/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/x86_64/multiarch/init-arch.h: Rewrite.
2015-08-13 10:37:47 +00:00
#include <stdlib.h>
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
#include <stdio.h>
x86: Install <sys/platform/x86.h> [BZ #26124] Install <sys/platform/x86.h> so that programmers can do #if __has_include(<sys/platform/x86.h>) #include <sys/platform/x86.h> #endif ... if (CPU_FEATURE_USABLE (SSE2)) ... if (CPU_FEATURE_USABLE (AVX2)) ... <sys/platform/x86.h> exports only: enum { COMMON_CPUID_INDEX_1 = 0, COMMON_CPUID_INDEX_7, COMMON_CPUID_INDEX_80000001, COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007, COMMON_CPUID_INDEX_80000008, COMMON_CPUID_INDEX_7_ECX_1, /* Keep the following line at the end. */ COMMON_CPUID_INDEX_MAX }; struct cpuid_features { struct cpuid_registers cpuid; struct cpuid_registers usable; }; struct cpu_features { struct cpu_features_basic basic; struct cpuid_features features[COMMON_CPUID_INDEX_MAX]; }; /* Get a pointer to the CPU features structure. */ extern const struct cpu_features *__x86_get_cpu_features (unsigned int max) __attribute__ ((const)); Since all feature checks are done through macros, programs compiled with a newer <sys/platform/x86.h> are compatible with the older glibc binaries as long as the layout of struct cpu_features is identical. The features array can be expanded with backward binary compatibility for both .o and .so files. When COMMON_CPUID_INDEX_MAX is increased to support new processor features, __x86_get_cpu_features in the older glibc binaries returns NULL and HAS_CPU_FEATURE/CPU_FEATURE_USABLE return false on the new processor feature. No new symbol version is neeeded. Both CPU_FEATURE_USABLE and HAS_CPU_FEATURE are provided. HAS_CPU_FEATURE can be used to identify processor features. Note: Although GCC has __builtin_cpu_supports, it only supports a subset of <sys/platform/x86.h> and it is equivalent to CPU_FEATURE_USABLE. It doesn't support HAS_CPU_FEATURE.
2020-06-30 01:30:54 +00:00
#include <sys/platform/x86.h>
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
#include <support/check.h>
#define CHECK_CPU_FEATURE_PRESENT(name) \
{ \
if (CPU_FEATURE_PRESENT (name)) \
printf (" " #name "\n"); \
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
}
#define CHECK_CPU_FEATURE_ACTIVE(name) \
{ \
if (CPU_FEATURE_ACTIVE(name)) \
printf (" " #name "\n"); \
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
}
Add _dl_x86_cpu_features to rtld_global This patch adds _dl_x86_cpu_features to rtld_global in x86 ld.so and initializes it early before __libc_start_main is called so that cpu_features is always available when it is used and we can avoid calling __init_cpu_features in IFUNC selectors. * sysdeps/i386/dl-machine.h: Include <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/i386/dl-procinfo.c (_dl_x86_cpu_features): New. * sysdeps/i386/i686/cacheinfo.c (DISABLE_PREFERRED_MEMORY_INSTRUCTION): Removed. * sysdeps/i386/i686/multiarch/Makefile (aux): Remove init-arch. * sysdeps/i386/i686/multiarch/Versions: Removed. * sysdeps/i386/i686/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/i386/ldsodefs.h: Include <cpu-features.h>. * sysdeps/unix/sysv/linux/x86/Makefile (libpthread-sysdep_routines): Remove init-arch. * sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c: Include <sysdeps/x86_64/dl-procinfo.c> instead of sysdeps/generic/dl-procinfo.c>. * sysdeps/x86/Makefile [$(subdir) == csu] (gen-as-const-headers): Add cpu-features-offsets.sym and rtld-global-offsets.sym. [$(subdir) == elf] (sysdep-dl-routines): Add dl-get-cpu-features. [$(subdir) == elf] (tests): Add tst-get-cpu-features. [$(subdir) == elf] (tests-static): Add tst-get-cpu-features-static. * sysdeps/x86/Versions: New file. * sysdeps/x86/cpu-features-offsets.sym: Likewise. * sysdeps/x86/cpu-features.c: Likewise. * sysdeps/x86/cpu-features.h: Likewise. * sysdeps/x86/dl-get-cpu-features.c: Likewise. * sysdeps/x86/libc-start.c: Likewise. * sysdeps/x86/rtld-global-offsets.sym: Likewise. * sysdeps/x86/tst-get-cpu-features-static.c: Likewise. * sysdeps/x86/tst-get-cpu-features.c: Likewise. * sysdeps/x86_64/dl-procinfo.c: Likewise. * sysdeps/x86_64/cacheinfo.c (__cpuid_count): Removed. Assume USE_MULTIARCH is defined and don't check it. (is_intel): Replace __cpu_features with GLRO(dl_x86_cpu_features). (is_amd): Likewise. (max_cpuid): Likewise. (intel_check_word): Likewise. (__cache_sysconf): Don't call __init_cpu_features. (__x86_preferred_memory_instruction): Removed. (init_cacheinfo): Don't call __init_cpu_features. Replace __cpu_features with GLRO(dl_x86_cpu_features). * sysdeps/x86_64/dl-machine.h: <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/x86_64/ldsodefs.h: Include <cpu-features.h>. * sysdeps/x86_64/multiarch/Makefile (aux): Remove init-arch. * sysdeps/x86_64/multiarch/Versions: Removed. * sysdeps/x86_64/multiarch/cacheinfo.c: Likewise. * sysdeps/x86_64/multiarch/init-arch.c: Likewise. * sysdeps/x86_64/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/x86_64/multiarch/init-arch.h: Rewrite.
2015-08-13 10:37:47 +00:00
static int
do_test (void)
{
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
#ifdef __SSE2__
TEST_VERIFY_EXIT (CPU_FEATURE_PRESENT (SSE2));
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
#endif
printf ("CPU features:\n");
CHECK_CPU_FEATURE_PRESENT (SSE3);
CHECK_CPU_FEATURE_PRESENT (PCLMULQDQ);
CHECK_CPU_FEATURE_PRESENT (DTES64);
CHECK_CPU_FEATURE_PRESENT (MONITOR);
CHECK_CPU_FEATURE_PRESENT (DS_CPL);
CHECK_CPU_FEATURE_PRESENT (VMX);
CHECK_CPU_FEATURE_PRESENT (SMX);
CHECK_CPU_FEATURE_PRESENT (EIST);
CHECK_CPU_FEATURE_PRESENT (TM2);
CHECK_CPU_FEATURE_PRESENT (SSSE3);
CHECK_CPU_FEATURE_PRESENT (CNXT_ID);
CHECK_CPU_FEATURE_PRESENT (SDBG);
CHECK_CPU_FEATURE_PRESENT (FMA);
CHECK_CPU_FEATURE_PRESENT (CMPXCHG16B);
CHECK_CPU_FEATURE_PRESENT (XTPRUPDCTRL);
CHECK_CPU_FEATURE_PRESENT (PDCM);
CHECK_CPU_FEATURE_PRESENT (PCID);
CHECK_CPU_FEATURE_PRESENT (DCA);
CHECK_CPU_FEATURE_PRESENT (SSE4_1);
CHECK_CPU_FEATURE_PRESENT (SSE4_2);
CHECK_CPU_FEATURE_PRESENT (X2APIC);
CHECK_CPU_FEATURE_PRESENT (MOVBE);
CHECK_CPU_FEATURE_PRESENT (POPCNT);
CHECK_CPU_FEATURE_PRESENT (TSC_DEADLINE);
CHECK_CPU_FEATURE_PRESENT (AES);
CHECK_CPU_FEATURE_PRESENT (XSAVE);
CHECK_CPU_FEATURE_PRESENT (OSXSAVE);
CHECK_CPU_FEATURE_PRESENT (AVX);
CHECK_CPU_FEATURE_PRESENT (F16C);
CHECK_CPU_FEATURE_PRESENT (RDRAND);
CHECK_CPU_FEATURE_PRESENT (FPU);
CHECK_CPU_FEATURE_PRESENT (VME);
CHECK_CPU_FEATURE_PRESENT (DE);
CHECK_CPU_FEATURE_PRESENT (PSE);
CHECK_CPU_FEATURE_PRESENT (TSC);
CHECK_CPU_FEATURE_PRESENT (MSR);
CHECK_CPU_FEATURE_PRESENT (PAE);
CHECK_CPU_FEATURE_PRESENT (MCE);
CHECK_CPU_FEATURE_PRESENT (CX8);
CHECK_CPU_FEATURE_PRESENT (APIC);
CHECK_CPU_FEATURE_PRESENT (SEP);
CHECK_CPU_FEATURE_PRESENT (MTRR);
CHECK_CPU_FEATURE_PRESENT (PGE);
CHECK_CPU_FEATURE_PRESENT (MCA);
CHECK_CPU_FEATURE_PRESENT (CMOV);
CHECK_CPU_FEATURE_PRESENT (PAT);
CHECK_CPU_FEATURE_PRESENT (PSE_36);
CHECK_CPU_FEATURE_PRESENT (PSN);
CHECK_CPU_FEATURE_PRESENT (CLFSH);
CHECK_CPU_FEATURE_PRESENT (DS);
CHECK_CPU_FEATURE_PRESENT (ACPI);
CHECK_CPU_FEATURE_PRESENT (MMX);
CHECK_CPU_FEATURE_PRESENT (FXSR);
CHECK_CPU_FEATURE_PRESENT (SSE);
CHECK_CPU_FEATURE_PRESENT (SSE2);
CHECK_CPU_FEATURE_PRESENT (SS);
CHECK_CPU_FEATURE_PRESENT (HTT);
CHECK_CPU_FEATURE_PRESENT (TM);
CHECK_CPU_FEATURE_PRESENT (PBE);
CHECK_CPU_FEATURE_PRESENT (FSGSBASE);
CHECK_CPU_FEATURE_PRESENT (TSC_ADJUST);
CHECK_CPU_FEATURE_PRESENT (SGX);
CHECK_CPU_FEATURE_PRESENT (BMI1);
CHECK_CPU_FEATURE_PRESENT (HLE);
CHECK_CPU_FEATURE_PRESENT (AVX2);
CHECK_CPU_FEATURE_PRESENT (SMEP);
CHECK_CPU_FEATURE_PRESENT (BMI2);
CHECK_CPU_FEATURE_PRESENT (ERMS);
CHECK_CPU_FEATURE_PRESENT (INVPCID);
CHECK_CPU_FEATURE_PRESENT (RTM);
CHECK_CPU_FEATURE_PRESENT (RDT_M);
CHECK_CPU_FEATURE_PRESENT (DEPR_FPU_CS_DS);
CHECK_CPU_FEATURE_PRESENT (MPX);
CHECK_CPU_FEATURE_PRESENT (RDT_A);
CHECK_CPU_FEATURE_PRESENT (AVX512F);
CHECK_CPU_FEATURE_PRESENT (AVX512DQ);
CHECK_CPU_FEATURE_PRESENT (RDSEED);
CHECK_CPU_FEATURE_PRESENT (ADX);
CHECK_CPU_FEATURE_PRESENT (SMAP);
CHECK_CPU_FEATURE_PRESENT (AVX512_IFMA);
CHECK_CPU_FEATURE_PRESENT (CLFLUSHOPT);
CHECK_CPU_FEATURE_PRESENT (CLWB);
CHECK_CPU_FEATURE_PRESENT (TRACE);
CHECK_CPU_FEATURE_PRESENT (AVX512PF);
CHECK_CPU_FEATURE_PRESENT (AVX512ER);
CHECK_CPU_FEATURE_PRESENT (AVX512CD);
CHECK_CPU_FEATURE_PRESENT (SHA);
CHECK_CPU_FEATURE_PRESENT (AVX512BW);
CHECK_CPU_FEATURE_PRESENT (AVX512VL);
CHECK_CPU_FEATURE_PRESENT (PREFETCHWT1);
CHECK_CPU_FEATURE_PRESENT (AVX512_VBMI);
CHECK_CPU_FEATURE_PRESENT (UMIP);
CHECK_CPU_FEATURE_PRESENT (PKU);
CHECK_CPU_FEATURE_PRESENT (OSPKE);
CHECK_CPU_FEATURE_PRESENT (WAITPKG);
CHECK_CPU_FEATURE_PRESENT (AVX512_VBMI2);
CHECK_CPU_FEATURE_PRESENT (SHSTK);
CHECK_CPU_FEATURE_PRESENT (GFNI);
CHECK_CPU_FEATURE_PRESENT (VAES);
CHECK_CPU_FEATURE_PRESENT (VPCLMULQDQ);
CHECK_CPU_FEATURE_PRESENT (AVX512_VNNI);
CHECK_CPU_FEATURE_PRESENT (AVX512_BITALG);
CHECK_CPU_FEATURE_PRESENT (AVX512_VPOPCNTDQ);
CHECK_CPU_FEATURE_PRESENT (LA57);
CHECK_CPU_FEATURE_PRESENT (RDPID);
CHECK_CPU_FEATURE_PRESENT (KL);
CHECK_CPU_FEATURE_PRESENT (BUS_LOCK_DETECT);
CHECK_CPU_FEATURE_PRESENT (CLDEMOTE);
CHECK_CPU_FEATURE_PRESENT (MOVDIRI);
CHECK_CPU_FEATURE_PRESENT (MOVDIR64B);
CHECK_CPU_FEATURE_PRESENT (ENQCMD);
CHECK_CPU_FEATURE_PRESENT (SGX_LC);
CHECK_CPU_FEATURE_PRESENT (PKS);
CHECK_CPU_FEATURE_PRESENT (SGX_KEYS);
CHECK_CPU_FEATURE_PRESENT (AVX512_4VNNIW);
CHECK_CPU_FEATURE_PRESENT (AVX512_4FMAPS);
CHECK_CPU_FEATURE_PRESENT (FSRM);
CHECK_CPU_FEATURE_PRESENT (UINTR);
CHECK_CPU_FEATURE_PRESENT (AVX512_VP2INTERSECT);
CHECK_CPU_FEATURE_PRESENT (MD_CLEAR);
CHECK_CPU_FEATURE_PRESENT (RTM_ALWAYS_ABORT);
CHECK_CPU_FEATURE_PRESENT (RTM_FORCE_ABORT);
CHECK_CPU_FEATURE_PRESENT (SERIALIZE);
CHECK_CPU_FEATURE_PRESENT (HYBRID);
CHECK_CPU_FEATURE_PRESENT (TSXLDTRK);
CHECK_CPU_FEATURE_PRESENT (LBR);
CHECK_CPU_FEATURE_PRESENT (PCONFIG);
CHECK_CPU_FEATURE_PRESENT (IBT);
CHECK_CPU_FEATURE_PRESENT (AMX_BF16);
CHECK_CPU_FEATURE_PRESENT (AVX512_FP16);
CHECK_CPU_FEATURE_PRESENT (AMX_TILE);
CHECK_CPU_FEATURE_PRESENT (AMX_INT8);
CHECK_CPU_FEATURE_PRESENT (IBRS_IBPB);
CHECK_CPU_FEATURE_PRESENT (STIBP);
CHECK_CPU_FEATURE_PRESENT (L1D_FLUSH);
CHECK_CPU_FEATURE_PRESENT (ARCH_CAPABILITIES);
CHECK_CPU_FEATURE_PRESENT (CORE_CAPABILITIES);
CHECK_CPU_FEATURE_PRESENT (SSBD);
CHECK_CPU_FEATURE_PRESENT (LAHF64_SAHF64);
CHECK_CPU_FEATURE_PRESENT (SVM);
CHECK_CPU_FEATURE_PRESENT (LZCNT);
CHECK_CPU_FEATURE_PRESENT (SSE4A);
CHECK_CPU_FEATURE_PRESENT (PREFETCHW);
CHECK_CPU_FEATURE_PRESENT (XOP);
CHECK_CPU_FEATURE_PRESENT (LWP);
CHECK_CPU_FEATURE_PRESENT (FMA4);
CHECK_CPU_FEATURE_PRESENT (TBM);
CHECK_CPU_FEATURE_PRESENT (SYSCALL_SYSRET);
CHECK_CPU_FEATURE_PRESENT (NX);
CHECK_CPU_FEATURE_PRESENT (PAGE1GB);
CHECK_CPU_FEATURE_PRESENT (RDTSCP);
CHECK_CPU_FEATURE_PRESENT (LM);
CHECK_CPU_FEATURE_PRESENT (XSAVEOPT);
CHECK_CPU_FEATURE_PRESENT (XSAVEC);
CHECK_CPU_FEATURE_PRESENT (XGETBV_ECX_1);
CHECK_CPU_FEATURE_PRESENT (XSAVES);
CHECK_CPU_FEATURE_PRESENT (XFD);
CHECK_CPU_FEATURE_PRESENT (INVARIANT_TSC);
CHECK_CPU_FEATURE_PRESENT (WBNOINVD);
CHECK_CPU_FEATURE_PRESENT (RAO_INT);
CHECK_CPU_FEATURE_PRESENT (AVX_VNNI);
CHECK_CPU_FEATURE_PRESENT (AVX512_BF16);
CHECK_CPU_FEATURE_PRESENT (LASS);
CHECK_CPU_FEATURE_PRESENT (CMPCCXADD);
CHECK_CPU_FEATURE_PRESENT (ArchPerfmonExt);
CHECK_CPU_FEATURE_PRESENT (FZLRM);
CHECK_CPU_FEATURE_PRESENT (FSRS);
CHECK_CPU_FEATURE_PRESENT (FSRCS);
CHECK_CPU_FEATURE_PRESENT (WRMSRNS);
CHECK_CPU_FEATURE_PRESENT (AMX_FP16);
CHECK_CPU_FEATURE_PRESENT (HRESET);
CHECK_CPU_FEATURE_PRESENT (AVX_IFMA);
CHECK_CPU_FEATURE_PRESENT (LAM);
CHECK_CPU_FEATURE_PRESENT (MSRLIST);
CHECK_CPU_FEATURE_PRESENT (AVX_VNNI_INT8);
CHECK_CPU_FEATURE_PRESENT (AVX_NE_CONVERT);
CHECK_CPU_FEATURE_PRESENT (AMX_COMPLEX);
CHECK_CPU_FEATURE_PRESENT (PREFETCHI);
CHECK_CPU_FEATURE_PRESENT (AVX10);
CHECK_CPU_FEATURE_PRESENT (APX_F);
CHECK_CPU_FEATURE_PRESENT (AESKLE);
CHECK_CPU_FEATURE_PRESENT (WIDE_KL);
CHECK_CPU_FEATURE_PRESENT (PTWRITE);
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
printf ("Possible CPU features:\n");
CHECK_CPU_FEATURE_ACTIVE (SSE3);
CHECK_CPU_FEATURE_ACTIVE (PCLMULQDQ);
CHECK_CPU_FEATURE_ACTIVE (DTES64);
CHECK_CPU_FEATURE_ACTIVE (MONITOR);
CHECK_CPU_FEATURE_ACTIVE (DS_CPL);
CHECK_CPU_FEATURE_ACTIVE (VMX);
CHECK_CPU_FEATURE_ACTIVE (SMX);
CHECK_CPU_FEATURE_ACTIVE (EIST);
CHECK_CPU_FEATURE_ACTIVE (TM2);
CHECK_CPU_FEATURE_ACTIVE (SSSE3);
CHECK_CPU_FEATURE_ACTIVE (CNXT_ID);
CHECK_CPU_FEATURE_ACTIVE (SDBG);
CHECK_CPU_FEATURE_ACTIVE (FMA);
CHECK_CPU_FEATURE_ACTIVE (CMPXCHG16B);
CHECK_CPU_FEATURE_ACTIVE (XTPRUPDCTRL);
CHECK_CPU_FEATURE_ACTIVE (PDCM);
CHECK_CPU_FEATURE_ACTIVE (PCID);
CHECK_CPU_FEATURE_ACTIVE (DCA);
CHECK_CPU_FEATURE_ACTIVE (SSE4_1);
CHECK_CPU_FEATURE_ACTIVE (SSE4_2);
CHECK_CPU_FEATURE_ACTIVE (X2APIC);
CHECK_CPU_FEATURE_ACTIVE (MOVBE);
CHECK_CPU_FEATURE_ACTIVE (POPCNT);
CHECK_CPU_FEATURE_ACTIVE (TSC_DEADLINE);
CHECK_CPU_FEATURE_ACTIVE (AES);
CHECK_CPU_FEATURE_ACTIVE (XSAVE);
CHECK_CPU_FEATURE_ACTIVE (OSXSAVE);
CHECK_CPU_FEATURE_ACTIVE (AVX);
CHECK_CPU_FEATURE_ACTIVE (F16C);
CHECK_CPU_FEATURE_ACTIVE (RDRAND);
CHECK_CPU_FEATURE_ACTIVE (FPU);
CHECK_CPU_FEATURE_ACTIVE (VME);
CHECK_CPU_FEATURE_ACTIVE (DE);
CHECK_CPU_FEATURE_ACTIVE (PSE);
CHECK_CPU_FEATURE_ACTIVE (TSC);
CHECK_CPU_FEATURE_ACTIVE (MSR);
CHECK_CPU_FEATURE_ACTIVE (PAE);
CHECK_CPU_FEATURE_ACTIVE (MCE);
CHECK_CPU_FEATURE_ACTIVE (CX8);
CHECK_CPU_FEATURE_ACTIVE (APIC);
CHECK_CPU_FEATURE_ACTIVE (SEP);
CHECK_CPU_FEATURE_ACTIVE (MTRR);
CHECK_CPU_FEATURE_ACTIVE (PGE);
CHECK_CPU_FEATURE_ACTIVE (MCA);
CHECK_CPU_FEATURE_ACTIVE (CMOV);
CHECK_CPU_FEATURE_ACTIVE (PAT);
CHECK_CPU_FEATURE_ACTIVE (PSE_36);
CHECK_CPU_FEATURE_ACTIVE (PSN);
CHECK_CPU_FEATURE_ACTIVE (CLFSH);
CHECK_CPU_FEATURE_ACTIVE (DS);
CHECK_CPU_FEATURE_ACTIVE (ACPI);
CHECK_CPU_FEATURE_ACTIVE (MMX);
CHECK_CPU_FEATURE_ACTIVE (FXSR);
CHECK_CPU_FEATURE_ACTIVE (SSE);
CHECK_CPU_FEATURE_ACTIVE (SSE2);
CHECK_CPU_FEATURE_ACTIVE (SS);
CHECK_CPU_FEATURE_ACTIVE (HTT);
CHECK_CPU_FEATURE_ACTIVE (TM);
CHECK_CPU_FEATURE_ACTIVE (PBE);
CHECK_CPU_FEATURE_ACTIVE (FSGSBASE);
CHECK_CPU_FEATURE_ACTIVE (TSC_ADJUST);
CHECK_CPU_FEATURE_ACTIVE (SGX);
CHECK_CPU_FEATURE_ACTIVE (BMI1);
CHECK_CPU_FEATURE_ACTIVE (HLE);
CHECK_CPU_FEATURE_ACTIVE (AVX2);
CHECK_CPU_FEATURE_ACTIVE (SMEP);
CHECK_CPU_FEATURE_ACTIVE (BMI2);
CHECK_CPU_FEATURE_ACTIVE (ERMS);
CHECK_CPU_FEATURE_ACTIVE (INVPCID);
CHECK_CPU_FEATURE_ACTIVE (RTM);
CHECK_CPU_FEATURE_ACTIVE (RDT_M);
CHECK_CPU_FEATURE_ACTIVE (DEPR_FPU_CS_DS);
CHECK_CPU_FEATURE_ACTIVE (MPX);
CHECK_CPU_FEATURE_ACTIVE (RDT_A);
CHECK_CPU_FEATURE_ACTIVE (AVX512F);
CHECK_CPU_FEATURE_ACTIVE (AVX512DQ);
CHECK_CPU_FEATURE_ACTIVE (RDSEED);
CHECK_CPU_FEATURE_ACTIVE (ADX);
CHECK_CPU_FEATURE_ACTIVE (SMAP);
CHECK_CPU_FEATURE_ACTIVE (AVX512_IFMA);
CHECK_CPU_FEATURE_ACTIVE (CLFLUSHOPT);
CHECK_CPU_FEATURE_ACTIVE (CLWB);
CHECK_CPU_FEATURE_ACTIVE (TRACE);
CHECK_CPU_FEATURE_ACTIVE (AVX512PF);
CHECK_CPU_FEATURE_ACTIVE (AVX512ER);
CHECK_CPU_FEATURE_ACTIVE (AVX512CD);
CHECK_CPU_FEATURE_ACTIVE (SHA);
CHECK_CPU_FEATURE_ACTIVE (AVX512BW);
CHECK_CPU_FEATURE_ACTIVE (AVX512VL);
CHECK_CPU_FEATURE_ACTIVE (PREFETCHWT1);
CHECK_CPU_FEATURE_ACTIVE (AVX512_VBMI);
CHECK_CPU_FEATURE_ACTIVE (UMIP);
CHECK_CPU_FEATURE_ACTIVE (PKU);
CHECK_CPU_FEATURE_ACTIVE (OSPKE);
CHECK_CPU_FEATURE_ACTIVE (WAITPKG);
CHECK_CPU_FEATURE_ACTIVE (AVX512_VBMI2);
CHECK_CPU_FEATURE_ACTIVE (SHSTK);
CHECK_CPU_FEATURE_ACTIVE (GFNI);
CHECK_CPU_FEATURE_ACTIVE (VAES);
CHECK_CPU_FEATURE_ACTIVE (VPCLMULQDQ);
CHECK_CPU_FEATURE_ACTIVE (AVX512_VNNI);
CHECK_CPU_FEATURE_ACTIVE (AVX512_BITALG);
CHECK_CPU_FEATURE_ACTIVE (AVX512_VPOPCNTDQ);
CHECK_CPU_FEATURE_ACTIVE (RDPID);
CHECK_CPU_FEATURE_ACTIVE (KL);
CHECK_CPU_FEATURE_ACTIVE (CLDEMOTE);
CHECK_CPU_FEATURE_ACTIVE (MOVDIRI);
CHECK_CPU_FEATURE_ACTIVE (MOVDIR64B);
CHECK_CPU_FEATURE_ACTIVE (ENQCMD);
CHECK_CPU_FEATURE_ACTIVE (SGX_LC);
CHECK_CPU_FEATURE_ACTIVE (PKS);
CHECK_CPU_FEATURE_ACTIVE (AVX512_4VNNIW);
CHECK_CPU_FEATURE_ACTIVE (AVX512_4FMAPS);
CHECK_CPU_FEATURE_ACTIVE (FSRM);
CHECK_CPU_FEATURE_ACTIVE (AVX512_VP2INTERSECT);
CHECK_CPU_FEATURE_ACTIVE (MD_CLEAR);
CHECK_CPU_FEATURE_ACTIVE (RTM_ALWAYS_ABORT);
CHECK_CPU_FEATURE_ACTIVE (SERIALIZE);
CHECK_CPU_FEATURE_ACTIVE (HYBRID);
CHECK_CPU_FEATURE_ACTIVE (TSXLDTRK);
CHECK_CPU_FEATURE_ACTIVE (PCONFIG);
CHECK_CPU_FEATURE_ACTIVE (IBT);
CHECK_CPU_FEATURE_ACTIVE (AMX_BF16);
CHECK_CPU_FEATURE_ACTIVE (AVX512_FP16);
CHECK_CPU_FEATURE_ACTIVE (AMX_TILE);
CHECK_CPU_FEATURE_ACTIVE (AMX_INT8);
CHECK_CPU_FEATURE_ACTIVE (IBRS_IBPB);
CHECK_CPU_FEATURE_ACTIVE (STIBP);
CHECK_CPU_FEATURE_ACTIVE (L1D_FLUSH);
CHECK_CPU_FEATURE_ACTIVE (ARCH_CAPABILITIES);
CHECK_CPU_FEATURE_ACTIVE (CORE_CAPABILITIES);
CHECK_CPU_FEATURE_ACTIVE (SSBD);
CHECK_CPU_FEATURE_ACTIVE (LAHF64_SAHF64);
CHECK_CPU_FEATURE_ACTIVE (SVM);
CHECK_CPU_FEATURE_ACTIVE (LZCNT);
CHECK_CPU_FEATURE_ACTIVE (SSE4A);
CHECK_CPU_FEATURE_ACTIVE (PREFETCHW);
CHECK_CPU_FEATURE_ACTIVE (XOP);
CHECK_CPU_FEATURE_ACTIVE (LWP);
CHECK_CPU_FEATURE_ACTIVE (FMA4);
CHECK_CPU_FEATURE_ACTIVE (TBM);
CHECK_CPU_FEATURE_ACTIVE (SYSCALL_SYSRET);
CHECK_CPU_FEATURE_ACTIVE (NX);
CHECK_CPU_FEATURE_ACTIVE (PAGE1GB);
CHECK_CPU_FEATURE_ACTIVE (RDTSCP);
CHECK_CPU_FEATURE_ACTIVE (LM);
CHECK_CPU_FEATURE_ACTIVE (XSAVEOPT);
CHECK_CPU_FEATURE_ACTIVE (XSAVEC);
CHECK_CPU_FEATURE_ACTIVE (XGETBV_ECX_1);
CHECK_CPU_FEATURE_ACTIVE (XSAVES);
CHECK_CPU_FEATURE_ACTIVE (XFD);
CHECK_CPU_FEATURE_ACTIVE (INVARIANT_TSC);
CHECK_CPU_FEATURE_ACTIVE (WBNOINVD);
CHECK_CPU_FEATURE_ACTIVE (RAO_INT);
CHECK_CPU_FEATURE_ACTIVE (AVX_VNNI);
CHECK_CPU_FEATURE_ACTIVE (AVX512_BF16);
CHECK_CPU_FEATURE_ACTIVE (CMPCCXADD);
CHECK_CPU_FEATURE_ACTIVE (FZLRM);
CHECK_CPU_FEATURE_ACTIVE (FSRS);
CHECK_CPU_FEATURE_ACTIVE (FSRCS);
CHECK_CPU_FEATURE_ACTIVE (AMX_FP16);
CHECK_CPU_FEATURE_ACTIVE (AVX_IFMA);
CHECK_CPU_FEATURE_ACTIVE (AVX_VNNI_INT8);
CHECK_CPU_FEATURE_ACTIVE (AVX_NE_CONVERT);
CHECK_CPU_FEATURE_ACTIVE (AMX_COMPLEX);
CHECK_CPU_FEATURE_ACTIVE (PREFETCHI);
CHECK_CPU_FEATURE_ACTIVE (AVX10);
CHECK_CPU_FEATURE_ACTIVE (APX_F);
CHECK_CPU_FEATURE_ACTIVE (AESKLE);
CHECK_CPU_FEATURE_ACTIVE (WIDE_KL);
CHECK_CPU_FEATURE_ACTIVE (PTWRITE);
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
if (CPU_FEATURE_ACTIVE (AVX10))
{
CHECK_CPU_FEATURE_ACTIVE (AVX10_XMM);
CHECK_CPU_FEATURE_ACTIVE (AVX10_YMM);
CHECK_CPU_FEATURE_ACTIVE (AVX10_ZMM);
}
Add _dl_x86_cpu_features to rtld_global This patch adds _dl_x86_cpu_features to rtld_global in x86 ld.so and initializes it early before __libc_start_main is called so that cpu_features is always available when it is used and we can avoid calling __init_cpu_features in IFUNC selectors. * sysdeps/i386/dl-machine.h: Include <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/i386/dl-procinfo.c (_dl_x86_cpu_features): New. * sysdeps/i386/i686/cacheinfo.c (DISABLE_PREFERRED_MEMORY_INSTRUCTION): Removed. * sysdeps/i386/i686/multiarch/Makefile (aux): Remove init-arch. * sysdeps/i386/i686/multiarch/Versions: Removed. * sysdeps/i386/i686/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/i386/ldsodefs.h: Include <cpu-features.h>. * sysdeps/unix/sysv/linux/x86/Makefile (libpthread-sysdep_routines): Remove init-arch. * sysdeps/unix/sysv/linux/x86_64/dl-procinfo.c: Include <sysdeps/x86_64/dl-procinfo.c> instead of sysdeps/generic/dl-procinfo.c>. * sysdeps/x86/Makefile [$(subdir) == csu] (gen-as-const-headers): Add cpu-features-offsets.sym and rtld-global-offsets.sym. [$(subdir) == elf] (sysdep-dl-routines): Add dl-get-cpu-features. [$(subdir) == elf] (tests): Add tst-get-cpu-features. [$(subdir) == elf] (tests-static): Add tst-get-cpu-features-static. * sysdeps/x86/Versions: New file. * sysdeps/x86/cpu-features-offsets.sym: Likewise. * sysdeps/x86/cpu-features.c: Likewise. * sysdeps/x86/cpu-features.h: Likewise. * sysdeps/x86/dl-get-cpu-features.c: Likewise. * sysdeps/x86/libc-start.c: Likewise. * sysdeps/x86/rtld-global-offsets.sym: Likewise. * sysdeps/x86/tst-get-cpu-features-static.c: Likewise. * sysdeps/x86/tst-get-cpu-features.c: Likewise. * sysdeps/x86_64/dl-procinfo.c: Likewise. * sysdeps/x86_64/cacheinfo.c (__cpuid_count): Removed. Assume USE_MULTIARCH is defined and don't check it. (is_intel): Replace __cpu_features with GLRO(dl_x86_cpu_features). (is_amd): Likewise. (max_cpuid): Likewise. (intel_check_word): Likewise. (__cache_sysconf): Don't call __init_cpu_features. (__x86_preferred_memory_instruction): Removed. (init_cacheinfo): Don't call __init_cpu_features. Replace __cpu_features with GLRO(dl_x86_cpu_features). * sysdeps/x86_64/dl-machine.h: <cpu-features.c>. (dl_platform_init): Call init_cpu_features. * sysdeps/x86_64/ldsodefs.h: Include <cpu-features.h>. * sysdeps/x86_64/multiarch/Makefile (aux): Remove init-arch. * sysdeps/x86_64/multiarch/Versions: Removed. * sysdeps/x86_64/multiarch/cacheinfo.c: Likewise. * sysdeps/x86_64/multiarch/init-arch.c: Likewise. * sysdeps/x86_64/multiarch/ifunc-defines.sym (KIND_OFFSET): Removed. * sysdeps/x86_64/multiarch/init-arch.h: Rewrite.
2015-08-13 10:37:47 +00:00
return 0;
}
x86: Extend CPUID support in struct cpu_features Extend CPUID support for all feature bits from CPUID. Add a new macro, CPU_FEATURE_USABLE, which can be used to check if a feature is usable at run-time, instead of HAS_CPU_FEATURE and HAS_ARCH_FEATURE. Add COMMON_CPUID_INDEX_D_ECX_1, COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008 to check CPU feature bits in them. Tested on i686 and x86-64 as well as using build-many-glibcs.py with x86 targets. * sysdeps/x86/cacheinfo.c (intel_check_word): Updated for cpu_features_basic. (__cache_sysconf): Likewise. (init_cacheinfo): Likewise. * sysdeps/x86/cpu-features.c (get_extended_indeces): Also populate COMMON_CPUID_INDEX_80000007 and COMMON_CPUID_INDEX_80000008. (get_common_indices): Also populate COMMON_CPUID_INDEX_D_ECX_1. Use CPU_FEATURES_CPU_P (cpu_features, XSAVEC) to check if XSAVEC is available. Set the bit_arch_XXX_Usable bits. (init_cpu_features): Use _Static_assert on index_arch_Fast_Unaligned_Load. __get_cpuid_registers and __get_arch_feature. Updated for cpu_features_basic. Set stepping in cpu_features. * sysdeps/x86/cpu-features.h: (FEATURE_INDEX_1): Changed to enum. (FEATURE_INDEX_2): New. (FEATURE_INDEX_MAX): Changed to enum. (COMMON_CPUID_INDEX_D_ECX_1): New. (COMMON_CPUID_INDEX_80000007): Likewise. (COMMON_CPUID_INDEX_80000008): Likewise. (cpuid_registers): Likewise. (cpu_features_basic): Likewise. (CPU_FEATURE_USABLE): Likewise. (bit_arch_XXX_Usable): Likewise. (cpu_features): Use cpuid_registers and cpu_features_basic. (bit_arch_XXX): Reweritten. (bit_cpu_XXX): Likewise. (index_cpu_XXX): Likewise. (reg_XXX): Likewise. * sysdeps/x86/tst-get-cpu-features.c: Include <stdio.h> and <support/check.h>. (CHECK_CPU_FEATURE): New. (CHECK_CPU_FEATURE_USABLE): Likewise. (cpu_kinds): Likewise. (do_test): Print vendor, family, model and stepping. Check HAS_CPU_FEATURE and CPU_FEATURE_USABLE. (TEST_FUNCTION): Removed. Include <support/test-driver.c> instead of "../../test-skeleton.c". * sysdeps/x86_64/multiarch/sched_cpucount.c (__sched_cpucount): Check POPCNT instead of POPCOUNT. * sysdeps/x86_64/multiarch/test-multiarch.c (do_test): Likewise.
2018-12-03 13:54:43 +00:00
#include <support/test-driver.c>