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

Re: [Patch/RFC] libstdc++/20610


Paolo Carlini <pcarlini@suse.de> writes:

| Hi,
| 
| Fredrik noticed that the code we produce for complex * real is
| suboptimal. The primary template for operator*= is:
| 
|   template<typename _Tp>
|     complex<_Tp>&
|     complex<_Tp>::operator*=(const _Tp& __t)
|     {
|       _M_real *= __t;
|       _M_imag *= __t;
|       return *this;
|     }
| 
| whereas the specializations read (f.i., for double):
| 
|   inline complex<double>&
|   complex<double>::operator*=(double __d)
|   {
|     _M_value *= __d;
|     return *this;
|   }
| 
| A simple fix for this issue is expanding the latter to:
| 
|   inline complex<double>&
|   complex<double>::operator*=(double __d)
|   {
|     __real__ _M_value *= __d;
|     __imag__ _M_value *= __d;
|     return *this;
|   }


This really is again a compiler issue.  _M_value, in the specialization, is
of type "double _Complex", which means that it is also a problem in
C-land.  Have the compiler do the obvious thing, namely tranform

    _M_value *= d

into

    __real__ _M_value *= d
    __imag__ _M_value *= d

if it is known, as you report, that is what gives better code.
This looks to me to be a simple vectorization issue.

Let's fix the problem, not its symptoms.

-- Gaby


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