I am implementing Kahan summation, in a project that supports compilation with gcc47, gcc48, clang33, icc13, and icc14.
As part of this algorithm, I would like to disable optimizations that take advantage of the associativity of addition of real numbers. (Floating point operations are not associative.)
I would like to disable those optimizations only in the relevant function. I have figured out how to do this under gcc, using the ''no-associative-math'' attribute. How can I do this in icc or clang? I have searched without luck.
class KahanSummation
{
// GCC declaration
void operator()(float observation) __attribute__((__optimize__("no-associative-math")))
{
// Kahan summation implementation
}
};
Other GCC attributes that would imply no-associative-math
are no-unsafe-math-optimizations
or no-fast-math
.
Looking at an Intel presentation (PDF, slide 8) or another or another (PDF, slide 11), I want to set "fp-model precise" in ICC, for only this function. The compilers I care about are ICC 13 and ICC 14.
class KahanSummation
{
// ICC or clang declaration
void operator()(float observation) __attribute__((????))
{
// Kahan summation implementation
}
};
__attribute__
is a GCC extension. Implement those functions in a separate translation unit and compile that using the appropriate switch? – T.C.