From 7538ff810aa683a0c3694f20e749dee4a6469f39 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 30 Nov 2020 12:39:26 -0800 Subject: [PATCH 1/3] Revert "Disable riscv64gc" This reverts commit 3ad356d90268e5dd3236f460422df6136e9d0e11. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d331257692..2104c74a4d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,8 +121,7 @@ jobs: # for NaNs which makes it worth testing on despite that. - mips-unknown-linux-gnu - mips64-unknown-linux-gnuabi64 - # TODO: reenable pending https://github.com/rust-lang/rust/issues/77866 - # - riscv64gc-unknown-linux-gnu + - riscv64gc-unknown-linux-gnu steps: - uses: actions/checkout@v2 From e9cc3066a82941a15ceb60de7a55e0c163c25b2c Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 30 Nov 2020 12:49:37 -0800 Subject: [PATCH 2/3] Remove round, trunc tests There are no platform intrinsics in the rustc for these functions yet, so this removes them as a distinct commit for later reversion. --- .../core_simd/tests/ops_impl/float_macros.rs | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/crates/core_simd/tests/ops_impl/float_macros.rs b/crates/core_simd/tests/ops_impl/float_macros.rs index 1f49aef9f12..fe347a5362d 100644 --- a/crates/core_simd/tests/ops_impl/float_macros.rs +++ b/crates/core_simd/tests/ops_impl/float_macros.rs @@ -353,42 +353,6 @@ fn floor_odd_floats() { } } - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn round_odd_floats() { - for v in slice_chunks(&C) { - let expected = apply_unary_lanewise(v, <$scalar>::round); - assert_biteq!(v.round(), expected); - } - } - - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn round_mode() { - assert_biteq!(core_simd::$vector::splat(1.5).round(), core_simd::$vector::splat(2.0)); - assert_biteq!(core_simd::$vector::splat(2.5).round(), core_simd::$vector::splat(3.0)); - assert_biteq!(core_simd::$vector::splat(-1.5).round(), core_simd::$vector::splat(-2.0)); - assert_biteq!(core_simd::$vector::splat(-2.5).round(), core_simd::$vector::splat(-3.0)); - } - - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn trunc_odd_floats() { - for v in slice_chunks(&C) { - let expected = apply_unary_lanewise(v, <$scalar>::trunc); - assert_biteq!(v.trunc(), expected); - } - } - - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn fract_odd_floats() { - for v in slice_chunks(&C) { - let expected = apply_unary_lanewise(v, <$scalar>::fract); - assert_biteq!(v.fract(), expected); - } - } - #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn to_int_unchecked() { From 3d9bbf9b86f9f41d9ea5fe649343f3d763003866 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 30 Nov 2020 12:52:30 -0800 Subject: [PATCH 3/3] Use simd_{floor,ceil} intrinsics for round.rs --- crates/core_simd/src/intrinsics.rs | 6 +++ crates/core_simd/src/round.rs | 85 ++++-------------------------- 2 files changed, 16 insertions(+), 75 deletions(-) diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index acf85983a98..b2edc3747ef 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -39,4 +39,10 @@ /// fptoui/fptosi/uitofp/sitofp pub(crate) fn simd_cast(x: T) -> U; + + // floor + pub(crate) fn simd_floor(x: T) -> T; + + // ceil + pub(crate) fn simd_ceil(x: T) -> T; } diff --git a/crates/core_simd/src/round.rs b/crates/core_simd/src/round.rs index 021e5af8873..0529bbe0080 100644 --- a/crates/core_simd/src/round.rs +++ b/crates/core_simd/src/round.rs @@ -1,60 +1,23 @@ macro_rules! implement { { impl $type:ident { - int_type = $int_type:ident, - floor = $floor_intrinsic:literal, - ceil = $ceil_intrinsic:literal, - round = $round_intrinsic:literal, - trunc = $trunc_intrinsic:literal, + int_type = $int_type:ident } } => { mod $type { - #[allow(improper_ctypes)] - extern "C" { - #[link_name = $floor_intrinsic] - fn floor_intrinsic(x: crate::$type) -> crate::$type; - #[link_name = $ceil_intrinsic] - fn ceil_intrinsic(x: crate::$type) -> crate::$type; - #[link_name = $round_intrinsic] - fn round_intrinsic(x: crate::$type) -> crate::$type; - #[link_name = $trunc_intrinsic] - fn trunc_intrinsic(x: crate::$type) -> crate::$type; - } - impl crate::$type { /// Returns the largest integer less than or equal to each lane. #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn floor(self) -> Self { - unsafe { floor_intrinsic(self) } + unsafe { crate::intrinsics::simd_floor(self) } } /// Returns the smallest integer greater than or equal to each lane. #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn ceil(self) -> Self { - unsafe { ceil_intrinsic(self) } - } - - /// Returns the nearest integer to each lane. Round half-way cases away from 0.0. - #[must_use = "method returns a new vector and does not mutate the original value"] - #[inline] - pub fn round(self) -> Self { - unsafe { round_intrinsic(self) } - } - - /// Returns the integer part of each lane. - #[must_use = "method returns a new vector and does not mutate the original value"] - #[inline] - pub fn trunc(self) -> Self { - unsafe { trunc_intrinsic(self) } - } - - /// Returns the fractional part of each lane. - #[must_use = "method returns a new vector and does not mutate the original value"] - #[inline] - pub fn fract(self) -> Self { - self - self.trunc() + unsafe { crate::intrinsics::simd_ceil(self) } } /// Rounds toward zero and converts to the same-width integer type, assuming that @@ -84,70 +47,42 @@ pub fn round_from_int(value: crate::$int_type) -> Self { implement! { impl f32x2 { - int_type = i32x2, - floor = "llvm.floor.v2f32", - ceil = "llvm.ceil.v2f32", - round = "llvm.round.v2f32", - trunc = "llvm.trunc.v2f32", + int_type = i32x2 } } implement! { impl f32x4 { - int_type = i32x4, - floor = "llvm.floor.v4f32", - ceil = "llvm.ceil.v4f32", - round = "llvm.round.v4f32", - trunc = "llvm.trunc.v4f32", + int_type = i32x4 } } implement! { impl f32x8 { - int_type = i32x8, - floor = "llvm.floor.v8f32", - ceil = "llvm.ceil.v8f32", - round = "llvm.round.v8f32", - trunc = "llvm.trunc.v8f32", + int_type = i32x8 } } implement! { impl f32x16 { - int_type = i32x16, - floor = "llvm.floor.v16f32", - ceil = "llvm.ceil.v16f32", - round = "llvm.round.v16f32", - trunc = "llvm.trunc.v16f32", + int_type = i32x16 } } implement! { impl f64x2 { - int_type = i64x2, - floor = "llvm.floor.v2f64", - ceil = "llvm.ceil.v2f64", - round = "llvm.round.v2f64", - trunc = "llvm.trunc.v2f64", + int_type = i64x2 } } implement! { impl f64x4 { - int_type = i64x4, - floor = "llvm.floor.v4f64", - ceil = "llvm.ceil.v4f64", - round = "llvm.round.v4f64", - trunc = "llvm.trunc.v4f64", + int_type = i64x4 } } implement! { impl f64x8 { - int_type = i64x8, - floor = "llvm.floor.v8f64", - ceil = "llvm.ceil.v8f64", - round = "llvm.round.v8f64", - trunc = "llvm.trunc.v8f64", + int_type = i64x8 } }