[Cfp-interest] issues about rounding attributes
Jim Thomas
jwthomas at cup.hp.com
Mon Aug 29 17:50:13 PDT 2011
Here are some thoughts on two issues about rounding attributes that came
up in our Aug meeting.
ISSUE 1: Must FENV_ACCESS ON be in effect where static rounding
attributes appear?
No. The point of FENV_ACCESS ON is to inform the compiler of possible
runtime controls (mode changes) which cannot be known at compile time
but which must be accommodated. The static rounding attributes tell the
compiler precisely what controls are to be used, so they do not require
FENV_ACCESS ON to be in effect.
An implementation that supports static rounding attributes by saving,
setting, and restoring dynamic rounding modes may have a static rounding
attribute effectively imply FENV_ACCESS ON as a means of keeping its
optimizer from undermining the static attribute. But this is not
something the user should need to manage or be aware of.
ISSUE 2: Do static rounding attributes affect function calls within
their scope? If so, which ones?
IEEE 754-2008 requires static attributes to affect the operations for
which it specifies rounding. For C, some of these operations are (and
more will be) implemented by standard library functions, including:
sqrt
fma
scalbn
formatOf operations (add, sub, mul, div, fma, sqrt)
The effect of the dynamic rounding mode on other standard library
functions is not currently specified. Implementations of these standard
library functions might honor directed roundings, guard against them, or
ignore them (getting a haphazard effect). Thus, leaving the effect of
static rounding attributes on these functions unspecified would seem to
be acceptable by current expectations, and would make it easier for
implementations. Greater consistency might be achieved by requiring that
a static attribute either have (1) no effect or (2) the same effect
(whatever it may be) as a dynamic rounding mode.
Having static rounding attributes affect calls to user functions seems
inconsistent with the concept of static rounding attributes, turning
them into syntactic sugar for save, set, and restore the global rounding
mode. This would not free implementations (that might benefit from such
freedom) from having to keep track of the global rounding mode, which
was the purpose of static rounding attributes.
Proposal:
If a static rounding attribute is in effect, calls to functions for
which IEEE 754-2008 specifies rounding shall be correctly rounded
according to the static rounding attribute.
The effect of static rounding attributes on other standard library
functions is unspecified.
Calls to user functions shall not be affected by static rounding attributes.
-Jim T
More information about the Cfp-interest
mailing list