iPhone上最快的反方形根 [英] Fastest Inverse Square Root on iPhone

查看:145
本文介绍了iPhone上最快的反方形根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款涉及某些物理计算的iPhone应用程序,这些计算每秒进行数千次。我正在努力优化代码以提高帧速率。我正在寻求改进的其中一个部分是平方根。现在,我正在使用 Quake 3快速反平方根方法。然而,在做了一些研究后,我听说通过使用NEON 指令集。我不熟悉内联汇编,无法弄清楚如何使用NEON。我尝试实施 math-neon 库,但由于大多数基于NEON的函数缺少返回

I'm working on an iPhone app that involves certain physics calculations that are done thousands of times per second. I am working on optimizing the code to improve the framerate. One of the pieces that I am looking at improving is the inverse square root. Right now, I am using the Quake 3 fast inverse square root method. After doing some research, however, I heard that there is a faster way by using the NEON instruction set. I am unfamiliar with inline assembly and cannot figure out how to use NEON. I tried implementing the math-neon library but I get compiler errors because most of the NEON-based functions lack return.

编辑:我突然得到一些不明确的问题关闭投票。虽然我认为它非常明确而且回答明显的人明白了,也许有些人需要明确说明:
你如何使用Neon来执行更快的计算?它是否真的是在iPhone上获得平方根的最快方法?

I've suddenly been getting some "unclear question" close votes. Although I think its quite clear and those who answered obviously understood, maybe some people need it stated explicitly: How do you use Neon to perform faster calculations? And is it really the fastest method for getting the inverse square root on the iPhone?

编辑:我今天在Neon VS Quake上做了一些更正式的测试,但如果有的话,我现在对结果更加不确定了:

I did some more formal testing on Neon VS Quake today, but If anything, I'm even more uncertain about the outcome now:


  • 应用内测试:(一个应用程序是目前在app商店中修改了invsqrt方法)

  • In-App Testing: (An app that is currently in the app store with its invsqrt method modified)


  1. Quake Method(在压力条件下平均FPS略有增加)

  2. 霓虹灯(这是一个非常接近的电话,但似乎Quake稍快一点)

  3. 1 / sqrtf()(差异更明显,1 -3 FPS下降)。


  • 正式测试(吞噬我手机CPU的应用程序。花费多长时间每个方法通过一组10000000随机生成的浮点数)

  • "Formal" Testing (An app that devours my Phone's CPU. Times how long it takes each method to get through an array of 10000000 randomly generated floats)


    1. Neon(显然是最快的,如果它用于一次做两个sqrts。)

    2. 1 / sqrtf()(只是略慢一点)比霓虹灯。这个令人惊讶的结果让我认为这个测试不确定,直到我进一步调查。)

    3. Quake(令人惊讶的是,这种方法比其他两种方法慢了几个数量级。这是鉴于其在其他测试中的表现,尤其令人惊讶。)


  • 虽然地震与霓虹灯相比在应用程序性能测试中过于接近无法确切地说出任何事情,第一次测试中的地震vs 1 / sqrtf()非常明显地被切断,第二次测试与它输出的值非常一致。但最重要的是应用程序性能,所以我将根据该测试做出最终决定。

    While quake vs neon was too close to say anything for sure in the app performance test, the quake vs 1/sqrtf() was quite clearly cut out in the first test, and the second test was extremely consistent with the values it outputted. What is important in the end, though, is app performance, so I'm going to make my final decision based on that test.

    推荐答案

    接受的答复 -in-square-root-on-the-iphone>你链接的问题已经提供了答案,但没有拼写出来:

    The accepted answer of the question you've linked already provides the answer, but doesn't spell it out:

    #import <arm_neon.h>
    
    void foo() {
        float32x2_t inverseSqrt = vrsqrte_f32(someFloat);
    }
    

    iOS SDK已经提供了标题和功能。

    Header and function are already provided by the iOS SDK.

    这篇关于iPhone上最快的反方形根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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