Skip to content

Commit

Permalink
doubled 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Aug 8, 2022
1 parent f81b595 commit 62c1610
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"

[dependencies.doubled]
git = "https://github.com/burrbull/doubled-rs"
branch = "portable-simd"
version = "0.3.0"
features = ["simd"]

[features]
Expand Down
8 changes: 4 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ impl SqrtAsDoubled for f32 {
#[inline]
fn sqrt_as_doubled(self) -> Doubled<Self> {
let t = self.sqrt();
((self + t.mul_as_doubled(t)) * t.recpre()).scale(0.5)
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(0.5)
}
}

impl SqrtAsDoubled for f64 {
#[inline]
fn sqrt_as_doubled(self) -> Doubled<Self> {
let t = self.sqrt();
((self + t.mul_as_doubled(t)) * t.recpre()).scale(0.5)
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(0.5)
}
}

Expand All @@ -52,15 +52,15 @@ impl Sqrt for Doubled<f32> {
#[inline]
fn sqrt(self) -> Self {
let t = f32::from(self).sqrt();
((self + t.mul_as_doubled(t)) * t.recpre()).scale(0.5)
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(0.5)
}
}

impl Sqrt for Doubled<f64> {
#[inline]
fn sqrt(self) -> Self {
let t = f64::from(self).sqrt();
((self + t.mul_as_doubled(t)) * t.recpre()).scale(0.5)
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(0.5)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/f32/u05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub fn sqrtf(mut d: f32) -> f32 {
x *= 1.5 - 0.5 * d * x * x;
x *= (1.5 - 0.5 * d * x * x) * d;

let d2 = (d + x.mul_as_doubled(x)) * x.recpre();
let d2 = (d + x.mul_as_doubled(x)) * x.recip_as_doubled();

if (d == 0.) || (d == f32::INFINITY) {
d
Expand Down
16 changes: 10 additions & 6 deletions src/f32/u10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn tanf(d: f32) -> f32 {
x = t * x;

if (q & 1) != 0 {
x = x.recpre();
x = x.recip();
}

if d.is_neg_zero() {
Expand Down Expand Up @@ -439,7 +439,7 @@ fn test_atanf() {
pub fn sinhf(x: f32) -> f32 {
let mut y = fabsfk(x);
let mut d = expk2f(Doubled::from(y));
d = d.sub_checked(d.recpre());
d = d.sub_checked(d.recip());
y = f32::from(d) * 0.5;

y = if fabsfk(x) > 89. { f32::INFINITY } else { y };
Expand All @@ -466,7 +466,7 @@ fn test_sinhf() {
pub fn coshf(x: f32) -> f32 {
let mut y = fabsfk(x);
let mut d = expk2f(Doubled::from(y));
d = d.add_checked(d.recpre());
d = d.add_checked(d.recip());
y = f32::from(d) * 0.5;

y = if fabsfk(x) > 89. { f32::INFINITY } else { y };
Expand All @@ -490,7 +490,7 @@ fn test_coshf() {
pub fn tanhf(x: f32) -> f32 {
let mut y = fabsfk(x);
let mut d = expk2f(Doubled::from(y));
let e = d.recpre();
let e = d.recip();
d = d.sub_checked(e) / d.add_checked(e);
y = f32::from(d);

Expand Down Expand Up @@ -534,7 +534,11 @@ fn logk2f(d: Doubled<f32>) -> Doubled<f32> {
pub fn asinhf(x: f32) -> f32 {
let mut y = fabsfk(x);

let mut d = if y > 1. { x.recpre() } else { Doubled::from(y) };
let mut d = if y > 1. {
x.recip_as_doubled()
} else {
Doubled::from(y)
};
d = (d.square() + 1.).sqrt();
d = if y > 1. { d * y } else { d };

Expand Down Expand Up @@ -1400,7 +1404,7 @@ pub fn erff(a: f32) -> f32 {
t2 = t2.square();
t2 = t2.square();
t2 = t2.square();
t2 = t2.recpre();
t2 = t2.recip();
} else if x > 4. {
t2 = Doubled::from(0.);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/f32x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ macro_rules! impl_math_f32 {
#[inline]
fn sqrt_as_doubled(self) -> Doubled<Self> {
let t = self.sqrt();
((self + t.mul_as_doubled(t)) * t.recpre_as_doubled()).scale(Self::splat(0.5))
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(Self::splat(0.5))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/f32x/u05_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ macro_rules! impl_math_f32_u05 {
x *= F32x::splat(1.5) - HALF * d * x * x;
x *= d;

let d2 = (d + x.mul_as_doubled(x)) * x.recpre_as_doubled();
let d2 = (d + x.mul_as_doubled(x)) * x.recip_as_doubled();

x = F32x::from(d2) * q;

Expand Down
16 changes: 8 additions & 8 deletions src/f32x/u10_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ macro_rules! impl_math_f32_u10 {
.add_checked(F32x::splat(0.333_333_611_488_342_285_156_25).add_checked(s * x) * s);
x = t * x;

x = o.select_doubled(x.recpre(), x);
x = o.select_doubled(x.recip(), x);

let u = F32x::from(x);

Expand Down Expand Up @@ -517,7 +517,7 @@ macro_rules! impl_math_f32_u10 {
.add_checked(F32x::splat(0.333_333_611_488_342_285_156_25).add_checked(s * x) * s);
x = t * x;

x = o.select_doubled(x.recpre(), x);
x = o.select_doubled(x.recip(), x);

let u = F32x::from(x);

Expand Down Expand Up @@ -737,7 +737,7 @@ macro_rules! impl_math_f32_u10 {
pub fn sinhf(x: F32x) -> F32x {
let mut y = x.abs();
let d = expk2f(Doubled::from(y));
let d = d.sub_checked(d.recpre());
let d = d.sub_checked(d.recip());
y = F32x::from(d) * HALF;

y = (x.abs().simd_gt(F32x::splat(89.)) | y.is_nan()).select(INFINITY, y);
Expand All @@ -764,7 +764,7 @@ macro_rules! impl_math_f32_u10 {
pub fn coshf(x: F32x) -> F32x {
let mut y = x.abs();
let d = expk2f(Doubled::from(y));
let d = d.add_checked(d.recpre());
let d = d.add_checked(d.recip());
y = F32x::from(d) * HALF;

y = (x.abs().simd_gt(F32x::splat(89.)) | y.is_nan()).select(INFINITY, y);
Expand All @@ -788,7 +788,7 @@ macro_rules! impl_math_f32_u10 {
pub fn tanhf(x: F32x) -> F32x {
let mut y = x.abs();
let d = expk2f(Doubled::from(y));
let e = d.recpre();
let e = d.recip();
let d = d.add_checked(-e) / d.add_checked(e);
y = F32x::from(d);

Expand Down Expand Up @@ -839,7 +839,7 @@ macro_rules! impl_math_f32_u10 {
let mut y = x.abs();
let o = y.simd_gt(ONE);

let mut d = o.select_doubled(x.recpre_as_doubled(), Doubled::from(y));
let mut d = o.select_doubled(x.recip_as_doubled(), Doubled::from(y));
d = (d.square() + ONE).sqrt();
d = o.select_doubled(d * y, d);

Expand Down Expand Up @@ -1778,7 +1778,7 @@ macro_rules! impl_math_f32_u10 {
t2 = t2.square();
t2 = t2.square();
t2 = t2.square();
t2 = t2.recpre();
t2 = t2.recip();
} else {
let t = F32x::poly6(x, x2, x4,
o25.select_splat(-0.436_044_700_8_e-6, -0.113_001_284_8_e-6),
Expand Down Expand Up @@ -1825,7 +1825,7 @@ macro_rules! impl_math_f32_u10 {
s2 = s2.square();
s2 = s2.square();
s2 = s2.square();
s2 = s2.recpre();
s2 = s2.recip();
t2 = o25.select_doubled(s2, Doubled::from(expkf(t2)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/f64/u05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn sqrt(mut d: f64) -> f64 {
x = x * (1.5 - 0.5 * d * x * x);
x = x * (1.5 - 0.5 * d * x * x) * d;

let d2 = (d + x.mul_as_doubled(x)) * x.recpre();
let d2 = (d + x.mul_as_doubled(x)) * x.recip_as_doubled();

let ret = f64::from(d2) * q;

Expand Down
14 changes: 9 additions & 5 deletions src/f64/u10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ fn test_atan() {
pub fn sinh(x: f64) -> f64 {
let mut y = fabsk(x);
let mut d = expk2(Doubled::from(y));
d = d.sub_checked(d.recpre());
d = d.sub_checked(d.recip());
y = f64::from(d) * 0.5;

y = if fabsk(x) > 710. { f64::INFINITY } else { y };
Expand All @@ -610,7 +610,7 @@ fn test_sinh() {
pub fn cosh(x: f64) -> f64 {
let mut y = fabsk(x);
let mut d = expk2(Doubled::from(y));
d = d.add_checked(d.recpre());
d = d.add_checked(d.recip());
y = f64::from(d) * 0.5;

y = if fabsk(x) > 710. { f64::INFINITY } else { y };
Expand All @@ -634,7 +634,7 @@ fn test_cosh() {
pub fn tanh(x: f64) -> f64 {
let mut y = fabsk(x);
let mut d = expk2(Doubled::from(y));
let e = d.recpre();
let e = d.recip();
d = d.sub_checked(e) / d.add_checked(e);
y = f64::from(d);

Expand Down Expand Up @@ -691,7 +691,11 @@ fn logk2(d: Doubled<f64>) -> Doubled<f64> {
pub fn asinh(x: f64) -> f64 {
let mut y = fabsk(x);

let mut d = if y > 1. { x.recpre() } else { Doubled::from(y) };
let mut d = if y > 1. {
x.recip_as_doubled()
} else {
Doubled::from(y)
};
d = (d.square() + 1.).sqrt();
d = if y > 1. { d * y } else { d };

Expand Down Expand Up @@ -1839,7 +1843,7 @@ pub fn erf(a: f64) -> f64 {
t2 = t2.square();
t2 = t2.square();
t2 = t2.square();
t2 = t2.recpre();
t2 = t2.recip();
} else if x > 6. {
t2 = Doubled::from(0.);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/f64x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ macro_rules! impl_math_f64 {
#[inline]
fn sqrt_as_doubled(self) -> Doubled<Self> {
let t = self.sqrt();
((self + t.mul_as_doubled(t)) * t.recpre_as_doubled()).scale(Self::splat(0.5))
((self + t.mul_as_doubled(t)) * t.recip_as_doubled()).scale(Self::splat(0.5))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/f64x/u05_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ macro_rules! impl_math_f64_u05 {
x *= F64x::splat(1.5) - HALF * d * x * x;
x *= d;

let d2 = (d + x.mul_as_doubled(x)) * x.recpre_as_doubled();
let d2 = (d + x.mul_as_doubled(x)) * x.recip_as_doubled();

x = F64x::from(d2) * q;

Expand Down
12 changes: 6 additions & 6 deletions src/f64x/u10_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ macro_rules! impl_math_f64_u10 {
pub fn sinh(x: F64x) -> F64x {
let mut y = x.abs();
let mut d = expk2(Doubled::from(y));
d = d.sub_checked(d.recpre());
d = d.sub_checked(d.recip());
y = F64x::from(d) * HALF;

y = (x.abs().simd_gt(F64x::splat(710.)) | y.is_nan()).select(INFINITY, y);
Expand All @@ -971,7 +971,7 @@ macro_rules! impl_math_f64_u10 {
pub fn cosh(x: F64x) -> F64x {
let mut y = x.abs();
let mut d = expk2(Doubled::from(y));
d = d.add_checked(d.recpre());
d = d.add_checked(d.recip());
y = F64x::from(d) * HALF;

y = (x.abs().simd_gt(F64x::splat(710.)) | y.is_nan()).select(INFINITY, y);
Expand All @@ -995,7 +995,7 @@ macro_rules! impl_math_f64_u10 {
pub fn tanh(x: F64x) -> F64x {
let mut y = x.abs();
let mut d = expk2(Doubled::from(y));
let e = d.recpre();
let e = d.recip();
d = (d + (-e)) / (d + e);
y = F64x::from(d);

Expand Down Expand Up @@ -1055,7 +1055,7 @@ macro_rules! impl_math_f64_u10 {
let mut y = x.abs();
let o = y.simd_gt(ONE);

let mut d = o.select_doubled(x.recpre_as_doubled(), Doubled::from(y));
let mut d = o.select_doubled(x.recip_as_doubled(), Doubled::from(y));
d = (d.square() + ONE).sqrt();
d = o.select_doubled(d * y, d);

Expand Down Expand Up @@ -2248,7 +2248,7 @@ macro_rules! impl_math_f64_u10 {
t2 = t2.square();
t2 = t2.square();
t2 = t2.square();
t2 = t2.recpre();
t2 = t2.recip();
} else {
let t = F64x::poly21(x, x2, x4, x8, x16,
o25.select_splat(-0.208_327_100_252_522_209_7_e-14, -0.402_401_513_075_262_193_2_e-18),
Expand Down Expand Up @@ -2309,7 +2309,7 @@ macro_rules! impl_math_f64_u10 {
s2 = s2.square();
s2 = s2.square();
s2 = s2.square();
s2 = s2.recpre();
s2 = s2.recip();
t2 = o25.select_doubled(s2, Doubled::from(expk(t2)));
}

Expand Down

0 comments on commit 62c1610

Please sign in to comment.