gcc-performance::number of local variables

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

 



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?

Another acceleration might be declare the variable s as constant inside the function body:

#Version 3
double vFoo( const double &a, const double &b, double &e )
{
  const double s = a + b;
         e = s - a;
         e =(s-(a-e))+(e-b);
  return s;
}


Best regards

Martin


-- 
Nur bis 31.05.: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und
Telefonanschluss nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

[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