[cfe-dev] C2x FP_ROUND pragma meaning ambiguous?

Steve (Numerics) Canon via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 5 13:47:31 PST 2021


FENV_ROUND applies to all floating-point operations in its scope, not the compiler.

It is not equivalent to a call to fesetround(), because it does not propagate into any calls that take control out of the source language scope of the pragma. If the direction is anything other than FE_DYNAMIC, every operation in the block is to be performed in the specified mode, regardless of the dynamic rounding mode set by any calls to fesetround or inherited from the environment. If it is FE_DYNAMIC, every operation in the block is to be performed according to the dynamic rounding mode set by a call to fesetround.

– Steve

> On Mar 5, 2021, at 3:30 PM, Kevin Neal via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> I’m looking at #pragma STDC FP_ROUND in n2596. It isn’t clear to me that the pragma is supposed to only apply to the compiler, or if the compiler is required to change the floating point environment when the compiled code is executed.
>  
> The draft says: “The FENV_ROUND pragma provides a means to specify a constant rounding direction for floating point operations for standard floating types within a translation unit or compound statement.”
>  
> Use of the word “constant” sounds to me like it only applies to constants. Especially since the next paragraph contrasts the “constant rounding mode” with the “dynamic rounding mode”. The “constant rounding mode” does not apply to functions that are called from a place where the #pragma is in effect.
>  
> On the other hand, paragraph 4 starts out with “The FENV_ROUND pragma affects operations for standard floating types. Within the scope of an FENV_ROUND pragma establishing a mode other than FE_DYNAMIC, floating-point operators, implicit conversions...”
>  
> That paragraph doesn’t sound like the #pragma is restricted to operations on constants. Plus, there’s a block of example code showing that the compiler “could” insert calls to fesetround(). 
>  
> So which is it? Is this pragma equivalent to a call to fesetround() or not?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210305/701877a5/attachment.html>


More information about the cfe-dev mailing list