From 0ddf7acc89d414d12c4fc04c90cf208c78fd8d5e Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Mon, 14 Dec 2020 00:07:36 -0500 Subject: [PATCH] Reenable rounding ops --- crates/core_simd/src/lib.rs | 2 +- crates/core_simd/src/round.rs | 111 ++++++------------ .../core_simd/tests/ops_impl/float_macros.rs | 3 - 3 files changed, 35 insertions(+), 81 deletions(-) diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index 9d4ce683f22a..312a3237e232 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -9,7 +9,7 @@ mod macros; mod fmt; mod intrinsics; mod ops; -//mod round; +mod round; mod masks; pub use masks::*; diff --git a/crates/core_simd/src/round.rs b/crates/core_simd/src/round.rs index 0529bbe0080c..d77bc4e8fa7e 100644 --- a/crates/core_simd/src/round.rs +++ b/crates/core_simd/src/round.rs @@ -1,88 +1,45 @@ macro_rules! implement { { - impl $type:ident { - int_type = $int_type:ident - } + $type:ident, $int_type:ident } => { - mod $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 { crate::intrinsics::simd_floor(self) } - } + 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 { 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 { crate::intrinsics::simd_ceil(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 { crate::intrinsics::simd_ceil(self) } + } - /// Rounds toward zero and converts to the same-width integer type, assuming that - /// the value is finite and fits in that type. - /// - /// # Safety - /// The value must: - /// - /// * Not be NaN - /// * Not be infinite - /// * Be representable in the return type, after truncating off its fractional part - #[inline] - pub unsafe fn to_int_unchecked(self) -> crate::$int_type { - crate::intrinsics::simd_cast(self) - } + /// Rounds toward zero and converts to the same-width integer type, assuming that + /// the value is finite and fits in that type. + /// + /// # Safety + /// The value must: + /// + /// * Not be NaN + /// * Not be infinite + /// * Be representable in the return type, after truncating off its fractional part + #[inline] + pub unsafe fn to_int_unchecked(self) -> crate::$int_type { + crate::intrinsics::simd_cast(self) + } - /// Creates a floating-point vector from an integer vector. Rounds values that are - /// not exactly representable. - #[inline] - pub fn round_from_int(value: crate::$int_type) -> Self { - unsafe { crate::intrinsics::simd_cast(value) } - } + /// Creates a floating-point vector from an integer vector. Rounds values that are + /// not exactly representable. + #[inline] + pub fn round_from_int(value: crate::$int_type) -> Self { + unsafe { crate::intrinsics::simd_cast(value) } } } } } -implement! { - impl f32x2 { - int_type = i32x2 - } -} - -implement! { - impl f32x4 { - int_type = i32x4 - } -} - -implement! { - impl f32x8 { - int_type = i32x8 - } -} - -implement! { - impl f32x16 { - int_type = i32x16 - } -} - -implement! { - impl f64x2 { - int_type = i64x2 - } -} - -implement! { - impl f64x4 { - int_type = i64x4 - } -} - -implement! { - impl f64x8 { - int_type = i64x8 - } -} +implement! { SimdF32, SimdI32 } +implement! { SimdF64, SimdI64 } diff --git a/crates/core_simd/tests/ops_impl/float_macros.rs b/crates/core_simd/tests/ops_impl/float_macros.rs index a46367d0cc2f..fe347a5362da 100644 --- a/crates/core_simd/tests/ops_impl/float_macros.rs +++ b/crates/core_simd/tests/ops_impl/float_macros.rs @@ -335,8 +335,6 @@ macro_rules! float_tests { } } - // TODO reenable after converting float ops to platform intrinsics - /* #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn ceil_odd_floats() { @@ -415,7 +413,6 @@ macro_rules! float_tests { assert_biteq!(core_simd::$vector::round_from_int(v), expected); } } - */ } } }