diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-06-29 18:30:54 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-09-11 17:20:52 -0700 |
commit | 9620398097de3981c1adf5233e2b3478d36bc1b3 (patch) | |
tree | 20e492ba12ab22a57ed91df3698fdf57eba54810 /sysdeps/x86_64/multiarch | |
parent | a92f4e6299fe0e3cb6f77e79de00817aece501ce (diff) | |
download | glibc-9620398097de3981c1adf5233e2b3478d36bc1b3.tar.gz glibc-9620398097de3981c1adf5233e2b3478d36bc1b3.tar.xz glibc-9620398097de3981c1adf5233e2b3478d36bc1b3.zip |
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.
Diffstat (limited to 'sysdeps/x86_64/multiarch')
-rw-r--r-- | sysdeps/x86_64/multiarch/Makefile | 4 | ||||
-rw-r--r-- | sysdeps/x86_64/multiarch/test-multiarch.c | 96 |
2 files changed, 0 insertions, 100 deletions
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile index 395e432c09..9477538af4 100644 --- a/sysdeps/x86_64/multiarch/Makefile +++ b/sysdeps/x86_64/multiarch/Makefile @@ -1,7 +1,3 @@ -ifeq ($(subdir),csu) -tests += test-multiarch -endif - ifeq ($(subdir),string) sysdep_routines += strncat-c stpncpy-c strncpy-c \ diff --git a/sysdeps/x86_64/multiarch/test-multiarch.c b/sysdeps/x86_64/multiarch/test-multiarch.c deleted file mode 100644 index 2782803e73..0000000000 --- a/sysdeps/x86_64/multiarch/test-multiarch.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Test CPU feature data. - This file is part of the GNU C Library. - Copyright (C) 2012-2020 Free Software Foundation, Inc. - - 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 - <https://www.gnu.org/licenses/>. */ - -#include <cpu-features.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static char *cpu_flags; - -/* Search for flags in /proc/cpuinfo and store line - in cpu_flags. */ -void -get_cpuinfo (void) -{ - FILE *f; - char *line = NULL; - size_t len = 0; - ssize_t read; - - f = fopen ("/proc/cpuinfo", "r"); - if (f == NULL) - { - printf ("cannot open /proc/cpuinfo\n"); - exit (1); - } - - while ((read = getline (&line, &len, f)) != -1) - { - if (strncmp (line, "flags", 5) == 0) - { - cpu_flags = strdup (line); - break; - } - } - fclose (f); - free (line); -} - -int -check_proc (const char *proc_name, int flag, const char *name) -{ - int found = 0; - - printf ("Checking %s:\n", name); - printf (" init-arch %d\n", flag); - if (strstr (cpu_flags, proc_name) != NULL) - found = 1; - printf (" cpuinfo (%s) %d\n", proc_name, found); - - if (found != flag) - printf (" *** failure ***\n"); - - return (found != flag); -} - -static int -do_test (int argc, char **argv) -{ - int fails; - - get_cpuinfo (); - fails = check_proc ("avx", CPU_FEATURE_USABLE (AVX), - "CPU_FEATURE_USABLE (AVX)"); - fails += check_proc ("fma4", CPU_FEATURE_USABLE (FMA4), - "CPU_FEATURE_USABLE (FMA4)"); - fails += check_proc ("sse4_2", CPU_FEATURE_USABLE (SSE4_2), - "CPU_FEATURE_USABLE (SSE4_2)"); - fails += check_proc ("sse4_1", CPU_FEATURE_USABLE (SSE4_1) - , "CPU_FEATURE_USABLE (SSE4_1)"); - fails += check_proc ("ssse3", CPU_FEATURE_USABLE (SSSE3), - "CPU_FEATURE_USABLE (SSSE3)"); - fails += check_proc ("popcnt", CPU_FEATURE_USABLE (POPCNT), - "CPU_FEATURE_USABLE (POPCNT)"); - - printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails); - - return (fails != 0); -} - -#include "../../../test-skeleton.c" |