Is it possible to roll a significantly faster version of sqrt

后端 未结 6 1819
傲寒
傲寒 2020-12-14 01:38

In an app I\'m profiling, I found that in some scenarios this function is able to take over 10% of total execution time.

I\'ve seen discussion over the years of fast

6条回答
  •  忘掉有多难
    2020-12-14 02:04

    Don't know if you fixed this, but I've read about it before, and it seems that the fastest thing to do is replace the sqrt function with an inline assembly version;

    you can see a description of a load of alternatives here.

    The best is this snippet of magic:

    double inline __declspec (naked) __fastcall sqrt(double n)
    {
        _asm fld qword ptr [esp+4]
        _asm fsqrt
        _asm ret 8
    } 
    

    It's about 4.7x faster than the standard sqrt call with the same precision.

提交回复
热议问题