有没有办法在 Xcode 4 中为 ARM 而不是 Thumb 编译?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8390606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:40:53  来源:igfitidea点击:

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

iosxcodecompiler-constructionxcode4arm

提问by openfrog

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.

如果正在进行许多浮点运算,Apple 建议为 ARM 编译而不是使用拇指。我的整个应用程序几乎是一个大浮点运算。

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

这是他们在 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.

iOS 设备支持两种指令集,ARM 和 Thumb。Xcode 默认使用 Thumb 指令,因为与 ARM 相比,使用 Thumb 通常可以将代码大小减少约 35%。如果使用 ARM 指令而不是 Thumb,则具有大量浮点代码的应用程序可能会执行得更好。您可以为您的应用程序关闭 Thumb,以便它为 ARM 编译,方法是将 Compile for Thumb 构建设置设置为 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?

但是,我在构建设置中找不到任何“为 Thumb 编译”设置。他们重命名了吗?还是现在 Xcode 4 不可用?

回答by Brad Larson

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.

首先,建议不要针对 Thumb 指令集进行编译以提高浮点性能,这仅适用于旧的 ARMv6 设备。

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.

ARMv7 硬件(iPhone 3GS 和更新版本,包括所有 iPad)使用更高效的 Thumb-2 指令集,不会遭受相同类型的浮点速度减慢。对于 ARMv7 构建,建议在几乎所有为 Thumb 构建的情况下使用。我在此处的回答中提供了更多有关此的详细信息。

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.

这可能就是此编译器设置不再作为常见选项公开的原因,因为 ARMv7 设备是绝大多数 iOS 设备。

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).

如果您只想为您的 ARMv6 构建执行此操作,您可以转到构建设置并将鼠标悬停在“其他 C 标志”选项上。单击此选项右侧出现的小加号按钮,并为 ARMv6 架构添加条件。再次执行此操作为 ARMv7 体系结构创建一个。在 ARMv6 架构下,添加额外的编译器标志-mno-thumb(如 Kevin 建议的)。

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

您应该最终得到如下所示的内容:

Build settings for ARMv6

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.

我在我的一个应用程序中这样做了,因为我确实看到了旧 ARMv6 设备的性能提升。但是,我的另一个应用程序在不为 ARMv6 上的 Thumb 构建时速度较慢,因此您需要先对其进行概要分析。

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.

此外,目前在 Xcode 4.2 附带的 LLVM Compiler 3.0 中存在一个错误(据我所知,此错误已在 4.2.1 中修复),其中浮点计算在 ARMv6 的 Thumb 下编译错误。如果您使用的是该特定版本的 Xcode,则需要执行此操作才能在旧设备上正常运行。

回答by Lily Ballard

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

我不知道 Xcode 4 中是否应该存在“Compile for Thumb”,但您始终可以-mno-thumb将其添加到其他 C 标志构建设置中。

回答by xoconoxtle

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")!

关于您的原始问题:我注意到 Xcode 4.2.1 中的“为 Thumb 编译”(在“项目构建设置”的“代码生成”部分下)仅在您使用 LLVM GCC 4.2 时才可用(如果在“ 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.

如果使用 Apple LLVM 3.0 进行编译,那么您将找不到“Compile for Thumb”选项。但是 - 正如 Brad 已经说过的 - 您仍然可以更改“Other C Flags”选项以关闭 Thumb 模式。

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.

另一个有趣的一点:我在我的项目中使用了 sqlite 合并源(我需要 fts - 全文搜索)并且自从使用 LLVM 3.0 编译后,我在访问数据库时在 armv6 设备上发生了奇怪且相当随机的崩溃:事实证明这是因为在为 armv6 设备编译时未禁用 Thumb 模式。