[PATCH] D155546: [clang][Interp] Implement __builtin_fmin
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 25 08:15:22 PDT 2023
aaron.ballman added a comment.
In D155546#4521383 <https://reviews.llvm.org/D155546#4521383>, @tbaeder wrote:
> In D155546#4510691 <https://reviews.llvm.org/D155546#4510691>, @aaron.ballman wrote:
>
>> I'd like to see test coverage for treatment of NaNs. According to the C23 standard, a quiet NaN is treated as missing data for fmax and fmin; so if there's a quiet NaN and a numeric value, the numeric value it's what's returned.
>
> Isn't this always the case?
>
> constexpr float qNan = __builtin_nan("");
>
> constexpr float min = __builtin_fmin(qNan, 1);
> static_assert(min == 1);
> constexpr float min2 = __builtin_fmin(1, qNan);
> static_assert(min2 == 1);
>
> works already.
I believe it generally is always true, but it's good to have the test coverage.
> It's not yet clear to me what happens when any of these functions encounter a signaling NaN at compile time. CC @hubert.reinterpretcast @jcranmer-intel @rsmith
I asked some members of the C floating point study group and it turns out signaling NaN is a bit weirder than I had realized. Basically, a signal should be raised during any "mathematical operation" unless the operation is explicitly defined to *not* raise the signal or the implementation defines that it doesn't signal under those circumstances. e.g.,
float some_float_nan(); // Produces a signaling NaN of float type
double d = some_float_nan(); // Subject to F.3p4, might signal, might not
float f = some_float_nan(); // Also subject to F.3p4
sizeof(some_float_nan()); // No signal, unevaluated operand
isnan(some_float_nan()); // No signal, allowed explicitly by standard
some_float_nan() + 12; // Signals
(void)some_float_nan(); // No signal, no mathematical operation
(int)some_float_nan(); // Subject to Annex F, might or might not signal
Also, translation-time initialization with SNAN macros don’t convert to a quiet NaN (which is the return value for the default handling of the signal due to a signaling NaN operand of a runtime conversion).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155546/new/
https://reviews.llvm.org/D155546
More information about the cfe-commits
mailing list