[PATCH] PR11706, optimize std::pow(T, int)

Richard Guenther rguenth@tat.physik.uni-tuebingen.de
Wed Jan 12 15:11:00 GMT 2005


Hi!

This is a fix for the ages old PR11706 (or rather a work-around?).
cmath __pow_helper now recognizes constant (or small constant)
integer powers and dispatches to the appropriate gcc builtin in
these cases.  This makes the code for ::pow(x, 2), std::pow(x, 2)
and std::pow(x, 2.0) the same, likewise for exponents > 2 in case
of -ffast-math (even without -funroll-loops).

Ok for mainline?

Thanks,
Richard.


2005-01-12  Richard Guenther <richard.guenther@uni-tuebingen.de>

	PR11706
	* libstdc++-v3/include/c_std/std_cmath.h (__pow_helper):
	Specialize for (small) constant exponents.
-------------- next part --------------
Index: libstdc++-v3/include/c_std/std_cmath.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/std_cmath.h,v
retrieving revision 1.15
diff -u -c -3 -p -r1.15 std_cmath.h
*** libstdc++-v3/include/c_std/std_cmath.h	29 Dec 2003 19:26:11 -0000	1.15
--- libstdc++-v3/include/c_std/std_cmath.h	12 Jan 2005 15:03:19 -0000
*************** namespace std
*** 333,338 ****
--- 333,344 ----
      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
+         return pow(__x, (_Tp)__n);
        return __n < 0
          ? _Tp(1)/__cmath_power(__x, -__n)
          : __cmath_power(__x, __n);


More information about the Libstdc++ mailing list