This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[PATCH, RFC] fma vs gcc 4.9


GCC 4.9 optimizes

  double a1 = z + m1;
  double t1 = a1 - z;
  double t2 = a1 - t1;
  t1 = m1 - t1;
  t2 = z - t2;
  double a2 = t1 + t2;
  feclearexcept (FE_INEXACT);

  if (a1 == 0 && m2 == 0)
    ... return ...

into

  double a1 = z + m1;
  feclearexcept (FE_INEXACT);

  if (a1 == 0 && m2 == 0)
    ... return ...

  double t1 = a1 - z;
  double t2 = a1 - t1;
  t1 = m1 - t1;
  t2 = z - t2;
  double a2 = t1 + t2;

because the later computation is partially redundant for the path leading to
the return.  I noticed this because, of course, the moved computation raises
INEXACT, leading to incorrect results.

At first I was simply going to add a math_force_eval to make sure everything is
complete before the feclearexcept, but on further reflection it seemed odd that
most of the computation is in fact redundant.

It seems to me that there's a typo on that exact zero test: a2 should be used,
not m2.  Correct, or have I mis-read the code?


r~

Attachment: z
Description: Text document


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