From 7fda54f9bc0838fcf4d93ac128eb020729bc633d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 23 Oct 2018 09:10:54 -0700 Subject: [PATCH] fix _mm_castsi128_pd and _mm_castpd_si128 impls (#581) * fix _mm_castsi128_pd and _mm_castpd_si128 impls The _mm_castX_Y SSE intrinsics are "reinterpreting" casts; LLVM's simd_cast is a "converting" cast. Replace simd_cast with mem::transmute. Fixes #55249 * Temporarily pin CI * Fix i686 segfaults * Fix wasm CI Output of `wasm2wat` has changed! * Fix AppVeyor with an older nightly --- library/stdarch/.appveyor.yml | 2 +- library/stdarch/.travis.yml | 6 ++++++ library/stdarch/ci/run.sh | 5 ++++- library/stdarch/coresimd/x86/sse2.rs | 4 ++-- library/stdarch/crates/stdsimd-test/Cargo.toml | 1 + library/stdarch/crates/stdsimd-test/src/lib.rs | 1 + library/stdarch/crates/stdsimd-test/src/wasm.rs | 3 ++- 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/library/stdarch/.appveyor.yml b/library/stdarch/.appveyor.yml index 65fc9aa4134a..1ee078630d45 100644 --- a/library/stdarch/.appveyor.yml +++ b/library/stdarch/.appveyor.yml @@ -10,7 +10,7 @@ environment: install: # Install rust, x86_64-pc-windows-msvc host - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly + - rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly-2018-10-20 - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - if NOT "%TARGET%" == "x86_64-pc-windows-msvc" rustup target add %TARGET% - rustc -vV diff --git a/library/stdarch/.travis.yml b/library/stdarch/.travis.yml index 6b2165245607..bf8be8eada64 100644 --- a/library/stdarch/.travis.yml +++ b/library/stdarch/.travis.yml @@ -6,9 +6,13 @@ matrix: fast_finish: true include: - env: TARGET=i586-unknown-linux-gnu + rust: nightly-2018-10-20 - env: TARGET=i686-unknown-linux-gnu + rust: nightly-2018-10-20 - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1 + rust: nightly-2018-10-20 - env: TARGET=x86_64-unknown-linux-gnu-emulated NO_ADD=1 STDSIMD_TEST_EVERYTHING=1 + rust: nightly-2018-10-20 - env: TARGET=x86_64-linux-android - env: TARGET=arm-unknown-linux-gnueabihf - env: TARGET=arm-linux-androideabi @@ -26,9 +30,11 @@ matrix: - os: osx env: TARGET=i686-apple-darwin script: ci/run.sh + rust: nightly-2018-10-20 - os: osx env: TARGET=x86_64-apple-darwin NO_ADD=1 script: ci/run.sh + rust: nightly-2018-10-20 - env: TARGET=wasm32-unknown-unknown - env: TARGET=thumbv6m-none-eabi NOSTD=1 - env: TARGET=thumbv7m-none-eabi NOSTD=1 diff --git a/library/stdarch/ci/run.sh b/library/stdarch/ci/run.sh index 8bc915d38ba0..edca35015b58 100755 --- a/library/stdarch/ci/run.sh +++ b/library/stdarch/ci/run.sh @@ -33,8 +33,11 @@ case ${TARGET} in # instruction assertion checks to pass below the 20 instruction limit. If # this is the default, dynamic, then too many instructions are generated # when we assert the instruction for a function and it causes tests to fail. + # + # It's not clear why `-Z plt=yes` is required here. Probably a bug in LLVM. + # If you can remove it and CI passes, please feel free to do so! i686-* | i586-*) - export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static" + export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static -Z plt=yes" ;; *android*) export STDSIMD_DISABLE_ASSERT_INSTR=1 diff --git a/library/stdarch/coresimd/x86/sse2.rs b/library/stdarch/coresimd/x86/sse2.rs index 1c1f8de52f5f..3a141aaaf99a 100644 --- a/library/stdarch/coresimd/x86/sse2.rs +++ b/library/stdarch/coresimd/x86/sse2.rs @@ -2787,7 +2787,7 @@ pub unsafe fn _mm_castpd_ps(a: __m128d) -> __m128 { #[target_feature(enable = "sse2")] #[stable(feature = "simd_x86", since = "1.27.0")] pub unsafe fn _mm_castpd_si128(a: __m128d) -> __m128i { - mem::transmute::(simd_cast(a)) + mem::transmute(a) } /// Casts a 128-bit floating-point vector of `[4 x float]` into a 128-bit @@ -2820,7 +2820,7 @@ pub unsafe fn _mm_castps_si128(a: __m128) -> __m128i { #[target_feature(enable = "sse2")] #[stable(feature = "simd_x86", since = "1.27.0")] pub unsafe fn _mm_castsi128_pd(a: __m128i) -> __m128d { - simd_cast(a.as_i64x2()) + mem::transmute(a) } /// Casts a 128-bit integer vector into a 128-bit floating-point vector diff --git a/library/stdarch/crates/stdsimd-test/Cargo.toml b/library/stdarch/crates/stdsimd-test/Cargo.toml index cb2b0a661462..60b0b72ef8ea 100644 --- a/library/stdarch/crates/stdsimd-test/Cargo.toml +++ b/library/stdarch/crates/stdsimd-test/Cargo.toml @@ -14,6 +14,7 @@ cfg-if = "0.1" [target.wasm32-unknown-unknown.dependencies] wasm-bindgen = "=0.2.19" +console_error_panic_hook = "0.1" [features] default = [] diff --git a/library/stdarch/crates/stdsimd-test/src/lib.rs b/library/stdarch/crates/stdsimd-test/src/lib.rs index c7200b0bbc30..9b33073b96c5 100644 --- a/library/stdarch/crates/stdsimd-test/src/lib.rs +++ b/library/stdarch/crates/stdsimd-test/src/lib.rs @@ -26,6 +26,7 @@ use std::{collections::HashMap, env, str}; cfg_if! { if #[cfg(target_arch = "wasm32")] { extern crate wasm_bindgen; + extern crate console_error_panic_hook; pub mod wasm; use wasm::disassemble_myself; } else { diff --git a/library/stdarch/crates/stdsimd-test/src/wasm.rs b/library/stdarch/crates/stdsimd-test/src/wasm.rs index cc0cf8788836..c3eac5fbaee7 100644 --- a/library/stdarch/crates/stdsimd-test/src/wasm.rs +++ b/library/stdarch/crates/stdsimd-test/src/wasm.rs @@ -33,6 +33,7 @@ macro_rules! println { pub(crate) fn disassemble_myself() -> HashMap> { use std::path::Path; + ::console_error_panic_hook::set_once(); // Our wasm module in the wasm-bindgen test harness is called // "wasm-bindgen-test_bg". When running in node this is actually a shim JS // file. Ask node where that JS file is, and then we use that with a wasm @@ -51,7 +52,7 @@ pub(crate) fn disassemble_myself() -> HashMap> { // If we found the table of function pointers, fill in the known // address for all our `Function` instances if line.starts_with("(elem") { - for (i, name) in line.split_whitespace().skip(3).enumerate() { + for (i, name) in line.split_whitespace().skip(4).enumerate() { let name = name.trim_right_matches(")"); for f in ret.get_mut(name).expect("ret.get_mut(name) failed") { f.addr = Some(i + 1);