This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

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



This patch cleans up libstdc++-v3/include/c_shadow/bits/std_cmath.h
following my earlier patch to define sinf and cosf in libmath/stubs.c
if needed.  http://gcc.gnu.org/ml/gcc-patches/2001-12/msg02509.html

As explained by Gabriel Dos Reis, libstdc++ provides the necessary
implementations of libm math functions, so that the GCC __builtin
math functions are always available in g++.

This patch avoids unnecessary checks and calls the __builtin versions
even if they weren't available at configure time.  This patch together
with the earlier one, have been tested by rebuilding libstdc++ and
"make -k check" at the top level in i686-pc-linux-gnu with no new
regressions.

David, can you check that PR 3184 is still fixed on powerpc-ibm-aix4.3
with both of these patches applied?  One advantage of this fix to that
problem is that g++ should now generate machine instructions where
available when using c_shadow.  For example, sqrt(float) on solaris 2.7
will generate the fsqrts instruction and only call the libmath stub if
necessary to set errno.

Best Wishes for a Happy New Year,

Roger


2001-12-28  Roger Sayle <roger@eyesopen.com>
	* include/c_shadow/bits/std_cmath.h: All __builtin math functions
	are available in libstdc++ as the necessary stub implementations
	are provided by libmath/stubs.c.


*** gcc/libstdc++-v3/include/c_shadow/bits/std_cmath.h	Fri Dec 14 14:06:35 2001
--- patch6/libstdc++-v3/include/c_shadow/bits/std_cmath.h	Sat Dec 29 09:27:32 2001
*************** namespace _C_legacy {
*** 84,99 ****
    _CPP_ceil_capture(float __x) { return ceil(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_COSHF
    inline float
--- 84,91 ----
*************** namespace _C_legacy {
*** 111,126 ****
    _CPP_exp_capture(float __x) { return exp(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_FLOORF
    inline float
--- 103,110 ----
*************** namespace _C_legacy {
*** 197,212 ****

    float pow(float, int);

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

  #if _GLIBCPP_HAVE_SINHF
    inline float
--- 181,188 ----
*************** namespace _C_legacy {
*** 216,231 ****
    _CPP_sinh_capture(float __x) { return sinh(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_TANF
    inline float
--- 192,199 ----
*************** namespace _C_legacy {
*** 259,271 ****
    inline double
    _CPP_ceil_capture(double __x) { return ceil(__x); }

- #if _GLIBCPP_HAVE___BUILTIN_COS
    inline double
    _CPP_cos_capture(double __x) { return __builtin_cos(__x); }
- #else
-   inline double
-   _CPP_cos_capture(double __x) { return cos(__x); }
- #endif

    inline double
    _CPP_cosh_capture(double __x) { return cosh(__x); }
--- 227,234 ----
*************** namespace _C_legacy {
*** 273,285 ****
    inline double
    _CPP_exp_capture(double __x) { return exp(__x); }

- #if _GLIBCPP_HAVE___BUILTIN_FABS
    inline double
    _CPP_fabs_capture(double __x) { return __builtin_fabs(__x); }
- #else
-   inline double
-   _CPP_fabs_capture(double __x) { return fabs(__x); }
- #endif

    inline double
    _CPP_floor_capture(double __x) { return floor(__x); }
--- 236,243 ----
*************** namespace _C_legacy {
*** 305,328 ****
    inline double
    _CPP_pow_capture(double __x, double __y) { return pow(__x, __y); }

- #if _GLIBCPP_HAVE___BUILTIN_SIN
    inline double
    _CPP_sin_capture(double __x) { return __builtin_sin(__x); }
- #else
-   inline double
-   _CPP_sin_capture(double __x) { return sin(__x); }
- #endif

    inline double
    _CPP_sinh_capture(double __x) { return sinh(__x); }

- #if _GLIBCPP_HAVE___BUILTIN_SQRT
    inline double
    _CPP_sqrt_capture(double __x) { return __builtin_sqrt(__x); }
- #else
-   inline double
-   _CPP_sqrt_capture(double __x) { return sqrt(__x); }
- #endif

    inline double
    _CPP_tan_capture(double __x) { return tan(__x); }
--- 263,276 ----
*************** namespace _C_legacy {
*** 372,387 ****
    _CPP_ceil_capture(long double __x) { return ceil(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_COSHL
    inline long double
--- 320,327 ----
*************** namespace _C_legacy {
*** 399,414 ****
    _CPP_exp_capture(long double __x) { return exp(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_FLOORL
    inline long double
--- 339,346 ----
*************** namespace _C_legacy {
*** 489,504 ****
    { return pow(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

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

  #if _GLIBCPP_HAVE_SINHL
    inline long double
--- 421,428 ----
*************** namespace _C_legacy {
*** 508,523 ****
    _CPP_sinh_capture(long double __x) { return sinh(static_cast<double>(__x)); }
  #endif

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

  #if _GLIBCPP_HAVE_TANL
    inline long double
--- 432,439 ----

--
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]