[PATCH 19/30] x86_64: Add glibc-hwcaps support

Florian Weimer fweimer@redhat.com
Thu Jun 25 10:13:47 GMT 2020


* Florian Weimer via Libc-alpha:

> Details of the supported CPU flags and the names are still subject to
> changes.
> +int32_t
> +_dl_hwcaps_subdirs_active (void)
> +{
> +  const struct cpu_features *cpu_features = __get_cpu_features ();
> +  int32_t result = 0;
> +  int32_t bit = 1 << 3;
> +
> +  /* Test in reverse preference order.  */
> +
> +  /* x86-100.  */
> +  if (!(CPU_FEATURES_ARCH_P (cpu_features, CMPXCHG16B_Usable)
> +        && CPU_FEATURES_ARCH_P (cpu_features, POPCNT_Usable)
> +        && CPU_FEATURES_ARCH_P (cpu_features, SSE3_Usable)
> +        && CPU_FEATURES_ARCH_P (cpu_features, SSE4_1_Usable)
> +        && CPU_FEATURES_ARCH_P (cpu_features, SSE4_2_Usable)
> +        && CPU_FEATURES_ARCH_P (cpu_features, SSSE3_Usable)))
> +    return result;

This misuses CPU_FEATURES_ARCH_P, and the recent <cpu-features.h> update
on the master branch makes it finally fail to compile.  The version
below should fix the build and also correct the feature detection logic.

Thanks,
Florian

diff --git a/sysdeps/x86_64/dl-hwcaps-subdirs.c b/sysdeps/x86_64/dl-hwcaps-subdirs.c
new file mode 100644
index 0000000000..1a90854b69
--- /dev/null
+++ b/sysdeps/x86_64/dl-hwcaps-subdirs.c
@@ -0,0 +1,73 @@
+/* Architecture-specific glibc-hwcaps subdirectories.  x86 version.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <dl-hwcaps.h>
+#include <cpu-features.h>
+
+const char _dl_hwcaps_subdirs[] = "x86-103:x86-102:x86-101:x86-100";
+
+int32_t
+_dl_hwcaps_subdirs_active (void)
+{
+  const struct cpu_features *cpu_features = __get_cpu_features ();
+  int32_t result = 0;
+  int32_t bit = 1 << 3;
+
+  /* Test in reverse preference order.  */
+
+  /* x86-100.  */
+  if (!(CPU_FEATURES_CPU_P (cpu_features, CMPXCHG16B)
+        && CPU_FEATURES_CPU_P (cpu_features, POPCNT)
+        && CPU_FEATURES_CPU_P (cpu_features, SSE3)
+        && CPU_FEATURES_CPU_P (cpu_features, SSE4_1)
+        && CPU_FEATURES_CPU_P (cpu_features, SSE4_2)
+        && CPU_FEATURES_CPU_P (cpu_features, SSSE3)))
+    return result;
+  result |= bit;
+  bit >>= 1;
+
+  /* x86-101.  */
+  if (!(CPU_FEATURES_ARCH_P (cpu_features, AVX_Usable)))
+    return result;
+  result |= bit;
+  bit >>= 1;
+
+  /* x86-102.  */
+  if (!(CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable)
+        && CPU_FEATURES_CPU_P (cpu_features, BMI1)
+        && CPU_FEATURES_CPU_P (cpu_features, BMI2)
+        && CPU_FEATURES_ARCH_P (cpu_features, F16C_Usable)
+        && CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable)
+        && CPU_FEATURES_CPU_P (cpu_features, LZCNT)
+        && CPU_FEATURES_CPU_P (cpu_features, MOVBE)))
+    return result;
+  result |= bit;
+  bit >>= 1;
+
+ /* x86-103.  */
+  if (!(CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable)
+        && CPU_FEATURES_CPU_P (cpu_features, AVX512BW)
+        && CPU_FEATURES_CPU_P (cpu_features, AVX512CD)
+        && CPU_FEATURES_CPU_P (cpu_features, AVX512DQ)
+        && CPU_FEATURES_CPU_P (cpu_features, AVX512VL)))
+    return result;
+  result |= bit;
+  bit >>= 1;
+
+  return result;
+}



More information about the Libc-alpha mailing list