This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch fw/libm-noprivate-2.27 created. glibc-2.27-42-ga7acf79
- From: fw at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 10 May 2018 10:42:28 -0000
- Subject: GNU C Library master sources branch fw/libm-noprivate-2.27 created. glibc-2.27-42-ga7acf79
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, fw/libm-noprivate-2.27 has been created
at a7acf79a8adaeff8fa3e9d6d3f90c4566d54eb8c (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a7acf79a8adaeff8fa3e9d6d3f90c4566d54eb8c
commit a7acf79a8adaeff8fa3e9d6d3f90c4566d54eb8c
Author: Florian Weimer <fweimer@redhat.com>
Date: Thu May 10 11:50:00 2018 +0200
Use custom x86 feature selection in libm
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 9a89bfc..9987e1b 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -15,6 +15,8 @@ libm-sysdep_routines += e_exp-fma e_log-fma e_pow-fma s_atan-fma \
halfulp-fma mpexp-fma \
mpatan2-fma mpatan-fma mpsqrt-fma mptan-fma
+libm-sysdep_routines += x86-math-features
+
CFLAGS-doasin-fma.c = -mfma -mavx2
CFLAGS-dosincos-fma.c = -mfma -mavx2
CFLAGS-e_asin-fma.c = -mfma -mavx2
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
index a5f9375..c592430 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
@@ -18,6 +18,7 @@
<http://www.gnu.org/licenses/>. */
#include <init-arch.h>
+#include <x86-math-features.h>
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
extern __typeof (REDIRECT_NAME) OPTIMIZE (avx) attribute_hidden;
@@ -27,16 +28,14 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (fma4) attribute_hidden;
static inline void *
IFUNC_SELECTOR (void)
{
- const struct cpu_features* cpu_features = __get_cpu_features ();
+ unsigned int features = __x86_math_features ();
- if (CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable)
- && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable))
+ if ((features & x86_math_feature_fma)
+ && (features & x86_math_feature_avx2))
return OPTIMIZE (fma);
-
- if (CPU_FEATURES_ARCH_P (cpu_features, FMA4_Usable))
+ if (features & x86_math_feature_fma4)
return OPTIMIZE (fma4);
-
- if (CPU_FEATURES_ARCH_P (cpu_features, AVX_Usable))
+ if (features & x86_math_feature_avx)
return OPTIMIZE (avx);
return OPTIMIZE (sse2);
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-fma.h b/sysdeps/x86_64/fpu/multiarch/ifunc-fma.h
index 63a8cd2..1b0a95d 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-fma.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-fma.h
@@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <init-arch.h>
+#include <x86-math-features.h>
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
extern __typeof (REDIRECT_NAME) OPTIMIZE (fma) attribute_hidden;
@@ -24,10 +25,10 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (fma) attribute_hidden;
static inline void *
IFUNC_SELECTOR (void)
{
- const struct cpu_features* cpu_features = __get_cpu_features ();
+ unsigned int features = __x86_math_features ();
- if (CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable)
- && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable))
+ if ((features & x86_math_feature_fma)
+ && (features & x86_math_feature_avx2))
return OPTIMIZE (fma);
return OPTIMIZE (sse2);
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
index a2526a2..6fb21ee 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
@@ -18,6 +18,7 @@
<http://www.gnu.org/licenses/>. */
#include <init-arch.h>
+#include <x86-math-features.h>
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
extern __typeof (REDIRECT_NAME) OPTIMIZE (fma) attribute_hidden;
@@ -26,13 +27,12 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (fma4) attribute_hidden;
static inline void *
IFUNC_SELECTOR (void)
{
- const struct cpu_features* cpu_features = __get_cpu_features ();
+ unsigned int features = __x86_math_features ();
- if (CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable)
- && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable))
+ if ((features & x86_math_feature_fma)
+ && (features & x86_math_feature_avx2))
return OPTIMIZE (fma);
-
- if (CPU_FEATURES_ARCH_P (cpu_features, FMA4_Usable))
+ if (features & x86_math_feature_fma4)
return OPTIMIZE (fma4);
return OPTIMIZE (sse2);
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h b/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h
index a8710ba..ff136f4 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h
@@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <init-arch.h>
+#include <x86-math-features.h>
extern __typeof (REDIRECT_NAME) OPTIMIZE (c) attribute_hidden;
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse41) attribute_hidden;
@@ -24,9 +25,9 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (sse41) attribute_hidden;
static inline void *
IFUNC_SELECTOR (void)
{
- const struct cpu_features* cpu_features = __get_cpu_features ();
+ unsigned int features = __x86_math_features ();
- if (CPU_FEATURES_CPU_P (cpu_features, SSE4_1))
+ if (features & x86_math_feature_sse41)
return OPTIMIZE (sse41);
return OPTIMIZE (c);
diff --git a/sysdeps/x86_64/fpu/multiarch/s_fma.c b/sysdeps/x86_64/fpu/multiarch/s_fma.c
index 875c76d..66da7ff 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_fma.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_fma.c
@@ -20,6 +20,7 @@
#include <config.h>
#include <math.h>
#include <init-arch.h>
+#include <x86-math-features.h>
#include <libm-alias-double.h>
extern double __fma_sse2 (double x, double y, double z) attribute_hidden;
@@ -41,8 +42,8 @@ __fma_fma4 (double x, double y, double z)
}
-libm_ifunc (__fma, HAS_ARCH_FEATURE (FMA_Usable)
- ? __fma_fma3 : (HAS_ARCH_FEATURE (FMA4_Usable)
+libm_ifunc (__fma, __x86_math_features () & x86_math_feature_fma
+ ? __fma_fma3 : (__x86_math_features () & x86_math_feature_fma4
? __fma_fma4 : __fma_sse2));
libm_alias_double (__fma, fma)
diff --git a/sysdeps/x86_64/fpu/multiarch/s_fmaf.c b/sysdeps/x86_64/fpu/multiarch/s_fmaf.c
index 5f4c2ec..d65aa9a 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_fmaf.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_fmaf.c
@@ -19,6 +19,7 @@
#include <config.h>
#include <math.h>
#include <init-arch.h>
+#include <x86-math-features.h>
#include <libm-alias-float.h>
extern float __fmaf_sse2 (float x, float y, float z) attribute_hidden;
@@ -40,8 +41,8 @@ __fmaf_fma4 (float x, float y, float z)
}
-libm_ifunc (__fmaf, HAS_ARCH_FEATURE (FMA_Usable)
- ? __fmaf_fma3 : (HAS_ARCH_FEATURE (FMA4_Usable)
+libm_ifunc (__fmaf, __x86_math_features () & x86_math_feature_fma
+ ? __fmaf_fma3 : (__x86_math_features () & x86_math_feature_fma4
? __fmaf_fma4 : __fmaf_sse2));
libm_alias_float (__fma, fma)
diff --git a/sysdeps/x86_64/fpu/multiarch/x86-math-features.c b/sysdeps/x86_64/fpu/multiarch/x86-math-features.c
new file mode 100644
index 0000000..e803b73
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/x86-math-features.c
@@ -0,0 +1,96 @@
+/* Initialize CPU features for use by the math library.
+ This file is part of the GNU C Library.
+ Copyright (C) 2008-2018 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/>. */
+
+#include <x86-math-features.h>
+#include <atomic.h>
+#include <cpuid.h>
+#include <cpu-features.h>
+#include <stdbool.h>
+
+static unsigned int features;
+
+unsigned int
+__x86_math_features (void)
+{
+ unsigned int features_local = atomic_load_relaxed (&features);
+ if (features_local != 0)
+ /* At least the initialization bit is set, which means that we
+ have a proper value. */
+ return features_local;
+
+ /* Perform initialization. */
+ features_local = x86_math_feature_initialized;
+
+ unsigned int eax, ebx, ecx, edx;
+ unsigned int max_cpuid;
+ __cpuid (0, max_cpuid, ebx, ecx, edx);
+ bool cpu_amd = ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65;
+
+ if (max_cpuid >= 7)
+ {
+ __cpuid (1, eax, ebx, ecx, edx);
+ bool flag_fma = ecx & bit_cpu_FMA;
+ bool flag_osxsave = ecx & bit_cpu_OSXSAVE;
+ bool flag_avx = ecx & bit_cpu_AVX;
+ bool flag_sse41 = ecx & bit_cpu_SSE4_1;
+
+ if (flag_sse41)
+ features_local |= x86_math_feature_sse41;
+
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ bool flag_avx2 = ebx & bit_cpu_AVX2;
+
+ if (flag_osxsave)
+ {
+ unsigned int xcrlow;
+ unsigned int xcrhigh;
+ asm ("xgetbv" : "=a" (xcrlow), "=d" (xcrhigh) : "c" (0));
+ bool ymm_xmm_usable
+ = (xcrlow & (bit_YMM_state | bit_XMM_state))
+ == (bit_YMM_state | bit_XMM_state);
+
+ /* Is YMM and XMM state usable? */
+ if (ymm_xmm_usable)
+ {
+ if (flag_avx)
+ {
+ features_local |= x86_math_feature_avx;
+ if (flag_avx2)
+ features_local |= x86_math_feature_avx2;
+ if (flag_fma)
+ features_local |= x86_math_feature_fma;
+
+ if (cpu_amd)
+ {
+ __cpuid (0x80000000, eax, ebx, ecx, edx);
+ if (eax >= 0x80000001)
+ {
+ __cpuid (0x80000001, eax, ebx, ecx, edx);
+ bool flag_fma4 = ecx & bit_cpu_FMA4;
+ if (flag_fma4)
+ features_local |= x86_math_feature_fma4;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ atomic_store_relaxed (&features, features_local);
+ return features_local;
+}
diff --git a/sysdeps/x86_64/fpu/multiarch/x86-math-features.h b/sysdeps/x86_64/fpu/multiarch/x86-math-features.h
new file mode 100644
index 0000000..c43b66d
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/x86-math-features.h
@@ -0,0 +1,18 @@
+#ifndef X86_MATH_FEATURES_H
+#define X86_MATH_FEATURES_H
+
+enum
+ {
+ x86_math_feature_initialized = 1 << 0,
+ x86_math_feature_avx = 1 << 1,
+ x86_math_feature_avx2 = 1 << 2,
+ x86_math_feature_fma = 1 << 3,
+ x86_math_feature_fma4 = 1 << 4,
+ x86_math_feature_sse41 = 1 << 5,
+ };
+
+/* Return a combination of flags x86_math_feature_* above. */
+unsigned int __x86_math_features (void)
+ __attribute__ ((const)) attribute_hidden;
+
+#endif /* X86_MATH_FEATURES_H */
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8e2c360c90d61b2f573d19b5cb991e9644fc0458
commit 8e2c360c90d61b2f573d19b5cb991e9644fc0458
Author: Florian Weimer <fweimer@redhat.com>
Date: Thu May 10 11:49:03 2018 +0200
Avoid use GLIBC_PRIVATE symbols in the implementation of nan* functions
diff --git a/math/s_nan_template.c b/math/s_nan_template.c
index fe39047..575d72d 100644
--- a/math/s_nan_template.c
+++ b/math/s_nan_template.c
@@ -23,11 +23,50 @@
#include <string.h>
#include <ieee754.h>
+/* See stdlib/strtod_nan_main.c. */
+
+#define STRING_TYPE char
+#define STRTOD_NAN strtod_nan_internal
+#define L_(ch) ch
+#define STRTOULL(str, endp, endc) \
+ __strtoull_internal (str, endp, endc, /* group */ 0)
+
+static
+FLOAT
+STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
+{
+ const STRING_TYPE *cp = str;
+
+ while ((*cp >= L_('0') && *cp <= L_('9'))
+ || (*cp >= L_('A') && *cp <= L_('Z'))
+ || (*cp >= L_('a') && *cp <= L_('z'))
+ || *cp == L_('_'))
+ ++cp;
+
+ FLOAT retval = NAN;
+ if (*cp != endc)
+ goto out;
+
+ /* This is a system-dependent way to specify the bitmask used for
+ the NaN. We expect it to be a number which is put in the
+ mantissa of the number. */
+ STRING_TYPE *endp;
+ unsigned long long int mant;
+
+ mant = STRTOULL (str, &endp, 0);
+ if (endp == cp)
+ SET_MANTISSA (retval, mant);
+
+ out:
+ if (endptr != NULL)
+ *endptr = (STRING_TYPE *) cp;
+ return retval;
+}
FLOAT
M_DECL_FUNC (__nan) (const char *tagp)
{
- return M_STRTO_NAN (tagp, NULL, 0);
+ return strtod_nan_internal (tagp, NULL, 0);
}
declare_mgen_alias (__nan, nan)
diff --git a/sysdeps/generic/math-type-macros-double.h b/sysdeps/generic/math-type-macros-double.h
index 1af4c74..a4b5daf 100644
--- a/sysdeps/generic/math-type-macros-double.h
+++ b/sysdeps/generic/math-type-macros-double.h
@@ -27,6 +27,8 @@
#define CFLOAT _Complex double
#define M_STRTO_NAN __strtod_nan
+#include <stdlib/strtod_nan_double.h>
+
#include <libm-alias-double.h>
#ifndef declare_mgen_alias
diff --git a/sysdeps/generic/math-type-macros-float.h b/sysdeps/generic/math-type-macros-float.h
index 9273bde..529c553 100644
--- a/sysdeps/generic/math-type-macros-float.h
+++ b/sysdeps/generic/math-type-macros-float.h
@@ -30,6 +30,8 @@
the double macro constants. */
#define M_MLIT(c) c
+#include <stdlib/strtod_nan_float.h>
+
#include <libm-alias-float.h>
#ifndef declare_mgen_alias
diff --git a/sysdeps/generic/math-type-macros-float128.h b/sysdeps/generic/math-type-macros-float128.h
index 605996e..264d34e 100644
--- a/sysdeps/generic/math-type-macros-float128.h
+++ b/sysdeps/generic/math-type-macros-float128.h
@@ -32,6 +32,8 @@
#define M_MLIT(c) c ## f128
+#include <strtod_nan_float128.h>
+
#include <libm-alias-float128.h>
#ifndef declare_mgen_alias
diff --git a/sysdeps/generic/math-type-macros-ldouble.h b/sysdeps/generic/math-type-macros-ldouble.h
index 5fe1600..726ac87 100644
--- a/sysdeps/generic/math-type-macros-ldouble.h
+++ b/sysdeps/generic/math-type-macros-ldouble.h
@@ -27,6 +27,8 @@
#define CFLOAT _Complex long double
#define M_STRTO_NAN __strtold_nan
+#include <strtod_nan_ldouble.h>
+
#include <libm-alias-ldouble.h>
#ifndef declare_mgen_alias
diff --git a/sysdeps/ieee754/float128/strtod_nan_float128.h b/sysdeps/ieee754/float128/strtod_nan_float128.h
index c3eaca4..44a8d18 100644
--- a/sysdeps/ieee754/float128/strtod_nan_float128.h
+++ b/sysdeps/ieee754/float128/strtod_nan_float128.h
@@ -16,6 +16,8 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <ieee754_float128.h>
+
#define FLOAT _Float128
#define SET_MANTISSA(flt, mant) \
do \
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9e9dccb635991aa70187253bc188c87d3e139ed0
commit 9e9dccb635991aa70187253bc188c87d3e139ed0
Author: Florian Weimer <fweimer@redhat.com>
Date: Thu May 10 11:48:19 2018 +0200
Use __errno_location in libm
diff --git a/include/errno.h b/include/errno.h
index 3c3d228..a296f0a 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -20,7 +20,7 @@
# define errno rtld_errno
extern int rtld_errno attribute_hidden;
-# elif IS_IN_LIB
+# elif IS_IN_LIB && !IS_IN (libm)
# include <tls.h>
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources