[Cfp-interest] implementing tgmath for constant rounding modes
Fred J. Tydeman
tydeman at tybor.com
Thu Jun 7 12:48:23 PDT 2012
On Sat, 2 Jun 2012 08:22:55 -0700 Jim Thomas wrote:
>
>At our last teleconference, Fred asked about how <tgmath.h> could be written to work correctly
>with the pragma that switch between constant and dynamic rounding modes.
>
><tgmath.h> aside, the math functions that can be affected by constant rounding modes must be
>sensitive to whether a constant rounding mode is in effect.
>Take the example of cbrt. <math.h> could have
>
>#define cbrt(x) __roundwise_cbrt(x)
>
>Then the translator would have to keep track of whether a constant rounding mode is in effect at
>each call site for __roundwise_cbrt and, if so, what the rounding direction is.
>
>Compilers already keep track of the state of other FP pragmas, which have the same sort of
>scoping as the constant rounding mode pragmas.
As far as I recall, neither gcc nor clang keep track of FENV_ACCESS. So, I am not
sure how easy it is to track state of FP pragmas.
So, in effect, __roundwise_cbrt becomes a special keyword/token/symbol to the compiler.
And the same for all the other math functions (that is a lot of names to treat special).
So, if another compiler did it as
#define cbrt(x) __RoundWise_cbrt(x)
it will be hard for 3rd party library/header implementors
(such as P.J.Plauger's Dinkumware) to create a header that
works with all compilers.
Would it be better to add just one new attribute, eg,
#define cbrt(x) [[ROUNDWISE]] cbrt(x)
that would be the same for all compilers?
---
Fred J. Tydeman Tydeman Consulting
tydeman at tybor.com Testing, numerics, programming
+1 (775) 358-9748 Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.
More information about the Cfp-interest
mailing list