我要评分
获取效率
正确性
完整性
易理解

Using Precision-Friendly Compilation Options

The -fp-model compilation option of ICC is used to control floating-point operation optimization, which affects program running performance and accuracy. An optimization option for better performance inevitably causes precision loss.

When the optimization level is -O2 or higher, the default value of -fp-model is fast=1. When the optimization level is -Ofast, the default value of -fp-model is fast=2, indicating that the compiler optimizes floating-point operations more deeply. To obtain higher floating-point calculation precision, set -fp-model=precise to ensure that floating-point numbers are value-safe during calculation. That is, the compiler does not perform conversions that are equal in mathematical logic, for example, converting A + B + C to A + (B + C). Of course, changes may affect program performance. Exercise caution when performing this operation.

The BiSheng Compiler has the compilation option -ffp-contract= off/on/fast to control floating-point operation optimization. The default value of -ffp-contract is fast, which enables multiply-add operations on floating-point numbers. One multiplication operation and one addition operation are combined into one multiply-add operation to improve performance. To obtain higher floating-point calculation precision, you can set -ffp-contract to off.

The BiSheng Compiler also provides compilation options to control floating-point operation optimization. For details, see Floating-Point Operation Control Options in the Kunpeng Compiler User Guide (BiSheng Compiler).

Suggestions

  • Add the compilation option -ffp-contract=off to the BiSheng Compiler.
  • Add the compilation option -fp-model=precise to ICC.