Simplify generic fdim implementations.
commit4fea2cda618de1c74959aaec79c020993c34c552
authorJoseph Myers <joseph@codesourcery.com>
Tue, 14 Jun 2016 14:56:42 +0000 (14 14:56 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Tue, 14 Jun 2016 14:56:42 +0000 (14 14:56 +0000)
tree539442064517695eadeeec91c18817045edb781d
parentc8376f3e07602aaef9cb843bb73cb5f2b860634a
Simplify generic fdim implementations.

The generic fdim implementations have unnecessarily complicated code,
using fpclassify to determine whether the arguments are NaNs,
subtracting NaNs if so and otherwise subtracting the non-NaN arguments
if not (x <= y), then using fpclassify on the result to see if it is
infinite.

This patch simplifies the code.  Instead of handling NaNs separately,
it suffices to use an unordered comparison with islessequal (x, y) to
determine whether to return zero, and otherwise NaNs can go through
the same subtraction as non-NaN arguments; no explicit tests for NaN
are needed at all.  Then, isinf instead of fpclassify can be used to
determine whether to set errno (in the normal non-overflow case, only
one classification will need to occur, unlike the three in the
previous code, of which two occurred even if returning zero, because
the result will not be infinite in the normal case).

The resulting logic is essentially the same as that in the powerpc
version, except that the powerpc version is missing errno setting and
uses <= not islessequal, so relying on
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58684>, the GCC bug that
unordered comparison instructions are wrongly used on powerpc for
ordered comparisons.

The compiled code for fdim and fdimf on x86_64 is less than half the
size of the previous code.

Tested for x86_64.

* math/s_fdim.c (__fdim): Use islessequal and isinf instead of
fpclassify.
* math/s_fdimf.c (__fdimf): Likewise.
* math/s_fdiml.c (__fdiml): Likewise.
ChangeLog
math/s_fdim.c
math/s_fdimf.c
math/s_fdiml.c