fix crate::stdsimd
authorJacob Lifshay <programmerjake@gmail.com>
Mon, 10 May 2021 05:26:04 +0000 (22:26 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Mon, 10 May 2021 05:26:04 +0000 (22:26 -0700)
src/stdsimd.rs

index e1a389eb3b54d2258a6022167bd40c186ce3376e..3d757cc21b7a0dee350115ecd9e282f53174d98a 100644 (file)
@@ -2,8 +2,7 @@
 use crate::f16::panic_f16_feature_disabled;
 use crate::{
     f16::F16,
-    ieee754::FloatEncoding,
-    scalar,
+    prim::PrimFloat,
     traits::{
         Bool, Compare, Context, ConvertFrom, ConvertTo, Float, Int, Make, SInt, Select, UInt,
     },
@@ -566,10 +565,11 @@ macro_rules! impl_int_vector {
     };
 }
 
-macro_rules! impl_uint_vector {
-    ($ty:ident) => {
-        impl_int_vector!($ty);
-        impl<const LANES: usize> UInt for Wrapper<$ty<LANES>, LANES>
+macro_rules! impl_uint_sint_vector {
+    ($uint:ident, $sint:ident) => {
+        impl_int_vector!($uint);
+        impl_int_vector!($sint);
+        impl<const LANES: usize> UInt for Wrapper<$uint<LANES>, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -586,19 +586,11 @@ macro_rules! impl_uint_vector {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
+            type PrimUInt = Self::Prim;
+            type SignedType = Wrapper<$sint<LANES>, LANES>;
         }
-    };
-}
 
-impl_uint_vector!(SimdU8);
-impl_uint_vector!(SimdU16);
-impl_uint_vector!(SimdU32);
-impl_uint_vector!(SimdU64);
-
-macro_rules! impl_uint_scalar {
-    ($ty:ident) => {
-        impl_int_scalar!($ty);
-        impl<const LANES: usize> UInt for Wrapper<$ty, LANES>
+        impl<const LANES: usize> SInt for Wrapper<$sint<LANES>, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -615,19 +607,22 @@ macro_rules! impl_uint_scalar {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
+            type PrimSInt = Self::Prim;
+            type UnsignedType = Wrapper<$uint<LANES>, LANES>;
         }
     };
 }
 
-impl_uint_scalar!(u8);
-impl_uint_scalar!(u16);
-impl_uint_scalar!(u32);
-impl_uint_scalar!(u64);
+impl_uint_sint_vector!(SimdU8, SimdI8);
+impl_uint_sint_vector!(SimdU16, SimdI16);
+impl_uint_sint_vector!(SimdU32, SimdI32);
+impl_uint_sint_vector!(SimdU64, SimdI64);
 
-macro_rules! impl_sint_vector {
-    ($ty:ident) => {
-        impl_int_vector!($ty);
-        impl<const LANES: usize> SInt for Wrapper<$ty<LANES>, LANES>
+macro_rules! impl_uint_sint_scalar {
+    ($uint:ident, $sint:ident) => {
+        impl_int_scalar!($uint);
+        impl_int_scalar!($sint);
+        impl<const LANES: usize> UInt for Wrapper<$uint, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -644,19 +639,11 @@ macro_rules! impl_sint_vector {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
+            type PrimUInt = Self::Prim;
+            type SignedType = Wrapper<$sint, LANES>;
         }
-    };
-}
 
-impl_sint_vector!(SimdI8);
-impl_sint_vector!(SimdI16);
-impl_sint_vector!(SimdI32);
-impl_sint_vector!(SimdI64);
-
-macro_rules! impl_sint_scalar {
-    ($ty:ident) => {
-        impl_int_scalar!($ty);
-        impl<const LANES: usize> SInt for Wrapper<$ty, LANES>
+        impl<const LANES: usize> SInt for Wrapper<$sint, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -673,14 +660,16 @@ macro_rules! impl_sint_scalar {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
+            type PrimSInt = Self::Prim;
+            type UnsignedType = Wrapper<$uint, LANES>;
         }
     };
 }
 
-impl_sint_scalar!(i8);
-impl_sint_scalar!(i16);
-impl_sint_scalar!(i32);
-impl_sint_scalar!(i64);
+impl_uint_sint_scalar!(u8, i8);
+impl_uint_sint_scalar!(u16, i16);
+impl_uint_sint_scalar!(u32, i32);
+impl_uint_sint_scalar!(u64, i64);
 
 macro_rules! impl_float {
     ($ty:ident, $prim:ident, $uint:ident, $sint:ident) => {
@@ -701,11 +690,11 @@ macro_rules! impl_float {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
-            type FloatEncoding = $prim;
+            type PrimFloat = $prim;
 
-            type BitsType = Wrapper<<$prim as FloatEncoding>::BitsType, LANES>;
+            type BitsType = Wrapper<<$prim as PrimFloat>::BitsType, LANES>;
 
-            type SignedBitsType = Wrapper<<$prim as FloatEncoding>::SignedBitsType, LANES>;
+            type SignedBitsType = Wrapper<<$prim as PrimFloat>::SignedBitsType, LANES>;
 
             fn abs(self) -> Self {
                 self.0.abs().into()
@@ -729,9 +718,10 @@ macro_rules! impl_float {
 
             #[cfg(feature = "fma")]
             fn fma(self, a: Self, b: Self) -> Self {
-                let a = scalar::Value(a.0);
-                let b = scalar::Value(b.0);
-                scalar::Value(self.0).fma(a, b).0.into()
+                use crate::scalar::Value;
+                let a = Value(a.0);
+                let b = Value(b.0);
+                Value(self.0).fma(a, b).0.into()
             }
 
             fn is_finite(self) -> Self::Bool {
@@ -764,7 +754,7 @@ macro_rules! impl_float {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
-            type FloatEncoding = $prim;
+            type PrimFloat = $prim;
 
             type BitsType = Wrapper<$uint<LANES>, LANES>;