如何设置ICC属性" fp-model precise"对于单个函数,是为了防止关联优化?

时间:2014-06-22 00:01:30

标签: c++ gcc clang compiler-optimization icc

我正在一个支持使用gcc47,gcc48,clang33,icc13和icc14进行编译的项目中实现Kahan summation

作为此算法的一部分,我想禁用利用实数加法的相关性的优化。 (浮点运算不是关联的。)

我想仅在相关功能中禁用这些优化。我已经找到了如何使用''no-associative-math''属性在gcc下执行此操作。我怎么能在icc或clang中做到这一点?我没有运气搜索过。

class KahanSummation
{
  // GCC declaration
  void operator()(float observation) __attribute__((__optimize__("no-associative-math")))
  {
    // Kahan summation implementation
  }
};

暗示no-associative-math的其他GCC属性为no-unsafe-math-optimizationsno-fast-math

查看Intel presentation (PDF, slide 8)或其他or another (PDF, slide 11),我想设置" fp-model precise"在ICC中,仅用于此功能。我关心的编译器是ICC 13和ICC 14。

class KahanSummation
{
  // ICC or clang declaration
  void operator()(float observation) __attribute__((????))
  {
    // Kahan summation implementation
  }
};

1 个答案:

答案 0 :(得分:1)

__attribute__是GCC扩展程序。 Clang还支持该语法以保持一些GCC兼容性,但它似乎支持的唯一与优化相关的属性是optnone,它会关闭所有优化。 ICC a few optimization pragmas,但没有什么可以做我想说的事情。 appears to support #pragma float_control兼容VC ++,尽管我可以&#39 ;找不到ICC文档中应该如何使用该pragma的任何内容,因此您必须使用VC++

但是,您可以做的是在单独的翻译单元(即cpp文件)中定义所需的功能:

// Your header
class KahanSummation
{
  // Declaration
  void operator()(float observation);
};

// Separate cpp file - implements only this function
void KahanSummation::operator()(float observation)
{
    // Kahan summation implementation
}

然后,您可以使用您需要使用的任何编译器选项编译单独的文件,并将生成的目标文件链接到您的程序的其余部分。