[Cfp-interest] outline of directives pragmas
David Hough CFP
pcfp at oakapple.net
Mon May 12 17:06:18 PDT 2014
I've prepared an outline of directives pragmas content - but not filled
in as much content as I'd hoped.
Tomorrow we can discuss specific issues evident so far.
Much of the text is from the existing standard and reports, to provide
a framework for new material.
Directives Pragmas
754-2008 specifies:
==========
4.1 Attribute specification
An attribute is logically associated with a program block to modify
its numerical and exception semantics. A user can specify a constant
value for an attribute parameter.
Some attributes have the effect of an implicit parameter to most
individual operations of this standard; language standards shall
specify
* rounding-direction attributes
and should specify
* alternate exception handling attributes
Other attributes change the mapping of language expressions into
operations of this standard; language standards that permit more than
one such mapping should provide support for:
* preferredWidth attributes
* value-changing optimization attributes
* reproducibility attributes
For attribute specification, the implementation shall provide
language-defined means, such as compiler directives, to specify a
constant value for the attribute parameter for all standard operations
in a block; the scope of the attribute value is the block with which
it is associated. Language standards shall provide for constant
specification of the default and each specific value of the
attribute.
==========
ANSI-C specifies standard pragmas thus:
==========
6.10.6 Pragma directive
Semantics A preprocessing directive of the form
# pragma pp-tokensopt new-line where the preprocessing token STDC
does not immediately follow pragma in the directive (prior to any
macro replacement)174) causes the implementation to behave in an
implementation-defined manner. The behavior might cause translation to
fail or cause the translator or the resulting program to behave in a
non-conforming manner. Any such pragma that is not recognized by the
implementation is ignored.
If the preprocessing token STDC does immediately follow pragma in the
directive (prior to any macro replacement), then no macro replacement
is performed on the directive, and the directive shall have one of the
following forms175) whose meanings are described elsewhere:
#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV_ACCESS on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch
on-off-switch: one of
ON OFF DEFAULT
==========
Scope (adapted from C 7.12.2 for FP_CONTRACT) :
==========
Each FP_CONTRACT pragma can occur either outside external declarations
or preceding all explicit declarations and statements inside a
compound statement. When outside external declarations, the pragma
takes effect from its occurrence until another FP_CONTRACT pragma is
encountered, or until the end of the translation unit. When inside a
compound statement, the pragma takes effect from its occurrence until
another FP_CONTRACT pragma is encountered (including within a nested
compound statement), or until the end of the compound statement; at
the end of a compound statement the state for the pragma is restored
to its condition just before the compound statement. If this pragma is
used in any other context, the behavior is undefined.
==========
This existing pragma STDC syntax and scope will be extended to
encompass the attributes required by 754-2008.
(existing)
#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV_ACCESS on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch
on-off-switch: one of
ON
OFF
DEFAULT
(part 1)
#pragma STDC FENV_ROUND bdirection
bdirection:
FE_DOWNWARD
FE_TONEAREST
FE_TOWARDZERO
FE_UPWARD
FE_DYNAMIC
(part2 )
#pragma STDC FENV_DEC_ROUND ddirection
ddirection:
FE_DEC_DOWNWARD
FE_DEC_TONEAREST
FE_DEC_TONEARESTFROMZERO
FE_DEC_TOWARDZERO
FE_DEC_UPWARD
FE_DEC_DYNAMIC
#pragma STDC FENV_WIDTH format
for generic floating-point types, format is:
genericnone
float
double
long double
for binary floating-point types, format is:
_Floatnone
_Float32
_Float64
_Float128
_Float32x
_Float64x
_Float128x
for decimal floating-point types, format is:
_Decimalnone
_Decimal64
_Decimal128
_Decimal64x
_Decimal128x
FENV_WIDTH specifies the minimum evaluation width for expressions involving
generic, or binary, or decimal floating-point types. In a particular
implementation, generic types might be the same as binary types
or might be the same as decimal types
#pragma STDC FENV_VALUE_CHANGING_OPTIMIZATIONS switch
switch:
ENABLE
DISABLE
DEFAULT
and specific optimizations under this umbrella...
such as
#pragma STDC FENV_FAST_SUBNORMAL switch
allows abrupt underflow and zero treatment of subnormal operands if faster,
implementation defined
#pragma STDC FENV_REPRODUCIBLE switch
ENABLE
DISABLE
DEFAULT
and specific optimizations under this umbrella...
#pragma STDC FENV_EXCEPT exception-list action
exception list is a list of exceptions and subexceptions
separated by commas
exception:
FE_INEXACT
FE_UNDERFLOW
FE_OVERFLOW
FE_DIVBYZERO
FE_INVALID
FE_ALL shorthand for all
and the following subexceptions of invalid and divbyzero:
subexception:
FE_SNAN 7.2a
FE_INVALID_MUL 7.2b
FE_INVALID_FMA 7.2c
FE_INVALID_ADD 7.2d
FE_INVALID_DIV 7.2e
FE_INVALID_REM 7.2f
FE_INVALID_SQRT 7.2g
FE_INVALID_QUANTIZE 7.2h
FE_INVALID_INT 7.2i
FE_UNORDERED 7.2j
FE_INVALID_LOGB 7.2k
FE_DIV_ZERO 7.3 divisor zero
FE_DIV_LOG 7.3 log(0) or logb(0)
actions that don't change control flow:
DEFAULT 754 default
NOFLAG default result, but no flag raised
OPTFLAG implementation may raise flag or not
ABRUPT underflow only
SUBSTITUTE expression
SUBSTITUTEXOR expression multiplication or division only
RECORD record the exception in a "debugger"
and continue; same as default if
no debugger active
actions that change control flow:
BREAK to just past end of pragma scope
ASAP label goto
DELAYED label goto
ASAP function(...) call, no return
DELAYED function(...) call, no return
ASAP means as soon as possible - implementation defined.
DELAYED means at exit from the pragma scope
labels, functions, and expressions raise scope issues: is the relevant
scope defined at the site of the pragma or at the site of the exception?
Because of scope issues, pragmas specifying
actions that change control flow are only allowed within compound statements,
and not at the beginning of a file.
What about functions invoked within compound statements controlled by
an alternate exception handling pragma? To follow the lead of
FENV_ROUND, a list of functions corresponding to 754 operations
specifies those affected by rounding and alternate exception handling pragmas.
Inlining does not affect whether an operation is affected.
Functions affected by constant rounding modes and alternate exception
handling modes
Within the scope of an FENV directive establishing a constant rounding mode
or an alternate exception handling mode,
all floating-point operators,
implicit conversions (including the conversion of a value represented in a
format wider than its semantic types to its semantic type,
as done by classification macros), and
invocations of functions indicated in the table below,
for which macro replacement has not been
suppressed,
shall be evaluated according to the specified mode.
Invocations of functions for which macro replacement has
been suppressed and invocations of functions other than those indicated in the
table below shall not
be affected by constant rounding modes or alternate exception handling modes.
<Header> Function groups
<math.h> acos, asin, atan, atan2
<math.h> cos, sin, tan
<math.h> acosh, asinh, atanh
<math.h> cosh, sinh, tanh
<math.h> exp, exp2, expm1
<math.h> log, log10, log1p, log2
<math.h> scalbn, scalbln, ldexp
<math.h> cbrt, hypot, pow, sqrt
<math.h> erf, erfc
<math.h> lgamma, tgamma
<math.h> rint, nearbyint, lrint, llrint
<math.h> fdim
<math.h> fma
<math.h> fadd, daddl, fsub, dsubl, fmul, dmull, fdiv, ddivl, ffma, dfmal
<math.h> fsqrt, dsqrtl
<stdlib.h> atof, strfromd, strfromf, strfroml, strtod, strtof, strtold
<wchar.h> wcstod, wcstof, wcstold
<stdio.h> printf and scanf families
<wchar.h> wprintf and wscanf families
Each <math.h> functon listed in the table above indicates the family of functions of all supported types (for example, acosf and acosl as well as acos).
More information about the Cfp-interest
mailing list