Is there a way to compile for ARM rather than Thumb in Xcode 4?
Asked Answered
L

3

28

Apple is recommending to compiling for ARM rather than thumb if there are many floating point operations going on. My whole app is almost one big floating point operation.

Here's what they say in the iOS App Development Workflow Guide:

iOS devices support two instruction sets, ARM and Thumb. Xcode uses Thumb instructions by default because using Thumb typically reduces code size by about 35 percent relative to ARM. Applications that have extensive floating-point code might perform better if they use ARM instructions rather than Thumb. You can turn off Thumb for your application, so it compiles for ARM, by setting the Compile for Thumb build setting to No.

However, I cannot find any "Compile for Thumb" setting in my build settings. Did they rename it? Or is this unavailable now with Xcode 4?

Leighannleighland answered 5/12, 2011 at 19:18 Comment(0)
F
49

First, the advice to not compile for the Thumb instruction set in order to improve floating point performance only really applies to the old ARMv6 devices.

ARMv7 hardware (iPhone 3G S and newer, including all iPads) uses the more efficient Thumb-2 instruction set, which does not suffer the same sort of floating point slowdowns. For ARMv7 builds, it is recommended in almost all cases that you build for Thumb. I provide a little more detail about this in my answer here.

This might be why this compiler setting is no longer exposed as a common option, because ARMv7 devices are the vast majority of iOS devices out there.

If you want to do this for just your ARMv6 builds, you can go to your build settings and mouse over the "Other C Flags" option. Click on the little plus button that appears to the right of this option and add a condition for the ARMv6 architecture. Do this again to create one for the ARMv7 architecture. Under the ARMv6 architecture, add the extra compiler flag of -mno-thumb (as Kevin suggests).

You should end up with something that looks like the following:

Build settings for ARMv6

I do this in one of my applications, because I did see a performance boost on the older ARMv6 devices with that. However, another of my applications was slower when not building for Thumb on ARMv6, so you'll want to profile this first.

Additionally, there is currently a bug in the LLVM Compiler 3.0 that ships with Xcode 4.2 (which has since been fixed in 4.2.1, from what I hear) where floating point calculations are compiled wrong under Thumb for ARMv6. If you're using that particular version of Xcode, you'll need to do this for proper behavior on the older devices.

Flaunch answered 5/12, 2011 at 20:40 Comment(2)
Xcode 4.2.1 seems to be only for Lion. Would use it if Photoshop and a whole bunch of other apps wouldn't have big issues with Lion. Damn. Is there a workaround to that bug in Xcode 4.2? Can you point out what to do in case where Lion is not an option?Leighannleighland
@Leighannleighland - Just don't build for Thumb when targeting ARMv6 in that case, like I show above. ARMv7 has no such problems, and can be built using Thumb instructions just fine. Honestly, disabling Thumb for ARMv6 won't affect many of your users if it does cause a slowdown, as estimates place ARMv6 devices at 3-5% of the currently active iOS devices out there: marco.org/2011/11/30/…Flaunch
F
8

I don't know whether or not "Compile for Thumb" is supposed to exist in Xcode 4, but you can always add -mno-thumb to the Other C Flags build setting.

Fiorenza answered 5/12, 2011 at 19:23 Comment(0)
M
3

Regarding your original question: I have noticed that "Compile for Thumb" (under the section "Code Generation" of your "Project Build Settings") in Xcode 4.2.1 is only available if you are using LLVM GCC 4.2 (if set in "Compiler for C/C++/Objective-C")!

If compiling with Apple LLVM 3.0 then you will find no "Compile for Thumb" option. But - as Brad already said - you can still change the "Other C Flags" option to turn off Thumb mode.

Another interesting point: I am using the sqlite amalgamation source in my project (i need fts - full text search) and since compiling with LLVM 3.0 I had strange and rather random crashes on armv6 devices whenever accessing the database: as it turns out that was because of Thumb mode not disabled when compiling for armv6 devices.

Mesothorium answered 17/12, 2011 at 21:56 Comment(1)
i also expected sqlite crashes on armv6, but only when i build library with llvm gcc. after switching to llvm - it works fine.Hiroshima

© 2022 - 2024 — McMap. All rights reserved.