views:

380

answers:

1
+1  Q: 

iPhone Thumb & VFP

How do 'compile for Thumb' and VFP code relate to each other?

on the iPhone 2G/3G, i know that the Thumb instructionset doesn't include floatingpoint calculations (on the 3GS, Thumb2 aparently has..). So what happens, if one compiles for thumb, but uses VFP code for floatingpoint calculations?

i know that's pretty indepth - but probably someone here knows...c

+3  A: 

I'm not sure what you mean by "use VFP code". Do you mean floating-point code, which may get compiled to run on VFP, or do you mean actual VFP assembly instructions?

If you compile in thumb mode and use floating point, a function call will be made for each floating point operation in your code. These function calls (they'll have names like __muldf3vfp) switch the mode to ARM, move the data into the floating point registers, perform the operation, move the data back to integer registers, and return. That's a lot of work for something that's only one instruction if you compile in ARM mode, so don't use thumb in float-intensive code.

If you try to use VFP assembly instructions in thumb mode, you'll just get an assembler error.

As you noted, the 3GS supports thumb2, which does have access to the VFP and NEON registers, so this situation doesn't apply.

Also note that the switch between thumb and ARM compilation can be done per source file, so you can compile most of your project in thumb and use ARM for a few routines that do a lot of floating-point, for example. If you want to write assembly code, you can switch between ARM and thumb per function.

Stephen Canon
i meant actual VFP assembly instructions. however - what compiler setting makes floating point math automatically be compiled for the VFP?
genesys
Added to my answer that using VFP assembly instructions in thumb mode will just give you an assembler error. Also, floating-point is compiled to VFP by default (except for single precision when targeting the 3GS, which uses NEON instructions).
Stephen Canon
hm. I'm working on a 3d game which does a lot of fp math (matrix computations, vector transformations and so on) - however, turning of thumb only slightly decreases performance instead of increasing it. Do you have an idea what could this tells me?
genesys
and how do I set thumb mode per sourcefile?
genesys
Are you measuring performance on a 3GS or an earlier model? To set thumb mode for a single file in an XCode project, right-click on the file in the source list, click `Get Info`, choose the `Build` tab, and add `-mthumb` to the `Additional Compiler Flags` field. (This field is actually per file/target combination, so if your project has multiple targets you need to make sure the right one is active)
Stephen Canon
Alternatively, you can put some of your sources into a secondary build target that uses a different set of flags to build, say, a static library that gets linked into your final executable. If you have a lot of sources, this can be easier than setting the flags per-file for all of them.
Stephen Canon
and how can i DEactivate thumb for a single file?
genesys