[6/8] float128: Expose _Float128 finite math functions.

Message ID 1478716859-3246-7-git-send-email-gftg@linux.vnet.ibm.com
State Superseded
Delegated to: Joseph Myers
Headers

Commit Message

Gabriel F T Gomes Nov. 9, 2016, 6:40 p.m. UTC
  From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>

Similar to the other types, entry points to
dodge wrapper call for non-finite arguments.

	* math/bits/math-finite.h:
	(__acosf128_finite): New function declaration.
	(__acoshf128_finite): Likewise.
	(__asinf128_finite): Likewise.
	(__atan2f128_finite): Likewise.
	(__atanhf128_finite): Likewise.
	(__coshf128_finite): Likewise.
	(__expf128_finite): Likewise.
	(__exp10f128_finite): Likewise.
	(__exp2f128_finite): Likewise.
	(__fmodf128_finite): Likewise.
	(__hypotf128_finite): Likewise.
	(__j0f128_finite): Likewise.
	(__y0f128_finite): Likewise.
	(__j1f128_finite): Likewise.
	(__y1f128_finite): Likewise.
	(__jnf128_finite): Likewise.
	(__ynf128_finite): Likewise.
	(__logf128_finite): Likewise.
	(__log10f128_finite): Likewise.
	(__log2f128_finite): Likewise.
	(__powf128_finite): Likewise.
	(__remainderf128_finite): Likewise.
	(__sinhf128_finite): Likewise.
	(__sqrtf128_finite): Likewise.
	(__gammaf128_r_finite): Likewise.
	(__lgammaf128_r_finite): Likewise.
	(lgammaf128): Inline override of the
	same name.
	(tgammaf128): Likewise.
---
 math/bits/math-finite.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
  

Comments

Joseph Myers Nov. 9, 2016, 10:05 p.m. UTC | #1
On Wed, 9 Nov 2016, Gabriel F. T. Gomes wrote:

> From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>
> 
> Similar to the other types, entry points to
> dodge wrapper call for non-finite arguments.

Rather than a load of repetitive boilerplate, the function declarations 
here should be macroized, with only the definition of the macros depending 
on __USE_ISOC99, __MATH_DECLARE_LDOUBLE, __NO_LONG_DOUBLE_MATH and 
float128 presence etc. (for most functions, maybe obsolete and lgamma ones 
are more complicated).
  
Gabriel F T Gomes March 3, 2017, 8:17 p.m. UTC | #2
On Wed, 9 Nov 2016 22:05:57 +0000
Joseph Myers <joseph@codesourcery.com> wrote:

> Rather than a load of repetitive boilerplate, the function declarations 
> here should be macroized, with only the definition of the macros depending 
> on __USE_ISOC99, __MATH_DECLARE_LDOUBLE, __NO_LONG_DOUBLE_MATH and 
> float128 presence etc. (for most functions, maybe obsolete and lgamma ones 
> are more complicated).
> 

My attempts to macroize the function declarations were a bit
frustrating.  While some of the declarations follow a nice pattern
(always declare for double; always declare for float when __USE_ISOC99;
declare for long double based on __USE_ISOC99, __MATH_DECLARE_LDOUBLE,
and __NO_LONG_DOUBLE_MATH), when that is not the case, the declarations
are somewhat less clear and trickier to read, imo.

For instance:

For exp10 and pow10, the float version is declared *even* when
__USE_ISOC99 is not. This means that I cannot create a macro that
*always* checks for __USE_ISOC99 to declare the float version.
Otherwise, I need to declare the float versions of exp10 and pow10
without using such macro.  I find it less clear [to declare some
functions using macros, while others without] than current code.

Another option would be to create this macro not dependent on
__USE_ISOC99, but then it defeats the purpose [of making the macros
dependent on __USE_ISOC99], which you suggested.


I would like to keep this patch as is for the next iteration of this
series...  Would you be fine with that?  Or maybe you had something
else in mind and I was not able to grasp.


Thanks,
Gabriel
  
Joseph Myers March 3, 2017, 8:50 p.m. UTC | #3
On Fri, 3 Mar 2017, Gabriel F. T. Gomes wrote:

> On Wed, 9 Nov 2016 22:05:57 +0000
> Joseph Myers <joseph@codesourcery.com> wrote:
> 
> > Rather than a load of repetitive boilerplate, the function declarations 
> > here should be macroized, with only the definition of the macros depending 
> > on __USE_ISOC99, __MATH_DECLARE_LDOUBLE, __NO_LONG_DOUBLE_MATH and 
> > float128 presence etc. (for most functions, maybe obsolete and lgamma ones 
> > are more complicated).
> > 
> 
> My attempts to macroize the function declarations were a bit
> frustrating.  While some of the declarations follow a nice pattern
> (always declare for double; always declare for float when __USE_ISOC99;
> declare for long double based on __USE_ISOC99, __MATH_DECLARE_LDOUBLE,
> and __NO_LONG_DOUBLE_MATH), when that is not the case, the declarations
> are somewhat less clear and trickier to read, imo.

In subsequent discussions 
<https://sourceware.org/ml/libc-alpha/2017-01/msg00404.html> I suggested 
the right approach was like bits/mathcalls.h: make bits/math-finite.h into 
a header included once for each type, with different macros defined.  The 
inclusions for float and long double would be conditional on __USE_ISOC99 
(and the inclusions for _Float128 would be conditional on the same 
conditions under which bits/mathcalls.h is included for _Float128).

An alternative would be merging bits/math-finite.h into bits/mathcalls.h 
as I suggested in 
<https://sourceware.org/ml/libc-alpha/2016-11/msg01098.html>, but I think 
that would be more complicated to implement.

> For exp10 and pow10, the float version is declared *even* when
> __USE_ISOC99 is not. This means that I cannot create a macro that

That's because __USE_GNU implies __USE_ISOC99.  That also means that there 
is no change in semantics from making the inclusion for float conditional 
on __USE_ISOC99, as those float versions will still be declared exactly 
for __USE_GNU.
  

Patch

diff --git a/math/bits/math-finite.h b/math/bits/math-finite.h
index adaad0e..0c6e2ff 100644
--- a/math/bits/math-finite.h
+++ b/math/bits/math-finite.h
@@ -32,6 +32,9 @@  extern long double __REDIRECT_NTH (acosl, (long double), __acosl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (acosf128, (_Float128), __acosf128_finite);
+#endif
 
 #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
 /* acosh.  */
@@ -47,6 +50,9 @@  extern long double __REDIRECT_NTH (acoshl, (long double), __acoshl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (acoshf128, (_Float128), __acoshf128_finite);
+#endif
 
 /* asin.  */
 extern double __REDIRECT_NTH (asin, (double), __asin_finite);
@@ -60,6 +66,9 @@  extern long double __REDIRECT_NTH (asinl, (long double), __asinl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (asinf128, (_Float128), __asinf128_finite);
+#endif
 
 /* atan2.  */
 extern double __REDIRECT_NTH (atan2, (double, double), __atan2_finite);
@@ -75,6 +84,10 @@  extern long double __REDIRECT_NTH (atan2l, (long double, long double),
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (atan2f128, (_Float128, _Float128),
+				 __atan2f128_finite);
+#endif
 
 #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
 /* atanh.  */
@@ -90,6 +103,9 @@  extern long double __REDIRECT_NTH (atanhl, (long double), __atanhl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (atanhf128, (_Float128), __atanhf128_finite);
+#endif
 
 /* cosh.  */
 extern double __REDIRECT_NTH (cosh, (double), __cosh_finite);
@@ -103,6 +119,9 @@  extern long double __REDIRECT_NTH (coshl, (long double), __coshl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (coshf128, (_Float128), __coshf128_finite);
+#endif
 
 /* exp.  */
 extern double __REDIRECT_NTH (exp, (double), __exp_finite);
@@ -116,6 +135,9 @@  extern long double __REDIRECT_NTH (expl, (long double), __expl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (expf128, (_Float128), __expf128_finite);
+#endif
 
 #ifdef __USE_GNU
 /* exp10.  */
@@ -128,6 +150,9 @@  extern long double __REDIRECT_NTH (exp10l, (long double), __exp10_finite);
 extern long double __REDIRECT_NTH (exp10l, (long double), __exp10l_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (exp10f128, (_Float128), __exp10f128_finite);
+# endif
 
 /* pow10.  */
 extern double __REDIRECT_NTH (pow10, (double), __exp10_finite);
@@ -153,6 +178,9 @@  extern long double __REDIRECT_NTH (exp2l, (long double), __exp2l_finite);
 #  endif
 # endif
 #endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (exp2f128, (_Float128), __exp2f128_finite);
+# endif
 
 /* fmod.  */
 extern double __REDIRECT_NTH (fmod, (double, double), __fmod_finite);
@@ -168,6 +196,10 @@  extern long double __REDIRECT_NTH (fmodl, (long double, long double),
 #  endif
 # endif
 #endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (fmodf128, (_Float128, _Float128),
+				 __fmodf128_finite);
+# endif
 
 #if defined __USE_XOPEN || defined __USE_ISOC99
 /* hypot.  */
@@ -185,6 +217,10 @@  extern long double __REDIRECT_NTH (hypotl, (long double, long double),
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (hypotf128, (_Float128, _Float128),
+				   __hypotf128_finite);
+#endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
 /* j0.  */
@@ -199,6 +235,9 @@  extern long double __REDIRECT_NTH (j0l, (long double), __j0_finite);
 extern long double __REDIRECT_NTH (j0l, (long double), __j0l_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (j0f128, (_Float128), __j0f128_finite);
+# endif
 #endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
@@ -214,6 +253,9 @@  extern long double __REDIRECT_NTH (y0l, (long double), __y0_finite);
 extern long double __REDIRECT_NTH (y0l, (long double), __y0l_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (y0f128, (_Float128), __y0f128_finite);
+# endif
 #endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
@@ -229,6 +271,9 @@  extern long double __REDIRECT_NTH (j1l, (long double), __j1_finite);
 extern long double __REDIRECT_NTH (j1l, (long double), __j1l_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (j1f128, (_Float128), __j1f128_finite);
+# endif
 #endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
@@ -244,6 +289,9 @@  extern long double __REDIRECT_NTH (y1l, (long double), __y1_finite);
 extern long double __REDIRECT_NTH (y1l, (long double), __y1l_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (y1f128, (_Float128), __y1f128_finite);
+# endif
 #endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
@@ -259,6 +307,9 @@  extern long double __REDIRECT_NTH (jnl, (int, long double), __jn_finite);
 extern long double __REDIRECT_NTH (jnl, (int, long double), __jnl_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (jnf128, (int, _Float128), __jnf128_finite);
+# endif
 #endif
 
 #if defined __USE_MISC || defined __USE_XOPEN
@@ -274,6 +325,9 @@  extern long double __REDIRECT_NTH (ynl, (int, long double), __yn_finite);
 extern long double __REDIRECT_NTH (ynl, (int, long double), __ynl_finite);
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (ynf128, (int, _Float128), __ynf128_finite);
+# endif
 #endif
 
 #ifdef __USE_MISC
@@ -291,6 +345,10 @@  extern long double __REDIRECT_NTH (lgammal_r, (long double, int *),
 #   endif
 #  endif
 # endif
+# if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (lgammaf128_r, (_Float128, int *),
+				   __lgammaf128_r_finite);
+# endif
 #endif
 
 extern double __lgamma_r_finite (double, int *);
@@ -301,6 +359,9 @@  extern long double __REDIRECT_NTH (__lgammal_r_finite, (long double, int *),
 #else
 extern long double __lgammal_r_finite (long double, int *);
 #endif
+#if __USE_FLOAT128
+extern _Float128 __lgammaf128_r_finite (_Float128, int *);
+#endif
 
 #if ((defined __USE_XOPEN || defined __USE_ISOC99) \
      && defined __extern_always_inline)
@@ -336,6 +397,17 @@  __extern_always_inline long double __NTH (lgammal (long double __d))
 # endif
 }
 # endif
+# if __USE_FLOAT128
+__extern_always_inline _Float128 __NTH (lgammaf128 (_Float128 __d))
+{
+# if defined __USE_MISC || defined __USE_XOPEN
+  return __lgammaf128_r_finite (__d, &signgam);
+# else
+  int __local_signgam = 0;
+  return __lgammaf128_r_finite (__d, &__local_signgam);
+# endif
+}
+# endif
 #endif
 
 #if ((defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)) \
@@ -371,6 +443,9 @@  extern long double __REDIRECT_NTH (logl, (long double), __logl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (logf128, (_Float128), __logf128_finite);
+#endif
 
 /* log10.  */
 extern double __REDIRECT_NTH (log10, (double), __log10_finite);
@@ -384,6 +459,9 @@  extern long double __REDIRECT_NTH (log10l, (long double), __log10l_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (log10f128, (_Float128), __log10f128_finite);
+#endif
 
 #ifdef __USE_ISOC99
 /* log2.  */
@@ -397,6 +475,9 @@  extern long double __REDIRECT_NTH (log2l, (long double), __log2l_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (log2f128, (_Float128), __log2f128_finite);
+#endif
 
 /* pow.  */
 extern double __REDIRECT_NTH (pow, (double, double), __pow_finite);
@@ -412,6 +493,10 @@  extern long double __REDIRECT_NTH (powl, (long double, long double),
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (powf128, (_Float128, _Float128),
+				   __powf128_finite);
+#endif
 
 #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
 /* remainder.  */
@@ -429,6 +514,10 @@  extern long double __REDIRECT_NTH (remainderl, (long double, long double),
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (remainderf128, (_Float128, _Float128),
+				   __remainderf128_finite);
+#endif
 
 #if (defined __USE_MISC							\
      || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8))
@@ -460,6 +549,9 @@  extern long double __REDIRECT_NTH (sinhl, (long double), __sinhl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (sinhf128, (_Float128), __sinhf128_finite);
+#endif
 
 /* sqrt.  */
 extern double __REDIRECT_NTH (sqrt, (double), __sqrt_finite);
@@ -473,6 +565,9 @@  extern long double __REDIRECT_NTH (sqrtl, (long double), __sqrtl_finite);
 #  endif
 # endif
 #endif
+#if __USE_FLOAT128
+extern _Float128 __REDIRECT_NTH (sqrtf128, (_Float128), __sqrtf128_finite);
+#endif
 
 #if defined __USE_ISOC99 && defined __extern_always_inline
 /* tgamma.  */
@@ -503,4 +598,13 @@  __extern_always_inline long double __NTH (tgammal (long double __d))
   return __local_signgam < 0 ? -__res : __res;
 }
 # endif
+# if __USE_FLOAT128
+extern _Float128 __gammaf128_r_finite (_Float128, int *);
+__extern_always_inline _Float128 __NTH (tgammaf128 (_Float128 __d))
+{
+  int __local_signgam = 0;
+  _Float128 __res = __gammaf128_r_finite (__d, &__local_signgam);
+  return __local_signgam < 0 ? -__res : __res;
+}
+# endif
 #endif