There are several compiler options that affect floating-point computations. In general, the options discussed here let you decide between performance and accuracy. To achieve greater performance, it may be necessary to sacrifice some degree of floating-point accuracy.
See also Floating-point Arithmetic Options for Itanum(R)-based Systems.
The -mp option restricts some optimizations to maintain declared precision and to ensure that floating-point arithmetic conforms more closely to the ANSI and IEEE standards. Floating point intermediate results are kept in full 10-byte internal precision. All spills and reloads of the X87 floating-point registers utilize this internal format to prevent accidental loss of precision.
For most programs, specifying this option adversely affects performance. If you are not sure whether your application needs this option, try compiling and running your program both with and without it to evaluate the effects on performance versus precision. Alternatives to -mp include -xN (for the Intel® Pentium 4 processor or newer) and -mp1.
Use the -mp1 option to improve floating-point precision. -mp1 disables fewer optimizations and has less impact on performance than -mp. -mp1 prevents the compiler from performing optimizations which change NAN comparison semantics. It also causes all values used in comparisons to be truncated to declared precision prior to use in the comparison. It also makes sure to use library routines which give better precision results compared to the X87 transcendental instructions.
This option enables the use of the basic algebraic expansions of some complex arithmetic operations. At the loss of some exponent range, the -complex_limited_range option can allow for some performance improvement in programs which utilize complex arithmetic. By default, the compiler disables this option by using -complex_limited_range-.
A change of the default precision control or rounding mode (for example, by using the -pc32 flag or by user intervention) may affect the results returned by some of the mathematical functions.
With some optimizations, the Intel® C++ Compiler changes floating-point division computations into multiplication by the reciprocal of the denominator. For example, A/B is computed as A x (1/B) to improve the speed of the computation. However, for values of B greater than 2126, the value of 1/B is "flushed" (changed) to 0. When it is important to maintain the value of 1/B, use -prec_div to disable the floating-point division-to-multiplication optimization. The result of -prec_div is greater accuracy with some loss of performance.
Use the -pcn option to enable floating-point significand precision control. Some floating-point algorithms are sensitive to the accuracy of the significand or fractional part of the floating-point value. For example, iterative operations like division and finding the square root can run faster if you lower the precision with the -pcn option. Set n to one of the following values to round the significand to the indicated number of bits:
The default value for n is 80, indicating long double precision. This option allows full optimization. Using this option does not have the negative performance impact of using the -Op option because only the fractional part of the floating-point value is affected. The range of the exponent is not affected. The -pcn option causes the compiler to change the floating-point precision control when the main() function is compiled. The program that uses -pcn must use main() as its entry point, and the file containing main() must be compiled with -pcn.
The Intel compiler uses the -rcd option to improve the performance of code that requires floating-point-to-integer conversions. The optimization is obtained by controlling the change of the rounding mode. The system default floating point rounding mode is round-to-nearest. This means that values are rounded during floating point calculations. However, the C language requires floating point values to be truncated when a conversion to an integer is involved. To do this, the compiler must change the rounding mode to truncation before each floating-point-to-integer conversion and change it back afterwards. The -rcd option disables the change to truncation of the rounding mode for all floating point calculations, including floating point-to-integer conversions. Turning on this option can improve performance, but floating point conversions to integer will not conform to C semantics.
The -fp_port option rounds floating-point results at assignments and casts. An impact on speed may result.
When a function call returns a floating-point value, the return value should be placed at the top of the FP stack. If the return value is unused, the compiler pops the value off the stack to keep the FP stack in the correct state. However, if the application leaves out the function's prototype or incorrectly prototypes the function, then the return value may remain on the stack. This may result in the FP stack filling up and eventually overflowing.
Generally, when the FP stack overflows, a NaN value is put into FP calculations, and the program's results differ. Unfortunately, the overflow point can be far away from the point of the actual bug. The -fpchkstk option places code that would access violate immediately after an incorrect call occurred, thus making it easier to locate these issues.