https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70299

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #5)
> Using the __builtin_powi* functions was done for PR11706, I believe because
> they can be a lot more efficient than the general powl(double, double)
> implementations. So it seems that for C++11 and later we provide more
> accuracy, but probably via slower functions than we use for C++03.

It was done because the original implementation did not just call
pow(double, double) but implemented pow (double, int) via an (inline) loop
and multiplications which was very hard for GCC to optimize.  So GCC
now provides that "loop implementation" itself (in libgcc):

TYPE
NAME (TYPE x, int m)
{
  unsigned int n = m < 0 ? -m : m;
  TYPE y = n % 2 ? x : 1;
  while (n >>= 1)
    {
      x = x * x;
      if (n % 2)
        y = y * x;
    }
  return m < 0 ? 1/y : y;
}

but generally knows how to expand it inline as well (for small constant
powers).  Note this is similar to how fortran semantics work IIRC.

Reply via email to