On 2/3/20 3:10 PM, Paul E. Murphy wrote:
> From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
>
> Modify the headers to redirect long double functions to global __*f128
> symbols or to __*ieee128 otherwise.
>
> Most of the functions in math.h benefit from the infrastructure already
> available for __LDBL_COMPAT. The only exceptions are nexttowardf and
> nexttoward that need especial treatment.
>
> Both math/bits/mathcalls-helper-functions.h and math/bits/mathcalls.h
> were modified in order to provide alternative redirection destinations
> that are essential to support functions that should not be redirected to
> the same name pattern of the rest of the functions, i.e.: __fpclassify,
> __signbit, __iseqsig, __issignaling, isinf, finite and isnan, which will
> be redirected to __*f128 instead of __*ieee128 used for the rest.
> ---
> include/math.h | 9 ++-
> math/bits/mathcalls-helper-functions.h | 18 +++---
> math/bits/mathcalls.h | 9 ++-
> math/math.h | 59 ++++++++++++++++++-
> .../ieee754/ldbl-128ibm/bits/iscanonical.h | 8 ++-
> 5 files changed, 85 insertions(+), 18 deletions(-)
I think the majority of this patch is OK. My only contribution was to
fixup against the deprecation of the finite entry points.
The naming of the nexttoward ABI is a bit awkward, but I proffer no
better solutions.
If there are no requests for improvement, or objections, I will commit
this and the following patch 4, the equivalent support for complex.h, on
Friday.
> diff --git a/math/math.h b/math/math.h
> index e13b3f3a29..1692ff4a45 100644
> --- a/math/math.h
> +++ b/math/math.h
> @@ -283,6 +283,10 @@ enum
> extern type __MATH_PRECNAME(function,suffix) args __THROW
> #define __MATHDECL_1(type, function, suffix, args) \
> __MATHDECL_1_IMPL(type, function, suffix, args)
> +/* Ignore the alias by default. The alias is only useful with
> + redirections. */
> +#define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
> + __MATHDECL_1(type, function, suffix, args)
>
> #define __MATHREDIR(type, function, suffix, args, to) \
> extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to)
> @@ -338,6 +342,35 @@ extern long double __REDIRECT_NTH (nexttowardl,
> # undef __MATHDECL_1
> # define __MATHDECL_1(type, function,suffix, args) \
> __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
> +
> +# elif __LONG_DOUBLE_USES_FLOAT128 == 1
> +# ifdef __REDIRECT_NTH
> +# ifdef __USE_ISOC99
> +extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
> + __nexttowardf_to_ieee128)
> + __attribute__ ((__const__));
> +extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
> + __nexttoward_to_ieee128)
> + __attribute__ ((__const__));
@@ -18,7 +18,8 @@ hidden_proto (__finitef)
hidden_proto (__isinff)
hidden_proto (__isnanf)
-# ifndef __NO_LONG_DOUBLE_MATH
+# if !defined __NO_LONG_DOUBLE_MATH \
+ && __LONG_DOUBLE_USES_FLOAT128 == 0
hidden_proto (__finitel)
hidden_proto (__isinfl)
hidden_proto (__isnanl)
@@ -40,7 +41,8 @@ libm_hidden_proto (__exp)
libm_hidden_proto (__expf)
libm_hidden_proto (__roundeven)
-# ifndef __NO_LONG_DOUBLE_MATH
+# if !defined __NO_LONG_DOUBLE_MATH \
+ && __LONG_DOUBLE_USES_FLOAT128 == 0
libm_hidden_proto (__fpclassifyl)
libm_hidden_proto (__issignalingl)
libm_hidden_proto (__expl)
@@ -140,7 +142,8 @@ fabsf128 (_Float128 x)
double (FUNC) (ARGS (double)) asm (PREFIX #FUNC ); \
MATH_REDIRECT_LDBL (FUNC, PREFIX, ARGS) \
MATH_REDIRECT_F128 (FUNC, PREFIX, ARGS)
-# ifdef __NO_LONG_DOUBLE_MATH
+# if defined __NO_LONG_DOUBLE_MATH \
+ || __LONG_DOUBLE_USES_FLOAT128 == 1
# define MATH_REDIRECT_LDBL(FUNC, PREFIX, ARGS)
# else
# define MATH_REDIRECT_LDBL(FUNC, PREFIX, ARGS) \
@@ -16,28 +16,30 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-
/* Classify given number. */
-__MATHDECL_1 (int, __fpclassify,, (_Mdouble_ __value))
+__MATHDECL_ALIAS (int, __fpclassify,, (_Mdouble_ __value), fpclassify)
__attribute__ ((__const__));
/* Test for negative number. */
-__MATHDECL_1 (int, __signbit,, (_Mdouble_ __value))
+__MATHDECL_ALIAS (int, __signbit,, (_Mdouble_ __value), signbit)
__attribute__ ((__const__));
/* Return 0 if VALUE is finite or NaN, +1 if it
is +Infinity, -1 if it is -Infinity. */
-__MATHDECL_1 (int, __isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int, __isinf,, (_Mdouble_ __value), isinf)
+ __attribute__ ((__const__));
/* Return nonzero if VALUE is finite and not NaN. Used by isfinite macro. */
-__MATHDECL_1 (int, __finite,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int, __finite,, (_Mdouble_ __value), finite)
+ __attribute__ ((__const__));
/* Return nonzero if VALUE is not a number. */
-__MATHDECL_1 (int, __isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int, __isnan,, (_Mdouble_ __value), isnan)
+ __attribute__ ((__const__));
/* Test equality. */
-__MATHDECL_1 (int, __iseqsig,, (_Mdouble_ __x, _Mdouble_ __y));
+__MATHDECL_ALIAS (int, __iseqsig,, (_Mdouble_ __x, _Mdouble_ __y), iseqsig);
/* Test for signaling NaN. */
-__MATHDECL_1 (int, __issignaling,, (_Mdouble_ __value))
+__MATHDECL_ALIAS (int, __issignaling,, (_Mdouble_ __value), issignaling)
__attribute__ ((__const__));
@@ -174,12 +174,14 @@ __MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y));
&& !__MATH_DECLARING_FLOATN
/* Return 0 if VALUE is finite or NaN, +1 if it
is +Infinity, -1 if it is -Infinity. */
-__MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int,isinf,, (_Mdouble_ __value), isinf)
+ __attribute__ ((__const__));
# endif
# if !__MATH_DECLARING_FLOATN
/* Return nonzero if VALUE is finite and not NaN. */
-__MATHDECL_1 (int,finite,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int,finite,, (_Mdouble_ __value), finite)
+ __attribute__ ((__const__));
/* Return the remainder of X/Y. */
__MATHCALL (drem,, (_Mdouble_ __x, _Mdouble_ __y));
@@ -208,7 +210,8 @@ __MATHCALL (nan,, (const char *__tagb));
|| __MATH_DECLARING_DOUBLE == 0)) /* isnanf or isnanl don't. */ \
&& !__MATH_DECLARING_FLOATN
/* Return nonzero if VALUE is not a number. */
-__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
+__MATHDECL_ALIAS (int,isnan,, (_Mdouble_ __value), isnan)
+ __attribute__ ((__const__));
# endif
#endif
@@ -283,6 +283,10 @@ enum
extern type __MATH_PRECNAME(function,suffix) args __THROW
#define __MATHDECL_1(type, function, suffix, args) \
__MATHDECL_1_IMPL(type, function, suffix, args)
+/* Ignore the alias by default. The alias is only useful with
+ redirections. */
+#define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
+ __MATHDECL_1(type, function, suffix, args)
#define __MATHREDIR(type, function, suffix, args, to) \
extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to)
@@ -338,6 +342,35 @@ extern long double __REDIRECT_NTH (nexttowardl,
# undef __MATHDECL_1
# define __MATHDECL_1(type, function,suffix, args) \
__MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
+
+# elif __LONG_DOUBLE_USES_FLOAT128 == 1
+# ifdef __REDIRECT_NTH
+# ifdef __USE_ISOC99
+extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
+ __nexttowardf_to_ieee128)
+ __attribute__ ((__const__));
+extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
+ __nexttoward_to_ieee128)
+ __attribute__ ((__const__));
+
+#define __dremieee128 __remainderieee128
+#define __gammaieee128 __lgammaieee128
+
+# endif
+# endif
+
+# undef __MATHDECL_1
+# undef __MATHDECL_ALIAS
+
+# define __REDIRTO(function, suffix) \
+ __ ## function ## ieee128 ## suffix
+# define __REDIRTO_ALT(function, suffix) \
+ __ ## function ## f128 ## suffix
+
+# define __MATHDECL_1(type, function, suffix, args) \
+ __MATHREDIR (type, function, suffix, args, __REDIRTO (function, suffix))
+# define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
+ __MATHREDIR (type, function, suffix, args, __REDIRTO_ALT (alias, suffix))
# endif
/* Include the file of declarations again, this time using `long double'
@@ -350,15 +383,22 @@ extern long double __REDIRECT_NTH (nexttowardl,
# define __MATH_DECLARE_LDOUBLE 1
# include <bits/mathcalls-helper-functions.h>
# include <bits/mathcalls.h>
+
# undef _Mdouble_
# undef __MATH_PRECNAME
# undef __MATH_DECLARING_DOUBLE
# undef __MATH_DECLARING_FLOATN
-# if defined __LDBL_COMPAT
+# if defined __LDBL_COMPAT \
+ || __LONG_DOUBLE_USES_FLOAT128 == 1
+# undef __REDIRTO
+# undef __REDIRTO_ALT
# undef __MATHDECL_1
+# undef __MATHDECL_ALIAS
# define __MATHDECL_1(type, function, suffix, args) \
__MATHDECL_1_IMPL(type, function, suffix, args)
+# define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
+ __MATHDECL_1(type, function, suffix, args)
# endif
# endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
@@ -488,6 +528,7 @@ extern long double __REDIRECT_NTH (nexttowardl,
#undef __MATHDECL_1_IMPL
#undef __MATHDECL_1
+#undef __MATHDECL_ALIAS
#undef __MATHDECL
#undef __MATHCALL
@@ -519,6 +560,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 __LONG_DOUBLE_USES_FLOAT128 == 1
+# define __MATHCALL_REDIR_NAME(name) __ ## f32 ## name ## ieee128
+# undef __MATHCALL_NARROW
# define __MATHCALL_NARROW(func, redir, nargs) \
__MATHCALL_NARROW_REDIR (func, redir, nargs)
# endif
@@ -526,7 +572,8 @@ extern long double __REDIRECT_NTH (nexttowardl,
# undef _Mret_
# undef _Marg_
# undef __MATHCALL_NAME
-# ifdef __LDBL_COMPAT
+# if defined __LDBL_COMPAT \
+ || __LONG_DOUBLE_USES_FLOAT128 == 1
# undef __MATHCALL_REDIR_NAME
# undef __MATHCALL_NARROW
# define __MATHCALL_NARROW(func, redir, nargs) \
@@ -539,6 +586,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 __LONG_DOUBLE_USES_FLOAT128 == 1
+# define __MATHCALL_REDIR_NAME(name) __ ## f64 ## name ## ieee128
+# undef __MATHCALL_NARROW
# define __MATHCALL_NARROW(func, redir, nargs) \
__MATHCALL_NARROW_REDIR (func, redir, nargs)
# endif
@@ -546,7 +598,8 @@ extern long double __REDIRECT_NTH (nexttowardl,
# undef _Mret_
# undef _Marg_
# undef __MATHCALL_NAME
-# ifdef __LDBL_COMPAT
+# if defined __LDBL_COMPAT \
+ || __LONG_DOUBLE_USES_FLOAT128 == 1
# undef __MATHCALL_REDIR_NAME
# undef __MATHCALL_NARROW
# define __MATHCALL_NARROW(func, redir, nargs) \
@@ -23,8 +23,12 @@
#ifdef __NO_LONG_DOUBLE_MATH
# define iscanonical(x) ((void) (__typeof (x)) (x), 1)
#else
+# if __LONG_DOUBLE_USES_FLOAT128 == 1
+# define __iscanonicall(x) ((void) (__typeof (x)) (x), 1)
+# else
extern int __iscanonicall (long double __x)
__THROW __attribute__ ((__const__));
+# endif
# define __iscanonicalf(x) ((void) (__typeof (x)) (x), 1)
# define __iscanonical(x) ((void) (__typeof (x)) (x), 1)
# if __HAVE_DISTINCT_FLOAT128
@@ -50,7 +54,9 @@ 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 && __HAVE_FLOAT128_UNLIKE_LDBL
inline int iscanonical (_Float128 __val) { return __iscanonicalf128 (__val); }
# endif
}