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

Floating-Point Operation Control Options

After compiler optimizations, the floating-point operation results may be inconsistent. The possible causes are as follows:

  • The floating-point precision is limited.
  • Each compiler has options that affect floating-point operation results.
  • Options vary with compilers and have different default values.
  • Some options can be explicitly enabled or disabled by other seemingly irrelevant options.
  • A compiler can control the results of floating-point operations by enabling or disabling correct options.

Default Options

For details about the floating-point operation control options of BiSheng compiler, see the LLVM official document at https://clang.llvm.org/docs/UsersManual.html#controlling-floating-point-behavior. In addition, BiSheng compiler provides the following compilation options to adjust the floating-point precision to meet users' flexible requirements.

-Mflushz

This option indicates whether to flush denormalized floating-point values to zero and is different from other unsecure floating-point optimizations. The open-source Clang and Flang support this option only in the x86 architecture. BiSheng compiler supports this option in both the x86 and AArch64 architectures. The method of using this option is the same as that in open-source Clang and Flang.

For details, visit https://en.wikipedia.org/wiki/Denormal_number.

-ffp-contract=style

The value of this option can be off, on, or fast. BiSheng compiler sets the value to fast by default to enable floating-point multiply-add operations and combine multiplication and addition into one operation, improving operation performance.

-faarch64-pow-alt-precision=18/21

This Flang option is valid only for Fortran code. It is used to change the optimization policy of the pow function so that the computing result of the pow function is the same as that on the non-Arm platform.

-faarch64-minmax-alt-precision

This Flang option is valid only for Fortran code. It is used to change the optimization policy of the min or max function so that the computing result of the min or max function is the same as that on the non-Arm platform.

-mllvm -disable-sincos-opt

This llvm option is used to change the optimization policies of the sin or cos function so that the computing result of the sin or cos function is the same as that on the non-Arm platform.

-mllvm -aarch64-recip-alt-precision

This llc option uses the soft floating-point compensation to ensure that the computing result of the recip reciprocal instruction is the same as that on the non-Arm platform.

-mllvm -aarch64-rsqrt-alt-precision

This llc option uses the soft floating-point compensation to ensure that the computing result of the rsqrt reciprocal square root extraction instruction is the same as that on the non-Arm platform.

-mllvm -enable-alt-precision-math-functions

This llvm option is used to replace names of the math functions __mth_i_cosd, __mth_i_asind, and __pd_powi_1 with cosdf, asindf, and powr8i4 to control their precision. This option must be used together with the Kunpeng Math Library (KML). This option takes effect only for O1 or higher optimization levels.

-mllvm -enable-18-math-compatibility

This llvm option is used to convert math functions such as tgammaf, cbrt, log, and log10 to functions suffixed with _18 to control their precision. This option must be used together with the KML. This option takes effect only when the optimization level is higher than or equal to O1 and -mllvm -enable-alt-precision-math-functions is enabled.

-mllvm -enable-80-math-compatibility = <true|false>

This llvm option is used to convert 80-bit floating-point math functions such as cosl, sinl, and logl to functions suffixed with _k80 to control their precision. This option must be used together with the KML. This option takes effect only when the optimization level is higher than or equal to O1 and -mllvm -enable-alt-precision-math-functions is enabled. By default, the conversion is enabled. If this option is set to false, the conversion is disabled.

-mllvm -disable-80-math-compatibility = all/func1,func2...

This llvm option is used to disable the conversion from a specified function to a function suffixed with _k80 in the KML after -mllvm -enable-80-math-compatibility is enabled. In this way, the math function precision can be controlled. This option must be used together with the KML. This option takes effect only when the optimization level is higher than or equal to O1 and -mllvm -enable-alt-precision-math-functions is enabled.

-ffp-compatibility=17/18/21/gnu_4.8.4

This general option is used to control all options that need to be enabled to ensure that the calculation result is consistent with that on the non-Arm platform.

-ffma-combine-fdiv

This general option is used to optimize the expression a/b+c to fma(a, 1/b, c), which ensures that the calculation result is consistent with that on the non-Arm platform. This parameter is valid only when -ffp-contract is set to fast.

-ffma-reverse-associative

This general option is used to optimize the expression ab+cd to fma(a, b, c*d), which ensures that the calculation result is consistent with that on the non-Arm platform. This parameter is valid only when -ffp-contract is set to fast.

-fprecision-align-when-round

This Flang option is used to keep the rounding mode of constant initialization consistent with that on the non-Arm computing platform. This option is valid only for Fortran.