Programming Tradeoffs in Floating-Point Applications
In general, the programming objectives for floating-point applications fall into the following categories:
- Accuracy:The application produces results that are close to the correct result.
- Reproducibility and portability:The application produces consistent results across different runs, different sets of build options, different compilers, different platforms, and different architectures.
- Performance:The application produces fast, efficient code.
Based on the goal of an application, you will need to make tradeoffs among these objectives. For example, if you are developing a 3D graphics engine, performance may be the most important factor to consider, with reproducibility and accuracy as secondary concerns.
C++Compiler provides several compiler options that allow you to tune your applications based on specific objectives. Broadly speaking, there are the floating-point specific options, such as the
/fp(Windows*) option, and the fast-but-low-accuracy options, such as the
[Q]imf-max-erroroption. The compiler optimizes and generates code differently when you specify these different compiler options. Select appropriate compiler options by carefully balancing your programming objectives and making tradeoffs among these objectives. Some of these options may influence the choice of math routines that are invoked.
Many routines in the
svmllibrary are more highly optimized for Intel microprocessors than for non-Intel microprocessors.
Using Floating-Point Options
Take the following code as an example:
If you specify the
/fp:extended(Windows*) option in favor of accuracy, the compiler generates the fo