[cfe-dev] [llvm-dev] Should rint and nearbyint be always constrained?
Stephen Canon via cfe-dev
cfe-dev at lists.llvm.org
Thu Mar 5 09:56:56 PST 2020
> On Mar 5, 2020, at 12:48 PM, Serge Pavlov <sepavloff at gmail.com> wrote:
>
> +cfe-dev as the discussion is now biased toward C standard.
>
> I'm not sure what problem you see here. In default mode, i.e.
> when there is no "#pragma STDC FENV_ACCESS on" in effect,
> then the compiler can always assume that the default rounding
> mode is in effect.
>
> Well, if #pragma STDC FENV_ACCESS on is not in effect, that means
> that the user has promised that at this point during execution,
> we will *always* have the default FP environment.
>
> This is a strong statement (no pragma == default mode), we need to confirm it with proper references to the standard. If it is true and the code:
>
> float qqq(float x) {
> return nearbyint(x);
> }
>
> is really equivalent to:
>
> float qqq(float x) {
> return roundeven(x);
> }
>
> (in absence of 'pragma STD FENV_ACCESS), it is a fact that would be surprise for many user.
>
> Thanks,
> —Serge
C standard: _The FENV_ACCESS pragma_
> The FENV_ACCESS pragma provides a means to inform the implementation when a program might access the floating-point environment to test floating-point status flags or run under non-default floating-point control modes.
"When set appropriately, the implementation may assume the default rounding mode is in effect."
> … The default state ("on" or "off") for the pragma is implementation-defined.
“`Off` is allowed to be the default mode.”
In the presence of the default rounding mode, if you cannot access flags, nearbyint and roundeven have identical observable behavior.
– Steve
More information about the cfe-dev
mailing list