1 Jun 2009 13:31
gcc-performance::number of local variables
Martin Ettl <ettl.martin <at> gmx.de>
2009-06-01 11:31:56 GMT
2009-06-01 11:31:56 GMT
Hello,
i try to improve the performance of a cpp-program. I am insterested to understand how gcc optimizes the code
(switch on -02 or -O3 flag).
Suppose i have this simple function:
#Version 1
double vFoo( const double &a, const double &b, double &e )
{
double s = a + b;
double h = s - a;
e =(s-(a-h))+(h-b);
return s;
}
This function ca be rewritten to:
#Version 2
double vFoo( const double &a, const double &b, double &e )
{
double s = a + b;
e = s - a;
e =(s-(a-e))+(e-b);
return s;
}
A version 2 there is one local variable allocation less than at version 1.Is this step automatically done by
gcc, or can i improve the performance of code by doing this myself?
(Continue reading)
RSS Feed