[2/4] Macroize inclusion of math-finite.h (part 2)

Submitted by Gabriel Ferreira Teles Gomes on March 13, 2017, 9:01 p.m.

Details

Message ID 1489438919-4009-3-git-send-email-gftg@linux.vnet.ibm.com
State New
Headers show

Commit Message

Gabriel Ferreira Teles Gomes March 13, 2017, 9:01 p.m.
I could not come up with a more clever way to declare __lgammal_r_finite when
__NO_LONG_DOUBLE_MATH is set.
---
 math/bits/math-finite.h | 49 ++++++++++++++++---------------------------------
 math/math.h             |  6 ++++++
 2 files changed, 22 insertions(+), 33 deletions(-)

Comments

Joseph S. Myers March 21, 2017, 6:20 p.m.
On Mon, 13 Mar 2017, Gabriel F. T. Gomes wrote:

> I could not come up with a more clever way to declare __lgammal_r_finite when
> __NO_LONG_DOUBLE_MATH is set.

It should be OK to use __REDIRECT_NTH when the asm name used is the same 
name the function would have had anyway.  So declare __lgamma*_r_finite 
using __MATH_REDIRCALL_2 (__lgamma, _r_finite, (_Mdouble_, int *), lgamma) 
or similar.

Patch hide | download patch | download mbox

diff --git a/math/bits/math-finite.h b/math/bits/math-finite.h
index 8f29698..ea199ed 100644
--- a/math/bits/math-finite.h
+++ b/math/bits/math-finite.h
@@ -126,50 +126,33 @@  __MATH_REDIRCALL (yn, , (int, _Mdouble_));
 __MATH_REDIRCALL (lgamma, _r, (_Mdouble_, int *));
 #endif
 
-extern double __lgamma_r_finite (double, int *);
-extern float __lgammaf_r_finite (float, int *);
-#ifdef __NO_LONG_DOUBLE_MATH
-extern long double __REDIRECT_NTH (__lgammal_r_finite, (long double, int *),
-				   __lgamma_r_finite);
+/* Special case when declaring the finite long double version of
+   lgamma_r (__lgammal_r_finite).  */
+#if __MATH_DECLARING_LGAMMAL && defined __NO_LONG_DOUBLE_MATH
+extern long double
+__REDIRECT_NTH (__lgammal_r_finite, (long double, int *),
+		__lgamma_r_finite);
 #else
-extern long double __lgammal_r_finite (long double, int *);
+extern _Mdouble_
+__REDIRFROM (__lgamma, _r_finite, _MSUF_) (_Mdouble_, int *);
 #endif
 
-#if ((defined __USE_XOPEN || defined __USE_ISOC99) \
-     && defined __extern_always_inline)
+#if defined __extern_always_inline \
+    && ((__MATH_DECLARING_DOUBLE && \
+	 (defined __USE_XOPEN || defined __USE_ISOC99)) \
+	|| (!__MATH_DECLARING_DOUBLE && defined __USE_ISOC99))
 /* lgamma.  */
-__extern_always_inline double __NTH (lgamma (double __d))
+__extern_always_inline _Mdouble_
+__NTH (__REDIRFROM (lgamma, , _MSUF_) (_Mdouble_ __d))
 {
 # if defined __USE_MISC || defined __USE_XOPEN
-  return __lgamma_r_finite (__d, &signgam);
+  return __REDIRTO (lgamma, _r, _MSUF_) (__d, &signgam);
 # else
   int __local_signgam = 0;
-  return __lgamma_r_finite (__d, &__local_signgam);
+  return __REDIRTO (lgamma, _r, _MSUF_) (__d, &__local_signgam);
 # endif
 }
 #endif
-#if defined __USE_ISOC99 && defined __extern_always_inline
-__extern_always_inline float __NTH (lgammaf (float __d))
-{
-# if defined __USE_MISC || defined __USE_XOPEN
-  return __lgammaf_r_finite (__d, &signgam);
-# else
-  int __local_signgam = 0;
-  return __lgammaf_r_finite (__d, &__local_signgam);
-# endif
-}
-# ifdef __MATH_DECLARE_LDOUBLE
-__extern_always_inline long double __NTH (lgammal (long double __d))
-{
-# if defined __USE_MISC || defined __USE_XOPEN
-  return __lgammal_r_finite (__d, &signgam);
-# else
-  int __local_signgam = 0;
-  return __lgammal_r_finite (__d, &__local_signgam);
-# endif
-}
-# endif
-#endif
 
 #if ((defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)) \
      && defined __extern_always_inline)
diff --git a/math/math.h b/math/math.h
index 09709c4..8a5c6f9 100644
--- a/math/math.h
+++ b/math/math.h
@@ -572,27 +572,33 @@  extern int matherr (struct exception *__exc);
 /* Include bits/math-finite.h for double.  */
 # define _Mdouble_ double
 # define __MATH_DECLARING_DOUBLE 1
+# define __MATH_DECLARING_LGAMMAL 0
 # define _MSUF_
 # include <bits/math-finite.h>
 # undef _Mdouble_
 # undef __MATH_DECLARING_DOUBLE
+# undef __MATH_DECLARING_LGAMMAL
 # undef _MSUF_
 /* Include bits/math-finite.h for float.  */
 # define _Mdouble_ float
 # define __MATH_DECLARING_DOUBLE 0
+# define __MATH_DECLARING_LGAMMAL 0
 # define _MSUF_ f
 # include <bits/math-finite.h>
 # undef _Mdouble_
 # undef __MATH_DECLARING_DOUBLE
+# undef __MATH_DECLARING_LGAMMAL
 # undef _MSUF_
 /* Include bits/math-finite.h for long double.  */
 # if __MATH_DECLARE_LDOUBLE
 #  define _Mdouble_ long double
 #  define __MATH_DECLARING_DOUBLE 0
+#  define __MATH_DECLARING_LGAMMAL 1
 #  define _MSUF_ l
 #  include <bits/math-finite.h>
 #  undef _Mdouble_
 #  undef __MATH_DECLARING_DOUBLE
+#  undef __MATH_DECLARING_LGAMMAL
 #  undef _MSUF_
 # endif
 #endif