public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/grte] Add workarounds for incomplete float128 support in clang
@ 2021-08-27 23:21 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-27 23:21 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dfb17f123a38fd08e577bf4904dc4cf7c22a1e93

commit dfb17f123a38fd08e577bf4904dc4cf7c22a1e93
Author: Stan Shebs <stanshebs@google.com>
Date:   Tue Jan 23 09:41:49 2018 -0800

    Add workarounds for incomplete float128 support in clang

Diff:
---
 sysdeps/i386/fpu/fenv_private.h     |  2 +-
 sysdeps/ieee754/float128/Makeconfig |  2 +-
 sysdeps/ieee754/float128/Makefile   |  2 ++
 sysdeps/x86/bits/floatn.h           | 27 +++++++++++++++++++++++++++
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/sysdeps/i386/fpu/fenv_private.h b/sysdeps/i386/fpu/fenv_private.h
index 38fd0b92b5..953b559f93 100644
--- a/sysdeps/i386/fpu/fenv_private.h
+++ b/sysdeps/i386/fpu/fenv_private.h
@@ -5,7 +5,7 @@
 #include <fenv.h>
 #include <fpu_control.h>
 
-#ifdef __SSE2_MATH__
+#if defined(__SSE2_MATH__) && !defined(__clang__)
 # define math_opt_barrier(x)						\
   ({ __typeof(x) __x;							\
      if (sizeof (x) <= sizeof (double)					\
diff --git a/sysdeps/ieee754/float128/Makeconfig b/sysdeps/ieee754/float128/Makeconfig
index a493ff1d41..99ae5e07bb 100644
--- a/sysdeps/ieee754/float128/Makeconfig
+++ b/sysdeps/ieee754/float128/Makeconfig
@@ -1,4 +1,4 @@
 # Include this earlier so it can be used earlier in Makefiles,
 # and sysdep/ makefiles.
-float128-fcts = yes
+float128-fcts = $(enable-float128)
 float64x-alias-fcts = yes
diff --git a/sysdeps/ieee754/float128/Makefile b/sysdeps/ieee754/float128/Makefile
index 571a841809..70bb3ac406 100644
--- a/sysdeps/ieee754/float128/Makefile
+++ b/sysdeps/ieee754/float128/Makefile
@@ -1,3 +1,4 @@
+ifeq ($(enable-float128),yes)
 ifeq ($(subdir),stdlib)
 routines += float1282mpn strfromf128
 routines += strtof128 strtof128_l strtof128_nan mpn2float128
@@ -10,3 +11,4 @@ endif
 ifeq ($(subdir),wcsmbs)
 routines += wcstof128_l wcstof128 wcstof128_nan
 endif
+endif # enable-float128
diff --git a/sysdeps/x86/bits/floatn.h b/sysdeps/x86/bits/floatn.h
index 49c75f26c5..11a147c483 100644
--- a/sysdeps/x86/bits/floatn.h
+++ b/sysdeps/x86/bits/floatn.h
@@ -21,6 +21,8 @@
 
 #include <features.h>
 
+#define capture(sym, val) extern int sym[val]
+
 /* Defined to 1 if the current compiler invocation provides a
    floating-point type with the IEEE 754 binary128 format, and this
    glibc includes corresponding *f128 interfaces for it.  The required
@@ -55,6 +57,9 @@
 
 #ifndef __ASSEMBLER__
 
+capture(i_have_float128, __HAVE_FLOAT128);
+capture(i_have_distinct_float128, __HAVE_DISTINCT_FLOAT128);
+
 /* Defined to concatenate the literal suffix to be used with _Float128
    types, if __HAVE_FLOAT128 is 1. */
 # if __HAVE_FLOAT128
@@ -83,9 +88,25 @@ typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
 
 /* The type _Float128 exists only since GCC 7.0.  */
 #  if !__GNUC_PREREQ (7, 0) || defined __cplusplus
+/* need a clang 5.0 case here? */
 typedef __float128 _Float128;
 #  endif
 
+#if defined __clang__
+
+#if 0 /* clang 5.0 or less */
+#define __builtin_huge_valf128() ((_Float128) __builtin_huge_val ())
+#define __builtin_inff128() ((_Float128) __builtin_inf ())
+#define __builtin_nanf128(x) ((_Float128) __builtin_nan (x))
+#define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
+
+#define __builtin_copysignf128(x,y) ((_Float128) __builtin_copysign ((double)(x),(double)(y)))
+#define __builtin_fabsf128(x) ((_Float128) __builtin_fabs ((double)(x)))
+#endif
+#define __builtin_signbitf128(x) (__builtin_signbit (x))
+
+#else /* GCC */
+
 /* __builtin_huge_valf128 doesn't exist before GCC 7.0.  */
 #  if !__GNUC_PREREQ (7, 0)
 #   define __builtin_huge_valf128() ((_Float128) __builtin_huge_val ())
@@ -112,8 +133,14 @@ typedef __float128 _Float128;
 #   define __builtin_signbitf128 __signbitf128
 #  endif
 
+#endif /* clang or GCC */
+
 # endif
 
+#if !__HAVE_FLOAT128 && defined __clang__
+typedef long double _Float128;
+#endif
+
 #endif /* !__ASSEMBLER__.  */
 
 #include <bits/floatn-common.h>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-27 23:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 23:21 [glibc/maskray/grte] Add workarounds for incomplete float128 support in clang Fangrui Song

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