public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] float128: Extend __MATH_TG for float128 support
@ 2017-05-17 20:04 Gabriel F. T. Gomes
  2017-05-17 20:12 ` Joseph Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel F. T. Gomes @ 2017-05-17 20:04 UTC (permalink / raw)
  To: libc-alpha

Changes since v1:

  - Add the new macro __HAVE_GENERIC_SELECTION to sys/cdefs.h to control if
    the current compiler invocation has support for _Generic.
  - Use the macro above in place of __USE_ISOC11 (which was wrong).

2017-02-23  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>
	    Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>

	* math/math.h (__MATH_TG): Extend the conditions to add
	_Float128 support.
	* misc/sys/cdefs.h (__HAVE_GENERIC_SELECTION): New macro.
---
 math/math.h      | 21 +++++++++++++++++++++
 misc/sys/cdefs.h | 16 ++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/math/math.h b/math/math.h
index 2d1508e..e217080 100644
--- a/math/math.h
+++ b/math/math.h
@@ -343,6 +343,27 @@ extern int signgam;
 #ifdef __NO_LONG_DOUBLE_MATH
 # define __MATH_TG(TG_ARG, FUNC, ARGS)					\
   (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
+#elif __HAVE_DISTINCT_FLOAT128
+# if __HAVE_GENERIC_SELECTION
+#  define __MATH_TG(TG_ARG, FUNC, ARGS)		\
+     _Generic ((TG_ARG),			\
+	       float: FUNC ## f ARGS,		\
+	       default: FUNC ARGS,		\
+	       long double: FUNC ## l ARGS,	\
+	       _Float128: FUNC ## f128 ARGS)
+# else
+#  define __MATH_TG(TG_ARG, FUNC, ARGS)					\
+     __builtin_choose_expr						\
+     (__builtin_types_compatible_p (__typeof (TG_ARG), float),		\
+      FUNC ## f ARGS,							\
+      __builtin_choose_expr						\
+      (__builtin_types_compatible_p (__typeof (TG_ARG), double),	\
+       FUNC ARGS,							\
+       __builtin_choose_expr						\
+       (__builtin_types_compatible_p (__typeof (TG_ARG), long double),	\
+	FUNC ## l ARGS,							\
+	FUNC ## f128 ARGS)))
+# endif
 #else
 # define __MATH_TG(TG_ARG, FUNC, ARGS)		\
   (sizeof (TG_ARG) == sizeof (float)		\
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 74f9a49..06523bf 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -464,4 +464,20 @@
 # define __glibc_macro_warning(msg)
 #endif
 
+/* Support for generic selection (ISO C11) is available in GCC since
+   version 4.9.  Previous versions do not provide generic selection,
+   even though they might set __STDC_VERSION__ to 201112L, when in
+   -std=c11 mode.  Thus, we must check for !defined __GNUC__ when
+   testing __STDC_VERSION__ for generic selection support.
+   On the other hand, Clang also defines __GNUC__, so a clang-specific
+   check is required to enable the use of generic selection.  */
+#if __GNUC_PREREQ (4, 9) \
+    || __glibc_clang_has_extension (c_generic_selections) \
+    || (!defined __GNUC__ && defined __STDC_VERSION__ \
+	&& __STDC_VERSION__ >= 201112L)
+# define __HAVE_GENERIC_SELECTION 1
+#else
+# define __HAVE_GENERIC_SELECTION 0
+#endif
+
 #endif	 /* sys/cdefs.h */
-- 
2.4.11

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

* Re: [PATCH v2] float128: Extend __MATH_TG for float128 support
  2017-05-17 20:04 [PATCH v2] float128: Extend __MATH_TG for float128 support Gabriel F. T. Gomes
@ 2017-05-17 20:12 ` Joseph Myers
  2017-05-18  1:39   ` Gabriel F. T. Gomes
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2017-05-17 20:12 UTC (permalink / raw)
  To: Gabriel F. T. Gomes; +Cc: libc-alpha

On Wed, 17 May 2017, Gabriel F. T. Gomes wrote:

> Changes since v1:
> 
>   - Add the new macro __HAVE_GENERIC_SELECTION to sys/cdefs.h to control if
>     the current compiler invocation has support for _Generic.
>   - Use the macro above in place of __USE_ISOC11 (which was wrong).
> 
> 2017-02-23  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>
> 	    Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>
> 
> 	* math/math.h (__MATH_TG): Extend the conditions to add
> 	_Float128 support.
> 	* misc/sys/cdefs.h (__HAVE_GENERIC_SELECTION): New macro.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v2] float128: Extend __MATH_TG for float128 support
  2017-05-17 20:12 ` Joseph Myers
@ 2017-05-18  1:39   ` Gabriel F. T. Gomes
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel F. T. Gomes @ 2017-05-18  1:39 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

On Wed, 17 May 2017 20:11:50 +0000
Joseph Myers <joseph@codesourcery.com> wrote:

> On Wed, 17 May 2017, Gabriel F. T. Gomes wrote:
> 
> > Changes since v1:
> > 
> >   - Add the new macro __HAVE_GENERIC_SELECTION to sys/cdefs.h to control if
> >     the current compiler invocation has support for _Generic.
> >   - Use the macro above in place of __USE_ISOC11 (which was wrong).
> > 
> > 2017-02-23  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>
> > 	    Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>
> > 
> > 	* math/math.h (__MATH_TG): Extend the conditions to add
> > 	_Float128 support.
> > 	* misc/sys/cdefs.h (__HAVE_GENERIC_SELECTION): New macro.  
> 
> OK.

Thanks.  Now committed.

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

end of thread, other threads:[~2017-05-18  1:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 20:04 [PATCH v2] float128: Extend __MATH_TG for float128 support Gabriel F. T. Gomes
2017-05-17 20:12 ` Joseph Myers
2017-05-18  1:39   ` Gabriel F. T. Gomes

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