[cfe-dev] C2x FP_ROUND pragma meaning ambiguous?

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


Note that it can be implemented by multiple calls to fegetround and fesetround, but it need not be. For example, on machines with AVX-512 support, a compiler might use the static rounding modes on individual floating-point instructions to implement the desired semantics.

> On Mar 5, 2021, at 4:47 PM, Steve (Numerics) Canon via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> 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 <mailto: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?
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

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


More information about the cfe-dev mailing list