简体   繁体   English

是否有可能通过gcc提高浮点算法的准确性?

[英]Is it possible to increase accuracy of floating point arithemtic with gcc?

some program in C which does extensive floating point calculations get right results on a pc linux box, but wrong results on the SPE of the cell processor, but not on the PPU of the cell. C中的一些程序进行广泛的浮点计算,在pc linux盒子上获得了正确的结果,但是在单元处理器的SPE上得到了错误的结果,但在单元的PPU上却没有。 I am using gcc compilers. 我正在使用gcc编译器。 I wonder if there is some gcc compilation option to increase rounding method or similar so I get single float precision calculations with more precision. 我想知道是否有一些gcc编译选项来增加舍入方法或类似方法,所以我得到更精确的单浮点精度计算。 I can not change to double, as on the SPE performance would drastic reduce 我不能改为双倍,因为在SPE性能上会急剧减少

Thanks 谢谢

Based on the IBM documentation for the differences from IEEE 754 on the SPU , it could be any number of things: 根据IBM 文档中有关SPU上IEEE 754的差异 ,它可以是任意数量的东西:

  • Zero results from arithmetic operations are always +0, never -0. 算术运算的零结果总是+0,从不-0。
  • Denormal inputs from 2-149 to 2-126 to arithmetic operations are treated as zero with the same sign. 从2-149到2-126到算术运算的非正常输入被视为零,具有相同的符号。 Arithmetic operations never produce denormal results, but produce +0 instead. 算术运算永远不会产生非正规结果,而是产生+0。
  • Arithmetic operations do not support IEEE Inf or NaN. 算术运算不支持IEEE Inf或NaN。 These bit patterns represent valid numbers. 这些位模式表示有效数字。 Overflow results produce the maximum magnitude value of appropriate sign. 溢出结果产生适当符号的最大幅度值。
  • Arithmetic operations use only the round-to-zero (chop, truncate) rounding mode, regardless of the setting of the rounding mode in the Floating-Point Status and Control Register (FPSCR), which affects only double-precision arithmetic operations. 无论浮点状态和控制寄存器(FPSCR)中的舍入模式的设置如何,算术运算仅使用舍入到零(斩波,截断)舍入模式,这仅影响双精度算术运算。

Of course, on a related page, you can also compile SPU code for strict IEEE conformance : 当然,在相关页面上, 您还可以编译SPU代码以实现严格的IEEE一致性

By default, XL C/C++ follows most, but not all of the rules in the IEEE standard. 默认情况下,XL C / C ++遵循IEEE标准中的大多数规则,但不是所有规则。 If you compile with the -qnostrict option, which is enabled by default at optimization level -O3 or higher, some IEEE floating-point rules are violated in ways that can improve performance but might affect program correctness. 如果使用-qnostrict选项进行编译(默认情况下在优化级别-O3或更高级别启用),则会以可提高性能但可能影响程序正确性的方式违反某些IEEE浮点规则。 To avoid this issue, and to compile for strict compliance with the IEEE standard, do the following: 要避免此问题,并编译以严格遵守IEEE标准,请执行以下操作:

  • Use the -qfloat=nomaf compiler option. 使用-qfloat = nomaf编译器选项。
  • If the program changes the rounding mode at runtime, use the -qfloat=rrm option. 如果程序在运行时更改舍入模式,请使用-qfloat = rrm选项。
  • If the data or program code contains signaling NaN values (NaNS), use the -qfloat=nans option. 如果数据或程序代码包含信令NaN值(NaNS),请使用-qfloat = nans选项。 (A signaling NaN is different from a quiet NaN; you must explicitly code it into the program or data or create it by using the -qinitauto compiler option.) (信令NaN与安静的NaN不同;您必须将其显式编码到程序或数据中,或使用-qinitauto编译器选项创建它。)
  • If you compile with -O3, -O4, or -O5, include the option -qstrict after it. 如果使用-O3,-O4或-O5进行编译,请在其后包含选项-qstrict。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM