From dd0150888d24cdd85f267453956934b35018b8e8 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sat, 13 Feb 2021 16:25:56 -0800 Subject: [PATCH 01/12] Uncommented bitmask code --- crates/core_arch/src/wasm32/simd128.rs | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/core_arch/src/wasm32/simd128.rs b/crates/core_arch/src/wasm32/simd128.rs index bb8e238a91..5eb922f158 100644 --- a/crates/core_arch/src/wasm32/simd128.rs +++ b/crates/core_arch/src/wasm32/simd128.rs @@ -1452,14 +1452,14 @@ pub unsafe fn i8x16_all_true(a: v128) -> i32 { llvm_i8x16_all_true(a.as_i8x16()) } -// FIXME: not available in our LLVM yet -// /// Extracts the high bit for each lane in `a` and produce a scalar mask with -// /// all bits concatenated. -// #[inline] -// #[cfg_attr(test, assert_instr(i8x16.all_true))] -// pub unsafe fn i8x16_bitmask(a: v128) -> i32 { -// llvm_bitmask_i8x16(transmute(a)) -// } +/// Extracts the high bit for each lane in `a` and produce a scalar mask with +/// all bits concatenated. +#[inline] +#[cfg_attr(test, assert_instr(i8x16.bitmask))] +#[target_feature(enable = "simd128")] +pub unsafe fn i8x16_bitmask(a: v128) -> i32 { + llvm_bitmask_i8x16(transmute(a)) +} /// Converts two input vectors into a smaller lane vector by narrowing each /// lane. @@ -1662,14 +1662,14 @@ pub unsafe fn i16x8_all_true(a: v128) -> i32 { llvm_i16x8_all_true(a.as_i16x8()) } -// FIXME: not available in our LLVM yet -// /// Extracts the high bit for each lane in `a` and produce a scalar mask with -// /// all bits concatenated. -// #[inline] -// #[cfg_attr(test, assert_instr(i16x8.all_true))] -// pub unsafe fn i16x8_bitmask(a: v128) -> i32 { -// llvm_bitmask_i16x8(transmute(a)) -// } +/// Extracts the high bit for each lane in `a` and produce a scalar mask with +/// all bits concatenated. +#[inline] +#[cfg_attr(test, assert_instr(i16x8.bitmask))] +#[target_feature(enable = "simd128")] +pub unsafe fn i16x8_bitmask(a: v128) -> i32 { + llvm_bitmask_i16x8(transmute(a)) +} /// Converts two input vectors into a smaller lane vector by narrowing each /// lane. @@ -1913,14 +1913,14 @@ pub unsafe fn i32x4_all_true(a: v128) -> i32 { llvm_i32x4_all_true(a.as_i32x4()) } -// FIXME: not available in our LLVM yet -// /// Extracts the high bit for each lane in `a` and produce a scalar mask with -// /// all bits concatenated. -// #[inline] -// #[cfg_attr(test, assert_instr(i32x4.all_true))] -// pub unsafe fn i32x4_bitmask(a: v128) -> i32 { -// llvm_bitmask_i32x4(transmute(a)) -// } +/// Extracts the high bit for each lane in `a` and produce a scalar mask with +/// all bits concatenated. +#[inline] +#[cfg_attr(test, assert_instr(i32x4.bitmask))] +#[target_feature(enable = "simd128")] +pub unsafe fn i32x4_bitmask(a: v128) -> i32 { + llvm_bitmask_i32x4(transmute(a)) +} /// Converts low half of the smaller lane vector to a larger lane /// vector, sign extended. From eadc9c972380fb2bcb37a5c5878a9c5a75abf0dc Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sat, 13 Feb 2021 19:06:24 -0800 Subject: [PATCH 02/12] Added i64x2 bitmask and some tests --- crates/core_arch/src/wasm32/simd128.rs | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/crates/core_arch/src/wasm32/simd128.rs b/crates/core_arch/src/wasm32/simd128.rs index 5eb922f158..858b2be0b0 100644 --- a/crates/core_arch/src/wasm32/simd128.rs +++ b/crates/core_arch/src/wasm32/simd128.rs @@ -2125,6 +2125,15 @@ pub unsafe fn i64x2_mul(a: v128, b: v128) -> v128 { transmute(simd_mul(a.as_i64x2(), b.as_i64x2())) } +/// Extracts the high bit for each lane in `a` and produce a scalar mask with +/// all bits concatenated. +#[inline] +#[cfg_attr(test, assert_instr(i64x2.bitmask))] +#[target_feature(enable = "simd128")] +pub unsafe fn i64x2_bitmask(a: v128) -> i32 { + llvm_bitmask_i64x2(transmute(a)) +} + /// Calculates the absolute value of each lane of a 128-bit vector interpreted /// as four 32-bit floating point numbers. #[inline] @@ -2806,6 +2815,46 @@ pub mod tests { } } + #[test] + fn test_bitmask_ops() { + unsafe { + let a: [u32; 4] = [u32::MAX, 0, u32::MAX, 0]; + let b: [u32; 4] = [u32::MAX; 4]; + let c: [u32; 4] = [0; 4]; + + let vec_a: v128 = transmute(a); + let vec_b: v128 = transmute(b); + let vec_c: v128 = transmute(c); + + let r: i32 = i8x16_bitmask(vec_a); + assert_eq!(r, 0b1111000011110000); + let r: i32 = i16x8_bitmask(vec_a); + assert_eq!(r, 0b11001100); + let r: i32 = i32x4_bitmask(vec_a); + assert_eq!(r, 0b1010); + let r: i32 = i64x2_bitmask(vec_a); + assert_eq!(r, 0b11); + + let r: i32 = i8x16_bitmask(vec_b); + assert_eq!(r, 0xFFFF); + let r: i32 = i16x8_bitmask(vec_b); + assert_eq!(r, 0xFF); + let r: i32 = i32x4_bitmask(vec_b); + assert_eq!(r, 0xF); + let r: i32 = i64x2_bitmask(vec_b); + assert_eq!(r, 0b11); + + let r: i32 = i8x16_bitmask(vec_c); + assert_eq!(r, 0); + let r: i32 = i16x8_bitmask(vec_c); + assert_eq!(r, 0); + let r: i32 = i32x4_bitmask(vec_c); + assert_eq!(r, 0); + let r: i32 = i64x2_bitmask(vec_c); + assert_eq!(r, 0); + } + } + macro_rules! test_bool_red { ([$test_id:ident, $any:ident, $all:ident] | [$($true:expr),*] | [$($false:expr),*] | [$($alt:expr),*]) => { #[test] From 5f283f3a01f68d251278c2d32e90ae2a07c84088 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sat, 13 Feb 2021 19:21:54 -0800 Subject: [PATCH 03/12] Fixed error with i64x2 bitmask --- crates/core_arch/src/wasm32/simd128.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/core_arch/src/wasm32/simd128.rs b/crates/core_arch/src/wasm32/simd128.rs index 858b2be0b0..a5761b3675 100644 --- a/crates/core_arch/src/wasm32/simd128.rs +++ b/crates/core_arch/src/wasm32/simd128.rs @@ -190,6 +190,9 @@ extern "C" { fn llvm_widen_low_i32x4_u(a: i16x8) -> i32x4; #[link_name = "llvm.wasm.widen.high.unsigned.v4i32.v8i16"] fn llvm_widen_high_i32x4_u(a: i16x8) -> i32x4; + + #[link_name = "llvm.wasm.bitmask.v2i64"] + fn llvm_bitmask_i64x2(a: i64x2) -> i32; } /// Loads a `v128` vector from the given heap address. From d47c42352294361a6284c688ebfd4bd7d47cbda6 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sat, 13 Feb 2021 19:44:25 -0800 Subject: [PATCH 04/12] Removed a couple of other FIXME comments --- crates/core_arch/src/wasm32/simd128.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/core_arch/src/wasm32/simd128.rs b/crates/core_arch/src/wasm32/simd128.rs index a5761b3675..c56c3876ba 100644 --- a/crates/core_arch/src/wasm32/simd128.rs +++ b/crates/core_arch/src/wasm32/simd128.rs @@ -1419,7 +1419,7 @@ pub unsafe fn v128_bitselect(v1: v128, v2: v128, c: v128) -> v128 { /// Lane-wise wrapping absolute value. #[inline] -// #[cfg_attr(test, assert_instr(i8x16.abs))] // FIXME support not in our LLVM yet +#[cfg_attr(test, assert_instr(i8x16.abs))] #[target_feature(enable = "simd128")] pub unsafe fn i8x16_abs(a: v128) -> v128 { let a = transmute::<_, i8x16>(a); @@ -1629,7 +1629,7 @@ pub unsafe fn i8x16_avgr_u(a: v128, b: v128) -> v128 { /// Lane-wise wrapping absolute value. #[inline] -// #[cfg_attr(test, assert_instr(i16x8.abs))] // FIXME support not in our LLVM yet +#[cfg_attr(test, assert_instr(i16x8.abs))] #[target_feature(enable = "simd128")] pub unsafe fn i16x8_abs(a: v128) -> v128 { let a = transmute::<_, i16x8>(a); @@ -1880,7 +1880,7 @@ pub unsafe fn i16x8_avgr_u(a: v128, b: v128) -> v128 { /// Lane-wise wrapping absolute value. #[inline] -// #[cfg_attr(test, assert_instr(i32x4.abs))] // FIXME support not in our LLVM yet +#[cfg_attr(test, assert_instr(i32x4.abs))] #[target_feature(enable = "simd128")] pub unsafe fn i32x4_abs(a: v128) -> v128 { let a = transmute::<_, i32x4>(a); @@ -2122,7 +2122,7 @@ pub unsafe fn i64x2_sub(a: v128, b: v128) -> v128 { /// Multiplies two 128-bit vectors as if they were two packed two 64-bit integers. #[inline] -// #[cfg_attr(test, assert_instr(i64x2.mul))] // FIXME: not present in our LLVM +#[cfg_attr(test, assert_instr(i64x2.mul))] #[target_feature(enable = "simd128")] pub unsafe fn i64x2_mul(a: v128, b: v128) -> v128 { transmute(simd_mul(a.as_i64x2(), b.as_i64x2())) From fa32c0295214d96040d27f312db2e8fda57472d0 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 17:22:46 -0800 Subject: [PATCH 05/12] Debugging --- crates/core_arch/src/wasm32/simd128.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/core_arch/src/wasm32/simd128.rs b/crates/core_arch/src/wasm32/simd128.rs index c56c3876ba..db19c2e78e 100644 --- a/crates/core_arch/src/wasm32/simd128.rs +++ b/crates/core_arch/src/wasm32/simd128.rs @@ -191,8 +191,8 @@ extern "C" { #[link_name = "llvm.wasm.widen.high.unsigned.v4i32.v8i16"] fn llvm_widen_high_i32x4_u(a: i16x8) -> i32x4; - #[link_name = "llvm.wasm.bitmask.v2i64"] - fn llvm_bitmask_i64x2(a: i64x2) -> i32; + //#[link_name = "llvm.wasm.bitmask.v2i64"] + //fn llvm_bitmask_i64x2(a: i64x2) -> i32; } /// Loads a `v128` vector from the given heap address. @@ -2128,14 +2128,14 @@ pub unsafe fn i64x2_mul(a: v128, b: v128) -> v128 { transmute(simd_mul(a.as_i64x2(), b.as_i64x2())) } -/// Extracts the high bit for each lane in `a` and produce a scalar mask with +/*/// Extracts the high bit for each lane in `a` and produce a scalar mask with /// all bits concatenated. #[inline] #[cfg_attr(test, assert_instr(i64x2.bitmask))] #[target_feature(enable = "simd128")] pub unsafe fn i64x2_bitmask(a: v128) -> i32 { llvm_bitmask_i64x2(transmute(a)) -} +}*/ /// Calculates the absolute value of each lane of a 128-bit vector interpreted /// as four 32-bit floating point numbers. @@ -2835,8 +2835,8 @@ pub mod tests { assert_eq!(r, 0b11001100); let r: i32 = i32x4_bitmask(vec_a); assert_eq!(r, 0b1010); - let r: i32 = i64x2_bitmask(vec_a); - assert_eq!(r, 0b11); + /*let r: i32 = i64x2_bitmask(vec_a); + assert_eq!(r, 0b11);*/ let r: i32 = i8x16_bitmask(vec_b); assert_eq!(r, 0xFFFF); @@ -2844,8 +2844,8 @@ pub mod tests { assert_eq!(r, 0xFF); let r: i32 = i32x4_bitmask(vec_b); assert_eq!(r, 0xF); - let r: i32 = i64x2_bitmask(vec_b); - assert_eq!(r, 0b11); + /*let r: i32 = i64x2_bitmask(vec_b); + assert_eq!(r, 0b11);*/ let r: i32 = i8x16_bitmask(vec_c); assert_eq!(r, 0); @@ -2853,8 +2853,8 @@ pub mod tests { assert_eq!(r, 0); let r: i32 = i32x4_bitmask(vec_c); assert_eq!(r, 0); - let r: i32 = i64x2_bitmask(vec_c); - assert_eq!(r, 0); + /*let r: i32 = i64x2_bitmask(vec_c); + assert_eq!(r, 0);*/ } } From da3f76cb8a7020dee6f18ee04eed8d2d47eedd1f Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 17:57:10 -0800 Subject: [PATCH 06/12] Try wasmer --- ci/docker/wasm32-wasi/Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index eca3f61c70..b80c01e4f5 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -7,10 +7,18 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ xz-utils \ clang -RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/wasmtime-v0.22.1-x86_64-linux.tar.xz | tar xJf - -ENV PATH=$PATH:/wasmtime-v0.22.1-x86_64-linux +RUN curl https://get.wasmer.io -sSfL | sh -ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime \ +ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ + --llvm \ --enable-simd \ --mapdir .::/checkout/target/wasm32-wasi/release/deps \ --" + +#RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/wasmtime-v0.22.1-x86_64-linux.tar.xz | tar xJf - +#ENV PATH=$PATH:/wasmtime-v0.22.1-x86_64-linux + +#ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime \ +# --enable-simd \ +# --mapdir .::/checkout/target/wasm32-wasi/release/deps \ +# --" From dd3e91d743f72e4942f5a62585a23a73733829e9 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 18:11:18 -0800 Subject: [PATCH 07/12] Try wasmer again --- ci/docker/wasm32-wasi/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index b80c01e4f5..9f31767e4f 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -9,6 +9,8 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ RUN curl https://get.wasmer.io -sSfL | sh +RUN source /root/.wasmer/wasmer.sh + ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ --llvm \ --enable-simd \ From 652452249fffd514506848d68237d1678307092e Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 18:26:18 -0800 Subject: [PATCH 08/12] Try wasmer again again --- ci/docker/wasm32-wasi/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index 9f31767e4f..7bc48c7b53 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ RUN curl https://get.wasmer.io -sSfL | sh -RUN source /root/.wasmer/wasmer.sh +ENV PATH="$PATH:/root/.wasmer:/root/.wasmer/bin" ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ --llvm \ From 2fd61118303c7cabe2a5dec8f59e760e6b2608e3 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 18:47:02 -0800 Subject: [PATCH 09/12] Wasmer just work please --- ci/docker/wasm32-wasi/Dockerfile | 3 +-- ci/run.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index 7bc48c7b53..094af4b4dc 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -14,8 +14,7 @@ ENV PATH="$PATH:/root/.wasmer:/root/.wasmer/bin" ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ --llvm \ --enable-simd \ - --mapdir .::/checkout/target/wasm32-wasi/release/deps \ - --" + --mapdir .::/checkout/target/wasm32-wasi/release/deps" #RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/wasmtime-v0.22.1-x86_64-linux.tar.xz | tar xJf - #ENV PATH=$PATH:/wasmtime-v0.22.1-x86_64-linux diff --git a/ci/run.sh b/ci/run.sh index 699c89cecb..1be2448629 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -52,7 +52,7 @@ cargo_test() { # output. case ${TARGET} in wasm32*) - cmd="$cmd --nocapture" + cmd="$cmd -- --nocapture" ;; esac From 58c170ff6a629ee820e79f1893b0a92b0467d535 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 18:57:31 -0800 Subject: [PATCH 10/12] Wasmer plz --- ci/docker/wasm32-wasi/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index 094af4b4dc..52bf538566 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -7,9 +7,11 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ xz-utils \ clang +ENV WASMER_DIR="/.wasmer" + RUN curl https://get.wasmer.io -sSfL | sh -ENV PATH="$PATH:/root/.wasmer:/root/.wasmer/bin" +ENV PATH="$PATH:/.wasmer:/.wasmer/bin" ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ --llvm \ From 89cd23e3098c842144d38a4cb7262151a787232f Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 19:08:34 -0800 Subject: [PATCH 11/12] Try try again --- ci/docker/wasm32-wasi/Dockerfile | 3 ++- ci/run.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index 52bf538566..38ee9a0c5c 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -16,7 +16,8 @@ ENV PATH="$PATH:/.wasmer:/.wasmer/bin" ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ --llvm \ --enable-simd \ - --mapdir .::/checkout/target/wasm32-wasi/release/deps" + --mapdir .::/checkout/target/wasm32-wasi/release/deps \ + --" #RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/wasmtime-v0.22.1-x86_64-linux.tar.xz | tar xJf - #ENV PATH=$PATH:/wasmtime-v0.22.1-x86_64-linux diff --git a/ci/run.sh b/ci/run.sh index 1be2448629..699c89cecb 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -52,7 +52,7 @@ cargo_test() { # output. case ${TARGET} in wasm32*) - cmd="$cmd -- --nocapture" + cmd="$cmd --nocapture" ;; esac From 42c39a452b485c56ca24509dabcd7922a9e05c50 Mon Sep 17 00:00:00 2001 From: c0deb0t Date: Sun, 14 Feb 2021 20:20:28 -0800 Subject: [PATCH 12/12] Try latest wasmtime release --- ci/docker/wasm32-wasi/Dockerfile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile index 38ee9a0c5c..392294ed48 100644 --- a/ci/docker/wasm32-wasi/Dockerfile +++ b/ci/docker/wasm32-wasi/Dockerfile @@ -7,22 +7,22 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ xz-utils \ clang -ENV WASMER_DIR="/.wasmer" +#ENV WASMER_DIR="/.wasmer" -RUN curl https://get.wasmer.io -sSfL | sh +#RUN curl https://get.wasmer.io -sSfL | sh -ENV PATH="$PATH:/.wasmer:/.wasmer/bin" +#ENV PATH="$PATH:/.wasmer:/.wasmer/bin" -ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ - --llvm \ - --enable-simd \ - --mapdir .::/checkout/target/wasm32-wasi/release/deps \ - --" - -#RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/wasmtime-v0.22.1-x86_64-linux.tar.xz | tar xJf - -#ENV PATH=$PATH:/wasmtime-v0.22.1-x86_64-linux - -#ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime \ +#ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmer run \ +# --llvm \ # --enable-simd \ # --mapdir .::/checkout/target/wasm32-wasi/release/deps \ # --" + +RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz | tar xJf - +ENV PATH=$PATH:/wasmtime-dev-x86_64-linux + +ENV CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime \ + --enable-simd \ + --mapdir .::/checkout/target/wasm32-wasi/release/deps \ + --"