public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 1/3] libstdc++: Stop using _GLIBCXX_USE_C99_COMPLEX_TR1 in <complex>
Date: Tue, 16 May 2023 10:11:30 +0100	[thread overview]
Message-ID: <20230516091132.1698684-1-jwakely@redhat.com> (raw)

Tested powerpc64le-linux. Pushed to trunk.

-- >8 --

The _GLIBCXX_USE_C99_COMPLEX_TR1 macro (and the comments about it in
acinclude.m4 and config.h) are misleading when it is also used for
<complex>, not only <tr1/complex>. It is also wrong, because the
configure checks for TR1 use -std=c++98 and a target might define cacos
etc. for C++11 but not for C++98.

Add a separate configure check for the inverse trigonometric functions
that are covered by _GLIBCXX_USE_C99_COMPLEX_TR1, but using -std=c++11
for the checks. Use the result of that separate check in <complex>.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_USE_C99): Check for complex inverse trig
	functions in C++11 mode and define _GLIBCXX_USE_C99_COMPLEX_ARC.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* doc/doxygen/user.cfg.in (PREDEFINED): Add new macro.
	* include/std/complex: Check _GLIBCXX_USE_C99_COMPLEX_ARC
	instead of _GLIBCXX_USE_C99_COMPLEX_TR1.
---
 libstdc++-v3/acinclude.m4            | 37 +++++++++++++++++++
 libstdc++-v3/config.h.in             |  5 +++
 libstdc++-v3/configure               | 53 ++++++++++++++++++++++++++++
 libstdc++-v3/doc/doxygen/user.cfg.in |  1 +
 libstdc++-v3/include/std/complex     | 14 ++++----
 5 files changed, 103 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 0ce3b8b5b31..84b12adbc24 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1200,6 +1200,43 @@ AC_DEFUN([GLIBCXX_ENABLE_C99], [
         requires corresponding C99 library functions to be present.])
     fi
 
+    # Check for the existence of <complex.h> complex inverse trigonometric
+    # math functions used by <complex> for C++11 and later.
+    ac_c99_complex_arc=no;
+    if test x"$ac_has_complex_h" = x"yes"; then
+      AC_MSG_CHECKING([for ISO C99 support for inverse trig functions in <complex.h>])
+      AC_TRY_COMPILE([#include <complex.h>],
+		     [typedef __complex__ float float_type; float_type tmpf;
+		      cacosf(tmpf);
+		      casinf(tmpf);
+		      catanf(tmpf);
+		      cacoshf(tmpf);
+		      casinhf(tmpf);
+		      catanhf(tmpf);
+		      typedef __complex__ double double_type; double_type tmpd;
+		      cacos(tmpd);
+		      casin(tmpd);
+		      catan(tmpd);
+		      cacosh(tmpd);
+		      casinh(tmpd);
+		      catanh(tmpd);
+		      typedef __complex__ long double ld_type; ld_type tmpld;
+		      cacosl(tmpld);
+		      casinl(tmpld);
+		      catanl(tmpld);
+		      cacoshl(tmpld);
+		      casinhl(tmpld);
+		      catanhl(tmpld);
+		     ],[ac_c99_complex_arc=yes], [ac_c99_complex_arc=no])
+    fi
+    AC_MSG_RESULT($ac_c99_complex_arc)
+    if test x"$ac_c99_complex_arc" = x"yes"; then
+      AC_DEFINE(_GLIBCXX_USE_C99_COMPLEX_ARC, 1,
+		[Define if C99 inverse trig functions in <complex.h> should be
+		used in <complex>. Using compiler builtins for these functions
+		requires corresponding C99 library functions to be present.])
+    fi
+
     # Check for the existence in <stdio.h> of vscanf, et. al.
     AC_CACHE_CHECK([for ISO C99 support in <stdio.h> for C++11],
       glibcxx_cv_c99_stdio_cxx11, [
diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in
index 14981c96f95..210e13400b9 100644
--- a/libstdc++-v3/doc/doxygen/user.cfg.in
+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
@@ -2352,6 +2352,7 @@ PREDEFINED             = __cplusplus=202002L \
                          _GLIBCXX_USE_NOEXCEPT=noexcept \
                          _GLIBCXX_USE_WCHAR_T \
                          _GLIBCXX_USE_LONG_LONG \
+			 _GLIBCXX_USE_C99_COMPLEX_ARC \
                          _GLIBCXX_USE_C99_STDINT_TR1 \
                          _GLIBCXX_USE_SCHED_YIELD \
                          _GLIBCXX_USE_NANOSLEEP \
diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index 0f5f14c3ddb..40fc062e53d 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -2021,7 +2021,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag());
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
 #if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
   inline __complex__ _Float16
   __complex_acos(__complex__ _Float16 __z)
@@ -2177,7 +2177,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 #endif
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_acos(__complex__ float __z)
   { return __builtin_cacosf(__z); }
@@ -2213,7 +2213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return std::complex<_Tp>(__t.imag(), -__t.real());
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_asin(__complex__ float __z)
   { return __builtin_casinf(__z); }
@@ -2257,7 +2257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			       _Tp(0.25) * log(__num / __den));
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_atan(__complex__ float __z)
   { return __builtin_catanf(__z); }
@@ -2293,7 +2293,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 				 + std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_acosh(__complex__ float __z)
   { return __builtin_cacoshf(__z); }
@@ -2332,7 +2332,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return std::log(__t + __z);
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_asinh(__complex__ float __z)
   { return __builtin_casinhf(__z); }
@@ -2376,7 +2376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			       _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
     }
 
-#if _GLIBCXX_USE_C99_COMPLEX_TR1
+#if _GLIBCXX_USE_C99_COMPLEX_ARC
   inline __complex__ float
   __complex_atanh(__complex__ float __z)
   { return __builtin_catanhf(__z); }
-- 
2.40.1


             reply	other threads:[~2023-05-16  9:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  9:11 Jonathan Wakely [this message]
2023-05-16  9:11 ` [committed 2/3] libstdc++: Stop using _GLIBCXX_USE_C99_STDINT_TR1 in <cstdint> Jonathan Wakely
2023-05-16  9:11 ` [committed 3/3] libstdc++: Stop using TR1 macros in <cctype> and <cfenv> Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230516091132.1698684-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).