Next | Prev | Up | Top | Contents | Index

Floating Point Optimizations

Floating point numbers (Fortran's REAL*n, DOUBLE PRECISION, and COMPLEX*n, and C's float, double, and long double) are inexact representations of ideal real numbers. The operations performed on them are also necessarily inexact. However, the MIPS processors conform to the IEEE 754 floating point standard, producing results as precise as possible given the constraints of the IEEE 754 representations. The MIPSpro 64-bit compilers generally preserve this conformance. (Note, however, that 128-bit floating point, such as Fortran's REAL*16 and C's long double, is not precisely IEEE-compliant.)

In addition, the source language standards imply rules about how expressions are to be evaluated. However, most code that has not been written with careful attention to floating point behavior does not require precise conformance to either the source language expression evaluation standards or to IEEE 754 arithmetic standards. Therefore, the MIPSpro 64-bit compilers provide a number of options which trade off source language expression evaluation rules and IEEE 754 conformance against better performance of generated code. These options allow transformations of calculations specified by the source code that may not produce precisely the same floating point result, although they involve a mathematically equivalent calculation.

Two of these options are the preferred controls. -OPT:roundoff deals with the extent to which language expression evaluation rules are observed, generally affecting the transformation of expressions involving multiple operations. -OPT:IEEE_arithmetic deals with the extent to which the generated code conforms to IEEE 754 standards for discrete IEEE-specified operations (for example, a divide or a square root). The remaining options in this class may be used to obtain finer control, but they may disappear or change in future compiler releases.

The first general option provides control over floating point accuracy and overflow/underflow exception behavior relative to the source language rules:


-OPT:roundoff=n

The roundoff option specifies the extent to which optimizations are allowed to affect floating point results, in terms of both accuracy and overflow/underflow behavior. The roundoff value, n, has a value in the range 0..3 with the following meaning:

The second general option controls conformance to IEEE 754 arithmetic standards for discrete operators:


-OPT:IEEE_arithmetic=n

The roundoff option specifies the extent to which optimizations must preserve IEEE floating point arithmetic. The value n must be in the range 1..3, with the following meaning:

There are several other options which allow finer control of floating point behavior than is provided by -OPT:roundoff.


-OPT:div_split[=(ON|OFF)]

Enable/disable the calculation of x/y as x*(1.0/y), normally enabled by IEEE_arithmetic=2. See -OPT:recip.


-OPT:fast_complex[=(ON|OFF)]

Enable/disable the fast algorithms for complex absolute value and division, normally enabled by roundoff=3.


-OPT:fast_exp[=(ON|OFF)]

Enable/disable the translation of exponentiation by integers or halves to sequences of multiplies and square roots. This can change roundoff and can make these functions produce minor discontinuities at the exponents where it applies. Normally enabled by roundoff>0 for Fortran, or for C if the function exp() is labelled intrinsic in <math.h> (the default in -xansi and -cckr modes).


-OPT:fast_sqrt[=(ON|OFF)]

Enable/disable the calculation of square root as x*rsqrt(x) for MIPS4 and above. Note that this optimization produces a NaN instead of 0.0 for a 0 operand.


-OPT:fold_reassociate[=(ON|OFF)]

Enable/disable transformations which reassociate or distribute floating point expressions, normally enabled by roundoff>1.


-OPT:IEEE_comparisons[=ON]

Force comparisons to yield results conforming to the IEEE 754 standard for NaN and Inf operands, normally disabled. Setting this option disables certain optimizations like assuming that a comparison x==x is always TRUE (since it is FALSE if x is a NaN).

It also disables optimizations which reverse the sense of a comparison, for example, turning x < y into ! (x >= y), since both x<y and x>=y may be FALSE if one of the operands is a NaN.


-OPT:recip[=(ON|OFF)]

Allow use of the MIPS4 reciprocal instruction for 1.0/y, normally enabled by IEEE_arithmetic>/=1. See -OPT:div_split.


-OPT:rsqrt[=(ON|OFF)]

Allow use of the MIPS4 reciprocal square root instruction for 1.0/sqrt(y), normally enabled by IEEE_arithmetic>/=1.


-TARG:madd[=(ON|OFF)]

The MIPS 4 architecture supports fused multiply-add instructions, which add the product of two operands to a third, with a single roundoff step at the end. Because the product is not rounded separately, this can produce slightly different (but more accurate) results than a separate multiply and add pair of instructions. This is normally enabled for -mips4.


Next | Prev | Up | Top | Contents | Index