This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH][Fortran] Use MIN/MAX_EXPR for intrinsics or __builtin_fmin/max when appropriate
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: Kyrill Tkachov <kyrylo dot tkachov at foss dot arm dot com>, Richard Biener <richard dot guenther at gmail dot com>, "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 17 Jul 2018 23:06:19 +0300
- Subject: Re: [PATCH][Fortran] Use MIN/MAX_EXPR for intrinsics or __builtin_fmin/max when appropriate
- References: <5B4DE283.9060100@foss.arm.com> <CAFiYyc2F_H1bSCQg+caLQr8WnqExtkAVyAhaQMky_HbZCC=5hQ@mail.gmail.com> <5B4DF325.2050609@foss.arm.com> <9d0cf3dc-8c5c-bbb2-960c-386b2c936a50@netcologne.de>
On Tue, Jul 17, 2018 at 6:36 PM, Thomas Koenig <tkoenig@netcologne.de>
wrote:
> Hi Kyrill,
>
> The current implementation expands to:
>> mvar = a1;
>> if (a2 .op. mvar || isnan (mvar))
>> mvar = a2;
>> if (a3 .op. mvar || isnan (mvar))
>> mvar = a3;
>> ...
>> return mvar;
>>
>> That is, if one of the operands is a NaN it will return the other
>> argument.
>> If both (all) are NaNs, it will return NaN. This is the same as the
>> semantics of fmin/max
>> as far as I can tell.
>>
>
> I've looked at the F2008 standard, and, interestingly enough, the
> requirement on MIN and MAX do not mention NaNs at all. 13.7.106
> has, for MAX,
>
> Result Value. The value of the result is that of the largest argument.
>
> plus some stuff about character variables (not relevant here). Similar
> for MIN.
>
FWIW, this has not changed in the latest(?) draft for F2018 (N2146), see
16.9.125.
Also, the section on IEEE_ARITHMETIC (14.9) does not mention
> comparisons; also, "Complete conformance with IEC 60559:1989 is not
> required", what is required is the correct support for +,-, and *,
> plus support for / if IEEE_SUPPORT_DIVIDE is covered.
>
Interestingly, here the F2018 draft has new intrinsics in the
IEEE_ARITHMETIC module, IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM,
IEEE_MIN_NUM_MAG. These correspond to the {max,min}num{,_mag} operations in
IEEE 754-2008, which AFAICT has the same NaN semantics as __builtin_fmax
etc.
> So, the Fortran standard does not impose many requirements.
If so, why don't we just use {MAX,MIN}_EXPR unconditionally? Those who
worry about the behavior wrt. NaNs, infinities etc. can use the intrinsics
from IEEE_ARITHMETIC?
This thread also has some interesting discussion on the topic:
https://github.com/JuliaLang/julia/issues/7866
--
Janne Blomqvist