This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++ patch] Check for __builtins in std_cmath.h



This patch was originally developed as a possible solution to the
high priority PR libstdc++/3184.  Just my luck, PR 3184 was closed
earlier today whilst this patch was being regression tested.  It
does however protect against using __builtin functions on targets
that don't support them.

The libstdc++-v3/include/c_std version of <cmath.h> wasn't checking for
the existance of __builtin_sinf and similar functions before using them.
These were already being tested for by the libstdc++-v3 configure
machinery, and the resulting _GLIBCPP_HAVE___BUILTIN macros were being
used in the libstdc++-v3/include/c_shadow version of <cmath.h>.

This patch has been tested by "make bootstrap" and "make -k check" on
i686-pc-linux-gnu with no new regressions.  Alas because glibc implements
sinf and friends, this hasn't tested the previously failing code paths,
but hopefully the changes should be obvious.  I've proof read the code
several times just to be sure [famous last words].

Is this OK for mainline, even though it no longer has a PR?

Roger
--

2001-12-28  Roger Sayle <roger@eyesopen.com>
	* include/c_std/bits/std_cmath.h: Check for the existance
	of __builtin functions before using them.


*** gcc/libstdc++-v3/include/c_std/bits/std_cmath.h	Tue Sep  4 15:42:24 2001
--- patch6/libstdc++-v3/include/c_std/bits/std_cmath.h	Fri Dec 28 17:54:28 2001
*************** namespace std
*** 78,94 ****
        return __x < _Tp() ? -__x : __x;
      }

    inline float
!   abs(float __x)
!   { return __builtin_fabsf(__x); }

    inline double
!   abs(double __x)
!   { return __builtin_fabs(__x); }

    inline long double
!   abs(long double __x)
!   { return __builtin_fabsl(__x); }

  #if _GLIBCPP_HAVE_ACOSF
    inline float
--- 78,112 ----
        return __x < _Tp() ? -__x : __x;
      }

+ #if _GLIBCPP_HAVE___BUILTIN_FABSF
    inline float
!   abs(float __x) { return __builtin_fabsf(__x); }
! #elif _GLIBCPP_HAVE_FABSF
!   inline float
!   abs(float __x) { return ::fabsf(__x); }
! #else
!   inline float
!   abs(float __x) { return ::fabs(static_cast<double>(__x)); }
! #endif

+ #if _GLIBCPP_HAVE___BUILTIN_FABS
+   inline double
+   abs(double __x) { return __builtin_fabs(__x); }
+ #else
    inline double
!   abs(double __x) { return ::fabs(__x); }
! #endif

+ #if _GLIBCPP_HAVE___BUILTIN_FABSL
+   inline long double
+   abs(long double __x) { return __builtin_fabsl(__x); }
+ #elif _GLIBCPP_HAVE_FABSL
    inline long double
!   abs(long double __x) { return ::fabsl(__x); }
! #else
!   inline long double
!   abs(long double __x) { return ::fabs(static_cast<double>(__x)); }
! #endif

  #if _GLIBCPP_HAVE_ACOSF
    inline float
*************** namespace std
*** 182,196 ****
    ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
  #endif

    inline float
!   cos(float __x)
!   { return __builtin_cosf(__x); }

    using ::cos;

    inline long double
!   cos(long double __x)
!   { return __builtin_cosl(__x); }

  #if _GLIBCPP_HAVE_COSHF
    inline float
--- 200,228 ----
    ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
  #endif

+ #if _GLIBCPP_HAVE___BUILTIN_COSF
    inline float
!   cos(float __x) { return __builtin_cosf(__x); }
! #elif _GLIBCPP_HAVE_COSF
!   inline float
!   cos(float __x) { return ::cosf(__x); }
! #else
!   inline float
!   cos(float __x) { return ::cos(static_cast<double>(__x)); }
! #endif

    using ::cos;

+ #if _GLIBCPP_HAVE___BUILTIN_COSL
+   inline long double
+   cos(long double __x) { return __builtin_cosl(__x); }
+ #elif _GLIBCPP_HAVE_COSL
    inline long double
!   cos(long double __x) { return ::cosl(__x); }
! #else
!   inline long double
!   cos(long double __x) { return ::cos(static_cast<double>(__x)); }
! #endif

  #if _GLIBCPP_HAVE_COSHF
    inline float
*************** namespace std
*** 228,242 ****
    exp(long double __x) { return ::exp(static_cast<double>(__x)); }
  #endif

    inline float
!   fabs(float __x)
!   { return __builtin_fabsf(__x); }

    using ::fabs;

    inline long double
!   fabs(long double __x)
!   { return __builtin_fabsl(__x); }

  #if _GLIBCPP_HAVE_FLOORF
    inline float
--- 260,288 ----
    exp(long double __x) { return ::exp(static_cast<double>(__x)); }
  #endif

+ #if _GLIBCPP_HAVE___BUILTIN_FABSF
+   inline float
+   fabs(float __x) { return __builtin_fabsf(__x); }
+ #elif _GLIBCPP_HAVE_FABSF
+   inline float
+   fabs(float __x) { return ::fabsf(__x); }
+ #else
    inline float
!   fabs(float __x) { return ::fabs(static_cast<double>(__x)); }
! #endif

    using ::fabs;

+ #if _GLIBCPP_HAVE___BUILTIN_FABSL
+   inline long double
+   fabs(long double __x) { return __builtin_fabsl(__x); }
+ #elif _GLIBCPP_HAVE_FABSL
+   inline long double
+   fabs(long double __x) { return ::fabsl(__x); }
+ #else
    inline long double
!   fabs(long double __x) { return ::fabs(static_cast<double>(__x)); }
! #endif

  #if _GLIBCPP_HAVE_FLOORF
    inline float
*************** namespace std
*** 422,436 ****
    pow(long double __x, int __n)
    { return __pow_helper(__x, __n); }

    inline float
!   sin(float __x)
!   { return __builtin_sinf(__x); }

    using ::sin;

    inline long double
!   sin(long double __x)
!   { return __builtin_sinl(__x); }

  #if _GLIBCPP_HAVE_SINHF
    inline float
--- 468,496 ----
    pow(long double __x, int __n)
    { return __pow_helper(__x, __n); }

+ #if _GLIBCPP_HAVE___BUILTIN_SINF
+   inline float
+   sin(float __x) { return __builtin_sinf(__x); }
+ #elif _GLIBCPP_HAVE_SINF
    inline float
!   sin(float __x) { return ::sinf(__x); }
! #else
!   inline float
!   sin(float __x) { return ::sin(static_cast<double>(__x)); }
! #endif

    using ::sin;

+ #if _GLIBCPP_HAVE___BUILTIN_SINL
    inline long double
!   sin(long double __x) { return __builtin_sinl(__x); }
! #elif _GLIBCPP_HAVE_SINL
!   inline long double
!   sin(long double __x) { return ::sinl(__x); }
! #else
!   inline long double
!   sin(long double __x) { return ::sin(static_cast<double>(__x)); }
! #endif

  #if _GLIBCPP_HAVE_SINHF
    inline float
*************** namespace std
*** 450,464 ****
    sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
  #endif

    inline float
!   sqrt(float __x)
!   { return __builtin_sqrtf(__x); }

    using ::sqrt;

    inline long double
!   sqrt(long double __x)
!   { return __builtin_sqrtl(__x); }

  #if _GLIBCPP_HAVE_TANF
    inline float
--- 510,538 ----
    sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
  #endif

+ #if _GLIBCPP_HAVE___BUILTIN_SQRTF
+   inline float
+   sqrt(float __x) { return __builtin_sqrtf(__x); }
+ #elif _GLIBCPP_HAVE_SQRTF
+   inline float
+   sqrt(float __x) { return ::sqrtf(__x); }
+ #else
    inline float
!   sqrt(float __x) { return ::sqrt(static_cast<double>(__x)); }
! #endif

    using ::sqrt;

+ #if _GLIBCPP_HAVE___BUILTIN_SQRTL
+   inline long double
+   sqrt(long double __x) { return __builtin_sqrtl(__x); }
+ #elif _GLIBCPP_HAVE_SQRTL
    inline long double
!   sqrt(long double __x) { return ::sqrtl(__x); }
! #else
!   inline long double
!   sqrt(long double __x) { return ::sqrt(static_cast<double>(__x)); }
! #endif

  #if _GLIBCPP_HAVE_TANF
    inline float

--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-438-3470


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]