Floating-Point Optimizations

Application performance is an important goal of the Intel® oneAPI DPC++/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® oneAPI DPC++/C++ Compiler provides the -fp-model (Linux*) 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:

The following table lists possible keyword values for the -fp-model option:

Keyword

Description

precise

Enables value-safe optimizations on floating-point data .

strict

Enables precise, disables contractions, and enables pragma stdc fenv_access.

fast

Enables more aggressive optimizations on floating-point data.

The keyword that is specified for the -fp-model option may influence the choice of math routines that are invoked. Many routines in the libirc, libm, and libsvml libraries are more highly optimized for Intel microprocessors than for non-Intel microprocessors.

The following table describes the impact of different -fp-model keywords on compiler rules and optimizations:

Keyword

Value Safety

Math errno Support

Floating-Point
Contractions

Floating-Point
Environment Access

Precise Floating-Point
Exceptions

precise

Safe

Enabled

Sets fp-contract=on

No

No

strict

Safe

Enabled

No

Yes

Yes

fast=1 (default)

Unsafe

Disabled

Sets fp-contract=fast

No

No

fast=2

Very unsafe

Disabled

Sets fp-contract=fast

No

No

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.

For example, math errno support can be enabled with the -fno-fast-math option or explicitly disabled using the -fno-math-errno option. For improved performance, you should use the -fno-math-errno option if you are not using errno for error handling.