Skip to content

Commit

Permalink
Add wasm32 simd128 intrinsics (#549)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gnzlbg authored and alexcrichton committed Aug 15, 2018
1 parent d05795a commit 9467185
Show file tree
Hide file tree
Showing 17 changed files with 1,684 additions and 60 deletions.
12 changes: 0 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ matrix:
env: TARGET=x86_64-apple-darwin NO_ADD=1
script: ci/run.sh
- env: TARGET=wasm32-unknown-unknown
before_script:
- git clone --recursive https://github.com/WebAssembly/wabt
- (cd wabt && git reset --hard a0bdeb7 && make -j4)
- export PATH=$PATH:$PWD/wabt/bin
script:
- cargo build --target wasm32-unknown-unknown -p stdsimd
- cargo build --target wasm32-unknown-unknown -p stdsimd --release
- cargo rustc --target wasm32-unknown-unknown -p stdsimd --release --example wasm -- -C lto
- wasm2wat target/wasm32-unknown-unknown/release/examples/wasm.wasm -o wasm.wat
- cat wasm.wat
- grep current_memory wasm.wat
- grep grow_memory wasm.wat
- env: TARGET=thumbv6m-none-eabi NOSTD=1
- env: TARGET=thumbv7m-none-eabi NOSTD=1
- env: TARGET=thumbv7em-none-eabi NOSTD=1
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ members = [
"crates/stdsimd-verify",
"crates/stdsimd",
]
exclude = [
"crates/wasm-assert-instr-tests"
]

[profile.release]
debug = true
Expand Down
37 changes: 37 additions & 0 deletions ci/docker/wasm32-unknown-unknown/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:18.04

RUN apt-get update -y && apt-get install -y --no-install-recommends \
ca-certificates \
clang \
cmake \
curl \
git \
libc6-dev \
make \
python \
xz-utils

# Install `wasm2wat`
RUN git clone --recursive https://github.com/WebAssembly/wabt
RUN make -C wabt -j$(nproc)
ENV PATH=$PATH:/wabt/bin

# Install `wasm-bindgen-test-runner`
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 \
| tar xzf -
ENV PATH=$PATH:/wasm-bindgen-0.2.16-x86_64-unknown-linux-musl
ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner

# Install `node`
RUN curl https://nodejs.org/dist/v10.8.0/node-v10.8.0-linux-x64.tar.xz | tar xJf -
ENV PATH=$PATH:/node-v10.8.0-linux-x64/bin

# We use a shim linker that removes `--strip-debug` when passed to LLD. While
# this typically results in invalid debug information in release mode it doesn't
# result in an invalid names section which is what we're interested in.
COPY lld-shim.rs /
ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER=/tmp/lld-shim

# Rustc isn't available until this container starts, so defer compilation of the
# shim.
ENTRYPOINT /rust/bin/rustc /lld-shim.rs -o /tmp/lld-shim && exec bash "$@"
1 change: 1 addition & 0 deletions ci/dox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dox aarch64 aarch64-unknown-linux-gnu
dox powerpc64le powerpc64le-unknown-linux-gnu
dox mips mips-unknown-linux-gnu
dox mips64 mips64-unknown-linux-gnuabi64
dox wasm32 wasm32-unknown-unknown

# If we're on travis, not a PR, and on the right branch, publish!
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
Expand Down
11 changes: 11 additions & 0 deletions ci/lld-shim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::os::unix::prelude::*;
use std::process::Command;
use std::env;

fn main() {
let args = env::args()
.skip(1)
.filter(|s| s != "--strip-debug")
.collect::<Vec<_>>();
panic!("failed to exec: {}", Command::new("rust-lld").args(&args).exec());
}
6 changes: 3 additions & 3 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ run() {
--user `id -u`:`id -g` \
--rm \
--init \
--volume $HOME/.cargo:/cargo \
--env CARGO_HOME=/cargo \
--volume $HOME/.cargo:/cargo-h \
--env CARGO_HOME=/cargo-h \
--volume `rustc --print sysroot`:/rust:ro \
--env TARGET=$target \
--env STDSIMD_TEST_EVERYTHING \
Expand All @@ -25,7 +25,7 @@ run() {
--privileged \
stdsimd \
bash \
-c 'PATH=$PATH:/rust/bin exec ci/run.sh'
-c 'PATH=/rust/bin:$PATH exec ci/run.sh'
}

if [ -z "$1" ]; then
Expand Down
6 changes: 5 additions & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ cargo_test() {
cargo_test
cargo_test "--release"

# Test x86 targets compiled with AVX.
# Test targets compiled with extra features.
case ${TARGET} in
x86*)
RUSTFLAGS="${RUSTFLAGS} -C target-feature=+avx"
export STDSIMD_DISABLE_ASSERT_INSTR=1
cargo_test "--release"
;;
wasm32-unknown-unknown*)
# export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+simd128"
cargo_test "--release --features=wasm_simd128"
;;
*)
;;
esac
3 changes: 1 addition & 2 deletions coresimd/simd_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ extern "platform-intrinsic" {
pub fn simd_select<M, T>(m: M, a: T, b: T) -> T;

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

pub fn simd_fsqrt<T>(a: T) -> T;
pub fn simd_fma<T>(a: T, b: T, c: T) -> T;
Expand Down
19 changes: 19 additions & 0 deletions coresimd/wasm32.rs → coresimd/wasm32/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
//! WASM32 intrinsics

#[macro_use]
#[cfg(all(not(test), feature = "wasm_simd128"))]
mod simd128;

#[cfg(all(test, feature = "wasm_simd128"))]
pub mod simd128;
#[cfg(all(test, feature = "wasm_simd128"))]
pub use self::simd128::*;

#[cfg(test)]
use stdsimd_test::assert_instr;
#[cfg(test)]
use wasm_bindgen_test::wasm_bindgen_test;

extern "C" {
#[link_name = "llvm.wasm.grow.memory.i32"]
fn llvm_grow_memory(pages: i32) -> i32;
Expand All @@ -12,6 +29,7 @@ extern "C" {
///
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
#[inline]
#[cfg_attr(test, assert_instr("memory.size"))]
pub unsafe fn current_memory() -> i32 {
llvm_current_memory()
}
Expand All @@ -25,6 +43,7 @@ pub unsafe fn current_memory() -> i32 {
///
/// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
#[inline]
#[cfg_attr(test, assert_instr("memory.grow"))]
pub unsafe fn grow_memory(delta: i32) -> i32 {
llvm_grow_memory(delta)
}
Loading

0 comments on commit 9467185

Please sign in to comment.