Accessing the environment

The environment model presented in this chapter treats each operation as subject to the prevailing rounding mode and able to raise any exception flag. Strict adherence to this model affects some forms of optimization. Consider the following programming idiom:

      double low  = f(x + y);
      double high = g(x + y);
One might expect an optimizing compiler to recognize the common subexpression x + y appearing as the argument to f and g, and to evaluate it just once, before the call to f. However, the sum x + y could cause side effects. The possibility that g could depend on the flags raised by the sum and the possibility that f could clear those flags combine to make such optimizations incompatible with the environment model. However, it will rarely be the case in such code sequences that the dependencies mentioned will actually exist, so it is usually desirable to permit the compiler this form of optimization.

Performance is also an issue for some platforms, on which strict adherence to the rounding modes or raising of flags may be more costly than running with rounding to nearest without flags.

To accommodate such optimization and performance needs, CommonPoint follows the proposed Floating-point C Extensions by supporting the pragma fenv_access. This pragma, when set to on, indicates to the compiler that the following code might run with rounding other than the default or might access the floating-point environment. The pragma forces careful attention to the environment model. When set to off, the default for most platforms, fenv_access permits more liberal reordering of code by the compiler and possibly the use of faster floating-point operations not guaranteed to set exception flags or to round other than to nearest.

NOTE Assume that fenv_access will be off until you explicitly set it to on. Check your compiler documentation for the default.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker