gcc -ffp-contract选项的区别 [英] Difference in gcc -ffp-contract options

查看:1456
本文介绍了gcc -ffp-contract选项的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于GNU GCC中的 -ffp-contract 标志的问题(参见 https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html )。


$ b $标志文档写成如下:


-ffp-contract = off 禁用浮点表达式收缩。 -ffp-contract = fast 启用浮点表达式收缩,例如,如果目标对它们有本地支持,则会形成融合的乘加操作。如果语言标准允许, -ffp-contract = on 将启用浮点表达式收缩。目前尚未实施并且被视为等于 -ffp-contract = off 。默认值是 -ffp-contract = fast


现在提问:


  • 是在快速和开启之间的区别吗?


除了FMA之外是否还有其他收缩示例(或类似fused-mult子)? >

解决方案

在C89中,FP收缩是不允许的。从C99开始,默认情况下,实现可能会执行FP收缩表达式,但是需要提供可以切换以影响收缩行为的 #pragma FP_CONTRACT



因此,GCC开关应该是:
$ b $ ul

  • -ffp-contract = off :不要收缩。忽略 #pragma FP_CONTRACT 。这是 -std = c89 的默认值。

  • -ffp-contract = on :默认启用收缩,并为 #pragma FP_CONTRACT 赋值。这是 -std = c99 及以上的默认值。

  • -ffp-contract = fast :我们没有在快速数学模式下声明ISO一致性,所以可以总是收缩,即使是单独的表达式也是如此(请参阅Marc Glisse的评论)。


    不幸的是,在GCC中尚未实现 #pragma FP_CONTRACT ,所以现在 -ffp-contract = on 保持符合ISO标准的必要条件: nothing



    您必须深入了解资源(或邮件列表),才能了解GCC能够执行哪种收缩操作,但不必限于FMA。




    C11标准对 #pragma FP_CONTRACT


    §6.5¶8:可能会收缩浮动表达式,也就是计算为
    虽然它是一个单一的操作,从而省略了四舍五入错误由源代码和表达式评估方法完成.89)FP_CONTRACT编译指示提供了一种禁止约束表达式的方法。否则,表达式是否和如何被约定是实现定义的.90)

    89)收缩表达式中的中间操作被评估为无限范围和精度,而最后的操作被舍入到由表达式评估方法确定的格式。一个约定的表达式可能也会忽略浮点异常的产生。


    90)这个许可证专门用于允许实现利用组合多个C操作符的快速机器指令。由于收缩可能会削弱可预测性,甚至会降低包含表达式的准确性,所以它们的使用需要有明确的定义和明确的文档记录。


    I have a question regarding the -ffp-contract flag in GNU GCC (see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html).

    The flag documentation is written as follows:

    -ffp-contract=off disables floating-point expression contraction. -ffp-contract=fast enables floating-point expression contraction such as forming of fused multiply-add operations if the target has native support for them. -ffp-contract=on enables floating-point expression contraction if allowed by the language standard. This is currently not implemented and treated equal to -ffp-contract=off. The default is -ffp-contract=fast.

    Now the question:

    • What is the difference between fast and on?
    • Is there any other contraction example beside the FMA (or similar like the fused-mult sub)?

    解决方案

    In C89, FP contraction is disallowed. Starting with C99, an implementation may do FP contraction of expressions by default, but would then be required to provide a #pragma FP_CONTRACT which can be toggled to influence contraction behavior.

    So the GCC switch was supposed to be:

    • -ffp-contract=off: Don't do contraction. Ignore #pragma FP_CONTRACT. This is the default for -std=c89.
    • -ffp-contract=on: Enable contraction by default and honor #pragma FP_CONTRACT. This would be the default for -std=c99 and above.
    • -ffp-contract=fast: We don't claim ISO conformance in fast-math mode, so it's ok to always contract, even separate expressions (See Marc Glisse's comment).

    Unfortunately, #pragma FP_CONTRACT is not yet implemented in GCC, so for now -ffp-contract=on does what is necessary to stay ISO-conforming: nothing.

    You'd have to dig into the sources (or mailing list) to see what kind of contractions GCC is able to do, but it doesn't have to be limited to FMA.


    What the C11 standard has to say about #pragma FP_CONTRACT:

    §6.5¶8: A floating expression may be contracted , that is, evaluated as though it were a single operation, thereby omitting rounding errors implied by the source code and the expression evaluation method.89) The FP_CONTRACT pragma in provides a way to disallow contracted expressions. Otherwise, whether and how expressions are contracted is implementation-defined.90)

    89) The intermediate operations in the contracted expression are evaluated as if to infinite range and precision, while the final operation is rounded to the format determined by the expression evaluation method. A contracted expression might also omit the raising of floating-point exceptions.

    90) This license is specifically intended to allow implementations to exploit fast machine instructions that combine multiple C operators. As contractions potentially undermine predictability, and can even decrease accuracy for containing expressions, their use needs to be well-defined and clearly documented.

    这篇关于gcc -ffp-contract选项的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆