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 /sysdeps/i386 | |
parent | bf7730194fed694a9ce821c306683266a5a7b78b (diff) | |
download | glibc-hjl/hwcap/master.tar glibc-hjl/hwcap/master.tar.gz glibc-hjl/hwcap/master.tar.bz2 glibc-hjl/hwcap/master.zip |
x86: Set dl_hwcap from CPU featureshjl/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.
Diffstat (limited to 'sysdeps/i386')
-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 |
3 files changed, 42 insertions, 55 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) |