[8/9] ldbl-128ibm-compat: Redirect long double functions to f128/ieee128 functions

Message ID 20180606223909.16675-9-tuliom@linux.ibm.com
State New
Headers show
Series
  • Introduce ieee128 symbols and redirections
Related show

Commit Message

Tulio Magno Quites Machado Filho June 6, 2018, 10:39 p.m.
Modify the headers to redirect long double functions to global __*f128
symbols or to __*ieee128 otherwise.

Most of the functions benefit from math-redir.h.  The only exceptions
are nexttowardf and nexttoward that need especial treatment.

2018-06-06  Tulio Magno Quites Machado Filho  <tuliom@linux.ibm.com>

	* include/math.h [__HAVE_DISTINCT_FLOAT128 &&
	!__HAVE_FLOAT128_UNLIKE_LDBL]: Avoid redirecting __finitel,
	__isinfl, __isnanl, __fpclassifyl, __issignalingl, __expl,
	__expml and sqrtl as they conflict with the redirections from
	math/math.h.
	* sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h
	[__HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL]: Likewise
	for function iscanonical(_Float128).
	* math/math.h [__HAVE_DISTINCT_FLOAT128 &&
	!__HAVE_FLOAT128_UNLIKE_LDBL]: Redirect long double functions to
	__*f128 or _*ieee128, reusing mathcalls-redir.h.

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
---
 include/math.h                                 | 12 +++++-
 math/math.h                                    | 57 +++++++++++++++++++++++++-
 sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h |  6 ++-
 3 files changed, 70 insertions(+), 5 deletions(-)

Patch

diff --git a/include/math.h b/include/math.h
index e21d34b868..57d77cfd13 100644
--- a/include/math.h
+++ b/include/math.h
@@ -18,7 +18,9 @@  hidden_proto (__finitef)
 hidden_proto (__isinff)
 hidden_proto (__isnanf)
 
-#  ifndef __NO_LONG_DOUBLE_MATH
+#  if !defined __NO_LONG_DOUBLE_MATH \
+      && (!__HAVE_DISTINCT_FLOAT128 \
+	  || (__HAVE_DISTINCT_FLOAT128 && __HAVE_FLOAT128_UNLIKE_LDBL))
 hidden_proto (__finitel)
 hidden_proto (__isinfl)
 hidden_proto (__isnanl)
@@ -40,7 +42,9 @@  libm_hidden_proto (__exp)
 libm_hidden_proto (__expf)
 libm_hidden_proto (__roundeven)
 
-# ifndef __NO_LONG_DOUBLE_MATH
+#  if !defined __NO_LONG_DOUBLE_MATH \
+  && (!__HAVE_DISTINCT_FLOAT128 \
+      || (__HAVE_DISTINCT_FLOAT128 && __HAVE_FLOAT128_UNLIKE_LDBL))
 libm_hidden_proto (__fpclassifyl)
 libm_hidden_proto (__issignalingl)
 libm_hidden_proto (__expl)
@@ -61,7 +65,11 @@  libm_hidden_proto (__expm1f128)
 float (sqrtf) (float) asm ("__ieee754_sqrtf");
 double (sqrt) (double) asm ("__ieee754_sqrt");
 #   ifndef __NO_LONG_DOUBLE_MATH
+/* Do not redirect sqrtl twice when the long double already redirects it.  */
+#    if !__HAVE_DISTINCT_FLOAT128 \
+	|| (__HAVE_DISTINCT_FLOAT128 && __HAVE_FLOAT128_UNLIKE_LDBL)
 long double (sqrtl) (long double) asm ("__ieee754_sqrtl");
+#    endif
 #   endif
 #   if __HAVE_DISTINCT_FLOAT128 > 0
 _Float128 (sqrtf128) (_Float128) asm ("__ieee754_sqrtf128");
diff --git a/math/math.h b/math/math.h
index 3edf275e26..6ad6c7f6d0 100644
--- a/math/math.h
+++ b/math/math.h
@@ -348,6 +348,42 @@  extern long double __REDIRECT_NTH (nexttowardl,
 #  define __MATH_DECLARE_LDOUBLE   1
 #  include <bits/mathcalls-helper-functions.h>
 #  include <bits/mathcalls.h>
+
+/* Provide ieee long double function redirection.  */
+#  if !defined __LDBL_COMPAT \
+      && __HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL
+#   define __REDIRFROM_X(function, reentrant) \
+  function ## l ## reentrant
+#   define __REDIRTO_X(function, reentrant) \
+  __ ## function ## ieee128 ## reentrant
+#   define __REDIRTO_ALT_X(function, reentrant)	\
+  __ ## function ## f128 ## reentrant
+#   define __MATH_REDIR_X(type, from, args, to)			\
+  extern type __REDIRECT_NTH (from, args, to);			\
+  extern type __REDIRECT_NTH (__CONCAT(__,from), args, to);
+#   if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
+/* Do not redirect when finite functions are requested.  Leave this job to
+   bits/math-finite.h.  */
+#    define __MATH_REDIR_FINITE 0
+#   else
+#    define __MATH_REDIR_FINITE 1
+#   endif
+#   define __MATH_REDIR_NON_FINITE 1
+#   include <bits/mathcalls-redir.h>
+/* Redirect all nexttoward functions when redirecting long double.  */
+__MATH_REDIR_X (float, nexttowardf, (float __x, long double __y), \
+		__REDIRTO_X (nexttowardf_to_,));
+__MATH_REDIR_X (double, nexttoward, (double __x, long double __y), \
+		__REDIRTO_X (nexttoward_to_,));
+
+#   undef __MATH_REDIR_NON_FINITE
+#   undef __MATH_REDIR_FINITE
+#   undef __MATH_REDIR_X
+#   undef __REDIRTO_ALT_X
+#   undef __REDIRTO_X
+#   undef __REDIRFROM_X
+#  endif
+
 #  undef _Mdouble_
 #  undef __MATH_PRECNAME
 #  undef __MATH_DECLARING_DOUBLE
@@ -511,6 +547,11 @@  extern long double __REDIRECT_NTH (nexttowardl,
 # ifdef __LDBL_COMPAT
 #  define __MATHCALL_REDIR_NAME(name) f ## name
 #  undef __MATHCALL_NARROW
+#  define __MATHCALL_NARROW(func, redir, nargs) \
+  __MATHCALL_NARROW_REDIR (func, redir, nargs)
+# elif __HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL
+#  define __MATHCALL_REDIR_NAME(name) f32 ## name ## f128
+#  undef __MATHCALL_NARROW
 #  define __MATHCALL_NARROW(func, redir, nargs) \
   __MATHCALL_NARROW_REDIR (func, redir, nargs)
 # endif
@@ -518,7 +559,8 @@  extern long double __REDIRECT_NTH (nexttowardl,
 # undef _Mret_
 # undef _Marg_
 # undef __MATHCALL_NAME
-# ifdef __LDBL_COMPAT
+# if defined __LDBL_COMPAT \
+     || (__HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL)
 #  undef __MATHCALL_REDIR_NAME
 #  undef __MATHCALL_NARROW
 #  define __MATHCALL_NARROW(func, redir, nargs) \
@@ -531,6 +573,11 @@  extern long double __REDIRECT_NTH (nexttowardl,
 # ifdef __LDBL_COMPAT
 #  define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
 #  undef __MATHCALL_NARROW
+#  define __MATHCALL_NARROW(func, redir, nargs) \
+  __MATHCALL_NARROW_REDIR (func, redir, nargs)
+# elif __HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL
+#  define __MATHCALL_REDIR_NAME(name) f64 ## name ## f128
+#  undef __MATHCALL_NARROW
 #  define __MATHCALL_NARROW(func, redir, nargs) \
   __MATHCALL_NARROW_REDIR (func, redir, nargs)
 # endif
@@ -538,7 +585,8 @@  extern long double __REDIRECT_NTH (nexttowardl,
 # undef _Mret_
 # undef _Marg_
 # undef __MATHCALL_NAME
-# ifdef __LDBL_COMPAT
+# if defined __LDBL_COMPAT \
+     || (__HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL)
 #  undef __MATHCALL_REDIR_NAME
 #  undef __MATHCALL_NARROW
 #  define __MATHCALL_NARROW(func, redir, nargs) \
@@ -1296,6 +1344,11 @@  iszero (__T __val)
    __ ## function ## reentrant ## _finite
 #    define __REDIRTO_PUBLIC_X(function, reentrant) \
    __REDIRTO_X(function, reentrant)
+#   elif __HAVE_DISTINCT_FLOAT128 && !__HAVE_FLOAT128_UNLIKE_LDBL
+#    define __REDIRTO_X(function, reentrant)	\
+   __ ## function ## f128 ## reentrant ## _finite
+#    define __REDIRTO_PUBLIC_X(function, reentrant) \
+   __ ## function ## l ## reentrant ## _finite
 #   else
 #    define __REDIRTO_X(function, reentrant) \
    __ ## function ## l ## reentrant ## _finite
diff --git a/sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h b/sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h
index 60c54cca46..f54e5d9ddb 100644
--- a/sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h
+++ b/sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h
@@ -50,7 +50,11 @@  extern "C++" {
 inline int iscanonical (float __val) { return __iscanonicalf (__val); }
 inline int iscanonical (double __val) { return __iscanonical (__val); }
 inline int iscanonical (long double __val) { return __iscanonicall (__val); }
-#  if __HAVE_DISTINCT_FLOAT128
+/* When using an IEEE 128-bit long double, _Float128 is defined as long double
+   in C++.  */
+#  if __HAVE_DISTINCT_FLOAT128 \
+      && (!defined __cplusplus \
+	  || defined __cplusplus && __HAVE_FLOAT128_UNLIKE_LDBL)
 inline int iscanonical (_Float128 __val) { return __iscanonicalf128 (__val); }
 #  endif
 }