Intel® C++ Compiler 16.0 User and Reference Guide

Floating-point Optimizations

Application performance is an important goal of the Intel® C++ Compiler, even at default optimization levels. A number of optimizations involve transformations that might affect the floating-point behavior of the application, such as evaluation of constant expressions at compile time, hoisting invariant expressions out of loops, or changes in the order of evaluation of expressions. These optimizations usually help the compiler to produce the most efficient code possible. However, the optimizations might be contrary to the floating-point requirements of the application.

Some optimizations are not consistent with strict interpretation of the ANSI or ISO standards for C and C++. Such optimizations can cause differences in rounding and small variations in floating-point results that may be more or less accurate than the ANSI-conformant result.

The Intel® C++ Compiler provides the -fp-model (Linux* and OS X*) or /fp (Windows*) option, which allows you to control the optimizations performed when you build an application. The option allows you to specify the compiler rules for:

double a=1.5; int x=0; ... 
  __try {
    int t0=a; //raises inexact
    x=1;
    a*=2; 
  } __except(1) {
  printf("SEH Exception: x=%d\n", x); 
}

Without precise floating-point exceptions, the result is SEH Exception: x=1; with precision floating-point exceptions, the result is SEH Exception: x=0.

The following table describes the impact of different keywords of the option on compiler rules and optimizations:

Keyword

Value Safety

Floating-Point
Expression Evaluation

Floating-Point
Contractions

Floating-Point
Environment Access

Precise Floating-Point
Exceptions

precise
source
double
extended

Safe

Varies
Source
Double
Extended

Yes

No

No

strict

Safe

Varies

No

Yes

Yes

fast=1 (default)

Unsafe

Unknown

Yes

No

No

fast=2

Very unsafe

Unknown

Yes

No

No

except
except-

Unaffected
Unaffected

Unaffected
Unaffected

Unaffected
Unaffected

Unaffected
Unaffected

Yes
No

Note

It is illegal to specify the except keyword in an unsafe safety mode.

Based on the objectives of an application, you can choose to use different sets of compiler options and keywords to enable or disable certain optimizations, so that you can get the desired result.

See Also