Re: Array optimizing problem in C++?
On Mar 25, 12:20 pm, Lionel B <m...@privacy.net> wrote:
Personally I've never managed to code up a scenario (using GCC with
various optimisations) where __restrict__ appears to have made any
difference whatsoever.
Try the program I gave earlier on this topic.
Compile it with :
g++ -O3
Then uncomment the line :
//#define NO_ALIASING_OPTIMIZATION
and compile it again with g++ -O3.
There should be a difference.
Let me know if you don't find any.
Here is the program :
#include <iostream>
#include <ctime>
//#define NO_ALIASING_OPTIMIZATION
const int len = 50000;
__attribute__((noinline))
#ifndef NO_ALIASING_OPTIMIZATION
void smooth (int* dest, int * src )
#else
void smooth (int* __restrict dest, int * __restrict src )
#endif
{
for ( int i = 0 ; i < 17 ; ++i )
dest[ i ] = src[ i ] + src[ i + 1 ] + src[ i + 2 ];
}
void fill (int* src)
{
for (int i = 0 ; i < len ; ++ i )
src[i] = i;
}
int main()
{
int src_array [len] = {0} ;
int dest_array [len] = {0};
fill(src_array);
smooth (dest_array, dest_array); // dummy call
clock_t start=clock();
for (int i = 0; i < 100000000; i++)
smooth (dest_array, src_array);
clock_t endt=clock();
std::cout <<"Time smooth(): " <<
double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";
// doesn't work without the following cout on vc++
std::cout << dest_array [0] ;
return 0;
}
Alexandre Courpron.