是否可能滚动明显更快的版本的sqrt [英] Is it possible to roll a significantly faster version of sqrt

查看:166
本文介绍了是否可能滚动明显更快的版本的sqrt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程式中,我发现在某些情况下,此功能可以占用总执行时间的10%。

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

讨论多年来使用sneaky浮点骗局更快的sqrt实现,但我不知道这样的事情是否过时的现代CPU。

I've seen discussion over the years of faster sqrt implementations using sneaky floating-point trickery, but I don't know if such things are outdated on modern CPUs.

MSVC ++ 2008编译器用于参考...虽然我认为sqrt不会增加很多开销,

MSVC++ 2008 compiler is being used, for reference... though I'd assume sqrt is not going to add much overhead though.

另请参见这里讨论 modf function。

See also here for similar discussion on modf function.

EDIT:作为参考,是一种广泛使用的方法,但实际上更快?

for reference, this is one widely-used method, but is it actually much quicker? How many cycles is SQRT anyway these days?

推荐答案

是的,这是可能的,即使没有骗局:

Yes, it is possible even without trickery:

1)牺牲速度的准确性:sqrt算法是迭代的,用较少的迭代重新实现。

1) sacrifice accuracy for speed: the sqrt algorithm is iterative, re-implement with fewer iterations.

2)查找表:

3)缓存:你总是在使用相同的有限值吗?如果是这样,缓存可以很好地工作。我发现这在图形应用程序中是有用的,同样的事情正在计算大量形状相同的大小,因此结果可以有用地缓存。

3) caching: are you always sqrting the same limited set of values? if so, caching can work well. I've found this useful in graphics applications where the same thing is being calculated for lots of shapes the same size, so results can be usefully cached.

这篇关于是否可能滚动明显更快的版本的sqrt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆