iPhone 4 和 iPad 2:定点运算相对于浮点的优势

发布于 2024-10-29 19:01:31 字数 180 浏览 4 评论 0原文

我听说 iPhone 4 和 iPad 有一个称为 VFP 的 FPU,它以某种方式优化浮点运算,甚至允许 SIMD(尽管 GCC 是否利用这一点值得怀疑)。然而,我读到,对于某些 Android 设备,使用定点相对于浮点的加速可以导致性能提高 20 倍。

在这些设备中使用定点算术实现代码中的浮点密集型部分相对于浮点有什么优势。

I've heard that the iPhone 4 and the iPad have a fpu called the VFP that in some way optimizes floating point arithmetic, even allowing SIMD (though whether GCC takes advantage of that is doubtful). However, I've read that for some Android devices, the speedup of using fixed point over floating point can lead to increases of 20x in performance.

What would be the advantages of implementing a floating point-intensive part of my code using fixed point arithmetic over floating point in those devices.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾`听者〃 2024-11-05 19:01:32

iPhone 3G Armv6 CPU 有一个 VFP 流水线浮点单元,它比以整数进行相同计算具有更高的吞吐量。 GCC 确实支持生成安排用于流水线操作的 VFP 指令。 iPhone 3GS 和 iPhone 4 armv7 CPU 没有流水线 VFP 单元,因此在某些浮点序列上实际上比 iPhone 3G 稍慢;但 armv7 处理器在可矢量化短浮点方面速度更快,因为它具有 NEON 并行矢量单元。某些 Android 设备 CPU 根本没有任何硬件浮点单元,因此操作系统使用 FP 的软件模拟,这可能比整数或定点慢一个数量级以上。

一般的经验法则可能是,如果您的算法只能处理 24 位尾数精度,并且不在浮点和整数之间进行大量转换,请在 iOS 上使用短浮点数。它几乎总是更快。

但如果您想使用 C 代码(使用 NDK)支持较旧的 Android 设备,请使用缩放整数。

如果您的应用程序没有进行大量的数字运算,对于低于 0.1% 的典型应用程序来说,上述任何一项都不会真正产生明显的差异。

The iPhone 3G armv6 CPU had a VFP pipelined floating point unit that had a higher throughput than doing the same calculations in integer. GCC does support generating VFP instructions scheduled for pipelining. The iPhone 3GS and iPhone 4 armv7 CPU does not have a pipelined VFP unit, and is thus actually slightly slower at some floating point sequences than the iPhone 3G; but the armv7 processor is faster at vectorizable short floating point because it has the NEON parallel vector unit instead. Some Android device CPUs don't have any hardware floating point unit at all, so the OS uses software emulation for FP, which can be more than an order of magnitude slower than integer or fixed-point.

A general rule of thumb might be that if your algorithms can deal with only 24 bits of mantissa precision, and don't do a lot of conversions between float and integer, use short floating point on iOS. It's almost always faster.

But if you want to support older Android devices with your C code (using the NDK), use scaled integer.

If your app doesn't do a lot of number crunching, for a typical app that does under 0.1%, none of the above really makes a noticeable difference.

明明#如月 2024-11-05 19:01:32

正如 hotpaw2 所说,iPhone 4 和 iPad 2 都有硬件浮点,因此您不会看到在缺乏此类硬件的平台上获得的数量级加速。

也就是说,NEON 向量单元确实支持整数运算和浮点运算,并且可以通过将某些运算转换为定点问题来加速某些运算。 但是,除非您真正了解自己在做什么,并且准备好编写关键例程的汇编实现,否则您不会看到任何好处。

如果适合您的问题,请坚持使用浮点。如果您需要提高性能,我保证跟踪应用程序的执行将带来许多更好的调整机会。

As hotpaw2 said, both the iPhone 4 and the iPad 2 have hardware floating-point, so you won't see the order-of-magnitude speedups that you get on platforms that lack such hardware.

That said, the NEON vector unit does support integer operations as well as floating-point, and it is possible to speed up certain operations by casting them as fixed-point problems instead. However, unless you really understand what you're doing, and are prepared to write assembly implementations of your critical routines, you will not see any benefit.

Stick to floating-point if it suits your problem. If you need to improve performance, I guarantee that tracing execution of your app will turn up many better opportunities for tuning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文