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

            Bug ID: 85003
           Summary: Inline built-in fdim for -fno-math-errno
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jsm28 at gcc dot gnu.org
  Target Milestone: ---

GCC should support inline code generation for the fdim / fdimf / fdiml
functions, given -fno-math-errno.

glibc's bits/mathinline.h headers for powerpc and sparc (only) have inlines of
the form:

__MATH_INLINE double
__NTH (fdim (double __x, double __y))
{
  return __x <= __y ? 0 : __x - __y;
}

We're moving away from such inlines in glibc, preferring to leave it to the
compiler to inline standard functions under appropriate conditions.  Now, the
above (which lacks a -fno-math-errno conditional) isn't actually correct; you
need to use an unordered comparison, so the appropriate expansion (given
-fno-math-errno) is of the form (considered as an inline not a macro, so
avoiding multiple evaluations of arguments):

__builtin_islessequal (x, y) ? 0 : x - y

Note: as well as -fno-math-errno, for correctness this also requires that, if
standard-conforming excess precision has been requested, the back end does not
add any implicit excess precision for the type in question, as specified by the
targetm.c.excess_precision hook (so it's not correct to do this inline
expansion for 32-bit x86 with x87 floating point for float or double if
-fexcess-precision=standard, in particular).

Reply via email to