This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/20610] Real by complex multiplications perform unnecessary operations
- From: "fredrik dot huss at home dot se" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Mar 2005 09:21:09 -0000
- Subject: [Bug middle-end/20610] Real by complex multiplications perform unnecessary operations
- References: <20050323205957.20610.fredrik.huss@home.se>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From fredrik dot huss at home dot se 2005-03-24 09:21 -------
Thanks for looking into this!
Yes, I was meaning when -ffast-math is NOT used, so maybe this is completely
unrelated. But I was thinking that even without -ffast-math, this should not
require a full complex multiplication.
I looked in the C++ library, and the multiplication is implemented as
template<typename _Tp>
inline complex<_Tp>
operator*(const complex<_Tp>& __x, const _Tp& __y)
{
complex<_Tp> __r = __x;
__r *= __y;
return __r;
}
where operator*=() is implemented as
inline complex<double>&
complex<double>::operator*=(double __d)
{
_M_value *= __d;
return *this;
}
The typedef _M_value is defined as __complex__ double. So it seems that the
multiplication is converted to a full complex multiplication within the
compiler.
For comparison, here is the generic version of operator*()
// 26.2.5/5
template<typename _Tp>
complex<_Tp>&
complex<_Tp>::operator*=(const _Tp& __t)
{
_M_real *= __t;
_M_imag *= __t;
return *this;
}
Here, the multiplication is performed separately for the real and imaginary
parts.
It would be nice if the multiplication worked like this also for
complex<double>, even without -ffast-math. Or, is there something in the
standard which would disallow this?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20610