about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2020-12-14 00:07:36 -0500
committerCaleb Zulawski <caleb.zulawski@gmail.com>2020-12-14 00:07:36 -0500
commit0ddf7acc89d414d12c4fc04c90cf208c78fd8d5e (patch)
tree9a88f9b31c75afa3a04976992a7ace3de51583da
parent9cc3deaa9256060868bb952ea5f850a910633f19 (diff)
downloadrust-0ddf7acc89d414d12c4fc04c90cf208c78fd8d5e.tar.gz
rust-0ddf7acc89d414d12c4fc04c90cf208c78fd8d5e.zip
Reenable rounding ops
-rw-r--r--crates/core_simd/src/lib.rs2
-rw-r--r--crates/core_simd/src/round.rs111
-rw-r--r--crates/core_simd/tests/ops_impl/float_macros.rs3
3 files changed, 35 insertions, 81 deletions
diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs
index 9d4ce683f22..312a3237e23 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 0529bbe0080..d77bc4e8fa7 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<const LANES: usize> crate::$type<LANES> {
+            /// 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<LANES> {
+                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<LANES>) -> 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 a46367d0cc2..fe347a5362d 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);
                 }
             }
-            */
         }
     }
 }