Skip to content

Commit 9179d9b

Browse files
committed
Auto merge of #117468 - daxpedda:wasm-relaxed-simd, r=alexcrichton
Stabilize Wasm relaxed SIMD This PR stabilizes [Wasm relaxed SIMD](https://github.com/WebAssembly/relaxed-simd) which has already reached [phase 4](https://github.com/WebAssembly/proposals/tree/04fa8c810e1dc99ab399e41052a6e427ee988180?tab=readme-ov-file#phase-4---standardize-the-feature-wg). Tracking issue: #111196 Implementation PR: rust-lang/stdarch#1393 Documentation: rust-lang/reference#1421 Stdarch: rust-lang/stdarch#1494 Closes #111196.
2 parents 4d48a6b + 80b74d3 commit 9179d9b

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+16
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,22 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
646646
}
647647
}
648648

649+
// This is a workaround for a LLVM bug that doesn't implicitly enable
650+
// `simd128` when `relaxed-simd` is.
651+
// See <https://github.com/llvm/llvm-project/pull/99803>, which didn't make
652+
// it into a released version of LLVM yet.
653+
//
654+
// This doesn't use the "implicit target feature" system because it is only
655+
// used for function attributes in other targets, which fixes this bug as
656+
// well on the function attribute level.
657+
if sess.target.families.contains(&"wasm".into()) {
658+
if features.iter().any(|f| f == "+relaxed-simd")
659+
&& !features.iter().any(|f| f == "+simd128")
660+
{
661+
features.push("+simd128".into());
662+
}
663+
}
664+
649665
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
650666
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
651667
features: f,

compiler/rustc_codegen_ssa/src/target_features.rs

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ pub fn from_target_feature(
9797
Some(Symbol::intern(feature))
9898
}));
9999
}
100+
101+
for (feature, requires) in tcx.sess.target.implicit_target_features() {
102+
if target_features.iter().any(|f| f.as_str() == *feature)
103+
&& !target_features.iter().any(|f| f.as_str() == *requires)
104+
{
105+
target_features.push(Symbol::intern(requires));
106+
}
107+
}
100108
}
101109

102110
/// Computes the set of target features used in a function for the purposes of

compiler/rustc_target/src/target_features.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,14 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability)] = &[
333333
("mutable-globals", Stable),
334334
("nontrapping-fptoint", Stable),
335335
("reference-types", Unstable(sym::wasm_target_feature)),
336-
("relaxed-simd", Unstable(sym::wasm_target_feature)),
336+
("relaxed-simd", Stable),
337337
("sign-ext", Stable),
338338
("simd128", Stable),
339339
// tidy-alphabetical-end
340340
];
341341

342+
const WASM_IMPLICIT_FEATURES: &[(&str, &str)] = &[("relaxed-simd", "simd128")];
343+
342344
const BPF_ALLOWED_FEATURES: &[(&str, Stability)] = &[("alu32", Unstable(sym::bpf_target_feature))];
343345

344346
const CSKY_ALLOWED_FEATURES: &[(&str, Stability)] = &[
@@ -455,4 +457,13 @@ impl super::spec::Target {
455457
_ => &[],
456458
}
457459
}
460+
461+
/// Returns a list of target features. Each items first target feature
462+
/// implicitly enables the second one.
463+
pub fn implicit_target_features(&self) -> &'static [(&'static str, &'static str)] {
464+
match &*self.arch {
465+
"wasm32" | "wasm64" => WASM_IMPLICIT_FEATURES,
466+
_ => &[],
467+
}
468+
}
458469
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ only-wasm32-wasip1
2+
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
3+
//@ build-pass
4+
5+
use std::arch::wasm32::*;
6+
7+
pub fn test(a: v128, b: v128, m: v128) -> v128 {
8+
i64x2_relaxed_laneselect(a, b, m)
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ only-wasm32-wasip1
2+
//@ compile-flags: --crate-type=lib
3+
//@ build-pass
4+
5+
use std::arch::wasm32::*;
6+
7+
#[target_feature(enable = "relaxed-simd")]
8+
pub fn test(a: v128, b: v128, m: v128) -> v128 {
9+
i64x2_relaxed_laneselect(a, b, m)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ only-wasm32-wasip1
2+
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
3+
//@ build-pass
4+
5+
use std::arch::wasm32::*;
6+
7+
pub fn test(a: v128, b: v128, m: v128) -> v128 {
8+
i64x2_relaxed_laneselect(a, b, m)
9+
}

0 commit comments

Comments
 (0)