Does anyone happen to know whether the iPhone has an FPU and what the performance of floating point operations is?
I've seen a few references to a "vector floating point co-processor for 3d graphics" [1], but it's unclear to me whether that's something that needs a special API to access, or is it like a normal FPU and the just compiler uses it whenever you use floats?
I'm guessing there must be decent floating point, what with all the OpenGL stuff going on. But I'm wanting to figure out whether I can use floats or if I'll need to do fixed point math. Are there pointers to performance numbers perhaps?
The ARM processor used by the iPhone/iPod touch has an extension called VFP for doing fast floating point operations.
If you just want to do a few floating point calculations you probably don't need to worry much. If you're doing a lot of them you should switch off the "Compile for Thumb" option in your project settings for maximum floating point performance. This will make your code run in ARM processor mode instead of Thumb mode. Thumb doesn't directly support floating point.
Sorry, just to be clear, is there anything special you need to do to use the VFP? Special API calls or whatever? Or can I just use floats/doubles as normal? (except for the non-thumb mode stuff, that is).
In the general case, no. If you want to get fancy you can write assembler to take advantage of the vector instructions which will do several operations at once.
I didn't realize there was an option to compile in ARM mode. This could be handy if you're writing a game or some other really performance intensive application.
Why there's no benchmarking utility? Because there isn't much hardware variation (yet). The Touch 2G has a faster CPU, but otherwise I think everything is all the same on all platforms.
...you should switch off the "Compile for Thumb" option in your project settings...
Not meaning to be dense, but I can't find "compile for Thumb" in the project's build settings... only a selection of which compiler to use. It seems many moons ago I saw this somewhere, but did it go somewhere?
Directions to this option would help me out! (maybe, we'll see)!
Yeah, this option likes to hide. The trick is to right-click on your main build target under the "Targets" folder and select "Get Info". For some reason the option only shows when you enter project settings this way. In the dialog that opens make sure the "Build" tab is selected. Then enter "Thumb" in the search and you should see the option.
Project Settings, go all the way to the bottom to the section "GCC 4.0 - Code Generation", there is a setting labeled "Compile for Thumb".
On a commercial project I work on (not iphone-related) we compile some objects in ARM (for speed critical code) and some in Thumb mode (to save space). I don't see an easy way to do that with the Xcode build system though.
Actually, it's pretty easy. Just right click on a file you want to compile with ARM. Select "Get Info" and make sure the "Build" tab is selected. Should be an large text field. In this text field add "-mno-thumb" and that file will be compiled for ARM.
That works for me on my iPhone app. Alternatively you can use the "#pragma arm" and "#pragma thumb" directives to wrap your ARM code.
Thanks gang... I found it. Interesting though, as a test I compiled not-for-thumb and ran my regression test loop which basically does millions and millions and millions of floating point calculations with no display interaction (very very sparse output to console, one NSLog every 10 minutes or so) and while I didn't wait for it to finish the first segment of the regression test actually was taking longer than it does when compiled-for-thumb. Being the impatient sort with many other things to do than to watch a test run, I terminated after waiting 3x the normal time. My "floating point laden" routines mostly do arithmetic with liberal use of exp, log and pow but no trig (sin/cos etc.) so perhaps the vector graphics unit is optimized for trig? Makes sense to me!
I may benchmark some view generation that I do that contains Quartz2D drawing to see if thumb has any effect, but since I don't do much trig in there either I'm not expecting to see a difference.
All this is just another way to say: it would appear that your mileage may vary!
Actually, it's pretty easy. Just right click on a file you want to compile with ARM. Select "Get Info" and make sure the "Build" tab is selected. Should be an large text field. In this text field add "-mno-thumb" and that file will be compiled for ARM.
That works for me on my iPhone app. Alternatively you can use the "#pragma arm" and "#pragma thumb" directives to wrap your ARM code.
Good to know. The armcc compiler I use at work supports the same pragmas but I couldn't find any gcc documentation about that.
tawpie, here's the deal with ARM vs Thumb code. ARM code is a larger instruction set and has a lot shiny options that can give you faster performance. But Thumb code is 16 bits/instruction (half the size of ARM code) so you end up with a smaller code image. Smaller code means more of your code is cached and less time in general fetching instructions. So it definitely depends on your application which is optimal.
Probably, it's better to leave everything in Thumb mode and put only the most critical pieces in ARM mode (inner loops, heavy calculations, etc).
When I have some time (???) I may run some benchmarks for grins. For now, it'd be the difference of a half sec or so from the viewpoint of the user so it's not crucial but we all know that faster is better!
I see the "User-Defined" section at the end of the build info. I do NOT see GCC 4.0 Code Generation, Language, Preprocessing, and Warnings.
I found myself in this position a while back. Let's see if you're having the same problem I was having.
Next time you're in Xcode, looking for those "GCC 4.0..." settings, check your current build settings. Are you building against the Simulator? I was, and you probably are too.
Now, change your build settings so that you're building against the Device and check your project settings again. Do you now have the "GCC 4.0..." settings? I did, and you probably do to.
If this doesn't work for you, I'm sorry as I have no other idea what could be causing your problem. But I've found that once I discovered this behavior pattern, it's been consistent across all of my iPhone projects.