diff options
Diffstat (limited to 'sysdeps/x86')
-rw-r--r-- | sysdeps/x86/cpu-features.c | 48 | ||||
-rw-r--r-- | sysdeps/x86/cpu-features.h | 15 | ||||
-rw-r--r-- | sysdeps/x86/dl-hwcap.h | 75 | ||||
-rw-r--r-- | sysdeps/x86/dl-procinfo.c | 38 | ||||
-rw-r--r-- | sysdeps/x86/dl-procinfo.h | 48 |
5 files changed, 223 insertions, 1 deletions
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index f30918dd3b..b481f50e75 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, @@ -310,4 +311,51 @@ no_cpuid: cpu_features->family = family; cpu_features->model = model; cpu_features->kind = kind; + +#if IS_IN (rtld) + /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86. */ + GLRO(dl_platform) = NULL; + GLRO(dl_hwcap) = 0; + GLRO(dl_hwcap_mask) = HWCAP_IMPORTANT; + +# ifdef __x86_64__ + if (cpu_features->kind == arch_kind_intel) + { + if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable) + && CPU_FEATURES_CPU_P (cpu_features, AVX512CD)) + { + if (CPU_FEATURES_CPU_P (cpu_features, AVX512ER)) + { + if (CPU_FEATURES_CPU_P (cpu_features, AVX512PF)) + GLRO(dl_platform) = "xeon_phi"; + } + else + { + if (CPU_FEATURES_CPU_P (cpu_features, AVX512BW) + && CPU_FEATURES_CPU_P (cpu_features, AVX512DQ) + && CPU_FEATURES_CPU_P (cpu_features, AVX512VL)) + GLRO(dl_hwcap) |= HWCAP_X86_AVX512_1; + } + } + + if (GLRO(dl_platform) == NULL + && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable) + && CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable) + && CPU_FEATURES_CPU_P (cpu_features, BMI1) + && CPU_FEATURES_CPU_P (cpu_features, BMI2) + && CPU_FEATURES_CPU_P (cpu_features, LZCNT) + && CPU_FEATURES_CPU_P (cpu_features, MOVBE) + && CPU_FEATURES_CPU_P (cpu_features, POPCNT)) + GLRO(dl_platform) = "haswell"; + } +# else + if (CPU_FEATURES_CPU_P (cpu_features, SSE2)) + GLRO(dl_hwcap) |= HWCAP_X86_SSE2; + + if (CPU_FEATURES_ARCH_P (cpu_features, I686)) + GLRO(dl_platform) = "i686"; + else if (CPU_FEATURES_ARCH_P (cpu_features, I586)) + GLRO(dl_platform) = "i586"; +# endif +#endif } diff --git a/sysdeps/x86/cpu-features.h b/sysdeps/x86/cpu-features.h index 85a39e7d70..31c7c8023e 100644 --- a/sysdeps/x86/cpu-features.h +++ b/sysdeps/x86/cpu-features.h @@ -57,8 +57,13 @@ #define bit_cpu_FMA (1 << 12) #define bit_cpu_FMA4 (1 << 16) #define bit_cpu_HTT (1 << 28) +#define bit_cpu_LZCNT (1 << 5) +#define bit_cpu_MOVBE (1 << 22) +#define bit_cpu_POPCNT (1 << 23) /* COMMON_CPUID_INDEX_7. */ +#define bit_cpu_BMI1 (1 << 3) +#define bit_cpu_BMI2 (1 << 8) #define bit_cpu_ERMS (1 << 9) #define bit_cpu_RTM (1 << 11) #define bit_cpu_AVX2 (1 << 5) @@ -258,6 +263,11 @@ extern const struct cpu_features *__get_cpu_features (void) # define index_cpu_POPCOUNT COMMON_CPUID_INDEX_1 # define index_cpu_OSXSAVE COMMON_CPUID_INDEX_1 # define index_cpu_HTT COMMON_CPUID_INDEX_1 +# define index_cpu_BMI1 COMMON_CPUID_INDEX_7 +# define index_cpu_BMI2 COMMON_CPUID_INDEX_7 +# define index_cpu_LZCNT COMMON_CPUID_INDEX_1 +# define index_cpu_MOVBE COMMON_CPUID_INDEX_1 +# define index_cpu_POPCNT COMMON_CPUID_INDEX_1 # define reg_CX8 edx # define reg_CMOV edx @@ -282,6 +292,11 @@ extern const struct cpu_features *__get_cpu_features (void) # define reg_POPCOUNT ecx # define reg_OSXSAVE ecx # define reg_HTT edx +# define reg_BMI1 ebx +# define reg_BMI2 ebx +# define reg_LZCNT ecx +# define reg_MOVBE ecx +# define reg_POPCNT ecx # define index_arch_Fast_Rep_String FEATURE_INDEX_1 # define index_arch_Fast_Copy_Backward FEATURE_INDEX_1 diff --git a/sysdeps/x86/dl-hwcap.h b/sysdeps/x86/dl-hwcap.h new file mode 100644 index 0000000000..c95668415a --- /dev/null +++ b/sysdeps/x86/dl-hwcap.h @@ -0,0 +1,75 @@ +/* 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/>. */ + +#ifndef _DL_HWCAP_H +#define _DL_HWCAP_H + +#if IS_IN (ldconfig) +/* Since ldconfig processes both i386 and x86-64 libraries, it needs + to cover all platforms and hardware capabilities. */ +# define HWCAP_PLATFORMS_START 0 +# define HWCAP_PLATFORMS_COUNT 4 +# define HWCAP_START 0 +# define HWCAP_COUNT 2 +# define HWCAP_IMPORTANT (HWCAP_X86_SSE2 | HWCAP_X86_AVX512_1) +#elif defined __x86_64__ +/* For 64 bit, only cover x86-64 platforms and capabilities. */ +# define HWCAP_PLATFORMS_START 2 +# define HWCAP_PLATFORMS_COUNT 4 +# define HWCAP_START 1 +# define HWCAP_COUNT 2 +# define HWCAP_IMPORTANT (HWCAP_X86_AVX512_1) +#else +/* For 32 bit, only cover i586, i686 and SSE2. */ +# define HWCAP_PLATFORMS_START 0 +# define HWCAP_PLATFORMS_COUNT 2 +# define HWCAP_START 0 +# define HWCAP_COUNT 1 +# define HWCAP_IMPORTANT (HWCAP_X86_SSE2) +#endif + +enum +{ + HWCAP_X86_SSE2 = 1 << 0, + HWCAP_X86_AVX512_1 = 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 = HWCAP_START; i < 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 + +#endif /* dl-hwcap.h */ diff --git a/sysdeps/x86/dl-procinfo.c b/sysdeps/x86/dl-procinfo.c index 9d154bfc62..43ab8fe25b 100644 --- a/sysdeps/x86/dl-procinfo.c +++ b/sysdeps/x86/dl-procinfo.c @@ -16,7 +16,11 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -/* If anything should be added here check whether the size of each string +/* This information must be kept in sync with the _DL_HWCAP_COUNT, + HWCAP_PLATFORMS_START and HWCAP_PLATFORMS_COUNT definitions in + dl-hwcap.h. + + If anything should be added here check whether the size of each string is still ok with the given array size. All the #ifdefs in the definitions are quite irritating but @@ -50,3 +54,35 @@ PROCINFO_CLASS struct cpu_features _dl_x86_cpu_features , # endif #endif + +#if !defined PROCINFO_DECL && defined SHARED + ._dl_x86_hwcap_flags +#else +PROCINFO_CLASS const char _dl_x86_hwcap_flags[2][9] +#endif +#ifndef PROCINFO_DECL += { + "sse2", "avx512_1" + } +#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][9] +#endif +#ifndef PROCINFO_DECL += { + "i586", "i686", "haswell", "xeon_phi" + } +#endif +#if !defined SHARED || defined PROCINFO_DECL +; +#else +, +#endif diff --git a/sysdeps/x86/dl-procinfo.h b/sysdeps/x86/dl-procinfo.h new file mode 100644 index 0000000000..5feb1467e4 --- /dev/null +++ b/sysdeps/x86/dl-procinfo.h @@ -0,0 +1,48 @@ +/* x86 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 <ldsodefs.h> +#include <dl-hwcap.h> + +#define _DL_HWCAP_COUNT HWCAP_COUNT +#define _DL_PLATFORMS_COUNT HWCAP_PLATFORMS_COUNT + +/* Start at 48 to reserve spaces for hardware capabilities. */ +#define _DL_FIRST_PLATFORM 48 +/* Mask to filter out platforms. */ +#define _DL_HWCAP_PLATFORM (((1ULL << _DL_PLATFORMS_COUNT) - 1) \ + << _DL_FIRST_PLATFORM) + +static inline int +__attribute__ ((unused, always_inline)) +_dl_string_platform (const char *str) +{ + int i; + + if (str != NULL) + for (i = HWCAP_PLATFORMS_START; i < HWCAP_PLATFORMS_COUNT; ++i) + { + if (strcmp (str, GLRO(dl_x86_platforms)[i]) == 0) + return _DL_FIRST_PLATFORM + i; + } + return -1; +}; + +#endif /* dl-procinfo.h */ |