diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/packed_simd_2/src/api/math | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/packed_simd_2/src/api/math')
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float.rs | 64 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/abs.rs | 31 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/consts.rs | 86 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/cos.rs | 44 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/exp.rs | 33 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/ln.rs | 33 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/mul_add.rs | 44 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/mul_adde.rs | 48 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/powf.rs | 36 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/recpre.rs | 36 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/rsqrte.rs | 40 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/sin.rs | 50 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/sqrt.rs | 35 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/sqrte.rs | 44 | ||||
-rw-r--r-- | vendor/packed_simd_2/src/api/math/float/tanh.rs | 29 |
15 files changed, 653 insertions, 0 deletions
diff --git a/vendor/packed_simd_2/src/api/math/float.rs b/vendor/packed_simd_2/src/api/math/float.rs new file mode 100644 index 000000000..d5d2bee2e --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float.rs @@ -0,0 +1,64 @@ +//! Implements vertical floating-point math operations. + +#[macro_use] +mod abs; + +#[macro_use] +mod consts; + +#[macro_use] +mod cos; + +#[macro_use] +mod exp; + +#[macro_use] +mod powf; + +#[macro_use] +mod ln; + +#[macro_use] +mod mul_add; + +#[macro_use] +mod mul_adde; + +#[macro_use] +mod recpre; + +#[macro_use] +mod rsqrte; + +#[macro_use] +mod sin; + +#[macro_use] +mod sqrt; + +#[macro_use] +mod sqrte; + +#[macro_use] +mod tanh; + +macro_rules! impl_float_category { + ([$elem_ty:ident; $elem_count:expr]: $id:ident, $mask_ty:ident) => { + impl $id { + #[inline] + pub fn is_nan(self) -> $mask_ty { + self.ne(self) + } + + #[inline] + pub fn is_infinite(self) -> $mask_ty { + self.eq(Self::INFINITY) | self.eq(Self::NEG_INFINITY) + } + + #[inline] + pub fn is_finite(self) -> $mask_ty { + !(self.is_nan() | self.is_infinite()) + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/abs.rs b/vendor/packed_simd_2/src/api/math/float/abs.rs new file mode 100644 index 000000000..1865bdb68 --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/abs.rs @@ -0,0 +1,31 @@ +//! Implements vertical (lane-wise) floating-point `abs`. + +macro_rules! impl_math_float_abs { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Absolute value. + #[inline] + pub fn abs(self) -> Self { + use crate::codegen::math::float::abs::Abs; + Abs::abs(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_abs>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn abs() { + let o = $id::splat(1 as $elem_ty); + assert_eq!(o, o.abs()); + + let mo = $id::splat(-1 as $elem_ty); + assert_eq!(o, mo.abs()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/consts.rs b/vendor/packed_simd_2/src/api/math/float/consts.rs new file mode 100644 index 000000000..89f93a6d6 --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/consts.rs @@ -0,0 +1,86 @@ +macro_rules! impl_float_consts { + ([$elem_ty:ident; $elem_count:expr]: $id:ident) => { + impl $id { + /// Machine epsilon value. + pub const EPSILON: $id = $id::splat(core::$elem_ty::EPSILON); + + /// Smallest finite value. + pub const MIN: $id = $id::splat(core::$elem_ty::MIN); + + /// Smallest positive normal value. + pub const MIN_POSITIVE: $id = + $id::splat(core::$elem_ty::MIN_POSITIVE); + + /// Largest finite value. + pub const MAX: $id = $id::splat(core::$elem_ty::MAX); + + /// Not a Number (NaN). + pub const NAN: $id = $id::splat(core::$elem_ty::NAN); + + /// Infinity (∞). + pub const INFINITY: $id = $id::splat(core::$elem_ty::INFINITY); + + /// Negative infinity (-∞). + pub const NEG_INFINITY: $id = + $id::splat(core::$elem_ty::NEG_INFINITY); + + /// Archimedes' constant (π) + pub const PI: $id = $id::splat(core::$elem_ty::consts::PI); + + /// π/2 + pub const FRAC_PI_2: $id = + $id::splat(core::$elem_ty::consts::FRAC_PI_2); + + /// π/3 + pub const FRAC_PI_3: $id = + $id::splat(core::$elem_ty::consts::FRAC_PI_3); + + /// π/4 + pub const FRAC_PI_4: $id = + $id::splat(core::$elem_ty::consts::FRAC_PI_4); + + /// π/6 + pub const FRAC_PI_6: $id = + $id::splat(core::$elem_ty::consts::FRAC_PI_6); + + /// π/8 + pub const FRAC_PI_8: $id = + $id::splat(core::$elem_ty::consts::FRAC_PI_8); + + /// 1/π + pub const FRAC_1_PI: $id = + $id::splat(core::$elem_ty::consts::FRAC_1_PI); + + /// 2/π + pub const FRAC_2_PI: $id = + $id::splat(core::$elem_ty::consts::FRAC_2_PI); + + /// 2/sqrt(π) + pub const FRAC_2_SQRT_PI: $id = + $id::splat(core::$elem_ty::consts::FRAC_2_SQRT_PI); + + /// sqrt(2) + pub const SQRT_2: $id = $id::splat(core::$elem_ty::consts::SQRT_2); + + /// 1/sqrt(2) + pub const FRAC_1_SQRT_2: $id = + $id::splat(core::$elem_ty::consts::FRAC_1_SQRT_2); + + /// Euler's number (e) + pub const E: $id = $id::splat(core::$elem_ty::consts::E); + + /// log<sub>2</sub>(e) + pub const LOG2_E: $id = $id::splat(core::$elem_ty::consts::LOG2_E); + + /// log<sub>10</sub>(e) + pub const LOG10_E: $id = + $id::splat(core::$elem_ty::consts::LOG10_E); + + /// ln(2) + pub const LN_2: $id = $id::splat(core::$elem_ty::consts::LN_2); + + /// ln(10) + pub const LN_10: $id = $id::splat(core::$elem_ty::consts::LN_10); + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/cos.rs b/vendor/packed_simd_2/src/api/math/float/cos.rs new file mode 100644 index 000000000..e5b8f4603 --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/cos.rs @@ -0,0 +1,44 @@ +//! Implements vertical (lane-wise) floating-point `cos`. + +macro_rules! impl_math_float_cos { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Cosine. + #[inline] + pub fn cos(self) -> Self { + use crate::codegen::math::float::cos::Cos; + Cos::cos(self) + } + + /// Cosine of `self * PI`. + #[inline] + pub fn cos_pi(self) -> Self { + use crate::codegen::math::float::cos_pi::CosPi; + CosPi::cos_pi(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_cos>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn cos() { + use crate::$elem_ty::consts::PI; + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let p = $id::splat(PI as $elem_ty); + let ph = $id::splat(PI as $elem_ty / 2.); + let z_r = $id::splat((PI as $elem_ty / 2.).cos()); + let o_r = $id::splat((PI as $elem_ty).cos()); + + assert_eq!(o, z.cos()); + assert_eq!(z_r, ph.cos()); + assert_eq!(o_r, p.cos()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/exp.rs b/vendor/packed_simd_2/src/api/math/float/exp.rs new file mode 100644 index 000000000..e3356d853 --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/exp.rs @@ -0,0 +1,33 @@ +//! Implements vertical (lane-wise) floating-point `exp`. + +macro_rules! impl_math_float_exp { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Returns the exponential function of `self`: `e^(self)`. + #[inline] + pub fn exp(self) -> Self { + use crate::codegen::math::float::exp::Exp; + Exp::exp(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_exp>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn exp() { + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + assert_eq!(o, z.exp()); + + let e = $id::splat(crate::f64::consts::E as $elem_ty); + let tol = $id::splat(2.4e-4 as $elem_ty); + assert!((e - o.exp()).abs().le(tol).all()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/ln.rs b/vendor/packed_simd_2/src/api/math/float/ln.rs new file mode 100644 index 000000000..5ceb9173a --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/ln.rs @@ -0,0 +1,33 @@ +//! Implements vertical (lane-wise) floating-point `ln`. + +macro_rules! impl_math_float_ln { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Returns the natural logarithm of `self`. + #[inline] + pub fn ln(self) -> Self { + use crate::codegen::math::float::ln::Ln; + Ln::ln(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_ln>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn ln() { + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + assert_eq!(z, o.ln()); + + let e = $id::splat(crate::f64::consts::E as $elem_ty); + let tol = $id::splat(2.4e-4 as $elem_ty); + assert!((o - e.ln()).abs().le(tol).all()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/mul_add.rs b/vendor/packed_simd_2/src/api/math/float/mul_add.rs new file mode 100644 index 000000000..4b170ee2b --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/mul_add.rs @@ -0,0 +1,44 @@ +//! Implements vertical (lane-wise) floating-point `mul_add`. + +macro_rules! impl_math_float_mul_add { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Fused multiply add: `self * y + z` + #[inline] + pub fn mul_add(self, y: Self, z: Self) -> Self { + use crate::codegen::math::float::mul_add::MulAdd; + MulAdd::mul_add(self, y, z) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_mul_add>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn mul_add() { + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let t = $id::splat(2 as $elem_ty); + let t3 = $id::splat(3 as $elem_ty); + let f = $id::splat(4 as $elem_ty); + + assert_eq!(z, z.mul_add(z, z)); + assert_eq!(o, o.mul_add(o, z)); + assert_eq!(o, o.mul_add(z, o)); + assert_eq!(o, z.mul_add(o, o)); + + assert_eq!(t, o.mul_add(o, o)); + assert_eq!(t, o.mul_add(t, z)); + assert_eq!(t, t.mul_add(o, z)); + + assert_eq!(f, t.mul_add(t, z)); + assert_eq!(f, t.mul_add(o, t)); + assert_eq!(t3, t.mul_add(o, o)); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/mul_adde.rs b/vendor/packed_simd_2/src/api/math/float/mul_adde.rs new file mode 100644 index 000000000..c5b27110f --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/mul_adde.rs @@ -0,0 +1,48 @@ +//! Implements vertical (lane-wise) floating-point `mul_adde`. + +macro_rules! impl_math_float_mul_adde { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Fused multiply add estimate: ~= `self * y + z` + /// + /// While fused multiply-add (`fma`) has infinite precision, + /// `mul_adde` has _at worst_ the same precision of a multiply followed by an add. + /// This might be more efficient on architectures that do not have an `fma` instruction. + #[inline] + pub fn mul_adde(self, y: Self, z: Self) -> Self { + use crate::codegen::math::float::mul_adde::MulAddE; + MulAddE::mul_adde(self, y, z) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_mul_adde>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn mul_adde() { + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let t = $id::splat(2 as $elem_ty); + let t3 = $id::splat(3 as $elem_ty); + let f = $id::splat(4 as $elem_ty); + + assert_eq!(z, z.mul_adde(z, z)); + assert_eq!(o, o.mul_adde(o, z)); + assert_eq!(o, o.mul_adde(z, o)); + assert_eq!(o, z.mul_adde(o, o)); + + assert_eq!(t, o.mul_adde(o, o)); + assert_eq!(t, o.mul_adde(t, z)); + assert_eq!(t, t.mul_adde(o, z)); + + assert_eq!(f, t.mul_adde(t, z)); + assert_eq!(f, t.mul_adde(o, t)); + assert_eq!(t3, t.mul_adde(o, o)); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/powf.rs b/vendor/packed_simd_2/src/api/math/float/powf.rs new file mode 100644 index 000000000..83dc9ff9c --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/powf.rs @@ -0,0 +1,36 @@ +//! Implements vertical (lane-wise) floating-point `powf`. + +macro_rules! impl_math_float_powf { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Raises `self` number to the floating point power of `x`. + #[inline] + pub fn powf(self, x: Self) -> Self { + use crate::codegen::math::float::powf::Powf; + Powf::powf(self, x) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_powf>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn powf() { + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let t = $id::splat(2 as $elem_ty); + assert_eq!(o, o.powf(z)); + assert_eq!(o, t.powf(z)); + assert_eq!(o, o.powf(o)); + assert_eq!(t, t.powf(o)); + + let f = $id::splat(4 as $elem_ty); + assert_eq!(f, t.powf(t)); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/recpre.rs b/vendor/packed_simd_2/src/api/math/float/recpre.rs new file mode 100644 index 000000000..127f0b2ff --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/recpre.rs @@ -0,0 +1,36 @@ +//! Implements vertical (lane-wise) floating-point `recpre`. + +macro_rules! impl_math_float_recpre { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Reciprocal estimate: `~= 1. / self`. + /// + /// FIXME: The precision of the estimate is currently unspecified. + #[inline] + pub fn recpre(self) -> Self { + $id::splat(1.) / self + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_recpre>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn recpre() { + let tol = $id::splat(2.4e-4 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let error = (o - o.recpre()).abs(); + assert!(error.le(tol).all()); + + let t = $id::splat(2 as $elem_ty); + let e = 0.5; + let error = (e - t.recpre()).abs(); + assert!(error.le(tol).all()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/rsqrte.rs b/vendor/packed_simd_2/src/api/math/float/rsqrte.rs new file mode 100644 index 000000000..c77977f7b --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/rsqrte.rs @@ -0,0 +1,40 @@ +//! Implements vertical (lane-wise) floating-point `rsqrte`. + +macro_rules! impl_math_float_rsqrte { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Reciprocal square-root estimate: `~= 1. / self.sqrt()`. + /// + /// FIXME: The precision of the estimate is currently unspecified. + #[inline] + pub fn rsqrte(self) -> Self { + unsafe { + use crate::llvm::simd_fsqrt; + $id::splat(1.) / Simd(simd_fsqrt(self.0)) + } + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_rsqrte>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn rsqrte() { + use crate::$elem_ty::consts::SQRT_2; + let tol = $id::splat(2.4e-4 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + let error = (o - o.rsqrte()).abs(); + assert!(error.le(tol).all()); + + let t = $id::splat(2 as $elem_ty); + let e = 1. / SQRT_2; + let error = (e - t.rsqrte()).abs(); + assert!(error.le(tol).all()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/sin.rs b/vendor/packed_simd_2/src/api/math/float/sin.rs new file mode 100644 index 000000000..49908319b --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/sin.rs @@ -0,0 +1,50 @@ +//! Implements vertical (lane-wise) floating-point `sin`. + +macro_rules! impl_math_float_sin { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Sine. + #[inline] + pub fn sin(self) -> Self { + use crate::codegen::math::float::sin::Sin; + Sin::sin(self) + } + + /// Sine of `self * PI`. + #[inline] + pub fn sin_pi(self) -> Self { + use crate::codegen::math::float::sin_pi::SinPi; + SinPi::sin_pi(self) + } + + /// Sine and cosine of `self * PI`. + #[inline] + pub fn sin_cos_pi(self) -> (Self, Self) { + use crate::codegen::math::float::sin_cos_pi::SinCosPi; + SinCosPi::sin_cos_pi(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_sin>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn sin() { + use crate::$elem_ty::consts::PI; + let z = $id::splat(0 as $elem_ty); + let p = $id::splat(PI as $elem_ty); + let ph = $id::splat(PI as $elem_ty / 2.); + let o_r = $id::splat((PI as $elem_ty / 2.).sin()); + let z_r = $id::splat((PI as $elem_ty).sin()); + + assert_eq!(z, z.sin()); + assert_eq!(o_r, ph.sin()); + assert_eq!(z_r, p.sin()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/sqrt.rs b/vendor/packed_simd_2/src/api/math/float/sqrt.rs new file mode 100644 index 000000000..ae624122d --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/sqrt.rs @@ -0,0 +1,35 @@ +//! Implements vertical (lane-wise) floating-point `sqrt`. + +macro_rules! impl_math_float_sqrt { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + #[inline] + pub fn sqrt(self) -> Self { + use crate::codegen::math::float::sqrt::Sqrt; + Sqrt::sqrt(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_sqrt>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn sqrt() { + use crate::$elem_ty::consts::SQRT_2; + let z = $id::splat(0 as $elem_ty); + let o = $id::splat(1 as $elem_ty); + assert_eq!(z, z.sqrt()); + assert_eq!(o, o.sqrt()); + + let t = $id::splat(2 as $elem_ty); + let e = $id::splat(SQRT_2); + assert_eq!(e, t.sqrt()); + + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/sqrte.rs b/vendor/packed_simd_2/src/api/math/float/sqrte.rs new file mode 100644 index 000000000..f7ffad748 --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/sqrte.rs @@ -0,0 +1,44 @@ +//! Implements vertical (lane-wise) floating-point `sqrte`. + +macro_rules! impl_math_float_sqrte { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Square-root estimate. + /// + /// FIXME: The precision of the estimate is currently unspecified. + #[inline] + pub fn sqrte(self) -> Self { + use crate::codegen::math::float::sqrte::Sqrte; + Sqrte::sqrte(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_sqrte>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn sqrte() { + use crate::$elem_ty::consts::SQRT_2; + let tol = $id::splat(2.4e-4 as $elem_ty); + + let z = $id::splat(0 as $elem_ty); + let error = (z - z.sqrte()).abs(); + assert!(error.le(tol).all()); + + let o = $id::splat(1 as $elem_ty); + let error = (o - o.sqrte()).abs(); + assert!(error.le(tol).all()); + + let t = $id::splat(2 as $elem_ty); + let e = $id::splat(SQRT_2 as $elem_ty); + let error = (e - t.sqrte()).abs(); + + assert!(error.le(tol).all()); + } + } + } + } + }; +} diff --git a/vendor/packed_simd_2/src/api/math/float/tanh.rs b/vendor/packed_simd_2/src/api/math/float/tanh.rs new file mode 100644 index 000000000..acfd93caa --- /dev/null +++ b/vendor/packed_simd_2/src/api/math/float/tanh.rs @@ -0,0 +1,29 @@ +//! Implements vertical (lane-wise) floating-point `tanh`. + +macro_rules! impl_math_float_tanh { + ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => { + impl $id { + /// Tanh. + #[inline] + pub fn tanh(self) -> Self { + use crate::codegen::math::float::tanh::Tanh; + Tanh::tanh(self) + } + } + + test_if!{ + $test_tt: + paste::item! { + pub mod [<$id _math_tanh>] { + use super::*; + #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn tanh() { + let z = $id::splat(0 as $elem_ty); + + assert_eq!(z, z.tanh()); + } + } + } + } + }; +} |