This is the mail archive of the 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: [PATCH] PR11706, optimize std::pow(T, int)

On Wed, 12 Jan 2005, Richard Guenther wrote:

> On Wed, 12 Jan 2005, Paolo Carlini wrote:
> > Richard Guenther wrote:
> >
> > Maybe Gaby wants to add something here, but I seem to remember that
> > we really dislike this kind of approach, calling back pow from __pow_helper
> > via a cast, thus giving away the info that the exponent is integer.
> We can dispatch directly to __builtin_pow[lf](), too, and the frontends

Like with

      inline _Tp
      __pow_helper(_Tp __x, int __n)
#if __FAST_MATH__
       if (__builtin_constant_p(__n))
       if (__builtin_constant_p(__n) && __n >= -2 && __n <= -2)
           if (__builtin_types_compatible_p(_Tp, float))
             return __builtin_powf(__x, __n);
           else if (__builtin_types_compatible_p(_Tp, double))
             return __builtin_pow(__x, __n);
           else if (__builtin_types_compatible_p(_Tp, long double))
             return __builtin_powl(__x, __n);
       return __n < 0
          ? _Tp(1)/__cmath_power(__x, -__n)
          : __cmath_power(__x, __n);

(untested, maybe only __typeof(__x) works), which would even work if
someone cared to call std::__pow_helper with _Tp other than float, double
or long double.


Richard Guenther <richard dot guenther at uni-tuebingen dot de>

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