diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-04-05 15:24:30 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2017-04-07 08:09:47 -0700 |
commit | 32ffd2e11cfe3f7c71988bca8cbe0ba514e71340 (patch) | |
tree | aceb8c8179af8bae4f1a27f2e6a98455fb0698d4 | |
parent | bf7730194fed694a9ce821c306683266a5a7b78b (diff) | |
download | glibc-hjl/hwcap/master.tar.gz glibc-hjl/hwcap/master.tar.xz glibc-hjl/hwcap/master.zip |
x86: Set dl_hwcap from CPU features hjl/hwcap/master
On x86, the usage of AT_HWCAP in glibc is obsolete since addition of dl_x86_cpu_features. dl_hwcap, which was set from AT_HWCAP, is used by dynamic linker to build an array of hardware capability names, which are added to search path when loading shared object. dl_hwcap was unused on x86-64 and only SSE2 was used on i386. This patch sets dl_hwcap with new hardware capabilities from CPU features. Currently, 2 capabilities, SSE2 and AVX2, are supported. The maximum number of hardware capabilities is 64. Since x86-64 includes SSE2, SSE2 is skipped on x86-64. dl_x86_cap_flags is kepted for i386 and is used by _dl_show_auxv. dl_x86_hwcap_flags is added for new hardware capabilities. * sysdeps/i386/dl-hwcap.h: New file. * sysdeps/x86/dl-hwcap.h: Likewise. * sysdeps/x86_64/dl-hwcap.h: Likewise. * sysdeps/x86_64/dl-procinfo.h: Likewise. * sysdeps/i386/dl-procinfo.c (_dl_x86_hwcap_flags): New. * sysdeps/i386/dl-procinfo.h: Include <dl-hwcap.h>. (_DL_HWCAP_COUNT): Removed. (HWCAP_I386_XXX): Likewise. (HWCAP_IMPORTANT): Likewise. (_dl_procinfo): Likewise. (_dl_hwcap_string): Likewise. (_dl_string_hwcap): Likewise. * sysdeps/unix/sysv/linux/i386/dl-procinfo.h (_dl_procinfo): Replace _DL_HWCAP_COUNT with 32. * sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h [!IS_IN (ldconfig)]: Include <sysdeps/x86_64/dl-procinfo.h>. * sysdeps/x86/cpu-features.c: Include <dl-hwcap.h>. (init_cpu_features): Set dl_hwcap and dl_hwcap_mask. * sysdeps/x86_64/dl-procinfo.c (_dl_x86_hwcap_flags): New.
-rw-r--r-- | sysdeps/i386/dl-hwcap.h | 25 | ||||
-rw-r--r-- | sysdeps/i386/dl-procinfo.c | 16 | ||||
-rw-r--r-- | sysdeps/i386/dl-procinfo.h | 56 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/i386/dl-procinfo.h | 2 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h | 2 | ||||
-rw-r--r-- | sysdeps/x86/cpu-features.c | 9 | ||||
-rw-r--r-- | sysdeps/x86/dl-hwcap.h | 48 | ||||
-rw-r--r-- | sysdeps/x86_64/dl-hwcap.h | 25 | ||||
-rw-r--r-- | sysdeps/x86_64/dl-procinfo.c | 16 | ||||
-rw-r--r-- | sysdeps/x86_64/dl-procinfo.h | 28 |
10 files changed, 170 insertions, 57 deletions
diff --git a/sysdeps/i386/dl-hwcap.h b/sysdeps/i386/dl-hwcap.h new file mode 100644 index 0000000000..0e8d95f0cf --- /dev/null +++ b/sysdeps/i386/dl-hwcap.h @@ -0,0 +1,25 @@ +/* i386 version of hardware capability information handling macros. + Copyright (C) 2017 Free Software Foundation, Inc. + 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef _DL_HWCAP_H +#define _DL_HWCAP_H +#include <sysdeps/x86/dl-hwcap.h> + +#define HWCAP_IMPORTANT (HWCAP_X86_SSE2 | HWCAP_X86_AVX2) + +#endif /* dl-hwcap.h */ diff --git a/sysdeps/i386/dl-procinfo.c b/sysdeps/i386/dl-procinfo.c index cec7dccfb8..acb800b342 100644 --- a/sysdeps/i386/dl-procinfo.c +++ b/sysdeps/i386/dl-procinfo.c @@ -79,6 +79,22 @@ PROCINFO_CLASS const char _dl_x86_cap_flags[32][8] #endif #if !defined PROCINFO_DECL && defined SHARED + ._dl_x86_hwcap_flags +#else +PROCINFO_CLASS const char _dl_x86_hwcap_flags[2][8] +#endif +#ifndef PROCINFO_DECL += { + "sse2", "avx2" + } +#endif +#if !defined SHARED || defined PROCINFO_DECL +; +#else +, +#endif + +#if !defined PROCINFO_DECL && defined SHARED ._dl_x86_platforms #else PROCINFO_CLASS const char _dl_x86_platforms[4][5] diff --git a/sysdeps/i386/dl-procinfo.h b/sysdeps/i386/dl-procinfo.h index 9c38846f0b..5b9bb4c070 100644 --- a/sysdeps/i386/dl-procinfo.h +++ b/sysdeps/i386/dl-procinfo.h @@ -20,8 +20,7 @@ #ifndef _DL_PROCINFO_H #define _DL_PROCINFO_H 1 #include <ldsodefs.h> - -#define _DL_HWCAP_COUNT 32 +#include <dl-hwcap.h> #define _DL_PLATFORMS_COUNT 4 @@ -31,59 +30,6 @@ #define _DL_HWCAP_PLATFORM (((1ULL << _DL_PLATFORMS_COUNT) - 1) \ << _DL_FIRST_PLATFORM) -enum -{ - HWCAP_I386_FPU = 1 << 0, - HWCAP_I386_VME = 1 << 1, - HWCAP_I386_DE = 1 << 2, - HWCAP_I386_PSE = 1 << 3, - HWCAP_I386_TSC = 1 << 4, - HWCAP_I386_MSR = 1 << 5, - HWCAP_I386_PAE = 1 << 6, - HWCAP_I386_MCE = 1 << 7, - HWCAP_I386_CX8 = 1 << 8, - HWCAP_I386_APIC = 1 << 9, - HWCAP_I386_SEP = 1 << 11, - HWCAP_I386_MTRR = 1 << 12, - HWCAP_I386_PGE = 1 << 13, - HWCAP_I386_MCA = 1 << 14, - HWCAP_I386_CMOV = 1 << 15, - HWCAP_I386_FCMOV = 1 << 16, - HWCAP_I386_MMX = 1 << 23, - HWCAP_I386_OSFXSR = 1 << 24, - HWCAP_I386_XMM = 1 << 25, - HWCAP_I386_XMM2 = 1 << 26, - HWCAP_I386_AMD3D = 1 << 31, - - /* XXX Which others to add here? */ - HWCAP_IMPORTANT = (HWCAP_I386_XMM2) - -}; - -/* We cannot provide a general printing function. */ -#define _dl_procinfo(type, word) -1 - -static inline const char * -__attribute__ ((unused)) -_dl_hwcap_string (int idx) -{ - return GLRO(dl_x86_cap_flags)[idx]; -}; - -static inline int -__attribute__ ((unused, always_inline)) -_dl_string_hwcap (const char *str) -{ - int i; - - for (i = 0; i < _DL_HWCAP_COUNT; i++) - { - if (strcmp (str, GLRO(dl_x86_cap_flags)[i]) == 0) - return i; - } - return -1; -}; - static inline int __attribute__ ((unused, always_inline)) _dl_string_platform (const char *str) diff --git a/sysdeps/unix/sysv/linux/i386/dl-procinfo.h b/sysdeps/unix/sysv/linux/i386/dl-procinfo.h index d49638c2e0..c8196a81dc 100644 --- a/sysdeps/unix/sysv/linux/i386/dl-procinfo.h +++ b/sysdeps/unix/sysv/linux/i386/dl-procinfo.h @@ -36,7 +36,7 @@ _dl_procinfo (unsigned int type, unsigned long int word) _dl_printf ("AT_HWCAP: "); - for (i = 0; i < _DL_HWCAP_COUNT; ++i) + for (i = 0; i < 32; ++i) if (word & (1 << i)) _dl_printf (" %s", GLRO(dl_x86_cap_flags)[i]); diff --git a/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h b/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h index 7829e1cd67..dba5cc960f 100644 --- a/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h +++ b/sysdeps/unix/sysv/linux/x86_64/dl-procinfo.h @@ -1,5 +1,5 @@ #if IS_IN (ldconfig) # include <sysdeps/unix/sysv/linux/i386/dl-procinfo.h> #else -# include <sysdeps/generic/dl-procinfo.h> +# include <sysdeps/x86_64/dl-procinfo.h> #endif diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 33788ed323..10fe2f3f85 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -18,6 +18,7 @@ #include <cpuid.h> #include <cpu-features.h> +#include <dl-hwcap.h> static void get_common_indeces (struct cpu_features *cpu_features, @@ -302,4 +303,12 @@ no_cpuid: cpu_features->family = family; cpu_features->model = model; cpu_features->kind = kind; + + /* Reuse dl_hwcap and dl_hwcap_mask for x86. */ + GLRO(dl_hwcap) = 0; + if (CPU_FEATURES_CPU_P (cpu_features, SSE2)) + GLRO(dl_hwcap) |= HWCAP_X86_SSE2; + if (CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable)) + GLRO(dl_hwcap) |= HWCAP_X86_AVX2; + GLRO(dl_hwcap_mask) = HWCAP_IMPORTANT; } diff --git a/sysdeps/x86/dl-hwcap.h b/sysdeps/x86/dl-hwcap.h new file mode 100644 index 0000000000..13ff32a485 --- /dev/null +++ b/sysdeps/x86/dl-hwcap.h @@ -0,0 +1,48 @@ +/* x86 version of hardware capability information handling macros. + Copyright (C) 2017 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 + <http://www.gnu.org/licenses/>. */ + +#define _DL_HWCAP_COUNT 2 + +enum +{ + HWCAP_X86_SSE2 = 1 << 0, + HWCAP_X86_AVX2 = 1 << 1 +}; + +static inline const char * +__attribute__ ((unused)) +_dl_hwcap_string (int idx) +{ + return GLRO(dl_x86_hwcap_flags)[idx]; +}; + +static inline int +__attribute__ ((unused, always_inline)) +_dl_string_hwcap (const char *str) +{ + int i; + + for (i = 0; i < _DL_HWCAP_COUNT; i++) + { + if (strcmp (str, GLRO(dl_x86_hwcap_flags)[i]) == 0) + return i; + } + return -1; +}; + +/* We cannot provide a general printing function. */ +#define _dl_procinfo(type, word) -1 diff --git a/sysdeps/x86_64/dl-hwcap.h b/sysdeps/x86_64/dl-hwcap.h new file mode 100644 index 0000000000..6e31fa91be --- /dev/null +++ b/sysdeps/x86_64/dl-hwcap.h @@ -0,0 +1,25 @@ +/* x86-64 version of hardware capability information handling macros. + Copyright (C) 2017 Free Software Foundation, Inc. + 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef _DL_HWCAP_H +#define _DL_HWCAP_H +#include <sysdeps/x86/dl-hwcap.h> + +#define HWCAP_IMPORTANT (HWCAP_X86_AVX2) + +#endif /* dl-hwcap.h */ diff --git a/sysdeps/x86_64/dl-procinfo.c b/sysdeps/x86_64/dl-procinfo.c index a76624fb06..5ccdb7fbc3 100644 --- a/sysdeps/x86_64/dl-procinfo.c +++ b/sysdeps/x86_64/dl-procinfo.c @@ -53,5 +53,21 @@ PROCINFO_CLASS struct cpu_features _dl_x86_cpu_features , #endif +#if !defined PROCINFO_DECL && defined SHARED + ._dl_x86_hwcap_flags +#else +PROCINFO_CLASS const char _dl_x86_hwcap_flags[2][8] +#endif +#ifndef PROCINFO_DECL += { + "sse2", "avx2" + } +#endif +#if !defined SHARED || defined PROCINFO_DECL +; +#else +, +#endif + #undef PROCINFO_DECL #undef PROCINFO_CLASS diff --git a/sysdeps/x86_64/dl-procinfo.h b/sysdeps/x86_64/dl-procinfo.h new file mode 100644 index 0000000000..ddbde2d946 --- /dev/null +++ b/sysdeps/x86_64/dl-procinfo.h @@ -0,0 +1,28 @@ +/* x86-64 version of processor capability information handling macros. + Copyright (C) 2017 Free Software Foundation, Inc. + 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef _DL_PROCINFO_H +#define _DL_PROCINFO_H 1 +#include <dl-hwcap.h> + +/* There're no platforms to filter out. */ +#define _DL_HWCAP_PLATFORM 0 + +#define _dl_string_platform(str) (-1) + +#endif /* dl-procinfo.h */ |