views:

818

answers:

4

As the title, I'm finding vector/matrix library in C optimized for iPhone/iPod processors. Or just generally fast.

---(edit)---

I'm sorry for unclear question. I'm looking for fast lib for commercial games for iPhone/iPod. So GPL lib cannot be used.

However, I'll stop finding fastest lib, it maybe meaningless.

A: 

GSL from GNU.

Hassan Syed
+2  A: 

Depends very much on your needs, if you're just using straight floating point math you will probably find that the compiler will use software floating point, which will be very slow. So step one is making sure that youuse the hardware floating point unit that is available in the iPhone processor.

Step two is using an already well established library, there are several, Hassan already provided you with a link to the GNU GSL which is nice.

The next step would be to take advantage of the VFP SIMD like abilities. The VFP is not actually SIMD, but does provide SIMD like instructions for which the individual operations are perform consequtively. The advantage of still using these instructions is that your program text will be shorter, allowing better use of the instruction cache and less problems when missing branch predictions and so forth. I am however not aware of any vector library taking advantage of the VFP, you'd have to do a good search and possible write your own if it's not available.

Finally, if you still need more speed, you'll want to use the true SIMD unit in the iPhone processor. However this unit is not a floating point unit, but an integer unit. So, assuming you do want real numbers, you'll be stuck with fixed point, it depends on your application whether you can get away with that. Again I am not aware of any vector library providing fixed point arithmetic using the SIMD unit provided by the iPhone processor, so again you'd need a thorough search and possibly get your hands dirty yourself.

wich
Thanks. My request is not so critical, implementing VFP/SIMD for this is too heavy work. I just wish GCC auto-vectorization saves me.
Eonil
A: 

Has anyone successfully ported & built GSL (Gnu Scientific Library) into their iPhone application? Being a noob, not too familiar how to get this to work as GSL requires running MAKE on your local machine.

Not sure how to do this for XCode for an iPhone project (vs MAKE for Mac OSX)

zeroinverse
+4  A: 

Now(2010.06.26) Accelerate framework included on iOS4, so vDSP/BLAS functions are available.

This utilizes hardware feature (CPU or SIMD) to accelerate floating point operations, so superior speed (2~4.5x average, 8x maximum) and less energy(0.25x maximum) consuming can be gained by using this.

Thanks people for other answers.

Eonil
+1 I've used the cblas functions successfully and once you get the hang of their documentation, they're quite useful.
Dave DeLong
+1 This is so useful to my current project that I'm only developing it for iOS4.0+ ... glad you mentioned this.
Rab