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

            Bug ID: 66462
           Summary: GCC isinf/isnan/... builtins cause sNaN exceptions
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wdijkstr at arm dot com
  Target Milestone: ---

The isinf, isnan, isnormal, isfinite, fpclassify and signbit builtins use FP
arithmetic to compute their result even with -fsignaling-nans (signbit only
when -ffast-math is also used). This means sNaNs cause invalid operation
exceptions which is incorrect according to the IEEE754-2008 standard.

The reason is the use of FP comparisons. Integer arithmetic avoids this, and is
typically faster, especially when using softfloat.

int snan_fail(double x)
{
  return __builtin_isinf (x);
}

gcc6.0 -O2 -fsignaling-nans generates for AArch64:

snan_fail:
        ldr     d1, .LC7
        fabs    d0, d0
        fcmp    d0, d1  // will signal on sNaN...
        cset    w0, gt
        ret

Reply via email to