How to Compile for Arm Rather Than Thumb in Xcode 4

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

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.

iPhone compile for thumb

GCC_THUMB_SUPPORT is the right variable. Just set it to NO to disable THUMB code generation.

A general rule of THUMB is, to disable it if your code is floating point heavy :)

More about that here.

Update:

The advice to compile for the THUMB instruction set is no longer valid (actually since the iPhone 3GS).

How to add -mthumb to Xcode

Looking at the assembler output, I believe Thumb generation is the default in clang when building for armv7. You can turn it off using -mno-thumb.

GCC_THUMB_SUPPORT: Can it be turned OFF for just one module?

In Xcode 3, you can follow the process described by Paul in his answer here to set per-file build settings. Using that, you can add a custom setting to not use Thumb support for a file.

Xcode 4 moves these per-file configuration options. Joshua Nozzi describes where they end up in his short article here. Basically, they're now under the Build Phases tab within the project settings, under the Compile Sources grouping.

Be aware, however, that turning off building for Thumb is only recommended for the non-ARMv7 devices. Building using the Thumb2 instruction set in the ARMv7 devices (the iPhone 3G S and newer) is recommended in almost all cases. The Thumb instruction set can lead to a smaller binary, and it only slows down floating-point-heavy calculations on the older ARMv6 devices, not the overwhelming majority of hardware out there right now.

Why both arm and thumb compiling in Eclipse ADT?

You probably mean, for arm v6 and arm v7a? Both can be compiled as ARM or THUMB. This is controlled by LOCAL_ARM_MODE in Android.mk. To disable armeabi, set

APP_ABI=armeabi-v7a

in Application.mk. This will not only reduce your build time, but also the size of your APK.

Why is XCode archive acting different than XCode build/run on iPhone

Try to turn off compiler optimizations.

Something is going wrong with UI on old iOS 3.x and 4.x ARMv6 devices when compiling a release build. I have no idea why, but turning off compiler optimizations will help.

Turning off Thumb may also help you with this issue, 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.

Thumb turned off for ARMv6



Related Topics



Leave a reply



Submit