This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug middle-end/20610] Real by complex multiplications perform unnecessary operations


------- 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


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