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

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

commit 066e928543bd0263022468eb6ce0c5727de71fc9
Author: Stan Shebs <stanshebs@google.com>
Date:   Mon Jan 22 16:44:05 2018 -0800

    Add clang versions of CMPLX* macros

Diff:
---
 math/complex.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/math/complex.h b/math/complex.h
index 544e7acd82..50701f6115 100644
--- a/math/complex.h
+++ b/math/complex.h
@@ -52,23 +52,40 @@ __BEGIN_DECLS
 #undef I
 #define I _Complex_I
 
+#if defined(__clang__)
+/* Clang casts types to _Complex instead of using __builtin_complex.  */
+#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
+#define CMPLX(x, y) __CMPLX(x, y, double)
+#define CMPLXF(x, y) __CMPLX(x, y, float)
+#define CMPLXL(x, y) __CMPLX(x, y, long double)
+#else
 #if defined __USE_ISOC11 && __GNUC_PREREQ (4, 7)
 /* Macros to expand into expression of specified complex type.  */
 # define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
 # define CMPLXF(x, y) __builtin_complex ((float) (x), (float) (y))
 # define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y))
 #endif
+#endif /* __clang __ */
 
 #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
 # define CMPLXF16(x, y) __builtin_complex ((_Float16) (x), (_Float16) (y))
 #endif
 
 #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
+#if defined(__clang__)
+/* The typedef _Float32 does not seem to work here.  */
+# define CMPLXF32(x, y) __CMPLX(x, y, float)
+#else
 # define CMPLXF32(x, y) __builtin_complex ((_Float32) (x), (_Float32) (y))
+#endif /* __clang __ */
 #endif
 
 #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
+#if defined(__clang__)
+# define CMPLXF64(x, y) __CMPLX(x, y, double)
+#else
 # define CMPLXF64(x, y) __builtin_complex ((_Float64) (x), (_Float64) (y))
+#endif /* __clang __ */
 #endif
 
 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
@@ -76,11 +93,19 @@ __BEGIN_DECLS
 #endif
 
 #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
+#if defined(__clang__)
+# define CMPLXF32X(x, y) __CMPLX(x, y, double)
+#else
 # define CMPLXF32X(x, y) __builtin_complex ((_Float32x) (x), (_Float32x) (y))
 #endif
+#endif /* __clang __ */
 
 #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
+#if defined(__clang__)
+# define CMPLXF64X(x, y) __CMPLX(x, y, long double)
+#else
 # define CMPLXF64X(x, y) __builtin_complex ((_Float64x) (x), (_Float64x) (y))
+#endif /* __clang __ */
 #endif
 
 #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)


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

only message in thread, other threads:[~2021-08-27 23:20 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:20 [glibc/maskray/grte] Add clang versions of CMPLX* macros 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).