--wip-- [skip ci]

This commit is contained in:
2025-07-08 23:20:20 +01:00
parent e4eb599744
commit 52cc5c7385
11 changed files with 2338 additions and 803 deletions
+14 -33
View File
@@ -7,8 +7,8 @@ use std::simd::{
use crate::{
interpreter::{
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, Value, glfract,
glsign,
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, VALUE_PI_2,
VALUE_TAU, Value, glfract, glsign,
},
vm::choice::{Choice, VChoice},
};
@@ -40,6 +40,7 @@ impl Interval {
pub const NAN: Self = Self::const_splat(core::f32::NAN);
pub const ONE: Self = Self::const_splat(1.0);
pub const PI: Self = Self::const_splat(core::f32::consts::PI);
pub const PI_2: Self = Self::const_splat(core::f32::consts::FRAC_PI_2);
pub const ZERO: Self = Self::const_splat(0.0);
/// Builds a new interval
@@ -164,47 +165,27 @@ impl Interval {
/// Computes the sine of the interval
#[inline]
pub fn sin(self) -> Self {
let same_cycle = ((self.lower / VALUE_PI) + VALUE_05)
.floor()
.simd_eq(((self.upper / VALUE_PI) + VALUE_05).floor());
let up = (((self.upper / VALUE_PI) + VALUE_05).floor()) % (VALUE_2);
let whole_cycle = (((self.upper / VALUE_PI) + VALUE_05).floor()
- ((self.lower / VALUE_PI) + VALUE_05).floor())
.simd_gt(VALUE_1);
let temp0 = self.lower.sin();
let temp1 = self.upper.sin();
let lower = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_1))) | same_cycle)
.select(temp0.simd_min(temp1), VALUE_M1),
);
let upper = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_0))) | same_cycle)
.select(temp0.simd_max(temp1), VALUE_1),
);
Interval::new(lower, upper)
(self - Self::PI_2).cos()
}
/// Computes the cosine of the interval
#[inline]
pub fn cos(self) -> Self {
let same_cycle = (self.lower / VALUE_PI)
.floor()
.simd_eq((self.upper / VALUE_PI).floor());
let up = ((self.upper / VALUE_PI).floor()) % (VALUE_2);
let whole_cycle =
((self.upper / VALUE_PI).floor() - (self.lower / VALUE_PI).floor()).simd_gt(VALUE_1);
let lower_cycle = (self.lower / VALUE_PI).floor();
let upper_cycle = (self.upper / VALUE_PI).floor();
let same_cycle = lower_cycle.simd_eq(upper_cycle);
let cycle = upper_cycle % VALUE_2;
let within_one_cycle = (upper_cycle - lower_cycle).simd_eq(VALUE_1);
let temp0 = self.lower.cos();
let temp1 = self.upper.cos();
let lower = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_0))) | same_cycle)
(same_cycle | (within_one_cycle & (cycle.simd_eq(VALUE_0))))
.select(temp0.simd_min(temp1), VALUE_M1),
);
let upper = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_1))) | same_cycle)
(same_cycle | (within_one_cycle & (cycle.simd_eq(VALUE_1))))
.select(temp0.simd_max(temp1), VALUE_1),
);
Interval::new(lower, upper)
@@ -350,8 +331,8 @@ impl Interval {
);
(
Interval::new(
has_nan.select(VALUE_NAN, self.lower.simd_min(rhs.lower)),
has_nan.select(VALUE_NAN, self.upper.simd_min(rhs.upper)),
has_nan.select(VALUE_NAN, self.lower.simd_max(rhs.lower)),
has_nan.select(VALUE_NAN, self.upper.simd_max(rhs.upper)),
),
VChoice(choice),
)
@@ -629,7 +610,7 @@ impl std::ops::Rem<Interval> for Interval {
);
let upper = has_nan.select(
VALUE_NAN,
(other_constant & floors).select(self.upper % rhs.lower, rhs.upper.abs()),
(other_constant & floors).select(self.upper % rhs.lower, rhs.abs().upper),
);
Interval::new(lower, upper)