add sin_pi_f16, cos_pi_f16, and sin_cos_pi_f16
[vector-math.git] / src / stdsimd.rs
index b691f7c1e0ed7ca30f58fff6faca48d595863614..e1a389eb3b54d2258a6022167bd40c186ce3376e 100644 (file)
@@ -2,7 +2,11 @@
 use crate::f16::panic_f16_feature_disabled;
 use crate::{
     f16::F16,
-    traits::{Bool, Compare, Context, ConvertTo, Float, Int, Make, SInt, Select, UInt},
+    ieee754::FloatEncoding,
+    scalar,
+    traits::{
+        Bool, Compare, Context, ConvertFrom, ConvertTo, Float, Int, Make, SInt, Select, UInt,
+    },
 };
 use core::{
     marker::PhantomData,
@@ -293,7 +297,11 @@ where
     Mask64<LANES>: Mask,
 {
     fn select(self, true_v: V, false_v: V) -> V {
-        self.0.select(true_v, false_v)
+        if self.0 {
+            true_v
+        } else {
+            false_v
+        }
     }
 }
 
@@ -319,27 +327,27 @@ macro_rules! impl_scalar_compare {
             type Bool = Wrapper<bool, LANES>;
 
             fn eq(self, rhs: Self) -> Self::Bool {
-                self.0.eq(rhs.0).into()
+                self.0.eq(&rhs.0).into()
             }
 
             fn ne(self, rhs: Self) -> Self::Bool {
-                self.0.ne(rhs.0).into()
+                self.0.ne(&rhs.0).into()
             }
 
             fn lt(self, rhs: Self) -> Self::Bool {
-                self.0.lt(rhs.0).into()
+                self.0.lt(&rhs.0).into()
             }
 
             fn gt(self, rhs: Self) -> Self::Bool {
-                self.0.gt(rhs.0).into()
+                self.0.gt(&rhs.0).into()
             }
 
             fn le(self, rhs: Self) -> Self::Bool {
-                self.0.le(rhs.0).into()
+                self.0.le(&rhs.0).into()
             }
 
             fn ge(self, rhs: Self) -> Self::Bool {
-                self.0.ge(rhs.0).into()
+                self.0.ge(&rhs.0).into()
             }
         }
     };
@@ -695,9 +703,9 @@ macro_rules! impl_float {
         {
             type FloatEncoding = $prim;
 
-            type BitsType = Wrapper<<$prim as Float>::BitsType, LANES>;
+            type BitsType = Wrapper<<$prim as FloatEncoding>::BitsType, LANES>;
 
-            type SignedBitsType = Wrapper<<$prim as Float>::SignedBitsType, LANES>;
+            type SignedBitsType = Wrapper<<$prim as FloatEncoding>::SignedBitsType, LANES>;
 
             fn abs(self) -> Self {
                 self.0.abs().into()
@@ -721,7 +729,9 @@ macro_rules! impl_float {
 
             #[cfg(feature = "fma")]
             fn fma(self, a: Self, b: Self) -> Self {
-                self.0.fma(a.0, b.0).into()
+                let a = scalar::Value(a.0);
+                let b = scalar::Value(b.0);
+                scalar::Value(self.0).fma(a, b).0.into()
             }
 
             fn is_finite(self) -> Self::Bool {
@@ -806,9 +816,9 @@ impl_float!(SimdF16, F16, SimdU16, SimdI16);
 impl_float!(SimdF32, f32, SimdU32, SimdI32);
 impl_float!(SimdF64, f64, SimdU64, SimdI64);
 
-macro_rules! impl_scalar_convert_to_helper {
+macro_rules! impl_vector_convert_from_helper {
     ($src:ty => $dest:ty) => {
-        impl<const LANES: usize> ConvertTo<Wrapper<$dest, LANES>> for Wrapper<$src, LANES>
+        impl<const LANES: usize> ConvertFrom<Wrapper<$src, LANES>> for Wrapper<$dest, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -825,31 +835,31 @@ macro_rules! impl_scalar_convert_to_helper {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
-            fn to(self) -> Wrapper<$dest, LANES> {
-                let v: $dest = self.0.to();
+            fn cvt_from(v: Wrapper<$src, LANES>) -> Self {
+                let v: $dest = v.0.to();
                 v.into()
             }
         }
     };
 }
 
-macro_rules! impl_scalar_convert_to {
+macro_rules! impl_vector_convert_from {
     ($first:ty $(, $ty:ty)*) => {
         $(
-            impl_scalar_convert_to_helper!($first => $ty);
-            impl_scalar_convert_to_helper!($ty => $first);
+            impl_vector_convert_from_helper!($first => $ty);
+            impl_vector_convert_from_helper!($ty => $first);
         )*
-        impl_scalar_convert_to![$($ty),*];
+        impl_vector_convert_from![$($ty),*];
     };
     () => {};
 }
 
-impl_scalar_convert_to![u8, i8, u16, i16, F16, u32, i32, u64, i64, f32, f64];
+impl_vector_convert_from![u8, i8, u16, i16, F16, u32, i32, u64, i64, f32, f64];
 
-macro_rules! impl_vector_convert_to_helper {
+macro_rules! impl_vector_convert_from_helper {
     (($(#[From = $From:ident])? $src:ident, $src_prim:ident) => ($(#[From = $From2:ident])? $dest:ident, $dest_prim:ident)) => {
-        impl<const LANES: usize> ConvertTo<Wrapper<$dest<LANES>, LANES>>
-            for Wrapper<$src<LANES>, LANES>
+        impl<const LANES: usize> ConvertFrom<Wrapper<$src<LANES>, LANES>>
+            for Wrapper<$dest<LANES>, LANES>
         where
             SimdI8<LANES>: LanesAtMost32,
             SimdU8<LANES>: LanesAtMost32,
@@ -866,9 +876,9 @@ macro_rules! impl_vector_convert_to_helper {
             SimdF64<LANES>: LanesAtMost32,
             Mask64<LANES>: Mask,
         {
-            fn to(self) -> Wrapper<$dest<LANES>, LANES> {
+            fn cvt_from(v: Wrapper<$src<LANES>, LANES>) -> Self {
                 // FIXME(programmerjake): workaround https://github.com/rust-lang/stdsimd/issues/116
-                let src: [$src_prim; LANES] = self.0.into();
+                let src: [$src_prim; LANES] = v.0.into();
                 let mut dest: [$dest_prim; LANES] = [Default::default(); LANES];
                 for i in 0..LANES {
                     dest[i] = src[i].to();
@@ -901,18 +911,18 @@ macro_rules! impl_vector_convert_to_helper {
     };
 }
 
-macro_rules! impl_vector_convert_to {
+macro_rules! impl_vector_convert_from {
     ($first:tt $(, $ty:tt)*) => {
         $(
-            impl_vector_convert_to_helper!($first => $ty);
-            impl_vector_convert_to_helper!($ty => $first);
+            impl_vector_convert_from_helper!($first => $ty);
+            impl_vector_convert_from_helper!($ty => $first);
         )*
-        impl_vector_convert_to![$($ty),*];
+        impl_vector_convert_from![$($ty),*];
     };
     () => {};
 }
 
-impl_vector_convert_to![
+impl_vector_convert_from![
     (SimdU8, u8),
     (SimdI8, i8),
     (SimdU16, u16),
@@ -926,7 +936,7 @@ impl_vector_convert_to![
     (SimdF64, f64)
 ];
 
-impl_vector_convert_to![
+impl_vector_convert_from![
     (
         #[From = From]
         Mask8,
@@ -969,7 +979,7 @@ macro_rules! impl_from_helper {
             Mask64<LANES>: Mask,
         {
             fn from(v: $src) -> Self {
-                <$src as ConvertTo<$dest>>::to(v)
+                <$dest>::cvt_from(v)
             }
         }
     };