是否可以使用 gcc 提高浮点运算的精度?

发布于 2024-09-24 05:50:16 字数 190 浏览 0 评论 0原文

一些用 C 编写的程序进行大量浮点计算,在 PC Linux 机器上得到正确的结果,但在单元处理器的 SPE 上得到错误的结果,但在单元的 PPU 上却得不到错误的结果。我正在使用 gcc 编译器。我想知道是否有一些 gcc 编译选项来增加舍入方法或类似方法,以便我获得更高精度的单浮点精度计算。我无法更改为双倍,因为 SPE 性能会急剧下降,

谢谢

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. I am using gcc compilers. 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. I can not change to double, as on the SPE performance would drastic reduce

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书间行客 2024-10-01 05:50:16

基于 IBM SPU 上与 IEEE 754 的差异的文档,它可以是任意数量的东西:

  • 算术运算的零结果始终是+0,而不是-0。
  • 处理算术运算中从 2-149 到 2-126 的非正规输入
    为零且符号相同。算术
    操作永远不会产生异常
    结果,但产生+0。
  • 算术运算不支持 IEEE Inf 或 NaN。这些位模式
    代表有效数字。溢出
    结果产生最大震级
    适当符号的值。
  • 算术运算仅使用舍入到零(截断、截断)
    舍入模式,无论
    舍入模式的设置
    浮点状态和控制
    寄存器(FPSCR),仅影响
    双精度算术
    运营。

当然,在相关页面上, 您还可以编译 SPU 代码以严格符合 IEEE

默认情况下,XL C/C++ 紧随其后,但是
并非 IEEE 中的所有规则
标准。如果您使用以下命令进行编译
-qnostrict 选项,默认情况下在优化级别 -O3 或
更高一些 IEEE 浮点规则
以可以改进的方式受到侵犯
性能但可能会影响程序
正确性。为了避免这个问题,并且
严格遵守编译
IEEE 标准,执行以下操作:

  • 使用 -qfloat=nomaf 编译器选项。
  • 如果程序在运行时更改舍入模式,请使用 -qfloat=rrm
    选项。
  • 如果数据或程序代码包含信号 NaN 值 (NaNS),请使用
    -qfloat=nans 选项。 (信号 NaN 与安静 NaN 不同;您
    必须显式地将其编码到
    程序或数据或通过使用创建它
    -qinitauto 编译器选项。)
  • 如果使用 -O3、-O4 或 -O5 进行编译,请在其后包含选项 -qstrict。

Based on the IBM documentation for the differences from IEEE 754 on the SPU, it could be any number of things:

  • Zero results from arithmetic operations are always +0, never -0.
  • Denormal inputs from 2-149 to 2-126 to arithmetic operations are treated
    as zero with the same sign. Arithmetic
    operations never produce denormal
    results, but produce +0 instead.
  • Arithmetic operations do not support IEEE Inf or 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.

Of course, on a related page, you can also compile SPU code for strict IEEE conformance:

By default, XL C/C++ follows most, but
not all of the rules in the IEEE
standard. 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. To avoid this issue, and
to compile for strict compliance with
the IEEE standard, do the following:

  • Use the -qfloat=nomaf compiler option.
  • If the program changes the rounding mode at runtime, use the -qfloat=rrm
    option.
  • If the data or program code contains signaling NaN values (NaNS), use the
    -qfloat=nans option. (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.)
  • If you compile with -O3, -O4, or -O5, include the option -qstrict after it.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文