Can I make my compiler use fast-math on a per-function basis?

后端 未结 2 1661
孤街浪徒
孤街浪徒 2021-01-12 09:44

Suppose I have

template  void foo(float* data, size_t length);

and I want to compile one instantiation with

2条回答
  •  鱼传尺愫
    2021-01-12 10:30

    In GCC you can declare functions like following:

    __attribute__((optimize("-ffast-math")))
    double
    myfunc(double val)
    {
        return val / 2;
    }
    

    This is GCC-only feature.

    See working example here -> https://gcc.gnu.org/ml/gcc/2009-10/msg00385.html

    It seems that GCC not verifies optimize() arguments. So typos like "-ffast-match" will be silently ignored.

提交回复
热议问题