Re: dot product optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Henning wrote:
> is there a way to optimize the following c++ method?
> 
> // dot product
> template <class T>
> T Vector<T>::operator*(const Vector& v) const
> {
> T ret_val=0;
> for(std::size_t i=0; i < m_Dim; i++) ret_val += m_data[i] * v.m_data[i];
> return ret_val;
> }
> 
> (m_Dim is around 500-1000)
> 
> especially for 32-float, i.e. using sse?
> or do you think g++ will make the best out of it?
> 
For suitable data types (all float or double), with -fassociative-math (or
-ffast-math) it should be optimized by g++ 4.3.  I'm assuming that size_t
is a normal 32- or 64-bit int, according to which mode you compile for.
The optimization for 32-bit data types with g++ won't be as good as icpc
can achieve when it is possible to assert #pragma vector aligned.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux