public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* V7: [PATCH 0/2] x86: Install <sys/platform/x86.h>
@ 2020-06-30  4:35 H.J. Lu
  2020-06-30  4:35 ` V7: [PATCH 1/2] x86: Support usable check for all CPU features H.J. Lu
  2020-06-30  4:35 ` V7: [PATCH 2/2] x86: Install <sys/platform/x86.h> [BZ #26124] H.J. Lu
  0 siblings, 2 replies; 18+ messages in thread
From: H.J. Lu @ 2020-06-30  4:35 UTC (permalink / raw)
  To: libc-alpha; +Cc: Florian Weimer

Support usable check for all CPU features with the following changes:

1. Change struct cpu_features to

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];
  unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX];
...
};

so that there is a usable bit for each cpuid bit.
2. After the cpuid bits have been initialized, copy them to the usable
bits.
3. Clear the usable bits which require OS support.
4. If the feature is supported by OS, copy its cpuid bit to its usable
bit.

The results are

a. If the feature doesn't requre OS support, its usable bit is copied
from the cpuid bit.
b. Otherwise, its usable bit is copied from the cpuid bit only if the
feature is supported by OS.

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 falses 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.

H.J. Lu (2):
  x86: Support usable check for all CPU features
  x86: Install <sys/platform/x86.h> [BZ #26124]

 NEWS                                          |   2 +
 manual/platform.texi                          |  24 ++
 sysdeps/i386/i686/multiarch/s_fma.c           |   2 +-
 sysdeps/i386/i686/multiarch/s_fmaf.c          |   2 +-
 sysdeps/unix/sysv/linux/i386/ld.abilist       |   1 +
 sysdeps/unix/sysv/linux/x86_64/64/ld.abilist  |   1 +
 sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist |   1 +
 sysdeps/x86/Makefile                          |   1 +
 sysdeps/x86/Versions                          |   4 +-
 sysdeps/x86/cacheinfo.c                       |   2 +-
 sysdeps/x86/cpu-features.c                    | 341 +++++++++---------
 sysdeps/x86/cpu-tunables.c                    | 170 ++++-----
 sysdeps/x86/dl-get-cpu-features.c             |   6 +-
 sysdeps/x86/include/cpu-features.h            | 179 +++++++++
 .../{cpu-features.h => sys/platform/x86.h}    | 275 ++------------
 sysdeps/x86/tst-get-cpu-features.c            | 125 ++++++-
 sysdeps/x86_64/Makefile                       |   6 +-
 sysdeps/x86_64/dl-machine.h                   |   6 +-
 sysdeps/x86_64/fpu/math-tests-arch.h          |   8 +-
 sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h |   8 +-
 sysdeps/x86_64/fpu/multiarch/ifunc-fma.h      |   4 +-
 sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h     |   6 +-
 .../x86_64/fpu/multiarch/ifunc-mathvec-avx2.h |   4 +-
 .../fpu/multiarch/ifunc-mathvec-avx512.h      |   4 +-
 sysdeps/x86_64/fpu/multiarch/s_fma.c          |   4 +-
 sysdeps/x86_64/fpu/multiarch/s_fmaf.c         |   4 +-
 sysdeps/x86_64/multiarch/ifunc-avx2.h         |   2 +-
 sysdeps/x86_64/multiarch/ifunc-impl-list.c    | 146 ++++----
 sysdeps/x86_64/multiarch/ifunc-memcmp.h       |   2 +-
 sysdeps/x86_64/multiarch/ifunc-memmove.h      |   2 +-
 sysdeps/x86_64/multiarch/ifunc-memset.h       |   4 +-
 sysdeps/x86_64/multiarch/ifunc-strcasecmp.h   |   2 +-
 sysdeps/x86_64/multiarch/ifunc-strcpy.h       |   2 +-
 sysdeps/x86_64/multiarch/ifunc-wmemset.h      |   4 +-
 sysdeps/x86_64/multiarch/strchr.c             |   2 +-
 sysdeps/x86_64/multiarch/strcmp.c             |   2 +-
 sysdeps/x86_64/multiarch/strncmp.c            |   2 +-
 sysdeps/x86_64/multiarch/test-multiarch.c     |  10 +-
 sysdeps/x86_64/multiarch/wcsnlen.c            |   2 +-
 39 files changed, 721 insertions(+), 651 deletions(-)
 create mode 100644 sysdeps/x86/include/cpu-features.h
 rename sysdeps/x86/{cpu-features.h => sys/platform/x86.h} (64%)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-03-08 14:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30  4:35 V7: [PATCH 0/2] x86: Install <sys/platform/x86.h> H.J. Lu
2020-06-30  4:35 ` V7: [PATCH 1/2] x86: Support usable check for all CPU features H.J. Lu
2020-07-04 17:17   ` H.J. Lu
2020-07-06 10:45     ` Florian Weimer
2020-07-06 14:28       ` V8: [PATCH] " H.J. Lu
2020-07-07 11:18         ` Florian Weimer
2020-07-07 11:46           ` V9 " H.J. Lu
2020-07-08 15:49             ` Florian Weimer
2020-07-08 16:32               ` V10 " H.J. Lu
2020-07-12 12:36                 ` H.J. Lu
2020-07-13 11:19                 ` Florian Weimer
2020-07-13 12:40                   ` H.J. Lu
2021-03-08 14:26                     ` Andreas Schwab
2021-03-08 14:29                       ` Florian Weimer
2020-06-30  4:35 ` V7: [PATCH 2/2] x86: Install <sys/platform/x86.h> [BZ #26124] H.J. Lu
2020-07-15 14:55   ` PING: " H.J. Lu
2020-07-15 14:58     ` H.J. Lu
2020-07-16 20:15   ` Carlos O'Donell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).