What is floating point speculation and how does it differ from the compiler's floating point model

↘锁芯ラ 提交于 2019-12-21 04:34:09

问题


The Intel C++ compiler provides two options for controlling floating point:

-fp-speculation (fast/safe/strict/off) -fp-model (precise/fast/strict and source/double/extended)

I think I understand what fp-model does. But what is fp-speculation and how does it relate to fp-model? I have yet to find any intel doc which explains this!


回答1:


-fp-model influences how floating-point computations are carried out, and can change the numeric result (by licensing unsafe optimizations or by changing the precision at which intermediate results are evaluated).

-fp-speculation does not change the numerical results, but can effect what floating-point flags are raised by an operation (or what traps are taken if floating-point traps are enabled). 99.99% of programmers don't need care about these things, so you can probably run with the default and not worry about it.

Here's a concrete example; suppose you have the following function:

double foo(double x) {
    // lots of computation
    if (x >= 0) return sqrt(x);
    else return x;
}

sqrt is, relatively speaking, slow. It would be nice to hoist the computation of sqrt(x) like this:

double foo(double x) {
    const double sqrtx = sqrt(x);
    // lots of computation
    if (x >= 0) return sqrtx;
    else return x;
}

By doing this, we allow the computation of sqrt to proceed simultaneously with other computations, reducing the latency of our function. However, there's a problem; if x is negative, then sqrt(x) raises the invalid flag. In the original program, this could never happen, because sqrt(x) was only computed if x was non-negative. In the modified program, sqrt(x) is computed unconditionally. Thus, if x is negative, the modified program raises the invalid flag, whereas the original program did not.

The -fp-speculation flag gives you a way to tell the compiler whether or not you care about these cases, so it knows whether or not it is licensed to make such transformations.




回答2:


Out of order execution and speculative execution can result in extraneous exceptions or raise exceptions at the wrong time.

If that matters to you, you can use the fp-speculation option to control speculation of floating-point instructions.

For (a little bit) more information: http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/copts/common_options/option_fp_speculation.htm




回答3:


On Windows OS: 1.Intel compiler floating calculation 32 bit application vs 64 bit application , same code Can give to you different result!!!! No matter what flag you choose:)!!!!

2.Visual studio compiler floating calculation 32 bit vs 64 bit application , same code output same result.



来源:https://stackoverflow.com/questions/7419113/what-is-floating-point-speculation-and-how-does-it-differ-from-the-compilers-fl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!