Skip to content

Commit 9467185

Browse files
gnzlbgalexcrichton
authored andcommitted
Add wasm32 simd128 intrinsics (#549)
* Add wasm32 simd128 intrinsics * test wasm32 simd128 instructions * Run wasm tests like all other tests * use modules instead of types to access wasm simd128 interpretations * generate docs for wasm32-unknown-unknown * fix typo * Enable #[assert_instr] on wasm32 * Shell out to Node's `execSync` to execute `wasm2wat` over our wasm file * Parse the wasm file line-by-line, looking for various function markers and such * Use the `elem` section to build a function pointer table, allowing us to map exactly from function pointer to a function * Avoid losing debug info (the names section) in release mode by stripping `--strip-debug` from `rust-lld`. * remove exclude list from Cargo.toml * fix assert_instr for non-wasm targets * re-format assert-instr changes * add crate that uses assert_instr * Fix instructions having extra quotes * Add assert_instr for wasm memory intrinsics * Remove hacks for git wasm-bindgen * add wasm_simd128 feature * make wasm32 build correctly * run simd128 tests on ci * remove wasm-assert-instr-tests
1 parent d05795a commit 9467185

File tree

17 files changed

+1684
-60
lines changed

17 files changed

+1684
-60
lines changed

.travis.yml

-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ matrix:
3030
env: TARGET=x86_64-apple-darwin NO_ADD=1
3131
script: ci/run.sh
3232
- env: TARGET=wasm32-unknown-unknown
33-
before_script:
34-
- git clone --recursive https://github.com/WebAssembly/wabt
35-
- (cd wabt && git reset --hard a0bdeb7 && make -j4)
36-
- export PATH=$PATH:$PWD/wabt/bin
37-
script:
38-
- cargo build --target wasm32-unknown-unknown -p stdsimd
39-
- cargo build --target wasm32-unknown-unknown -p stdsimd --release
40-
- cargo rustc --target wasm32-unknown-unknown -p stdsimd --release --example wasm -- -C lto
41-
- wasm2wat target/wasm32-unknown-unknown/release/examples/wasm.wasm -o wasm.wat
42-
- cat wasm.wat
43-
- grep current_memory wasm.wat
44-
- grep grow_memory wasm.wat
4533
- env: TARGET=thumbv6m-none-eabi NOSTD=1
4634
- env: TARGET=thumbv7m-none-eabi NOSTD=1
4735
- env: TARGET=thumbv7em-none-eabi NOSTD=1

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ members = [
33
"crates/stdsimd-verify",
44
"crates/stdsimd",
55
]
6+
exclude = [
7+
"crates/wasm-assert-instr-tests"
8+
]
69

710
[profile.release]
811
debug = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
ca-certificates \
5+
clang \
6+
cmake \
7+
curl \
8+
git \
9+
libc6-dev \
10+
make \
11+
python \
12+
xz-utils
13+
14+
# Install `wasm2wat`
15+
RUN git clone --recursive https://github.com/WebAssembly/wabt
16+
RUN make -C wabt -j$(nproc)
17+
ENV PATH=$PATH:/wabt/bin
18+
19+
# Install `wasm-bindgen-test-runner`
20+
RUN curl -L https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.16/wasm-bindgen-0.2.16-x86_64-unknown-linux-musl.tar.gz \
21+
| tar xzf -
22+
ENV PATH=$PATH:/wasm-bindgen-0.2.16-x86_64-unknown-linux-musl
23+
ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner
24+
25+
# Install `node`
26+
RUN curl https://nodejs.org/dist/v10.8.0/node-v10.8.0-linux-x64.tar.xz | tar xJf -
27+
ENV PATH=$PATH:/node-v10.8.0-linux-x64/bin
28+
29+
# We use a shim linker that removes `--strip-debug` when passed to LLD. While
30+
# this typically results in invalid debug information in release mode it doesn't
31+
# result in an invalid names section which is what we're interested in.
32+
COPY lld-shim.rs /
33+
ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER=/tmp/lld-shim
34+
35+
# Rustc isn't available until this container starts, so defer compilation of the
36+
# shim.
37+
ENTRYPOINT /rust/bin/rustc /lld-shim.rs -o /tmp/lld-shim && exec bash "$@"

ci/dox.sh

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dox aarch64 aarch64-unknown-linux-gnu
4444
dox powerpc64le powerpc64le-unknown-linux-gnu
4545
dox mips mips-unknown-linux-gnu
4646
dox mips64 mips64-unknown-linux-gnuabi64
47+
dox wasm32 wasm32-unknown-unknown
4748

4849
# If we're on travis, not a PR, and on the right branch, publish!
4950
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then

ci/lld-shim.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::os::unix::prelude::*;
2+
use std::process::Command;
3+
use std::env;
4+
5+
fn main() {
6+
let args = env::args()
7+
.skip(1)
8+
.filter(|s| s != "--strip-debug")
9+
.collect::<Vec<_>>();
10+
panic!("failed to exec: {}", Command::new("rust-lld").args(&args).exec());
11+
}

ci/run-docker.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ run() {
1313
--user `id -u`:`id -g` \
1414
--rm \
1515
--init \
16-
--volume $HOME/.cargo:/cargo \
17-
--env CARGO_HOME=/cargo \
16+
--volume $HOME/.cargo:/cargo-h \
17+
--env CARGO_HOME=/cargo-h \
1818
--volume `rustc --print sysroot`:/rust:ro \
1919
--env TARGET=$target \
2020
--env STDSIMD_TEST_EVERYTHING \
@@ -25,7 +25,7 @@ run() {
2525
--privileged \
2626
stdsimd \
2727
bash \
28-
-c 'PATH=$PATH:/rust/bin exec ci/run.sh'
28+
-c 'PATH=/rust/bin:$PATH exec ci/run.sh'
2929
}
3030

3131
if [ -z "$1" ]; then

ci/run.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ cargo_test() {
5959
cargo_test
6060
cargo_test "--release"
6161

62-
# Test x86 targets compiled with AVX.
62+
# Test targets compiled with extra features.
6363
case ${TARGET} in
6464
x86*)
6565
RUSTFLAGS="${RUSTFLAGS} -C target-feature=+avx"
6666
export STDSIMD_DISABLE_ASSERT_INSTR=1
6767
cargo_test "--release"
6868
;;
69+
wasm32-unknown-unknown*)
70+
# export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+simd128"
71+
cargo_test "--release --features=wasm_simd128"
72+
;;
6973
*)
7074
;;
7175
esac

coresimd/simd_llvm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ extern "platform-intrinsic" {
5151
pub fn simd_select<M, T>(m: M, a: T, b: T) -> T;
5252

5353
pub fn simd_fmin<T>(a: T, b: T) -> T;
54-
// FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/416
55-
// pub fn simd_fmax<T>(a: T, b: T) -> T;
54+
pub fn simd_fmax<T>(a: T, b: T) -> T;
5655

5756
pub fn simd_fsqrt<T>(a: T) -> T;
5857
pub fn simd_fma<T>(a: T, b: T, c: T) -> T;

coresimd/wasm32.rs renamed to coresimd/wasm32/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
//! WASM32 intrinsics
2+
3+
4+
#[macro_use]
5+
#[cfg(all(not(test), feature = "wasm_simd128"))]
6+
mod simd128;
7+
8+
#[cfg(all(test, feature = "wasm_simd128"))]
9+
pub mod simd128;
10+
#[cfg(all(test, feature = "wasm_simd128"))]
11+
pub use self::simd128::*;
12+
13+
#[cfg(test)]
14+
use stdsimd_test::assert_instr;
15+
#[cfg(test)]
16+
use wasm_bindgen_test::wasm_bindgen_test;
17+
118
extern "C" {
219
#[link_name = "llvm.wasm.grow.memory.i32"]
320
fn llvm_grow_memory(pages: i32) -> i32;
@@ -12,6 +29,7 @@ extern "C" {
1229
///
1330
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
1431
#[inline]
32+
#[cfg_attr(test, assert_instr("memory.size"))]
1533
pub unsafe fn current_memory() -> i32 {
1634
llvm_current_memory()
1735
}
@@ -25,6 +43,7 @@ pub unsafe fn current_memory() -> i32 {
2543
///
2644
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
2745
#[inline]
46+
#[cfg_attr(test, assert_instr("memory.grow"))]
2847
pub unsafe fn grow_memory(delta: i32) -> i32 {
2948
llvm_grow_memory(delta)
3049
}

0 commit comments

Comments
 (0)