C2x FP_ROUND pragma meaning ambiguous?

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?

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

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.