This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/11706] std::pow(T, int) implementation pessimizes code
- From: "steven at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Jul 2003 12:39:42 -0000
- Subject: [Bug libstdc++/11706] std::pow(T, int) implementation pessimizes code
- References: <20030729120327.11706.rguenth@tat.physik.uni-tuebingen.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11706
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |pessimizes-code
Priority|P2 |P3
Last reconfirmed|0000-00-00 00:00:00 |2003-07-29 12:39:42
date| |
------- Additional Comments From steven at gcc dot gnu dot org 2003-07-29 12:39 -------
__cmath_power() should probably be declared inline, something like this:
---- 8< ---- 8< ---- 8< ---- 8< ----
Index: libstdc++-v3/include/c_std/cmath.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/cmath.tcc,v
retrieving revision 1.3
diff -c -3 -p -r1.3 cmath.tcc
*** libstdc++-v3/include/c_std/cmath.tcc 23 Jul 2003 15:28:44 -0000 1.3
--- libstdc++-v3/include/c_std/cmath.tcc 29 Jul 2003 12:36:26 -0000
***************
*** 35,41 ****
namespace std
{
export template<typename _Tp>
! _Tp
__cmath_power(_Tp __x, unsigned int __n)
{
_Tp __y = __n % 2 ? __x : 1;
--- 35,41 ----
namespace std
{
export template<typename _Tp>
! inline _Tp
__cmath_power(_Tp __x, unsigned int __n)
{
_Tp __y = __n % 2 ? __x : 1;
---- 8< ---- 8< ---- 8< ---- 8< ----
Or are there reasons bigger than us that prevent such an implementation from
being correct?
Richard, can you test this and see if it helps? It's still not as good as
pow(x,2)->x*x but it's darn close and with loop unrolling it might even get to that.