Skip to content

Commit

Permalink
Rollup merge of rust-lang#117468 - daxpedda:wasm-relaxed-simd, r=alex…
Browse files Browse the repository at this point in the history
…crichton

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: rust-lang#111196
Implementation PR: rust-lang/stdarch#1393
Documentation: rust-lang/reference#1421
Stdarch: rust-lang/stdarch#1494

Closes rust-lang#111196.
  • Loading branch information
tgross35 authored Jul 31, 2024
2 parents 99322d8 + 61d95e2 commit 4ffdd2a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 23 deletions.
16 changes: 16 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,22 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
}
}

// This is a workaround for a LLVM bug that doesn't implicitly enable
// `simd128` when `relaxed-simd` is.
// See <https://github.com/llvm/llvm-project/pull/99803>, which didn't make
// it into a released version of LLVM yet.
//
// This doesn't use the "implicit target feature" system because it is only
// used for function attributes in other targets, which fixes this bug as
// well on the function attribute level.
if sess.target.families.contains(&"wasm".into()) {
if features.iter().any(|f| f == "+relaxed-simd")
&& !features.iter().any(|f| f == "+simd128")
{
features.push("+simd128".into());
}
}

if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
features: f,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ pub fn from_target_feature(
Some(Symbol::intern(feature))
}));
}

for (feature, requires) in tcx.sess.target.implicit_target_features() {
if target_features.iter().any(|f| f.as_str() == *feature)
&& !target_features.iter().any(|f| f.as_str() == *requires)
{
target_features.push(Symbol::intern(requires));
}
}
}

/// Computes the set of target features used in a function for the purposes of
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,14 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability)] = &[
("mutable-globals", Stable),
("nontrapping-fptoint", Stable),
("reference-types", Unstable(sym::wasm_target_feature)),
("relaxed-simd", Unstable(sym::wasm_target_feature)),
("relaxed-simd", Stable),
("sign-ext", Stable),
("simd128", Stable),
// tidy-alphabetical-end
];

const WASM_IMPLICIT_FEATURES: &[(&str, &str)] = &[("relaxed-simd", "simd128")];

const BPF_ALLOWED_FEATURES: &[(&str, Stability)] = &[("alu32", Unstable(sym::bpf_target_feature))];

const CSKY_ALLOWED_FEATURES: &[(&str, Stability)] = &[
Expand Down Expand Up @@ -452,4 +454,13 @@ impl super::spec::Target {
_ => &[],
}
}

/// Returns a list of target features. Each items first target feature
/// implicitly enables the second one.
pub fn implicit_target_features(&self) -> &'static [(&'static str, &'static str)] {
match &*self.arch {
"wasm32" | "wasm64" => WASM_IMPLICIT_FEATURES,
_ => &[],
}
}
}
2 changes: 1 addition & 1 deletion library/stdarch
Submodule stdarch updated 91 files
+8 −16 .github/workflows/main.yml
+1 −1 ci/docker/aarch64-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/arm-unknown-linux-gnueabihf/Dockerfile
+1 −1 ci/docker/i586-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/i686-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/mips-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile
+1 −1 ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile
+1 −1 ci/docker/mipsel-unknown-linux-musl/Dockerfile
+1 −1 ci/docker/nvptx64-nvidia-cuda/Dockerfile
+1 −1 ci/docker/powerpc-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/powerpc64-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/riscv64gc-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/s390x-unknown-linux-gnu/Dockerfile
+1 −1 ci/docker/wasm32-wasip1/Dockerfile
+7 −6 ci/docker/x86_64-unknown-linux-gnu-emulated/Dockerfile
+61 −0 ci/docker/x86_64-unknown-linux-gnu-emulated/cpuid.def
+1 −1 ci/docker/x86_64-unknown-linux-gnu/Dockerfile
+0 −764 crates/core_arch/avx512bw.md
+0 −2,633 crates/core_arch/avx512f.md
+1,270 −0 crates/core_arch/missing-x86.md
+2 −1 crates/core_arch/src/lib.rs
+12 −0 crates/core_arch/src/mod.rs
+17 −17 crates/core_arch/src/powerpc/altivec.rs
+139 −0 crates/core_arch/src/simd.rs
+1 −1 crates/core_arch/src/wasm32/mod.rs
+70 −30 crates/core_arch/src/wasm32/relaxed_simd.rs
+17 −47 crates/core_arch/src/wasm32/simd128.rs
+9 −3 crates/core_arch/src/x86/adx.rs
+133 −48 crates/core_arch/src/x86/avx.rs
+55 −65 crates/core_arch/src/x86/avx2.rs
+356 −1 crates/core_arch/src/x86/avx512bf16.rs
+19 −36 crates/core_arch/src/x86/avx512bitalg.rs
+3,264 −1,749 crates/core_arch/src/x86/avx512bw.rs
+6 −20 crates/core_arch/src/x86/avx512cd.rs
+10,701 −0 crates/core_arch/src/x86/avx512dq.rs
+3,385 −2,350 crates/core_arch/src/x86/avx512f.rs
+557 −26 crates/core_arch/src/x86/avx512ifma.rs
+49 −121 crates/core_arch/src/x86/avx512vbmi2.rs
+876 −0 crates/core_arch/src/x86/avx512vnni.rs
+19 −42 crates/core_arch/src/x86/avx512vpopcntdq.rs
+253 −0 crates/core_arch/src/x86/avxneconvert.rs
+20 −0 crates/core_arch/src/x86/bmi1.rs
+8 −0 crates/core_arch/src/x86/bt.rs
+0 −86 crates/core_arch/src/x86/cpuid.rs
+8 −0 crates/core_arch/src/x86/f16c.rs
+78 −89 crates/core_arch/src/x86/fma.rs
+1 −1 crates/core_arch/src/x86/fxsr.rs
+21 −21 crates/core_arch/src/x86/gfni.rs
+30 −0 crates/core_arch/src/x86/macros.rs
+34 −5 crates/core_arch/src/x86/mod.rs
+1 −5 crates/core_arch/src/x86/pclmulqdq.rs
+4 −4 crates/core_arch/src/x86/rtm.rs
+21 −45 crates/core_arch/src/x86/sse.rs
+169 −40 crates/core_arch/src/x86/sse2.rs
+31 −10 crates/core_arch/src/x86/sse41.rs
+61 −3 crates/core_arch/src/x86/sse4a.rs
+20 −255 crates/core_arch/src/x86/tbm.rs
+4 −16 crates/core_arch/src/x86/test.rs
+10 −31 crates/core_arch/src/x86/xsave.rs
+9 −3 crates/core_arch/src/x86_64/adx.rs
+21 −1 crates/core_arch/src/x86_64/avx.rs
+0 −48 crates/core_arch/src/x86_64/avx2.rs
+45 −0 crates/core_arch/src/x86_64/avx512bw.rs
+698 −85 crates/core_arch/src/x86_64/avx512f.rs
+8 −0 crates/core_arch/src/x86_64/bt.rs
+1 −1 crates/core_arch/src/x86_64/fxsr.rs
+6 −2 crates/core_arch/src/x86_64/mod.rs
+11 −9 crates/core_arch/src/x86_64/sse2.rs
+1 −1 crates/core_arch/src/x86_64/sse41.rs
+225 −0 crates/core_arch/src/x86_64/tbm.rs
+11 −23 crates/core_arch/src/x86_64/xsave.rs
+184 −86 crates/std_detect/src/detect/arch/aarch64.rs
+41 −0 crates/std_detect/src/detect/arch/x86.rs
+19 −11 crates/std_detect/src/detect/cache.rs
+190 −8 crates/std_detect/src/detect/os/linux/aarch64.rs
+39 −12 crates/std_detect/src/detect/os/x86.rs
+0 −4 crates/std_detect/src/lib.rs
+53 −0 crates/std_detect/tests/cpu-detection.rs
+1 −0 crates/std_detect/tests/macro_trailing_commas.rs
+45 −19 crates/std_detect/tests/x86-specific.rs
+14 −26 crates/stdarch-gen-arm/src/main.rs
+23 −29 crates/stdarch-test/src/disassembly.rs
+2 −2 crates/stdarch-test/src/lib.rs
+1 −1 crates/stdarch-verify/Cargo.toml
+24 −1 crates/stdarch-verify/src/lib.rs
+1 −0 crates/stdarch-verify/tests/arm.rs
+2 −1 crates/stdarch-verify/tests/mips.rs
+221 −228 crates/stdarch-verify/tests/x86-intel.rs
+178,389 −147,738 crates/stdarch-verify/x86-intel.xml
21 changes: 0 additions & 21 deletions tests/codegen/simd/issue-120720-reduce-nan.rs

This file was deleted.

9 changes: 9 additions & 0 deletions tests/ui/target-feature/implicit-features-cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ only-wasm32-wasip1
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
//@ build-pass

use std::arch::wasm32::*;

pub fn test(a: v128, b: v128, m: v128) -> v128 {
i64x2_relaxed_laneselect(a, b, m)
}
10 changes: 10 additions & 0 deletions tests/ui/target-feature/implicit-features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ only-wasm32-wasip1
//@ compile-flags: --crate-type=lib
//@ build-pass

use std::arch::wasm32::*;

#[target_feature(enable = "relaxed-simd")]
pub fn test(a: v128, b: v128, m: v128) -> v128 {
i64x2_relaxed_laneselect(a, b, m)
}
9 changes: 9 additions & 0 deletions tests/ui/target-feature/wasm-relaxed-simd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ only-wasm32-wasip1
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
//@ build-pass

use std::arch::wasm32::*;

pub fn test(a: v128, b: v128, m: v128) -> v128 {
i64x2_relaxed_laneselect(a, b, m)
}

0 comments on commit 4ffdd2a

Please sign in to comment.