[Patch/RFC] libstdc++/20610
Gabriel Dos Reis
gdr@integrable-solutions.net
Thu Mar 24 15:44:00 GMT 2005
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
More information about the Libstdc++
mailing list