Skip to content

Commit d8aba28

Browse files
committed
More wasm SIMD updates
* Sync with the latest LLVM which has a few new intrinsic names * Move explicit tests back to `assert_instr` since `assert_instr` now supports specifying const-generic arguments inline. * Enable tests where wasmtime implements the instruction as well as LLVM. * Ensure there are tests for all functions that can be tested at this time (those that aren't unimplemented in wasmtime). There's still a number of `assert_instr` tests that are commented out. These are either because they're unimplemented in wasmtime at the moment or LLVM doesn't have an implementation for the instruction yet.
1 parent 37d9253 commit d8aba28

File tree

4 files changed

+1073
-433
lines changed

4 files changed

+1073
-433
lines changed

ci/docker/wasm32-wasi/Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
FROM rust:1.50.0
2+
3+
# Install wasmtime from source for now while the `experimental_x64` feature is
4+
# not yet the default. (it's not actually that experimental at the time of this
5+
# writing, wasmtime should switch defaults soon and the backend this enables has
6+
# better support for simd instructions)
7+
RUN \
8+
CARGO_INCREMENTAL=0 \
9+
CARGO_PROFILE_DEV_DEBUGINFO=0 \
10+
cargo install wasmtime-cli --features experimental_x64 --debug --vers 0.25.0 --locked
11+
112
FROM ubuntu:20.04
213

314
ENV DEBIAN_FRONTEND=noninteractive
415
RUN apt-get update -y && apt-get install -y --no-install-recommends \
516
ca-certificates \
6-
curl \
7-
xz-utils \
817
clang
918

10-
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.24.0/wasmtime-v0.24.0-x86_64-linux.tar.xz | tar xJf -
11-
ENV PATH=$PATH:/wasmtime-v0.24.0-x86_64-linux
19+
COPY --from=0 /usr/local/cargo/bin/wasmtime /usr/local/bin/wasmtime
1220

1321
ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime \
1422
--enable-simd \

ci/run.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ case ${TARGET} in
8787
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+avx"
8888
cargo_test "--release"
8989
;;
90-
wasm32*)
91-
# TODO: need to re-enable simd testing for wasm32
92-
# TODO: should enable atomics testing for wasm32
93-
# prev="$RUSTFLAGS"
94-
# export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+simd128,+unimplemented-simd128"
95-
# cargo_test "--release"
96-
# export RUSTFLAGS="$prev"
97-
;;
9890
# FIXME: don't build anymore
9991
#mips-*gnu* | mipsel-*gnu*)
10092
# export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+msa,+fp64,+mips32r5"

crates/core_arch/src/mod.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,13 @@ pub mod arch {
9292
/// The [simd proposal][simd] for WebAssembly adds a new `v128` type for a
9393
/// 128-bit SIMD register. It also adds a large array of instructions to
9494
/// operate on the `v128` type to perform data processing. The SIMD proposal
95-
/// has been in progress for quite some time and many instructions have come
96-
/// and gone. This module attempts to keep up with the proposal, but if you
97-
/// notice anything awry please feel free to [open an
95+
/// at the time of this writing is in [phase 4] which means that it's in the
96+
/// standardization phase. It's expected that once some testing on nightly
97+
/// has happened a stabilization proposal will be made for the Rust
98+
/// intrinsics. If you notice anything awry please feel free to [open an
9899
/// issue](https://github.com/rust-lang/stdarch/issues/new).
99100
///
100-
/// It's important to be aware that the current state of development of SIMD
101-
/// in WebAssembly is still somewhat early days. There's lots of pieces to
102-
/// demo and prototype with, but discussions and support are still in
103-
/// progress. There's a number of pitfalls and gotchas in various places,
104-
/// which will attempt to be documented here, but there may be others
105-
/// lurking!
101+
/// [phase 4]: https://github.com/webassembly/proposals
106102
///
107103
/// Using SIMD is intended to be similar to as you would on `x86_64`, for
108104
/// example. You'd write a function such as:
@@ -118,15 +114,17 @@ pub mod arch {
118114
///
119115
/// Unlike `x86_64`, however, WebAssembly does not currently have dynamic
120116
/// detection at runtime as to whether SIMD is supported (this is one of the
121-
/// motivators for the [conditional sections proposal][condsections], but
122-
/// that is still pretty early days). This means that your binary will
123-
/// either have SIMD and can only run on engines which support SIMD, or it
124-
/// will not have SIMD at all. For compatibility the standard library itself
125-
/// does not use any SIMD internally. Determining how best to ship your
126-
/// WebAssembly binary with SIMD is largely left up to you as it can can be
127-
/// pretty nuanced depending on your situation.
117+
/// motivators for the [conditional sections][condsections] and [feature
118+
/// detection] proposals, but that is still pretty early days). This means
119+
/// that your binary will either have SIMD and can only run on engines
120+
/// which support SIMD, or it will not have SIMD at all. For compatibility
121+
/// the standard library itself does not use any SIMD internally.
122+
/// Determining how best to ship your WebAssembly binary with SIMD is
123+
/// largely left up to you as it can can be pretty nuanced depending on
124+
/// your situation.
128125
///
129126
/// [condsections]: https://github.com/webassembly/conditional-sections
127+
/// [feature detection]: https://github.com/WebAssembly/feature-detection
130128
///
131129
/// To enable SIMD support at compile time you need to do one of two things:
132130
///
@@ -138,7 +136,9 @@ pub mod arch {
138136
/// * Second you can compile your program with `-Ctarget-feature=+simd128`.
139137
/// This compilation flag blanket enables SIMD support for your entire
140138
/// compilation. Note that this does not include the standard library
141-
/// unless you recompile the standard library.
139+
/// unless you [recompile the standard library][buildstd].
140+
///
141+
/// [buildstd]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std
142142
///
143143
/// If you enable SIMD via either of these routes then you'll have a
144144
/// WebAssembly binary that uses SIMD instructions, and you'll need to ship
@@ -147,21 +147,6 @@ pub mod arch {
147147
/// generated in your program. This means to generate a binary without SIMD
148148
/// you'll need to avoid both options above plus calling into any intrinsics
149149
/// in this module.
150-
///
151-
/// > **Note**: Due to
152-
/// > [rust-lang/rust#74320](https://github.com/rust-lang/rust/issues/74320)
153-
/// > it's recommended to compile your entire program with SIMD support
154-
/// > (using `RUSTFLAGS`) or otherwise functions may not be inlined
155-
/// > correctly.
156-
///
157-
/// > **Note**: LLVM's SIMD support is actually split into two features:
158-
/// > `simd128` and `unimplemented-simd128`. Rust code can enable `simd128`
159-
/// > with `#[target_feature]` (and test for it with `#[cfg(target_feature =
160-
/// > "simd128")]`, but it cannot enable `unimplemented-simd128`. The only
161-
/// > way to enable this feature is to compile with
162-
/// > `-Ctarget-feature=+simd128,+unimplemented-simd128`. This second
163-
/// > feature enables more recent instructions implemented in LLVM which
164-
/// > haven't always had enough time to make their way to runtimes.
165150
#[cfg(any(target_arch = "wasm32", doc))]
166151
#[doc(cfg(target_arch = "wasm32"))]
167152
#[stable(feature = "simd_wasm32", since = "1.33.0")]

0 commit comments

Comments
 (0)