From 870607d0c78308a4cbb426648d559fc5562cf9ec Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 2 Feb 2022 18:14:16 -0800 Subject: [PATCH 1/2] Delete outmoded fn round_from_int --- crates/core_simd/src/round.rs | 7 ------- crates/core_simd/tests/round.rs | 8 -------- 2 files changed, 15 deletions(-) diff --git a/crates/core_simd/src/round.rs b/crates/core_simd/src/round.rs index 06ccab3ec49..08339593600 100644 --- a/crates/core_simd/src/round.rs +++ b/crates/core_simd/src/round.rs @@ -22,13 +22,6 @@ macro_rules! implement { pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> { unsafe { 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: Simd<$int_type, LANES>) -> Self { - unsafe { intrinsics::simd_cast(value) } - } } } } diff --git a/crates/core_simd/tests/round.rs b/crates/core_simd/tests/round.rs index 1a1bc9ebca7..90547d5782c 100644 --- a/crates/core_simd/tests/round.rs +++ b/crates/core_simd/tests/round.rs @@ -53,14 +53,6 @@ macro_rules! float_rounding_test { } test_helpers::test_lanes! { - fn from_int() { - test_helpers::test_unary_elementwise( - &Vector::::round_from_int, - &|x| x as Scalar, - &|_| true, - ) - } - fn to_int_unchecked() { // The maximum integer that can be represented by the equivalently sized float has // all of the mantissa digits set to 1, pushed up to the MSB. From cadb30f96680c680955470e37c51b1e3f0bdddc4 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 2 Feb 2022 18:21:12 -0800 Subject: [PATCH 2/2] Genericize to_int_unchecked --- crates/core_simd/src/lib.rs | 1 + crates/core_simd/src/round.rs | 15 ++++++++++----- crates/core_simd/tests/round.rs | 6 +++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index 960a6640083..41f64e972d9 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![feature( const_fn_trait_bound, + convert_float_to_int, decl_macro, platform_intrinsics, repr_simd, diff --git a/crates/core_simd/src/round.rs b/crates/core_simd/src/round.rs index 08339593600..f1724cbc263 100644 --- a/crates/core_simd/src/round.rs +++ b/crates/core_simd/src/round.rs @@ -1,9 +1,10 @@ use crate::simd::intrinsics; -use crate::simd::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; +use core::convert::FloatToInt; macro_rules! implement { { - $type:ty, $int_type:ty + $type:ty } => { impl Simd<$type, LANES> where @@ -19,12 +20,16 @@ macro_rules! implement { /// * Not be infinite /// * Be representable in the return type, after truncating off its fractional part #[inline] - pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> { + pub unsafe fn to_int_unchecked(self) -> Simd + where + $type: FloatToInt, + I: SimdElement, + { unsafe { intrinsics::simd_cast(self) } } } } } -implement! { f32, i32 } -implement! { f64, i64 } +implement! { f32 } +implement! { f64 } diff --git a/crates/core_simd/tests/round.rs b/crates/core_simd/tests/round.rs index 90547d5782c..53732329237 100644 --- a/crates/core_simd/tests/round.rs +++ b/crates/core_simd/tests/round.rs @@ -64,11 +64,11 @@ macro_rules! float_rounding_test { runner.run( &test_helpers::array::UniformArrayStrategy::new(-MAX_REPRESENTABLE_VALUE..MAX_REPRESENTABLE_VALUE), |x| { - let result_1 = unsafe { Vector::from_array(x).to_int_unchecked().to_array() }; + let result_1 = unsafe { Vector::from_array(x).to_int_unchecked::().to_array() }; let result_2 = { - let mut result = [0; LANES]; + let mut result: [IntScalar; LANES] = [0; LANES]; for (i, o) in x.iter().zip(result.iter_mut()) { - *o = unsafe { i.to_int_unchecked() }; + *o = unsafe { i.to_int_unchecked::() }; } result };