This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::pow implementation


On 29 Jul 2003, Gabriel Dos Reis wrote:

> Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:
>
> | On 29 Jul 2003, Gabriel Dos Reis wrote:
> |
> | > Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:
> | >
> | > | Can such be done for 3.4 and possibly 3.3, too?
> | >
> | > This is mainly an inlining problem with the compiler.  Please fix the
> | > compiler, don't obfuscate the library.
> |
> | cmath.tcc:std::__cmath_power is not even declared inline.
>
> That can be fixed if I'm given enough data ways to reproduce them.
> (The body of that function is already available in any translation
> unit that use it)

Testcase would be:

double foo(double x, int n)
{
   switch (n) {
   case 0:
      return std::pow(x, 0);
   case 1:
      return std::pow(x, 1);
   case 2:
      return std::pow(x, 2);
   default:
      return 0.0;
   }
}

And scan for the call to std::__cmath_power. It should be absent for
-O2.

> | to something avoiding the call to std::__cmath_power. And I dont
> | expect inlining heuristics to consider constant arguments even for
> | tree-ssa in 3.5 timeframe.
>
> Assume __cmath_power is defined inline, then if GCC refuses to
> inline it is because it is broken: it thinks it knows better than the
> programmer whereas it does not.

I know. But its easy to fix the common case with existing gcc
infrastructure and it gets me away from

Flat profile:
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
  9.50      1.67     1.67 105523470     0.00     0.00  double std::__cmath_power<double>(double, unsigned)

for my scientific app. If this ends up the same way as the
__attribute__((leafify)) discussion, I'll stop complaining now and instead
just file a PR for the record.

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]