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
|
|
|
/* Data structure for x86 CPU features.
|
|
|
|
This file is part of the GNU C Library.
|
2021-01-02 19:32:25 +00:00
|
|
|
Copyright (C) 2008-2021 Free Software Foundation, Inc.
|
2015-08-13 10:37:47 +00:00
|
|
|
|
|
|
|
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/>. */
|
2015-08-13 10:37:47 +00:00
|
|
|
|
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
|
|
|
#ifndef _SYS_PLATFORM_X86_H
|
|
|
|
#define _SYS_PLATFORM_X86_H
|
2015-08-13 10:37:47 +00:00
|
|
|
|
2020-12-25 15:30:46 +00:00
|
|
|
#include <features.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <bits/platform/x86.h>
|
2015-08-13 10:37:47 +00:00
|
|
|
|
2020-12-25 15:30:46 +00:00
|
|
|
__BEGIN_DECLS
|
2015-08-13 10:37:47 +00:00
|
|
|
|
2020-12-25 15:30:46 +00:00
|
|
|
/* Get a pointer to the CPU feature structure. */
|
|
|
|
extern const struct cpuid_feature *__x86_get_cpuid_feature_leaf (unsigned int)
|
|
|
|
__attribute__ ((pure));
|
2020-06-29 23:36:08 +00:00
|
|
|
|
2020-12-25 15:30:46 +00:00
|
|
|
static __inline__ _Bool
|
2021-06-05 13:42:20 +00:00
|
|
|
x86_cpu_present (unsigned int __index)
|
2018-12-03 13:54:43 +00:00
|
|
|
{
|
2020-12-25 15:30:46 +00:00
|
|
|
const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
|
|
|
|
(__index / (8 * sizeof (unsigned int) * 4));
|
|
|
|
unsigned int __reg
|
|
|
|
= __index & (8 * sizeof (unsigned int) * 4 - 1);
|
|
|
|
unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
|
|
|
|
__reg /= 8 * sizeof (unsigned int);
|
|
|
|
|
|
|
|
return __ptr->cpuid_array[__reg] & (1 << __bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ _Bool
|
2021-06-05 13:42:20 +00:00
|
|
|
x86_cpu_active (unsigned int __index)
|
2015-08-13 10:37:47 +00:00
|
|
|
{
|
2020-12-25 15:30:46 +00:00
|
|
|
const struct cpuid_feature *__ptr = __x86_get_cpuid_feature_leaf
|
|
|
|
(__index / (8 * sizeof (unsigned int) * 4));
|
|
|
|
unsigned int __reg
|
|
|
|
= __index & (8 * sizeof (unsigned int) * 4 - 1);
|
|
|
|
unsigned int __bit = __reg & (8 * sizeof (unsigned int) - 1);
|
|
|
|
__reg /= 8 * sizeof (unsigned int);
|
2018-12-03 13:54:43 +00:00
|
|
|
|
2021-06-05 13:42:20 +00:00
|
|
|
return __ptr->active_array[__reg] & (1 << __bit);
|
2020-12-25 15:30:46 +00:00
|
|
|
}
|
2016-03-22 14:46:56 +00:00
|
|
|
|
2021-06-05 13:42:20 +00:00
|
|
|
/* CPU_FEATURE_PRESENT evaluates to true if CPU supports the feature. */
|
|
|
|
#define CPU_FEATURE_PRESENT(name) x86_cpu_present (x86_cpu_##name)
|
|
|
|
/* CPU_FEATURE_ACTIVE evaluates to true if the feature is active. */
|
|
|
|
#define CPU_FEATURE_ACTIVE(name) x86_cpu_active (x86_cpu_##name)
|
2020-09-15 12:49:27 +00:00
|
|
|
|
2020-12-25 15:30:46 +00:00
|
|
|
__END_DECLS
|
2020-09-15 12:49:27 +00:00
|
|
|
|
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
|
|
|
#endif /* _SYS_PLATFORM_X86_H */
|