[PATCH]: PR29335 use MPFR for builtins fma, fmin and fmax

Richard Guenther richard.guenther@gmail.com
Fri Nov 10 10:42:00 GMT 2006

On 11/10/06, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> On Thu, 9 Nov 2006, Andrew Pinski wrote:
> > > This is OK for mainline.  Thanks.
> > >
> > > I'm not exactly sure what the official middle-end position on
> > > min(0.0,-0.0) and max(0.0,-0.0) is.  I know that Java requires
> > > the sign to be taken into consideration, but I'm unsure whether
> > > we require this of the backend-provided min?f3/max?f3 optabs or
> > > of the RTL we expand if a min/max optab isn't available.  I've
> > > not checked but I've a suspicion that we generate a<b?a:b, and
> > > therefore obtain an arbitrary sign.
> >
> > Java has already been moved away from using MIN/MAX_EXPR. See PR
> > 25676.
> >
> > tree.def says:
> > /* Minimum and maximum values.  When used with floating point, if both
> >    operands are zeros, or if either operand is NaN, then it is unspecified
> >    which of the two operands is returned as the result.  */
> >
> > Which means to me zero and negative zero are handled as zero which is why Java
> > moved away from using MIN/MAX_EXPR.
> > Andrew Pinski
> Right.  I wish MIN/MAX_EXPR were suitable for fmin/fmax replacements.
> There are a lot of optimizations in the middle-end for these EXPRs that
> I'd rather not duplicate in the builtins.  Instead I'd like to be able to
> lower the builtins into these codes like we do for fabs->ABS_EXPR.  But
> that would require work to change all the backends to honor the new
> behaviors for -0.0 and/or NaN.
> Actually, I'm not sure if fmin/fmax care about -0.0, but I think they do
> care about NaN vs a normal number.  Anyone got the standard handy?

In the ISO/IEC 9899 appendix of the C99 standard it says

'If just one argument is NaN, the fmax functions return the other
argument (if both
arguments are NaNs, the functions return NaN).

The body of the fmax function might be
   { return (isgreater (x, y) || isnan(y)) ? x : y; }

but I agree that the one-argument NaN thing is stupid and not what would be
usually expected.  In a footnote it says

"Ideally, fmax would be sensitive to the sign of zero, for example
fmax (-0.0, 0.0)
would return 0; however, implementation in software might be impractical."

The Library math.h part of C99 doesn't say anything about signed zeros, but also
has the not useful behavior with NaNs.


More information about the Gcc-patches mailing list