Skip to content

Commit 3d1ed35

Browse files
committed
Rollup merge of rust-lang#48126 - newpavlov:patch-1, r=alexcrichton Whitelist pclmulqdq x86 feature flag Relevant stdsimd [issue](rust-lang/stdarch#318).
2 parents 5a0a9a0 + c2a31de commit 3d1ed35

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

src/librustc_trans/attributes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn provide(providers: &mut Providers) {
142142
assert_eq!(cnum, LOCAL_CRATE);
143143
Rc::new(llvm_util::target_feature_whitelist(tcx.sess)
144144
.iter()
145-
.map(|c| c.to_str().unwrap().to_string())
145+
.map(|c| c.to_string())
146146
.collect())
147147
};
148148

@@ -212,7 +212,8 @@ fn from_target_feature(
212212
let value = value.as_str();
213213
for feature in value.split(',') {
214214
if whitelist.contains(feature) {
215-
target_features.push(format!("+{}", feature));
215+
let llvm_feature = llvm_util::to_llvm_feature(feature);
216+
target_features.push(format!("+{}", llvm_feature));
216217
continue
217218
}
218219

src/librustc_trans/llvm_util.rs

+39-35
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use llvm;
1414
use rustc::session::Session;
1515
use rustc::session::config::PrintRequest;
1616
use libc::c_int;
17-
use std::ffi::{CStr, CString};
17+
use std::ffi::CString;
1818

1919
use std::sync::atomic::{AtomicBool, Ordering};
2020
use std::sync::Once;
@@ -79,57 +79,61 @@ unsafe fn configure_llvm(sess: &Session) {
7979
// detection code will walk past the end of the feature array,
8080
// leading to crashes.
8181

82-
const ARM_WHITELIST: &'static [&'static str] = &["neon\0", "v7\0", "vfp2\0", "vfp3\0", "vfp4\0"];
82+
const ARM_WHITELIST: &'static [&'static str] = &["neon", "v7", "vfp2", "vfp3", "vfp4"];
8383

84-
const AARCH64_WHITELIST: &'static [&'static str] = &["neon\0", "v7\0"];
84+
const AARCH64_WHITELIST: &'static [&'static str] = &["neon", "v7"];
8585

86-
const X86_WHITELIST: &'static [&'static str] = &["avx\0", "avx2\0", "bmi\0", "bmi2\0", "sse\0",
87-
"sse2\0", "sse3\0", "sse4.1\0", "sse4.2\0",
88-
"ssse3\0", "tbm\0", "lzcnt\0", "popcnt\0",
89-
"sse4a\0", "rdrnd\0", "rdseed\0", "fma\0",
90-
"xsave\0", "xsaveopt\0", "xsavec\0",
91-
"xsaves\0", "aes\0",
92-
"avx512bw\0", "avx512cd\0",
93-
"avx512dq\0", "avx512er\0",
94-
"avx512f\0", "avx512ifma\0",
95-
"avx512pf\0", "avx512vbmi\0",
96-
"avx512vl\0", "avx512vpopcntdq\0",
97-
"mmx\0", "fxsr\0"];
86+
const X86_WHITELIST: &'static [&'static str] = &["avx", "avx2", "bmi", "bmi2", "sse",
87+
"sse2", "sse3", "sse4.1", "sse4.2",
88+
"ssse3", "tbm", "lzcnt", "popcnt",
89+
"sse4a", "rdrnd", "rdseed", "fma",
90+
"xsave", "xsaveopt", "xsavec",
91+
"xsaves", "aes", "pclmulqdq",
92+
"avx512bw", "avx512cd",
93+
"avx512dq", "avx512er",
94+
"avx512f", "avx512ifma",
95+
"avx512pf", "avx512vbmi",
96+
"avx512vl", "avx512vpopcntdq",
97+
"mmx", "fxsr"];
9898

99-
const HEXAGON_WHITELIST: &'static [&'static str] = &["hvx\0", "hvx-double\0"];
99+
const HEXAGON_WHITELIST: &'static [&'static str] = &["hvx", "hvx-double"];
100100

101-
const POWERPC_WHITELIST: &'static [&'static str] = &["altivec\0",
102-
"power8-altivec\0", "power9-altivec\0",
103-
"power8-vector\0", "power9-vector\0",
104-
"vsx\0"];
101+
const POWERPC_WHITELIST: &'static [&'static str] = &["altivec",
102+
"power8-altivec", "power9-altivec",
103+
"power8-vector", "power9-vector",
104+
"vsx"];
105105

106-
const MIPS_WHITELIST: &'static [&'static str] = &["msa\0"];
106+
const MIPS_WHITELIST: &'static [&'static str] = &["msa"];
107+
108+
pub fn to_llvm_feature(s: &str) -> &str {
109+
match s {
110+
"pclmulqdq" => "pclmul",
111+
s => s,
112+
}
113+
}
107114

108115
pub fn target_features(sess: &Session) -> Vec<Symbol> {
109-
let whitelist = target_feature_whitelist(sess);
110116
let target_machine = create_target_machine(sess);
111-
let mut features = Vec::new();
112-
for feat in whitelist {
113-
if unsafe { llvm::LLVMRustHasFeature(target_machine, feat.as_ptr()) } {
114-
features.push(Symbol::intern(feat.to_str().unwrap()));
115-
}
116-
}
117-
features
117+
target_feature_whitelist(sess)
118+
.iter()
119+
.filter(|feature| {
120+
let llvm_feature = to_llvm_feature(feature);
121+
let cstr = CString::new(llvm_feature).unwrap();
122+
unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) }
123+
})
124+
.map(|feature| Symbol::intern(feature)).collect()
118125
}
119126

120-
pub fn target_feature_whitelist(sess: &Session) -> Vec<&CStr> {
121-
let whitelist = match &*sess.target.target.arch {
127+
pub fn target_feature_whitelist(sess: &Session) -> &'static [&'static str] {
128+
match &*sess.target.target.arch {
122129
"arm" => ARM_WHITELIST,
123130
"aarch64" => AARCH64_WHITELIST,
124131
"x86" | "x86_64" => X86_WHITELIST,
125132
"hexagon" => HEXAGON_WHITELIST,
126133
"mips" | "mips64" => MIPS_WHITELIST,
127134
"powerpc" | "powerpc64" => POWERPC_WHITELIST,
128135
_ => &[],
129-
};
130-
whitelist.iter().map(|m| {
131-
CStr::from_bytes_with_nul(m.as_bytes()).unwrap()
132-
}).collect()
136+
}
133137
}
134138

135139
pub fn print_version() {

0 commit comments

Comments
 (0)