Skip to content

Commit b5f1979

Browse files
committed
Enable the +v7 feature on Android by default
With the recently added double word CAS functionality on 32-bit ARM (enabled via a 64-bit atomic instruction in LLVM IR), without some extra features enabled LLVM lowers code to function calls which emulate atomic instructions. With the v7 feature enabled, proper 64-bit CAS instructions are used on 32-bit arm. I've been told that v7 for arm is what we should have been doing anyway. This is overridable by providing some other non-empty feature string.
1 parent b00147a commit b5f1979

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/librustc/back/link.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,32 @@ pub mod write {
9898
use lib;
9999
use syntax::abi;
100100
use util::common::time;
101+
use syntax::abi;
101102

102103
use std::c_str::ToCStr;
103104
use std::libc::{c_uint, c_int};
104105
use std::path::Path;
105106
use std::run;
106107
use std::str;
107108

109+
// On android, we by default compile for armv7 processors. This enables
110+
// things like double word CAS instructions (rather than emulating them)
111+
// which are *far* more efficient. This is obviously undesirable in some
112+
// cases, so if any sort of target feature is specified we don't append v7
113+
// to the feature list.
114+
fn target_feature<'a>(sess: &'a Session) -> &'a str {
115+
match sess.targ_cfg.os {
116+
abi::OsAndroid => {
117+
if "" == sess.opts.target_feature {
118+
"+v7"
119+
} else {
120+
sess.opts.target_feature.as_slice()
121+
}
122+
}
123+
_ => sess.opts.target_feature.as_slice()
124+
}
125+
}
126+
108127
pub fn run_passes(sess: Session,
109128
trans: &CrateTranslation,
110129
output_type: OutputType,
@@ -136,7 +155,7 @@ pub mod write {
136155

137156
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|T| {
138157
sess.opts.target_cpu.with_c_str(|CPU| {
139-
sess.opts.target_feature.with_c_str(|Features| {
158+
target_feature(&sess).with_c_str(|Features| {
140159
llvm::LLVMRustCreateTargetMachine(
141160
T, CPU, Features,
142161
lib::llvm::CodeModelDefault,

0 commit comments

Comments
 (0)