[PATCH] PR11706, optimize std::pow(T, int)
Richard Guenther
rguenth@tat.physik.uni-tuebingen.de
Wed Jan 12 15:48:00 GMT 2005
On Wed, 12 Jan 2005, Richard Guenther wrote:
> 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))
> #else
> if (__builtin_constant_p(__n) && __n >= -2 && __n <= -2)
> #endif
> {
> 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);
> }
Doesn't work - __builtin_types_compatible_p seems to be available
in C only. Then of course changing the three pow overloads with
integer exponent works - anyway, the first patch was just the
shortest one.
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
More information about the Libstdc++
mailing list