iPhone 4 and iPad 2: Advantages of fixed point arithmetic over floating point

怎甘沉沦 提交于 2019-12-24 01:25:49

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/5508933/iphone-4-and-ipad-2-advantages-of-fixed-point-arithmetic-over-floating-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!